]> granicus.if.org Git - linux-pam/commitdiff
Relevant BUGIDs: 440107
authorSteve Langasek <vorlon@debian.org>
Thu, 13 Sep 2001 19:52:47 +0000 (19:52 +0000)
committerSteve Langasek <vorlon@debian.org>
Thu, 13 Sep 2001 19:52:47 +0000 (19:52 +0000)
Purpose of commit: module reentrancy

Commit summary:
---------------
Commit sample code that uses getpwnam_r instead of getpwnam.  All code is
#ifdef'ed out right now.

CHANGELOG
modules/pam_unix/support.c

index 82a8fe386c79738c24e4d9b7bfdd1c738034ee02..11ccbe20fc9c974069abc112e3f5363502afde3d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -49,6 +49,8 @@ bug report - outstanding bugs are listed here:
 0.76: please submit patches for this section with actual code/doc
       patches!
 
+* pam_unix/support.c: sample use of reentrant NSS function.  Not yet active,
+  because modules do not include _pam_aconf_h! (Bug 440107 - vorlon)
 * doc/Makefile changes - use $(mandir) [courtesy Harald Welte] (Bug
   435760) and add some rules to make/delete the draft rfc I've been
   working on (Task 17426 - agmorgan)
index 964d1a46267ae1873c73297232a395f176d8530b..61915e57156961ef0d699bacb5997031adcd114c 100644 (file)
@@ -314,6 +314,13 @@ int _unix_blankpasswd(unsigned int ctrl, const char *name)
        struct spwd *spwdent = NULL;
        char *salt = NULL;
        int retval;
+#if HAVE_GETPWNAM_R
+       char *buf = NULL;
+       int bufsize = 0;
+       struct passwd pwd_buf;
+
+       pwd = &pwd_buf;
+#endif
 
        D(("called"));
 
@@ -327,7 +334,25 @@ int _unix_blankpasswd(unsigned int ctrl, const char *name)
                return 0;       /* will fail but don't let on yet */
 
        /* UNIX passwords area */
-       pwd = getpwnam(name);   /* Get password file entry... */
+
+       /* Get password file entry... */
+#if HAVE_GETPWNAM_R
+       bufsize = 1024;
+       buf = malloc(bufsize);
+
+       if ((retval = getpwnam_r(name, pwd, buf, bufsize, &pwd))) {
+               pwd = NULL;
+       }
+       while (retval == ERANGE) {
+               bufsize += 1024;
+               buf = realloc(buf, bufsize);
+               if ((retval getpwnam_r(name, pwd, buf, bufsize, &pwd))) {
+                       pwd = NULL;
+               }
+       }
+#else
+       pwd = getpwnam(name);
+#endif
 
        if (pwd != NULL) {
                if (strcmp( pwd->pw_passwd, "*NP*" ) == 0)
@@ -345,6 +370,10 @@ int _unix_blankpasswd(unsigned int ctrl, const char *name)
                                        setreuid( 0, -1 );
                                        if(setreuid( -1, pwd->pw_uid ) == -1)
                                                /* Will fail elsewhere. */
+#if HAVE_GETPWNAM_R
+                                               if (buf)
+                                                       free(buf);
+#endif
                                                return 0;
                                }
                        }
@@ -384,6 +413,11 @@ int _unix_blankpasswd(unsigned int ctrl, const char *name)
        if (salt)
                _pam_delete(salt);
 
+#if HAVE_GETPWNAM_R
+       if (buf)
+               free(buf);
+#endif
+
        return retval;
 }