Exemplo n.º 1
0
/* 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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
static int do_load_plugin(const char *filename, void *data)
{
  struct load_params *params = (struct load_params *)data;

  params->plugin->handle = lt_dlopenext(filename);
  if (params->plugin->handle == NULL)
    {
      return 0;
    }

  params->plugin->info = lt_dlsym(params->plugin->handle, "info");
  if (params->plugin->info == NULL)
    {
      goto end;
    }

  if (strcmp(params->plugin->info->id, params->id) == 0)
    {
      return 1;
    }

end:
  lt_dlclose(params->plugin->handle);
  params->plugin->handle = NULL;
  return 0;
}
Exemplo n.º 4
0
void loadmod(void) {
	int (*lse_mod_test)(void) ;
	char * modname = cstring(0,0);
        lt_dlhandle modp;

        // Initialize libtool
        lt_dlinit(); 
        // Add local modules to search path
        lt_dladdsearchdir("./modules/");

#ifdef PKGLIBDIR
        // Add global modules to search path
        lt_dladdsearchdir(PKGLIBDIR);
#endif
        // try to load the module
        modp = lt_dlopenext(modname);

        // If we fail, set the flag to 0 and exit
	flag = 0;
	if ( ! modp ) return;

        // Else make sure the module is sane
	if ( !(lse_mod_test = (int (*)(void)) lt_dlsym(modp, "lse_mod_test")) ) return;
        // If all is well, then the test value 
        // should return 1, so se the flag to this and 
	flag = lse_mod_test();
}
Exemplo n.º 5
0
BOSS::Module * BOSS_Synthesis::load(const string & name) {
  char * errormsg = NULL;
  //load the module library
  cerr << "BOSS_Synthesis: loading " << name << endl;
  lt_dlhandle lib = lt_dlopenext(name.c_str());
  if (!lib) {
    errormsg = dlerrordup (errormsg);
    cerr << "Cannot load library: " << errormsg << endl;
    return 0;
  }
  
  std::cerr << "retrieving library symbols" << std::endl;
  // load the symbols
  create_module * create = (create_module*) lt_dlsym(lib, "create");

  // the destroy function is by current design not so necessary
  //  destroy_module * destroy = (destroy_module*) lt_dlsym(lib, "destroy");
  if (!create ) { //|| !destroy) {
    errormsg = dlerrordup (errormsg);
    cerr << "Cannot load symbols: " << errormsg << endl;
    return 0;
  }
  
  std::cerr << "creating module class instance" << std::endl;
  // create an instance of the class
  BOSS::Module * module = create(cl, data_base);
  return module;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
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;
  }
}
Exemplo n.º 9
0
int load_plugin(struct oh_plugin_config *config)
{
    lt_dlhandle h;
    int (*get_interface) (struct oh_abi_v1 ** pp, const uuid_t uuid);
    int err;

    h = lt_dlopenext(config->name);
    if (h == NULL) {
        dbg("Can not find %s plugin", config->name);
        goto err1;
    }

    get_interface = lt_dlsym(h, "get_interface");
    if (!get_interface) {
        dbg("Can not get 'get_interface' symbol, is it a plugin?!");
        goto err1;
    }

    err = get_interface(&config->abi, UUID_OH_ABI_V1);
    if (err < 0 || !config->abi || !config->abi->open) {
        dbg("Can not get ABI V1");
        goto err1;
    }

    return 0;
err1:
    lt_dlclose(h);
    return -1;
}
Exemplo n.º 10
0
/**************************************************************************
  Load ai module from file.
**************************************************************************/
bool load_ai_module(const char *modname)
{
  struct ai_type *ai = ai_type_alloc();
  bool setup_success;
  lt_dlhandle handle;
  bool (*setup_func)(struct ai_type *ai);
  const char *(*capstr_func)(void);
  const char *capstr;
  char buffer[2048];
  char filename[1024];

  if (ai == NULL) {
    return FALSE;
  }

  init_ai(ai);

  fc_snprintf(filename, sizeof(filename), "fc_ai_%s", modname);
  fc_snprintf(buffer, sizeof(buffer), "%s", filename);
  handle = lt_dlopenext(buffer);
  if (handle == NULL) {
    log_error(_("Cannot open AI module %s (%s)"), filename, fc_module_error());
    return FALSE;
  }

  fc_snprintf(buffer, sizeof(buffer), "%s_capstr", filename);
  capstr_func = lt_dlsym(handle, buffer);
  if (capstr_func == NULL) {
    log_error(_("Cannot find capstr function from ai module %s (%s)"),
              filename, fc_module_error());
    return FALSE;
  }

  capstr = capstr_func();
  if (strcmp(FC_AI_MOD_CAPSTR, capstr)) {
    log_error(_("Incompatible ai module %s:"), filename);
    log_error(_("  Module options:    %s"), capstr);
    log_error(_("  Supported options: %s"), FC_AI_MOD_CAPSTR);

    return FALSE;
  }

  fc_snprintf(buffer, sizeof(buffer), "%s_setup", filename);
  setup_func = lt_dlsym(handle, buffer);
  if (setup_func == NULL) {
    log_error(_("Cannot find setup function from ai module %s (%s)"),
              filename, fc_module_error());
    return FALSE;
  }
  setup_success = setup_func(ai);

  if (!setup_success) {
    log_error(_("Setup of ai module %s failed."), filename);
    return FALSE;
  }

  return TRUE;
}
Exemplo n.º 11
0
/* This function will parse a tconfig "module" block, and attempt
 * to load the module
 */
struct tmodule *tmodule_from_tconfig(struct tconfig_block *tcfg, struct tconfig_block *global_cfg)
{
	lt_dlhandle ltmodule   = NULL;
	struct tmodule *module = NULL;
	int (*tmodule_load)(struct tconfig_block *, struct tconfig_block *);

	if (strcmp(tcfg->key, "module"))
		return NULL;

	/* Search modules directory */
	lt_dlsetsearchpath("modules");

	ltmodule = lt_dlopenext(tcfg->value);

	if (ltmodule == NULL)
	{
		troll_debug(LOG_WARN, "Could not open module \"%s\" (Reason: %s)", tcfg->value, lt_dlerror());
		return NULL;
	}

	troll_debug(LOG_DEBUG, "Loaded module \"%s\"", tcfg->value);

