Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpam/modules Use getpwnam_r().



details:   https://anonhg.NetBSD.org/src/rev/4921fc52d095
branches:  trunk
changeset: 579912:4921fc52d095
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Mar 31 15:11:54 2005 +0000

description:
Use getpwnam_r().

diffstat:

 lib/libpam/modules/pam_chroot/pam_chroot.c       |  10 +++++---
 lib/libpam/modules/pam_ftpusers/pam_ftpusers.c   |  10 +++++---
 lib/libpam/modules/pam_group/pam_group.c         |  10 +++++---
 lib/libpam/modules/pam_krb5/pam_krb5.c           |  20 ++++++++--------
 lib/libpam/modules/pam_lastlog/pam_lastlog.c     |  10 +++++---
 lib/libpam/modules/pam_nologin/pam_nologin.c     |   9 ++++---
 lib/libpam/modules/pam_radius/pam_radius.c       |   9 +++++--
 lib/libpam/modules/pam_rhosts/pam_rhosts.c       |   9 ++++---
 lib/libpam/modules/pam_securetty/pam_securetty.c |  10 +++++---
 lib/libpam/modules/pam_self/pam_self.c           |  10 +++++---
 lib/libpam/modules/pam_ssh/pam_ssh.c             |  16 +++++++-------
 lib/libpam/modules/pam_unix/pam_unix.c           |  27 ++++++++++++++---------
 12 files changed, 86 insertions(+), 64 deletions(-)

diffs (truncated from 588 to 300 lines):

diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_chroot/pam_chroot.c
--- a/lib/libpam/modules/pam_chroot/pam_chroot.c        Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_chroot/pam_chroot.c        Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_chroot.c,v 1.2 2004/12/12 08:18:43 christos Exp $  */
+/*     $NetBSD: pam_chroot.c,v 1.3 2005/03/31 15:11:54 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2003 Networks Associates Technology, Inc.
@@ -38,7 +38,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_chroot/pam_chroot.c,v 1.3 2003/04/30 00:40:24 des Exp $");
 #else
-__RCSID("$NetBSD: pam_chroot.c,v 1.2 2004/12/12 08:18:43 christos Exp $");
+__RCSID("$NetBSD: pam_chroot.c,v 1.3 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 #include <sys/param.h>
@@ -59,11 +59,13 @@
     int argc __unused, const char *argv[] __unused)
 {
        const char *dir, *end, *cwd, *user;
-       struct passwd *pwd;
+       struct passwd *pwd, pwres;
        char buf[PATH_MAX];
+       char pwbuf[1024];
 
        if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS ||
-           user == NULL || (pwd = getpwnam(user)) == NULL)
+           user == NULL ||
+           getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0)
                return (PAM_SESSION_ERR);
        if (pwd->pw_uid == 0 && !openpam_get_option(pamh, "also_root"))
                return (PAM_SUCCESS);
diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_ftpusers/pam_ftpusers.c
--- a/lib/libpam/modules/pam_ftpusers/pam_ftpusers.c    Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_ftpusers/pam_ftpusers.c    Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_ftpusers.c,v 1.2 2004/12/12 08:18:44 christos Exp $        */
+/*     $NetBSD: pam_ftpusers.c,v 1.3 2005/03/31 15:11:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2001 Networks Associates Technology, Inc.
@@ -38,7 +38,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_ftpusers/pam_ftpusers.c,v 1.1 2002/05/08 00:30:10 des Exp $");
 #else
-__RCSID("$NetBSD: pam_ftpusers.c,v 1.2 2004/12/12 08:18:44 christos Exp $");
+__RCSID("$NetBSD: pam_ftpusers.c,v 1.3 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 #include <ctype.h>
@@ -60,18 +60,20 @@
 pam_sm_acct_mgmt(pam_handle_t *pamh, int flags __unused,
     int argc __unused, const char *argv[] __unused)
 {
-       struct passwd *pwd;
+       struct passwd *pwd, pwres;
        struct group *grp;
        const char *user;
        int pam_err, found, allow;
        char *line, *name, **mem;
        size_t len, ulen;
        FILE *f;
+       char pwbuf[1024];
 
        pam_err = pam_get_user(pamh, &user, NULL);
        if (pam_err != PAM_SUCCESS)
                return (pam_err);
-       if (user == NULL || (pwd = getpwnam(user)) == NULL)
+       if (user == NULL ||
+           getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0)
                return (PAM_SERVICE_ERR);
 
        found = 0;
diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_group/pam_group.c
--- a/lib/libpam/modules/pam_group/pam_group.c  Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_group/pam_group.c  Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_group.c,v 1.5 2005/03/05 20:33:40 christos Exp $   */
+/*     $NetBSD: pam_group.c,v 1.6 2005/03/31 15:11:54 thorpej Exp $    */
 
 /*-
  * Copyright (c) 2003 Networks Associates Technology, Inc.
@@ -38,7 +38,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_group/pam_group.c,v 1.4 2003/12/11 13:55:15 des Exp $");
 #else
-__RCSID("$NetBSD: pam_group.c,v 1.5 2005/03/05 20:33:40 christos Exp $");
+__RCSID("$NetBSD: pam_group.c,v 1.6 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 #include <sys/types.h>
@@ -69,14 +69,16 @@
        const char *group, *user;
        const void *ruser;
        char *const *list;
-       struct passwd *pwd;
+       struct passwd *pwd, pwres;
        struct group *grp;
        int pam_err;
        char *promptresp = NULL;
+       char pwbuf[1024];
 
        /* get target account */
        if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS ||
