static Module *load_stdmodule( const char *modfilename, Client * u ) { int err; void *handle; ModuleInfo *infoptr = NULL; ModuleEvent *eventlistptr = NULL; Module *mod_ptr = NULL; int( *ModInit )( void ); CmdParams *cmd; SET_SEGV_LOCATION(); if( hash_isfull( modulehash ) ) { load_module_error( u, modfilename, __( "module list is full", u ) ); return NULL; } handle = ns_dlopen( modfilename, RTLD_NOW | RTLD_GLOBAL ); if( !handle ) { load_module_error( u, modfilename, ns_dlerrormsg, modfilename ); return NULL; } infoptr = ns_dlsym( handle, "module_info" ); if( infoptr == NULL ) { load_module_error( u, modfilename, __( "missing module_info", u ) ); ns_dlclose( handle ); return NULL; } /* Check module was built for this version of NeoStats */ if( ircstrncasecmp( NEOSTATS_VERSION, infoptr->neostats_version, VERSIONSIZE ) !=0 ) { load_module_error( u, modfilename, __( "module built with an old version of NeoStats and must be rebuilt.", u ) ); ns_dlclose( handle ); return NULL; } if( !infoptr->copyright || ircstrcasecmp( infoptr->copyright[0], "Copyright (c) <year>, <your name>" ) ==0 ) { load_module_error( u, modfilename, __( "missing copyright text.", u ) ); ns_dlclose( handle ); return NULL; } if( !infoptr->about_text || ircstrcasecmp( infoptr->about_text[0], "About your module" ) ==0 ) { load_module_error( u, modfilename, __( "missing about text.", u ) ); ns_dlclose( handle ); return NULL; } /* Check that the Module hasn't already been loaded */ if( hash_lookup( modulehash, infoptr->name ) ) { ns_dlclose( handle ); load_module_error( u, modfilename, __( "already loaded", u ) ); return NULL; } /* Check we have require PROTOCOL/FEATURE support for module */ if( ( infoptr->features & ircd_srv.features ) != infoptr->features ) { load_module_error( u, modfilename, __( "Required module features not available on this IRCd.", u ), modfilename ); ns_dlclose( handle ); return NULL; } /* Lookup ModInit( replacement for library __init() call */ ModInit = ns_dlsym( ( int * ) handle, "ModInit" ); if( !ModInit ) { load_module_error( u, modfilename, __( "missing ModInit.", u ) ); ns_dlclose( handle ); return NULL; } /* Allocate module */ mod_ptr = ( Module * ) ns_calloc( sizeof( Module ) ); dlog( DEBUG1, "Module internal name: %s", infoptr->name ); dlog( DEBUG1, "Module description: %s", infoptr->description ); mod_ptr->info = infoptr; mod_ptr->handle = handle; insert_module( mod_ptr ); mod_ptr->type = MOD_TYPE_STANDARD; /* Extract pointer to event list */ eventlistptr = ns_dlsym( handle, "module_events" ); if( eventlistptr ) { SET_RUN_LEVEL( mod_ptr ); AddEventList( eventlistptr ); RESET_RUN_LEVEL(); } /* For Auth modules, register auth function */ if( infoptr->flags & MODULE_FLAG_AUTH ) { if( AddAuthModule( mod_ptr ) != NS_SUCCESS ) { load_module_error( u, modfilename, __( "Unable to load auth module: %s missing ModAuthUser function",u ), infoptr->name ); unload_module( mod_ptr->info->name, NULL ); return NULL; } } /* Module side user authentication for e.g. SecureServ helpers * Not available on auth modules */ if( !( infoptr->flags & MODULE_FLAG_AUTH ) ) mod_ptr->authcb = ns_dlsym( ( int * ) handle, "ModAuthUser" ); if( infoptr->flags & MODULE_FLAG_CTCP_VERSION ) me.versionscan ++; /* assign a module number to this module */ assign_mod_number( mod_ptr ); SET_SEGV_LOCATION(); SET_RUN_LEVEL( mod_ptr ); DBAOpenDatabase(); err = ( *ModInit )(); RESET_RUN_LEVEL(); if( err < 1 || IsModuleError( mod_ptr ) ) { load_module_error( u, modfilename, __( "See %s.log for further information.",u ), mod_ptr->info->name ); unload_module( mod_ptr->info->name, NULL ); return NULL; } if( infoptr->flags & MODULE_FLAG_LOCAL_EXCLUDES ) { SET_RUN_LEVEL( mod_ptr ); InitExcludes( mod_ptr ); RESET_RUN_LEVEL(); } SET_SEGV_LOCATION(); /* Let this module know we are online if we are! */ if( IsNeoStatsSynched() ) { if( SynchModule( mod_ptr ) != NS_SUCCESS || IsModuleError( mod_ptr ) ) { load_module_error( u, modfilename, __( "See %s.log for further information.", u ), mod_ptr->info->name ); unload_module( mod_ptr->info->name, NULL ); return NULL; } } cmd = ns_calloc( sizeof( CmdParams ) ); cmd->param = ( char * )infoptr->name; SendAllModuleEvent( EVENT_MODULELOAD, cmd ); ns_free( cmd ); if( u ) { irc_prefmsg( ns_botptr, u, __( "Module %s loaded, %s",u ), infoptr->name, infoptr->description ); irc_globops( NULL, _( "Module %s loaded" ), infoptr->name ); } return mod_ptr; }
static void ipmi_init(struct opal_prd_ctx *ctx) { insert_module("ipmi_devintf"); }
/* Add new module. */ static void internal_function add_module (char *rp, const char *directory, size_t dir_len, void **modules, size_t *nmodules, int modcounter) { /* We expect now 1. `from' name 2. `to' name 3. filename of the module 4. an optional cost value */ struct gconv_alias fake_alias; struct gconv_module *new_module; char *from, *to, *module, *wp; int need_ext; int cost_hi; while (__isspace_l (*rp, &_nl_C_locobj)) ++rp; from = rp; while (*rp != '\0' && !__isspace_l (*rp, &_nl_C_locobj)) { *rp = __toupper_l (*rp, &_nl_C_locobj); ++rp; } if (*rp == '\0') return; *rp++ = '\0'; to = wp = rp; while (__isspace_l (*rp, &_nl_C_locobj)) ++rp; while (*rp != '\0' && !__isspace_l (*rp, &_nl_C_locobj)) *wp++ = __toupper_l (*rp++, &_nl_C_locobj); if (*rp == '\0') return; *wp++ = '\0'; do ++rp; while (__isspace_l (*rp, &_nl_C_locobj)); module = wp; while (*rp != '\0' && !__isspace_l (*rp, &_nl_C_locobj)) *wp++ = *rp++; if (*rp == '\0') { /* There is no cost, use one by default. */ *wp++ = '\0'; cost_hi = 1; } else { /* There might be a cost value. */ char *endp; *wp++ = '\0'; cost_hi = strtol (rp, &endp, 10); if (rp == endp || cost_hi < 1) /* No useful information. */ cost_hi = 1; } if (module[0] == '\0') /* No module name given. */ return; if (module[0] == '/') dir_len = 0; /* See whether we must add the ending. */ need_ext = 0; if (wp - module < (ptrdiff_t) sizeof (gconv_module_ext) || memcmp (wp - sizeof (gconv_module_ext), gconv_module_ext, sizeof (gconv_module_ext)) != 0) /* We must add the module extension. */ need_ext = sizeof (gconv_module_ext) - 1; /* See whether we have already an alias with this name defined. */ fake_alias.fromname = strndupa (from, to - from); if (__tfind (&fake_alias, &__gconv_alias_db, __gconv_alias_compare) != NULL) /* This module duplicates an alias. */ return; new_module = (struct gconv_module *) calloc (1, sizeof (struct gconv_module) + (wp - from) + dir_len + need_ext); if (new_module != NULL) { char *tmp; new_module->from_string = tmp = (char *) (new_module + 1); tmp = __mempcpy (tmp, from, to - from); new_module->to_string = tmp; tmp = __mempcpy (tmp, to, module - to); new_module->cost_hi = cost_hi; new_module->cost_lo = modcounter; new_module->module_name = tmp; if (dir_len != 0) tmp = __mempcpy (tmp, directory, dir_len); tmp = __mempcpy (tmp, module, wp - module); if (need_ext) memcpy (tmp - 1, gconv_module_ext, sizeof (gconv_module_ext)); /* Now insert the new module data structure in our search tree. */ insert_module (new_module, 1); } }