	if ((tmodule_load = lt_dlsym(ltmodule, "tmodule_load")) == NULL)
	{
		troll_debug(LOG_WARN, "Could not find symbol tmodule_load in  module \"%s\"", tcfg->value);
		lt_dlclose(ltmodule);
	} 
	else
	{
		/* We praise our magnificient overlords */
		if (!(*tmodule_load)(tcfg->child, global_cfg))
		{
			troll_debug(LOG_WARN, "Init function for module \"%s\" failed", tcfg->value);
			lt_dlclose(ltmodule);
			return NULL;
		}
	}

	module = tmalloc(sizeof(struct tmodule));

	module->name                    = tstrdup(tcfg->value);
	module->handle                  = ltmodule;

	/* Loading mechanism */
	module->tmodule_load            = lt_dlsym(ltmodule, "tmodule_load"); 
	module->tmodule_unload          = lt_dlsym(ltmodule, "tmodule_unload");

	/* Socket system */
	module->tmodule_get_tsockets    = lt_dlsym(ltmodule, "tmodule_get_tsockets");

	/* Messaging system */
	module->tmodule_get_messages    = lt_dlsym(ltmodule, "tmodule_get_messages");
	module->tmodule_handle_messages = lt_dlsym(ltmodule, "tmodule_handle_messages");

	return module;
}
Exemplo n.º 12
0
/* return 0 on error */
int nutscan_load_upsclient_library()
{

        if( dl_handle != NULL ) {
                /* if previous init failed */
                if( dl_handle == (void *)1 ) {
                        return 0;
                }
                /* init has already been done */
                return 1;
        }

        if( lt_dlinit() != 0 ) {
                fprintf(stderr, "Error initializing lt_init\n");
                return 0;
        }

        dl_handle = lt_dlopenext(libname);
        if (!dl_handle) {
                dl_error = lt_dlerror();
                goto err;
        }

        lt_dlerror();      /* Clear any existing error */

        *(void **) (&nut_upscli_splitaddr) = lt_dlsym(dl_handle,
                                                        "upscli_splitaddr");
        if ((dl_error = lt_dlerror()) != NULL)  {
                goto err;
        }

        *(void **) (&nut_upscli_tryconnect) = lt_dlsym(dl_handle,
							"upscli_tryconnect");
        if ((dl_error = lt_dlerror()) != NULL)  {
                goto err;
        }

        *(void **) (&nut_upscli_list_start) = lt_dlsym(dl_handle,
							"upscli_list_start");
        if ((dl_error = lt_dlerror()) != NULL)  {
                goto err;
        }

        *(void **) (&nut_upscli_list_next) = lt_dlsym(dl_handle,
							"upscli_list_next");
        if ((dl_error = lt_dlerror()) != NULL)  {
                goto err;
        }

        return 1;
err:
        fprintf(stderr, "Cannot load NUT library (%s) : %s. NUT search disabled.\n", libname, dl_error);
        dl_handle = (void *)1;
	lt_dlexit();
        return 0;
}
Exemplo n.º 13
0
module_handle module_open(const char* name, enum module_type_t type, int flags){
	log_message(Log_Debug, "Loading plugin '%s'\n", name);

	/* dlopenext tries all searchpaths and adds appropriate suffix */
	lt_dlhandle handle = lt_dlopenext(name);

	if ( !handle ){
		log_message(Log_Debug, "Failed to load plugin '%s': %s\n", name, lt_dlerror());
		errnum = MODULE_NOT_FOUND;
		return NULL;
	}

	/* test if the module is valid by quering a symbol which must exists in
	 * every module. */
	void* sym = lt_dlsym(handle, "__module_type");
	if ( !sym ){
		log_message(Log_Debug, "Plugin '%s' found but is invalid\n", name);
		errnum = MODULE_INVALID;
		return NULL;
	}

	if ( type != ANY_MODULE && *((enum module_type_t*)sym) != type ){
		log_message(Log_Debug, "Plugin '%s' found but is invalid\n", name);
		errnum = MODULE_INVALID;
		return NULL;
	}

	/* base functions */
	void* module_init    = lt_dlsym(handle, "module_init");
	void* module_cleanup = lt_dlsym(handle, "module_cleanup");
	void* module_alloc   = lt_dlsym(handle, "module_alloc");
	void* module_free    = lt_dlsym(handle, "module_free");

	/* create base structure (later copied into the real struct */
	struct module_t base;
	base.handle  = handle;
	base.info    = lt_dlgetinfo(handle);
	base.init    = (module_init_callback)module_init;
	base.cleanup = (module_cleanup_callback)module_cleanup;
	base.alloc   = module_alloc ? (module_alloc_callback)module_alloc : default_alloc;
	base.free    = module_free  ?  (module_free_callback)module_free  : default_free;

	/* allocate real structure and copy base fields */
	module_handle module = base.alloc();
	*module = base;

	/* run module initialization if available */
	if ( callee_init(flags) && module->init && module->init(module) != 0 ){
		log_message(Log_Fatal, "Plugin `%s' initialization failed.\n", name);
		return NULL;
	}

	return module;
}
Exemplo n.º 14
0
static int plibltpdl_open(const char *fname, bool use_ext, bool private_namespace,
                          pmix_pdl_handle_t **handle, char **err_msg)
{
    assert(handle);

    *handle = NULL;
    if (NULL != err_msg) {
        *err_msg = NULL;
    }

    lt_dlhandle local_handle;

#if PMIX_DL_LIBLTDL_HAVE_LT_DLADVISE
    pmix_pdl_plibltpdl_component_t *c = &mca_pdl_plibltpdl_component;

    if (use_ext && private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_private_ext);
    } else if (use_ext && !private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_public_ext);
    } else if (!use_ext && private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_private_noext);
    } else if (!use_ext && !private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_public_noext);
    }
#else
    if (use_ext) {
        local_handle = lt_dlopenext(fname);
    } else {
        local_handle = lt_dlopen(fname);
    }
