Annotation of 42BSD/ingres/source/support/usersetup.c, revision 1.1.1.1

1.1       root        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 7.1     2/5/81)
                      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: 
                     41:        Proc_name = "USERSETUP";
                     42:        pathname = NULL;
                     43:        if (argc > 1)
                     44:        {
                     45:                argc--;
                     46:                stat = *++argv;
                     47:        }
                     48: 
                     49:        code = "aa";
                     50:        if ((iop = (int) fopen("/etc/passwd", "r")) == NULL)
                     51:                syserr(0, "cannot open /etc/passwd for reading");
                     52: 
                     53:        /* scan for INGRES in /etc/passwd */
                     54:        while (fgets(buf, MAXLINE, iop))
                     55:        {
                     56:                i = decode(buf, field);
                     57:                if (!sequal(USERINGRES, field[0]))
                     58:                        continue;
                     59:                pathname = field[i - 1];
                     60: 
                     61:                break;
                     62:        }
                     63: 
                     64:        /* test for INGRES entry found */
                     65:        if (!pathname)
                     66:                syserr(0, "USERINGRES not installed as UNIX user");
                     67: 
                     68:        /* get override pathname */
                     69:        if (argc > 1)
                     70:                pathname = argv[1];
                     71: 
                     72:        /* rewind passwd file */
                     73:        if (fclose(iop))
                     74:                syserr("fclose");
                     75:        if ((iop = (int) fopen("/etc/passwd", "r")) == NULL)
                     76:                syserr("open /etc/passwd 2");
                     77: 
                     78:        /* open output file as needed */
                     79:        if (pathname[0] != '-')
                     80:        {
                     81:                concat(pathname, "/files/users", buf);
                     82:                if ((i = open(buf, 0)) >= 0)
                     83:                        syserr(0, "%s already exists", buf);
                     84:                if ((i = creat(buf, 0644)) < 0)
                     85:                        syserr("Cannot create %s", buf);
                     86:                close(i);
                     87:                if (freopen(buf, "w", stdout) == NULL)
                     88:                        syserr("cannot open %s", buf);
                     89:        }
                     90: 
                     91:        while (fgets(buf, MAXLINE, iop))
                     92:        {
                     93:                i = decode(buf, field);
                     94:                /* print username & code */
                     95:                printf("%s:%s:%s:%s:%s:::%s/.ingres::\n",
                     96:                        field[0],       /* user name */
                     97:                        code,
                     98:                        field[2],       /* user id */
                     99:                        field[3],       /* user group */
                    100:                        sequal(field[0], USERINGRES) ? "177777" : stat,
                    101:                        field[i - 1]);  /* working directory */
                    102:                next(code);
                    103:        }
                    104:        fflush(stdout);
                    105: }
                    106: /*
                    107: **  DECODE
                    108: */
                    109: 
                    110: decode(buf, field)
                    111: char   *buf;
                    112: char   *field[];
                    113: {
                    114:        register char   *cp, c;
                    115:        register int    i;
                    116: 
                    117:        field[0] = buf;
                    118:        for (i = 0, cp = buf; (c = *cp) != '\n' && c != '\0'; cp++)
                    119:        {
                    120:                if (c == ':')
                    121:                {
                    122:                        *cp = '\0';
                    123:                        i++;
                    124:                        field[i] = cp + 1;
                    125:                }
                    126:        }
                    127: 
                    128:        return (i);
                    129: }
                    130: /*
                    131: **  NEXT -- return successor to code.
                    132: */
                    133: 
                    134: next(code)
                    135: char   code[2];
                    136: {
                    137:        register char   *c;
                    138:        register char   a, b;
                    139: 
                    140:        c = code;
                    141:        a = c[0];
                    142:        b = c[1];
                    143: 
                    144:        if (++b > 'z')
                    145:        {
                    146:                b = '0';
                    147:        }
                    148:        else if (b == '9' + 1)
                    149:        {
                    150:                b = 'a';
                    151:                if (a == 'Z')
                    152:                {
                    153:                        write(2, "Too many users\n", 15);
                    154:                        exit(-1);
                    155:                }
                    156:                if (++a > 'z')
                    157:                {
                    158:                        a = 'A';
                    159:                }
                    160:        }
                    161: 
                    162:        c[0] = a;
                    163:        c[1] = b;
                    164: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.