2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* modules.c: A module loader.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "modules.h"
|
2008-04-03 04:52:01 +02:00
|
|
|
#include "logger.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "ircd_defs.h"
|
2008-04-20 07:47:38 +02:00
|
|
|
#include "match.h"
|
2016-01-12 07:37:54 +01:00
|
|
|
#include "s_serv.h"
|
2016-03-06 23:53:03 +01:00
|
|
|
#include "capability.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-01-06 04:39:09 +01:00
|
|
|
#include <ltdl.h>
|
|
|
|
|
2016-03-13 03:10:46 +01:00
|
|
|
#ifndef LT_MODULE_EXT
|
|
|
|
# error "Charybdis requires loadable module support."
|
|
|
|
#endif
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
struct module **modlist = NULL;
|
|
|
|
|
|
|
|
static const char *core_module_table[] = {
|
2010-03-05 18:36:44 +01:00
|
|
|
"m_ban",
|
2007-01-25 07:40:21 +01:00
|
|
|
"m_die",
|
|
|
|
"m_error",
|
|
|
|
"m_join",
|
|
|
|
"m_kick",
|
|
|
|
"m_kill",
|
|
|
|
"m_message",
|
|
|
|
"m_mode",
|
|
|
|
"m_nick",
|
|
|
|
"m_part",
|
|
|
|
"m_quit",
|
|
|
|
"m_server",
|
|
|
|
"m_squit",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-03-08 01:10:22 +01:00
|
|
|
#define MOD_WARN_DELTA (90 * 86400) /* time in seconds, 86400 seconds in a day */
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
#define MODS_INCREMENT 10
|
|
|
|
int num_mods = 0;
|
|
|
|
int max_mods = MODS_INCREMENT;
|
|
|
|
|
2008-04-01 22:41:52 +02:00
|
|
|
static rb_dlink_list mod_paths;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void mo_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
|
|
|
|
static void me_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
|
|
|
|
static void do_modload(struct Client *, const char *);
|
|
|
|
static void do_modunload(struct Client *, const char *);
|
|
|
|
static void do_modreload(struct Client *, const char *);
|
|
|
|
static void do_modlist(struct Client *, const char *);
|
|
|
|
static void do_modrestart(struct Client *);
|
2016-01-12 07:37:54 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
struct Message modload_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"MODLOAD", 0, 0, 0, 0,
|
2016-01-12 07:37:54 +01:00
|
|
|
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modload, 2}, {mo_modload, 2}}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Message modunload_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"MODUNLOAD", 0, 0, 0, 0,
|
2016-01-12 07:37:54 +01:00
|
|
|
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modunload, 2}, {mo_modunload, 2}}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Message modreload_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"MODRELOAD", 0, 0, 0, 0,
|
2016-01-12 07:37:54 +01:00
|
|
|
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modreload, 2}, {mo_modreload, 2}}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Message modlist_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"MODLIST", 0, 0, 0, 0,
|
2016-01-12 07:37:54 +01:00
|
|
|
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modlist, 0}, {mo_modlist, 0}}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Message modrestart_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"MODRESTART", 0, 0, 0, 0,
|
2016-01-12 07:37:54 +01:00
|
|
|
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modrestart, 0}, {mo_modrestart, 0}}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
modules_init(void)
|
|
|
|
{
|
2016-01-06 04:39:09 +01:00
|
|
|
if(lt_dlinit())
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "lt_dlinit failed");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
mod_add_cmd(&modload_msgtab);
|
|
|
|
mod_add_cmd(&modunload_msgtab);
|
|
|
|
mod_add_cmd(&modreload_msgtab);
|
|
|
|
mod_add_cmd(&modlist_msgtab);
|
|
|
|
mod_add_cmd(&modrestart_msgtab);
|
|
|
|
|
|
|
|
/* Add the default paths we look in to the module system --nenolod */
|
2016-03-25 00:45:28 +01:00
|
|
|
mod_add_path(ircd_paths[IRCD_PATH_MODULES]);
|
|
|
|
mod_add_path(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_find_path()
|
|
|
|
*
|
|
|
|
* input - path
|
|
|
|
* output - none
|
|
|
|
* side effects - returns a module path from path
|
|
|
|
*/
|
2014-02-23 23:47:27 +01:00
|
|
|
static char *
|
2007-01-25 07:40:21 +01:00
|
|
|
mod_find_path(const char *path)
|
|
|
|
{
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2014-02-23 23:47:27 +01:00
|
|
|
char *mpath;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, mod_paths.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
mpath = ptr->data;
|
|
|
|
|
2014-02-23 23:47:27 +01:00
|
|
|
if(!strcmp(path, mpath))
|
2007-01-25 07:40:21 +01:00
|
|
|
return mpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_add_path
|
|
|
|
*
|
|
|
|
* input - path
|
2014-03-03 05:25:47 +01:00
|
|
|
* ouput -
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - adds path to list
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mod_add_path(const char *path)
|
|
|
|
{
|
2014-02-23 23:47:27 +01:00
|
|
|
char *pathst;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(mod_find_path(path))
|
|
|
|
return;
|
|
|
|
|
2014-02-23 23:47:27 +01:00
|
|
|
pathst = rb_strdup(path);
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlinkAddAlloc(pathst, &mod_paths);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_clear_paths()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects - clear the lists of paths
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mod_clear_paths(void)
|
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *ptr, *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(ptr->data);
|
2008-04-02 03:03:13 +02:00
|
|
|
rb_free_rb_dlink_node(ptr);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mod_paths.head = mod_paths.tail = NULL;
|
|
|
|
mod_paths.length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* findmodule_byname
|
|
|
|
*
|
2016-04-03 08:51:26 +02:00
|
|
|
* input - module to load
|
|
|
|
* output - index of module on success, -1 on failure
|
|
|
|
* side effects - none
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
findmodule_byname(const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
2016-03-20 12:00:20 +01:00
|
|
|
char name_ext[PATH_MAX + 1];
|
|
|
|
|
2016-03-20 12:01:12 +01:00
|
|
|
rb_strlcpy(name_ext, name, sizeof name_ext);
|
|
|
|
rb_strlcat(name_ext, LT_MODULE_EXT, sizeof name_ext);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
for (i = 0; i < num_mods; i++)
|
|
|
|
{
|
|
|
|
if(!irccmp(modlist[i]->name, name))
|
|
|
|
return i;
|
2016-03-20 12:00:20 +01:00
|
|
|
|
|
|
|
if(!irccmp(modlist[i]->name, name_ext))
|
|
|
|
return i;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-03-20 12:00:20 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load_all_modules()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-04-03 08:51:26 +02:00
|
|
|
load_all_modules(bool warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
DIR *system_module_dir = NULL;
|
|
|
|
struct dirent *ldirent = NULL;
|
|
|
|
char module_fq_name[PATH_MAX + 1];
|
2016-03-18 21:32:33 +01:00
|
|
|
size_t module_ext_len = strlen(LT_MODULE_EXT);
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
modules_init();
|
|
|
|
|
2014-02-23 22:39:42 +01:00
|
|
|
modlist = (struct module **) rb_malloc(sizeof(struct module *) * (MODS_INCREMENT));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
max_mods = MODS_INCREMENT;
|
|
|
|
|
2016-03-25 00:45:28 +01:00
|
|
|
system_module_dir = opendir(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(system_module_dir == NULL)
|
|
|
|
{
|
2016-03-25 00:45:28 +01:00
|
|
|
ilog(L_MAIN, "Could not load modules from %s: %s", ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], strerror(errno));
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ldirent = readdir(system_module_dir)) != NULL)
|
|
|
|
{
|
2016-04-03 08:21:06 +02:00
|
|
|
size_t len = strlen(ldirent->d_name);
|
2016-03-13 03:10:46 +01:00
|
|
|
|
2016-04-03 08:21:06 +02:00
|
|
|
if(len > module_ext_len &&
|
|
|
|
strncasecmp(ldirent->d_name + (len - module_ext_len), LT_MODULE_EXT, module_ext_len) == 0)
|
2016-02-10 02:25:32 +01:00
|
|
|
{
|
2016-04-03 08:21:06 +02:00
|
|
|
(void) snprintf(module_fq_name, sizeof(module_fq_name), "%s%c%s",
|
|
|
|
ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], RB_PATH_SEPARATOR, ldirent->d_name);
|
2016-04-03 08:51:26 +02:00
|
|
|
(void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, false);
|
2016-02-10 02:25:32 +01:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
(void) closedir(system_module_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load_core_modules()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects - core modules are loaded, if any fail, kill ircd
|
|
|
|
*/
|
|
|
|
void
|
2016-04-03 08:51:26 +02:00
|
|
|
load_core_modules(bool warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-10-28 16:45:18 +02:00
|
|
|
char module_name[PATH_MAX];
|
2007-01-25 07:40:21 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; core_module_table[i]; i++)
|
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
snprintf(module_name, sizeof(module_name), "%s%c%s", ircd_paths[IRCD_PATH_MODULES], RB_PATH_SEPARATOR,
|
|
|
|
core_module_table[i]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, true) == false)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
ilog(L_MAIN,
|
2016-03-13 03:10:46 +01:00
|
|
|
"Error loading core module %s: terminating ircd",
|
|
|
|
core_module_table[i]);
|
2007-01-25 07:40:21 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load_one_module()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects -
|
|
|
|
*/
|
2016-04-03 08:51:26 +02:00
|
|
|
bool
|
|
|
|
load_one_module(const char *path, int origin, bool coremodule)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-10-28 16:45:18 +02:00
|
|
|
char modpath[PATH_MAX];
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *pathst;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 09:19:31 +01:00
|
|
|
if (server_state_foreground)
|
2014-03-03 05:25:47 +01:00
|
|
|
inotice("loading module %s ...", path);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(coremodule)
|
2016-03-07 01:56:45 +01:00
|
|
|
origin = MAPI_ORIGIN_CORE;
|
|
|
|
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(pathst, mod_paths.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
struct stat statbuf;
|
|
|
|
const char *mpath = pathst->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
snprintf(modpath, sizeof(modpath), "%s%c%s%s", mpath, RB_PATH_SEPARATOR, path, LT_MODULE_EXT);
|
2007-01-25 07:40:21 +01:00
|
|
|
if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
|
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
if(stat(modpath, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
/* Regular files only please */
|
|
|
|
return load_a_module(modpath, true, origin, coremodule);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Cannot locate module %s", path);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* load a module .. */
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:13:44 +01:00
|
|
|
mo_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(!IsOperAdmin(source_p))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "admin");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 07:37:54 +01:00
|
|
|
if(parc > 2)
|
|
|
|
{
|
|
|
|
sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s MODLOAD %s", parv[2], parv[1]);
|
2016-04-03 08:51:26 +02:00
|
|
|
if(match(parv[2], me.name) == 0)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modload(source_p, parv[1]);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:13:44 +01:00
|
|
|
me_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2016-01-12 07:37:54 +01:00
|
|
|
{
|
|
|
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
|
|
|
|
"to load modules on this server.");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modload(source_p, parv[1]);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
|
|
|
|
/* unload a module .. */
|
|
|
|
static void
|
|
|
|
mo_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2016-01-12 07:37:54 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
if(!IsOperAdmin(source_p))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "admin");
|
|
|
|
return;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
if(parc > 2)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s MODUNLOAD %s", parv[2], parv[1]);
|
2016-04-03 08:51:26 +02:00
|
|
|
if(match(parv[2], me.name) == 0)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modunload(source_p, parv[1]);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
|
|
|
me_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
|
|
|
{
|
|
|
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
|
|
|
|
"to load modules on this server.");
|
|
|
|
return;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modunload(source_p, parv[1]);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
/* unload and load in one! */
|
|
|
|
static void
|
|
|
|
mo_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(!IsOperAdmin(source_p))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "admin");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 07:37:54 +01:00
|
|
|
if(parc > 2)
|
|
|
|
{
|
|
|
|
sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
|
2016-03-09 08:37:03 +01:00
|
|
|
"ENCAP %s MODRELOAD %s", parv[2], parv[1]);
|
2016-04-03 08:51:26 +02:00
|
|
|
if(match(parv[2], me.name) == 0)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modreload(source_p, parv[1]);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
|
|
|
me_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2016-01-12 07:37:54 +01:00
|
|
|
{
|
|
|
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
|
|
|
|
"to load modules on this server.");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modreload(source_p, parv[1]);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
/* list modules .. */
|
|
|
|
static void
|
|
|
|
mo_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2016-01-12 07:37:54 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
if(!IsOperAdmin(source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "admin");
|
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
if(parc > 2)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s MODLIST %s", parv[2], parv[1]);
|
2016-04-03 08:51:26 +02:00
|
|
|
if(match(parv[2], me.name) == 0)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modlist(source_p, parc > 1 ? parv[1] : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
me_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
|
|
|
{
|
|
|
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
|
|
|
|
"to load modules on this server.");
|
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2007-01-25 08:23:01 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modlist(source_p, parv[1]);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
/* unload and reload all modules */
|
|
|
|
static void
|
|
|
|
mo_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(!IsOperAdmin(source_p))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "admin");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
if(parc > 1)
|
2016-01-12 07:37:54 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s MODRESTART", parv[1]);
|
2016-04-03 08:51:26 +02:00
|
|
|
if(match(parv[1], me.name) == 0)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modrestart(source_p);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
|
|
|
me_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
2016-01-12 07:37:54 +01:00
|
|
|
{
|
|
|
|
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
|
|
|
|
"to load modules on this server.");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
do_modrestart(source_p);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
|
|
|
do_modload(struct Client *source_p, const char *module)
|
|
|
|
{
|
|
|
|
char *m_bn = rb_basename(module);
|
|
|
|
int origin;
|
|
|
|
|
|
|
|
if(findmodule_byname(m_bn) != -1)
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":Module %s is already loaded", m_bn);
|
|
|
|
rb_free(m_bn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
origin = strcmp(module, m_bn) == 0 ? MAPI_ORIGIN_CORE : MAPI_ORIGIN_EXTENSION;
|
2016-04-03 08:51:26 +02:00
|
|
|
load_one_module(module, origin, false);
|
2016-03-09 08:37:03 +01:00
|
|
|
|
|
|
|
rb_free(m_bn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_modunload(struct Client *source_p, const char *module)
|
|
|
|
{
|
|
|
|
int modindex;
|
|
|
|
char *m_bn = rb_basename(module);
|
|
|
|
|
|
|
|
if((modindex = findmodule_byname(m_bn)) == -1)
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
|
|
|
|
rb_free(m_bn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(modlist[modindex]->core)
|
2016-03-09 08:37:03 +01:00
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn);
|
|
|
|
rb_free(m_bn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(unload_one_module(m_bn, true) == false)
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
|
|
|
|
|
|
|
|
rb_free(m_bn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-12 07:37:54 +01:00
|
|
|
do_modreload(struct Client *source_p, const char *module)
|
|
|
|
{
|
|
|
|
int modindex;
|
|
|
|
int check_core;
|
|
|
|
char *m_bn = rb_basename(module);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if((modindex = findmodule_byname(m_bn)) == -1)
|
|
|
|
{
|
2007-01-25 08:23:01 +01:00
|
|
|
sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(m_bn);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
check_core = modlist[modindex]->core;
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(unload_one_module(m_bn, true) == false)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2007-01-25 08:23:01 +01:00
|
|
|
sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(m_bn);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if((load_one_module(m_bn, modlist[modindex]->origin, check_core) == false) && check_core)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-01-12 07:37:54 +01:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
2010-01-31 02:21:17 +01:00
|
|
|
"Error reloading core module: %s: terminating ircd", m_bn);
|
|
|
|
ilog(L_MAIN, "Error loading core module %s: terminating ircd", m_bn);
|
2007-01-25 07:40:21 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(m_bn);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
|
|
|
do_modrestart(struct Client *source_p)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
int modnum;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_one_notice(source_p, ":Reloading all modules");
|
2016-01-12 07:37:54 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
modnum = num_mods;
|
|
|
|
while (num_mods)
|
2016-04-03 08:51:26 +02:00
|
|
|
unload_one_module(modlist[0]->name, false);
|
2016-01-12 07:37:54 +01:00
|
|
|
|
2016-04-03 08:53:34 +02:00
|
|
|
load_all_modules(false);
|
|
|
|
load_core_modules(false);
|
|
|
|
rehash(false);
|
2016-01-12 07:37:54 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
|
|
|
"Module Restart: %d modules unloaded, %d modules loaded",
|
|
|
|
modnum, num_mods);
|
|
|
|
ilog(L_MAIN, "Module Restart: %d modules unloaded, %d modules loaded", modnum, num_mods);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-01-12 07:37:54 +01:00
|
|
|
do_modlist(struct Client *source_p, const char *pattern)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
for (i = 0; i < num_mods; i++)
|
|
|
|
{
|
2016-03-07 06:21:08 +01:00
|
|
|
const char *origin;
|
|
|
|
switch (modlist[i]->origin)
|
|
|
|
{
|
|
|
|
case MAPI_ORIGIN_EXTENSION:
|
|
|
|
origin = "extension";
|
|
|
|
break;
|
|
|
|
case MAPI_ORIGIN_CORE:
|
|
|
|
origin = "builtin";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
origin = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-12 07:37:54 +01:00
|
|
|
if(pattern)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-01-12 07:37:54 +01:00
|
|
|
if(match(pattern, modlist[i]->name))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(RPL_MODLIST),
|
|
|
|
me.name, source_p->name,
|
|
|
|
modlist[i]->name,
|
2016-03-07 06:21:08 +01:00
|
|
|
(unsigned long)(uintptr_t)modlist[i]->address, origin,
|
|
|
|
modlist[i]->core ? " (core)" : "", modlist[i]->version, modlist[i]->description);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(RPL_MODLIST),
|
|
|
|
me.name, source_p->name, modlist[i]->name,
|
2016-03-07 06:21:08 +01:00
|
|
|
(unsigned long)(uintptr_t)modlist[i]->address, origin,
|
|
|
|
modlist[i]->core ? " (core)" : "", modlist[i]->version, modlist[i]->description);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), me.name, source_p->name);
|
2016-01-12 07:37:54 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
static void increase_modlist(void);
|
|
|
|
|
|
|
|
#define MODS_INCREMENT 10
|
|
|
|
|
|
|
|
static char unknown_ver[] = "<unknown>";
|
2016-03-06 23:53:03 +01:00
|
|
|
static char unknown_description[] = "<none>";
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* unload_one_module()
|
|
|
|
*
|
|
|
|
* inputs - name of module to unload
|
2016-04-03 08:51:26 +02:00
|
|
|
* - true to say modules unloaded, false to not
|
|
|
|
* output - true if successful, false if error
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - module is unloaded
|
|
|
|
*/
|
2016-04-03 08:51:26 +02:00
|
|
|
bool
|
|
|
|
unload_one_module(const char *name, bool warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int modindex;
|
|
|
|
|
|
|
|
if((modindex = findmodule_byname(name)) == -1)
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
** XXX - The type system in C does not allow direct conversion between
|
|
|
|
** data and function pointers, but as it happens, most C compilers will
|
2014-03-03 05:25:47 +01:00
|
|
|
** safely do this, however it is a theoretical overlow to cast as we
|
|
|
|
** must do here. I have library functions to take care of this, but
|
|
|
|
** despite being more "correct" for the C language, this is more
|
2007-01-25 07:40:21 +01:00
|
|
|
** practical. Removing the abuse of the ability to cast ANY pointer
|
|
|
|
** to and from an integer value here will break some compilers.
|
|
|
|
** -jmallett
|
|
|
|
*/
|
|
|
|
/* Left the comment in but the code isn't here any more -larne */
|
|
|
|
switch (modlist[modindex]->mapi_version)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av1 *mheader = modlist[modindex]->mapi_header;
|
|
|
|
if(mheader->mapi_command_list)
|
|
|
|
{
|
|
|
|
struct Message **m;
|
|
|
|
for (m = mheader->mapi_command_list; *m; ++m)
|
|
|
|
mod_del_cmd(*m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hook events are never removed, we simply lose the
|
|
|
|
* ability to call them --fl
|
|
|
|
*/
|
|
|
|
if(mheader->mapi_hfn_list)
|
|
|
|
{
|
|
|
|
mapi_hfn_list_av1 *m;
|
|
|
|
for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
|
|
|
|
remove_hook(m->hapi_name, m->fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mheader->mapi_unregister)
|
|
|
|
mheader->mapi_unregister();
|
|
|
|
break;
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av2 *mheader = modlist[modindex]->mapi_header;
|
|
|
|
|
|
|
|
/* XXX duplicate code :( */
|
|
|
|
if(mheader->mapi_command_list)
|
|
|
|
{
|
|
|
|
struct Message **m;
|
|
|
|
for (m = mheader->mapi_command_list; *m; ++m)
|
|
|
|
mod_del_cmd(*m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hook events are never removed, we simply lose the
|
|
|
|
* ability to call them --fl
|
|
|
|
*/
|
|
|
|
if(mheader->mapi_hfn_list)
|
|
|
|
{
|
|
|
|
mapi_hfn_list_av1 *m;
|
|
|
|
for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
|
|
|
|
remove_hook(m->hapi_name, m->fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mheader->mapi_unregister)
|
|
|
|
mheader->mapi_unregister();
|
|
|
|
|
|
|
|
if(mheader->mapi_cap_list)
|
|
|
|
{
|
|
|
|
mapi_cap_list_av2 *m;
|
|
|
|
for (m = mheader->mapi_cap_list; m->cap_name; ++m)
|
|
|
|
{
|
|
|
|
struct CapabilityIndex *idx;
|
|
|
|
|
2016-03-07 06:21:08 +01:00
|
|
|
switch (m->cap_index)
|
2016-03-06 23:53:03 +01:00
|
|
|
{
|
|
|
|
case MAPI_CAP_CLIENT:
|
|
|
|
idx = cli_capindex;
|
|
|
|
break;
|
|
|
|
case MAPI_CAP_SERVER:
|
|
|
|
idx = serv_capindex;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
|
|
|
|
m->cap_index, m->cap_name, modlist[modindex]->name);
|
|
|
|
ilog(L_MAIN,
|
|
|
|
"Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
|
|
|
|
m->cap_index, m->cap_name, modlist[modindex]->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-04 09:30:00 +02:00
|
|
|
if (m->cap_id != NULL)
|
|
|
|
{
|
|
|
|
capability_orphan(idx, m->cap_name);
|
|
|
|
sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * DEL :%s", me.name, m->cap_name);
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
default:
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Unknown/unsupported MAPI version %d when unloading %s!",
|
|
|
|
modlist[modindex]->mapi_version, modlist[modindex]->name);
|
|
|
|
ilog(L_MAIN, "Unknown/unsupported MAPI version %d when unloading %s!",
|
|
|
|
modlist[modindex]->mapi_version, modlist[modindex]->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-06 04:39:09 +01:00
|
|
|
lt_dlclose(modlist[modindex]->address);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(modlist[modindex]->name);
|
2016-02-09 17:48:28 +01:00
|
|
|
rb_free(modlist[modindex]);
|
2010-03-05 22:05:15 +01:00
|
|
|
memmove(&modlist[modindex], &modlist[modindex + 1],
|
2014-02-23 22:39:42 +01:00
|
|
|
sizeof(struct module *) * ((num_mods - 1) - modindex));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(num_mods != 0)
|
|
|
|
num_mods--;
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Module %s unloaded", name);
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Module %s unloaded", name);
|
|
|
|
}
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load_a_module()
|
|
|
|
*
|
2016-04-03 08:51:26 +02:00
|
|
|
* inputs - path name of module, bool to notice, int of origin, bool if core
|
|
|
|
* output - false if error true if success
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - loads a module if successful
|
|
|
|
*/
|
2016-04-03 08:51:26 +02:00
|
|
|
bool
|
|
|
|
load_a_module(const char *path, bool warn, int origin, bool core)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-01-06 04:39:09 +01:00
|
|
|
lt_dlhandle tmpptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
char *mod_basename;
|
2016-03-06 23:53:03 +01:00
|
|
|
const char *ver, *description = NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
int *mapi_version;
|
|
|
|
|
2008-12-03 00:59:13 +01:00
|
|
|
mod_basename = rb_basename(path);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-13 03:10:46 +01:00
|
|
|
tmpptr = lt_dlopenext(path);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(tmpptr == NULL)
|
|
|
|
{
|
2016-01-06 04:39:09 +01:00
|
|
|
const char *err = lt_dlerror();
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Error loading module %s: %s", mod_basename, err);
|
|
|
|
ilog(L_MAIN, "Error loading module %s: %s", mod_basename, err);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(mod_basename);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _mheader is actually a struct mapi_mheader_*, but mapi_version
|
|
|
|
* is always the first member of this structure, so we treate it
|
|
|
|
* as a single int in order to determine the API version.
|
|
|
|
* -larne.
|
|
|
|
*/
|
2016-01-06 04:39:09 +01:00
|
|
|
mapi_version = (int *) (uintptr_t) lt_dlsym(tmpptr, "_mheader");
|
2007-01-25 07:40:21 +01:00
|
|
|
if((mapi_version == NULL
|
2016-01-06 04:39:09 +01:00
|
|
|
&& (mapi_version = (int *) (uintptr_t) lt_dlsym(tmpptr, "__mheader")) == NULL)
|
2007-01-25 07:40:21 +01:00
|
|
|
|| MAPI_MAGIC(*mapi_version) != MAPI_MAGIC_HDR)
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Data format error: module %s has no MAPI header.",
|
|
|
|
mod_basename);
|
|
|
|
ilog(L_MAIN, "Data format error: module %s has no MAPI header.", mod_basename);
|
2016-01-06 04:39:09 +01:00
|
|
|
(void) lt_dlclose(tmpptr);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(mod_basename);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (MAPI_VERSION(*mapi_version))
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2015-04-20 07:55:20 +02:00
|
|
|
struct mapi_mheader_av1 *mheader = (struct mapi_mheader_av1 *)(void *)mapi_version; /* see above */
|
2007-01-25 07:40:21 +01:00
|
|
|
if(mheader->mapi_register && (mheader->mapi_register() == -1))
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Module %s indicated failure during load.",
|
|
|
|
mod_basename);
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Module %s indicated failure during load.",
|
|
|
|
mod_basename);
|
2016-01-06 04:39:09 +01:00
|
|
|
lt_dlclose(tmpptr);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(mod_basename);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
if(mheader->mapi_command_list)
|
|
|
|
{
|
|
|
|
struct Message **m;
|
|
|
|
for (m = mheader->mapi_command_list; *m; ++m)
|
|
|
|
mod_add_cmd(*m);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mheader->mapi_hook_list)
|
|
|
|
{
|
|
|
|
mapi_hlist_av1 *m;
|
|
|
|
for (m = mheader->mapi_hook_list; m->hapi_name; ++m)
|
|
|
|
*m->hapi_id = register_hook(m->hapi_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mheader->mapi_hfn_list)
|
|
|
|
{
|
|
|
|
mapi_hfn_list_av1 *m;
|
|
|
|
for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
|
|
|
|
add_hook(m->hapi_name, m->fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
ver = mheader->mapi_module_version;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av2 *mheader = (struct mapi_mheader_av2 *)(void *)mapi_version; /* see above */
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-06 23:53:03 +01:00
|
|
|
/* XXX duplicated code :( */
|
2016-04-04 02:14:36 +02:00
|
|
|
if(mheader->mapi_register && (mheader->mapi_register() == -1))
|
2016-03-06 23:53:03 +01:00
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Module %s indicated failure during load.",
|
2016-03-08 01:10:22 +01:00
|
|
|
mod_basename);
|
2016-03-06 23:53:03 +01:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Module %s indicated failure during load.",
|
|
|
|
mod_basename);
|
|
|
|
lt_dlclose(tmpptr);
|
|
|
|
rb_free(mod_basename);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2016-03-06 23:53:03 +01:00
|
|
|
}
|
2016-03-08 01:10:22 +01:00
|
|
|
|
|
|
|
/* Basic date code checks
|
|
|
|
*
|
|
|
|
* Don't make them fatal, but do complain about differences within a certain time frame.
|
|
|
|
* Later on if there are major API changes we can add fatal checks.
|
|
|
|
* -- Elizafox
|
|
|
|
*/
|
|
|
|
if(mheader->mapi_datecode != datecode && mheader->mapi_datecode > 0)
|
|
|
|
{
|
2016-03-08 20:46:19 +01:00
|
|
|
long int delta = datecode - mheader->mapi_datecode;
|
2016-03-08 01:10:22 +01:00
|
|
|
if (delta > MOD_WARN_DELTA)
|
|
|
|
{
|
|
|
|
delta /= 86400;
|
2016-03-08 20:47:41 +01:00
|
|
|
iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
|
2016-03-08 01:10:22 +01:00
|
|
|
mod_basename, delta);
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Module %s build date is out of sync with ircd build date by %ld days, expect problems",
|
|
|
|
mod_basename, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 23:53:03 +01:00
|
|
|
if(mheader->mapi_command_list)
|
|
|
|
{
|
|
|
|
struct Message **m;
|
|
|
|
for (m = mheader->mapi_command_list; *m; ++m)
|
|
|
|
mod_add_cmd(*m);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mheader->mapi_hook_list)
|
|
|
|
{
|
|
|
|
mapi_hlist_av1 *m;
|
|
|
|
for (m = mheader->mapi_hook_list; m->hapi_name; ++m)
|
|
|
|
*m->hapi_id = register_hook(m->hapi_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mheader->mapi_hfn_list)
|
|
|
|
{
|
|
|
|
mapi_hfn_list_av1 *m;
|
|
|
|
for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
|
|
|
|
add_hook(m->hapi_name, m->fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* New in MAPI v2 - version replacement */
|
|
|
|
ver = mheader->mapi_module_version ? mheader->mapi_module_version : ircd_version;
|
|
|
|
description = mheader->mapi_module_description;
|
|
|
|
|
|
|
|
if(mheader->mapi_cap_list)
|
|
|
|
{
|
|
|
|
mapi_cap_list_av2 *m;
|
|
|
|
for (m = mheader->mapi_cap_list; m->cap_name; ++m)
|
|
|
|
{
|
|
|
|
struct CapabilityIndex *idx;
|
|
|
|
int result;
|
|
|
|
|
2016-03-07 06:21:08 +01:00
|
|
|
switch (m->cap_index)
|
2016-03-06 23:53:03 +01:00
|
|
|
{
|
|
|
|
case MAPI_CAP_CLIENT:
|
|
|
|
idx = cli_capindex;
|
|
|
|
break;
|
|
|
|
case MAPI_CAP_SERVER:
|
|
|
|
idx = serv_capindex;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
|
|
|
|
m->cap_index, m->cap_name, mod_basename);
|
|
|
|
ilog(L_MAIN,
|
|
|
|
"Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
|
|
|
|
m->cap_index, m->cap_name, mod_basename);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = capability_put(idx, m->cap_name, m->cap_ownerdata);
|
|
|
|
if (m->cap_id != NULL)
|
2016-04-04 09:30:00 +02:00
|
|
|
{
|
2016-03-06 23:53:03 +01:00
|
|
|
*(m->cap_id) = result;
|
2016-04-04 09:30:00 +02:00
|
|
|
sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * ADD :%s", me.name, m->cap_name);
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-07 00:08:44 +01:00
|
|
|
|
|
|
|
break;
|
2007-01-25 07:40:21 +01:00
|
|
|
default:
|
|
|
|
ilog(L_MAIN, "Module %s has unknown/unsupported MAPI version %d.",
|
|
|
|
mod_basename, MAPI_VERSION(*mapi_version));
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Module %s has unknown/unsupported MAPI version %d.",
|
|
|
|
mod_basename, *mapi_version);
|
2016-01-06 04:39:09 +01:00
|
|
|
lt_dlclose(tmpptr);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(mod_basename);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(ver == NULL)
|
|
|
|
ver = unknown_ver;
|
|
|
|
|
2016-03-06 23:53:03 +01:00
|
|
|
if(description == NULL)
|
|
|
|
description = unknown_description;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
increase_modlist();
|
|
|
|
|
2008-04-02 01:07:29 +02:00
|
|
|
modlist[num_mods] = rb_malloc(sizeof(struct module));
|
2007-01-25 07:40:21 +01:00
|
|
|
modlist[num_mods]->address = tmpptr;
|
|
|
|
modlist[num_mods]->version = ver;
|
2016-03-07 00:14:31 +01:00
|
|
|
modlist[num_mods]->description = description;
|
2007-01-25 07:40:21 +01:00
|
|
|
modlist[num_mods]->core = core;
|
2008-04-02 01:26:34 +02:00
|
|
|
modlist[num_mods]->name = rb_strdup(mod_basename);
|
2007-01-25 07:40:21 +01:00
|
|
|
modlist[num_mods]->mapi_header = mapi_version;
|
|
|
|
modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version);
|
2016-03-07 00:52:49 +01:00
|
|
|
modlist[num_mods]->origin = origin;
|
2007-01-25 07:40:21 +01:00
|
|
|
num_mods++;
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-07 00:52:49 +01:00
|
|
|
const char *o;
|
|
|
|
|
2016-03-07 06:21:08 +01:00
|
|
|
switch (origin)
|
2016-03-07 00:52:49 +01:00
|
|
|
{
|
|
|
|
case MAPI_ORIGIN_EXTENSION:
|
|
|
|
o = "extension";
|
|
|
|
break;
|
|
|
|
case MAPI_ORIGIN_CORE:
|
|
|
|
o = "core";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
o = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
2016-03-20 08:42:42 +01:00
|
|
|
"Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
|
2016-03-07 00:52:49 +01:00
|
|
|
mod_basename, ver, MAPI_VERSION(*mapi_version), o, description,
|
2016-03-20 08:42:42 +01:00
|
|
|
(void *) tmpptr);
|
|
|
|
ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
|
|
|
|
mod_basename, ver, MAPI_VERSION(*mapi_version), o, description, (void *) tmpptr);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(mod_basename);
|
2016-04-03 08:51:26 +02:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* increase_modlist
|
|
|
|
*
|
|
|
|
* inputs - NONE
|
|
|
|
* output - NONE
|
|
|
|
* side effects - expand the size of modlist if necessary
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
increase_modlist(void)
|
|
|
|
{
|
|
|
|
struct module **new_modlist = NULL;
|
|
|
|
|
|
|
|
if((num_mods + 1) < max_mods)
|
|
|
|
return;
|
|
|
|
|
2014-02-23 22:39:42 +01:00
|
|
|
new_modlist = (struct module **) rb_malloc(sizeof(struct module *) *
|
2007-01-25 07:40:21 +01:00
|
|
|
(max_mods + MODS_INCREMENT));
|
2014-02-23 22:39:42 +01:00
|
|
|
memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module *) * num_mods);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(modlist);
|
2007-01-25 07:40:21 +01:00
|
|
|
modlist = new_modlist;
|
|
|
|
max_mods += MODS_INCREMENT;
|
|
|
|
}
|