#endif

    if (NULL != local_handle) {
        *handle = calloc(1, sizeof(pmix_pdl_handle_t));
        (*handle)->ltpdl_handle = local_handle;

#if PMIX_ENABLE_DEBUG
        if( NULL != fname ) {
            (*handle)->filename = strdup(fname);
        }
        else {
            (*handle)->filename = strdup("(null)");
        }
#endif

        return PMIX_SUCCESS;
    }

    if (NULL != err_msg) {
        *err_msg = (char*) lt_dlerror();
    }
    return PMIX_ERROR;
}
Exemplo n.º 15
0
int module_load(const char *name)
{
	lt_dlhandle hand;
	module_list_t *entry;
	egg_start_func_t startfunc;
	char *startname;


	/* See if it's already loaded. */
	entry = find_active_module(name);
	if (entry) return(-1);
	entry = find_deleted_module(name);
	if (entry) return(-5);

	hand = lt_dlopenext(name);
	if (!hand) {
		const char *err = lt_dlerror();
		putlog(LOG_MISC, "*", "Error loading module %s: %s", name, err);
		return(-2);
	}

	startname = egg_mprintf("%s_LTX_start", name);
	startfunc = (egg_start_func_t)lt_dlsym(hand, startname);
	free(startname);
	if (!startfunc) {
		startfunc = (egg_start_func_t)lt_dlsym(hand, "start");
		if (!startfunc) {
			lt_dlclose(hand);
			return(-3);
		}
	}

	/* Create an entry for it. */
	entry = calloc(1, sizeof(*entry));
	entry->prev = NULL;
	entry->next = module_list_head;
	entry->refcount = 0;
	entry->hand = hand;
	module_list_head = entry;

	if (startfunc(&entry->modinfo)) {
		module_list_head = module_list_head->next;
		free(entry);
		return(-4);
	}

	putlog(LOG_MISC, "*", "Module loaded: %s", name);
	bind_check(BT_load, NULL, name, name);

	return(0);
}
Exemplo n.º 16
0
//===========================================================================
// DS_Load
//  "A3D", "OpenAL" and "Compat" are supported.
//===========================================================================
sfxdriver_t *DS_Load(const char *name)
{
	filename_t fn;

	// Compose the name, use the prefix "ds".
	sprintf(fn, "libds%s", name);

	if((handle = lt_dlopenext(fn)) == NULL)
	{
		Con_Message("DS_Load: Loading of %s failed.\n", fn);
		return NULL;
	}

	return DS_ImportExternal();
}
Exemplo n.º 17
0
bool CLibraryAccess::Load(const char *name, const char *directory)
{
	if(m_lib)
		Unload();

	if (strncmp(name,"oracle",6)==0)
	{
		/* this is very messy, but the server crashes/hangs
		   when the oracle library is unloaded due to the
	      	   putenv ... */

	      /* For this kind of thing better to put a load/unload hook in the
		 library itself, otherwise it just gets too messy hardcoding
		 everything. */

	      CServerIo::trace(3,"It is ORACLE so save environment.");
	      strcpy(save_nls_lang,getenv("NLS_LANG"));
	      strcpy(save_nls_nchar,getenv("NLS_NCHAR"));
	      strcpy(save_oracle_home,getenv("ORACLE_HOME"));
	      CServerIo::trace(3," NLS_LANG=%s",save_nls_lang);
	      CServerIo::trace(3," NLS_NCHAR=%s",save_nls_nchar);
	      CServerIo::trace(3," ORACLE_HOME=%s",save_oracle_home);
	}

	cvs::filename fn;
	if(directory && *directory)
		cvs::sprintf(fn,256,"%s/%s",directory,name);
	else
		fn = name;

	VerifyTrust(fn.c_str(),false);

	dlref();	
	m_lib = (void*)lt_dlopenext(fn.c_str());

	if(!m_lib)
	{
		CServerIo::trace(3,"LibraryAccess::Load failed for '%s', error = %d %s",fn.c_str(),errno, lt_dlerror());
		dlunref();
		return false;
	}

	if (strncmp(name,"oracle",6)==0)
	      save_m_lib=m_lib;

	return true;
}
Exemplo n.º 18
0
/*
 * DD_InitDGL
 *  Load the rendering DLL and setup the driver struct. The rendering DLL
 *  could be changed at runtime (but such an operation is currently never 
 *  done). Returns true if successful.
 */
