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

Defined functions

decode defined in line 113; used 2 times
main defined in line 7; never used
next defined in line 137; used 1 times
sysexit defined in line 174; used 2 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1291
Valid CSS Valid XHTML 1.0 Strict