#include static char dirallowed[200]; /* * makeallowed() creates the allowed directory string for * allowed to play around inside of. It must be run before * running allowed() */ makeallowed(src) register char *src; { register char *dirs; for (dirs=dirallowed; *src; *dirs++ = *src++) if (isspace(*src)) { do { ++src; } while (isspace(*src)); if (*src && dirs[-1] != ',' && *src != ',') *dirs++ = ' '; } *dirs = 0; } /* makeallowed */ /* * allowed() checks to see if a given directory is okay to access * if mode==0, we're checking for READ= permissions; if mode==1, * we're checking for WRITE= permissions. If only one set of * permissions is given and doesn't have READ= or WRITE= prefix, * it's generic permissions for everything. * * when allowed() runs, it processes the dirallowed string into an * internal form with no spaces at all except the ones separating * READ= and WRITE= permissions. */ allowed(mode,target) char *target; { register char *p; register amode; register char *dirs; dirs = dirallowed; while (1) { if (strnicmp(dirs, "READ=", 5) == 0) { amode=0; dirs += 5; } else if (strnicmp(dirs, "WRITE=", 6) == 0) { amode=1; dirs += 6; } else amode = (-1); if (*dirs == 0) return 0; if (amode < 0 || mode == amode) { if (strncmp(dirs, "any", 3) == 0) return 1; while (1) { /* pick out a token.... */ for (p=dirs; *p && *p != ',' && *p != ' '; ++p) ; /* try to match it... */ if (strncmp(target, dirs, (int)(p-dirs)) == 0) return 1; /* if we've hit the end of the string, just leave */ if (*p == 0) return 0; dirs = 1+p; /* if we've hit a non-comma, drop out and retry */ if (*p != ',') break; } } else { /* toss away text 'til next | or end of string */ while (*dirs && *dirs != ' ') ++dirs; if (*dirs) ++dirs; } } } /* allowed */