int DD_InitDGL(void)
{
	char   *libName = DEFAULT_LIB_NAME;

	// See if a specific renderer DLL is specified.
	if(ArgCheckWith("-gl", 1))
		libName = ArgNext();

	// Load the DLL.
#ifdef WIN32
	dglHandle = LoadLibrary(libName);
#endif
#ifdef UNIX
	dglHandle = lt_dlopenext(libName);
#endif
	if(!dglHandle)
	{
#ifdef WIN32
		DD_ErrorBox(true, "DD_InitDGL: Loading of %s failed (error %i).\n",
					libName, GetLastError());
#endif
#ifdef UNIX
		DD_ErrorBox(true, "DD_InitDGL: Loading of %s failed.\n  %s.\n",
					libName, lt_dlerror());
#endif
		return false;
	}

	// Prepare the driver struct.
	if(!DD_InitDGLDriver())
	{
		DD_ErrorBox(true, "DD_InitDGL: Rendering DLL %s is incompatible.\n",
					libName);
		return false;
	}

	// Check the version of the DLL.
	if(gl.GetInteger(DGL_VERSION) < DGL_VERSION_NUM)
	{
		DD_ErrorBox(true,
					"DD_InitDGL: Version %i renderer found. "
					"Version %i is required.\n", gl.GetInteger(DGL_VERSION),
					DGL_VERSION_NUM);
		return false;
	}
	return true;
}
Exemplo n.º 19
0
void *
radiusd_load_ext(const char *name, const char *ident, void **symbol)
{
	lt_dlhandle handle;

	GRAD_DEBUG2(1,"Loading module '%s', symbol '%s'", name, ident);
	if (lt_dlinit()) {
		GRAD_DEBUG(1,"lt_ldinit failed");
		return NULL;
	}
	
	handle = lt_dlopenext(name);
	if (handle) {
		*symbol = lt_dlsym(handle, ident);
		if (*symbol) {
			grad_dl_init_t initf =
				(grad_dl_init_t) lt_dlsym(handle, "init");
			if (initf) {
				if (initf()) {
					grad_log(GRAD_LOG_ERR,
						 _("Cannot load module %s: init function failed"),
						 name);
					lt_dlclose(handle);
					handle = NULL;
				}
			}

		} else {
			grad_log(GRAD_LOG_ERR,
				 _("Cannot load module %s: symbol %s not found"),
				 name, ident);
			lt_dlclose(handle);
			handle = NULL;
		}
	} else
		grad_log(GRAD_LOG_NOTICE, _("Cannot load module %s: %s"),
			 name, lt_dlerror());

	GRAD_DEBUG1(1,"Handle %p", handle);
	if (!handle) 
		lt_dlexit();
	else
		store_handle(handle);
	return handle;
}
Exemplo n.º 20
0
static int dso_load_file(char *path) {

  if (!path) {
    errno = EINVAL;
    return -1;
  }

  pr_trace_msg(trace_channel, 5, "loading file '%s'", path);

  /* XXX Is this sufficient for loading an external library? */
  if (lt_dlopenext(path) == NULL) {
    pr_log_pri(PR_LOG_NOTICE, MOD_DSO_VERSION ": unable to open '%s': %s",
      path, lt_dlerror());
    errno = EPERM;
    return -1;
  }

  pr_trace_msg(trace_channel, 8, "file '%s' successfully loaded", path);
  return 0;
}
Exemplo n.º 21
0
int load_plugin(struct oh_domain *d, char *plugin_name,
		char *name, char *addr)
{
        lt_dlhandle h;
        int (*get_interface) (struct oh_abi_v1 ** pp, const uuid_t uuid);
        struct oh_abi_v1 *abi;
        void *hnd;
        int err;

        h = lt_dlopenext(plugin_name);
        if (!h) {
                dbg("Can not find %s plugin", plugin_name);
                goto err1;
	}

	get_interface = lt_dlsym(h, "get_interface");
	if (!get_interface) {
		dbg("Can not get 'get_interface' symbol, is it a plugin?!");
		goto err1;
	}

	err = get_interface(&abi, UUID_OH_ABI_V1);
	if (err < 0 || !abi || !abi->open) {
		dbg("Can not get ABI V1");
		goto err1;
	}

	/* bootstrap plugin must work without parameter */
	hnd = abi->open(name, addr);
	if (!hnd) {
		dbg("Bootstrap plugin can not work");
		goto err1;
	}

	domain_add_zone(d, abi, hnd);

	return 0;
 err1:
	lt_dlclose(h);
	return -1;
}
Exemplo n.º 22
0
//#define Check_Failed_Module 0
exception_t SKY_load_module(const char* module_filename){
	exception_t ret;
	char **module_name;
 	lt_dlhandle * handler;
	const char* err_str = NULL;
	//skyeye_log(Debug_log, __FUNCTION__, "module_filename = %s\n", module_filename);
#ifndef Check_Failed_Module
        handler = lt_dlopenext(module_filename);
#else
        //handler = dlopen(module_filename, RTLD_LAZY);
	handler = dlopen(module_filename, RTLD_NOW);
	if(handler == NULL){
		err_str = dlerror();
		skyeye_log(Error_log, __FUNCTION__, "dll error: %s\n", err_str);
	}
	return Dll_open_exp;
#endif
        if (handler == NULL)
        {
        	err_str = dlerrordup(err_str);
                skyeye_log(Warnning_log, __FUNCTION__, "%s\n", err_str);
		return Dll_open_exp;
        }
	
	module_name = lt_dlsym(handler, "skyeye_module");
	if((err_str = dlerrordup(err_str)) != NULL){
		skyeye_log(Warnning_log, __FUNCTION__, "dll error %s\n", err_str);
		skyeye_log(Warnning_log, __FUNCTION__, "Invalid module in file %s\n", module_filename);
		lt_dlclose(handler);
		return Invmod_exp;
	}
	//skyeye_log(Debug_log, __FUNCTION__, "Load module %s\n", *module_name);
		
	ret = register_skyeye_module(*module_name, module_filename, handler);
	if(ret != No_exp){
		lt_dlclose(handler);
		return ret;
	}
	return No_exp;	
}
Exemplo n.º 23
0
static lt_dlhandle
load_module (mu_sieve_machine_t mach, const char *name)
{
  lt_dlhandle handle;

  if (sieve_init_load_path ())
    return NULL;

  handle = lt_dlopenext (name);
  if (handle)
    {
      sieve_module_init_t init = (sieve_module_init_t)
	                                lt_dlsym (handle, "init");
      if (init)
	{
	  init (mach);
	  /* FIXME: We used to have this:
  	       mu_sieve_machine_add_destructor (mach, _free_loaded_module,
 	                                        handle);
             However, unloading modules can lead to random segfaults in
	     case they allocated any global-access data (e.g. mach->msg).
	     In particular, this was the case with extensions/pipe.c. 
	  */
	  return handle;
	}
      else
	{
	  lt_dlclose (handle);
	  handle = NULL;
	}
    }

  if (!handle)
    {
      mu_sieve_error (mach, "%s: %s", name, lt_dlerror ());
      lt_dlexit ();
    }
  return handle;
}
Exemplo n.º 24
0
/*
 *	Instantiate the module.
 */
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
	rlm_cache_t *inst = instance;

	inst->cs = conf;

	inst->xlat_name = cf_section_name2(conf);
	if (!inst->xlat_name) {
		inst->xlat_name = cf_section_name1(conf);
	}

	/*
	 *	Register the cache xlat function
	 */
	xlat_register(inst->xlat_name, cache_xlat, NULL, inst);

	/*
	 *	Sanity check for crazy people.
	 */
	if (strncmp(inst->driver_name, "rlm_cache_", 8) != 0) {
		ERROR("%s: \"%s\" is NOT an Cache driver!", inst->xlat_name, inst->driver_name);
		return -1;
	}

	/*
	 *	Load the appropriate driver for our database
	 */
	inst->handle = lt_dlopenext(inst->driver_name);
	if (!inst->handle) {
		ERROR("Could not link driver %s: %s", inst->driver_name, dlerror());
		ERROR("Make sure it (and all its dependent libraries!) are in the search path of your system's ld");
		return -1;
	}

	inst->module = (cache_module_t *) dlsym(inst->handle, inst->driver_name);
	if (!inst->module) {
		ERROR("Could not link symbol %s: %s", inst->driver_name, dlerror());
		return -1;
	}

	DEBUG3("Driver %s loaded successfully", inst->module->name);

	/*
	 *	Non optional fields and callbacks
	 */
	rad_assert(inst->module->name);
	rad_assert(inst->module->find);
	rad_assert(inst->module->insert);
	rad_assert(inst->module->expire);

	if (inst->module->mod_instantiate) {
		CONF_SECTION *cs;
		char const *name;

		name = strrchr(inst->driver_name, '_');
		if (!name) {
			name = inst->driver_name;
		} else {
			name++;
		}

		cs = cf_section_sub_find(conf, name);
		if (!cs) {
			cs = cf_section_alloc(conf, name, NULL);
			if (!cs) return -1;
		}

		/*
		 *	It's up to the driver to register a destructor (using talloc)
		 *
		 *	Should write its instance data in inst->driver,
		 *	and parent it off of inst.
		 */
		if (inst->module->mod_instantiate(cs, inst) < 0) return -1;
	}

	rad_assert(inst->key && *inst->key);

	if (inst->ttl == 0) {
		cf_log_err_cs(conf, "Must set 'ttl' to non-zero");
		return -1;
	}

	if (inst->epoch != 0) {
		cf_log_err_cs(conf, "Must not set 'epoch' in the configuration files");
		return -1;
	}

	/*
	 *	Make sure the users don't screw up too badly.
	 */
	if (map_afrom_cs(&inst->maps, cf_section_sub_find(inst->cs, "update"),
			 PAIR_LIST_REQUEST, PAIR_LIST_REQUEST, cache_verify, NULL, MAX_ATTRMAP) < 0) {
		return -1;
	}

	if (!inst->maps) {
		cf_log_err_cs(inst->cs, "Cache config must contain an update section, and "
			      "that section must not be empty");

		return -1;
	}
	return 0;
}
Exemplo n.º 25
0
/**
 * oh_unload_plugin
 * @plugin_name
 *
 * Load plugin by name and make a instance.
 *
 * Returns: 0 on Success.
 **/
