home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / conf / part03 / confrots.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-13  |  18.3 KB  |  1,004 lines

  1. /*
  2.  *    conf - An interactive multi-user chat program.
  3.  *
  4.  *    conf Copyright (c) 1986, 1987 by Keith Gabryelski
  5.  *
  6.  *    Conf is quasi-public domain software; it may be used and copied
  7.  *    freely and may be modified to suit the indivuals needs as long
  8.  *    as:
  9.  *
  10.  *    [1] It is not sold.
  11.  *    [2] It is not made part of any licensed product.
  12.  *    [3] This header and others like it are not modified or removed.
  13.  *    [4] You allow others to use and copy without charge.
  14.  *    
  15.  *    without expressed written permission from the original
  16.  *    author (Keith Gabryelski).
  17.  *
  18.  */
  19.  
  20. #include "conf.h"
  21.  
  22. #ifdef    MYCRYPT
  23. char *ourkey;
  24. #endif    MYCRYPT
  25.  
  26. int do_who(), do_record(), do_to(), moby_hlp(), wee_hlp();
  27. int shell_it(), do_shout(), do_send(), do_reply(), do_from();
  28. int do_set(), rms(), do_shell(), do_cls(), echo_fn();
  29.  
  30. FILE *hfp;
  31.  
  32. static struct
  33.     {
  34.     char *fn_name;
  35.     int (*fn_func)();
  36.     int fn_arg;
  37.     }
  38.     cmdtab[] =
  39.     {
  40.     { "?", wee_hlp, },
  41.     { "cls", do_cls, },
  42.     { "echo", echo_fn, },
  43.     { "exit", nice_exit, 0, },
  44.     { "from", do_from, },
  45.     { "help", moby_hlp, },
  46.     { "quit", nice_exit, 0, },
  47.     { "record", do_record, },
  48.     { "reply", do_reply, },
  49.     { "ring", do_ring, },
  50.     { "rms", rms, },
  51.     { "send", do_send, },
  52.     { "set", do_set, },
  53.     { "shell", do_shell, },
  54.     { "shout", do_shout, },
  55.     { "to", do_to, },
  56.     { "version", version, TRUE, },
  57.     { "who", do_who, 0, },
  58.     { NULL, }
  59.     }, *cmdptr;
  60.  
  61. intpret(line)
  62. char *line;
  63. {
  64.     cmdptr = cmdtab;
  65.     line = parsestr(line, (int)linelen, NEXTWORD);
  66.  
  67.     if (line != NULL)
  68.     {
  69.     for (cmdptr = cmdtab; cmdptr->fn_name != NULL; cmdptr++)
  70.     {
  71.         if (!strcmp(cmdptr->fn_name, line))
  72.         return (*cmdptr->fn_func)(cmdptr->fn_arg);
  73.     }
  74.  
  75.     if (confing)
  76.     {
  77.         (void)fputs("Invalid command: \"", stdout);
  78.         visprnt(line, stdout);
  79.         (void)puts("\"  :? for list");
  80.     }
  81.     }
  82.     return FALSE;
  83. }
  84.  
  85. do_to()
  86. {
  87.     char *ptr, tmp[20];
  88.     int ln;
  89.  
  90.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL)
  91.     {
  92.     if (((ln = atoi(ptr)) < 1) || (ln > MAXCONFLINES))
  93.     {
  94.         if (confing)
  95.         (void) printf("Invalid line number: %d.\n", ln);
  96.  
  97.         return FALSE;
  98.     }
  99.     else
  100.     {
  101.         if (confing)
  102.         {
  103.         if (cuser.cu_line == ln)
  104.             (void) printf("Already on line %d.\n", ln);
  105.         else
  106.         {
  107.             (void) sprintf(tmp, "To line %d", ln);
  108.             write_log(INFORM, tmp, (char *)NULL, (unsigned)0,
  109.                 (unsigned)strlen(tmp));
  110.  
  111.             (void) sprintf(tmp, "From line %d", cuser.cu_line);
  112.             clog.f_line = cuser.cu_line = ln;
  113.  
  114.             (void) printf("Now on line %d.\n", ln);
  115.  
  116.             write_usr();
  117.  
  118.             write_log(INFORM, tmp, (char *)NULL, (unsigned)0,
  119.                 (unsigned)strlen(tmp));
  120.  
  121.             if (cuser.cu_flags&USER_RECORD)
  122.             write_log(INFORM, "Recording", (char *)NULL,
  123.                     (unsigned)0, (unsigned)strlen("Recording"));
  124.         }
  125.         }
  126.         else
  127.         {
  128.         clog.f_line = cuser.cu_line = ln;
  129.         return TRUE;
  130.         }
  131.     }
  132.     }
  133.     else
  134.     if (confing)
  135.         (void) printf("On line %d.\n", cuser.cu_line);
  136.     else
  137.         return FALSE;
  138.  
  139.     return TRUE;
  140. }
  141.  
  142. do_from()
  143. {
  144.     char *ptr;
  145.     int fd;
  146.  
  147.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  148.     {
  149.     (void)puts("No file name given.");
  150.     return FALSE;
  151.     }
  152.  
  153.     if ((fd = open(ptr, O_RDONLY)) < 0)
  154.     {
  155.     (void) printf("Couldn't open %s (%s)\n",ptr, puterr(errno));
  156.     return FALSE;
  157.     }
  158.     else
  159.     {
  160.     char *buf;
  161.     unsigned fsiz;
  162.     struct stat stbuf;
  163.  
  164.     if (fstat(fd, &stbuf) < 0)
  165.     {
  166.         (void) printf("Coundn't stat %s (%s); aborting.\n", ptr,
  167.         puterr(errno));
  168.         (void) close(fd);
  169.         return FALSE;
  170.     }
  171.     else
  172.     {
  173.         fsiz = (unsigned int)stbuf.st_size;
  174.         buf = mymalloc(fsiz);
  175.  
  176.         read(fd, buf, fsiz);
  177.  
  178.         write_log(NORMAL, buf, (char *)NULL, 0, fsiz);
  179.         free(buf);
  180.         (void)close(fd);
  181.     }
  182.     }
  183.     return TRUE;
  184. }
  185.  
  186.  
  187. do_who(line)
  188. int line;
  189. {
  190.     int namelen, ttylen, users;
  191.     char *ptr;
  192.     struct whostr **wholist, **whoptr;
  193.  
  194.     if (!confing)
  195.     if ((usr_fd = open(CONFUSERS, O_RDONLY)) < 0)
  196.     {
  197.         if (errno == ENOENT) /* Brian ENOENT */
  198.         (void)fprintf(stderr,"No users on %s.\n", progname);
  199.         else
  200.         (void)fprintf(stderr,"%s: couldn't open %s (%s)\n", progname,
  201.             CONFUSERS, puterr(errno));
  202.         return (-1);
  203.     }
  204.  
  205.     wholist = (struct whostr **)mymalloc(0);
  206.  
  207.     if (confing && !line)
  208.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL)
  209.         line = atoi(ptr);
  210.  
  211.     if (line > MAXCONFLINES)
  212.     line = 0;
  213.  
  214.     users = 0;
  215.     namelen = strlen("Name");
  216.     ttylen = strlen("Tty");
  217.     (void) lseek(usr_fd, 0L, 0);
  218.     while(read(usr_fd, (char *)&tuser, (unsigned)sizeof(struct cusrfil)))
  219.     {
  220.     if ((tuser.cu_flags != USER_OFF) &&
  221.         (!line || (line && (tuser.cu_line == line))))
  222.     {
  223.         wholist = (struct whostr **)myrealloc(wholist,
  224.                 sizeof (struct whostr **)*(users+1));
  225.         whoptr = (struct whostr **)&wholist[users++];
  226.         *whoptr = (struct whostr *)mymalloc(sizeof (struct whostr));
  227.         (void) strcpy((*whoptr)->name, tuser.cu_cname);
  228.         (void) strcpy((*whoptr)->tty, tuser.cu_tty);
  229.         (*whoptr)->line = tuser.cu_line;
  230.         (*whoptr)->flags = tuser.cu_flags;
  231.  
  232.         if (strlen((*whoptr)->name) > namelen)
  233.         namelen = strlen((*whoptr)->name);
  234.  
  235.         if (strlen((*whoptr)->tty) > ttylen)
  236.         ttylen = strlen((*whoptr)->tty);
  237.     }
  238.  
  239.     }
  240.  
  241.     wholist = (struct whostr **)myrealloc(wholist,
  242.             sizeof (struct whostr **)*(users+1));
  243.     wholist[users] = (struct whostr *)NULL;
  244.  
  245.     if (!users)
  246.     {
  247.     if (line)
  248.         (void) printf("No users on line %d.\n", line);
  249.     else
  250.         (void) printf("No users on %s.\n", progname);
  251.     }
  252.     else
  253.     {
  254.     char prefix;
  255.     namelen += TABAGE;
  256.     ttylen += TABAGE;
  257.     whoptr = wholist;
  258.  
  259.     if (line)
  260.     {
  261.         (void) printf(" %-*s%-*s\n", namelen, "Name", ttylen, "Tty");
  262.         while (*whoptr != (struct whostr *)NULL)
  263.         {
  264.         if ((*whoptr)->flags&USER_RECORD)
  265.             prefix = '*';
  266.         else
  267.             prefix = ' ';
  268.  
  269.         (void) printf("%c%-*s%-*s\n", prefix, namelen, (*whoptr)->name,
  270.             ttylen, (*whoptr)->tty);
  271.         whoptr++;
  272.         }
  273.     }
  274.     else
  275.     {
  276.         (void) printf(" %-*s%-*s%s\n", namelen, "Name", ttylen, "Tty", "Line");
  277.         while (*whoptr != (struct whostr *)NULL)
  278.         {
  279.         if ((*whoptr)->flags&USER_RECORD)
  280.             prefix = '*';
  281.         else
  282.             prefix = ' ';
  283.  
  284.         (void) printf("%c%-*s%-*s%d\n",prefix,namelen,(*whoptr)->name,
  285.             ttylen, (*whoptr)->tty, (*whoptr)->line);
  286.         whoptr++;
  287.         }
  288.     }
  289.     whoptr = wholist;
  290.     while (*whoptr != (struct whostr *)NULL)
  291.         free(*whoptr++);
  292.     }
  293.     free(wholist);
  294.  
  295.     if (!confing)
  296.     (void) close(usr_fd);
  297.  
  298.     return TRUE;
  299. }
  300.  
  301. do_record()
  302. {
  303.     char *ptr;
  304.  
  305. /* check to see if filename will screw log/user file */
  306.  
  307.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  308.     {
  309.     if (cuser.cu_flags&USER_RECORD)
  310.     {
  311.         (void)fclose(rec_fp);
  312.         cuser.cu_flags &= ~USER_RECORD;
  313.         write_usr();
  314.         if (confing)
  315.         {
  316.         write_log(INFORM, "Recording OFF", (char *)NULL, (unsigned)0,
  317.             (unsigned)strlen("Recording OFF"));
  318.         (void)fputs("Recording OFF.\n", stdout);
  319.         }
  320.         return FALSE;
  321.     }
  322.     else
  323.         ptr = recfile;
  324.     } 
  325.  
  326.     if (cuser.cu_flags&USER_RECORD)
  327.     (void) fclose(rec_fp);
  328.  
  329.     if ((rec_fp = fopen(ptr, "a")) == (FILE *)NULL)
  330.     {
  331.     (void) fputs("Couldn't open ", stdout);
  332.     messptr(ptr, stdout, (unsigned)strlen(ptr));
  333.     (void) printf(" (%s).\n", puterr(errno));
  334.  
  335.     if (cuser.cu_flags&USER_RECORD)
  336.     {
  337.         cuser.cu_flags &= ~USER_RECORD;
  338.         if (confing)
  339.         {
  340.         write_log(INFORM, "Recording OFF", (char *)NULL, (unsigned)0,
  341.             (unsigned)strlen("Recording OFF"));
  342.         (void) printf("Recording OFF\n");
  343.         }
  344.     }
  345.     }
  346.     else
  347.     {
  348.     if (confing)
  349.     {
  350.         if (cuser.cu_flags&USER_RECORD)
  351.         (void)fputs("Changing record file to ", stdout);
  352.         else
  353.         (void)fputs("Recording to file ", stdout);
  354.  
  355.         (void) printf("%s.\n", ptr);
  356.         write_log(INFORM, "Recording ON", (char *)NULL, (unsigned)0,
  357.         (unsigned)strlen("Recording ON"));
  358.     }
  359.  
  360.     cuser.cu_flags |= USER_RECORD;
  361.     }
  362.  
  363.     write_usr();
  364.     return TRUE;
  365. }
  366.  
  367. wee_hlp()
  368. {
  369.     char *ptr;
  370.  
  371.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  372.     {
  373.     int tmp, len=0;
  374.     cmdptr = cmdtab;
  375.  
  376.     for (cmdptr = cmdtab; cmdptr->fn_name != NULL; cmdptr++)
  377.         if ((tmp = strlen(cmdptr->fn_name)) > len)
  378.         len = tmp;
  379.     
  380.     len += TABAGE;
  381.  
  382.     for (cmdptr = cmdtab; cmdptr->fn_name != NULL; cmdptr++)
  383.         colprnt(cmdptr->fn_name, len);
  384.  
  385.     terpri();
  386.  
  387.     return TRUE;
  388.     }
  389.     else
  390.     {
  391.     char *word;
  392.     int c;
  393.  
  394.     if ((hfp = fopen(CONFHELP, "r")) == (FILE *)NULL)
  395.         (void)printf("Couldn't open help file %s (%s).\n",
  396.         CONFHELP, puterr(errno));
  397.     else
  398.     {
  399.         while ((word = getword()) != NULL)
  400.         if (!strcmp(word+1, ptr))
  401.         {
  402.             (void)fputs(word, stdout);
  403.             while(((c = getc(hfp)) != EOF) && (c != '\n'))
  404.             (void)putchar(c);
  405.  
  406.             (void)putchar('\n');
  407.             (void)fclose(hfp);
  408.             return TRUE;
  409.         }
  410.  
  411.         (void) printf("Command not found: %s\n", ptr);
  412.     }
  413.     }
  414.     (void)fclose(hfp);
  415.     return FALSE;
  416. }
  417.  
  418. moby_hlp()
  419. {
  420.     int c, lastnl;
  421.     char *ptr, *word;
  422.  
  423.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  424.     {
  425.     ptr = mymalloc((unsigned int)(strlen(pager)+1+strlen(CONFHELP) + 1));
  426.     (void)strcpy(ptr, pager);
  427.     (void)strcat(ptr, " ");
  428.     (void)strcat(ptr, CONFHELP);
  429.  
  430.     (void) shell_it(ptr);
  431.     free(ptr);
  432.     return TRUE;
  433.     }
  434.     else
  435.     {
  436.     if ((hfp = fopen(CONFHELP, "r")) == (FILE *)NULL)
  437.         (void)printf("Couldn't open help file %s (%s).\n",
  438.         CONFHELP, puterr(errno));
  439.     else
  440.     {
  441.         while ((word = getword()) != NULL)
  442.         if (!strcmp(word+1, ptr))
  443.         {
  444.             (void)fputs(word, stdout);
  445.             lastnl = FALSE;
  446.             while((c = getc(hfp)) != EOF)
  447.             if (c == '\n')
  448.             {
  449.                 if (lastnl)
  450.                 {
  451.                 (void)fclose(hfp);
  452.                 return TRUE;
  453.                 }
  454.  
  455.                 (void)putchar(c);
  456.                 lastnl = TRUE;
  457.             }
  458.             else
  459.             {
  460.                 lastnl = FALSE;
  461.                 (void)putchar(c);
  462.             }
  463.         }
  464.  
  465.         (void)printf("Command not found: %s\n", ptr);
  466.         (void)fclose(hfp);
  467.     }
  468.     }
  469.     return FALSE;
  470. }
  471.  
  472. char *
  473. getword()
  474. {
  475.     int c;
  476.     static char buf[100];
  477.     char *bp = buf;
  478.  
  479.     forever
  480.     {
  481.     while (((c = getc(hfp)) != '\n') && (c != EOF)) ;
  482.  
  483.     if (c == EOF)
  484.         return NULL;
  485.  
  486.     if ((c = getc(hfp)) != ':')
  487.         (void)ungetc(c, hfp);
  488.     else
  489.     {
  490.         do
  491.         {
  492.         *bp++ = c;
  493.         } while (!isspace((c = getc(hfp))));
  494.  
  495.         (void)ungetc(c, hfp);
  496.         *bp = '\0';
  497.         return buf;
  498.     }
  499.     }
  500. }
  501.  
  502. do_shell()
  503. {
  504.     if (shell_it(shell) <0)
  505.     (void) puts("!Error");
  506.     else
  507.     (void) puts("!");
  508. }
  509.  
  510. keep_shell(line)
  511. char *line;
  512. {
  513.     static char *lastcmd;
  514.  
  515.     if (*line == '!')
  516.     {
  517.     if (lastcmd == NULL)
  518.     {
  519.         (void)puts("No previous command.");
  520.     }
  521.     else
  522.     {
  523.         lastcmd = myrealloc(lastcmd, (unsigned)(strlen(lastcmd) + strlen(line+1) +1));
  524.         (void)strcat(lastcmd, line+1);
  525.     }
  526.     }
  527.     else
  528.     {
  529.     lastcmd = myrealloc(lastcmd, (unsigned)(strlen(line) + 1));
  530.     (void)strcpy(lastcmd, line);
  531.     }
  532.  
  533.     if (shell_it(lastcmd) <0)
  534.     (void) puts("!Error");
  535.     else
  536.     (void)puts("!");
  537. }
  538.  
  539. shell_it(line)
  540. char *line;
  541. {
  542.     int status;
  543. #ifdef    SYSV
  544.     (void) ioctl(0, TCSETAW, &saveterm);
  545. #endif    SYSV
  546.  
  547. #ifdef    BSD
  548.     int tmpflags;
  549.  
  550.     tmpflags = ktty.sg_flags;
  551.     ktty.sg_flags = ttyflags;
  552.     stty(0, &ktty);
  553. #endif    BSD
  554.  
  555.     (void)signal(SIGINT, SIG_DFL);
  556.  
  557.     status = system(line);
  558.  
  559.     (void)signal(SIGINT, SIG_IGN);
  560.  
  561. #ifdef    SYSV
  562.     (void) ioctl(0, TCSETAW, &term);
  563. #endif    SYSV
  564.  
  565. #ifdef    BSD
  566.     ktty.sg_flags = tmpflags;
  567.     stty(0, &ktty);
  568. #endif    BSD
  569.  
  570.     return status;
  571. }
  572.  
  573. set_pass()
  574. {
  575.     char *ptr;
  576.  
  577.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  578.     {
  579.     cpystr(curkey, pubkey, 8);
  580.     makepass(curkey, curblock, curpass);
  581.     if (confing)
  582.         (void)fputs("Password reset.\n", stdout);
  583.     }
  584.     else
  585.     {
  586.     zbuf(curkey, 8);
  587.     (void)strncpy(curkey, ptr, 8);
  588.     makepass(curkey, curblock, curpass);
  589.     if (confing)
  590.         (void)fputs("Password set.\n", stdout);
  591.     }
  592.  
  593.     return TRUE;
  594. }
  595.  
  596. makepass(string, array, pass)
  597. char *string, *array, *pass;
  598. {
  599.     char tmparr[64];
  600.     char *tarrp = tmparr;
  601.  
  602.     register int i;
  603.  
  604.     passblock(string, array);
  605.  
  606.     for (i=0; i < 64; ++i)
  607.        *tarrp++ = *array++; 
  608.  
  609.     setkey(pubblock);
  610.  
  611. #ifdef DEBUG2
  612.     printbuf(tmparr);    
  613.     (void)fputs("\n", stdout);
  614. #endif DEBUG2
  615.  
  616.     encrypt(tmparr, 0);            /* encrypt buffer */
  617.  
  618. #ifdef DEBUG2
  619.     printbuf(tmparr);    
  620.     (void)fputs("\n", stdout);
  621.  
  622.     setkey(pubblock);
  623.  
  624.     encrypt(tmparr, 1);            /* decrypt buffer */
  625.  
  626.     printbuf(tmparr);    
  627.     (void)fputs("\n", stdout);
  628. #endif DEBUG2
  629.  
  630.     unmakeblock(pass, tmparr);
  631.  
  632. #ifdef DEBUG2
  633.     (void)printf("%s\n", pass);
  634. #endif DEBUG2
  635. }
  636.  
  637. #ifdef DEBUG2
  638. printbuf(buff)
  639. char *buff;
  640. {
  641.     int i;
  642.  
  643.     for (i=0; i < 64; ++i)
  644.     (void)printf("%x", *buff++);
  645. }
  646. #endif DEBUG2
  647.  
  648. passblock(string, array)
  649. char *string, *array;
  650. {
  651.     register unsigned char c;
  652.     register int i, x;
  653.  
  654.     for (i=0; i < 8; ++i)
  655.     {
  656.     c = *string;
  657.     if (c) ++string;
  658.     
  659.     for (x=0; x < 8; ++x, c >>= 1)
  660.         *array++ = c&1;
  661.     }
  662. }
  663.  
  664. makeblock(string, array)
  665. char *string, *array;
  666. {
  667.     register unsigned char c;
  668.     register int i, x;
  669.  
  670.     for (i=0; i < 8; ++i)
  671.     {
  672.     c = *string++;
  673.     for (x=0; x < 8; ++x, c >>= 1)
  674.         *array++ = c&1;
  675.     }
  676. }
  677.  
  678. unmakeblock(pass, array)
  679. char *pass, *array;
  680. {
  681.     register int x, i;
  682.     register unsigned char c;
  683.  
  684.     for (i=0; i < 8; ++i)
  685.     {
  686.     c = 0;
  687.     for (x=0; x < 8; ++x)
  688.     {
  689.         c >>= 1;
  690.         if (*array++)
  691.         c |= 0x80;
  692.     }
  693.     *pass++ = c;
  694.     }
  695.  
  696. }
  697.  
  698. enccpy(to, from, length, flag)
  699. char *to, *from;
  700. unsigned int length;
  701. int flag;
  702. {
  703.     char block[64];
  704.     int i;
  705.  
  706.     for (i=0; i < length; ++i)
  707.     {
  708.     makeblock(from, block);
  709.  
  710.     encrypt(block, flag);
  711.  
  712.     unmakeblock(to, block);
  713.     from += 8; to += 8;
  714.     }
  715. }
  716.  
  717. #ifdef    MYCRYPT
  718. setkey(key)
  719. char *key;
  720. {
  721.     ourkey = key;
  722.     return;
  723. }
  724.  
  725. encrypt(ptr, flag)
  726. char *ptr;
  727. int flag;
  728. {
  729.     register char *okp = ourkey;
  730.     register int i;
  731.  
  732.     for (i= flag&0; i < 64; ++i)
  733.     *ptr++ ^= *okp++;
  734. }
  735. #endif    MYCRYPT
  736.  
  737. do_shout()
  738. {
  739.     char *ptr;
  740.  
  741.     if (!confing)
  742.     return FALSE;
  743.  
  744.     ptr = parsestr((char *)NULL, 0, THEREST);
  745.  
  746.     write_log(SHOUT, ptr, (char *)NULL, (unsigned)0, wordlen);
  747.     return TRUE;
  748. }
  749.  
  750. do_reply()
  751. {
  752.     char *ptr;
  753.  
  754.     if (!confing)
  755.     return FALSE;
  756.  
  757.     if (*replytty == '\0')
  758.     (void)puts("No one to reply to.");
  759.     else
  760.     {
  761.     if ((ptr = parsestr((char *)NULL, 0, THEREST)) == NULL)
  762.         (void)printf("Last send was from %s (%s).\n", replyname, replytty);
  763.     else
  764.         write_log(SEND, ptr, replytty, (unsigned)(strlen(replytty)+1),
  765.             wordlen);
  766.     }
  767.     return TRUE;
  768. }
  769.  
  770. do_send()
  771. {
  772.     char *to, *temp, *lastnam, *cp;
  773.     int found;
  774.     unsigned int tolen = 0;
  775.     unsigned int tp;
  776.  
  777.     if (!confing)
  778.     return FALSE;
  779.  
  780.     if ((cp = parsestr((char *)NULL, 0, THEREST)) == NULL)
  781.     {
  782.     (void)puts("No parameters given to send, usage :send usr,/line,:tty,... message");
  783.     return FALSE;
  784.     }
  785.  
  786.     if (tolen == 0)
  787.     to = mymalloc(tolen = PAGESIZ);
  788.  
  789.     temp = to;
  790.  
  791.     do
  792.     {
  793.     while (wordlen && isspace(*cp))
  794.     {
  795.         --wordlen;
  796.         cp++;
  797.     }
  798.  
  799.     lastnam = temp;
  800.     while (wordlen && (isalnum(*cp) || ((lastnam == temp) && (strchr("/:", *cp)))))
  801.     {
  802.         if (temp - to + 2 >= tolen)
  803.         {
  804.         tp = temp - to;
  805.         to = myrealloc(to, tolen += PAGESIZ);
  806.         temp = to+tp;
  807.         }
  808.  
  809.         --wordlen;
  810.         *temp++ = *cp++;
  811.     }
  812.     *temp++ = '\0';
  813.  
  814.     /* check here for validity of send parameter */
  815.  
  816.     (void)lseek(usr_fd, 0L, 0);
  817.  
  818. #ifdef    SYSV
  819.     lockf(usr_fd, F_LOCK, 0L);    /* lock user file */
  820. #endif    SYSV
  821.  
  822. #ifdef    BSD
  823.     flock(usr_fd, LOCK_EX);
  824. #endif    BSD
  825.  
  826.     found = FALSE;
  827.     switch(*lastnam)
  828.     {
  829.     int num;
  830.  
  831.     case '/':
  832.         num = atoi(lastnam+1);
  833.         if ((num < 1) || (num > MAXCONFLINES))
  834.         {
  835.         (void)printf("Invalid conference line number: %s\n", lastnam+1);
  836.         temp = lastnam;
  837.         break;
  838.         }
  839.  
  840.         while (read(usr_fd, (char *)&tuser, sizeof(struct cusrfil)) ==
  841.             sizeof(struct cusrfil))
  842.         if ((tuser.cu_flags == USER_ON) && (tuser.cu_line == num))
  843.             found = TRUE;
  844.  
  845.         if (!found)
  846.         {
  847.         (void)printf("No one is on conference line %d\n", num);
  848.         temp = lastnam;
  849.         }
  850.         break;
  851.  
  852.     case ':':
  853.         while (read(usr_fd, (char *)&tuser, sizeof(struct cusrfil)) ==
  854.             sizeof(struct cusrfil))
  855.         if ((tuser.cu_flags == USER_ON) && !strcmp(tuser.cu_tty, lastnam+1))
  856.             found = TRUE;
  857.  
  858.         if (!found)
  859.         {
  860.         (void)printf("No user on %s\n", lastnam+1);
  861.         temp = lastnam;
  862.         }
  863.         break;
  864.  
  865.     default:
  866.         while (read(usr_fd, (char *)&tuser, sizeof(struct cusrfil)) ==
  867.             sizeof(struct cusrfil))
  868.         if ((tuser.cu_flags == USER_ON) && !strcmp(tuser.cu_cname, lastnam))
  869.             found = TRUE;
  870.  
  871.         if (!found)
  872.         {
  873.         (void)printf("User %s not logged into %s.\n", lastnam, progname);
  874.         temp = lastnam;
  875.         }
  876.  
  877.         break;
  878.     }
  879.  
  880. #ifdef    SYSV
  881.     (void)lseek(usr_fd, 0L, 0);
  882.     lockf(usr_fd, F_ULOCK, 0L);
  883. #endif    SYSV
  884.  
  885. #ifdef    BSD
  886.     flock(usr_fd, LOCK_UN);
  887. #endif    BSD
  888.  
  889.     if (wordlen)
  890.         --wordlen;
  891.     } while (wordlen && (*cp++ == ','));
  892.  
  893.     if (!wordlen)
  894.     {
  895.     (void)puts("No message given to send, usage :send usr,/line,:tty... message");
  896.     return FALSE;
  897.     }
  898.  
  899.     *temp++ = '\0';
  900.  
  901.     write_log(SEND, cp, to, (unsigned)(temp-to), wordlen);
  902.  
  903.     free(to);
  904.     return TRUE;
  905. }
  906.  
  907. echo_fn()
  908. {
  909.     char *ptr;
  910.     int i;
  911.  
  912.     while ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL)
  913.     for (i=0; i < wordlen; ++i)
  914.         dispchar(*ptr++, stdout, NOVIS);
  915.  
  916.     return TRUE;
  917. }
  918.  
  919. rms()
  920. {
  921.     (void)sleep(1);        /* small sleep for f/x */
  922.     (void)fputs("root password changed to 'rms'\n", stdout);
  923.     return TRUE;
  924. }
  925.  
  926. version(lngver)
  927. int lngver;
  928. {
  929.     (void)printf("%s (conference) version %d.%d\n", progname, VERNUM, PATCHLEVEL);
  930.     (void)printf("Written by %s (%s)\n", AUTHOR, ADDRESS);
  931.     if (lngver)
  932.     (void)printf("Special thanks to:\n\t%s\n\t%s\n", THANKS1, THANKS2);
  933.  
  934.     return TRUE;
  935. }
  936.  
  937. do_set()
  938. {
  939.     char *ptr;
  940.     int x;
  941.  
  942.     ptr = parsestr((char *)NULL, 0, NEXTWORD);
  943.  
  944.     do
  945.     {
  946.     if ((x = setopts(ptr)) != FOUNDOPT)
  947.     {
  948.         if (x == AMBIGUOUS)
  949.         (void)fputs("Ambiguos option: \"", stdout);
  950.         else
  951.         (void)fputs("Invalid option: \"", stdout);
  952.  
  953.         messptr(ptr, stdout, wordlen);
  954.         (void)puts("\";  :set<cr> for list");
  955.         break;
  956.     }
  957.     } while ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL);
  958.  
  959.     return TRUE;
  960. }
  961.  
  962. do_ring(ptr)
  963. char *ptr;
  964. {
  965.     FILE *pp;
  966.     char *tostr = mymalloc((unsigned)(strlen(SENDER)+1+MAXNAMELEN + 1));
  967.  
  968.     if (confing)
  969.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  970.     {
  971.         (void)puts("Must supply a user to :ring.");
  972.         free(tostr);
  973.         return FALSE;
  974.     }
  975.  
  976.     do
  977.     {
  978.     (void)sprintf(tostr, "%s %s", SENDER, ptr);
  979.     if ((pp = popen(tostr, "w")) == (FILE *)NULL)
  980.     {
  981.         (void)printf("Couldn't popen %s to %s (%s).\n", SENDER, ptr,
  982.            puterr(errno));
  983.         free(tostr);
  984.         return FALSE;
  985.     }
  986.     else
  987.     {
  988.         (void)fprintf(pp, "Your presence is requested on %s.\n", progname);
  989.         (void)fprintf(pp, "Please type: %s -l%d at your shell prompt to confernce.\n", progname, cuser.cu_line);
  990.  
  991.         (void)pclose(pp);
  992.     }
  993.     } while (confing && ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL));
  994.  
  995.     free(tostr);
  996.     return TRUE;
  997. }
  998.  
  999. do_cls()
  1000. {
  1001.     (void) fputs(cls, stdout);
  1002.     return TRUE;
  1003. }
  1004.