Annotation of 43BSD/ingres/source/support/subs.c, revision 1.1.1.1

1.1       root        1: # include      <stdio.h>
                      2: # include      <ingres.h>
                      3: # include      <aux.h>
                      4: # include      <access.h>
                      5: # include      <lock.h>
                      6: # include      <sccs.h>
                      7: # include      <opsys.h>
                      8: # include      <sys/dir.h>
                      9: 
                     10: SCCSID(@(#)subs.c      8.3     1/31/86)
                     11: 
                     12: /*
                     13: ** These are subroutines common to RESTORE and PURGE.
                     14: */
                     15: 
                     16: #ifndef rewinddir
                     17: typedef        DIR     FILE;
                     18: 
                     19: DIR *
                     20: opendir(d)
                     21: char *d;
                     22: {
                     23:        return(fopen(d, "r"));
                     24: }
                     25: 
                     26: closedir(d);
                     27: DIR *d;
                     28: {
                     29:        return(fclose(d));
                     30: }
                     31: 
                     32: struct direct *
                     33: readdir(dirp)
                     34: DIR *dirp;
                     35: {
                     36:        static struct direct direc;
                     37:        struct direct *d = &direc;
                     38:        int n;
                     39: 
                     40:        n = fread(&direc, sizeof(struct direct), 1, dirp);
                     41:        if (n <= 0)
                     42:                d = NULL;
                     43:        return(d);
                     44: }
                     45: 
                     46: #endif rewinddir
                     47: 
                     48: 
                     49: char           All;
                     50: char           Qrymod;
                     51: char           Superuser;
                     52: char           Ask;
                     53: char           Purge;
                     54: char           Clean;
                     55: char           Lastflag;
                     56: DIR            *Direc;
                     57: extern int     Status;
                     58: extern char    *Usercode;
                     59: char           **Dblist;
                     60: 
                     61: 
                     62: 
                     63: 
                     64: /*
                     65: **  INITIALIZE GLOBALS
                     66: **
                     67: **     Set up Usercode and Status
                     68: */
                     69: 
                     70: initialize(argc, argv)
                     71: int    argc;
                     72: char   **argv;
                     73: {
                     74:        register int    i;
                     75:        long            l;
                     76:        extern char     *Flagvect[];
                     77:        extern char     *Parmvect[];
                     78:        register char   *p;
                     79:        register char   **av;
                     80:        char            datadir[MAXLINE];
                     81: 
                     82: #      ifdef   xTTR2
                     83:        tTfp(40, 0, "entered initialize\n");
                     84: #      endif
                     85:        i = initucode(argc, argv, FALSE, NULL, -1);
                     86: #      ifdef   xTTR2
                     87:        tTfp(40, 1, "initucode ret:%d\n", i);
                     88: #      endif
                     89:        switch (i)
                     90:        {
                     91:          case 0:
                     92:                break;
                     93: 
                     94:          case INVALIDUSR:
                     95:                printf("You are not a valid INGRES user\n");
                     96:                exit(-1);
                     97: 
                     98:          default:
                     99:                syserr("initucode %d", i);
                    100:        }
                    101:        initdbpath(NULL, datadir, FALSE);
                    102: 
                    103:        /* scan flags */
                    104: #      ifdef   xTTR2
                    105:        tTfp(40, 2, "scanning flags\n");
                    106: #      endif
                    107:        for (av = Flagvect;  *av != NULL; av++)
                    108:        {
                    109:                p = *av;
                    110:                if (p[0] != '-')
                    111:                {
                    112:                badflag:
                    113:                        printf("Bad flag: %s\n", p);
                    114:                        return (-1);
                    115:                }
                    116:                switch (p[1])
                    117:                {
                    118:                  case 'a':
                    119:                        Ask++;
                    120:                        break;
                    121: 
                    122:                  case 'p':
                    123:                        Purge++;
                    124:                        break;
                    125: 
                    126:                  case 's':
                    127:                        if (sucheck())
                    128:                                Superuser++;
                    129:                        else
                    130:                        {
                    131:                                printf("You may not use the -s flag\n");
                    132:                                exit(-1);
                    133:                        }
                    134:                        break;
                    135: 
                    136:                  case 'f':
                    137:                        Clean++;
                    138:                        break;
                    139: 
                    140:                  case 'T':
                    141:                        break;
                    142: 
                    143:                  default:
                    144:                        goto badflag;
                    145:                }
                    146:        }
                    147:        Dblist = Parmvect;
                    148:        if (*Dblist == 0)
                    149:        {
                    150: #              ifdef   xTTR2
                    151:                tTfp(40, 3, "doing all\n");
                    152: #              endif
                    153:                All++;
                    154:                Direc = opendir(datadir);
                    155:                if (Direc == NULL)
                    156:                {
                    157:                        syserr("cannot read .../data/base");
                    158:                }
                    159:        }
                    160: #      ifdef   xTTR2
                    161:        tTfp(40, 0, "leaving initialize\n");
                    162: #      endif
                    163: }
                    164: 
                    165: /*
                    166: **  CHECK FOR SUPERUSER
                    167: **
                    168: **     The user has requested the -s flag.  Can he do it?  Will Martha
                    169: **     recover from cancer?  Will Dick get the girl?  Stay tuned for
                    170: **     "sucheck".
                    171: **
                    172: **     Permission is based on the U_SUPER bit in the status field
                    173: **     in the users file.
                    174: */
                    175: 
                    176: sucheck()
                    177: {
                    178:        return (Status & U_SUPER);
                    179: }
                    180: 
                    181: 
                    182: 
                    183: /*
                    184: **  GET NEXT DATABASE
                    185: **
                    186: **     The next database to be purged is selected.  It comes from
                    187: **     either the directory or the database list.
                    188: **
                    189: **     Getnxtdb() leaves the user in the database directory.
                    190: */
                    191: 
                    192: char *
                    193: getnxtdb()
                    194: {
                    195:        struct direct           *dp;
                    196: #ifndef rewinddir
                    197:        static char             dbname[DIRSIZ+1];
                    198: #endif
                    199:        register char           *db;
                    200:        register FILE           *fd;
                    201:        register int            i;
                    202:        extern struct admin     Admin;
                    203:        static char             dbpbuf[MAXLINE];
                    204: 
                    205: #      ifdef   xTTR2
                    206:        tTfp(41, 0, "entered getnxtdb\n");
                    207: #      endif
                    208:        for (;;)
                    209:        {
                    210:                if (All)
                    211:                {
                    212: 
                    213:                        dp = readdir(Direc);
                    214:                        if (dp == NULL)
                    215:                                db = NULL;
                    216:                        else
                    217:                        {
                    218:                                if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
                    219:                                {
                    220:                                        continue;
                    221:                                }
                    222: #ifdef rewinddir
                    223:                                db = dp->d_name;
                    224: #else
                    225:                                strncpy(dbname, dp->d_name, DIRSIZ);
                    226:                                dbname[DIRSIZ] = '\0';
                    227:                                db = dbname;
                    228: #endif
                    229:                        }
                    230:                }
                    231:                else
                    232:                {
                    233:                        db = *Dblist++;
                    234:                }
                    235:                if (db == NULL)
                    236:                        return (NULL);
                    237: #              ifdef   xTTR2
                    238:                tTfp(41, 1, "using %s as Database\n", db);
                    239: #              endif
                    240:                i = initdbpath(db, dbpbuf, TRUE);
                    241: #              ifdef   xTTR2
                    242:                tTfp(41, 3, "initdbpath ret: %d, %s\n", i, dbpbuf);
                    243: #              endif
                    244:                switch (i)
                    245:                {
                    246:                  case 0:
                    247:                  case 1:
                    248:                        break;
                    249: 
                    250:                  case 2:
                    251:                  case 3:
                    252:                        printf("Database %s does not exist\n", db);
                    253:                        continue;
                    254: 
                    255:                  default:
                    256:                        syserr("initdbpath %d", i);
                    257:                }
                    258:                if (chdir(dbpbuf) < 0)
                    259:                {
                    260:                        printf("Cannot enter %s", dbpbuf);
                    261:                        continue;
                    262:                }
                    263: #              ifdef   xTTR2
                    264:                tTfp(41, 4, "chdir ok, Superuser: %d\n", Superuser);
                    265: #              endif
                    266:                fd = fopen("admin", "r");
                    267:                if (fd == NULL)
                    268:                {
                    269:                        printf("Cannot open %s/admin\n", dbpbuf);
                    270:                        continue;
                    271:                }
                    272:                fread(&Admin.adhdr, sizeof Admin.adhdr, 1, fd);
                    273:                fclose(fd);
                    274: #              ifdef   xTTR2
                    275:                tTfp(41, 5, "user: %.2s\n", Admin.adhdr.adowner);
                    276: #              endif
                    277: 
                    278:                /* set qrymod flag from database status */
                    279:                Qrymod = ((Admin.adhdr.adflags & A_QRYMOD) == A_QRYMOD);
                    280: 
                    281:                /* check for dba of database if not superuser */ 
                    282:                if (Superuser || bequal(Admin.adhdr.adowner, Usercode, 2))
                    283:                        break;
                    284: 
                    285:                /*
                    286:                ** not dba isn't an error if running in all mode since user
                    287:                ** couln't have specified the database
                    288:                */
                    289:                if (All)
                    290:                        continue;
                    291: printf("You are not the dba for %s\n", db);
                    292:        }
                    293: #      ifdef   xTTR2
                    294:        tTfp(41, 6, "leaving getnxtdb, %s ok\n", db);
                    295: #      endif
                    296:        return (db);
                    297: }
                    298: /*
                    299: ** ASK
                    300: **     If Ask is set desplay prompt and look for 'y' and return TRUE
                    301: **     If Ask is not set return TRUE
                    302: */
                    303: 
                    304: ask(prompt)
                    305: char   *prompt;
                    306: {
                    307:        register char   *p;
                    308:        char            line[MAXLINE];
                    309:        extern char     Ask;
                    310: 
                    311:        if (!Ask)
                    312:                return (TRUE);
                    313:        p = prompt;
                    314: 
                    315:        while (*p)
                    316:        {
                    317:                putchar(*p);
                    318:                p++;
                    319:        }
                    320: 
                    321:        if (fgets(line, MAXLINE, stdin) == NULL)
                    322:                return(FALSE);
                    323: 
                    324:        return (line[0] == 'y');
                    325: }

unix.superglobalmegacorp.com

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