From 3c8c40ce938067a509a34fbe9063bf9f937a9523 Mon Sep 17 00:00:00 2001 From: Steve Roseman Date: Sun, 8 May 2005 06:51:24 +0000 Subject: [PATCH] STABLE14-aix-auth-speedup-20050508 FIXES 18467 The security module "afs_dynamic_auth" can get VERY slow if trying to authenticate against a user in a large NIS password file. This happens because it "replaces" getpwnam with code which loops through the "passwd" file. this 1) makes external programs use the "real" getpwnam, and 2) changes the internal routine afs_getpwnam_int to use getpwnam instead of iterating. (cherry picked from commit 160c01035ca3775d8bf21dd9a34bd0f51f309159) --- src/tsm41/aix41_auth.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/tsm41/aix41_auth.c b/src/tsm41/aix41_auth.c index b9fa36e5a..d9879a25b 100644 --- a/src/tsm41/aix41_auth.c +++ b/src/tsm41/aix41_auth.c @@ -144,7 +144,7 @@ afs_getgrnam(char *name) struct passwd * afs_getpwnam(char *user) { - return (struct passwd *) afs_getpwnam_int(user, 0); + return (NULL); } struct passwd * @@ -164,24 +164,23 @@ afs_getpwnam_int(char *user, int ignore) if (!user) return &pwd; - while ((p = getpwent()) != NULL) { - if (!strcmp(p->pw_name, user)) { - strncpy(&name, p->pw_name, sizeof(name)); - strncpy(&passwd, p->pw_passwd, sizeof(passwd)); - strncpy(&gecos, p->pw_gecos, sizeof(gecos)); - strncpy(&dir, p->pw_dir, sizeof(dir)); - strncpy(&shell, p->pw_shell, sizeof(shell)); - pwd.pw_name = &name; - pwd.pw_passwd = &passwd; - pwd.pw_uid = p->pw_uid; - pwd.pw_gid = p->pw_gid; - pwd.pw_gecos = &gecos; - pwd.pw_dir = &dir; - pwd.pw_shell = &shell; - break; - } + p = getpwnam (user); + + if (p) { + strncpy(&name, p->pw_name, sizeof(name)); + strncpy(&passwd, p->pw_passwd, sizeof(passwd)); + strncpy(&gecos, p->pw_gecos, sizeof(gecos)); + strncpy(&dir, p->pw_dir, sizeof(dir)); + strncpy(&shell, p->pw_shell, sizeof(shell)); } - endpwent(); + pwd.pw_name = &name; + pwd.pw_passwd = &passwd; + pwd.pw_uid = p->pw_uid; + pwd.pw_gid = p->pw_gid; + pwd.pw_gecos = &gecos; + pwd.pw_dir = &dir; + pwd.pw_shell = &shell; + if (ignore && (p == NULL)) return NULL; return &pwd; -- 2.39.5