int oh_load_plugin(char *plugin_name)
{
    struct oh_plugin *plugin = NULL;
    int (*get_interface) (struct oh_abi_v2 ** pp, const uuid_t uuid);
    int err;
    struct oh_static_plugin *p = static_plugins;

    if (!plugin_name) {
        dbg("ERROR. NULL plugin name passed.");
        return -1;
    }

    data_access_lock();
    if (oh_init_ltdl()) {
        data_access_unlock();
        dbg("ERROR. Could not initialize ltdl for loading plugins.");
        return -1;
    }

    if (oh_lookup_plugin(plugin_name)) {
        dbg("Warning. Plugin %s already loaded. Not loading twice.",
            plugin_name);
        data_access_unlock();
        return -1;
    }

    plugin = (struct oh_plugin *)g_malloc0(sizeof(struct oh_plugin));
    if (!plugin) {
        dbg("Out of memory.");
        data_access_unlock();
        return -1;
    }
    plugin->name = g_strdup(plugin_name);
    plugin->refcount = 1;

    /* first take search plugin in the array of static plugin */
    while( p->name ) {
        if (!strcmp(plugin->name, p->name)) {
            plugin->dl_handle = 0;
            err = (*p->get_interface)((void **)&plugin->abi, UUID_OH_ABI_V2);

            if (err < 0 || !plugin->abi || !plugin->abi->open) {
                dbg("Can not get ABI V2");
                goto err1;
            }

            trace( "found static plugin %s", p->name );

            plugin_list = g_slist_append(plugin_list, plugin);
            data_access_unlock();

            return 0;
        }

        p++;
    }

    plugin->dl_handle = lt_dlopenext(plugin->name);
    if (plugin->dl_handle == NULL) {
        dbg("Can not open %s plugin: %s", plugin->name, lt_dlerror());
        goto err1;
    }

    get_interface = lt_dlsym(plugin->dl_handle, "get_interface");
    if (!get_interface) {
        dbg("Can not get 'get_interface' symbol, is it a plugin?!");
        goto err1;
    }

    err = get_interface(&plugin->abi, UUID_OH_ABI_V2);
    if (err < 0 || !plugin->abi || !plugin->abi->open) {
        dbg("Can not get ABI V2");
        goto err1;
    }
    plugin_list = g_slist_append(plugin_list, plugin);
    data_access_unlock();

    return 0;

err1:
    if (plugin->dl_handle) {
        lt_dlclose(plugin->dl_handle);
        plugin->dl_handle = 0;
    }
    data_access_unlock();
    g_free(plugin);

    return -1;
}
Exemplo n.º 26
0
/**
 * \brief Configure a port
 *
 * Makes a port functional by passing in the necessary path
 * information (from the serial:/dev/ttyS0 or similar variables).
 * After calling this function, you can access the port using for
 * example gp_port_open().
 * 
 * \param port a GPPort
 * \param info the GPPortInfo to set
 *
 * \return a gphoto2 error code
 **/
