Skip to content

Commit cc3d47b

Browse files
committed
sudo_auth_init: Fix setting FLAG_ONEANDONLY if only one auth method enabled
The inner for loop did not skip over the first enabled auth method, so FLAG_ONEANDONLY was never set. Fix this by eliminating the inner loop entirely and just clear the variable if we find a second enabled auth method. Reported by Aaron Esau. Fixes GitHub issue #527.
1 parent 8a40a50 commit cc3d47b

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

plugins/sudoers/auth/sudo_auth.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 1999-2005, 2008-2020 Todd C. Miller <[email protected]>
4+
* Copyright (c) 1999-2005, 2008-2020, 2022-2026
5+
* Todd C. Miller <[email protected]>
56
*
67
* Permission to use, copy, modify, and distribute this software for any
78
* purpose with or without fee is hereby granted, provided that the above
@@ -94,7 +95,7 @@ int
9495
sudo_auth_init(const struct sudoers_context *ctx, struct passwd *pw,
9596
unsigned int mode)
9697
{
97-
sudo_auth *auth;
98+
sudo_auth *auth, *highlander = NULL;
9899
debug_decl(sudo_auth_init, SUDOERS_DEBUG_AUTH);
99100

100101
if (auth_switch[0].name == NULL)
@@ -147,20 +148,18 @@ sudo_auth_init(const struct sudoers_context *ctx, struct passwd *pw,
147148
}
148149

149150
/* Set FLAG_ONEANDONLY if there is only one auth method. */
150-
for (auth = auth_switch; auth->name; auth++) {
151-
/* Find first enabled auth method. */
151+
for (auth = auth_switch; auth->name != NULL; auth++) {
152152
if (!IS_DISABLED(auth)) {
153-
sudo_auth *first = auth;
154-
/* Check for others. */
155-
for (; auth->name; auth++) {
156-
if (!IS_DISABLED(auth))
157-
break;
153+
/* There can be only one... */
154+
if (highlander != NULL) {
155+
highlander = NULL;
156+
break;
158157
}
159-
if (auth->name == NULL)
160-
SET(first->flags, FLAG_ONEANDONLY);
161-
break;
158+
highlander = auth;
162159
}
163160
}
161+
if (highlander != NULL)
162+
SET(highlander->flags, FLAG_ONEANDONLY);
164163

165164
debug_return_int(AUTH_SUCCESS);
166165
}

0 commit comments

Comments
 (0)