afsdirentry * afsroot::firstentry (sfs_aid aid) { afsdir *d = userdir (aid); afsdirentry *de = afsdir::firstentry (aid); if (!d || !d->lookup (de->name, aid)) return de; return nextentry (de, aid); }
void afsdir::ls () { warnx ("files in directory %d:\n", (u_int32_t) ino); pentry (this, "."); pentry (parent, ".."); for (afsdirentry *e = firstentry (NULL); e; e = nextentry (e, NULL)) pentry (e->node, e->name); }
int userdb_change(const char *filename, const struct userentry *uep, int create) { /* possible values for `create' are: * 0: never create a new record (return 1 if not already there). * 1: create a new record if required. * 2: fail (and return 1) if already exists (ie, force creation) * -1: delete an existing record (return 1 if it doesn't exist). * return values are: * 0: OK * 1: Value for `create' prevented us from going ahead * 2: Wanted to create a new record, but there is no room. */ static struct userentry ue; int n, initial, i, place; FILE *file; initbyuserid(filename,"r+b",F_WRLCK,uep->userid,uep->access,&file,&initial,&n); i= initial; place= -1; for(;;) { getentry(file,&ue,filename); if (!ue.userid[0]) { if (place==-1) place= i; } else if (!strncmp(uep->userid,ue.userid,USERID_MAXLEN)) /* && (uep->access < 0 || uep->access == ue.access)) */ { if (create==2) { ufclose(file,filename); return 1; } place=i; break; } i= nextentry(file,i,n,filename); if (i == initial) { /* OK, we didn't find it. We may have found a space, though */ if (create<=0) { ufclose(file,filename); return 1; } if (place==-1) { ufclose(file,filename); return 2; } break; } } if (fseek(file,sizeof(struct userentry)*place,SEEK_SET)) ohshite("User database `%s' unseekable for update",filename); if (create<0) { ue.userid[0]= 0; ue.secretbytes= 0; ue.disabled= 0; memset(ue.secret,0,SECRET_MAXBYTES); uep= &ue; } else { assert(uep->access >= 0); } errno=0; if (fwrite(uep,sizeof(*uep),1,file)!=1) ohshite("User database `%s' unwriteable",filename); if (ufclose(file,filename)) ohshite("User database `%s' uncloseable",filename); return 0; }
const struct userentry *userdb_find(const char *filename, const char userid[USERID_MAXLEN], int ac) { static struct userentry ue; int n, initial, i; FILE *file; initbyuserid(filename,"rb",F_RDLCK,userid,ac,&file,&initial,&n); i= initial; for(;;) { getentry(file,&ue,filename); if (!strncmp(userid,ue.userid,USERID_MAXLEN) && (ac<0 || ue.access == ac)) { ufclose(file,filename); return &ue; } i= nextentry(file,i,n,filename); if (i == initial) { ufclose(file,filename); return 0; } } }