From b5c2ca2fe55b04e9c5bd8eb26a53c2056c73f249 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 20 Jul 2016 14:16:00 -0600 Subject: [PATCH] Move sudoers locale callback function to locale.c and user it in visudo and testsudoers. --- plugins/sudoers/locale.c | 16 ++++++++++++++++ plugins/sudoers/logging.h | 1 + plugins/sudoers/sudoers.c | 18 +----------------- plugins/sudoers/testsudoers.c | 3 +++ plugins/sudoers/visudo.c | 3 +++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/plugins/sudoers/locale.c b/plugins/sudoers/locale.c index 60a40705b..459c39549 100644 --- a/plugins/sudoers/locale.c +++ b/plugins/sudoers/locale.c @@ -37,6 +37,7 @@ #include "sudo_compat.h" #include "sudo_fatal.h" #include "sudoers_debug.h" +#include "defaults.h" #include "logging.h" static int current_locale = SUDOERS_LOCALE_USER; @@ -133,3 +134,18 @@ sudoers_warn_setlocale(bool restore, int *cookie) debug_return_bool(sudoers_setlocale(*cookie, NULL)); debug_return_bool(sudoers_setlocale(SUDOERS_LOCALE_USER, cookie)); } + +/* + * Callback for sudoers_locale sudoers setting. + */ +bool +sudoers_locale_callback(const union sudo_defs_val *sd_un) +{ + debug_decl(sudoers_locale_callback, SUDOERS_DEBUG_UTIL) + + if (sudoers_initlocale(NULL, sd_un->str)) { + if (setlocale(LC_ALL, sd_un->str) != NULL) + debug_return_bool(true); + } + debug_return_bool(false); +} diff --git a/plugins/sudoers/logging.h b/plugins/sudoers/logging.h index 10d421159..2b64e7a7c 100644 --- a/plugins/sudoers/logging.h +++ b/plugins/sudoers/logging.h @@ -74,6 +74,7 @@ bool log_failure(int status, int flags); bool log_warning(int flags, const char *fmt, ...) __printflike(2, 3); bool log_warningx(int flags, const char *fmt, ...) __printflike(2, 3); bool sudoers_initlocale(const char *ulocale, const char *slocale); +bool sudoers_locale_callback(const union sudo_defs_val *); int writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen); #endif /* SUDOERS_LOGGING_H */ diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 58b7985c7..b02aa1962 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -71,7 +71,6 @@ static char *find_editor(int nfiles, char **files, int *argc_out, char ***argv_out); static bool cb_fqdn(const union sudo_defs_val *); static bool cb_runas_default(const union sudo_defs_val *); -static bool cb_sudoers_locale(const union sudo_defs_val *); static int set_cmnd(void); static int create_admin_success_flag(void); static bool init_vars(char * const *); @@ -750,7 +749,7 @@ init_vars(char * const envp[]) sudo_defs_table[I_RUNAS_DEFAULT].callback = cb_runas_default; /* Set locale callback. */ - sudo_defs_table[I_SUDOERS_LOCALE].callback = cb_sudoers_locale; + sudo_defs_table[I_SUDOERS_LOCALE].callback = sudoers_locale_callback; /* Set maxseq callback. */ sudo_defs_table[I_MAXSEQ].callback = cb_maxseq; @@ -1186,21 +1185,6 @@ cb_runas_default(const union sudo_defs_val *sd_un) debug_return_bool(true); } -/* - * Callback for sudoers_locale sudoers setting. - */ -static bool -cb_sudoers_locale(const union sudo_defs_val *sd_un) -{ - debug_decl(cb_sudoers_locale, SUDOERS_DEBUG_PLUGIN) - - if (sudoers_initlocale(NULL, sd_un->str)) { - if (setlocale(LC_ALL, sd_un->str) != NULL) - debug_return_bool(true); - } - debug_return_bool(false); -} - /* * Cleanup hook for sudo_fatal()/sudo_fatalx() */ diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index 009dfd04c..62d5c2602 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -245,6 +245,9 @@ main(int argc, char *argv[]) /* Set runas callback. */ sudo_defs_table[I_RUNAS_DEFAULT].callback = cb_runas_default; + /* Set locale callback. */ + sudo_defs_table[I_SUDOERS_LOCALE].callback = sudoers_locale_callback; + /* Load ip addr/mask for each interface. */ if (get_net_ifs(&p) > 0) { if (!set_interfaces(p)) diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 4dc9257d0..e4b63a587 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -159,6 +159,9 @@ main(int argc, char *argv[]) /* Register fatal/fatalx callback. */ sudo_fatal_callback_register(visudo_cleanup); + /* Set sudoers locale callback. */ + sudo_defs_table[I_SUDOERS_LOCALE].callback = sudoers_locale_callback; + /* Read debug and plugin sections of sudo.conf. */ if (sudo_conf_read(NULL, SUDO_CONF_DEBUG|SUDO_CONF_PLUGINS) == -1) exit(EXIT_FAILURE); -- 2.40.0