From: Todd C. Miller Date: Wed, 16 Nov 2016 17:13:26 +0000 (-0700) Subject: Always define _PATH_SUDO_NOEXEC, _PATH_SUDO_SESH, _PATH_SUDO_PLUGIN_DIR, X-Git-Tag: SUDO_1_8_19^2~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dff4ac7fdb8557de046539c0323801f176076bc;p=sudo Always define _PATH_SUDO_NOEXEC, _PATH_SUDO_SESH, _PATH_SUDO_PLUGIN_DIR, even if only defined to NULL. This means the accessors can always be present. Use RTLD_PRELOAD_VAR instead of _PATH_SUDO_NOEXEC to tell when noexec is available. Add ENABLE_SUDO_PLUGIN_API and use it instead of _PATH_SUDO_PLUGIN_DIR to tell when the plugin API is available. Add sudo_conf_clear_paths() to clear the path values so the regress tests are not affected by compile-time settings. --- diff --git a/config.h.in b/config.h.in index 0fb1b98e2..b07626dd3 100644 --- a/config.h.in +++ b/config.h.in @@ -16,6 +16,9 @@ /* A colon-separated list of pathnames to be used as the editor for visudo. */ #undef EDITOR +/* Define to 1 to enable sudo's plugin interface. */ +#undef ENABLE_SUDO_PLUGIN_API + /* Define to 1 to enable environment function debugging. */ #undef ENV_DEBUG diff --git a/configure b/configure index d16b64e98..645faa2c2 100755 --- a/configure +++ b/configure @@ -24396,14 +24396,29 @@ EOF #define _PATH_SUDO_PLUGIN_DIR "$PLUGINDIR/" EOF + +$as_echo "#define ENABLE_SUDO_PLUGIN_API 1" >>confdefs.h + fi exec_prefix="$oexec_prefix" +fi +if test X"$with_noexec" = X"no"; then + cat >>confdefs.h <>confdefs.h <>confdefs.h <symbol_name, info->path); if (info->options) { diff --git a/lib/util/regress/sudo_conf/test1.out.ok b/lib/util/regress/sudo_conf/test1.out.ok index 54e067180..18807483d 100644 --- a/lib/util/regress/sudo_conf/test1.out.ok +++ b/lib/util/regress/sudo_conf/test1.out.ok @@ -2,5 +2,6 @@ Set disable_coredump false Set group_source static Set max_groups -1 Path askpass /usr/X11R6/bin/ssh-askpass +Path noexec /usr/libexec/sudo_noexec.so Plugin sudoers_policy sudoers.so Plugin sudoers_io sudoers.so diff --git a/lib/util/sudo_conf.c b/lib/util/sudo_conf.c index d7988e793..f5dd57a9d 100644 --- a/lib/util/sudo_conf.c +++ b/lib/util/sudo_conf.c @@ -55,14 +55,6 @@ # define ROOT_UID 0 #endif -/* Avoid excessive #ifdefs in the code. */ -#ifndef _PATH_SUDO_NOEXEC -# define _PATH_SUDO_NOEXEC NULL -#endif -#ifndef _PATH_SUDO_PLUGIN_DIR -# define _PATH_SUDO_PLUGIN_DIR NULL -#endif - struct sudo_conf_table { const char *name; unsigned int namelen; @@ -631,3 +623,16 @@ done: free(prev_locale); debug_return_int(ret); } + +/* + * Used by the sudo_conf regress test to clear compile-time path settings. + */ +void +sudo_conf_clear_paths_v1(void) +{ + struct sudo_conf_path_table *cur; + debug_decl(sudo_conf_clear_paths, SUDO_DEBUG_UTIL) + + for (cur = sudo_conf_data.path_table; cur->pname != NULL; cur++) + cur->pval = NULL; +} diff --git a/lib/util/util.exp.in b/lib/util/util.exp.in index d29a00669..0164491e8 100644 --- a/lib/util/util.exp.in +++ b/lib/util/util.exp.in @@ -1,5 +1,6 @@ @COMPAT_EXP@initprogname sudo_conf_askpass_path_v1 +sudo_conf_clear_paths_v1 sudo_conf_debug_files_v1 sudo_conf_debugging_v1 sudo_conf_disable_coredump_v1 diff --git a/plugins/sudoers/policy.c b/plugins/sudoers/policy.c index 08ac25a81..2fa684b98 100644 --- a/plugins/sudoers/policy.c +++ b/plugins/sudoers/policy.c @@ -256,7 +256,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group) remhost = *cur + sizeof("remote_host=") - 1; continue; } -#ifdef _PATH_SUDO_PLUGIN_DIR +#ifdef ENABLE_SUDO_PLUGIN_API if (MATCHES(*cur, "plugin_dir=")) { path_plugin_dir = *cur + sizeof("plugin_dir=") - 1; continue; diff --git a/src/exec_common.c b/src/exec_common.c index 9dd2b2b8c..f0b345d26 100644 --- a/src/exec_common.c +++ b/src/exec_common.c @@ -36,7 +36,7 @@ #include "sudo.h" #include "sudo_exec.h" -#ifdef _PATH_SUDO_NOEXEC +#ifdef RTLD_PRELOAD_VAR /* * Add a DSO file to LD_PRELOAD or the system equivalent. */ @@ -144,7 +144,7 @@ preload_dso(char *envp[], const char *dso_file) debug_return_ptr(envp); } -#endif /* _PATH_SUDO_NOEXEC */ +#endif /* RTLD_PRELOAD_VAR */ /* * Disable execution of child processes in the command we are about @@ -166,10 +166,10 @@ disable_execute(char *envp[], const char *dso) sudo_warn(U_("unable to remove PRIV_PROC_EXEC from PRIV_LIMIT")); #endif /* HAVE_PRIV_SET */ -#ifdef _PATH_SUDO_NOEXEC +#ifdef RTLD_PRELOAD_VAR if (dso != NULL) envp = preload_dso(envp, dso); -#endif /* _PATH_SUDO_NOEXEC */ +#endif /* RTLD_PRELOAD_VAR */ debug_return_ptr(envp); } diff --git a/src/load_plugins.c b/src/load_plugins.c index 5fd6eafbf..fb620b121 100644 --- a/src/load_plugins.c +++ b/src/load_plugins.c @@ -37,7 +37,7 @@ /* We always use the same name for the sudoers plugin, regardless of the OS */ #define SUDOERS_PLUGIN "sudoers.so" -#ifdef _PATH_SUDO_PLUGIN_DIR +#ifdef ENABLE_SUDO_PLUGIN_API static int sudo_stat_plugin(struct plugin_info *info, char *fullpath, size_t pathsize, struct stat *sb) @@ -144,7 +144,7 @@ sudo_check_plugin(struct plugin_info *info, char *fullpath, size_t pathsize) (void)strlcpy(fullpath, info->path, pathsize); debug_return_bool(true); } -#endif /* _PATH_SUDO_PLUGIN_DIR */ +#endif /* ENABLE_SUDO_PLUGIN_API */ /* * Load the plugin specified by "info". diff --git a/src/parse_args.c b/src/parse_args.c index 22efddd72..b6dd2b87a 100644 --- a/src/parse_args.c +++ b/src/parse_args.c @@ -441,7 +441,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, SET(flags, (MODE_IMPLIED_SHELL | MODE_SHELL)); sudo_settings[ARG_IMPLIED_SHELL].value = "true"; } -#ifdef _PATH_SUDO_PLUGIN_DIR +#ifdef ENABLE_SUDO_PLUGIN_API sudo_settings[ARG_PLUGIN_DIR].value = sudo_conf_plugin_dir_path(); #endif