Esempio n. 1
0
/*
 * Load a plugin from a file
 * @param  path  the path to the plugin
 * @returns the plugin or NULL
 */
AbstractPlugin *DlOpenPluginLoader::LoadPlugin(const string &path) {
  lt_dlhandle module = NULL;
  AbstractPlugin *plugin;
  create_t *create;

  OLA_INFO << "Attempting to load " << path;
  module = lt_dlopenext(path.c_str());

  if (!module) {
    OLA_WARN << "failed to lt_dlopen " << path << ": " << lt_dlerror();
    return NULL;
  }

  create = reinterpret_cast<create_t*>(lt_dlsym(module, "create"));

  if (lt_dlerror()) {
    OLA_WARN << "Could not locate create symbol in " << path;
    lt_dlclose(module);
    return NULL;
  }

  // init plugin
  if ((plugin = create(m_plugin_adaptor)) == NULL) {
    lt_dlclose(module);
    return NULL;
  }

  m_plugin_handles.push_back(module);
  OLA_INFO << "Loaded plugin " << plugin->Name();
  return plugin;
}
Esempio n. 2
0
int
main (int argc, char* argv[])
{
  lt_dlhandle dlhand;
  char sym[300];
  char* drvnam = argv[1];
  char** info;

  /* Establish a handler for SIGSEGV signals. */
  signal (SIGSEGV, catch_segv);

  lt_dlinit ();
  dlhand = lt_dlopenext (drvnam);
  if (dlhand == NULL) {
    fprintf (stderr, "Could not open driver module %s\n"
                     "libltdl error: %s\n", drvnam, lt_dlerror ());
    return 1;
  }
  sprintf (sym, "plD_DEVICE_INFO_%s", drvnam);
  info = (char **) lt_dlsym (dlhand, sym);
  if (info != NULL) {
    printf ("%s", *info);
    return 0;
  }
  else {
    fprintf (stderr, "Could not read symbol %s in driver module %s\n"
                     "libltdl error: %s\n", sym, drvnam, lt_dlerror ());
    return 1;
  }
}
/* Pulls server library out of plugin folder */
int
scrapePlugin (const char *filename, void * data)
{
    lt_dlhandle pluginHandle = lt_dlopenext (filename);
    if (!pluginHandle)
    {
        doLog (ERROR, LOG_COMP, _("Unable to link %s\nDetails: %s."), filename, lt_dlerror());
        return 0;
    }
    
    /* Get Info for loaded Plugin */
    lt_dlinfo const * pluginInfo = lt_dlgetinfo (pluginHandle);
    if (!pluginInfo)
    {
        doLog (ERROR, LOG_COMP, _("Unable to get plugin SO info for %s\nDetails: %s."), 
               filename, lt_dlerror());
        return 0;
    }
    
    /* Continue Loading Plugin */
    doLog (NOTICE, LOG_COMP, _("Found %s."), pluginInfo->name);
    checkAddPlugin (pluginInfo->filename, pluginInfo->name, pluginHandle);
    
    return 0;
}
Esempio n. 4
0
/*
 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
 * object, but it will bitch about a shared object not having a
 * ``module_register'' symbol..
 */
