diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2024-01-02 21:33:41 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2024-01-03 17:16:02 +0000 |
commit | 1a2b73ac0befb25b4d297649a96636ca830a79f5 (patch) | |
tree | cdf9083379cc1f85fbb4e7aa7201962180c70d1a | |
parent | 4a2d60e9112b54e36c698379cc67ad299836dcca (diff) | |
download | pam-1a2b73ac0befb25b4d297649a96636ca830a79f5.tar.gz pam-1a2b73ac0befb25b4d297649a96636ca830a79f5.tar.bz2 pam-1a2b73ac0befb25b4d297649a96636ca830a79f5.zip |
pam_unix: calculate user length only if needed
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r-- | modules/pam_unix/support.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/modules/pam_unix/support.c b/modules/pam_unix/support.c index 5dd3b946..df5044e9 100644 --- a/modules/pam_unix/support.c +++ b/modules/pam_unix/support.c @@ -350,15 +350,16 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, char *buf = NULL; int matched = 0; char *slogin, *spasswd, *suid, *sgid, *sgecos, *shome, *sshell, *p; - size_t retlen, userlen; + size_t retlen; - userlen = strlen(name); if (!matched && files && strchr(name, ':') == NULL) { passwd = fopen("/etc/passwd", "r"); if (passwd != NULL) { - size_t n = 0; + size_t n = 0, userlen; ssize_t r; + userlen = strlen(name); + while ((r = getline(&buf, &n, passwd)) != -1) { if ((size_t)r > userlen && (buf[userlen] == ':') && (strncmp(name, buf, userlen) == 0)) { |