From 65197792f083bfa2394af6c8fbf683875068bba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 18 Nov 2026 22:22:24 +0000 Subject: [PATCH 2/9] auth: Distinguish an absent user from a failed lookup Expose cleanly if NSS lookup failed due to a missing record or because errors and denied accounts. Save errno before restoring the AIX authentication database. --- auth.c | 12 +++++++++++- auth.h | 2 +- monitor.c | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/auth.c b/auth.c index d48815ba4..16d8158f2 100644 --- a/auth.c +++ b/auth.c @@ -457,7 +457,7 @@ check_key_in_hostfiles(struct passwd *pw, struct sshkey *key, const char *host, } struct passwd * -getpwnamallow(struct ssh *ssh, const char *user) +getpwnamallow(struct ssh *ssh, const char *user, int *notfound) { #ifdef HAVE_LOGIN_CAP extern login_cap_t *lc; @@ -471,6 +471,9 @@ getpwnamallow(struct ssh *ssh, const char *user) struct passwd *pw; struct connection_info *ci; u_int i; + int lookup_errno; + + *notfound = 0; ci = server_get_connection_info(ssh, 1, options.use_dns); ci->user = user; @@ -489,12 +492,19 @@ getpwnamallow(struct ssh *ssh, const char *user) aix_setauthdb(user); #endif + errno = 0; pw = getpwnam(user); + lookup_errno = errno; #if defined(_AIX) && defined(HAVE_SETAUTHDB) aix_restoreauthdb(); #endif + if (pw == NULL && lookup_errno != 0) { + error_f("getpwnam for %.100s: %s", user, strerror(lookup_errno)); + return (NULL); + } if (pw == NULL) { + *notfound = 1; logit("Invalid user %.100s from %.100s port %d", user, ssh_remote_ipaddr(ssh), ssh_remote_port(ssh)); #ifdef CUSTOM_FAILED_LOGIN diff --git a/auth.h b/auth.h index 17227cffb..9b9341dab 100644 --- a/auth.h +++ b/auth.h @@ -191,7 +191,7 @@ int bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); int bsdauth_respond(void *, u_int, char **); int allowed_user(struct ssh *, struct passwd *); -struct passwd * getpwnamallow(struct ssh *, const char *user); +struct passwd * getpwnamallow(struct ssh *, const char *, int *); char *expand_authorized_keys(const char *, struct passwd *pw); char *authorized_principals_file(struct passwd *); diff --git a/monitor.c b/monitor.c index ebcd9c8c8..fb9e95cbf 100644 --- a/monitor.c +++ b/monitor.c @@ -846,7 +846,7 @@ int mm_answer_pwnamallow(struct ssh *ssh, int sock, struct sshbuf *m) { struct passwd *pwent; - int r, allowed = 0; + int r, allowed = 0, notfound; debug3_f("entering"); @@ -860,7 +860,7 @@ mm_answer_pwnamallow(struct ssh *ssh, int sock, struct sshbuf *m) if ((r = sshbuf_get_cstring(m, &authctxt->user, NULL)) != 0) fatal_fr(r, "parse"); - pwent = getpwnamallow(ssh, authctxt->user); + pwent = getpwnamallow(ssh, authctxt->user, ¬found); setproctitle("%s [priv]", pwent ? authctxt->user : "unknown"); -- 2.53.0