home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / unaxcess / part2 / conf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  13.1 KB  |  533 lines

  1. /*
  2.  * %W% %E% %U% ncoast!bsa %Z%
  3.  * %Z% Copyright (C) 1986 by Brandon S. Allbery, All Rights Reserved %Z%
  4.  */
  5.  
  6. #ifndef lint
  7. static char _SccsId[] = "%W% %E% %U% ncoast!bsa %Z%";
  8. static char _CopyRt[] = "%Z% Copyright (C) 1985 by Brandon S. Allbery %Z%";
  9. #endif  lint
  10.  
  11. #include "ua.h"
  12.  
  13. char conference[33];
  14.  
  15. confidx()
  16.     {
  17.     FILE *ifd;
  18.     short icnt, himsg;
  19.     char line[256];
  20.     DIR *dp;
  21.     struct direct *dfd;
  22.  
  23.     icnt = 0;
  24.     puts("\n\"!\" after a conference name indicates an unsubscribed-to conference.\n\nConference                        HiMsg Conference                        HiMsg");
  25.     if ((dp = opendir(MSGBASE)) == NULL)
  26.     {
  27.     log("Error %d opening dir %s/", errno, MSGBASE);
  28.     panic("msgdir");
  29.     }
  30.     while ((dfd = readdir(dp)) != NULL)
  31.     {
  32.     if (dfd->d_name[0] == '.')
  33.         continue;
  34.     sprintf(line, "%s/%s/himsg", MSGBASE, dfd->d_name);
  35.     if ((ifd = fopen(line, "r")) == NULL)
  36.         {
  37.         log("No himsg in conference %s", dfd->d_name);
  38.         continue;
  39.         }
  40.     fgets(line, 32, ifd);
  41.     himsg = atoi(line);
  42.     printf("%-32.32s%c %-5d", dfd->d_name, (isunsub(dfd->d_name)? '!': ':'), himsg);
  43.     fclose(ifd);
  44.     if (user.u_llen < 80 || !(++icnt % 2))
  45.         putchar('\n');
  46.     else if (!(icnt % 2))
  47.         putchar('|');
  48.     }
  49.     closedir(dp);
  50.     puts("\n");
  51.     return 1;
  52.     }
  53.  
  54. join(c)
  55.     char *c;
  56.     {
  57.     char line[256], *p;
  58.  
  59.     p = c - 1;
  60.     while (*++p != '\0')
  61.     if (*p == ' ')
  62.         if (verify(++p))
  63.         {
  64.         strcpy(conference, p);
  65.         return 1;
  66.         }
  67.     do
  68.     {
  69.     printf("Enter conference: ");
  70.     gets(line);
  71.     log("Enter conference: %s", line);
  72.     if (line[0] == '\0')
  73.         return 1;
  74.     }
  75.     while (!verify(line));
  76.     strcpy(conference, line);
  77.     log("Current conference is %s", conference);
  78.     return 1;
  79.     }
  80.  
  81. verify(conf)
  82.     char *conf;
  83.     {
  84.     char *cp, line[256];
  85.  
  86.     for (cp = conf; *cp != 0; cp++)
  87.     {
  88.     if (!isprint(*cp))
  89.         return 0;
  90.     else if (*cp == '/' || *cp == '!' || *cp == ':')
  91.         *cp = '.';
  92.     else
  93.         *cp = ToLower(*cp);
  94.     }
  95.     if (cp - conf > CONFSIZE)
  96.     conf[CONFSIZE] = '\0';
  97.     sprintf(line, "%s/%s", MSGBASE, conf);
  98.     if (chdir(line) == -1)
  99.     {
  100.     if (errno != ENOENT)
  101.         {
  102.         log("Error %d accessing dir %s/", errno, line);
  103.         return 0;
  104.         }
  105.     else
  106.         return newconf(conf);
  107.     }
  108.     chdir("../..");
  109.     if (isunsub(conf)) {
  110.         printf("You are unsubscribed from this conference.  Rejoin (N)? ");
  111.         gets(line);
  112.         log("Unsubscribed.  Resubscribe? %s", line);
  113.         if (ToLower(line[0]) == 'y')
  114.             resubscribe(conf);
  115.         else
  116.             return 0;
  117.     }
  118.     if (parms.ua_xrc && conf[0] == 'x' && conf[1] == '-')
  119.     {
  120.     printf("This is a Restricted Access (X-RATED) conference.  The material within\n may be unsuitable for, or unacceptable to, some users of UNaXcess.\n\nDo you still wish to join this conference (N)? ");
  121.     gets(line);
  122.     log("Restricted.  Join? %s", line);
  123.     return (ToLower(line[0]) == 'y');
  124.     }
  125.     return 1;
  126.     }
  127.  
  128. killmsg(n)
  129.     char *n;
  130.     {
  131.     short mnum, flag;
  132.     char line[256], *p;
  133.  
  134.     if (user.u_access == A_GUEST)
  135.     {
  136.     puts("You aren't authorized for this function.");
  137.     log("Security violation:  KILL by a GUEST");
  138.     return 1;
  139.     }
  140.     flag = 0;
  141.     for (p = n; *p != '\0'; p++)
  142.     if (*p == ' ')
  143.         {
  144.         if ((mnum = atoi(++p)) < 1)
  145.         break;
  146.         dokill(mnum);
  147.         flag++;
  148.         }
  149.     if (flag)
  150.     return 1;
  151.     printf("Enter message number to kill: ");
  152.     gets(line);
  153.     if (line[0] == '\0')
  154.     return 1;
  155.     if ((mnum = atoi(line)) < 1)
  156.     {
  157.     puts("Bad message number.");
  158.     log("Bad message number: %s", line);
  159.     return 1;
  160.     }
  161.     dokill(mnum);
  162.     return 1;
  163.     }
  164.  
  165. dokill(msg)
  166.     short msg;
  167.     {
  168.     char mfile[256];
  169.  
  170.     sprintf(mfile, "%s/%s/%d", MSGBASE, conference, msg);
  171.     if (user.u_access != A_WITNESS && strcmp(getowner(mfile), user.u_name) != 0)
  172.     {
  173.     puts("Sorry, you don't own that message.");
  174.     log("Security violation:  KILL by non-owner");
  175.     return;
  176.     }
  177.     if (unlink(mfile) < 0)
  178.     {
  179.     printf("No such message: %d", msg);
  180.     log("Error %d unlinking %s", errno, mfile);
  181.     return;
  182.     }
  183.     log("Deleted %s:%d", conference, msg);
  184.     }
  185.  
  186. char *getowner(file)
  187.     char *file;
  188.     {
  189.     FILE *f;
  190.     char line[1024], *p;
  191.     static char owner[256];
  192.  
  193.     strcpy(owner, parms.ua_sysop);
  194.     if ((f = fopen(file, "r")) == NULL)
  195.     return owner;
  196.     while (fgets(line, 1024, f) != NULL)
  197.     if (line[0] == '\n')
  198.         break;
  199.     else if (strncmp(line, "From: ", 6) == 0)
  200.         {
  201.         strcpy(owner, &line[6]);
  202.         break;
  203.         }
  204.     fclose(f);
  205.     for (p = owner; *p != '\0'; p++)
  206.     *p = ToLower(*p);
  207.     return owner;
  208.     }
  209.  
  210. newconf(conf)
  211.     char *conf;
  212.     {
  213.     char line[256];
  214.     FILE *f;
  215.  
  216.     if (user.u_access == A_GUEST)
  217.     {
  218.     log("Security violation:  attempted MKCONF by guest");
  219.     puts("Sorry, there is no such conference.");
  220.     return 0;
  221.     }
  222.     printf("There is no conference by that name.  Do you want to create it (N)? ");
  223.     gets(line);
  224.     log("Nonexistent.  Create? %s", line);
  225.     if (ToLower(line[0]) != 'y')
  226.     return 0;
  227.     if (parms.ua_xrc && conf[0] == 'x' && conf[1] == '-')
  228.     {
  229.     printf("Conferences beginning with \"x-\" are designated as Restricted Access (X-RATED)\nconferences under UNaXcess, and will often carry information unsuitable for some\n");
  230.     printf("users or unacceptable to some users.  If you do not wish to create such a\nconference, answer NO to the next question and choose a conference name not\n");
  231.     printf("beginning with the characters \"x-\".\n\nDo you wish to create an X-RATED conference (N)? ");
  232.     gets(line);
  233.     log("Restricted.  Create? %s", line);
  234.     if (ToLower(line[0]) != 'y')
  235.         return 0;
  236.     }
  237.     if (parms.ua_roc && conf[0] == 'r' && conf[1] == '-')
  238.     if (user.u_access != A_WITNESS)
  239.         {
  240.         puts("Only Fairwitnesses can make READ-ONLY conferences.");
  241.         log("Attempted mk of RO conf by non-FW");
  242.         return 0;
  243.         }
  244.     else
  245.         {
  246.         puts("This conference will be READ-ONLY, except to Fairwitnesses.\nIf you want anyone to be able to add to it, answer NO and use a name not\nbeginning with \"R-\".");
  247.         printf("\nDo you want to make this READ-ONLY conference (N)? ");
  248.         gets(line);
  249.         log("Read-only.  Create? %s", line);
  250.         if (ToLower(line[0]) != 'y')
  251.         return 0;
  252.         }
  253.     sprintf(line, "exec mkconf %s/%s %d", MSGBASE, conf, geteuid());
  254.     if (system(line) != 0)
  255.     {
  256.     log("Mkconf of %s failed.", conf);
  257.     puts("Hmmm... guess you aren't allowed.");
  258.     return 0;
  259.     }
  260.     log("New conference: %s", conf);
  261.     sprintf(line, "%s/%s/himsg", MSGBASE, conf);
  262.     if ((f = fopen(line, "w")) == NULL)
  263.     {
  264.     log("Error %d opening %s", line);
  265.     puts("Can't create high message file.  Strange...");
  266.     return 0;
  267.     }
  268.     fputs("0", f);
  269.     fclose(f);
  270.     puts("You will now be placed in the message editor to make a message describing\nthis conferemnce.  It will be addressed to, and readable by, all users.");
  271.     mkmsg("All", "This conference", conf, 0);
  272.     return 1;
  273.     }
  274.  
  275. isprivate(msg)
  276.     char *msg;
  277.     {
  278.     FILE *fp;
  279.     char line[1024], to[1024], from[1024];
  280.     short pflag;
  281.  
  282.     if (user.u_access == A_WITNESS)
  283.     return 0;
  284.     if ((fp = fopen(msg, "r")) == NULL)
  285.     return 0;
  286.     strcpy(to, "All");
  287.     pflag = 0;
  288.     while (fgets(line, 1024, fp) != NULL)
  289.     {
  290.     if (line[0] == '\n')
  291.         break;
  292.     else if (strncmp(line, "To: ", 4) == 0)
  293.         strcpy(to, &line[4]);
  294.     else if (strncmp(line, "From: ", 6) == 0)
  295.         strcpy(from, &line[6]);
  296.     else if (strncmp(line, "Subject (Private): ", 19) == 0)
  297.         pflag = 1;
  298.     }
  299.     fclose(fp);
  300.     if (pflag && strcmp(user.u_name, to) == 0)
  301.     return 0;
  302.     else if (pflag && strcmp(user.u_name, from) == 0)
  303.     return 0;
  304.     else if (pflag)
  305.     {
  306.     log("Message %s is private.", msg);
  307.     return 1;
  308.     }
  309.     else
  310.     return 0;
  311.     }
  312.  
  313. isunsub(conf)
  314. char *conf; {
  315.     struct _himsg *hip;
  316.  
  317.     for (hip = hicnts; hip != NULL; hip = hip->hi_next)
  318.         if (strcmp(hip->hi_conf, conf) == 0)
  319.             break;
  320.     return (hip != NULL && hip->hi_uns == HI_UNSUB);
  321. }
  322.  
  323. unsubscribe(conf)
  324. char *conf; {
  325.     struct _himsg *hip, *workp;
  326.     char line[512];
  327.     
  328.     if (s_cmp(conf, "general") == 0) {
  329.         puts("Can't unsubscribe the general conference.");
  330.         log("Attempted to unsubscribe to general.");
  331.         return;
  332.     }
  333.     if (s_cmp(conf, user.u_lconf) == 0) {
  334.         printf("Unsubscribe to login conference (N)? ");
  335.         gets(line);
  336.         log("Unsub login conf? %s", line);
  337.         if (ToLower(line[0]) != 'y')
  338.             return;
  339.         strcpy(user.u_lconf, "general");
  340.     }
  341.     for (hip = hicnts; hip != NULL; hip = hip->hi_next)
  342.         if (strcmp(hip->hi_conf, conf) == 0)
  343.             break;
  344.     if (hip != NULL)
  345.         hip->hi_uns = HI_UNSUB;
  346.     else {
  347.     if ((workp = (struct _himsg *) calloc((unsigned) 1, sizeof (struct _himsg))) == NULL)
  348.         {
  349.         log("Error %d allocating _himsg for %s", errno, conf);
  350.         panic("alloc");
  351.         }
  352.     strcpy(workp->hi_conf, conf);
  353.     workp->hi_num = 0;
  354.     workp->hi_next = hicnts;
  355.     hicnts = workp;
  356.     workp->hi_uns = HI_UNSUB;
  357.     }
  358.     log("Unsubscribed to %s", conf);
  359.     printf("Unsubscribed to conference %s.\n", conf);
  360. }
  361.  
  362. resubscribe(conf)
  363. char *conf; {
  364.     struct _himsg *hip, *workp;
  365.     
  366.     for (hip = hicnts; hip != NULL; hip = hip->hi_next)
  367.         if (strcmp(hip->hi_conf, conf) == 0)
  368.             break;
  369.     if (hip != NULL)
  370.         hip->hi_uns = HI_SUBSCR;
  371.     else {
  372.     if ((workp = (struct _himsg *) calloc((unsigned) 1, sizeof (struct _himsg))) == NULL)
  373.         {
  374.         log("Error %d allocating _himsg for %s", errno, conf);
  375.         panic("alloc");
  376.         }
  377.     strcpy(workp->hi_conf, conf);
  378.     workp->hi_num = 0;
  379.     workp->hi_next = hicnts;
  380.     hicnts = workp;
  381.     workp->hi_uns = HI_SUBSCR;
  382.     }
  383.     log("Resubscribed to %s", conf);
  384.     printf("Resubscribed to conference %s.\n", conf);
  385. }
  386.  
  387. unsub(c)
  388. char *c; {
  389.     char line[256], *p;
  390.  
  391.     p = c - 1;
  392.     while (*++p != '\0')
  393.     if (*p == ' ')
  394.         if (isconf(++p))
  395.         {
  396.         unsubscribe(p);
  397.         return 1;
  398.         }
  399.     for (;;) {
  400.     printf("Unsubscribe to which conference (%s) [NONE to abort]: ", conference);
  401.     gets(line);
  402.     log("Unsub conference: %s", line);
  403.     if (line[0] == '\0') {
  404.         unsubscribe(conference);
  405.         return 1;
  406.     }
  407.     if (s_cmp(line, "none") == 0)
  408.         return 1;
  409.     if (isconf(line)) {
  410.         unsubscribe(line);
  411.         return 1;
  412.     }
  413.     }
  414. }
  415.  
  416. isconf(conf)
  417. char *conf; {
  418.     char *cp, line[256];
  419.  
  420.     for (cp = conf; *cp != 0; cp++) {
  421.         if (!isprint(*cp))
  422.         return 0;
  423.     else if (*cp == '/' || *cp == '!' || *cp == ':')
  424.         *cp = '.';
  425.     else
  426.         *cp = ToLower(*cp);
  427.     }
  428.     if (cp - conf > CONFSIZE)
  429.     conf[CONFSIZE] = '\0';
  430.     sprintf(line, "%s/%s", MSGBASE, conf);
  431.     if (chdir(line) == -1)
  432.         return 0;
  433.     chdir("../..");
  434.     return 1;
  435. }
  436.  
  437. setlconf(conf)
  438. char *conf; {
  439.     char line[256], *p;
  440.  
  441.     if (s_cmp(user.u_name, "guest") == 0) {
  442.         log("Guest SET LOGIN CONF denied.");
  443.         puts("GUEST can't set a login conference.");
  444.         return 1;
  445.     }
  446.     p = conf - 1;
  447.     while (*++p != '\0')
  448.     if (*p == ' ')
  449.         if (isconf(++p)) {
  450.                 if (isunsub(p)) {
  451.                     puts("You're unsubscribed from it.  <J>oin it and resubscribe.");
  452.                     log("Unsubscribed -- login conf set aborted.");
  453.                     return 1;
  454.                 }
  455.         strcpy(user.u_lconf, p);
  456.         log("New login conference: %s", user.u_lconf);
  457.                 putuser(user.u_name, &user);
  458.         return 1;
  459.         }
  460.     do {
  461.     printf("Enter new login conference: ");
  462.     gets(line);
  463.     log("Login conference: %s", line);
  464.     if (line[0] == '\0')
  465.         return 1;
  466.     } while (!isconf(line));
  467.     if (isunsub(line)) {
  468.         puts("You're unsubscribed from it.  <J>oin it and resubscribe.");
  469.         log("Unsubscribed -- login conf set aborted.");
  470.         return 1;
  471.     }
  472.     strcpy(user.u_lconf, line);
  473.     log("New login conference: %s", user.u_lconf);
  474.     putuser(user.u_name, &user);
  475.     return 1;
  476. }
  477.  
  478. uisunsub(user, conf)
  479. char *user, *conf; {
  480.     struct _himsg *hip, *uhi;
  481.     char *cp;
  482.  
  483.     for (cp = user; *cp != '\0'; cp++)
  484.         *cp = ToLower(*cp);
  485.     if ((uhi = readhigh(user)) < 0) {
  486.         log("Couldn't read %s's userindex.", user);
  487.         return 0;
  488.     }
  489.     for (hip = uhi; hip != NULL; hip = hip->hi_next)
  490.         if (strcmp(hip->hi_conf, conf) == 0)
  491.             break;
  492.     cp = (hip != NULL && hip->hi_uns == HI_UNSUB? "!": ":");
  493.     for (hip = uhi->hi_next; uhi != NULL; uhi = hip)
  494.         free((char *) uhi);
  495.     return (*cp == '!');
  496. }
  497.  
  498. cleanhigh() {
  499.     struct _himsg *hip, *lastp;
  500.     DIR *conferences;
  501.     struct direct *conf;
  502.     
  503.     lastp = NULL;
  504.     puts("Checking for deleted conferences...");
  505.     for (hip = hicnts; hip != NULL; lastp = hip, hip = hip->hi_next) {
  506.         if (!isconf(hip->hi_conf)) {
  507.             printf("Conference \"%s\" was deleted since your last session.\n", hip->hi_conf);
  508.             if (lastp == NULL)
  509.                 hicnts = hip->hi_next;
  510.             else
  511.                 lastp->hi_next = hip->hi_next;
  512.             free((char *) hip);
  513.         }
  514.     }
  515.     puts("\nChecking for new conferences...");
  516.     if ((conferences = opendir(MSGBASE)) == NULL) {
  517.         log("Error %d opening dir %s/", errno, MSGBASE);
  518.         panic("msgdir");
  519.     }
  520.     while ((conf = readdir(conferences)) != NULL) {
  521.         if (strcmp(conf->d_name, ".") == 0)
  522.             continue;
  523.         if (strcmp(conf->d_name, "..") == 0)
  524.             continue;
  525.         for (hip = hicnts; hip != NULL; hip = hip->hi_next)
  526.             if (strcmp(hip->hi_conf, conf->d_name) == 0)
  527.                 break;
  528.         if (hip == NULL)
  529.             printf("Conference \"%s\" has been created since your last session.\n", conf->d_name);
  530.     }
  531.     closedir(conferences);
  532. }
  533.