Imported Upstream version 1.8.4p4
[debian/sudo] / src / load_plugins.c
index 6bee3f8471dd7f46b6e48e5c24fcc9e3ea07fef3..e86c1432c391521b55169647f100302ef56dea47 100644 (file)
 #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;
-
-    /* Parse sudo.conf */
-    plugin_list = sudo_read_conf(conf_file);
+    bool rval = false;
+    debug_decl(sudo_load_plugins, SUDO_DEBUG_PLUGIN)
 
-    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,7 +126,7 @@ 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;
@@ -223,7 +144,7 @@ sudo_load_plugins(const char *conf_file,
     }
     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 +153,8 @@ sudo_load_plugins(const char *conf_file,
        goto done;
     }
 
-    rval = TRUE;
+    rval = true;
 
 done:
-    return rval;
+    debug_return_bool(rval);
 }