static int plugin_load_file (char *file)
{
	lt_dlhandle dlh;
	void (*reg_handle) (void);

	DEBUG ("file = %s", file);

	lt_dlinit ();
	lt_dlerror (); /* clear errors */

	if ((dlh = lt_dlopen (file)) == NULL)
	{
		const char *error = lt_dlerror ();

		ERROR ("lt_dlopen (%s) failed: %s", file, error);
		fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
		return (1);
	}

	if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
	{
		WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
				file, lt_dlerror ());
		lt_dlclose (dlh);
		return (-1);
	}

	(*reg_handle) ();

	return (0);
}
void PluginManager::start(){
  Logger* log = Logger::getLogger();

  std::string list = Settings::getSettings()->get("autoload_plugins");
  size_t pos_c = 0;
  size_t pos_e;
  if(list.length() > 0){
    while(pos_c != list.npos){
      pos_e = list.find(",", pos_c);
      load(list.substr(pos_c, pos_e));
      pos_c = pos_e;
    }
  }else{
    log->info("No automatically loaded plugins were defined in the "
        "configuation, add \"autoload_plugins = <comma list of plugins>\" to conf "
        "to have them loaded.");
  }

  /* Initalise the ltdl module. */
  LTDL_SET_PRELOADED_SYMBOLS();
  if(lt_dlinit() != 0){
    // FIXME: Should raise an error here.!
    log->error("Failed to load initalise the loader %s", lt_dlerror());
	stop();
  }

  /* Need to load ourselves before we can load other modules. */
  lt_dlhandle nlib = lt_dlopen(NULL);
  if(nlib == NULL){
    log->error("Failed to load ourselves because %s.", lt_dlerror());
	stop();
  }

}
bool PluginManager::load(const std::string& libname){
  Logger* log = Logger::getLogger();

  lt_dlhandle nlib = lt_dlopenext(libname.c_str());
  if(nlib == NULL){
    log->error("Failed to load plugin \"%s\": \"%s\" %p", libname.c_str(), lt_dlerror(), nlib);
    return false;
  }else{
    log->debug("Loaded plugin \"%s\" sucessfully", libname.c_str());
    tpinit_function init;
    *(void **) (&init)= lt_dlsym(nlib, "tp_init");
    if(init == NULL){
      log->error("Failed to initialise plugin \"%s\": \"%s\"", libname.c_str(), lt_dlerror());
      lt_dlclose(nlib);
      return false;
    }else{
      log->debug("Initialisation function for plugin \"%s\" found", libname.c_str());
      if((*init)()){
        log->info("Loaded plugin \"%s\" sucessfully", libname.c_str());
        libs[libname] = nlib;
      }else{
        log->error("Could not initialise plugin \"%s\"", libname.c_str());
        lt_dlclose(nlib);
        return false;
      }
    }
  }
  return true;
}
Esempio n. 7
0
int init_module_loading()
{
	int ret;
	static int initialised=0;
	
	if (initialised){
		LOG(L_CRIT, "BUG: init_module_loading: already intialised\n");
		return -1;
	}
	/* make sure preloaded modules are initialised */
	/*LTDL_SET_PRELOADED_SYMBOLS();*/
	ret=lt_dlinit();
	
	if (ret){
		LOG(L_CRIT, "ERROR: init_module_loading: lt_dlinit failed: %s\n",
				lt_dlerror());
		goto error;
	}
	
	ret=lt_dlsetsearchpath(MODULE_SEARCH_PATH);
	if (ret){
		LOG(L_CRIT, "ERROR: init_module_loading: lt_dlsetsearchpath "
					"failed: %s\n",
				lt_dlerror());
		goto error;
	}
	initialised++;
	return ret;
error:
	lt_dlexit();
	return -1;
}
int oph_ioserver_setup(const char *server_type, oph_ioserver_handler **handle)
{
  if (!handle){
    pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_NULL_HANDLE);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_COMMON_LOG, OPH_IOSERVER_LOG_NULL_HANDLE);    
    return OPH_IOSERVER_NULL_HANDLE;
  }

  oph_ioserver_handler *internal_handle = (oph_ioserver_handler *)malloc(sizeof(oph_ioserver_handler));

  internal_handle->server_type = NULL;
  internal_handle->server_subtype = NULL;
  internal_handle->lib = NULL;
  internal_handle->dlh = NULL;

  //Set storage server type 
  if(oph_parse_server_name (server_type, &internal_handle->server_type, &internal_handle->server_subtype)){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_SERVER_PARSE_ERROR);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_COMMON_LOG, OPH_IOSERVER_LOG_SERVER_PARSE_ERROR);    
    return OPH_IOSERVER_INVALID_PARAM;
  }

  //If already executed don't procede further
  if (internal_handle->dlh)  
    return OPH_IOSERVER_SUCCESS;

  //LTDL_SET_PRELOADED_SYMBOLS();
  if(lt_dlinit () != 0)
  {
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_DLINIT_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type,  OPH_IOSERVER_LOG_DLINIT_ERROR, lt_dlerror());    
    return OPH_IOSERVER_DLOPEN_ERR;
  }

  if (oph_find_server_plugin (internal_handle->server_type, &internal_handle->lib)){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LIB_NOT_FOUND);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type, OPH_IOSERVER_LOG_LIB_NOT_FOUND);    
    return OPH_IOSERVER_LIB_NOT_FOUND;
  }

  if (!(internal_handle->dlh = (lt_dlhandle) lt_dlopen (internal_handle->lib)))
  {
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_DLOPEN_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type,  OPH_IOSERVER_LOG_DLOPEN_ERROR, lt_dlerror());    
    return OPH_IOSERVER_DLOPEN_ERR;
  }

  char func_name[OPH_IOSERVER_BUFLEN] = {'\0'};
  snprintf(func_name, OPH_IOSERVER_BUFLEN, OPH_IOSERVER_SETUP_FUNC, internal_handle->server_type);

  if (!(_SERVER_setup = (int (*)(oph_ioserver_handler *)) lt_dlsym (internal_handle->dlh, func_name))){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type,  OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());   
    return OPH_IOSERVER_DLSYM_ERR;
  }

  *handle = internal_handle; 
  return _SERVER_setup (*handle);
}
Esempio n. 9
0
void xdlclose(void *h)
{     xassert(h != NULL);
      if (lt_dlclose(h) != 0)
         xerror("xdlclose: %s\n", lt_dlerror());
      if (lt_dlexit() != 0)
         xerror("xdlclose: %s\n", lt_dlerror());
      return;
}
Esempio n. 10
0
/*
 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
 * object, but it will bitch about a shared object not having a
 * ``module_register'' symbol..
 */
