Diff for /embedaddon/sudo/src/load_plugins.c between versions 1.1.1.4 and 1.1.1.5

version 1.1.1.4, 2013/07/22 10:46:13 version 1.1.1.5, 2014/06/15 16:12:55
Line 36 Line 36
 #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
 # include <unistd.h>  # include <unistd.h>
 #endif /* HAVE_UNISTD_H */  #endif /* HAVE_UNISTD_H */
 #ifdef HAVE_DLOPEN  
 # include <dlfcn.h>  
 #else  
 # include "compat/dlfcn.h"  
 #endif  
 #include <errno.h>  #include <errno.h>
   
 #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_conf.h"
   #include "sudo_dso.h"
 #include "sudo_debug.h"  #include "sudo_debug.h"
   
#ifndef RTLD_GLOBAL/* We always use the same name for the sudoers plugin, regardless of the OS */
# define RTLD_GLOBAL     0#define SUDOERS_PLUGIN  "sudoers.so"
#endif 
   
 #ifndef SUDOERS_PLUGIN  
 # define SUDOERS_PLUGIN "sudoers.la"  
 #endif  
   
 #ifdef _PATH_SUDO_PLUGIN_DIR  #ifdef _PATH_SUDO_PLUGIN_DIR
 static int  static int
 sudo_stat_plugin(struct plugin_info *info, char *fullpath,  sudo_stat_plugin(struct plugin_info *info, char *fullpath,
Line 67  sudo_stat_plugin(struct plugin_info *info, char *fullp Line 58  sudo_stat_plugin(struct plugin_info *info, char *fullp
   
     if (info->path[0] == '/') {      if (info->path[0] == '/') {
         if (strlcpy(fullpath, info->path, pathsize) >= pathsize) {          if (strlcpy(fullpath, info->path, pathsize) >= pathsize) {
            warningx(_("error in %s, line %d while loading plugin `%s'"),            warningx(U_("error in %s, line %d while loading plugin `%s'"),
                 _PATH_SUDO_CONF, info->lineno, info->symbol_name);                  _PATH_SUDO_CONF, info->lineno, info->symbol_name);
            warningx(_("%s: %s"), info->path, strerror(ENAMETOOLONG));            warningx(U_("%s: %s"), info->path, strerror(ENAMETOOLONG));
             goto done;              goto done;
         }          }
         status = stat(fullpath, sb);          status = stat(fullpath, sb);
     } else {      } else {
        if (snprintf(fullpath, pathsize, "%s%s", _PATH_SUDO_PLUGIN_DIR,        int len;
            info->path) >= pathsize) {
            warningx(_("error in %s, line %d while loading plugin `%s'"),#ifdef STATIC_SUDOERS_PLUGIN
         /* Check static symbols. */
         if (strcmp(info->path, SUDOERS_PLUGIN) == 0) {
             if (strlcpy(fullpath, info->path, pathsize) >= pathsize) {
                 warningx(U_("error in %s, line %d while loading plugin `%s'"),
                     _PATH_SUDO_CONF, info->lineno, info->symbol_name);
                 warningx(U_("%s: %s"), info->path, strerror(ENAMETOOLONG));
                 goto done;
             }
             /* Plugin is static, fake up struct stat. */
             memset(sb, 0, sizeof(*sb));
             sb->st_uid = ROOT_UID;
             sb->st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
             status = 0;
             goto done;
         }
 #endif /* STATIC_SUDOERS_PLUGIN */
 
         len = snprintf(fullpath, pathsize, "%s%s", _PATH_SUDO_PLUGIN_DIR,
             info->path);
         if (len <= 0 || (size_t)len >= pathsize) {
             warningx(U_("error in %s, line %d while loading plugin `%s'"),
                 _PATH_SUDO_CONF, info->lineno, info->symbol_name);                  _PATH_SUDO_CONF, info->lineno, info->symbol_name);
            warningx(_("%s%s: %s"), _PATH_SUDO_PLUGIN_DIR, info->path,            warningx(U_("%s%s: %s"), _PATH_SUDO_PLUGIN_DIR, info->path,
                 strerror(ENAMETOOLONG));                  strerror(ENAMETOOLONG));
             goto done;              goto done;
         }          }
Line 129  sudo_check_plugin(struct plugin_info *info, char *full Line 141  sudo_check_plugin(struct plugin_info *info, char *full
     debug_decl(sudo_check_plugin, SUDO_DEBUG_PLUGIN)      debug_decl(sudo_check_plugin, SUDO_DEBUG_PLUGIN)
   
     if (sudo_stat_plugin(info, fullpath, pathsize, &sb) != 0) {      if (sudo_stat_plugin(info, fullpath, pathsize, &sb) != 0) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         warning("%s%s", _PATH_SUDO_PLUGIN_DIR, info->path);          warning("%s%s", _PATH_SUDO_PLUGIN_DIR, info->path);
         goto done;          goto done;
     }      }
     if (sb.st_uid != ROOT_UID) {      if (sb.st_uid != ROOT_UID) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        warningx(_("%s must be owned by uid %d"), fullpath, ROOT_UID);        warningx(U_("%s must be owned by uid %d"), fullpath, ROOT_UID);
         goto done;          goto done;
     }      }
     if ((sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {      if ((sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        warningx(_("%s must be only be writable by owner"), fullpath);        warningx(U_("%s must be only be writable by owner"), fullpath);
         goto done;          goto done;
     }      }
     rval = true;      rval = true;
Line 180  sudo_load_plugin(struct plugin_container *policy_plugi Line 192  sudo_load_plugin(struct plugin_container *policy_plugi
         goto done;          goto done;
   
     /* Open plugin and map in symbol */      /* Open plugin and map in symbol */
    handle = dlopen(path, RTLD_LAZY|RTLD_GLOBAL);    handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
     if (!handle) {      if (!handle) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        warningx(_("unable to dlopen %s: %s"), path, dlerror());        warningx(U_("unable to load %s: %s"), path, sudo_dso_strerror());
         goto done;          goto done;
     }      }
    plugin = dlsym(handle, info->symbol_name);    plugin = sudo_dso_findsym(handle, info->symbol_name);
     if (!plugin) {      if (!plugin) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        warningx(_("unable to find symbol `%s' in %s"), info->symbol_name, path);        warningx(U_("unable to find symbol `%s' in %s"), info->symbol_name, path);
         goto done;          goto done;
     }      }
   
     if (plugin->type != SUDO_POLICY_PLUGIN && plugin->type != SUDO_IO_PLUGIN) {      if (plugin->type != SUDO_POLICY_PLUGIN && plugin->type != SUDO_IO_PLUGIN) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        warningx(_("unknown policy type %d found in %s"), plugin->type, path);        warningx(U_("unknown policy type %d found in %s"), plugin->type, path);
         goto done;          goto done;
     }      }
     if (SUDO_API_VERSION_GET_MAJOR(plugin->version) != SUDO_API_VERSION_MAJOR) {      if (SUDO_API_VERSION_GET_MAJOR(plugin->version) != SUDO_API_VERSION_MAJOR) {
        warningx(_("error in %s, line %d while loading plugin `%s'"),        warningx(U_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);              _PATH_SUDO_CONF, info->lineno, info->symbol_name);
        warningx(_("incompatible plugin major version %d (expected %d) found in %s"),        warningx(U_("incompatible plugin major version %d (expected %d) found in %s"),
             SUDO_API_VERSION_GET_MAJOR(plugin->version),              SUDO_API_VERSION_GET_MAJOR(plugin->version),
             SUDO_API_VERSION_MAJOR, path);              SUDO_API_VERSION_MAJOR, path);
         goto done;          goto done;
Line 213  sudo_load_plugin(struct plugin_container *policy_plugi Line 225  sudo_load_plugin(struct plugin_container *policy_plugi
         if (policy_plugin->handle) {          if (policy_plugin->handle) {
             /* Ignore duplicate entries. */              /* Ignore duplicate entries. */
             if (strcmp(policy_plugin->name, info->symbol_name) != 0) {              if (strcmp(policy_plugin->name, info->symbol_name) != 0) {
                warningx(_("ignoring policy plugin `%s' in %s, line %d"),                warningx(U_("ignoring policy plugin `%s' in %s, line %d"),
                     info->symbol_name, _PATH_SUDO_CONF, info->lineno);                      info->symbol_name, _PATH_SUDO_CONF, info->lineno);
                warningx(_("only a single policy plugin may be specified"));                warningx(U_("only a single policy plugin may be specified"));
                 goto done;                  goto done;
             }              }
            warningx(_("ignoring duplicate policy plugin `%s' in %s, line %d"),            warningx(U_("ignoring duplicate policy plugin `%s' in %s, line %d"),
                 info->symbol_name, _PATH_SUDO_CONF, info->lineno);                  info->symbol_name, _PATH_SUDO_CONF, info->lineno);
            dlclose(handle);            sudo_dso_unload(handle);
             handle = NULL;              handle = NULL;
         }          }
         if (handle != NULL) {          if (handle != NULL) {
Line 231  sudo_load_plugin(struct plugin_container *policy_plugi Line 243  sudo_load_plugin(struct plugin_container *policy_plugi
         }          }
     } else if (plugin->type == SUDO_IO_PLUGIN) {      } else if (plugin->type == SUDO_IO_PLUGIN) {
         /* Check for duplicate entries. */          /* Check for duplicate entries. */
        tq_foreach_fwd(io_plugins, container) {        TAILQ_FOREACH(container, io_plugins, entries) {
             if (strcmp(container->name, info->symbol_name) == 0) {              if (strcmp(container->name, info->symbol_name) == 0) {
                warningx(_("ignoring duplicate I/O plugin `%s' in %s, line %d"),                warningx(U_("ignoring duplicate I/O plugin `%s' in %s, line %d"),
                     info->symbol_name, _PATH_SUDO_CONF, info->lineno);                      info->symbol_name, _PATH_SUDO_CONF, info->lineno);
                dlclose(handle);                sudo_dso_unload(handle);
                 handle = NULL;                  handle = NULL;
                 break;                  break;
             }              }
         }          }
         if (handle != NULL) {          if (handle != NULL) {
             container = ecalloc(1, sizeof(*container));              container = ecalloc(1, sizeof(*container));
             container->prev = container;  
             /* container->next = NULL; */  
             container->handle = handle;              container->handle = handle;
             container->name = info->symbol_name;              container->name = info->symbol_name;
             container->options = info->options;              container->options = info->options;
             container->u.generic = plugin;              container->u.generic = plugin;
            tq_append(io_plugins, container);            TAILQ_INSERT_TAIL(io_plugins, container, entries);
         }          }
     }      }
   
Line 272  sudo_load_plugins(struct plugin_container *policy_plug Line 282  sudo_load_plugins(struct plugin_container *policy_plug
   
     /* Walk the plugin list from sudo.conf, if any. */      /* Walk the plugin list from sudo.conf, if any. */
     plugins = sudo_conf_plugins();      plugins = sudo_conf_plugins();
    tq_foreach_fwd(plugins, info) {    TAILQ_FOREACH(info, plugins, entries) {
         rval = sudo_load_plugin(policy_plugin, io_plugins, info);          rval = sudo_load_plugin(policy_plugin, io_plugins, info);
         if (!rval)          if (!rval)
             goto done;              goto done;
Line 288  sudo_load_plugins(struct plugin_container *policy_plug Line 298  sudo_load_plugins(struct plugin_container *policy_plug
         info->symbol_name = "sudoers_policy";          info->symbol_name = "sudoers_policy";
         info->path = SUDOERS_PLUGIN;          info->path = SUDOERS_PLUGIN;
         /* info->options = NULL; */          /* info->options = NULL; */
         info->prev = info;  
         /* info->next = NULL; */  
         rval = sudo_load_plugin(policy_plugin, io_plugins, info);          rval = sudo_load_plugin(policy_plugin, io_plugins, info);
         efree(info);          efree(info);
         if (!rval)          if (!rval)
             goto done;              goto done;
   
         /* Default I/O plugin */          /* Default I/O plugin */
        if (tq_empty(io_plugins)) {        if (TAILQ_EMPTY(io_plugins)) {
             info = ecalloc(1, sizeof(*info));              info = ecalloc(1, sizeof(*info));
             info->symbol_name = "sudoers_io";              info->symbol_name = "sudoers_io";
             info->path = SUDOERS_PLUGIN;              info->path = SUDOERS_PLUGIN;
             /* info->options = NULL; */              /* info->options = NULL; */
             info->prev = info;  
             /* info->next = NULL; */  
             rval = sudo_load_plugin(policy_plugin, io_plugins, info);              rval = sudo_load_plugin(policy_plugin, io_plugins, info);
             efree(info);              efree(info);
             if (!rval)              if (!rval)
Line 310  sudo_load_plugins(struct plugin_container *policy_plug Line 316  sudo_load_plugins(struct plugin_container *policy_plug
         }          }
     }      }
     if (policy_plugin->u.policy->check_policy == NULL) {      if (policy_plugin->u.policy->check_policy == NULL) {
        warningx(_("policy plugin %s does not include a check_policy method"),        warningx(U_("policy plugin %s does not include a check_policy method"),
             policy_plugin->name);              policy_plugin->name);
         rval = false;          rval = false;
         goto done;          goto done;
Line 321  sudo_load_plugins(struct plugin_container *policy_plug Line 327  sudo_load_plugins(struct plugin_container *policy_plug
         if (policy_plugin->u.policy->register_hooks != NULL)          if (policy_plugin->u.policy->register_hooks != NULL)
             policy_plugin->u.policy->register_hooks(SUDO_HOOK_VERSION, register_hook);              policy_plugin->u.policy->register_hooks(SUDO_HOOK_VERSION, register_hook);
     }      }
    tq_foreach_fwd(io_plugins, container) {    TAILQ_FOREACH(container, io_plugins, entries) {
         if (container->u.io->version >= SUDO_API_MKVERSION(1, 2)) {          if (container->u.io->version >= SUDO_API_MKVERSION(1, 2)) {
             if (container->u.io->register_hooks != NULL)              if (container->u.io->register_hooks != NULL)
                 container->u.io->register_hooks(SUDO_HOOK_VERSION, register_hook);                  container->u.io->register_hooks(SUDO_HOOK_VERSION, register_hook);

Removed from v.1.1.1.4  
changed lines
  Added in v.1.1.1.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>