home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part02 / admin.c next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.8 KB  |  141 lines

  1. /*
  2.  * Perform administrative functions.  Check to see if the user has
  3.  * permission to make long distance calls, and record all phone calls
  4.  * made by pcomm.
  5.  */
  6.  
  7. #undef LOG_CALLS
  8. #undef LIMIT_LD
  9.  
  10. #define LOGFILE "/usr/adm/phone.calls"
  11. #define GRPNAME "uucp"
  12.  
  13. #include <stdio.h>
  14. #include <grp.h>
  15. #include "dial_dir.h"
  16. #include "param.h"
  17.  
  18. /*
  19.  * Make a log of all calls made by pcomm.  The argument is the index
  20.  * into the queue.
  21.  */
  22.  
  23. int
  24. log_calls(i)
  25. int i;
  26. {
  27. #ifdef LOG_CALLS
  28.     FILE *fp;
  29.     char *number, *build_num(), *date, *ctime(), *getlogin();
  30.     long now, time();
  31.     void error_win();
  32.                     /* build the complete phone number */
  33.     number = build_num(i);
  34.                     /* build date and time */
  35.     time(&now);
  36.     date = ctime(&now);
  37.     date[10] = NULL;
  38.     date[16] = NULL;
  39.  
  40.     if (!(fp = fopen(LOGFILE, "a+")))
  41.         error_win(1, "Can't open phone log file", "Contact your system administrator");
  42.  
  43.     fprintf(fp, "pcomm: %s called %s at %s on %s\n", getlogin(), number, &date[11], date);
  44.     fclose(fp);
  45. #endif /* LOG_CALLS */
  46.     return (0);
  47. }
  48.  
  49. /*
  50.  * Check to see if long distance (toll) call is authorized.  The argument
  51.  * is the index into the queue.
  52.  */
  53.  
  54. int
  55. limit_ld(i)
  56. int i;
  57. {
  58. #ifdef LIMIT_LD
  59.     char *number, *build_num(), *name, *getlogin();
  60.     struct group *getgrnam(), *grpbuf;
  61.  
  62.                     /* if no group, don't bother */
  63.     grpbuf = getgrnam(GRPNAME);
  64.     if (!grpbuf || !*grpbuf->gr_mem)
  65.         return(0);
  66.                     /* are you in the group? */
  67.     name = getlogin();
  68.     for (; *grpbuf->gr_mem != NULL; grpbuf->gr_mem++) {
  69.         if (!strcmp(*grpbuf->gr_mem, name))
  70.             return(0);
  71.     }
  72.                     /* numbers only... */
  73.     number = build_num(i);
  74.  
  75.     /*
  76.      * Very site specific!!!  We use a '9' to get an outside line,
  77.      * so any 9 followed by a 1 is a toll call (except for 1-800
  78.      * numbers).
  79.      */
  80.     if (!strncmp(number, "91", 2) && strncmp(number, "91800", 5)) {
  81.         error_win(0, "You are not authorized to place long distance \(toll\) calls", NULL);
  82.         return(1);
  83.     }
  84.  
  85.     if (*number == NULL) {
  86.         error_win(0, "You are not authorized direct access to the line", "Use the automatic dialing feature");
  87.         return(1);
  88.     }
  89. #endif /* LIMIT_LD */
  90.     return(0);
  91. }
  92.  
  93. #ifdef LOG_CALLS || LIMIT_LD
  94. /*
  95.  * Put together the complete phone number but strip out the extraneous
  96.  * characters.
  97.  */
  98.  
  99. char *
  100. build_num(i)
  101. int i;
  102. {
  103.     int j;
  104.     char *t, temp[40], *strcpy(), *strcat();
  105.     static char ans[40];
  106.  
  107.     temp[0] = NULL;
  108.                     /* add LD codes ? */
  109.     switch (dir->q_ld[i]) {
  110.         case 0:
  111.             break;
  112.         case '+':
  113.             strcpy(temp, param->ld_plus);
  114.             break;
  115.         case '-':
  116.             strcpy(temp, param->ld_minus);
  117.             break;
  118.         case '@':
  119.             strcpy(temp, param->ld_at);
  120.             break;
  121.         case '#':
  122.             strcpy(temp, param->ld_pound);
  123.             break;
  124.     }
  125.                     /* add the number */
  126.     strcat(temp, dir->number[dir->q_num[i]]);
  127.  
  128.                     /* copy only digits */
  129.     j = 0;
  130.     t = temp;
  131.     while (*t) {
  132.         if (*t >= '0' && *t <= '9')
  133.             ans[j++] = *t;
  134.         t++;
  135.     }
  136.     ans[j] = NULL;
  137.  
  138.     return(ans);
  139. }
  140. #endif /* LOG_CALLS || LIMIT_LD */
  141.