Skip to content

Commit 17aa768

Browse files
committed
sudo_pam_verify: move PAM_USER after getpass_error check
Move it into the PAM_SUCCESS case of the switch *pam_status switch.
1 parent 52c73b8 commit 17aa768

File tree

1 file changed

+14
-18
lines changed
  • plugins/sudoers/auth

1 file changed

+14
-18
lines changed

plugins/sudoers/auth/pam.c

+14-18
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,8 @@ int
297297
sudo_pam_verify(const struct sudoers_context *ctx, struct passwd *pw,
298298
const char *prompt, sudo_auth *auth, struct sudo_conv_callback *callback)
299299
{
300-
const char *envccname;
301-
const char *s;
302-
int *pam_status = (int *)auth->data;
300+
const char *envccname, *pam_user;
301+
int rc, *pam_status = (int *)auth->data;
303302
debug_decl(sudo_pam_verify, SUDOERS_DEBUG_AUTH);
304303

305304
def_prompt = prompt; /* for converse */
@@ -332,25 +331,22 @@ sudo_pam_verify(const struct sudoers_context *ctx, struct passwd *pw,
332331
debug_return_int(AUTH_FAILURE);
333332
}
334333

335-
if (*pam_status == PAM_SUCCESS) {
336-
const char *pam_user = NULL;
337-
338-
*pam_status = pam_get_item(pamh, PAM_USER, (const void **) &pam_user);
339-
if (*pam_status == PAM_SUCCESS &&
340-
(pam_user == NULL || strcmp(pam_user, pw->pw_name) != 0)) {
341-
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
342-
"unable to authenticate '%s' as user '%s'",
343-
pw->pw_name, pam_user);
344-
debug_return_int(AUTH_FAILURE);
345-
}
346-
}
347-
348334
if (getpass_error) {
349335
/* error or ^C from tgetpass() or running non-interactive */
350336
debug_return_int(noninteractive ? AUTH_NONINTERACTIVE : AUTH_INTR);
351337
}
338+
352339
switch (*pam_status) {
353340
case PAM_SUCCESS:
341+
/* Verify user did not change during PAM transaction. */
342+
rc = pam_get_item(pamh, PAM_USER, (const void **)&pam_user);
343+
if (rc == PAM_SUCCESS &&
344+
(pam_user == NULL || strcmp(pam_user, pw->pw_name) != 0)) {
345+
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
346+
"unable to authenticate '%s' as user '%s'",
347+
pw->pw_name, pam_user);
348+
debug_return_int(AUTH_FAILURE);
349+
}
354350
debug_return_int(AUTH_SUCCESS);
355351
case PAM_AUTH_ERR:
356352
case PAM_AUTHINFO_UNAVAIL:
@@ -360,8 +356,8 @@ sudo_pam_verify(const struct sudoers_context *ctx, struct passwd *pw,
360356
"pam_authenticate: %d", *pam_status);
361357
debug_return_int(AUTH_FAILURE);
362358
default:
363-
s = sudo_pam_strerror(pamh, *pam_status);
364-
log_warningx(ctx, 0, N_("PAM authentication error: %s"), s);
359+
log_warningx(ctx, 0, N_("PAM authentication error: %s"),
360+
sudo_pam_strerror(pamh, *pam_status));
365361
debug_return_int(AUTH_ERROR);
366362
}
367363
}

0 commit comments

Comments
 (0)