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

version 1.1.1.3, 2012/10/09 09:29:52 version 1.1.1.4, 2013/07/22 10:46:13
Line 1 Line 1
 /*  /*
 * Copyright (c) 2009-2011 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 17 Line 17
 #include <config.h>  #include <config.h>
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/param.h>  
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <stdio.h>  #include <stdio.h>
 #ifdef STDC_HEADERS  #ifdef STDC_HEADERS
Line 54 Line 53
 # define RTLD_GLOBAL    0  # define RTLD_GLOBAL    0
 #endif  #endif
   
/*#ifndef SUDOERS_PLUGIN
 * Load the plugin specified by "info".# define SUDOERS_PLUGIN "sudoers.la"
 */#endif
static bool
sudo_load_plugin(struct plugin_container *policy_plugin,#ifdef _PATH_SUDO_PLUGIN_DIR
    struct plugin_container_list *io_plugins, struct plugin_info *info)static int
 sudo_stat_plugin(struct plugin_info *info, char *fullpath,
     size_t pathsize, struct stat *sb)
 {  {
    struct plugin_container *container;    int status = -1;
    struct generic_plugin *plugin;    debug_decl(sudo_stat_plugin, SUDO_DEBUG_PLUGIN)
    struct stat sb; 
    void *handle; 
    char path[PATH_MAX]; 
    bool rval = false; 
    debug_decl(sudo_load_plugin, SUDO_DEBUG_PLUGIN) 
   
     if (info->path[0] == '/') {      if (info->path[0] == '/') {
        if (strlcpy(path, info->path, sizeof(path)) >= sizeof(path)) {        if (strlcpy(fullpath, info->path, pathsize) >= pathsize) {
             warningx(_("error in %s, line %d while loading plugin `%s'"),
                 _PATH_SUDO_CONF, info->lineno, info->symbol_name);
             warningx(_("%s: %s"), info->path, strerror(ENAMETOOLONG));              warningx(_("%s: %s"), info->path, strerror(ENAMETOOLONG));
             goto done;              goto done;
         }          }
           status = stat(fullpath, sb);
     } else {      } else {
        if (snprintf(path, sizeof(path), "%s%s", _PATH_SUDO_PLUGIN_DIR,        if (snprintf(fullpath, pathsize, "%s%s", _PATH_SUDO_PLUGIN_DIR,
            info->path) >= sizeof(path)) {            info->path) >= pathsize) {
             warningx(_("error in %s, line %d while loading plugin `%s'"),
                 _PATH_SUDO_CONF, info->lineno, info->symbol_name);
             warningx(_("%s%s: %s"), _PATH_SUDO_PLUGIN_DIR, info->path,              warningx(_("%s%s: %s"), _PATH_SUDO_PLUGIN_DIR, info->path,
                 strerror(ENAMETOOLONG));                  strerror(ENAMETOOLONG));
             goto done;              goto done;
         }          }
           /* Try parent dir for compatibility with old plugindir default. */
           if ((status = stat(fullpath, sb)) != 0) {
               char *cp = strrchr(fullpath, '/');
               if (cp > fullpath + 4 && cp[-5] == '/' && cp[-4] == 's' &&
                   cp[-3] == 'u' && cp[-2] == 'd' && cp[-1] == 'o') {
                   int serrno = errno;
                   strlcpy(cp - 4, info->path, pathsize - (cp - 4 - fullpath));
                   if ((status = stat(fullpath, sb)) != 0)
                       errno = serrno;
               }
           }
   # ifdef __hpux
           /* Try .sl instead of .so on HP-UX for backwards compatibility. */
           if (status != 0) {
               size_t len = strlen(info->path);
               if (len >= 3 && info->path[len - 3] == '.' &&
                   info->path[len - 2] == 's' && info->path[len - 1] == 'o') {
                   const char *sopath = info->path;
                   char *slpath = estrdup(info->path);
                   int serrno = errno;
   
                   slpath[len - 1] = 'l';
                   info->path = slpath;
                   status = sudo_stat_plugin(info, fullpath, pathsize, sb);
                   if (status == 0) {
                       efree((void *)sopath);
                   } else {
                       efree(slpath);
                       info->path = sopath;
                       errno = serrno;
                   }
               }
           }
   # endif /* __hpux */
     }      }
    if (stat(path, &sb) != 0) {done:
        warning("%s", path);    debug_return_int(status);
 }
 
 static bool
 sudo_check_plugin(struct plugin_info *info, char *fullpath, size_t pathsize)
 {
     struct stat sb;
     int rval = false;
     debug_decl(sudo_check_plugin, SUDO_DEBUG_PLUGIN)
 
     if (sudo_stat_plugin(info, fullpath, pathsize, &sb) != 0) {
         warningx(_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         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(_("%s must be owned by uid %d"), path, ROOT_UID);        warningx(_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         warningx(_("%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(_("%s must be only be writable by owner"), path);        warningx(_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         warningx(_("%s must be only be writable by owner"), fullpath);
         goto done;          goto done;
     }      }
       rval = true;
   
   done:
       debug_return_bool(rval);
   }
   #else
   static bool
   sudo_check_plugin(struct plugin_info *info, char *fullpath, size_t pathsize)
   {
       debug_decl(sudo_check_plugin, SUDO_DEBUG_PLUGIN)
       (void)strlcpy(fullpath, info->path, pathsize);
       debug_return_bool(true);
   }
   #endif /* _PATH_SUDO_PLUGIN_DIR */
   
   /*
    * Load the plugin specified by "info".
    */
   static bool
   sudo_load_plugin(struct plugin_container *policy_plugin,
       struct plugin_container_list *io_plugins, struct plugin_info *info)
   {
       struct plugin_container *container;
       struct generic_plugin *plugin;
       char path[PATH_MAX];
       bool rval = false;
       void *handle;
       debug_decl(sudo_load_plugin, SUDO_DEBUG_PLUGIN)
   
       /* Sanity check plugin and fill in path */
       if (!sudo_check_plugin(info, path, sizeof(path)))
           goto done;
   
     /* Open plugin and map in symbol */      /* Open plugin and map in symbol */
     handle = dlopen(path, RTLD_LAZY|RTLD_GLOBAL);      handle = dlopen(path, RTLD_LAZY|RTLD_GLOBAL);
     if (!handle) {      if (!handle) {
           warningx(_("error in %s, line %d while loading plugin `%s'"),
               _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         warningx(_("unable to dlopen %s: %s"), path, dlerror());          warningx(_("unable to dlopen %s: %s"), path, dlerror());
         goto done;          goto done;
     }      }
     plugin = dlsym(handle, info->symbol_name);      plugin = dlsym(handle, info->symbol_name);
     if (!plugin) {      if (!plugin) {
        warningx(_("%s: unable to find symbol %s"), path,        warningx(_("error in %s, line %d while loading plugin `%s'"),
            info->symbol_name);            _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         warningx(_("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(_("%s: unknown policy type %d"), path, plugin->type);        warningx(_("error in %s, line %d while loading plugin `%s'"),
             _PATH_SUDO_CONF, info->lineno, info->symbol_name);
         warningx(_("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(_("%s: incompatible policy major version %d, expected %d"),        warningx(_("error in %s, line %d while loading plugin `%s'"),
            path, SUDO_API_VERSION_GET_MAJOR(plugin->version),            _PATH_SUDO_CONF, info->lineno, info->symbol_name);
            SUDO_API_VERSION_MAJOR);        warningx(_("incompatible plugin major version %d (expected %d) found in %s"),
             SUDO_API_VERSION_GET_MAJOR(plugin->version),
             SUDO_API_VERSION_MAJOR, path);
         goto done;          goto done;
     }      }
     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"),            /* Ignore duplicate entries. */
                _PATH_SUDO_CONF);            if (strcmp(policy_plugin->name, info->symbol_name) != 0) {
            goto done;                warningx(_("ignoring policy plugin `%s' in %s, line %d"),
                     info->symbol_name, _PATH_SUDO_CONF, info->lineno);
                 warningx(_("only a single policy plugin may be specified"));
                 goto done;
             }
             warningx(_("ignoring duplicate policy plugin `%s' in %s, line %d"),
                 info->symbol_name, _PATH_SUDO_CONF, info->lineno);
             dlclose(handle);
             handle = NULL;
         }          }
        policy_plugin->handle = handle;        if (handle != NULL) {
        policy_plugin->name = info->symbol_name;            policy_plugin->handle = handle;
        policy_plugin->options = info->options;            policy_plugin->name = info->symbol_name;
        policy_plugin->u.generic = plugin;            policy_plugin->options = info->options;
             policy_plugin->u.generic = plugin;
         }
     } else if (plugin->type == SUDO_IO_PLUGIN) {      } else if (plugin->type == SUDO_IO_PLUGIN) {
        container = ecalloc(1, sizeof(*container));        /* Check for duplicate entries. */
        container->prev = container;        tq_foreach_fwd(io_plugins, container) {
        /* container->next = NULL; */            if (strcmp(container->name, info->symbol_name) == 0) {
        container->handle = handle;                warningx(_("ignoring duplicate I/O plugin `%s' in %s, line %d"),
        container->name = info->symbol_name;                    info->symbol_name, _PATH_SUDO_CONF, info->lineno);
        container->options = info->options;                dlclose(handle);
        container->u.generic = plugin;                handle = NULL;
        tq_append(io_plugins, container);                break;
             }
         }
         if (handle != NULL) {
             container = ecalloc(1, sizeof(*container));
             container->prev = container;
             /* container->next = NULL; */
             container->handle = handle;
             container->name = info->symbol_name;
             container->options = info->options;
             container->u.generic = plugin;
             tq_append(io_plugins, container);
         }
     }      }
   
     rval = true;      rval = true;

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


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