static int plugin_load_file (char *file, uint32_t flags)
{
	lt_dlhandle dlh;
	void (*reg_handle) (void);

	lt_dlinit ();
	lt_dlerror (); /* clear errors */

#if LIBTOOL_VERSION == 2
	if (flags & PLUGIN_FLAGS_GLOBAL) {
		lt_dladvise advise;
		lt_dladvise_init(&advise);
		lt_dladvise_global(&advise);
		dlh = lt_dlopenadvise(file, advise);
		lt_dladvise_destroy(&advise);
	} else {
        	dlh = lt_dlopen (file);
	}
#else /* if LIBTOOL_VERSION == 1 */
	if (flags & PLUGIN_FLAGS_GLOBAL)
		WARNING ("plugin_load_file: The global flag is not supported, "
				"libtool 2 is required for this.");
	dlh = lt_dlopen (file);
#endif

	if (dlh == NULL)
	{
		char errbuf[1024] = "";

		ssnprintf (errbuf, sizeof (errbuf),
				"lt_dlopen (\"%s\") failed: %s. "
				"The most common cause for this problem are "
				"missing dependencies. Use ldd(1) to check "
				"the dependencies of the plugin "
				"/ shared object.",
				file, lt_dlerror ());

		ERROR ("%s", errbuf);
		/* Make sure this is printed to STDERR in any case, but also
		 * make sure it's printed only once. */
		if (list_log != NULL)
			fprintf (stderr, "ERROR: %s\n", errbuf);

		return (1);
	}

	if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
	{
		WARNING ("Couldn't find symbol \"module_register\" in \"%s\": %s\n",
				file, lt_dlerror ());
		lt_dlclose (dlh);
		return (-1);
	}

	(*reg_handle) ();

	return (0);
}
Esempio n. 11
0
void xdlclose(void *h)
{     /* close dynamically linked library */
      xassert(h != NULL);
      if (lt_dlclose(h) != 0)
         xerror("xdlclose: %s\n", lt_dlerror());
      if (lt_dlexit() != 0)
         xerror("xdlclose: %s\n", lt_dlerror());
      return;
}
Esempio n. 12
0
static int dso_init(void) {
#ifdef PR_USE_CTRLS
  register unsigned int i = 0;
#endif /* PR_USE_CTRLS */

  /* Allocate the pool for this module's use. */
  dso_pool = make_sub_pool(permanent_pool);
  pr_pool_tag(dso_pool, MOD_DSO_VERSION);

  lt_dlpreload_default(lt_preloaded_symbols);

  /* Initialize libltdl. */
  if (lt_dlinit() < 0) {
    pr_log_pri(PR_LOG_ERR, MOD_DSO_VERSION ": error initializing libltdl: %s",
      lt_dlerror());
    return -1;
  }

  /* Explicitly set the search path used for opening modules. */
  if (lt_dlsetsearchpath(dso_module_path) < 0) {
    pr_log_pri(PR_LOG_ERR, MOD_DSO_VERSION ": error setting module path: %s",
      lt_dlerror());
    return -1;
  }

#ifdef PR_USE_CTRLS
  /* Register ctrls handlers. */
  for (i = 0; dso_acttab[i].act_action; i++) {
    pool *sub_pool = make_sub_pool(dso_pool);

    /* Allocate and initialize the ACL for this control. */
    dso_acttab[i].act_acl = pcalloc(sub_pool, sizeof(ctrls_acl_t));
    dso_acttab[i].act_acl->acl_pool = sub_pool;
    pr_ctrls_init_acl(dso_acttab[i].act_acl);

    if (pr_ctrls_register(&dso_module, dso_acttab[i].act_action,
        dso_acttab[i].act_desc, dso_acttab[i].act_cb) < 0)
      pr_log_pri(PR_LOG_INFO, MOD_DSO_VERSION
        ": error registering '%s' control: %s", dso_acttab[i].act_action,
        strerror(errno));
  }
#endif /* PR_USE_CTRLS */

  /* Ideally, we'd call register a listener for the 'core.exit' event
   * and call lt_dlexit() there, politely freeing up any resources allocated
   * by the ltdl library.  However, it's possible that other modules, later in
   * the dispatch cycles, may need to use pointers to memory in shared modules
   * that would become invalid by such finalization.  So we skip it, for now.
   *
   * If there was a way to schedule this handler, to happen after all other
   * exit handlers, that'd be best.
   */
  pr_event_register(&dso_module, "core.restart", dso_restart_ev, NULL);

  return 0;
}
Esempio n. 13
0
datasource_ptr datasource_cache::create(const parameters& params, bool bind)
{
    boost::optional<std::string> type = params.get<std::string>("type");
    if ( ! type)
    {
        throw config_error(std::string("Could not create datasource. Required ") +
                           "parameter 'type' is missing");
    }

#ifdef MAPNIK_THREADSAFE
    mutex::scoped_lock lock(mutex_);
#endif

    datasource_ptr ds;
    std::map<std::string,boost::shared_ptr<PluginInfo> >::iterator itr=plugins_.find(*type);
    if ( itr == plugins_.end() )
    {
        throw config_error(std::string("Could not create datasource. No plugin ") +
                           "found for type '" + * type + "' (searched in: " + plugin_directories() + ")");
    }

    if ( ! itr->second->handle())
    {
        throw std::runtime_error(std::string("Cannot load library: ") +
                                 lt_dlerror());
    }

    // http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
#ifdef __GNUC__
    __extension__
#endif
        create_ds* create_datasource =
        reinterpret_cast<create_ds*>(lt_dlsym(itr->second->handle(), "create"));

    if (! create_datasource)
    {
        throw std::runtime_error(std::string("Cannot load symbols: ") +
                                 lt_dlerror());
    }

#ifdef MAPNIK_LOG
    MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Size=" << params.size();

    parameters::const_iterator i = params.begin();
    for (; i != params.end(); ++i)
    {
        MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: -- " << i->first << "=" << i->second;
    }
#endif

    ds = datasource_ptr(create_datasource(params, bind), datasource_deleter());

    MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Datasource=" << ds << " type=" << type;

    return ds;
}
Esempio n. 14
0
void *xdlopen(const char *module)
{     void *h = NULL;
      if (lt_dlinit() != 0)
      {  lib_err_msg(lt_dlerror());
         goto done;
      }
      h = lt_dlopen(module);
      if (h == NULL)
      {  lib_err_msg(lt_dlerror());
         if (lt_dlexit() != 0)
            xerror("xdlopen: %s\n", lt_dlerror());
      }
done: return h;
}
Esempio n. 15
0
void modena_function_load_library(modena_function_t* self)
{
    PyObject *pFunctionName =
        PyObject_GetAttrString(self->pFunction, "functionName");
    if(!pFunctionName){ Modena_PyErr_Print(); }

    PyObject *pLibraryName =
        PyObject_GetAttrString(self->pFunction, "libraryName");
    if(!pLibraryName){ Modena_PyErr_Print(); }

    self->handle = lt_dlopen(PyString_AsString(pLibraryName));

    if(!self->handle)
    {
        fprintf
        (
           stderr,
           "lt_dlopen: Could not open library %s\nlt_dlopen: %s\n",
           PyString_AsString(pLibraryName),
           lt_dlerror()
        );
        exit(1);
    }

    self->function = lt_dlsym(self->handle, PyString_AsString(pFunctionName));
    if(!self->function)
    {
        fprintf
        (
            stderr,
            "lt_dlsym: Could not find function %s in library %s\n"
            "lt_dlsym: %s",
            PyString_AsString(pFunctionName),
            PyString_AsString(pLibraryName),
            lt_dlerror()
        );
        lt_dlclose(self->handle);
        exit(1);
    }

    Py_DECREF(pFunctionName);
    Py_DECREF(pLibraryName);

    PyObject *pParameters =
        PyObject_GetAttrString(self->pFunction, "parameters");
    if(!pParameters){ Modena_PyErr_Print(); }
    self->parameters_size = PyObject_Size(pParameters);
    Py_DECREF(pParameters);
}
Esempio n. 16
0
void *xdlopen(const char *module)
{     /* open dynamically linked library */
      void *h = NULL;
      if (lt_dlinit() != 0)
      {  put_err_msg(lt_dlerror());
         goto done;
      }
      h = lt_dlopen(module);
      if (h == NULL)
      {  put_err_msg(lt_dlerror());
         if (lt_dlexit() != 0)
            xerror("xdlopen: %s\n", lt_dlerror());
      }
done: return h;
}
Esempio n. 17
0
int main( int argc, char *argv[] )
{
	void	*hDLL;
	void	(*pFunc)();
	const char	*pError;

	if ( argc < 2  )
	{
		printf( szSyntax );
		exit( 1 );
	}

    /*
     * initialize libtool
     */

    if ( lt_dlinit() )
	{
		printf( "ERROR: Failed to lt_dlinit()\n" );
		exit( 1 );
	}

    hDLL = lt_dlopen( argv[1] );
	if ( !hDLL )
	{
		printf( "[dltest] ERROR dlopen: %s\n", lt_dlerror() );
		exit( 1 );
	}
	printf( "SUCCESS: Loaded %s\n", argv[1] );
	if ( argc > 2 )
	{
		pFunc = (void (*)()) lt_dlsym( hDLL, argv[2] );
/* PAH - lt_dlerror() is not a good indicator of success    */
/*		if ( (pError = lt_dlerror()) != NULL )              */
		if ( !pFunc )
		{
            if ( (pError = lt_dlerror()) != NULL )
			    printf( "ERROR: %s\n Could not find %s\n", pError, argv[2] );
            else
			    printf( "ERROR: Could not find %s\n", argv[2] );
			exit( 1 );
		}
		printf( "SUCCESS: Found %s\n", argv[2] );
	}
	lt_dlclose( hDLL );

	return ( 0 );
}
Esempio n. 18
0
/*
 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
 * object, but it will bitch about a shared object not having a
 * ``module_register'' symbol..
 */
