--- embedaddon/sudo/src/load_plugins.c 2012/02/21 16:23:02 1.1.1.1 +++ embedaddon/sudo/src/load_plugins.c 2012/05/29 12:26:49 1.1.1.2 @@ -47,112 +47,33 @@ #include "sudo.h" #include "sudo_plugin.h" #include "sudo_plugin_int.h" +#include "sudo_conf.h" +#include "sudo_debug.h" #ifndef RTLD_GLOBAL # define RTLD_GLOBAL 0 #endif -#ifdef _PATH_SUDO_NOEXEC -const char *noexec_path = _PATH_SUDO_NOEXEC; -#endif - /* - * Read in /etc/sudo.conf - * Returns a list of plugins. + * Load the plugins listed in sudo.conf. */ -static struct plugin_info_list * -sudo_read_conf(const char *conf_file) -{ - FILE *fp; - char *cp, *name, *path; - struct plugin_info *info; - static struct plugin_info_list pil; /* XXX */ - - if ((fp = fopen(conf_file, "r")) == NULL) - goto done; - - while ((cp = sudo_parseln(fp)) != NULL) { - /* Skip blank or comment lines */ - if (*cp == '\0') - continue; - - /* Look for a line starting with "Path" */ - if (strncasecmp(cp, "Path", 4) == 0) { - /* Parse line */ - if ((name = strtok(cp + 4, " \t")) == NULL || - (path = strtok(NULL, " \t")) == NULL) { - continue; - } - if (strcasecmp(name, "askpass") == 0) - askpass_path = estrdup(path); -#ifdef _PATH_SUDO_NOEXEC - else if (strcasecmp(name, "noexec") == 0) - noexec_path = estrdup(path); -#endif - continue; - } - - /* Look for a line starting with "Plugin" */ - if (strncasecmp(cp, "Plugin", 6) == 0) { - /* Parse line */ - if ((name = strtok(cp + 6, " \t")) == NULL || - (path = strtok(NULL, " \t")) == NULL) { - continue; - } - info = emalloc(sizeof(*info)); - info->symbol_name = estrdup(name); - info->path = estrdup(path); - info->prev = info; - info->next = NULL; - tq_append(&pil, info); - continue; - } - } - fclose(fp); - -done: - if (tq_empty(&pil)) { - /* Default policy plugin */ - info = emalloc(sizeof(*info)); - info->symbol_name = "sudoers_policy"; - info->path = SUDOERS_PLUGIN; - info->prev = info; - info->next = NULL; - tq_append(&pil, info); - - /* Default I/O plugin */ - info = emalloc(sizeof(*info)); - info->symbol_name = "sudoers_io"; - info->path = SUDOERS_PLUGIN; - info->prev = info; - info->next = NULL; - tq_append(&pil, info); - } - - return &pil; -} - -/* - * Load the plugins listed in conf_file. - */ -int -sudo_load_plugins(const char *conf_file, - struct plugin_container *policy_plugin, +bool +sudo_load_plugins(struct plugin_container *policy_plugin, struct plugin_container_list *io_plugins) { + struct plugin_info_list *plugins; struct generic_plugin *plugin; struct plugin_container *container; struct plugin_info *info; - struct plugin_info_list *plugin_list; struct stat sb; void *handle; char path[PATH_MAX]; - int rval = FALSE; + bool rval = false; + debug_decl(sudo_load_plugins, SUDO_DEBUG_PLUGIN) - /* Parse sudo.conf */ - plugin_list = sudo_read_conf(conf_file); - - tq_foreach_fwd(plugin_list, info) { + /* Walk plugin list. */ + plugins = sudo_conf_plugins(); + tq_foreach_fwd(plugins, info) { if (info->path[0] == '/') { if (strlcpy(path, info->path, sizeof(path)) >= sizeof(path)) { warningx(_("%s: %s"), info->path, strerror(ENAMETOOLONG)); @@ -205,25 +126,27 @@ sudo_load_plugins(const char *conf_file, if (plugin->type == SUDO_POLICY_PLUGIN) { if (policy_plugin->handle) { warningx(_("%s: only a single policy plugin may be loaded"), - conf_file); + _PATH_SUDO_CONF); goto done; } policy_plugin->handle = handle; policy_plugin->name = info->symbol_name; + policy_plugin->options = info->options; policy_plugin->u.generic = plugin; } else if (plugin->type == SUDO_IO_PLUGIN) { - container = emalloc(sizeof(*container)); + container = ecalloc(1, sizeof(*container)); container->prev = container; - container->next = NULL; + /* container->next = NULL; */ container->handle = handle; container->name = info->symbol_name; + container->options = info->options; container->u.generic = plugin; tq_append(io_plugins, container); } } if (policy_plugin->handle == NULL) { warningx(_("%s: at least one policy plugin must be specified"), - conf_file); + _PATH_SUDO_CONF); goto done; } if (policy_plugin->u.policy->check_policy == NULL) { @@ -232,8 +155,18 @@ sudo_load_plugins(const char *conf_file, goto done; } - rval = TRUE; + /* Install hooks (XXX - later). */ + if (policy_plugin->u.policy->version >= SUDO_API_MKVERSION(1, 2)) { + if (policy_plugin->u.policy->register_hooks != NULL) + policy_plugin->u.policy->register_hooks(SUDO_HOOK_VERSION, register_hook); + tq_foreach_fwd(io_plugins, container) { + if (container->u.io->register_hooks != NULL) + container->u.io->register_hooks(SUDO_HOOK_VERSION, register_hook); + } + } + rval = true; + done: - return rval; + debug_return_bool(rval); }