Move sudoers locale callback function to locale.c and user it in

visudo and testsudoers.
This commit is contained in:
Todd C. Miller
2016-07-20 14:16:00 -06:00
parent 30f7ecca10
commit b5c2ca2fe5
5 changed files with 24 additions and 17 deletions

View File

@@ -37,6 +37,7 @@
#include "sudo_compat.h" #include "sudo_compat.h"
#include "sudo_fatal.h" #include "sudo_fatal.h"
#include "sudoers_debug.h" #include "sudoers_debug.h"
#include "defaults.h"
#include "logging.h" #include "logging.h"
static int current_locale = SUDOERS_LOCALE_USER; 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(*cookie, NULL));
debug_return_bool(sudoers_setlocale(SUDOERS_LOCALE_USER, cookie)); 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);
}

View File

@@ -74,6 +74,7 @@ bool log_failure(int status, int flags);
bool log_warning(int flags, const char *fmt, ...) __printflike(2, 3); bool log_warning(int flags, const char *fmt, ...) __printflike(2, 3);
bool log_warningx(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_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); int writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen);
#endif /* SUDOERS_LOGGING_H */ #endif /* SUDOERS_LOGGING_H */

View File

@@ -71,7 +71,6 @@
static char *find_editor(int nfiles, char **files, int *argc_out, char ***argv_out); 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_fqdn(const union sudo_defs_val *);
static bool cb_runas_default(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 set_cmnd(void);
static int create_admin_success_flag(void); static int create_admin_success_flag(void);
static bool init_vars(char * const *); 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; sudo_defs_table[I_RUNAS_DEFAULT].callback = cb_runas_default;
/* Set locale callback. */ /* 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. */ /* Set maxseq callback. */
sudo_defs_table[I_MAXSEQ].callback = cb_maxseq; 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); 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() * Cleanup hook for sudo_fatal()/sudo_fatalx()
*/ */

View File

@@ -245,6 +245,9 @@ main(int argc, char *argv[])
/* Set runas callback. */ /* Set runas callback. */
sudo_defs_table[I_RUNAS_DEFAULT].callback = cb_runas_default; 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. */ /* Load ip addr/mask for each interface. */
if (get_net_ifs(&p) > 0) { if (get_net_ifs(&p) > 0) {
if (!set_interfaces(p)) if (!set_interfaces(p))

View File

@@ -159,6 +159,9 @@ main(int argc, char *argv[])
/* Register fatal/fatalx callback. */ /* Register fatal/fatalx callback. */
sudo_fatal_callback_register(visudo_cleanup); 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. */ /* Read debug and plugin sections of sudo.conf. */
if (sudo_conf_read(NULL, SUDO_CONF_DEBUG|SUDO_CONF_PLUGINS) == -1) if (sudo_conf_read(NULL, SUDO_CONF_DEBUG|SUDO_CONF_PLUGINS) == -1)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);