-           user == NULL || (pwd = getpwnam(user)) == NULL)
+           user == NULL ||
+           getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0)
                return (PAM_AUTH_ERR);
        if (pwd->pw_uid != 0 && openpam_get_option(pamh, "root_only"))
                return (PAM_IGNORE);
diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_krb5/pam_krb5.c
--- a/lib/libpam/modules/pam_krb5/pam_krb5.c    Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_krb5/pam_krb5.c    Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_krb5.c,v 1.6 2005/02/26 18:25:28 thorpej Exp $     */
+/*     $NetBSD: pam_krb5.c,v 1.7 2005/03/31 15:11:54 thorpej Exp $     */
 
 /*-
  * This pam_krb5 module contains code that is:
@@ -53,7 +53,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_krb5/pam_krb5.c,v 1.22 2005/01/24 16:49:50 rwatson Exp $");
 #else
-__RCSID("$NetBSD: pam_krb5.c,v 1.6 2005/02/26 18:25:28 thorpej Exp $");
+__RCSID("$NetBSD: pam_krb5.c,v 1.7 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 #include <sys/types.h>
@@ -110,13 +110,14 @@
        krb5_principal princ;
        krb5_ccache ccache;
        krb5_get_init_creds_opt opts;
-       struct passwd *pwd;
+       struct passwd *pwd, pwres;
        int retval;
        void *ccache_data;
        const char *user, *pass;
        const void *sourceuser, *service;
        char *principal, *princ_name, *ccache_name, luser[32], *srvdup;
        char password_prompt[80];
+       char pwbuf[1024];
 
        retval = pam_get_user(pamh, &user, USER_PROMPT);
        if (retval != PAM_SUCCESS)
@@ -223,13 +224,12 @@
                PAM_LOG("PAM_USER Redone");
        }
 
-       pwd = getpwnam(user);
-       if (pwd == NULL) {
+       if (getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0) {
                retval = PAM_USER_UNKNOWN;
                goto cleanup2;
        }
 
-       PAM_LOG("Done getpwnam()");
+       PAM_LOG("Done getpwnam_r()");
 
        /* Get a TGT */
        memset(&creds, 0, sizeof(krb5_creds));
@@ -349,12 +349,13 @@
        krb5_creds creds;
        krb5_ccache ccache_temp, ccache_perm;
        krb5_cc_cursor cursor;
-       struct passwd *pwd = NULL;
+       struct passwd *pwd = NULL, pwres;
        int retval;
        const char *cache_name, *q;
        const void *user;
        void *cache_data;
        char *cache_name_buf = NULL, *p;
+       char pwbuf[1024];
 
        uid_t euid;
        gid_t egid;
@@ -412,13 +413,12 @@
        }
 
        /* Get the uid. This should exist. */
