| 1 |
|
/* |
| 2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
< |
* modules.c: A module loader. |
| 2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 4 |
> |
* Copyright (c) 2000-2014 ircd-hybrid development team |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
* it under the terms of the GNU General Public License as published by |
| 15 |
|
* |
| 16 |
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
|
* USA |
| 21 |
– |
* |
| 22 |
– |
* $Id$ |
| 20 |
|
*/ |
| 21 |
|
|
| 22 |
+ |
/*! \file modules.c |
| 23 |
+ |
* \brief A module loader. |
| 24 |
+ |
* \version $Id$ |
| 25 |
+ |
*/ |
| 26 |
+ |
|
| 27 |
+ |
#include "ltdl.h" |
| 28 |
+ |
|
| 29 |
|
#include "stdinc.h" |
| 30 |
< |
#include "tools.h" |
| 30 |
> |
#include "list.h" |
| 31 |
|
#include "modules.h" |
| 32 |
< |
#include "s_log.h" |
| 32 |
> |
#include "log.h" |
| 33 |
|
#include "ircd.h" |
| 34 |
|
#include "client.h" |
| 35 |
|
#include "send.h" |
| 36 |
< |
#include "s_conf.h" |
| 33 |
< |
#include "handlers.h" |
| 36 |
> |
#include "conf.h" |
| 37 |
|
#include "numeric.h" |
| 38 |
|
#include "parse.h" |
| 39 |
|
#include "ircd_defs.h" |
| 40 |
|
#include "irc_string.h" |
| 41 |
|
#include "memory.h" |
| 39 |
– |
#include "list.h" |
| 40 |
– |
|
| 41 |
– |
/* -TimeMr14C: |
| 42 |
– |
* I have moved the dl* function definitions and |
| 43 |
– |
* the two functions (load_a_module / unload_a_module) to the |
| 44 |
– |
* file dynlink.c |
| 45 |
– |
* And also made the necessary changes to those functions |
| 46 |
– |
* to comply with shl_load and friends. |
| 47 |
– |
* In this file, to keep consistency with the makefile, |
| 48 |
– |
* I added the ability to load *.sl files, too. |
| 49 |
– |
* 27/02/2002 |
| 50 |
– |
*/ |
| 42 |
|
|
| 52 |
– |
#ifndef STATIC_MODULES |
| 43 |
|
|
| 44 |
< |
dlink_list mod_list = { NULL, NULL, 0 }; |
| 44 |
> |
static dlink_list modules_list; |
| 45 |
> |
static dlink_list modules_path; |
| 46 |
> |
static dlink_list modules_conf; |
| 47 |
|
|
| 48 |
+ |
static const char *unknown_ver = "<unknown>"; |
| 49 |
|
static const char *core_module_table[] = |
| 50 |
|
{ |
| 51 |
< |
"m_die", |
| 52 |
< |
"m_join", |
| 53 |
< |
"m_kick", |
| 54 |
< |
"m_kill", |
| 55 |
< |
"m_message", |
| 56 |
< |
"m_mode", |
| 57 |
< |
"m_nick", |
| 58 |
< |
"m_part", |
| 59 |
< |
"m_quit", |
| 60 |
< |
"m_server", |
| 61 |
< |
"m_sjoin", |
| 62 |
< |
"m_squit", |
| 51 |
> |
"m_bmask.la", |
| 52 |
> |
"m_die.la", |
| 53 |
> |
"m_error.la", |
| 54 |
> |
"m_join.la", |
| 55 |
> |
"m_kick.la", |
| 56 |
> |
"m_kill.la", |
| 57 |
> |
"m_message.la", |
| 58 |
> |
"m_mode.la", |
| 59 |
> |
"m_nick.la", |
| 60 |
> |
"m_part.la", |
| 61 |
> |
"m_quit.la", |
| 62 |
> |
"m_server.la", |
| 63 |
> |
"m_sjoin.la", |
| 64 |
> |
"m_squit.la", |
| 65 |
> |
"m_tmode.la", |
| 66 |
|
NULL |
| 67 |
|
}; |
| 68 |
|
|
| 73 |
– |
static dlink_list mod_paths = { NULL, NULL, 0 }; |
| 74 |
– |
static dlink_list conf_modules = { NULL, NULL, 0 }; |
| 69 |
|
|
| 70 |
< |
static void mo_modload(struct Client *, struct Client *, int, char *[]); |
| 71 |
< |
static void mo_modlist(struct Client *, struct Client *, int, char *[]); |
| 72 |
< |
static void mo_modreload(struct Client *, struct Client *, int, char *[]); |
| 73 |
< |
static void mo_modunload(struct Client *, struct Client *, int, char *[]); |
| 74 |
< |
static void mo_modrestart(struct Client *, struct Client *, int, char *[]); |
| 81 |
< |
|
| 82 |
< |
struct Message modload_msgtab = { |
| 83 |
< |
"MODLOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 84 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modload, m_ignore} |
| 85 |
< |
}; |
| 70 |
> |
dlink_list * |
| 71 |
> |
modules_get_list(void) |
| 72 |
> |
{ |
| 73 |
> |
return &modules_list; |
| 74 |
> |
} |
| 75 |
|
|
| 76 |
< |
struct Message modunload_msgtab = { |
| 77 |
< |
"MODUNLOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 78 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modunload, m_ignore} |
| 79 |
< |
}; |
| 76 |
> |
int |
| 77 |
> |
modules_valid_suffix(const char *name) |
| 78 |
> |
{ |
| 79 |
> |
return ((name = strrchr(name, '.'))) && !strcmp(name, ".la"); |
| 80 |
> |
} |
| 81 |
|
|
| 82 |
< |
struct Message modreload_msgtab = { |
| 83 |
< |
"MODRELOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 84 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modreload, m_ignore} |
| 85 |
< |
}; |
| 82 |
> |
/* unload_one_module() |
| 83 |
> |
* |
| 84 |
> |
* inputs - name of module to unload |
| 85 |
> |
* - 1 to say modules unloaded, 0 to not |
| 86 |
> |
* output - 0 if successful, -1 if error |
| 87 |
> |
* side effects - module is unloaded |
| 88 |
> |
*/ |
| 89 |
> |
int |
| 90 |
> |
unload_one_module(const char *name, int warn) |
| 91 |
> |
{ |
| 92 |
> |
struct module *modp = NULL; |
| 93 |
|
|
| 94 |
< |
struct Message modlist_msgtab = { |
| 95 |
< |
"MODLIST", 0, 0, 0, 0, MFLG_SLOW, 0, |
| 99 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modlist, m_ignore} |
| 100 |
< |
}; |
| 94 |
> |
if ((modp = findmodule_byname(name)) == NULL) |
| 95 |
> |
return -1; |
| 96 |
|
|
| 97 |
< |
struct Message modrestart_msgtab = { |
| 98 |
< |
"MODRESTART", 0, 0, 0, 0, MFLG_SLOW, 0, |
| 99 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modrestart, m_ignore} |
| 100 |
< |
}; |
| 97 |
> |
if (modp->modexit) |
| 98 |
> |
modp->modexit(); |
| 99 |
> |
|
| 100 |
> |
assert(dlink_list_length(&modules_list) > 0); |
| 101 |
> |
dlinkDelete(&modp->node, &modules_list); |
| 102 |
> |
MyFree(modp->name); |
| 103 |
> |
|
| 104 |
> |
lt_dlclose(modp->handle); |
| 105 |
> |
|
| 106 |
> |
if (warn == 1) |
| 107 |
> |
{ |
| 108 |
> |
ilog(LOG_TYPE_IRCD, "Module %s unloaded", name); |
| 109 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 110 |
> |
"Module %s unloaded", name); |
| 111 |
> |
} |
| 112 |
|
|
| 113 |
+ |
return 0; |
| 114 |
+ |
} |
| 115 |
|
|
| 116 |
< |
extern struct Message error_msgtab; |
| 116 |
> |
/* load_a_module() |
| 117 |
> |
* |
| 118 |
> |
* inputs - path name of module, int to notice, int of core |
| 119 |
> |
* output - -1 if error 0 if success |
| 120 |
> |
* side effects - loads a module if successful |
| 121 |
> |
*/ |
| 122 |
> |
int |
| 123 |
> |
load_a_module(const char *path, int warn) |
| 124 |
> |
{ |
| 125 |
> |
lt_dlhandle tmpptr = NULL; |
| 126 |
> |
const char *mod_basename = NULL; |
| 127 |
> |
struct module *modp = NULL; |
| 128 |
> |
|
| 129 |
> |
if (findmodule_byname((mod_basename = libio_basename(path)))) |
| 130 |
> |
return 1; |
| 131 |
> |
|
| 132 |
> |
if (!(tmpptr = lt_dlopen(path))) |
| 133 |
> |
{ |
| 134 |
> |
const char *err = ((err = lt_dlerror())) ? err : "<unknown>"; |
| 135 |
> |
|
| 136 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 137 |
> |
"Error loading module %s: %s", |
| 138 |
> |
mod_basename, err); |
| 139 |
> |
ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err); |
| 140 |
> |
return -1; |
| 141 |
> |
} |
| 142 |
> |
|
| 143 |
> |
if ((modp = lt_dlsym(tmpptr, "module_entry")) == NULL) |
| 144 |
> |
{ |
| 145 |
> |
const char *err = ((err = lt_dlerror())) ? err : "<unknown>"; |
| 146 |
> |
|
| 147 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 148 |
> |
"Error loading module %s: %s", |
| 149 |
> |
mod_basename, err); |
| 150 |
> |
ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err); |
| 151 |
> |
lt_dlclose(tmpptr); |
| 152 |
> |
return -1; |
| 153 |
> |
} |
| 154 |
> |
|
| 155 |
> |
modp->handle = tmpptr; |
| 156 |
> |
|
| 157 |
> |
if (EmptyString(modp->version)) |
| 158 |
> |
modp->version = unknown_ver; |
| 159 |
> |
|
| 160 |
> |
modp->name = xstrdup(mod_basename); |
| 161 |
> |
dlinkAdd(modp, &modp->node, &modules_list); |
| 162 |
> |
|
| 163 |
> |
if (modp->modinit) |
| 164 |
> |
modp->modinit(); |
| 165 |
> |
|
| 166 |
> |
if (warn == 1) |
| 167 |
> |
{ |
| 168 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 169 |
> |
"Module %s [version: %s handle: %p] loaded.", |
| 170 |
> |
modp->name, modp->version, tmpptr); |
| 171 |
> |
ilog(LOG_TYPE_IRCD, "Module %s [version: %s handle: %p] loaded.", |
| 172 |
> |
modp->name, modp->version, tmpptr); |
| 173 |
> |
} |
| 174 |
> |
|
| 175 |
> |
return 0; |
| 176 |
> |
} |
| 177 |
|
|
| 178 |
|
/* |
| 179 |
|
* modules_init |
| 185 |
|
void |
| 186 |
|
modules_init(void) |
| 187 |
|
{ |
| 188 |
< |
mod_add_cmd(&modload_msgtab); |
| 189 |
< |
mod_add_cmd(&modunload_msgtab); |
| 190 |
< |
mod_add_cmd(&modreload_msgtab); |
| 191 |
< |
mod_add_cmd(&modlist_msgtab); |
| 192 |
< |
mod_add_cmd(&modrestart_msgtab); |
| 193 |
< |
mod_add_cmd(&error_msgtab); |
| 188 |
> |
if (lt_dlinit()) |
| 189 |
> |
{ |
| 190 |
> |
ilog(LOG_TYPE_IRCD, "Couldn't initialize the libltdl run time dynamic" |
| 191 |
> |
" link library. Exiting."); |
| 192 |
> |
exit(0); |
| 193 |
> |
} |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
/* mod_find_path() |
| 202 |
|
static struct module_path * |
| 203 |
|
mod_find_path(const char *path) |
| 204 |
|
{ |
| 205 |
< |
dlink_node *ptr; |
| 138 |
< |
struct module_path *mpath; |
| 205 |
> |
dlink_node *node = NULL; |
| 206 |
|
|
| 207 |
< |
DLINK_FOREACH(ptr, mod_paths.head) |
| 207 |
> |
DLINK_FOREACH(node, modules_path.head) |
| 208 |
|
{ |
| 209 |
< |
mpath = ptr->data; |
| 209 |
> |
struct module_path *mpath = node->data; |
| 210 |
|
|
| 211 |
|
if (!strcmp(path, mpath->path)) |
| 212 |
|
return mpath; |
| 229 |
|
if (mod_find_path(path)) |
| 230 |
|
return; |
| 231 |
|
|
| 232 |
< |
pathst = MyMalloc(sizeof(struct module_path)); |
| 232 |
> |
pathst = MyCalloc(sizeof(struct module_path)); |
| 233 |
|
|
| 234 |
|
strlcpy(pathst->path, path, sizeof(pathst->path)); |
| 235 |
< |
dlinkAdd(pathst, &pathst->node, &mod_paths); |
| 235 |
> |
dlinkAdd(pathst, &pathst->node, &modules_path); |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
/* add_conf_module |
| 246 |
|
{ |
| 247 |
|
struct module_path *pathst; |
| 248 |
|
|
| 249 |
< |
pathst = MyMalloc(sizeof(struct module_path)); |
| 249 |
> |
pathst = MyCalloc(sizeof(struct module_path)); |
| 250 |
|
|
| 251 |
|
strlcpy(pathst->path, name, sizeof(pathst->path)); |
| 252 |
< |
dlinkAdd(pathst, &pathst->node, &conf_modules); |
| 252 |
> |
dlinkAdd(pathst, &pathst->node, &modules_conf); |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
/* mod_clear_paths() |
| 261 |
|
void |
| 262 |
|
mod_clear_paths(void) |
| 263 |
|
{ |
| 264 |
< |
struct module_path *pathst; |
| 198 |
< |
dlink_node *ptr; |
| 199 |
< |
dlink_node *next_ptr; |
| 264 |
> |
dlink_node *node = NULL, *node_next = NULL; |
| 265 |
|
|
| 266 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) |
| 266 |
> |
DLINK_FOREACH_SAFE(node, node_next, modules_path.head) |
| 267 |
|
{ |
| 268 |
< |
pathst = ptr->data; |
| 269 |
< |
|
| 205 |
< |
dlinkDelete(&pathst->node, &mod_paths); |
| 206 |
< |
MyFree(pathst); |
| 268 |
> |
dlinkDelete(node, &modules_path); |
| 269 |
> |
MyFree(node->data); |
| 270 |
|
} |
| 271 |
|
|
| 272 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, conf_modules.head) |
| 272 |
> |
DLINK_FOREACH_SAFE(node, node_next, modules_conf.head) |
| 273 |
|
{ |
| 274 |
< |
pathst = ptr->data; |
| 275 |
< |
|
| 213 |
< |
dlinkDelete(&pathst->node, &conf_modules); |
| 214 |
< |
MyFree(pathst); |
| 274 |
> |
dlinkDelete(node, &modules_conf); |
| 275 |
> |
MyFree(node->data); |
| 276 |
|
} |
| 277 |
|
} |
| 278 |
|
|
| 282 |
|
* output - NULL if not found or pointer to module |
| 283 |
|
* side effects - NONE |
| 284 |
|
*/ |
| 285 |
< |
dlink_node * |
| 285 |
> |
struct module * |
| 286 |
|
findmodule_byname(const char *name) |
| 287 |
|
{ |
| 288 |
< |
dlink_node *ptr; |
| 228 |
< |
struct module *modp; |
| 288 |
> |
dlink_node *node = NULL; |
| 289 |
|
|
| 290 |
< |
DLINK_FOREACH(ptr, mod_list.head) |
| 290 |
> |
DLINK_FOREACH(node, modules_list.head) |
| 291 |
|
{ |
| 292 |
< |
modp = ptr->data; |
| 292 |
> |
struct module *modp = node->data; |
| 293 |
|
|
| 294 |
< |
if (strcmp(modp->name, name) == 0) |
| 295 |
< |
return ptr; |
| 294 |
> |
if (!strcmp(modp->name, name)) |
| 295 |
> |
return modp; |
| 296 |
|
} |
| 297 |
|
|
| 298 |
|
return NULL; |
| 309 |
|
{ |
| 310 |
|
DIR *system_module_dir = NULL; |
| 311 |
|
struct dirent *ldirent = NULL; |
| 312 |
< |
char module_fq_name[PATH_MAX + 1]; |
| 253 |
< |
|
| 254 |
< |
modules_init(); |
| 312 |
> |
char module_fq_name[HYB_PATH_MAX + 1]; |
| 313 |
|
|
| 314 |
|
if ((system_module_dir = opendir(AUTOMODPATH)) == NULL) |
| 315 |
|
{ |
| 316 |
< |
ilog(L_WARN, "Could not load modules from %s: %s", |
| 316 |
> |
ilog(LOG_TYPE_IRCD, "Could not load modules from %s: %s", |
| 317 |
|
AUTOMODPATH, strerror(errno)); |
| 318 |
|
return; |
| 319 |
|
} |
| 320 |
|
|
| 321 |
< |
while ((ldirent = readdir(system_module_dir)) != NULL) |
| 321 |
> |
while ((ldirent = readdir(system_module_dir))) |
| 322 |
|
{ |
| 323 |
< |
const char *offset = strrchr(ldirent->d_name, '.'); |
| 266 |
< |
|
| 267 |
< |
if (offset && !strcmp(offset, SHARED_SUFFIX)) |
| 323 |
> |
if (modules_valid_suffix(ldirent->d_name)) |
| 324 |
|
{ |
| 325 |
|
snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", |
| 326 |
|
AUTOMODPATH, ldirent->d_name); |
| 327 |
< |
load_a_module(module_fq_name, warn, 0); |
| 327 |
> |
load_a_module(module_fq_name, warn); |
| 328 |
|
} |
| 329 |
|
} |
| 330 |
|
|
| 340 |
|
void |
| 341 |
|
load_conf_modules(void) |
| 342 |
|
{ |
| 343 |
< |
dlink_node *ptr = NULL; |
| 288 |
< |
struct module_path *mpath = NULL; |
| 343 |
> |
dlink_node *node = NULL; |
| 344 |
|
|
| 345 |
< |
DLINK_FOREACH(ptr, conf_modules.head) |
| 345 |
> |
DLINK_FOREACH(node, modules_conf.head) |
| 346 |
|
{ |
| 347 |
< |
mpath = ptr->data; |
| 347 |
> |
struct module_path *mpath = node->data; |
| 348 |
|
|
| 349 |
|
if (findmodule_byname(mpath->path) == NULL) |
| 350 |
< |
load_one_module(mpath->path, 0); |
| 350 |
> |
load_one_module(mpath->path); |
| 351 |
|
} |
| 352 |
|
} |
| 353 |
|
|
| 360 |
|
void |
| 361 |
|
load_core_modules(int warn) |
| 362 |
|
{ |
| 363 |
< |
char module_name[PATH_MAX + 1]; |
| 309 |
< |
int i = 0; |
| 363 |
> |
char module_name[HYB_PATH_MAX + 1]; |
| 364 |
|
|
| 365 |
< |
for (; core_module_table[i]; ++i) |
| 365 |
> |
for (unsigned int i = 0; core_module_table[i]; ++i) |
| 366 |
|
{ |
| 367 |
< |
snprintf(module_name, sizeof(module_name), "%s%s%s", MODPATH, |
| 368 |
< |
core_module_table[i], SHARED_SUFFIX); |
| 367 |
> |
snprintf(module_name, sizeof(module_name), "%s%s", |
| 368 |
> |
MODPATH, core_module_table[i]); |
| 369 |
|
|
| 370 |
< |
if (load_a_module(module_name, warn, 1) == -1) |
| 370 |
> |
if (load_a_module(module_name, warn) == -1) |
| 371 |
|
{ |
| 372 |
< |
ilog(L_CRIT, "Error loading core module %s%s: terminating ircd", |
| 373 |
< |
core_module_table[i], SHARED_SUFFIX); |
| 372 |
> |
ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", |
| 373 |
> |
core_module_table[i]); |
| 374 |
|
exit(EXIT_FAILURE); |
| 375 |
|
} |
| 376 |
|
} |
| 380 |
|
* |
| 381 |
|
* input - pointer to path |
| 382 |
|
* - flagged as core module or not |
| 383 |
< |
* output - -1 if error |
| 383 |
> |
* output - -1 if error |
| 384 |
|
* side effects - module is loaded if found. |
| 385 |
|
*/ |
| 386 |
|
int |
| 387 |
< |
load_one_module(char *path, int coremodule) |
| 387 |
> |
load_one_module(const char *name) |
| 388 |
|
{ |
| 389 |
< |
dlink_node *ptr = NULL; |
| 390 |
< |
char modpath[PATH_MAX + 1]; |
| 389 |
> |
dlink_node *node = NULL; |
| 390 |
> |
char path[HYB_PATH_MAX + 1]; |
| 391 |
|
struct stat statbuf; |
| 392 |
|
|
| 393 |
< |
DLINK_FOREACH(ptr, mod_paths.head) |
| 340 |
< |
{ |
| 341 |
< |
const struct module_path *mpath = ptr->data; |
| 342 |
< |
|
| 343 |
< |
snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path); |
| 344 |
< |
|
| 345 |
< |
if (strstr(modpath, "../") == NULL && |
| 346 |
< |
strstr(modpath, "/..") == NULL) |
| 347 |
< |
{ |
| 348 |
< |
if (!stat(modpath, &statbuf)) |
| 349 |
< |
{ |
| 350 |
< |
if (S_ISREG(statbuf.st_mode)) |
| 351 |
< |
{ |
| 352 |
< |
/* Regular files only please */ |
| 353 |
< |
return load_a_module(modpath, 1, coremodule); |
| 354 |
< |
} |
| 355 |
< |
} |
| 356 |
< |
} |
| 357 |
< |
} |
| 358 |
< |
|
| 359 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 360 |
< |
"Cannot locate module %s", path); |
| 361 |
< |
ilog(L_WARN, "Cannot locate module %s", path); |
| 362 |
< |
return -1; |
| 363 |
< |
} |
| 364 |
< |
|
| 365 |
< |
/* load a module .. */ |
| 366 |
< |
static void |
| 367 |
< |
mo_modload(struct Client *client_p, struct Client *source_p, |
| 368 |
< |
int parc, char *parv[]) |
| 369 |
< |
{ |
| 370 |
< |
char *m_bn; |
| 371 |
< |
|
| 372 |
< |
if (!IsAdmin(source_p)) |
| 373 |
< |
{ |
| 374 |
< |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 375 |
< |
me.name, source_p->name); |
| 376 |
< |
return; |
| 377 |
< |
} |
| 378 |
< |
|
| 379 |
< |
m_bn = basename(parv[1]); |
| 380 |
< |
|
| 381 |
< |
if (findmodule_byname(m_bn) != NULL) |
| 382 |
< |
{ |
| 383 |
< |
sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded", |
| 384 |
< |
me.name, source_p->name, m_bn); |
| 385 |
< |
return; |
| 386 |
< |
} |
| 387 |
< |
|
| 388 |
< |
load_one_module(parv[1], 0); |
| 389 |
< |
} |
| 390 |
< |
|
| 391 |
< |
/* unload a module .. */ |
| 392 |
< |
static void |
| 393 |
< |
mo_modunload(struct Client *client_p, struct Client *source_p, |
| 394 |
< |
int parc, char *parv[]) |
| 395 |
< |
{ |
| 396 |
< |
char *m_bn; |
| 397 |
< |
dlink_node *ptr; |
| 398 |
< |
struct module *modp; |
| 399 |
< |
|
| 400 |
< |
if (!IsAdmin(source_p)) |
| 401 |
< |
{ |
| 402 |
< |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 403 |
< |
me.name, source_p->name); |
| 404 |
< |
return; |
| 405 |
< |
} |
| 406 |
< |
|
| 407 |
< |
m_bn = basename(parv[1]); |
| 408 |
< |
|
| 409 |
< |
if ((ptr = findmodule_byname(m_bn)) == NULL) |
| 393 |
> |
DLINK_FOREACH(node, modules_path.head) |
| 394 |
|
{ |
| 395 |
< |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
| 412 |
< |
me.name, source_p->name, m_bn); |
| 413 |
< |
return; |
| 414 |
< |
} |
| 395 |
> |
const struct module_path *mpath = node->data; |
| 396 |
|
|
| 397 |
< |
modp = ptr->data; |
| 417 |
< |
|
| 418 |
< |
if (modp->core == 1) |
| 419 |
< |
{ |
| 420 |
< |
sendto_one(source_p, |
| 421 |
< |
":%s NOTICE %s :Module %s is a core module and may not be unloaded", |
| 422 |
< |
me.name, source_p->name, m_bn); |
| 423 |
< |
return; |
| 424 |
< |
} |
| 397 |
> |
snprintf(path, sizeof(path), "%s/%s", mpath->path, name); |
| 398 |
|
|
| 399 |
< |
/* XXX might want to simply un dlink it here */ |
| 399 |
> |
if (!modules_valid_suffix(name)) |
| 400 |
> |
continue; |
| 401 |
|
|
| 402 |
< |
if (unload_one_module(m_bn, 1) == -1) |
| 403 |
< |
{ |
| 404 |
< |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
| 405 |
< |
me.name, source_p->name, m_bn); |
| 402 |
> |
if (strstr(path, "../") == NULL && |
| 403 |
> |
strstr(path, "/..") == NULL) |
| 404 |
> |
if (!stat(path, &statbuf)) |
| 405 |
> |
if (S_ISREG(statbuf.st_mode)) /* Regular files only please */ |
| 406 |
> |
return load_a_module(path, 1); |
| 407 |
|
} |
| 433 |
– |
} |
| 408 |
|
|
| 409 |
< |
/* unload and load in one! */ |
| 410 |
< |
static void |
| 411 |
< |
mo_modreload(struct Client *client_p, struct Client *source_p, |
| 412 |
< |
int parc, char *parv[]) |
| 439 |
< |
{ |
| 440 |
< |
char *m_bn; |
| 441 |
< |
dlink_node *ptr; |
| 442 |
< |
struct module *modp; |
| 443 |
< |
int check_core; |
| 444 |
< |
|
| 445 |
< |
if (!IsAdmin(source_p)) |
| 446 |
< |
{ |
| 447 |
< |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 448 |
< |
me.name, source_p->name); |
| 449 |
< |
return; |
| 450 |
< |
} |
| 451 |
< |
|
| 452 |
< |
m_bn = basename(parv[1]); |
| 453 |
< |
|
| 454 |
< |
if ((ptr = findmodule_byname(m_bn)) == NULL) |
| 455 |
< |
{ |
| 456 |
< |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
| 457 |
< |
me.name, source_p->name, m_bn); |
| 458 |
< |
return; |
| 459 |
< |
} |
| 460 |
< |
|
| 461 |
< |
modp = ptr->data; |
| 462 |
< |
check_core = modp->core; |
| 463 |
< |
|
| 464 |
< |
if (unload_one_module(m_bn, 1) == -1) |
| 465 |
< |
{ |
| 466 |
< |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
| 467 |
< |
me.name, source_p->name, m_bn); |
| 468 |
< |
return; |
| 469 |
< |
} |
| 470 |
< |
|
| 471 |
< |
if ((load_one_module(parv[1], check_core) == -1) && check_core) |
| 472 |
< |
{ |
| 473 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core " |
| 474 |
< |
"module: %s: terminating ircd", parv[1]); |
| 475 |
< |
ilog(L_CRIT, "Error loading core module %s: terminating ircd", parv[1]); |
| 476 |
< |
exit(0); |
| 477 |
< |
} |
| 478 |
< |
} |
| 479 |
< |
|
| 480 |
< |
/* list modules .. */ |
| 481 |
< |
static void |
| 482 |
< |
mo_modlist(struct Client *client_p, struct Client *source_p, |
| 483 |
< |
int parc, char *parv[]) |
| 484 |
< |
{ |
| 485 |
< |
dlink_node *ptr; |
| 486 |
< |
struct module *modp; |
| 487 |
< |
|
| 488 |
< |
if (!IsAdmin(source_p)) |
| 489 |
< |
{ |
| 490 |
< |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 491 |
< |
me.name, source_p->name); |
| 492 |
< |
return; |
| 493 |
< |
} |
| 494 |
< |
|
| 495 |
< |
DLINK_FOREACH(ptr, mod_list.head) |
| 496 |
< |
{ |
| 497 |
< |
modp = ptr->data; |
| 498 |
< |
|
| 499 |
< |
if (parc > 1) |
| 500 |
< |
{ |
| 501 |
< |
if (match(parv[1], modp->name)) |
| 502 |
< |
{ |
| 503 |
< |
sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0], |
| 504 |
< |
modp->name, modp->address, |
| 505 |
< |
modp->version, modp->core?"(core)":""); |
| 506 |
< |
} |
| 507 |
< |
} |
| 508 |
< |
else |
| 509 |
< |
{ |
| 510 |
< |
sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0], |
| 511 |
< |
modp->name, modp->address, |
| 512 |
< |
modp->version, modp->core?"(core)":""); |
| 513 |
< |
} |
| 514 |
< |
} |
| 515 |
< |
|
| 516 |
< |
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), |
| 517 |
< |
me.name, source_p->name); |
| 518 |
< |
} |
| 519 |
< |
|
| 520 |
< |
/* unload and reload all modules */ |
| 521 |
< |
static void |
| 522 |
< |
mo_modrestart(struct Client *client_p, struct Client *source_p, |
| 523 |
< |
int parc, char *parv[]) |
| 524 |
< |
{ |
| 525 |
< |
unsigned int modnum = 0; |
| 526 |
< |
dlink_node *ptr; |
| 527 |
< |
dlink_node *tptr; |
| 528 |
< |
struct module *modp; |
| 529 |
< |
|
| 530 |
< |
if (!IsAdmin(source_p)) |
| 531 |
< |
{ |
| 532 |
< |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 533 |
< |
me.name, source_p->name); |
| 534 |
< |
return; |
| 535 |
< |
} |
| 536 |
< |
|
| 537 |
< |
sendto_one(source_p, ":%s NOTICE %s :Reloading all modules", |
| 538 |
< |
me.name, source_p->name); |
| 539 |
< |
|
| 540 |
< |
modnum = dlink_list_length(&mod_list); |
| 541 |
< |
|
| 542 |
< |
DLINK_FOREACH_SAFE(ptr, tptr, mod_list.head) |
| 543 |
< |
{ |
| 544 |
< |
modp = ptr->data; |
| 545 |
< |
unload_one_module(modp->name, 0); |
| 546 |
< |
} |
| 547 |
< |
|
| 548 |
< |
load_all_modules(0); |
| 549 |
< |
load_conf_modules(); |
| 550 |
< |
load_core_modules(0); |
| 551 |
< |
|
| 552 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 553 |
< |
"Module Restart: %u modules unloaded, %lu modules loaded", |
| 554 |
< |
modnum, dlink_list_length(&mod_list)); |
| 555 |
< |
ilog(L_WARN, "Module Restart: %u modules unloaded, %lu modules loaded", |
| 556 |
< |
modnum, dlink_list_length(&mod_list)); |
| 557 |
< |
} |
| 558 |
< |
|
| 559 |
< |
#else /* STATIC_MODULES */ |
| 560 |
< |
#include "s_serv.h" |
| 561 |
< |
|
| 562 |
< |
/* load_all_modules() |
| 563 |
< |
* |
| 564 |
< |
* input - warn flag |
| 565 |
< |
* output - NONE |
| 566 |
< |
* side effects - all the msgtabs are added for static modules |
| 567 |
< |
*/ |
| 568 |
< |
void |
| 569 |
< |
load_all_modules(int warn) |
| 570 |
< |
{ |
| 571 |
< |
mod_add_cmd(&error_msgtab); |
| 572 |
< |
mod_add_cmd(&accept_msgtab); |
| 573 |
< |
mod_add_cmd(&admin_msgtab); |
| 574 |
< |
mod_add_cmd(&away_msgtab); |
| 575 |
< |
mod_add_cmd(&capab_msgtab); |
| 576 |
< |
mod_add_cmd(&cburst_msgtab); |
| 577 |
< |
mod_add_cmd(&close_msgtab); |
| 578 |
< |
mod_add_cmd(&connect_msgtab); |
| 579 |
< |
#ifdef HAVE_LIBCRYPTO |
| 580 |
< |
mod_add_cmd(&challenge_msgtab); |
| 581 |
< |
mod_add_cmd(&cryptlink_msgtab); |
| 582 |
< |
#endif |
| 583 |
< |
mod_add_cmd(&die_msgtab); |
| 584 |
< |
mod_add_cmd(&drop_msgtab); |
| 585 |
< |
mod_add_cmd(&eob_msgtab); |
| 586 |
< |
mod_add_cmd(&etrace_msgtab); |
| 587 |
< |
mod_add_cmd(&gline_msgtab); |
| 588 |
< |
add_capability("GLN", CAP_GLN, 1); |
| 589 |
< |
mod_add_cmd(&hash_msgtab); |
| 590 |
< |
mod_add_cmd(&ungline_msgtab); |
| 591 |
< |
mod_add_cmd(&info_msgtab); |
| 592 |
< |
mod_add_cmd(&invite_msgtab); |
| 593 |
< |
mod_add_cmd(&ison_msgtab); |
| 594 |
< |
mod_add_cmd(&join_msgtab); |
| 595 |
< |
mod_add_cmd(&kick_msgtab); |
| 596 |
< |
mod_add_cmd(&kill_msgtab); |
| 597 |
< |
mod_add_cmd(&kline_msgtab); |
| 598 |
< |
add_capability("KLN", CAP_KLN, 1); |
| 599 |
< |
mod_add_cmd(&dline_msgtab); |
| 600 |
< |
mod_add_cmd(&unkline_msgtab); |
| 601 |
< |
mod_add_cmd(&undline_msgtab); |
| 602 |
< |
mod_add_cmd(&knock_msgtab); |
| 603 |
< |
add_capability("KNOCK", CAP_KNOCK, 1); |
| 604 |
< |
mod_add_cmd(&knockll_msgtab); |
| 605 |
< |
mod_add_cmd(&links_msgtab); |
| 606 |
< |
mod_add_cmd(&list_msgtab); |
| 607 |
< |
mod_add_cmd(&lljoin_msgtab); |
| 608 |
< |
mod_add_cmd(&llnick_msgtab); |
| 609 |
< |
mod_add_cmd(&locops_msgtab); |
| 610 |
< |
mod_add_cmd(&lusers_msgtab); |
| 611 |
< |
mod_add_cmd(&privmsg_msgtab); |
| 612 |
< |
mod_add_cmd(¬ice_msgtab); |
| 613 |
< |
mod_add_cmd(&map_msgtab); |
| 614 |
< |
mod_add_cmd(&mode_msgtab); |
| 615 |
< |
mod_add_cmd(&motd_msgtab); |
| 616 |
< |
mod_add_cmd(&names_msgtab); |
| 617 |
< |
mod_add_cmd(&nburst_msgtab); |
| 618 |
< |
mod_add_cmd(&nick_msgtab); |
| 619 |
< |
mod_add_cmd(&omotd_msgtab); |
| 620 |
< |
mod_add_cmd(&oper_msgtab); |
| 621 |
< |
mod_add_cmd(&operwall_msgtab); |
| 622 |
< |
mod_add_cmd(&part_msgtab); |
| 623 |
< |
mod_add_cmd(&pass_msgtab); |
| 624 |
< |
mod_add_cmd(&ping_msgtab); |
| 625 |
< |
mod_add_cmd(&pong_msgtab); |
| 626 |
< |
mod_add_cmd(&post_msgtab); |
| 627 |
< |
mod_add_cmd(&get_msgtab); |
| 628 |
< |
mod_add_cmd(&put_msgtab); |
| 629 |
< |
mod_add_cmd(&quit_msgtab); |
| 630 |
< |
mod_add_cmd(&rehash_msgtab); |
| 631 |
< |
mod_add_cmd(&restart_msgtab); |
| 632 |
< |
mod_add_cmd(&resv_msgtab); |
| 633 |
< |
mod_add_cmd(&rkline_msgtab); |
| 634 |
< |
mod_add_cmd(&rxline_msgtab); |
| 635 |
< |
mod_add_cmd(&server_msgtab); |
| 636 |
< |
mod_add_cmd(&set_msgtab); |
| 637 |
< |
mod_add_cmd(&sid_msgtab); |
| 638 |
< |
mod_add_cmd(&sjoin_msgtab); |
| 639 |
< |
mod_add_cmd(&squit_msgtab); |
| 640 |
< |
mod_add_cmd(&stats_msgtab); |
| 641 |
< |
mod_add_cmd(&svinfo_msgtab); |
| 642 |
< |
mod_add_cmd(&tb_msgtab); |
| 643 |
< |
add_capability("TB", CAP_TB, 1); |
| 644 |
< |
mod_add_cmd(&tburst_msgtab); |
| 645 |
< |
add_capability("TBURST", CAP_TBURST, 1); |
| 646 |
< |
mod_add_cmd(&testline_msgtab); |
| 647 |
< |
mod_add_cmd(&testgecos_msgtab); |
| 648 |
< |
mod_add_cmd(&testmask_msgtab); |
| 649 |
< |
mod_add_cmd(&time_msgtab); |
| 650 |
< |
mod_add_cmd(&topic_msgtab); |
| 651 |
< |
mod_add_cmd(&trace_msgtab); |
| 652 |
< |
add_capability("UNKLN", CAP_UNKLN, 1); |
| 653 |
< |
mod_add_cmd(&uid_msgtab); |
| 654 |
< |
mod_add_cmd(&unresv_msgtab); |
| 655 |
< |
mod_add_cmd(&unxline_msgtab); |
| 656 |
< |
mod_add_cmd(&user_msgtab); |
| 657 |
< |
mod_add_cmd(&userhost_msgtab); |
| 658 |
< |
mod_add_cmd(&users_msgtab); |
| 659 |
< |
mod_add_cmd(&version_msgtab); |
| 660 |
< |
mod_add_cmd(&wallops_msgtab); |
| 661 |
< |
mod_add_cmd(&who_msgtab); |
| 662 |
< |
mod_add_cmd(&whois_msgtab); |
| 663 |
< |
mod_add_cmd(&whowas_msgtab); |
| 664 |
< |
mod_add_cmd(&xline_msgtab); |
| 665 |
< |
mod_add_cmd(&help_msgtab); |
| 666 |
< |
mod_add_cmd(&uhelp_msgtab); |
| 667 |
< |
#ifdef BUILD_CONTRIB |
| 668 |
< |
mod_add_cmd(&botserv_msgtab); |
| 669 |
< |
mod_add_cmd(&capture_msgtab); |
| 670 |
< |
mod_add_cmd(&chanserv_msgtab); |
| 671 |
< |
mod_add_cmd(&chghost_msgtab); |
| 672 |
< |
mod_add_cmd(&chgident_msgtab); |
| 673 |
< |
mod_add_cmd(&chgname_msgtab); |
| 674 |
< |
mod_add_cmd(&classlist_msgtab); |
| 675 |
< |
mod_add_cmd(&clearchan_msgtab); |
| 676 |
< |
mod_add_cmd(&cs_msgtab); |
| 677 |
< |
mod_add_cmd(&ctrace_msgtab); |
| 678 |
< |
mod_add_cmd(&delspoof_msgtab); |
| 679 |
< |
mod_add_cmd(&flags_msgtab); |
| 680 |
< |
mod_add_cmd(&forcejoin_msgtab); |
| 681 |
< |
mod_add_cmd(&forcepart_msgtab); |
| 682 |
< |
mod_add_cmd(&global_msgtab); |
| 683 |
< |
mod_add_cmd(&help_msgtab); |
| 684 |
< |
mod_add_cmd(&uhelp_msgtab); |
| 685 |
< |
mod_add_cmd(&helpserv_msgtab); |
| 686 |
< |
mod_add_cmd(&hostserv_msgtab); |
| 687 |
< |
mod_add_cmd(&identify_msgtab); |
| 688 |
< |
mod_add_cmd(&jupe_msgtab); |
| 689 |
< |
mod_add_cmd(&killhost_msgtab); |
| 690 |
< |
mod_add_cmd(<race_msgtab); |
| 691 |
< |
mod_add_cmd(&memoserv_msgtab); |
| 692 |
< |
mod_add_cmd(&mkpasswd_msgtab); |
| 693 |
< |
mod_add_cmd(&ms_msgtab); |
| 694 |
< |
mod_add_cmd(&nickserv_msgtab); |
| 695 |
< |
mod_add_cmd(&ns_msgtab); |
| 696 |
< |
mod_add_cmd(&ojoin_msgtab); |
| 697 |
< |
mod_add_cmd(&operserv_msgtab); |
| 698 |
< |
mod_add_cmd(&operspy_msgtab); |
| 699 |
< |
mod_add_cmd(&opme_msgtab); |
| 700 |
< |
mod_add_cmd(&os_msgtab); |
| 701 |
< |
mod_add_cmd(&seenserv_msgtab); |
| 702 |
< |
mod_add_cmd(&spoof_msgtab); |
| 703 |
< |
mod_add_cmd(&statserv_msgtab); |
| 704 |
< |
mod_add_cmd(&svsnick_msgtab); |
| 705 |
< |
mod_add_cmd(&uncapture_msgtab); |
| 706 |
< |
/* FIXME: what about spy*? */ |
| 707 |
< |
#endif |
| 409 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 410 |
> |
"Cannot locate module %s", name); |
| 411 |
> |
ilog(LOG_TYPE_IRCD, "Cannot locate module %s", name); |
| 412 |
> |
return -1; |
| 413 |
|
} |
| 709 |
– |
#endif /* STATIC_MODULES */ |