Do not warn, log or send mail for errors when reinitializing defaults.

If there is a problem, we would have already warned, logged or mailed it.
The one exception is the initial defaults, which should never fail.
This commit is contained in:
Todd C. Miller
2022-03-14 13:54:12 -06:00
parent de47380350
commit ff17317988

View File

@@ -151,14 +151,14 @@ restore_nproc(void)
/* /*
* Re-initialize Defaults settings. * Re-initialize Defaults settings.
* We do not send mail for errors when reinitializing, mail would have * We do not warn, log or send mail for errors when reinitializing,
* already been sent the first time. * this would have already been done the first time through.
* TODO: prevent Defaults error logging too
*/ */
static bool static bool
sudoers_reinit_defaults(void) sudoers_reinit_defaults(void)
{ {
struct sudo_nss *nss, *nss_next; struct sudo_nss *nss, *nss_next;
sudoers_logger_t logger = sudoers_error_hook;
debug_decl(sudoers_reinit_defaults, SUDOERS_DEBUG_PLUGIN); debug_decl(sudoers_reinit_defaults, SUDOERS_DEBUG_PLUGIN);
if (!init_defaults()) { if (!init_defaults()) {
@@ -166,21 +166,25 @@ sudoers_reinit_defaults(void)
debug_return_bool(false); debug_return_bool(false);
} }
/* It should not be possible for the initial defaults to fail to apply. */
if (!update_defaults(NULL, &initial_defaults, if (!update_defaults(NULL, &initial_defaults,
SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS, false)) SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS, false))
debug_return_bool(false); debug_return_bool(false);
/* Disable error logging while re-processing defaults. */
sudoers_error_hook = NULL;
TAILQ_FOREACH_SAFE(nss, snl, entries, nss_next) { TAILQ_FOREACH_SAFE(nss, snl, entries, nss_next) {
/* Missing/invalid defaults is not a fatal error. */ /* Missing/invalid defaults is not a fatal error. */
if (nss->getdefs(nss) == -1) { if (nss->getdefs(nss) != -1) {
log_warningx(SLOG_SEND_MAIL|SLOG_NO_STDERR,
N_("unable to get defaults from %s"), nss->source);
} else {
(void)update_defaults(nss->parse_tree, NULL, (void)update_defaults(nss->parse_tree, NULL,
SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS, false); SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS, true);
} }
} }
/* Restore error logging. */
sudoers_error_hook = logger;
debug_return_bool(true); debug_return_bool(true);
} }