Annotation of researchv10no/netfs/serv/ex, revision 1.1.1.1

1.1       root        1: /*
                      2:  * parse the permission exceptions file
                      3:  */
                      4: 
                      5: #include <rf.h>
                      6: #include <stdio.h>
                      7: #include <ctype.h>
                      8: 
                      9: extern char *strchr();
                     10: extern char *malloc(), *realloc();
                     11: 
                     12: extern char rootname[];
                     13: 
                     14: Namemap *exulist, *exglist;
                     15: static int exuend, exgend;
                     16: static int exulim, exglim;
                     17: 
                     18: rdexcept(f)
                     19: FILE *f;
                     20: {
                     21:        char line[200];         /* big enough, ignore */
                     22:        char *typ, *arg;
                     23: 
                     24:        while (fgets(line, sizeof(line), f)) {
                     25:                if (crack(line, &typ, &arg) == 0)
                     26:                        continue;
                     27:                if (strcmp(typ, "client") == 0
                     28:                &&  matchclient(arg)) {
                     29:                        exclient(f);
                     30:                        return (1);
                     31:                }
                     32:        }
                     33:        return (0);
                     34: }
                     35: 
                     36: /*
                     37:  * parse one line from the file
                     38:  * return 1 if it looks valid, 0 if not
                     39:  * a valid line has
                     40:  * at least two blank-separated tokens
                     41:  * and does not begin with `#'
                     42:  * the first token is a type,
                     43:  * the second an argument;
                     44:  * pointers to be filled in for each are supplied
                     45:  */
                     46: crack(line, tp, ap)
                     47: register char *line;
                     48: char **tp, **ap;
                     49: {
                     50: 
                     51:        if (line[0] == '#')
                     52:                return (0);
                     53:        while (isspace(*line))
                     54:                line++;
                     55:        if (line[0] == 0)
                     56:                return (0);
                     57:        *tp = line;
                     58:        while (!isspace(*line))
                     59:                line++;
                     60:        if (line[0] == 0)
                     61:                return (0);
                     62:        *line++ = 0;
                     63:        while (isspace(*line))
                     64:                line++;
                     65:        if (line[0] == 0)
                     66:                return (0);
                     67:        *ap = line;
                     68:        while (*line)
                     69:                line++;
                     70:        if (line[-1] == '\n')
                     71:                line[-1] = 0;
                     72:        return (1);
                     73: }
                     74: 
                     75: /*
                     76:  * is this the client section we want?
                     77:  * -- take the first match, and no other
                     78:  */
                     79: matchclient(cp)
                     80: char *cp;
                     81: {
                     82:        if (strcmp(cp, "*") == 0 || strcmp(cp, rfclient) == 0)
                     83:                return (1);
                     84:        return (0);
                     85: }
                     86: 
                     87: /*
                     88:  * found the right client section;
                     89:  * stash the info away
                     90:  * we know that only this client section will be examined,
                     91:  * so don't worry about the fact that the
                     92:  * next `client' line in the file may be swallowed
                     93:  */
                     94: exclient(f)
                     95: FILE *f;
                     96: {
                     97:        char line[200];         /* again, big enough */
                     98:        char *typ, *arg;
                     99: 
                    100:        while (fgets(line, sizeof(line), f)) {
                    101:                if (crack(line, &typ, &arg) == 0)
                    102:                        continue;
                    103:                if (strcmp(typ, "client") == 0)
                    104:                        break;          /* end of our section */
                    105:                else if (strcmp(typ, "param") == 0)
                    106:                        exparam(arg);
                    107:                else if (strcmp(typ, "uid") == 0)
                    108:                        exuid(arg, strchr(arg, '='));
                    109:                else if (strcmp(typ, "gid") == 0)
                    110:                        exgid(arg);
                    111:                else if (strcmp(typ,  "unknownuser") == 0) {
                    112:                        exuid(RFUNKNOWNUSER, arg);
                    113:                        rfotherdeny = 1;
                    114:                } else if (strcmp(typ,  "unknowngroup") == 0) {
                    115:                } else
                    116:                        rflog("unexpected except line: %s %s\n", typ, arg);
                    117:        }
                    118: }
                    119: 
                    120: exparam(par)
                    121: char *par;
                    122: {
                    123:        register char *val;
                    124: 
                    125:        if (strcmp(par, "root") == 0)
                    126:                strcpy(rootname, val);
                    127:        else if (strcmp(par, "otherok") == 0)
                    128:                rfotherdeny = (*val != '1');    /* 1 means others OK */
                    129:        else
                    130:                rflog("unexpected except param %s=%s\n", par, val);
                    131: }
                    132: 
                    133: exuid(arg, val)
                    134: char *arg, char *val;
                    135: {
                    136:        register Namemap *p;
                    137: 
                    138:        if (val == 0)
                    139:                return;
                    140:        if (val[0] == '=')
                    141:                *val++ = 0;
                    142:        if (exulist == NULL) {
                    143:                exulim = 10;
                    144:                if ((exulist = (Namemap *)malloc(exulim*sizeof(Namemap))) == NULL)
                    145:                        rfpanic("no mem for except uids\n");
                    146:        }
                    147:        if (exuend >= exulim - 1) {
                    148:                exulim += 10;
                    149:                if ((exulist = (Namemap *)realloc((char *)exulist, exulim*sizeof(Namemap))) == NULL)
                    150:                        rfpanic("no mem for except uids\n");
                    151:        }
                    152:        p = &exulist[exuend++];
                    153:        strncpy(p->cname, arg, sizeof(p->cname)-1);
                    154:        p->cname[sizeof(p->cname)-1] = 0;
                    155:        strncpy(p->sname, val, sizeof(p->sname)-1);
                    156:        p->sname[sizeof(p->sname)-1] = 0;
                    157:        p[1].cname[0] = 0;
                    158: }
                    159: 
                    160: exgid(arg)
                    161: char *arg;
                    162: {
                    163:        char *val;
                    164:        register Namemap *p;
                    165: 
                    166:        if ((val = strchr(arg, '=')) == NULL)
                    167:                return;         /* may be wrong */
                    168:        *val++ = 0;
                    169:        if (exglist == NULL) {
                    170:                exglim = 10;
                    171:                if ((exglist = (Namemap *)malloc(exglim*sizeof(Namemap))) == NULL)
                    172:                        rfpanic("no mem for except uids\n");
                    173:        }
                    174:        if (exgend >= exglim-1) {
                    175:                exglim += 10;
                    176:                if ((exglist = (Namemap *)realloc((char *)exglist, exglim*sizeof(Namemap))) == NULL)
                    177:                        rfpanic("no mem for except uids\n");
                    178:        }
                    179:        p = &exglist[exgend++];
                    180:        strncpy(p->cname, arg, sizeof(p->cname)-1);
                    181:        p->cname[sizeof(p->cname)-1] = 0;
                    182:        strncpy(p->sname, val, sizeof(p->sname)-1);
                    183:        p->sname[sizeof(p->sname)-1] = 0;
                    184:        p[1].cname[0] = 0;
                    185: }

unix.superglobalmegacorp.com

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