home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part07 / bbscconf.c < prev    next >
C/C++ Source or Header  |  1992-09-08  |  8KB  |  320 lines

  1. /* Conference Section     05/01/90      */
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <utmp.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include <pwd.h>
  8. #include <signal.h>
  9. #include "bbscdef.h"
  10.  
  11. #ifdef SYSV
  12. #include <dirent.h>
  13. #include <sys/dir.h>
  14. #else
  15. #include <sys/ndir.h>
  16. #endif
  17.  
  18. extern int      no_cntrl_k;
  19. struct stat     thisstat;
  20. char           *getlogin();
  21.  
  22. #ifdef SYSV
  23. #ifndef ESIX54
  24. #define    opendir(path) fopen (path, "r")
  25. #define closedir(dirp) fclose (dirp)
  26. struct dirent  *
  27. readdir(dirp)
  28.     DIR            *dirp;
  29. {
  30.     static struct dirent entry;
  31.     if (dirp == NULL)
  32.     return (NULL);
  33.     for (;;) {
  34.     if (fread(&entry, sizeof(struct dirent), 1, dirp) == 0)
  35.         return (NULL);
  36.     if (entry.d_ino)
  37.         return (&entry);
  38.     }
  39. }
  40. #endif
  41. #endif
  42.  
  43. conf()
  44. {
  45.     int             mypid, loginpid, uid;
  46.     register struct utmp *u;
  47.     extern struct utmp *getutent();
  48.     struct passwd  *getpwuid();
  49.     struct passwd  *pwd;
  50.     char            mybyte;
  51.     char            byten, byter, bytes, bytet;
  52.     char           *bufptr, *myname, *cmf;
  53.     char            buffer[20], my_ext[10];
  54.     char            buffs[99];
  55.     int             length, handle, handlex;
  56.     int             match, sigrets, pidrets, cmpflag;
  57.     FILE           *infile;
  58.     match = 1;
  59.     byten = (char) '\n';
  60.     byter = (char) '\r';
  61.     bytes = (char) ' ';
  62.     mypid = getpid();
  63.     myname = getlogin();
  64.     uid = getuid();
  65.     loginpid = getppid();
  66.     pwd = getpwuid(uid);
  67. /*
  68.      *Check to see if the login name is the same as the present users pw
  69.      * name. If it isn't, let's play around a little and make it work for us!
  70. */
  71.     strcpy(who_am_i, myname);
  72.     strcpy(who_am_I, pwd->pw_name);
  73.     handle = strcmp(who_am_i, who_am_I);
  74.     if (handle != 0)
  75.     match = 0;
  76. /*
  77.      *Flag that we are in conference!
  78. */
  79.     while ((u = getutent()) != NULL) {
  80.     handle = strcmp(u->ut_user, myname);
  81.     if (match) {
  82.         if (handle == 0 && u->ut_pid == mypid) {
  83.         strcpy(my_ext, u->ut_id);
  84.         strcpy(who_am_I, u->ut_line);
  85.         }
  86.     } else {
  87.         if (handle == 0 && u->ut_pid == loginpid) {
  88.         strcpy(my_ext, u->ut_id);
  89.         strcpy(who_am_I, u->ut_line);
  90.         }
  91.     }
  92.     }
  93.     endutent();
  94.     strcpy(who_am_i, "/tmp/conf");
  95.     strcat(who_am_i, my_ext);
  96.     if ((inbuf = fopen(who_am_i, "w")) == NULL) {
  97.     portsout("\n\rError opening flag file!\n\r");
  98.     exit(1);
  99.     }
  100.     fprintf(inbuf, "%s %s %s\n", w_fname, w_lname, who_am_I);
  101.     fclose(inbuf);
  102. /*
  103.      *Flag all users that I just went into conference
  104. */
  105.     strcpy(buf128, "ls /tmp/pid* > /tmp/on.sys.");
  106.     strcat(buf128, my_ext);
  107.     (void) system(buf128);
  108.     strcpy(buf128, "/tmp/on.sys.");
  109.     strcat(buf128, my_ext);
  110.     if ((otbuf = fopen(buf128, "r")) == NULL) {
  111.     portsout("\n\rError opening list file!\n\r");
  112.     exit(1);
  113.     }
  114.     while (fscanf(otbuf, "%s", buffs) != EOF) {
  115.     infile = fopen(buffs, "r");
  116.     cmpflag = strlen(buffs);
  117.     cmf = buffs + cmpflag - 2;
  118.     strcpy(buffer, cmf);
  119.     fgets(buffs, 6, infile);
  120.     fclose(infile);
  121.     pidrets = atoi(buffs);
  122.     if ((sigrets = kill(pidrets, 0)) != 0)
  123.         continue;        /* not valid  */
  124.     setutent();
  125.     cmpflag = 0;
  126.     while ((u = getutent()) != NULL) {
  127.         if (u->ut_pid == pidrets) {
  128.         cmpflag = 1;
  129.         strcpy(buf128, "/dev/");
  130.         strcat(buf128, u->ut_line);
  131.         handle = open(buf128, O_WRONLY);
  132.         sprintf(buf128, "\n\r**** %s %s went into conference ****\n\r", w_fname, w_lname);
  133.         write(handle, buf128, strlen(buf128));
  134.         close(handle);
  135.         }
  136.     }
  137.     endutent();
  138.     if (!cmpflag) {
  139.         setutent();
  140.         while ((u = getutent()) != NULL) {
  141.         cmpflag = strlen(u->ut_line);
  142.         cmf = u->ut_line + cmpflag - 2;
  143.         if ((strcmp(cmf, buffer)) == 0) {
  144.             strcpy(buf128, "/dev/");
  145.             strcat(buf128, u->ut_line);
  146.             handle = open(buf128, O_WRONLY);
  147.             sprintf(buf128, "\n\r**** %s %s went into conference ****\n\r", w_fname, w_lname);
  148.             write(handle, buf128, strlen(buf128));
  149.             close(handle);
  150.         }
  151.         }
  152.         endutent();
  153.     }
  154.     cmpflag = 0;
  155.     }
  156.     fclose(otbuf);
  157.  
  158.  
  159. /*   
  160.      *List the users that are presently in conference
  161. */
  162.     portsout("\n\r\n\rThe following users are presently in conference\n\r");
  163.     no_cntrl_k = 1;
  164.     strcpy(buf128, "ls /tmp/conf* > /tmp/inconf.");
  165.     strcat(buf128, my_ext);
  166.     (void) system(buf128);
  167.     strcpy(buf128, "/tmp/inconf.");
  168.     strcat(buf128, my_ext);
  169.     if ((otbuf = fopen(buf128, "r")) == NULL) {
  170.     portsout("\n\rError opening list file!\n\r");
  171.     exit(1);
  172.     }
  173.     while (fscanf(otbuf, "%s", who_am_i) != EOF) {
  174.     cmd_p(who_am_i);
  175.     }
  176.     fclose(otbuf);
  177.     no_cntrl_k = 0;
  178. /*
  179.      *Start the loop for input
  180. */
  181.  
  182.     portsout("\n\rDepressing the escape key will exit the conference!\n\r");
  183.     strcpy(who_am_I, "<");
  184.     strcat(who_am_I, w_fname);
  185.     strcat(who_am_I, " ");
  186.     strcat(who_am_I, w_lname);
  187.     strcat(who_am_I, "> ");
  188.     buf128[0] = '\0';
  189.     while (1) {
  190.     bufptr = buf128;
  191.     *bufptr = '\0';
  192.       conf_loop:
  193.     mybyte = portin_chat();
  194.     if (mybyte == '\033')
  195.         break;
  196.     if (mybyte == 127)
  197.         mybyte = '\b';
  198.     if (mybyte == '\b') {
  199.         length = strlen(buf128);
  200.         if (!length)
  201.         goto conf_loop;
  202.         length--;
  203.         portout_chat(mybyte);
  204.         portout_chat(bytes);
  205.         portout_chat(mybyte);
  206.         bufptr = length + buf128;
  207.         *bufptr = '\0';
  208.         goto conf_loop;
  209.     }
  210.     portout_chat(mybyte);
  211.     length = strlen(buf128);
  212.     bufptr = length + buf128;
  213.     *bufptr++ = mybyte;
  214.     *bufptr = '\0';
  215.     if (mybyte == '\n' || mybyte == '\r')
  216.         goto saver;
  217.     goto conf_loop;
  218.       saver:
  219.     if (mybyte == '\n')
  220.         bytet = byter;
  221.     else
  222.         bytet = byten;
  223.     portout_chat(bytet);
  224.     length = strlen(buf128);
  225.     bufptr = length + buf128;
  226.     *bufptr++ = bytet;
  227.     *bufptr = '\0';
  228.     strcpy(who_am_i, "ls /tmp/conf* > /tmp/inconf.");
  229.     strcat(who_am_i, my_ext);
  230.     (void) system(who_am_i);
  231.     strcpy(who_am_i, "/tmp/inconf.");
  232.     strcat(who_am_i, my_ext);
  233.     if ((inbuf = fopen(who_am_i, "r")) == NULL) {
  234.         portsout("\n\rError opening list file!\n\r");
  235.         exit(1);
  236.     }
  237.     while (fscanf(inbuf, "%s", who_am_i) != EOF) {
  238.         handle = strlen(who_am_i);
  239.         handlex = strlen(my_ext);
  240.         length = handle - handlex + 1;
  241.         substr(who_am_i, x_pathandfile, length, handlex);
  242.         length = strcmp(x_pathandfile, my_ext);
  243.         if (length != 0) {
  244.         otbuf = fopen(who_am_i, "r");
  245.         fscanf(otbuf, "%s%s%s", who_am_i, x_filename, x_pathandfile);
  246.         fclose(otbuf);
  247.         strcpy(who_am_i, "/dev/");
  248.         strcat(who_am_i, x_pathandfile);
  249.         handle = open(who_am_i, O_WRONLY);
  250.         length = strlen(who_am_I);
  251.         write(handle, who_am_I, length);
  252.         length = strlen(buf128);
  253.         write(handle, buf128, length);
  254.         close(handle);
  255.         }
  256.     }
  257.     fclose(inbuf);
  258.     }
  259.     strcpy(who_am_i, "/tmp/conf");
  260.     strcat(who_am_i, my_ext);
  261.     unlink(who_am_i);
  262. }
  263. who_is_there()
  264. {
  265.     DIR            *dirp;
  266.     FILE           *infile;
  267.  
  268. #ifdef SYSV
  269.     struct dirent  *readdir();
  270.     struct dirent  *dp;
  271. #else
  272.     struct direct  *readdir();
  273.     struct direct  *dp;
  274. #endif
  275.  
  276.     char           *ptr1, *ptr2;
  277.     int             i, j;
  278.     portsout("\n\r\n\r");
  279.     dirp = opendir("/tmp");
  280.     while ((dp = readdir(dirp)) != NULL) {
  281.     strcpy(who_am_i, dp->d_name);
  282.     ptr1 = who_am_i;
  283.     ptr2 = who_am_I;
  284.     for (i = 0; i < 3; i++)
  285.         *ptr2++ = *ptr1++;
  286.     *ptr2 = '\0';
  287.     j = strcmp(who_am_I, "pid");
  288.     if (!j) {
  289.         strcpy(who_am_I, "/tmp/");
  290.         strcat(who_am_I, dp->d_name);
  291.         infile = fopen(who_am_I, "r");
  292.         fgets(who_am_I, 6, infile);
  293.         i = atoi(who_am_I);
  294.         fclose(infile);
  295.         j = kill(i, 0);    /* see if it is a good pid */
  296.         if (!j) {
  297.         strcpy(buf128, ORGPATH);
  298.         strcat(buf128, "lastcall.bbs");
  299.         ptr1 = who_am_i + 3;
  300.         ptr2 = who_am_I;
  301.         for (i = 3; i < 5; i++)
  302.             *ptr2++ = *ptr1++;
  303.         *ptr2 = '\0';
  304.         strcat(buf128, who_am_I);
  305.         infile = fopen(buf128, "r");
  306.         fgets(buf128, 99, infile);
  307.         strip(buf128);
  308.         portsout("On port ");
  309.         portsout(who_am_I);
  310.         portsout(" -- ");
  311.         portsout(buf128);
  312.         portsout(CRLF);
  313.         fclose(infile);
  314.         }
  315.     }
  316.     }
  317.     closedir(dirp);
  318.     portsout("\n\r\n\r");
  319. }
  320.