From 5a0b61224f538d832d4f88b169524c138648b0c2 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 2 Jan 2024 21:36:01 +0100 Subject: pam_unix: reduce variable visibility Signed-off-by: Tobias Stoeckmann --- modules/pam_unix/support.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/pam_unix') diff --git a/modules/pam_unix/support.c b/modules/pam_unix/support.c index df5044e9..a4e24210 100644 --- a/modules/pam_unix/support.c +++ b/modules/pam_unix/support.c @@ -346,13 +346,12 @@ static void _unix_cleanup(pam_handle_t *pamh UNUSED, void *data, int error_statu int _unix_getpwnam(pam_handle_t *pamh, const char *name, int files, int nis, struct passwd **ret) { - FILE *passwd; char *buf = NULL; int matched = 0; - char *slogin, *spasswd, *suid, *sgid, *sgecos, *shome, *sshell, *p; - size_t retlen; if (!matched && files && strchr(name, ':') == NULL) { + FILE *passwd; + passwd = fopen("/etc/passwd", "r"); if (passwd != NULL) { size_t n = 0, userlen; @@ -363,6 +362,8 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, while ((r = getline(&buf, &n, passwd)) != -1) { if ((size_t)r > userlen && (buf[userlen] == ':') && (strncmp(name, buf, userlen) == 0)) { + char *p; + p = buf + strlen(buf) - 1; while (isspace((unsigned char)*p) && (p >= buf)) { *p-- = '\0'; @@ -401,6 +402,9 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, #endif if (matched && (ret != NULL)) { + char *slogin, *spasswd, *suid, *sgid, *sgecos, *shome, *sshell, *p; + size_t retlen; + *ret = NULL; slogin = buf; -- cgit v1.2.3