home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / contrib / usr.x25 / lib / verify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-03  |  1.3 KB  |  71 lines

  1. /*
  2.  * x25_can_callin(person)
  3.  * x25_can_callout(person)
  4.  *    Boolean functions for determining if `person'
  5.  *     can charge an incoming (login) or outgoing X.25
  6.  *    call locally, using the file /etc/x25users.  Each line
  7.  *    of x25users is of the form
  8.  *        user [in|out]
  9.  *    If "in" or "out" is given, the user may place incoming
  10.  *    or outgoing calls only.  Otherwise, the user may place both.
  11.  *    Lines starting with # are comments.
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. #define CALL_OUT    (1<<0)    /* can charge outgoing calls locally */
  17. #define CALL_IN        (1<<1)    /* can charge incoming calls locally */
  18. static char Users[] = "/etc/x25users";
  19.  
  20. x25_can_callout(who)
  21.     char *who;
  22. {
  23.     return (lookup(who) & CALL_OUT) != 0;
  24. }
  25.  
  26. x25_can_callin(who)
  27.     char *who;
  28. {
  29.     return (lookup(who) & CALL_IN) != 0;
  30. }
  31.  
  32.     static int
  33. lookup(who)
  34.     char *who;
  35. {
  36.     FILE *f;
  37.     int r;
  38.  
  39.     if ((f = fopen(Users, "r")) == NULL)
  40.         return 0;
  41.     r = dolookup(f, who);
  42.     fclose(f);
  43.     return r;
  44. }
  45.  
  46.     static int
  47. dolookup(f, who)
  48.     FILE *f;
  49.     char *who;
  50. {
  51.     char buf[256], name[50], arg[50];
  52.     int n;
  53.     
  54.     while (fgets(buf, sizeof buf, f) != NULL) {
  55.         if (buf[0] == '#')
  56.             continue;
  57.         n = sscanf(buf, "%s%s", name, arg);
  58.         if (n < 1)
  59.             continue;
  60.         if (strcmp(name, who) != 0)
  61.             continue;
  62.         if (n == 1)
  63.             return CALL_IN|CALL_OUT;
  64.         if (strcmp(arg, "in") == 0)
  65.             return CALL_IN;
  66.         if (strcmp(arg, "out") == 0)
  67.             return CALL_OUT;
  68.     }
  69.     return 0;
  70. }
  71.