Skip to content

Commit a579fcf

Browse files
committed
Add sudoers_initialized to determine if sudoers_init() was called.
This gets cleared in sudoers_cleanup(), making it it possible to re-initialize sudoers after cleanup. The policy fuzzer relies on this behavior, broken by fd4b369.
1 parent c69f902 commit a579fcf

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

plugins/sudoers/sudoers.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ sudoers_reinit_defaults(struct sudoers_context *ctx)
175175
debug_return_bool(true);
176176
}
177177

178+
static bool sudoers_initialized;
179+
178180
/*
179181
* Initialize sudoers data structures and parse sudoers sources.
180182
* Returns 1 on success and -1 on error.
@@ -184,12 +186,13 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
184186
{
185187
struct sudo_nss *nss, *nss_next;
186188
int oldlocale, sources = 0;
187-
static int ret = 0;
189+
int ret = -1;
188190
debug_decl(sudoers_init, SUDOERS_DEBUG_PLUGIN);
189191

190-
/* Only initialize once, don't re-initialize on error (-1). */
191-
if (ret != 0)
192+
/* Only attempt to initialize once. */
193+
if (sudoers_initialized)
192194
debug_return_int(ret);
195+
sudoers_initialized = true;
193196

194197
bindtextdomain("sudoers", LOCALEDIR);
195198

@@ -201,29 +204,29 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
201204

202205
/* Initialize environment functions (including replacements). */
203206
if (!env_init(envp))
204-
goto done;
207+
debug_return_int(-1);
205208

206209
/* Setup defaults data structures. */
207210
if (!init_defaults()) {
208211
sudo_warnx("%s", U_("unable to initialize sudoers default values"));
209-
goto done;
212+
debug_return_int(-1);
210213
}
211214

212215
/* Parse info from front-end. */
213216
sudoers_ctx.mode = sudoers_policy_deserialize_info(&sudoers_ctx, info,
214217
&initial_defaults);
215218
if (ISSET(sudoers_ctx.mode, MODE_ERROR))
216-
goto done;
219+
debug_return_int(-1);
217220

218221
if (!init_vars(&sudoers_ctx, envp))
219-
goto done;
222+
debug_return_int(-1);
220223

221224
/* Parse nsswitch.conf for sudoers order. */
222225
snl = sudo_read_nss();
223226

224227
/* LDAP or NSS may modify the euid so we need to be root for the open. */
225228
if (!set_perms(NULL, PERM_ROOT))
226-
goto done;
229+
debug_return_int(-1);
227230

228231
/* Use the C locale unless another is specified in sudoers. */
229232
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
@@ -261,7 +264,7 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
261264

262265
/* Set login class if applicable (after sudoers is parsed). */
263266
if (set_loginclass(&sudoers_ctx))
264-
ret = 1;
267+
ret = true;
265268

266269
cleanup:
267270
mail_parse_errors(&sudoers_ctx);
@@ -273,9 +276,6 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
273276
sudo_warn_set_locale_func(NULL);
274277
sudoers_setlocale(oldlocale, NULL);
275278

276-
done:
277-
if (ret == 0)
278-
ret = -1;
279279
debug_return_int(ret);
280280
}
281281

@@ -1523,6 +1523,7 @@ sudoers_cleanup(void)
15231523
free(def->val);
15241524
free(def);
15251525
}
1526+
sudoers_initialized = false;
15261527
need_reinit = false;
15271528
if (def_group_plugin)
15281529
group_plugin_unload();

0 commit comments

Comments
 (0)