/* This is a multi-purpose funciton for use by either * GetNthIdentity or GetNthUser. The parameter 'id' indicates * whether we are counting all identities (if true), or just * ones which can be represented by the old-style interfaces * We return -1 for EOF, 0 for success, and >0 for all errors. */ static int GetNthIdentityOrUser(struct afsconf_dir *dir, int count, struct rx_identity **identity, int id) { bufio_p bp; char *tbuffer; struct rx_identity fileUser; afs_int32 code; tbuffer = malloc(AFSDIR_PATH_MAX); if (tbuffer == NULL) return ENOMEM; LOCK_GLOBAL_MUTEX; UserListFileName(dir, tbuffer, AFSDIR_PATH_MAX); bp = BufioOpen(tbuffer, O_RDONLY, 0); if (!bp) { UNLOCK_GLOBAL_MUTEX; free(tbuffer); return -1; } while (1) { code = BufioGets(bp, tbuffer, AFSDIR_PATH_MAX); if (code < 0) { code = -1; break; } code = ParseLine(tbuffer, &fileUser); if (code != 0) break; if (id || fileUser.kind == RX_ID_KRB4) count--; if (count < 0) break; else rx_identity_freeContents(&fileUser); } if (code == 0) { *identity = rx_identity_copy(&fileUser); rx_identity_freeContents(&fileUser); } BufioClose(bp); UNLOCK_GLOBAL_MUTEX; free(tbuffer); return code; }
/* This is a multi-purpose funciton for use by either * GetNthIdentity or GetNthUser. The parameter 'id' indicates * whether we are counting all identities (if true), or just * ones which can be represented by the old-style interfaces */ static int GetNthIdentityOrUser(struct afsconf_dir *dir, int count, struct rx_identity **identity, int id) { bufio_p bp; char tbuffer[1024]; struct rx_identity fileUser; afs_int32 code; LOCK_GLOBAL_MUTEX; UserListFileName(dir, tbuffer, sizeof(tbuffer)); bp = BufioOpen(tbuffer, O_RDONLY, 0); if (!bp) { UNLOCK_GLOBAL_MUTEX; return EIO; } while (1) { code = BufioGets(bp, tbuffer, sizeof(tbuffer)); if (code < 0) break; code = ParseLine(tbuffer, &fileUser); if (code != 0) break; if (id || fileUser.kind == RX_ID_KRB4) count--; if (count < 0) break; else rx_identity_freeContents(&fileUser); } if (code == 0) { *identity = rx_identity_copy(&fileUser); rx_identity_freeContents(&fileUser); } BufioClose(bp); UNLOCK_GLOBAL_MUTEX; return code; }