int
gp_port_set_info (GPPort *port, GPPortInfo info)
{
	GPPortLibraryOperations ops_func;

	CHECK_NULL (port);

	if (port->pc->info.name) free (port->pc->info.name);
	port->pc->info.name = strdup (info->name);
	if (port->pc->info.path) free (port->pc->info.path);
	port->pc->info.path = strdup (info->path);
	port->pc->info.type = info->type;
	if (port->pc->info.library_filename) free (port->pc->info.library_filename);
	port->pc->info.library_filename = strdup (info->library_filename);

	port->type = info->type;

	/* Clean up */
	if (port->pc->ops) {
		gp_port_exit (port);
		free (port->pc->ops);
		port->pc->ops = NULL;
	}
	if (port->pc->lh) {
		lt_dlclose (port->pc->lh);
		lt_dlexit ();
	}

	lt_dlinit ();
	port->pc->lh = lt_dlopenext (info->library_filename);
	if (!port->pc->lh) {
		gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not load "
			"'%s' ('%s')."), info->library_filename,
			lt_dlerror ());
		lt_dlexit ();
		return (GP_ERROR_LIBRARY);
	}

	/* Load the operations */
	ops_func = lt_dlsym (port->pc->lh, "gp_port_library_operations");
	if (!ops_func) {
		gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not find "
			"'gp_port_library_operations' in '%s' ('%s')"),
			info->library_filename, lt_dlerror ());
		lt_dlclose (port->pc->lh);
		lt_dlexit ();
		port->pc->lh = NULL;
		return (GP_ERROR_LIBRARY);
	}
	port->pc->ops = ops_func ();
	gp_port_init (port);

	/* Initialize the settings to some default ones */
	switch (info->type) {
	case GP_PORT_SERIAL:
		port->settings.serial.speed = 0;
		port->settings.serial.bits = 8;
		port->settings.serial.parity = 0;
		port->settings.serial.stopbits = 1;
		gp_port_set_timeout (port, 500);
		break;
	case GP_PORT_USB:
		strncpy (port->settings.usb.port, info->path,
			 sizeof (port->settings.usb.port));
		port->settings.usb.inep = -1;
		port->settings.usb.outep = -1;
		port->settings.usb.config = -1;
		port->settings.usb.interface = 0;
		port->settings.usb.altsetting = -1;
		gp_port_set_timeout (port, 5000);
		break;
	case GP_PORT_USB_DISK_DIRECT:
		snprintf(port->settings.usbdiskdirect.path,
			 sizeof(port->settings.usbdiskdirect.path), "%s",
			 strchr(info->path, ':') + 1);
		break;
	case GP_PORT_USB_SCSI:
		snprintf(port->settings.usbscsi.path,
			 sizeof(port->settings.usbscsi.path), "%s",
			 strchr(info->path, ':') + 1);
		break;
	default:
		/* Nothing in here */
		break;
	}
	gp_port_set_settings (port, port->settings);

	return (GP_OK);
}
Exemplo n.º 27
0
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
	rlm_sql_t *inst = instance;

	/*
	 *	Hack...
	 */
	inst->config = &inst->myconfig;
	inst->cs = conf;

	inst->config->xlat_name = cf_section_name2(conf);
	if (!inst->config->xlat_name) {
		inst->config->xlat_name = cf_section_name1(conf);
	} else {
		char *group_name;
		DICT_ATTR const *da;
		ATTR_FLAGS flags;

		/*
		 *	Allocate room for <instance>-SQL-Group
		 */
		group_name = talloc_typed_asprintf(inst, "%s-SQL-Group", inst->config->xlat_name);
		DEBUG("rlm_sql (%s): Creating new attribute %s",
		      inst->config->xlat_name, group_name);

		memset(&flags, 0, sizeof(flags));
		if (dict_addattr(group_name, -1, 0, PW_TYPE_STRING, flags) < 0) {
			ERROR("rlm_sql (%s): Failed to create "
			       "attribute %s: %s", inst->config->xlat_name, group_name,
			       fr_strerror());
			return -1;
		}

		da = dict_attrbyname(group_name);
		if (!da) {
			ERROR("rlm_sql (%s): Failed to create "
			       "attribute %s", inst->config->xlat_name, group_name);
			return -1;
		}

		if (inst->config->groupmemb_query &&
		    inst->config->groupmemb_query[0]) {
			DEBUG("rlm_sql (%s): Registering sql_groupcmp for %s",
			      inst->config->xlat_name, group_name);
			paircompare_register(da, dict_attrbyvalue(PW_USER_NAME, 0),
					     false, sql_groupcmp, inst);
		}
	}

	rad_assert(inst->config->xlat_name);

	/*
	 *	If the configuration parameters can't be parsed, then fail.
	 */
	if ((parse_sub_section(conf, inst, &inst->config->accounting, RLM_COMPONENT_ACCT) < 0) ||
	    (parse_sub_section(conf, inst, &inst->config->postauth, RLM_COMPONENT_POST_AUTH) < 0)) {
		cf_log_err_cs(conf, "Invalid configuration");
		return -1;
	}

	/*
	 *	Cache the SQL-User-Name DICT_ATTR, so we can be slightly
	 *	more efficient about creating SQL-User-Name attributes.
	 */
	inst->sql_user = dict_attrbyname("SQL-User-Name");
	if (!inst->sql_user) {
		return -1;
	}

	/*
	 *	Export these methods, too.  This avoids RTDL_GLOBAL.
	 */
	inst->sql_set_user		= sql_set_user;
	inst->sql_get_socket		= sql_get_socket;
	inst->sql_release_socket	= sql_release_socket;
	inst->sql_escape_func		= sql_escape_func;
	inst->sql_query			= rlm_sql_query;
	inst->sql_select_query		= rlm_sql_select_query;
	inst->sql_fetch_row		= rlm_sql_fetch_row;

	/*
	 *	Register the SQL xlat function
	 */
	xlat_register(inst->config->xlat_name, sql_xlat, sql_escape_func, inst);

	/*
	 *	Sanity check for crazy people.
	 */
	if (strncmp(inst->config->sql_driver_name, "rlm_sql_", 8) != 0) {
		ERROR("rlm_sql (%s): \"%s\" is NOT an SQL driver!",
		       inst->config->xlat_name, inst->config->sql_driver_name);
		return -1;
	}

	/*
	 *	Load the appropriate driver for our database
	 */
	inst->handle = lt_dlopenext(inst->config->sql_driver_name);
	if (!inst->handle) {
		ERROR("Could not link driver %s: %s",
		       inst->config->sql_driver_name,
		       dlerror());
		ERROR("Make sure it (and all its dependent libraries!)"
		       "are in the search path of your system's ld");
		return -1;
	}

	inst->module = (rlm_sql_module_t *) dlsym(inst->handle,
						  inst->config->sql_driver_name);
	if (!inst->module) {
		ERROR("Could not link symbol %s: %s",
		       inst->config->sql_driver_name,
		       dlerror());
		return -1;
	}

	if (inst->module->mod_instantiate) {
		CONF_SECTION *cs;
		char const *name;

		name = strrchr(inst->config->sql_driver_name, '_');
		if (!name) {
			name = inst->config->sql_driver_name;
		} else {
			name++;
		}

		cs = cf_section_sub_find(conf, name);
		if (!cs) {
			cs = cf_section_alloc(conf, name, NULL);
			if (!cs) {
				return -1;
			}
		}

		/*
		 *	It's up to the driver to register a destructor
		 */
		if (inst->module->mod_instantiate(cs, inst->config) < 0) {
			return -1;
		}
	}

	inst->lf = fr_logfile_init(inst);
	if (!inst->lf) {
		cf_log_err_cs(conf, "Failed creating log file context");
		return -1;
	}

	INFO("rlm_sql (%s): Driver %s (module %s) loaded and linked",
	       inst->config->xlat_name, inst->config->sql_driver_name,
	       inst->module->name);

	/*
	 *	Initialise the connection pool for this instance
	 */
	INFO("rlm_sql (%s): Attempting to connect to database \"%s\"",
	       inst->config->xlat_name, inst->config->sql_db);

	if (sql_socket_pool_init(inst) < 0) return -1;

	if (inst->config->groupmemb_query &&
	    inst->config->groupmemb_query[0]) {
		paircompare_register(dict_attrbyvalue(PW_SQL_GROUP, 0),
				dict_attrbyvalue(PW_USER_NAME, 0), false, sql_groupcmp, inst);
	}

	if (inst->config->do_clients) {
		if (generate_sql_clients(inst) == -1){
			ERROR("Failed to load clients from SQL");
			return -1;
		}
	}

	return RLM_MODULE_OK;
}
Exemplo n.º 28
0
int main(int argc, char **argv)
{
#if defined(ENABLE_LIBJVM) && !defined(WITH_STATIC_CLASSPATH)
	char           *path;
#endif

#if defined(ENABLE_LIBJVM)	
	/* Variables for JNI_CreateJavaVM dlopen call. */
	lt_dlhandle     libjvm_handle;
	lt_ptr          libjvm_vm_createjvm;
	lt_ptr          libjvm_vm_run;
	const char     *lterror;

	bool (*vm_createjvm)(JavaVM **, void **, void *);
	void (*vm_run)(JavaVM *, JavaVMInitArgs *);
#endif

	JavaVM         *vm;                 /* denotes a Java VM                  */
	JNIEnv         *env;
	JavaVMInitArgs *vm_args;

	/* prepare the options */

	/* vm_args = cacao_options_prepare(argc, argv); */
/*	char *tmp[] = {"cacao", "hello"};
	vm_args = cacao_options_prepare(2, &tmp); 
	char *tmp[] = {"cacao", "jbe.DoMicro"};
	char *tmp[] = {"cacao", "jbe.BenchKfl"};
	char *tmp[] = {"cacao", "jbe.BenchLift"};
	char *tmp[] = {"cacao", "jbe.BenchUdpIp"};
        char *tmp[] = {"cacao", "jbe.BenchUnpredictableKfl"};
        char *tmp[] = {"cacao", "jbe.BenchPredictableKfl"};
*/
	/*char *tmp[] = {"cacao", "hello"};*/
	char *tmp[] = {"cacao", "jbe.DoKernel"};
	/*char *tmp[] = {"cacao", "jbe.BenchKfl"};*/
	/*char *tmp[] = {"cacao", "jbe.BenchLift"};*/
	/*char *tmp[] = {"cacao", "jbe.DoMicro"};*/
	/*char *tmp[] = {"cacao", "jbe.BenchUdpIp"};*/

	vm_args = cacao_options_prepare(2, &tmp);

	/* load and initialize a Java VM, return a JNI interface pointer in env */

#if defined(ENABLE_LIBJVM) && !defined(WITH_STATIC_CLASSPATH)
# if defined(WITH_JRE_LAYOUT)
	/* SUN also uses a buffer of 4096-bytes (strace is your friend). */

	path = malloc(sizeof(char) * 4096);

	if (readlink("/proc/self/exe", path, 4095) == -1) {
		fprintf(stderr, "main: readlink failed: %s\n", strerror(errno));
		abort();
	}

	/* get the path of the current executable */

	path = dirname(path);

	if ((strlen(path) + strlen("/../lib/libjvm") + strlen("0")) > 4096) {
		fprintf(stderr, "main: libjvm name to long for buffer\n");
		abort();
	}

	/* concatinate the library name */

	strcat(path, "/../lib/libjvm");
# else
	path = CACAO_LIBDIR"/libjvm";
# endif

	if (lt_dlinit()) {
		fprintf(stderr, "main: lt_dlinit failed: %s\n", lt_dlerror());
		abort();
	}

	/* First try to open where dlopen searches, e.g. LD_LIBRARY_PATH.
	   If not found, try the absolute path. */

	if (!(libjvm_handle = lt_dlopenext("libjvm"))) {
		/* save the error message */

		lterror = strdup(lt_dlerror());

		if (!(libjvm_handle = lt_dlopenext(path))) {
			/* print the first error message too */

			fprintf(stderr, "main: lt_dlopenext failed: %s\n", lterror);

			/* and now the current one */

			fprintf(stderr, "main: lt_dlopenext failed: %s\n", lt_dlerror());
			abort();
		}

		/* free the error string */

		free((void *) lterror);
	}

	if (!(libjvm_vm_createjvm = lt_dlsym(libjvm_handle, "vm_createjvm"))) {
		fprintf(stderr, "main: lt_dlsym failed: %s\n", lt_dlerror());
		abort();
	}

	vm_createjvm =
		(bool (*)(JavaVM **, void **, void *)) (ptrint) libjvm_vm_createjvm;
#endif

	/* create the Java VM */

	(void) vm_createjvm(&vm, (void *) &env, vm_args);

#if defined(ENABLE_JVMTI)
	pthread_mutex_init(&dbgcomlock,NULL);
	if (jvmti) jvmti_set_phase(JVMTI_PHASE_START);
#endif

#if !defined(WITH_STATIC_CLASSPATH) && defined(ENABLE_LIBJVM)
	if (!(libjvm_vm_run = lt_dlsym(libjvm_handle, "vm_run"))) {
		fprintf(stderr, "lt_dlsym failed: %s\n", lt_dlerror());
		abort();
	}

	vm_run = (void (*)(JavaVM *, JavaVMInitArgs *)) (ptrint) libjvm_vm_run;
#endif

	/* run the VM */

	vm_run(vm, vm_args);

	/* keep compiler happy */

	return 0;
}
Exemplo n.º 29
0
int module_load(const char* file_name, int argc, char *argv[])
{
	module_loaded_t *module;
	const char *error;
	int rc;
	MODULE_INIT_FN initialize;
#ifdef HAVE_EBCDIC
#define	file	ebuf
#else
#define	file	file_name
#endif

	module = module_handle( file_name );
	if ( module ) {
		Debug( LDAP_DEBUG_ANY, "module_load: (%s) already loaded\n",
			file_name, 0, 0 );
		return -1;
	}

	/* If loading a backend, see if we already have it */
	if ( !strncasecmp( file_name, "back_", 5 )) {
		char *name = (char *)file_name + 5;
		char *dot = strchr( name, '.');
		if (dot) *dot = '\0';
		rc = backend_info( name ) != NULL;
		if (dot) *dot = '.';
		if ( rc ) {
			Debug( LDAP_DEBUG_CONFIG, "module_load: (%s) already present (static)\n",
				file_name, 0, 0 );
			return 0;
		}
	} else {
		/* check for overlays too */
		char *dot = strchr( file_name, '.' );
		if ( dot ) *dot = '\0';
		rc = overlay_find( file_name ) != NULL;
		if ( dot ) *dot = '.';
		if ( rc ) {
			Debug( LDAP_DEBUG_CONFIG, "module_load: (%s) already present (static)\n",
				file_name, 0, 0 );
			return 0;
		}
	}

	module = (module_loaded_t *)ch_calloc(1, sizeof(module_loaded_t) +
		strlen(file_name));
	if (module == NULL) {
		Debug(LDAP_DEBUG_ANY, "module_load failed: (%s) out of memory\n", file_name,
			0, 0);

		return -1;
	}
	strcpy( module->name, file_name );

#ifdef HAVE_EBCDIC
	strcpy( file, file_name );
	__atoe( file );
#endif
	/*
	 * The result of lt_dlerror(), when called, must be cached prior
	 * to calling Debug. This is because Debug is a macro that expands
	 * into multiple function calls.
	 */
	if ((module->lib = lt_dlopenext(file)) == NULL) {
		error = lt_dlerror();
#ifdef HAVE_EBCDIC
		strcpy( ebuf, error );
		__etoa( ebuf );
		error = ebuf;
#endif
		Debug(LDAP_DEBUG_ANY, "lt_dlopenext failed: (%s) %s\n", file_name,
			error, 0);

		ch_free(module);
		return -1;
	}

	Debug(LDAP_DEBUG_CONFIG, "loaded module %s\n", file_name, 0, 0);

   
#ifdef HAVE_EBCDIC
#pragma convlit(suspend)
#endif
	if ((initialize = lt_dlsym(module->lib, "init_module")) == NULL) {
#ifdef HAVE_EBCDIC
#pragma convlit(resume)
#endif
		Debug(LDAP_DEBUG_CONFIG, "module %s: no init_module() function found\n",
			file_name, 0, 0);

		lt_dlclose(module->lib);
		ch_free(module);
		return -1;
	}

	/* The imported init_module() routine passes back the type of
	 * module (i.e., which part of slapd it should be hooked into)
	 * or -1 for error.  If it passes back 0, then you get the 
	 * old behavior (i.e., the library is loaded and not hooked
	 * into anything).
	 *
	 * It might be better if the conf file could specify the type
	 * of module.  That way, a single module could support multiple
	 * type of hooks. This could be done by using something like:
	 *
	 *    moduleload extension /usr/local/openldap/whatever.so
	 *
	 * then we'd search through module_regtable for a matching
	 * module type, and hook in there.
	 */
	rc = initialize(argc, argv);
	if (rc == -1) {
		Debug(LDAP_DEBUG_CONFIG, "module %s: init_module() failed\n",
			file_name, 0, 0);

		lt_dlclose(module->lib);
		ch_free(module);
		return rc;
	}

	if (rc >= (int)(sizeof(module_regtable) / sizeof(struct module_regtable_t))
		|| module_regtable[rc].proc == NULL)
	{
		Debug(LDAP_DEBUG_CONFIG, "module %s: unknown registration type (%d)\n",
			file_name, rc, 0);

		module_int_unload(module);
		return -1;
	}

	rc = (module_regtable[rc].proc)(module, file_name);
	if (rc != 0) {
		Debug(LDAP_DEBUG_CONFIG, "module %s: %s module could not be registered\n",
			file_name, module_regtable[rc].type, 0);

		module_int_unload(module);
		return rc;
	}

	module->next = module_list;
	module_list = module;

	Debug(LDAP_DEBUG_CONFIG, "module %s: %s module registered\n",
		file_name, module_regtable[rc].type, 0);

	return 0;
}
Exemplo n.º 30
0
/*
 *	Find a module on disk or in memory, and link to it.
 */
