void InitPW(int firsttime) { int fd, i; struct stat stbuf; char *fbuf; char *admin = PRS_ADMINGROUP; if (firsttime == PWFIRSTTIME) { memcpy(FileKey, DefKey, RPC2_KEYSIZE); /* moved from void main in auth2: */ PWLen = 100; /* length of PW array; this is an initial guess, may increase below */ PWArray = (RPC2_EncryptionKey *)malloc(PWLen * RPC2_KEYSIZE); CODA_ASSERT(PWArray != NULL); } /* now back to the old InitPW */ /* Reads in contents of PWFile and builds a sorted list of passwords in PWArray. Frees existing storage coor to PWArray. */ if (PWFile == NULL) PWFile = strdup(vice_config_path("db/auth2.pw")); if ((fd = open(PWFile, O_RDONLY, 0)) < 0 || myflock(fd, MYFLOCK_SH, MYFLOCK_BL) < 0 /* locking is superstitious */ || fstat(fd, &stbuf)) { perror(PWFile); abort(); } /* make sure the auth2.pw file is not world readable */ if (stbuf.st_mode & 077) chmod(PWFile, 0600); CODA_ASSERT((fbuf = (char *)malloc(1 + stbuf.st_size)) != NULL); CODA_ASSERT(stbuf.st_size == read(fd, fbuf, stbuf.st_size)); /* entirefile */ PWTime = stbuf.st_mtime; /* time on file to check for changes */ fbuf[stbuf.st_size] = 0; /* sentinel to stop sscanf() later */ /* and unlock the file */ myflock(fd, MYFLOCK_UN, MYFLOCK_BL); close(fd); CODA_ASSERT(AL_NameToId(admin, &AdminID) == 0); for (i = 0; i < RPC2_KEYSIZE; i++) DeleteKey[i] = 0xff; BuildPWArray(fbuf); free(fbuf); }
/* On successful return, Alist will define a newly-created access list corresponding to the external access list defined by Elist. Returns 0 on successful conversion. Returns -1 if ANY name in the access list is not translatable, or if the total number of entries is greater than AL_MaxExtEntries. */ int AL_Internalize(IN AL_ExternalAccessList Elist, OUT AL_AccessList **Alist) { int i, m, p; char *nextc, tbuf[PRS_MAXNAMELEN+1]; if (sscanf(Elist, "%d\n%d\n", &p, &m) != 2) return EINVAL; if (p + m > AL_MaxExtEntries) return E2BIG; AL_NewAlist(p + m, Alist); (*Alist)->PlusEntriesInUse = p; (*Alist)->MinusEntriesInUse = m; nextc = Elist; while(*nextc && *nextc != '\n') nextc++; nextc++; while(*nextc && *nextc != '\n') nextc++; nextc++; /* now at the beginning of the entry list */ for (i = 0; i < (*Alist)->TotalNoOfEntries; i++){ if (sscanf(nextc, "%s\t%d\n", tbuf, &((*Alist)->ActualEntries[i].Rights)) != 2){ AL_FreeAlist(Alist); return EINVAL; } if (AL_NameToId(tbuf, &((*Alist)->ActualEntries[i].Id)) < 0){ AL_FreeAlist(Alist); return ENOENT; /* Unusual error, but we can't return EINVAL for everything */ } nextc = (char *)(1 + strchr(nextc, '\n')); } /* Sort positive and negative entries */ qsort( (char *)&((*Alist)->ActualEntries[0]),p,sizeof(AL_AccessEntry), (int (*)(const void *, const void *))CmpPlus); qsort( (char *)&((*Alist)->ActualEntries[m]),m, sizeof(AL_AccessEntry), (int (*)(const void *, const void *))CmpMinus); return 0; }