From 9b42640ef50e0bd5c532ce6230c949510679e6fc Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 18 Jul 2016 12:11:25 -0600 Subject: [PATCH] Change defaults callbacks to take a union sudo_defs_val * instead of a char *. --- plugins/sudoers/defaults.c | 12 ++++++------ plugins/sudoers/defaults.h | 24 +++++++++++++----------- plugins/sudoers/iolog.c | 15 ++++++++++++++- plugins/sudoers/sudoers.c | 15 ++++++++------- plugins/sudoers/sudoers.h | 2 +- plugins/sudoers/testsudoers.c | 6 +++--- 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/plugins/sudoers/defaults.c b/plugins/sudoers/defaults.c index b1916f0ae..c63c4373d 100644 --- a/plugins/sudoers/defaults.c +++ b/plugins/sudoers/defaults.c @@ -656,7 +656,7 @@ store_int(char *val, struct sudo_defs_types *def, int op) def->sd_un.ival = i; } if (def->callback) - debug_return_bool(def->callback(val)); + debug_return_bool(def->callback(&def->sd_un)); debug_return_bool(true); } @@ -679,7 +679,7 @@ store_uint(char *val, struct sudo_defs_types *def, int op) def->sd_un.uival = u; } if (def->callback) - debug_return_bool(def->callback(val)); + debug_return_bool(def->callback(&def->sd_un)); debug_return_bool(true); } @@ -700,7 +700,7 @@ store_float(char *val, struct sudo_defs_types *def, int op) def->sd_un.fval = d; } if (def->callback) - debug_return_bool(def->callback(val)); + debug_return_bool(def->callback(&def->sd_un)); debug_return_bool(true); } @@ -728,7 +728,7 @@ store_tuple(char *val, struct sudo_defs_types *def, int op) debug_return_bool(false); } if (def->callback) - debug_return_bool(def->callback(val)); + debug_return_bool(def->callback(&def->sd_un)); debug_return_bool(true); } @@ -747,7 +747,7 @@ store_str(char *val, struct sudo_defs_types *def, int op) } } if (def->callback) - debug_return_int(def->callback(val)); + debug_return_int(def->callback(&def->sd_un)); debug_return_int(true); } @@ -861,7 +861,7 @@ store_mode(char *val, struct sudo_defs_types *def, int op) def->sd_un.mode = mode; } if (def->callback) - debug_return_bool(def->callback(val)); + debug_return_bool(def->callback(&def->sd_un)); debug_return_bool(true); } diff --git a/plugins/sudoers/defaults.h b/plugins/sudoers/defaults.h index 03f327bdd..d7827c92c 100644 --- a/plugins/sudoers/defaults.h +++ b/plugins/sudoers/defaults.h @@ -43,6 +43,17 @@ struct def_values { enum def_tuple nval;/* numeric value */ }; +union sudo_defs_val { + int flag; + int ival; + unsigned int uival; + double fval; + enum def_tuple tuple; + char *str; + mode_t mode; + struct list_members list; +}; + /* * Structure describing compile-time and run-time options. */ @@ -51,17 +62,8 @@ struct sudo_defs_types { int type; char *desc; struct def_values *values; - bool (*callback)(const char *); - union { - int flag; - int ival; - unsigned int uival; - double fval; - enum def_tuple tuple; - char *str; - mode_t mode; - struct list_members list; - } sd_un; + bool (*callback)(const union sudo_defs_val *); + union sudo_defs_val sd_un; }; /* diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index bde966ec3..61c313089 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -154,7 +154,7 @@ io_mkdirs(char *path, mode_t mode, bool is_temp) /* * Set max session ID (aka sequence number) */ -bool +static bool io_set_max_sessid(const char *maxval) { const char *errstr; @@ -175,6 +175,19 @@ io_set_max_sessid(const char *maxval) debug_return_bool(true); } +/* + * Sudoers callback for maxseq Defaults setting. + */ +bool +cb_maxseq(const union sudo_defs_val *sd_un) +{ + debug_decl(cb_maxseq, SUDOERS_DEBUG_UTIL) + + /* Clamp value to SESSID_MAX as documented. */ + sessid_max = sd_un->uival < SESSID_MAX ? sd_un->uival : SESSID_MAX; + debug_return_bool(true); +} + /* * Read the on-disk sequence number, set sessid to the next * number, and update the on-disk copy. diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index f44b00dfe..0c4e56b50 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -69,8 +69,8 @@ * Prototypes */ static char *find_editor(int nfiles, char **files, int *argc_out, char ***argv_out); -static bool cb_runas_default(const char *); -static bool cb_sudoers_locale(const char *); +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 *); @@ -753,7 +753,7 @@ init_vars(char * const envp[]) sudo_defs_table[I_SUDOERS_LOCALE].callback = cb_sudoers_locale; /* Set maxseq callback. */ - sudo_defs_table[I_MAXSEQ].callback = io_set_max_sessid; + sudo_defs_table[I_MAXSEQ].callback = cb_maxseq; /* It is now safe to use log_warningx() and set_perms() */ if (unknown_user) { @@ -761,6 +761,7 @@ init_vars(char * const envp[]) (unsigned int) user_uid); debug_return_bool(false); } + debug_return_bool(true); } @@ -1171,11 +1172,11 @@ set_runasgr(const char *group, bool quiet) * Callback for runas_default sudoers setting. */ static bool -cb_runas_default(const char *user) +cb_runas_default(const union sudo_defs_val *sd_un) { /* Only reset runaspw if user didn't specify one. */ if (!runas_user && !runas_group) - return set_runaspw(user, true); + return set_runaspw(sd_un->str, true); return true; } @@ -1183,9 +1184,9 @@ cb_runas_default(const char *user) * Callback for sudoers_locale sudoers setting. */ static bool -cb_sudoers_locale(const char *locale) +cb_sudoers_locale(const union sudo_defs_val *sd_un) { - return sudoers_initlocale(NULL, locale); + return sudoers_initlocale(NULL, sd_un->str); } /* diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 6f41aeb2e..4f988f946 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -317,7 +317,7 @@ bool get_boottime(struct timespec *); /* iolog.c */ bool io_nextid(char *iolog_dir, char *iolog_dir_fallback, char sessid[7]); -bool io_set_max_sessid(const char *sessid); +bool cb_maxseq(const union sudo_defs_val *sd_un); /* iolog_path.c */ char *expand_iolog_path(const char *prefix, const char *dir, const char *file, diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index f59c448db..009dfd04c 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -71,7 +71,7 @@ void print_userspecs(void); void usage(void) __attribute__((__noreturn__)); static void set_runaspw(const char *); static void set_runasgr(const char *); -static bool cb_runas_default(const char *); +static bool cb_runas_default(const union sudo_defs_val *); static int testsudoers_print(const char *msg); extern void setgrfile(const char *); @@ -392,11 +392,11 @@ set_runasgr(const char *group) * Callback for runas_default sudoers setting. */ static bool -cb_runas_default(const char *user) +cb_runas_default(const union sudo_defs_val *sd_un) { /* Only reset runaspw if user didn't specify one. */ if (!runas_user && !runas_group) - set_runaspw(user); + set_runaspw(sd_un->str); return true; } -- 2.40.0