1: # include   <stdio.h>
   2: 
   3: # include   "../ingres.h"
   4: # include   "../aux.h"
   5: # include   "../unix.h"
   6: 
   7: /*
   8: **  Initialize Users File From Passwd File
   9: **
  10: **	Everyone in /etc/passwd is entered into the users file.  All
  11: **	users can access all databases.
  12: **
  13: **	User codes are assigned sequentially.  This should therefore
  14: **	probably be run once only, when INGRES is first installed.
  15: **	Otherwise, usercodes can change mysteriously.
  16: **
  17: **	The optional parameter replaces the root of the INGRES subtree
  18: **	as found in /etc/passwd.  The INGRES user must be installed
  19: **	(with that name) when usersetup is run.  If this parameter
  20: **	is a minus ("-"), output goes to the standard output.
  21: **
  22: **	The initialization file is initialized to "<home>/.ingres",
  23: **	where <home> is the home directory in the passwd file.
  24: */
  25: 
  26: main(argc, argv)
  27: int argc;
  28: char    **argv;
  29: {
  30:     register int        i;
  31:     char            buf[MAXLINE + 1];
  32:     char            *pathname;
  33:     register char       *code;
  34:     char            *field[UF_NFIELDS];
  35:     register FILE       *iop;
  36:     extern char     *Proc_name;
  37: 
  38:     Proc_name = "USERSETUP";
  39:     pathname = NULL;
  40: 
  41:     code = "aa";
  42:     if ((iop = fopen("/etc/passwd", "r")) == NULL)
  43:         syserr(0, "cannot open /etc/passwd for reading");
  44: 
  45:     /* scan for INGRES in /etc/passwd */
  46:     while (fgetline(buf, MAXLINE, iop))
  47:     {
  48:         i = decode(buf, field);
  49:         if (!sequal(USERINGRES, field[0]))
  50:             continue;
  51:         pathname = field[i - 1];
  52: 
  53:         break;
  54:     }
  55: 
  56:     /* test for INGRES entry found */
  57:     if (!pathname)
  58:         syserr(0, "USERINGRES not installed as UNIX user");
  59: 
  60:     /* get override pathname */
  61:     if (argc > 1)
  62:         pathname = argv[1];
  63: 
  64:     /* rewind passwd file */
  65:     if (fclose(iop))
  66:         syserr("fclose");
  67:     if ((iop = fopen("/etc/passwd", "r")) == NULL)
  68:         syserr("open /etc/passwd 2");
  69: 
  70:     /* open output file as needed */
  71:     if (pathname[0] != '-')
  72:     {
  73:         concat(pathname, "/files/users", buf);
  74:         if ((i = open(buf, 0)) >= 0)
  75:             syserr(0, "%s already exists", buf);
  76:         if ((i = creat(buf, 0644)) < 0)
  77:             syserr("Cannot create %s", buf);
  78:         close(i);
  79:         if (freopen(buf, "w", stdout) == NULL)
  80:             syserr("cannot open %s", buf);
  81:     }
  82: 
  83:     while (fgetline(buf, MAXLINE, iop))
  84:     {
  85:         i = decode(buf, field);
  86:         /* print username & code */
  87:         printf("%s:%s:%s:%s:%s:::%s/.ingres::\n",
  88:             field[0],   /* user name */
  89:             code,
  90:             field[2],   /* user id */
  91:             field[3],   /* user group */
  92:             sequal(field[0], USERINGRES) ? "177777" : "000000",
  93:             field[i - 1]);  /* working directory */
  94:         next(code);
  95:     }
  96:     flush();
  97: }
  98: 
  99: 
 100: decode(buf, field)
 101: char    *buf;
 102: char    *field[];
 103: {
 104:     register char   *cp, c;
 105:     register int    i;
 106: 
 107:     field[0] = buf;
 108:     for (i = 0, cp = buf; (c = *cp) != '\0'; cp++)
 109:     {
 110:         if (c == ':')
 111:         {
 112:             *cp = '\0';
 113:             i++;
 114:             field[i] = cp + 1;
 115:         }
 116:     }
 117: 
 118:     return (i);
 119: }
 120: 
 121: 
 122: 
 123: 
 124: next(code)
 125: char    code[2];
 126: {
 127:     register char   *c;
 128:     register char   a, b;
 129: 
 130:     c = code;
 131:     a = c[0];
 132:     b = c[1];
 133: 
 134:     if (++b > 'z')
 135:     {
 136:         b = '0';
 137:     }
 138:     else if (b == '9' + 1)
 139:     {
 140:         b = 'a';
 141:         if (a == 'Z')
 142:         {
 143:             write(2, "Too many users\n", 15);
 144:             exit(-1);
 145:         }
 146:         if (++a > 'z')
 147:         {
 148:             a = 'A';
 149:         }
 150:     }
 151: 
 152:     c[0] = a;
 153:     c[1] = b;
 154: }

Defined functions

decode defined in line 100; used 2 times
main defined in line 26; never used
next defined in line 124; used 1 times
  • in line 94
Last modified: 1995-02-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3044
Valid CSS Valid XHTML 1.0 Strict