diff options
author | Steve Langasek <vorlon@debian.org> | 2001-09-13 19:52:47 +0000 |
---|---|---|
committer | Steve Langasek <vorlon@debian.org> | 2001-09-13 19:52:47 +0000 |
commit | 55c3de6afdac8b957f705becadf83fffd17753cd (patch) | |
tree | 030207d95d165514fa1e97b6d89ba0ad4e37f30a /modules/pam_unix | |
parent | 66cd0c8e9a52b4933cfd71749db0ac44e3409bd9 (diff) | |
download | pam-55c3de6afdac8b957f705becadf83fffd17753cd.tar.gz pam-55c3de6afdac8b957f705becadf83fffd17753cd.tar.bz2 pam-55c3de6afdac8b957f705becadf83fffd17753cd.zip |
Relevant BUGIDs: 440107
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.
Diffstat (limited to 'modules/pam_unix')
-rw-r--r-- | modules/pam_unix/support.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/modules/pam_unix/support.c b/modules/pam_unix/support.c index 964d1a46..61915e57 100644 --- a/modules/pam_unix/support.c +++ b/modules/pam_unix/support.c @@ -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; } |