From 07c6c666000d18a2ecf5f2c188111eda66f6515c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 18 Nov 2026 22:46:13 +0000 Subject: [PATCH 7/9] monitor: Defer unknown users when PAMDeferUnknownUsers is set Mark a clean NSS miss as deferred when the option applies, and pass that state to the child as a third MONITOR_ANS_PWNAM result. Only the ssh-connection service can be deferred. No authentication method can complete a deferred login yet. --- auth2.c | 2 ++ monitor.c | 9 ++++++++- monitor.h | 3 +++ monitor_wrap.c | 4 +++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/auth2.c b/auth2.c index e640d9396..6b6ddb3d3 100644 --- a/auth2.c +++ b/auth2.c @@ -304,6 +304,8 @@ input_userauth_request(int type, uint32_t seq, struct ssh *ssh) authctxt->user = xstrdup(user); authctxt->service = xstrdup(service); authctxt->style = style ? xstrdup(style) : NULL; + if (strcmp(service, "ssh-connection") != 0) + authctxt->deferred = 0; if (authctxt->pw && strcmp(service, "ssh-connection")==0) { authctxt->valid = 1; debug2_f("setting up authctxt for %s", user); diff --git a/monitor.c b/monitor.c index a5d260edc..18e547bd6 100644 --- a/monitor.c +++ b/monitor.c @@ -891,9 +891,14 @@ mm_answer_pwnamallow(struct ssh *ssh, int sock, struct sshbuf *m) if (pwent == NULL) { invalid_user = 1; +#ifdef USE_PAM + authctxt->deferred = notfound && options.use_pam && + options.pam_defer_unknown_users; +#endif if (notfound && !authctxt->deferred) auth_invalid_user(ssh, authctxt->user); - if ((r = sshbuf_put_u8(m, 0)) != 0) + if ((r = sshbuf_put_u8(m, + authctxt->deferred ? MM_PWNAM_DEFERRED : 0)) != 0) fatal_fr(r, "assemble fakepw"); authctxt->pw = fakepw(); goto out; @@ -1003,6 +1008,8 @@ mm_answer_authserv(struct ssh *ssh, int sock, struct sshbuf *m) (r = sshbuf_get_cstring(m, &authctxt->style, NULL)) != 0) fatal_fr(r, "parse"); debug3_f("service=%s, style=%s", authctxt->service, authctxt->style); + if (strcmp(authctxt->service, "ssh-connection") != 0) + authctxt->deferred = 0; if (strlen(authctxt->style) == 0) { free(authctxt->style); diff --git a/monitor.h b/monitor.h index fe0b00b2e..194b3abf0 100644 --- a/monitor.h +++ b/monitor.h @@ -70,6 +70,9 @@ enum monitor_reqtype { struct ssh; struct sshbuf; +/* A third result in MONITOR_ANS_PWNAM, alongside 0 and 1. */ +#define MM_PWNAM_DEFERRED 2 + struct monitor { int m_recvfd; int m_sendfd; diff --git a/monitor_wrap.c b/monitor_wrap.c index 457a6196f..12412e950 100644 --- a/monitor_wrap.c +++ b/monitor_wrap.c @@ -330,6 +330,7 @@ mm_decode_activate_server_options(struct ssh *ssh, struct sshbuf *m) struct passwd * mm_getpwnamallow(struct ssh *ssh, const char *username) { + Authctxt *authctxt = ssh->authctxt; struct sshbuf *m; struct passwd *pw; size_t len; @@ -351,7 +352,8 @@ mm_getpwnamallow(struct ssh *ssh, const char *username) if ((r = sshbuf_get_u8(m, &ok)) != 0) fatal_fr(r, "parse success"); - if (ok == 0) { + if (ok != 1) { + authctxt->deferred = ok == MM_PWNAM_DEFERRED; pw = NULL; goto out; } -- 2.53.0