static int plugin_load_file (char *file, uint32_t flags)
{
	lt_dlhandle dlh;
	void (*reg_handle) (void);

	DEBUG ("file = %s", file);

	lt_dlinit ();
	lt_dlerror (); /* clear errors */

#if LIBTOOL_VERSION == 2
	if (flags & PLUGIN_FLAGS_GLOBAL) {
		lt_dladvise advise;
		lt_dladvise_init(&advise);
		lt_dladvise_global(&advise);
		dlh = lt_dlopenadvise(file, advise);
		lt_dladvise_destroy(&advise);
	} else {
        	dlh = lt_dlopen (file);
	}
#else /* if LIBTOOL_VERSION == 1 */
	if (flags & PLUGIN_FLAGS_GLOBAL)
		ERROR ("plugin_load_file: The global flag is not supported, "
				"libtool 2 is required for this.");
	dlh = lt_dlopen (file);
#endif

	if (dlh == NULL)
	{
		const char *error = lt_dlerror ();

		ERROR ("lt_dlopen (%s) failed: %s", file, error);
		fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
		return (1);
	}

	if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
	{
		WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
				file, lt_dlerror ());
		lt_dlclose (dlh);
		return (-1);
	}

	(*reg_handle) ();

	return (0);
}
Esempio n. 19
0
void
plugins_init(const char *path)
{
    char *plugins_path;
    lt_dladvise advise;

    if (path && !strcmp(path, "none")) {
        return;
    }

    if (!(plugins_path = path ? xstrdup(path) : xstrdup(ovs_pluginsdir()))) {
        VLOG_ERR("Failed to allocate plugins path");
        return;
    }

    if (lt_dlinit() ||
        lt_dlsetsearchpath(plugins_path) ||
        lt_dladvise_init(&advise)) {
        VLOG_ERR("ltdl initializations: %s", lt_dlerror());
        goto err_init;
    }

    if (!(interface_id = lt_dlinterface_register("ovs-plugin", NULL))) {
        VLOG_ERR("lt_dlinterface_register: %s", lt_dlerror());
        goto err_interface_register;
    }

    if (lt_dladvise_global(&advise) || lt_dladvise_ext (&advise) ||
        lt_dlforeachfile(lt_dlgetsearchpath(), &plugins_open_plugin, &advise)) {
        VLOG_ERR("ltdl setting advise: %s", lt_dlerror());
        goto err_set_advise;
    }

    VLOG_INFO("Successfully initialized all plugins");
    return;

err_set_advise:
    lt_dlinterface_free(interface_id);

err_interface_register:
    if (lt_dladvise_destroy(&advise)) {
        VLOG_ERR("destroying ltdl advise%s", lt_dlerror());
        return;
    }

err_init:
    free(plugins_path);
}
Esempio n. 20
0
/* usage: ModulePath path */
MODRET set_modulepath(cmd_rec *cmd) {
  int res;
  struct stat st;

  CHECK_ARGS(cmd, 1);
  CHECK_CONF(cmd, CONF_ROOT);

  if (pr_fs_valid_path(cmd->argv[1]) < 0)
    CONF_ERROR(cmd, "must be an absolute path");

  /* Make sure that the configured path is not world-writeable. */
  res = pr_fsio_stat(cmd->argv[1], &st);
  if (res < 0)
    CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "error checking '",
      cmd->argv[1], "': ", strerror(errno), NULL)); 

  if (!S_ISDIR(st.st_mode))
    CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, cmd->argv[1], " is not a directory",
      NULL));

  if (st.st_mode & S_IWOTH)
    CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, cmd->argv[1], " is world-writable",
      NULL));

  if (lt_dlsetsearchpath(cmd->argv[1]) < 0)
    CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "error setting module path: ",
      lt_dlerror(), NULL));

  dso_module_path = pstrdup(dso_pool, cmd->argv[1]);
  return PR_HANDLED(cmd);
}
Esempio n. 21
0
bool
SharedLib::openLib (const std::string& filespec)
{
    
    scoped_lock lock(_libMutex);

    log_debug(_("Trying to open shared library \"%s\""), filespec);

#ifdef HAVE_LTDL
    _dlhandle = lt_dlopenext (filespec.c_str());
    
    if (_dlhandle == NULL) {
        log_error("lt_dlopenext(\"%s\") failed: %s", filespec.c_str(), lt_dlerror());
        return false;
    }

    // Make this module unloadable
    lt_dlmakeresident(_dlhandle);
#endif
    
    log_debug (_("Opened dynamic library \"%s\""), filespec);

    _filespec = filespec;
    
    return true;
}
Esempio n. 22
0
EmbracePlugin *embrace_plugin_new (const char *path)
{
	EmbracePlugin *ep;
	bool (*init)(EmbracePlugin *p);

	assert (path);

	if (!(ep = calloc (1, sizeof (EmbracePlugin))))
		return NULL;

	if (!(ep->handle = lt_dlopen (path))) {
		fprintf (stderr, "Cannot load plugin '%s': %s\n",
		         path, lt_dlerror ());
		embrace_plugin_free (ep);
		return NULL;
	}

	if (!(init = lt_dlsym (ep->handle, "embrace_plugin_init"))) {
		fprintf (stderr, "Cannot load plugin '%s': "
		         "cannot find init method!\n", path);
		embrace_plugin_free (ep);
		return NULL;
	}

	if (!(*init)(ep) || !ep->check) {
		fprintf (stderr, "Cannot load plugin '%s': "
		         "init method failed!\n", path);
		embrace_plugin_free (ep);
		return NULL;
	}

	return ep;
}
Esempio n. 23
0
/* since the  next API call may overwrite the original. */
static char * dlerrordup (char *errormsg)
{
  char *error = (char *) lt_dlerror ();
  if (error && !errormsg)
    errormsg = strdup (error);
  return errormsg;
}
int oph_ioserver_free_result(oph_ioserver_handler* handle, oph_ioserver_result *result)
{
  if (!handle){
    pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_NULL_HANDLE);
        logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_NULL_HANDLE);
    return OPH_IOSERVER_NULL_HANDLE;    
  }
  
  if (!handle->dlh || !handle->server_type){
        pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_SERV_ERROR);
        logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_LOAD_SERV_ERROR);
    return OPH_IOSERVER_DLOPEN_ERR;
  }     
    
  char func_name[OPH_IOSERVER_BUFLEN] = {'\0'};
  snprintf(func_name, OPH_IOSERVER_BUFLEN, OPH_IOSERVER_FREE_RESULT_FUNC, handle->server_type);

  if (!(_SERVER_free_result = (int (*)(oph_ioserver_handler*, oph_ioserver_result*)) lt_dlsym (handle->dlh, func_name))){
          pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
        logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
    return OPH_IOSERVER_DLSYM_ERR;
  }

  return _SERVER_free_result (handle, result);
}
int oph_ioserver_close(oph_ioserver_handler* handle, void *connection)
{
  if (!handle){
    pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_NULL_HANDLE);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_NULL_HANDLE);    
    return OPH_IOSERVER_NULL_HANDLE;
  }

  if (!handle->dlh || !handle->server_type){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_SERV_ERROR);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_LOAD_SERV_ERROR);    
    return OPH_IOSERVER_DLOPEN_ERR;
  }

  char func_name[OPH_IOSERVER_BUFLEN] = {'\0'};
  snprintf(func_name, OPH_IOSERVER_BUFLEN, OPH_IOSERVER_CLOSE_FUNC, handle->server_type);

  if (!(_SERVER_close = (int (*)(oph_ioserver_handler*, void *)) lt_dlsym (handle->dlh, func_name))){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
    return OPH_IOSERVER_DLSYM_ERR;
  }    

  return _SERVER_close (handle, connection); 
}
int oph_ioserver_setup_query(oph_ioserver_handler* handle, void *connection, const char *operation, unsigned long long tot_run, oph_ioserver_query_arg **args, oph_ioserver_query **query) 
{
  if (!handle){
    pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_NULL_HANDLE);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_NULL_HANDLE);    
    return OPH_IOSERVER_NULL_HANDLE;
  }

  if (!handle->dlh || !handle->server_type){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_SERV_ERROR);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_LOAD_SERV_ERROR);    
    return OPH_IOSERVER_DLOPEN_ERR;
  }

  char func_name[OPH_IOSERVER_BUFLEN] = {'\0'};
  snprintf(func_name, OPH_IOSERVER_BUFLEN, OPH_IOSERVER_SETUP_QUERY_FUNC, handle->server_type);

  if (!(_SERVER_setup_query = (int (*)(oph_ioserver_handler*, void *, const char *, unsigned long long, oph_ioserver_query_arg **, oph_ioserver_query **)) lt_dlsym (handle->dlh, func_name))){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, handle->server_type, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
    return OPH_IOSERVER_DLSYM_ERR;
  }    

  return _SERVER_setup_query (handle, connection, operation, tot_run, args, query); 
}
Esempio n. 27
0
static int dso_unload_module(module *m) {
  int res;
  char *name;

  /* Some modules cannot be unloaded. */
  if (strcmp(m->name, "dso") == 0) {
    errno = EPERM;
    return -1;
  }

  name = pstrdup(dso_pool, m->name);

  pr_trace_msg(trace_channel, 5, "unloading module 'mod_%s.c'", name);

  res = pr_module_unload(m);
  if (res < 0) {
    pr_log_debug(DEBUG1, MOD_DSO_VERSION
      ": error unloading module 'mod_%s.c': %s", m->name, strerror(errno));
    pr_trace_msg(trace_channel, 1,
      "error unloading module 'mod_%s.c': %s", m->name, strerror(errno));
  }

  if (lt_dlclose(m->handle) < 0) {
    pr_log_debug(DEBUG1, MOD_DSO_VERSION ": error closing '%s': %s",
      name, lt_dlerror());
    return -1;
  }

  pr_trace_msg(trace_channel, 8, "module 'mod_%s.c' successfully unloaded",
    name);
  return 0;
}
Esempio n. 28
0
/*
 * Load the configuration plugin from the given file.
 * If the configuration plugin structure is NULL then it is allocated.
 * This should normally be the case.
 */
