home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / unaxcess / part3 / ua.c next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  8.4 KB  |  362 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. struct cmd
  14.     {
  15.     char c_ch;                /* command character */
  16.     char c_desc[33];            /* command description */
  17.     int (*c_exec)();            /* command executive */
  18.     }
  19.     ;                    /* used for command array */
  20.  
  21. /* forward references for command executives */
  22.  
  23. extern int
  24.     readmsg(),    readnew(),    confidx(),    enter(),
  25.     join(),        killmsg(),    helpme(),    scanmsg(),
  26.     logout(),    bulletin(),    linelen(),    shell(),
  27.     userctl(),    userlist(),    qscan(),    udl(),
  28.     unsub(),    setlconf();
  29.  
  30. struct cmd cmdt[] =
  31.     {
  32.     '?', "Print help messages",            helpme,
  33.     'a', "Alter or examine a user",        userctl,
  34.     'b', "Reprint login bulletins",        bulletin,
  35.     'c', "Shell command access",        shell,
  36.     'd', "Set default login conference",    setlconf,
  37.     'e', "Enter a message",            enter,
  38.     'f', "File area (Downloading)",        udl,
  39.     'g', "Exit UNaXcess",            logout,
  40.     'h', "Print help messages",            helpme,
  41.     'i', "Index of conferences",        confidx,
  42.     'j', "Join a new conference",        join,
  43.     'k', "Kill a message",            killmsg,
  44.     'l', "Set line length",            linelen,
  45.     'n', "Read all new messages",        readnew,
  46.     'q', "Quick scan of messages",        qscan,
  47.     'r', "Read messages in a conference",    readmsg,
  48.     's', "Scan messages",            scanmsg,
  49.     'u', "Unsubscribe from a conference",    unsub,
  50.     'w', "List of UNaXcess users",        userlist,
  51.     NULL,NULL,                    NULL
  52.     };
  53.  
  54. int nopause;
  55. jmp_buf cmdloop;
  56.  
  57. main(argc, argv)
  58.     char **argv;
  59.     {
  60.     char line[256], *lp;
  61.     short lcnt;
  62.     FILE *tp;
  63.  
  64.     getparms();
  65.     chdir(parms.ua_home);
  66.     logon();
  67.     if (parms.ua_hco == 1) {
  68.         printf("\nDo you wish me to stop every few lines to let you read messages (Y)? ");
  69.         gets(line);
  70.         log("Pause? %s", line);
  71.     }
  72.     if (parms.ua_hco == 0 || (parms.ua_hco == 1 && ToLower(line[0]) != 'n'))
  73.         nopause = 0;
  74.     else
  75.         nopause = 1;
  76.     alarm(parms.ua_tlimit * 60);        /* time limit */
  77.     signal(SIGINT, SIG_IGN);
  78.     signal(SIGQUIT, quit);
  79.     for (lcnt = 4; lcnt < SIGUSR1; lcnt++)    /* we don't muck with others */
  80.     signal(lcnt, logsig);
  81.     signal(SIGALRM, thatsall);
  82.     if (parms.ua_bnr[0] == '\0')
  83.     puts("\nWelcome to UNaXcess Version 0.04.03 (pre-release)\nCopyright (C) 1984, 1985 by Brandon Allbery");
  84.     else
  85.         cat(parms.ua_bnr);
  86.     if (argc > 2)
  87.     {
  88.     puts("To run UNaXcess from the shell, type `ua' or `ua username'.\nIf username has spaces or shell metacharacters in it, quote it.\n");
  89.     log("Invoked with %d arguments.  Goodbye.", argc);
  90.     exit(1);
  91.     }
  92.     else
  93.     argc--;
  94.     if (parms.ua_bbs[0] != '\0' && strcmp(getlogin(), parms.ua_bbs) == 0) {
  95.  
  96. nouser:
  97.         for (lcnt = 0; lcnt != 3; lcnt++) {
  98.          if (argc) {
  99.             strcpy(line, argv[1]);
  100.                 argc--;
  101.             putchar('\n');
  102.          }
  103.         else {
  104.                 if (parms.ua_login[0] == 0)
  105.                 printf("\nEnter your user name, GUEST, OFF, or NEW: ");
  106.             else
  107.                 fputs(parms.ua_login, stdout);
  108.             gets(line);
  109.         }
  110.     log("Login: %s", line);
  111.     if (line[0] == '\0')
  112.         {
  113.         lcnt--;
  114.         continue;
  115.         }
  116.     for (lp = line; *lp != '\0'; lp++)
  117.         *lp = ToLower(*lp);
  118.     if (strcmp(line, "off") == 0)
  119.         {
  120.         puts("Goodbye...\n\n");
  121.         log("Logout.");
  122.         exit(0);
  123.         }
  124.     if (!getuser(line, &user))
  125.         {
  126.         printf("No such user.\n");
  127.         log("No such user.");
  128.         }
  129.     else if (user.u_pass[0] != '\0')
  130.         {
  131.         strcpy(line, getpass("Enter your password: "));
  132.         log("Password: %s", line);
  133.         puts("\nChecking password...");
  134.         if (strcmp(crypt(line, line) + 2, user.u_pass) == 0)
  135.         break;
  136.         }
  137.     else
  138.         break;
  139.     }
  140.     if (parms.ua_nla > 0 && lcnt == parms.ua_nla)
  141.     {
  142.     puts("\nSorry, you blew it.");
  143.     log("Program aborted.");
  144.     exit(1);
  145.     }
  146.     }
  147.     else if (!getuser(getlogin(), &user))
  148.         goto nouser;
  149.     log("%s, access = %d, sys = %s, line = %d", user.u_name, user.u_access, user.u_login, user.u_llen);
  150.     if (user.u_access == A_NONE)
  151.     {
  152.     puts("Your access privileges have been revoked.  Goodbye...\n\n");
  153.     log("Security violation:  access revoked.");
  154.     exit(1);
  155.     }
  156.     if ((tp = fopen(RIndex(ttyname(fileno(stdin)), '/') + 1, "w")) == NULL)
  157.     {
  158.     log("Error %d opening %s", errno, RIndex(ttyname(fileno(stdin)), '/') + 1);
  159.     log("Non-interactive session not logged to terminal.");
  160.     }
  161.     else {
  162.     fprintf(tp, "%s on as \"%s\" on %s\n", getlogin(), user.u_name, longdate());
  163.     fclose(tp);
  164.     }
  165.     putchar('\n');
  166.     if (user.u_access != A_MKUSER)
  167.     bulletin(NULL);
  168.     umask(0);                    /* so xedit() works */
  169.     if (user.u_lconf[0] != '\0')
  170.         if (isconf(user.u_lconf))
  171.             strcpy(conference, user.u_lconf);
  172.         else {
  173.             putchar('\n');
  174.             for (lp = parms.ua_sysop; *lp != '\0'; lp++)
  175.                 putchar(ToUpper(*lp));
  176.             printf(" deleted \"%s\", your login conference.  I'm setting you\nback to the \"general\" conference.\n", user.u_lconf);
  177.             user.u_lconf[0] = '\0';
  178.             strcpy(conference, "general");
  179.         }
  180.     else
  181.         strcpy(conference, "general");
  182.     hicnts = readhigh(&user);
  183.     cleanhigh();    /* kill any lingering corpses */
  184.     if (!setjmp(cmdloop))
  185.     signal(SIGINT, intrp);
  186.     while (cmd())
  187.     ;
  188.     printf("Goodbye, ");
  189.     for (lp = user.u_name; *lp != '\0'; lp++)
  190.     putchar(ToUpper(*lp));
  191.     printf(".  Call again soon!\n\n\n");
  192.     log("Logout.");
  193.     cleanup();
  194.     }
  195.  
  196. cleanup()
  197.     {
  198.     char tmps[256];
  199.     FILE *fp;
  200.  
  201.     sprintf(tmps, "%s/himotd", MOTD);
  202.     if ((fp = fopen(tmps, "r")) == NULL)
  203.     {
  204.     log("Error %d opening %s", errno, tmps);
  205.     panic("himotd");
  206.     }
  207.     fgets(tmps, 32, fp);
  208.     fclose(fp);
  209.     user.u_nbull = atoi(tmps);
  210.     putuser(user.u_name, &user);
  211.     unlink(RIndex(ttyname(2), '/') + 1);
  212.     exit(0);
  213.     }
  214.  
  215. cmd()
  216.     {
  217.     char line[256], *p;
  218.     struct cmd *cmdp;
  219.  
  220.     if (user.u_access == A_MKUSER) {
  221.     newuser();
  222.     if (user.u_access == A_NONE) {
  223.         puts("\nYou'll have to be validated before you can use UNaXcess.");
  224.         return 0;
  225.     }
  226.     }
  227.     printf("\n(%s) Command (? = Help): ", conference);
  228.     gets(line);
  229.     log("Command: %s", line);
  230.     if (line[0] == '\0')
  231.     return 1;
  232.     for (p = line; *p != '\0'; p++)
  233.     *p = ToLower(*p);
  234.     for (cmdp = cmdt; cmdp->c_ch != NULL; cmdp++)
  235.     if (ToLower(cmdp->c_ch) == line[0])
  236.         return (*cmdp->c_exec)(line);
  237.     puts("Type '?' for help.");
  238.     log("No such command.");
  239.     return 1;
  240.     }
  241.  
  242. logout()
  243.     {
  244.     char line[256];
  245.  
  246.     printf("Are you sure you want to log out (N)? ");
  247.     gets(line);
  248.     log("Logout? %s", line);
  249.     return (ToLower(line[0]) != 'y');
  250.     }
  251.  
  252. helpme()
  253.     {
  254.     short lcnt;
  255.     struct cmd *cmdp;
  256.  
  257.     putchar('\n');
  258.     lcnt = 2 * ((user.u_llen < 80) + 1);
  259.     for (cmdp = cmdt; cmdp->c_ch != NULL; cmdp++)
  260.     {
  261.     printf("%c - %-32.32s", ToUpper(cmdp->c_ch), cmdp->c_desc);
  262.     lcnt++;
  263.     if (user.u_llen < 80 || !(lcnt % 2))
  264.         putchar('\n');
  265.     if ((lcnt / 2) % (user.u_llen >= 80? 32: 16) == 0)
  266.         if (!cont())
  267.         break;
  268.     }
  269.     if (user.u_llen >= 80 && lcnt % 2 != 0)
  270.         putchar('\n');
  271.     puts("\nIf you need further help, look for (or ask for) a HELP conference.");
  272.     return 1;
  273.     }
  274.  
  275. linelen(s)
  276.     char *s;
  277.     {
  278.     int llen;
  279.     char line[256], *p;
  280.  
  281.     p = s;
  282.     while (*p != '\0')
  283.     if (*p++ == ' ')
  284.         if ((llen = atoi(p)) > 40 && llen < 132)
  285.         {
  286.         printf("New line length = %d.\n", llen);
  287.         user.u_llen = llen;
  288.         putuser(user.u_name, &user);
  289.         return 1;
  290.         }
  291.         else
  292.         break;
  293.     llen = 0;
  294.     while (llen < 40 || llen > 132)
  295.     {
  296.     printf("\nEnter new line length (40-132): ");
  297.     gets(line);
  298.     llen = atoi(line);
  299.     }
  300.     return 1;
  301.     }
  302.  
  303. cont()
  304.     {
  305.     char ch;
  306.  
  307.     if (!isatty(0) || nopause)
  308.     return 1;
  309.     printf("More (Y)? ");
  310.     silent();
  311.     ch = getchar();
  312.     talk();
  313.     log("Cont? %c", ch);
  314.     printf("\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b");
  315.     return (RIndex(" Yy\r\n", ch) != NULL);
  316.     }
  317.  
  318. cat(file)
  319.     char *file;
  320.     {
  321.     FILE *f;
  322.     char ch;
  323.     short lcnt, ccnt;
  324.  
  325.     if ((f = fopen(file, "r")) == NULL)
  326.     {
  327.     log("Error %d opening %s", errno, file);
  328.     puts("Cannot open file.");
  329.     return;
  330.     }
  331.     lcnt = ccnt = 0;
  332.     while ((ch = getc(f)) != EOF)
  333.     {
  334.     if (ch == '\n')
  335.         {
  336.         putchar(ch);
  337.         ccnt = 0;
  338.         if (++lcnt % 16 == 0)
  339.         if (!cont())
  340.             break;
  341.         }
  342.     else if (ch == '\t')
  343.         putchar('\t');
  344.     else
  345.         {
  346.         if (iscntrl(ch))
  347.         putchar('.');
  348.         else
  349.         putchar(ch);
  350.         if (++ccnt == (user.u_llen<40? 80: user.u_llen) - 1)
  351.         {
  352.         ccnt = 0;
  353.         putchar('\n');
  354.         if (++lcnt % 16 == 0)
  355.             if (!cont())
  356.             break;
  357.         }
  358.         }
  359.     }
  360.     fclose(f);
  361.     }
  362.