version 1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2012/05/29 12:26:49
|
Line 47
|
Line 47
|
#include "sudo.h" |
#include "sudo.h" |
#include "sudo_plugin.h" |
#include "sudo_plugin.h" |
#include "sudo_plugin_int.h" |
#include "sudo_plugin_int.h" |
|
#include "sudo_conf.h" |
|
#include "sudo_debug.h" |
|
|
#ifndef RTLD_GLOBAL |
#ifndef RTLD_GLOBAL |
# define RTLD_GLOBAL 0 |
# define RTLD_GLOBAL 0 |
#endif |
#endif |
|
|
#ifdef _PATH_SUDO_NOEXEC |
|
const char *noexec_path = _PATH_SUDO_NOEXEC; |
|
#endif |
|
|
|
/* |
/* |
* Read in /etc/sudo.conf | * Load the plugins listed in sudo.conf. |
* Returns a list of plugins. | |
*/ |
*/ |
static struct plugin_info_list * | bool |
sudo_read_conf(const char *conf_file) | sudo_load_plugins(struct plugin_container *policy_plugin, |
{ | |
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, | |
struct plugin_container_list *io_plugins) |
struct plugin_container_list *io_plugins) |
{ |
{ |
|
struct plugin_info_list *plugins; |
struct generic_plugin *plugin; |
struct generic_plugin *plugin; |
struct plugin_container *container; |
struct plugin_container *container; |
struct plugin_info *info; |
struct plugin_info *info; |
struct plugin_info_list *plugin_list; |
|
struct stat sb; |
struct stat sb; |
void *handle; |
void *handle; |
char path[PATH_MAX]; |
char path[PATH_MAX]; |
int rval = FALSE; | bool rval = false; |
| debug_decl(sudo_load_plugins, SUDO_DEBUG_PLUGIN) |
|
|
/* Parse sudo.conf */ | /* Walk plugin list. */ |
plugin_list = sudo_read_conf(conf_file); | plugins = sudo_conf_plugins(); |
| tq_foreach_fwd(plugins, info) { |
tq_foreach_fwd(plugin_list, info) { | |
if (info->path[0] == '/') { |
if (info->path[0] == '/') { |
if (strlcpy(path, info->path, sizeof(path)) >= sizeof(path)) { |
if (strlcpy(path, info->path, sizeof(path)) >= sizeof(path)) { |
warningx(_("%s: %s"), info->path, strerror(ENAMETOOLONG)); |
warningx(_("%s: %s"), info->path, strerror(ENAMETOOLONG)); |
Line 205 sudo_load_plugins(const char *conf_file,
|
Line 126 sudo_load_plugins(const char *conf_file,
|
if (plugin->type == SUDO_POLICY_PLUGIN) { |
if (plugin->type == SUDO_POLICY_PLUGIN) { |
if (policy_plugin->handle) { |
if (policy_plugin->handle) { |
warningx(_("%s: only a single policy plugin may be loaded"), |
warningx(_("%s: only a single policy plugin may be loaded"), |
conf_file); | _PATH_SUDO_CONF); |
goto done; |
goto done; |
} |
} |
policy_plugin->handle = handle; |
policy_plugin->handle = handle; |
policy_plugin->name = info->symbol_name; |
policy_plugin->name = info->symbol_name; |
|
policy_plugin->options = info->options; |
policy_plugin->u.generic = plugin; |
policy_plugin->u.generic = plugin; |
} else if (plugin->type == SUDO_IO_PLUGIN) { |
} else if (plugin->type == SUDO_IO_PLUGIN) { |
container = emalloc(sizeof(*container)); | container = ecalloc(1, sizeof(*container)); |
container->prev = container; |
container->prev = container; |
container->next = NULL; | /* container->next = NULL; */ |
container->handle = handle; |
container->handle = handle; |
container->name = info->symbol_name; |
container->name = info->symbol_name; |
|
container->options = info->options; |
container->u.generic = plugin; |
container->u.generic = plugin; |
tq_append(io_plugins, container); |
tq_append(io_plugins, container); |
} |
} |
} |
} |
if (policy_plugin->handle == NULL) { |
if (policy_plugin->handle == NULL) { |
warningx(_("%s: at least one policy plugin must be specified"), |
warningx(_("%s: at least one policy plugin must be specified"), |
conf_file); | _PATH_SUDO_CONF); |
goto done; |
goto done; |
} |
} |
if (policy_plugin->u.policy->check_policy == NULL) { |
if (policy_plugin->u.policy->check_policy == NULL) { |
Line 232 sudo_load_plugins(const char *conf_file,
|
Line 155 sudo_load_plugins(const char *conf_file,
|
goto done; |
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: |
done: |
return rval; | debug_return_bool(rval); |
} |
} |