int config_p_init(char *file) {
	char *buf = NULL;
	int len = 0;
	lt_dlhandle module = NULL;
	int (*config_init)(struct nv_config_p *);
	int stat = 0;
	int ret = 0;

	/* get reference to config plugin file */
	nv_log(NVLOG_INFO, "loading config plugin from %s", file);
	len = strlen(CONFIG_PATH)+strlen(file)+2;
	buf = nv_calloc(char, len);
	snprintf(buf, len, "%s/%s", CONFIG_PATH, file);
	module = lt_dlopen(buf);
	nv_free(buf);
	if (module == NULL) {
		nv_log(NVLOG_ERROR, "lt_dlopen(): %s", lt_dlerror());
		stat = -1;
		goto cleanup;
	}

	/* allocate memory for config plugin struct if necessary */
	if (nv_config_p == NULL) {
		nv_config_p = nv_calloc(struct nv_config_p, 1);
	}
/*
 * Load a module - this will load the shared object, call
 * C_Initialize, and get the list of function pointers
 */
void *
C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
{
	sc_pkcs11_module_t *mod;
	CK_RV (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
	int rv;

	lt_dlinit();

	mod = (sc_pkcs11_module_t *) calloc(1, sizeof(*mod));
	mod->_magic = MAGIC;

	if (mspec == NULL)
		mspec = PKCS11_DEFAULT_MODULE_NAME;
	mod->handle = lt_dlopen(mspec);
	if (mod->handle == NULL) {
#if 0
		fprintf(stderr, "lt_dlopen failed: %s\n", lt_dlerror());
#endif
		goto failed;
	}

	/* Get the list of function pointers */
	c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
				lt_dlsym(mod->handle, "C_GetFunctionList");
	if (!c_get_function_list)
		goto failed;
	rv = c_get_function_list(funcs);
	if (rv == CKR_OK)
		return (void *) mod;

failed:
	C_UnloadModule((void *) mod);
	return NULL;
}
Esempio n. 30
0
static void module_really_unload(module_list_t *entry)
{
	int errors;
	const char *error;
	module_list_t *m;

	if (entry->prev) entry->prev->next = entry->next;
	else deleted_head = entry->next;
	if (entry->next) entry->next->prev = entry->prev;

	if (entry->modinfo.unload_func) entry->modinfo.unload_func();

	script_remove_events_by_owner(&entry->modinfo, 0);

	for (m = module_list_head; m; m = m->next) {
		if (m->modinfo.event_cleanup) m->modinfo.event_cleanup(&entry->modinfo);
	}
	
	for (m = deleted_head; m; m = m->next) {
		if (m->modinfo.event_cleanup) m->modinfo.event_cleanup(&entry->modinfo);
	}
	
	errors = lt_dlclose(entry->hand);
	if (errors) {
		putlog(LOG_MISC, "*", "Error unloading %s!", entry->modinfo.name);
		while ((error = lt_dlerror())) putlog(LOG_MISC, "*", "ltdlerror: %s", error);
	}

	free(entry);
}