aix-auth-speedup-20050508
authorSteve Roseman <sgr0@lehigh.edu>
Sun, 8 May 2005 06:50:23 +0000 (06:50 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 8 May 2005 06:50:23 +0000 (06:50 +0000)
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.

src/tsm41/aix41_auth.c

index b9fa36e..d9879a2 100644 (file)
@@ -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;