static module_list_t *linkto_module(const char *module_name,
		const char *cffilename, int cflineno)
{
	module_list_t *node;
	lt_dlhandle handle;
	char module_struct[256];
	char *p;

	/*
	 *	Look through the global module library list for the
	 *	named module.
	 */
	for (node = module_list; node != NULL; node = node->next) {
		/*
		 *	Found the named module.  Return it.
		 */
		if (strcmp(node->name, module_name) == 0)
			return node;

	}

	/*
	 *	Keep the handle around so we can dlclose() it.
	 */
	handle = lt_dlopenext(module_name);
	if (handle == NULL) {
		radlog(L_ERR|L_CONS, "%s[%d] Failed to link to module '%s':"
				" %s\n", cffilename, cflineno, module_name, lt_dlerror());
		return NULL;
	}

	/* make room for the module type */
	node = (module_list_t *) rad_malloc(sizeof(module_list_t));

	/* fill in the module structure */
	node->next = NULL;
	node->handle = handle;
	strNcpy(node->name, module_name, sizeof(node->name));
	
	/*
	 *	Link to the module's rlm_FOO{} module structure.
	 */
	/* module_name has the version embedded; strip it. */
	strcpy(module_struct, module_name);
	p = strrchr(module_struct, '-');
	if (p)
		*p = '\0';
	node->module = (module_t *) lt_dlsym(node->handle, module_struct);
	if (!node->module) {
		radlog(L_ERR|L_CONS, "%s[%d] Failed linking to "
				"%s structure in %s: %s\n",
				cffilename, cflineno,
				module_name, cffilename, lt_dlerror());
		lt_dlclose(node->handle);	/* ignore any errors */
		free(node);
		return NULL;
	}
	
	/* call the modules initialization */
	if (node->module->init && (node->module->init)() < 0) {
		radlog(L_ERR|L_CONS, "%s[%d] Module initialization failed.\n",
				cffilename, cflineno);
		lt_dlclose(node->handle);	/* ignore any errors */
		free(node);
		return NULL;
	}

	DEBUG("Module: Loaded %s ", node->module->name);

	node->next = module_list;
	module_list = node;

	return node;
}