-       pwd = getpwnam(user);
-       if (pwd == NULL) {
+       if (getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0) {
                retval = PAM_USER_UNKNOWN;
                goto cleanup3;
        }
 
-       PAM_LOG("Done getpwnam()");
+       PAM_LOG("Done getpwnam_r()");
 
        /* Avoid following a symlink as root */
        if (setegid(pwd->pw_gid)) {
diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_lastlog/pam_lastlog.c
--- a/lib/libpam/modules/pam_lastlog/pam_lastlog.c      Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_lastlog/pam_lastlog.c      Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_lastlog.c,v 1.6 2005/03/05 20:32:41 christos Exp $ */
+/*     $NetBSD: pam_lastlog.c,v 1.7 2005/03/31 15:11:54 thorpej Exp $  */
 
 /*-
  * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
@@ -47,7 +47,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_lastlog/pam_lastlog.c,v 1.20 2004/01/26 19:28:37 des Exp $");
 #else
-__RCSID("$NetBSD: pam_lastlog.c,v 1.6 2005/03/05 20:32:41 christos Exp $");
+__RCSID("$NetBSD: pam_lastlog.c,v 1.7 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 #include <sys/param.h>
@@ -97,18 +97,20 @@
 pam_sm_open_session(pam_handle_t *pamh, int flags,
     int argc __unused, const char *argv[] __unused)
 {
-       struct passwd *pwd;
+       struct passwd *pwd, pwres;
        struct timeval now;
        const char *user, *rhost, *tty, *nuser;
        const void *vrhost, *vtty, *vss, *vnuser;
        const struct sockaddr_storage *ss;
        int pam_err;
+       char pwbuf[1024];
 
        pam_err = pam_get_user(pamh, &user, NULL);
        if (pam_err != PAM_SUCCESS)
                return pam_err;
 
-       if (user == NULL || (pwd = getpwnam(user)) == NULL)
+       if (user == NULL ||
+           getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0)
                return PAM_SERVICE_ERR;
 
        PAM_LOG("Got user: %s", user);
diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_nologin/pam_nologin.c
--- a/lib/libpam/modules/pam_nologin/pam_nologin.c      Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_nologin/pam_nologin.c      Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_nologin.c,v 1.3 2005/01/23 09:45:02 manu Exp $     */
+/*     $NetBSD: pam_nologin.c,v 1.4 2005/03/31 15:11:54 thorpej Exp $  */
 
 /*-
  * Copyright 2001 Mark R V Murray
@@ -40,7 +40,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_nologin/pam_nologin.c,v 1.10 2002/04/12 22:27:21 des Exp $");
 #else
-__RCSID("$NetBSD: pam_nologin.c,v 1.3 2005/01/23 09:45:02 manu Exp $");
+__RCSID("$NetBSD: pam_nologin.c,v 1.4 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 
@@ -70,13 +70,14 @@
     int argc __unused, const char *argv[] __unused)
 {
        login_cap_t *lc;
-       struct passwd *pwd;
+       struct passwd *pwd, pwres;
        struct stat st;
        int retval, fd;
        int ignorenologin = 0;
        int rootlogin = 0;
        const char *user, *nologin;
        char *mtmp;
+       char pwbuf[1024];
 
        if ((retval = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS)
                return retval;
@@ -91,7 +92,7 @@
         * Do not allow login of unexisting users, so that a directory
         * failure will not cause the nologin capability to be ignored.
         */
-       if ((pwd = getpwnam(user)) == NULL) {
+       if (getpwnam_r(user, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0) {
                return PAM_USER_UNKNOWN;
        } else {
                if (pwd->pw_uid == 0)
diff -r faa987d09a05 -r 4921fc52d095 lib/libpam/modules/pam_radius/pam_radius.c
--- a/lib/libpam/modules/pam_radius/pam_radius.c        Thu Mar 31 14:29:32 2005 +0000
+++ b/lib/libpam/modules/pam_radius/pam_radius.c        Thu Mar 31 15:11:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_radius.c,v 1.2 2004/12/12 08:18:46 christos Exp $  */
+/*     $NetBSD: pam_radius.c,v 1.3 2005/03/31 15:11:54 thorpej Exp $   */
 
 /*-
  * Copyright 1998 Juniper Networks, Inc.
@@ -40,7 +40,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_radius/pam_radius.c,v 1.22 2004/06/25 12:32:45 kan Exp $");
 #else
-__RCSID("$NetBSD: pam_radius.c,v 1.2 2004/12/12 08:18:46 christos Exp $");
+__RCSID("$NetBSD: pam_radius.c,v 1.3 2005/03/31 15:11:54 thorpej Exp $");
 #endif
 
 #include <sys/param.h>
@@ -253,6 +253,8 @@
        struct rad_handle *radh;
        const char *user, *pass;
        const void *tmpuser;
+       struct passwd *pwd, pwres;



Home | Main Index | Thread Index | Old Index