|
|
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 ! 112: rflog("unexpected except line: %s %s\n", typ, arg); ! 113: } ! 114: } ! 115: ! 116: exparam(par) ! 117: char *par; ! 118: { ! 119: register char *val; ! 120: extern char *defaultuser, *defaultgroup; ! 121: ! 122: if ((val = strchr(par, '=')) != NULL) ! 123: *val++ = 0; ! 124: if (strcmp(par, "root") == 0) ! 125: strcpy(rootname, val); ! 126: else if (strcmp(par, "otherok") == 0) ! 127: rfotherdeny = (*val != '1'); /* 1 means others OK */ ! 128: else if (strcmp(par, "defaultuser") == 0) { ! 129: if ((defaultuser = (char *)malloc(strlen(val)+1)) == NULL) ! 130: rfpanic("no mem for defaultuser\n"); ! 131: strcpy(defaultuser, val); ! 132: } else if (strcmp(par, "defaultgroup") == 0) { ! 133: if ((defaultgroup = (char *)malloc(strlen(val)+1)) == NULL) ! 134: rfpanic("no mem for defaultgroup\n"); ! 135: strcpy(defaultgroup, val); ! 136: } else ! 137: rflog("unexpected except param %s=%s\n", par, val); ! 138: } ! 139: ! 140: exuid(arg, val) ! 141: char *arg, *val; ! 142: { ! 143: register Namemap *p; ! 144: ! 145: if (val == 0) ! 146: return; ! 147: if (val[0] == '=') ! 148: *val++ = 0; ! 149: if (exulist == NULL) { ! 150: exulim = 10; ! 151: if ((exulist = (Namemap *)malloc(exulim*sizeof(Namemap))) == NULL) ! 152: rfpanic("no mem for except uids\n"); ! 153: } ! 154: if (exuend >= exulim - 1) { ! 155: exulim += 10; ! 156: if ((exulist = (Namemap *)realloc((char *)exulist, exulim*sizeof(Namemap))) == NULL) ! 157: rfpanic("no mem for except uids\n"); ! 158: } ! 159: p = &exulist[exuend++]; ! 160: strncpy(p->cname, arg, sizeof(p->cname)-1); ! 161: p->cname[sizeof(p->cname)-1] = 0; ! 162: strncpy(p->sname, val, sizeof(p->sname)-1); ! 163: p->sname[sizeof(p->sname)-1] = 0; ! 164: p[1].cname[0] = 0; ! 165: } ! 166: ! 167: exgid(arg) ! 168: char *arg; ! 169: { ! 170: char *val; ! 171: register Namemap *p; ! 172: ! 173: if ((val = strchr(arg, '=')) == NULL) ! 174: return; /* may be wrong */ ! 175: *val++ = 0; ! 176: if (exglist == NULL) { ! 177: exglim = 10; ! 178: if ((exglist = (Namemap *)malloc(exglim*sizeof(Namemap))) == NULL) ! 179: rfpanic("no mem for except uids\n"); ! 180: } ! 181: if (exgend >= exglim-1) { ! 182: exglim += 10; ! 183: if ((exglist = (Namemap *)realloc((char *)exglist, exglim*sizeof(Namemap))) == NULL) ! 184: rfpanic("no mem for except uids\n"); ! 185: } ! 186: p = &exglist[exgend++]; ! 187: strncpy(p->cname, arg, sizeof(p->cname)-1); ! 188: p->cname[sizeof(p->cname)-1] = 0; ! 189: strncpy(p->sname, val, sizeof(p->sname)-1); ! 190: p->sname[sizeof(p->sname)-1] = 0; ! 191: p[1].cname[0] = 0; ! 192: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.