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 |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
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 "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" |
41 |
|
#include "memory.h" |
42 |
|
|
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.la", |
64 |
|
NULL |
65 |
|
}; |
66 |
|
|
61 |
– |
static dlink_list mod_paths = { NULL, NULL, 0 }; |
62 |
– |
static dlink_list conf_modules = { NULL, NULL, 0 }; |
67 |
|
|
68 |
< |
static void mo_modload(struct Client *, struct Client *, int, char *[]); |
69 |
< |
static void mo_modlist(struct Client *, struct Client *, int, char *[]); |
70 |
< |
static void mo_modreload(struct Client *, struct Client *, int, char *[]); |
71 |
< |
static void mo_modunload(struct Client *, struct Client *, int, char *[]); |
72 |
< |
static void mo_modrestart(struct Client *, struct Client *, int, char *[]); |
69 |
< |
|
70 |
< |
struct Message modload_msgtab = { |
71 |
< |
"MODLOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
72 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modload, m_ignore} |
73 |
< |
}; |
68 |
> |
dlink_list * |
69 |
> |
modules_get_list(void) |
70 |
> |
{ |
71 |
> |
return &modules_list; |
72 |
> |
} |
73 |
|
|
74 |
< |
struct Message modunload_msgtab = { |
75 |
< |
"MODUNLOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
76 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modunload, m_ignore} |
77 |
< |
}; |
74 |
> |
int |
75 |
> |
modules_valid_suffix(const char *name) |
76 |
> |
{ |
77 |
> |
return ((name = strrchr(name, '.'))) && !strcmp(name, ".la"); |
78 |
> |
} |
79 |
|
|
80 |
< |
struct Message modreload_msgtab = { |
81 |
< |
"MODRELOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
82 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modreload, m_ignore} |
83 |
< |
}; |
80 |
> |
/* unload_one_module() |
81 |
> |
* |
82 |
> |
* inputs - name of module to unload |
83 |
> |
* - 1 to say modules unloaded, 0 to not |
84 |
> |
* output - 0 if successful, -1 if error |
85 |
> |
* side effects - module is unloaded |
86 |
> |
*/ |
87 |
> |
int |
88 |
> |
unload_one_module(const char *name, int warn) |
89 |
> |
{ |
90 |
> |
struct module *modp = NULL; |
91 |
|
|
92 |
< |
struct Message modlist_msgtab = { |
93 |
< |
"MODLIST", 0, 0, 0, 0, MFLG_SLOW, 0, |
87 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modlist, m_ignore} |
88 |
< |
}; |
92 |
> |
if ((modp = findmodule_byname(name)) == NULL) |
93 |
> |
return -1; |
94 |
|
|
95 |
< |
struct Message modrestart_msgtab = { |
96 |
< |
"MODRESTART", 0, 0, 0, 0, MFLG_SLOW, 0, |
97 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modrestart, m_ignore} |
98 |
< |
}; |
95 |
> |
if (modp->modexit) |
96 |
> |
modp->modexit(); |
97 |
> |
|
98 |
> |
assert(dlink_list_length(&modules_list) > 0); |
99 |
> |
dlinkDelete(&modp->node, &modules_list); |
100 |
> |
MyFree(modp->name); |
101 |
> |
|
102 |
> |
lt_dlclose(modp->handle); |
103 |
> |
|
104 |
> |
if (warn == 1) |
105 |
> |
{ |
106 |
> |
ilog(LOG_TYPE_IRCD, "Module %s unloaded", name); |
107 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
108 |
> |
"Module %s unloaded", name); |
109 |
> |
} |
110 |
> |
|
111 |
> |
return 0; |
112 |
> |
} |
113 |
> |
|
114 |
> |
/* load_a_module() |
115 |
> |
* |
116 |
> |
* inputs - path name of module, int to notice, int of core |
117 |
> |
* output - -1 if error 0 if success |
118 |
> |
* side effects - loads a module if successful |
119 |
> |
*/ |
120 |
> |
int |
121 |
> |
load_a_module(const char *path, int warn) |
122 |
> |
{ |
123 |
> |
lt_dlhandle tmpptr = NULL; |
124 |
> |
const char *mod_basename = NULL; |
125 |
> |
struct module *modp = NULL; |
126 |
> |
|
127 |
> |
if (findmodule_byname((mod_basename = libio_basename(path)))) |
128 |
> |
return 1; |
129 |
> |
|
130 |
> |
if (!(tmpptr = lt_dlopen(path))) |
131 |
> |
{ |
132 |
> |
const char *err = ((err = lt_dlerror())) ? err : "<unknown>"; |
133 |
> |
|
134 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
135 |
> |
"Error loading module %s: %s", |
136 |
> |
mod_basename, err); |
137 |
> |
ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err); |
138 |
> |
return -1; |
139 |
> |
} |
140 |
> |
|
141 |
> |
if ((modp = lt_dlsym(tmpptr, "module_entry")) == NULL) |
142 |
> |
{ |
143 |
> |
const char *err = ((err = lt_dlerror())) ? err : "<unknown>"; |
144 |
> |
|
145 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
146 |
> |
"Error loading module %s: %s", |
147 |
> |
mod_basename, err); |
148 |
> |
ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err); |
149 |
> |
lt_dlclose(tmpptr); |
150 |
> |
return -1; |
151 |
> |
} |
152 |
> |
|
153 |
> |
modp->handle = tmpptr; |
154 |
> |
|
155 |
> |
if (EmptyString(modp->version)) |
156 |
> |
modp->version = unknown_ver; |
157 |
> |
|
158 |
> |
modp->name = xstrdup(mod_basename); |
159 |
> |
dlinkAdd(modp, &modp->node, &modules_list); |
160 |
> |
|
161 |
> |
if (modp->modinit) |
162 |
> |
modp->modinit(); |
163 |
> |
|
164 |
> |
if (warn == 1) |
165 |
> |
{ |
166 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
167 |
> |
"Module %s [version: %s handle: %p] loaded.", |
168 |
> |
modp->name, modp->version, tmpptr); |
169 |
> |
ilog(LOG_TYPE_IRCD, "Module %s [version: %s handle: %p] loaded.", |
170 |
> |
modp->name, modp->version, tmpptr); |
171 |
> |
} |
172 |
|
|
173 |
+ |
return 0; |
174 |
+ |
} |
175 |
|
|
176 |
|
/* |
177 |
|
* modules_init |
183 |
|
void |
184 |
|
modules_init(void) |
185 |
|
{ |
186 |
< |
dynlink_init(); |
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); |
112 |
< |
mod_add_cmd(&modrestart_msgtab); |
186 |
> |
if (lt_dlinit()) |
187 |
> |
{ |
188 |
> |
ilog(LOG_TYPE_IRCD, "Couldn't initialize the libltdl run time dynamic" |
189 |
> |
" link library. Exiting."); |
190 |
> |
exit(0); |
191 |
> |
} |
192 |
|
} |
193 |
|
|
194 |
|
/* mod_find_path() |
200 |
|
static struct module_path * |
201 |
|
mod_find_path(const char *path) |
202 |
|
{ |
203 |
< |
dlink_node *ptr; |
125 |
< |
struct module_path *mpath; |
203 |
> |
dlink_node *ptr = NULL; |
204 |
|
|
205 |
< |
DLINK_FOREACH(ptr, mod_paths.head) |
205 |
> |
DLINK_FOREACH(ptr, modules_path.head) |
206 |
|
{ |
207 |
< |
mpath = ptr->data; |
207 |
> |
struct module_path *mpath = ptr->data; |
208 |
|
|
209 |
|
if (!strcmp(path, mpath->path)) |
210 |
|
return mpath; |
230 |
|
pathst = MyMalloc(sizeof(struct module_path)); |
231 |
|
|
232 |
|
strlcpy(pathst->path, path, sizeof(pathst->path)); |
233 |
< |
dlinkAdd(pathst, &pathst->node, &mod_paths); |
233 |
> |
dlinkAdd(pathst, &pathst->node, &modules_path); |
234 |
|
} |
235 |
|
|
236 |
|
/* add_conf_module |
247 |
|
pathst = MyMalloc(sizeof(struct module_path)); |
248 |
|
|
249 |
|
strlcpy(pathst->path, name, sizeof(pathst->path)); |
250 |
< |
dlinkAdd(pathst, &pathst->node, &conf_modules); |
250 |
> |
dlinkAdd(pathst, &pathst->node, &modules_conf); |
251 |
|
} |
252 |
|
|
253 |
|
/* mod_clear_paths() |
259 |
|
void |
260 |
|
mod_clear_paths(void) |
261 |
|
{ |
262 |
< |
struct module_path *pathst; |
185 |
< |
dlink_node *ptr; |
186 |
< |
dlink_node *next_ptr; |
262 |
> |
dlink_node *ptr = NULL, *next_ptr = NULL; |
263 |
|
|
264 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) |
264 |
> |
DLINK_FOREACH_SAFE(ptr, next_ptr, modules_path.head) |
265 |
|
{ |
266 |
< |
pathst = ptr->data; |
267 |
< |
|
192 |
< |
dlinkDelete(&pathst->node, &mod_paths); |
193 |
< |
MyFree(pathst); |
266 |
> |
dlinkDelete(ptr, &modules_path); |
267 |
> |
MyFree(ptr->data); |
268 |
|
} |
269 |
|
|
270 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, conf_modules.head) |
270 |
> |
DLINK_FOREACH_SAFE(ptr, next_ptr, modules_conf.head) |
271 |
|
{ |
272 |
< |
pathst = ptr->data; |
273 |
< |
|
200 |
< |
dlinkDelete(&pathst->node, &conf_modules); |
201 |
< |
MyFree(pathst); |
272 |
> |
dlinkDelete(ptr, &modules_conf); |
273 |
> |
MyFree(ptr->data); |
274 |
|
} |
275 |
|
} |
276 |
|
|
280 |
|
* output - NULL if not found or pointer to module |
281 |
|
* side effects - NONE |
282 |
|
*/ |
283 |
< |
dlink_node * |
283 |
> |
struct module * |
284 |
|
findmodule_byname(const char *name) |
285 |
|
{ |
286 |
< |
dlink_node *ptr; |
215 |
< |
struct module *modp; |
286 |
> |
dlink_node *ptr = NULL; |
287 |
|
|
288 |
< |
DLINK_FOREACH(ptr, mod_list.head) |
288 |
> |
DLINK_FOREACH(ptr, modules_list.head) |
289 |
|
{ |
290 |
< |
modp = ptr->data; |
290 |
> |
struct module *modp = ptr->data; |
291 |
|
|
292 |
|
if (strcmp(modp->name, name) == 0) |
293 |
< |
return ptr; |
293 |
> |
return modp; |
294 |
|
} |
295 |
|
|
296 |
|
return NULL; |
307 |
|
{ |
308 |
|
DIR *system_module_dir = NULL; |
309 |
|
struct dirent *ldirent = NULL; |
310 |
< |
char module_fq_name[PATH_MAX + 1]; |
240 |
< |
|
241 |
< |
modules_init(); |
310 |
> |
char module_fq_name[HYB_PATH_MAX + 1]; |
311 |
|
|
312 |
|
if ((system_module_dir = opendir(AUTOMODPATH)) == NULL) |
313 |
|
{ |
314 |
< |
ilog(L_WARN, "Could not load modules from %s: %s", |
314 |
> |
ilog(LOG_TYPE_IRCD, "Could not load modules from %s: %s", |
315 |
|
AUTOMODPATH, strerror(errno)); |
316 |
|
return; |
317 |
|
} |
322 |
|
{ |
323 |
|
snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", |
324 |
|
AUTOMODPATH, ldirent->d_name); |
325 |
< |
load_a_module(module_fq_name, warn, 0); |
325 |
> |
load_a_module(module_fq_name, warn); |
326 |
|
} |
327 |
|
} |
328 |
|
|
339 |
|
load_conf_modules(void) |
340 |
|
{ |
341 |
|
dlink_node *ptr = NULL; |
273 |
– |
struct module_path *mpath = NULL; |
342 |
|
|
343 |
< |
DLINK_FOREACH(ptr, conf_modules.head) |
343 |
> |
DLINK_FOREACH(ptr, modules_conf.head) |
344 |
|
{ |
345 |
< |
mpath = ptr->data; |
345 |
> |
struct module_path *mpath = ptr->data; |
346 |
|
|
347 |
|
if (findmodule_byname(mpath->path) == NULL) |
348 |
< |
load_one_module(mpath->path, 0); |
348 |
> |
load_one_module(mpath->path); |
349 |
|
} |
350 |
|
} |
351 |
|
|
358 |
|
void |
359 |
|
load_core_modules(int warn) |
360 |
|
{ |
361 |
< |
char module_name[PATH_MAX + 1]; |
361 |
> |
char module_name[HYB_PATH_MAX + 1]; |
362 |
|
int i = 0; |
363 |
|
|
364 |
|
for (; core_module_table[i]; ++i) |
366 |
|
snprintf(module_name, sizeof(module_name), "%s%s", |
367 |
|
MODPATH, core_module_table[i]); |
368 |
|
|
369 |
< |
if (load_a_module(module_name, warn, 1) == -1) |
369 |
> |
if (load_a_module(module_name, warn) == -1) |
370 |
|
{ |
371 |
< |
ilog(L_CRIT, "Error loading core module %s: terminating ircd", |
371 |
> |
ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", |
372 |
|
core_module_table[i]); |
373 |
|
exit(EXIT_FAILURE); |
374 |
|
} |
379 |
|
* |
380 |
|
* input - pointer to path |
381 |
|
* - flagged as core module or not |
382 |
< |
* output - -1 if error |
382 |
> |
* output - -1 if error |
383 |
|
* side effects - module is loaded if found. |
384 |
|
*/ |
385 |
|
int |
386 |
< |
load_one_module(const char *path, int coremodule) |
386 |
> |
load_one_module(const char *name) |
387 |
|
{ |
388 |
|
dlink_node *ptr = NULL; |
389 |
< |
char modpath[PATH_MAX + 1]; |
389 |
> |
char path[HYB_PATH_MAX + 1]; |
390 |
|
struct stat statbuf; |
391 |
|
|
392 |
< |
DLINK_FOREACH(ptr, mod_paths.head) |
392 |
> |
DLINK_FOREACH(ptr, modules_path.head) |
393 |
|
{ |
394 |
|
const struct module_path *mpath = ptr->data; |
395 |
|
|
396 |
< |
snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path); |
396 |
> |
snprintf(path, sizeof(path), "%s/%s", mpath->path, name); |
397 |
|
|
398 |
< |
if (!modules_valid_suffix(path)) |
398 |
> |
if (!modules_valid_suffix(name)) |
399 |
|
continue; |
400 |
|
|
401 |
< |
if (strstr(modpath, "../") == NULL && |
402 |
< |
strstr(modpath, "/..") == NULL) |
403 |
< |
{ |
404 |
< |
if (!stat(modpath, &statbuf)) |
405 |
< |
{ |
338 |
< |
if (S_ISREG(statbuf.st_mode)) |
339 |
< |
{ |
340 |
< |
/* Regular files only please */ |
341 |
< |
return load_a_module(modpath, 1, coremodule); |
342 |
< |
} |
343 |
< |
} |
344 |
< |
} |
401 |
> |
if (strstr(path, "../") == NULL && |
402 |
> |
strstr(path, "/..") == NULL) |
403 |
> |
if (!stat(path, &statbuf)) |
404 |
> |
if (S_ISREG(statbuf.st_mode)) /* Regular files only please */ |
405 |
> |
return load_a_module(path, 1); |
406 |
|
} |
407 |
|
|
408 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
409 |
< |
"Cannot locate module %s", path); |
410 |
< |
ilog(L_WARN, "Cannot locate module %s", path); |
408 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
409 |
> |
"Cannot locate module %s", name); |
410 |
> |
ilog(LOG_TYPE_IRCD, "Cannot locate module %s", name); |
411 |
|
return -1; |
412 |
|
} |
352 |
– |
|
353 |
– |
/* load a module .. */ |
354 |
– |
static void |
355 |
– |
mo_modload(struct Client *client_p, struct Client *source_p, |
356 |
– |
int parc, char *parv[]) |
357 |
– |
{ |
358 |
– |
const char *m_bn = NULL; |
359 |
– |
|
360 |
– |
if (!IsAdmin(source_p)) |
361 |
– |
{ |
362 |
– |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
363 |
– |
me.name, source_p->name); |
364 |
– |
return; |
365 |
– |
} |
366 |
– |
|
367 |
– |
m_bn = libio_basename(parv[1]); |
368 |
– |
|
369 |
– |
if (findmodule_byname(m_bn) != NULL) |
370 |
– |
{ |
371 |
– |
sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded", |
372 |
– |
me.name, source_p->name, m_bn); |
373 |
– |
return; |
374 |
– |
} |
375 |
– |
|
376 |
– |
load_one_module(parv[1], 0); |
377 |
– |
} |
378 |
– |
|
379 |
– |
/* unload a module .. */ |
380 |
– |
static void |
381 |
– |
mo_modunload(struct Client *client_p, struct Client *source_p, |
382 |
– |
int parc, char *parv[]) |
383 |
– |
{ |
384 |
– |
const char *m_bn = NULL; |
385 |
– |
dlink_node *ptr; |
386 |
– |
struct module *modp; |
387 |
– |
|
388 |
– |
if (!IsAdmin(source_p)) |
389 |
– |
{ |
390 |
– |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
391 |
– |
me.name, source_p->name); |
392 |
– |
return; |
393 |
– |
} |
394 |
– |
|
395 |
– |
m_bn = libio_basename(parv[1]); |
396 |
– |
|
397 |
– |
if ((ptr = findmodule_byname(m_bn)) == NULL) |
398 |
– |
{ |
399 |
– |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
400 |
– |
me.name, source_p->name, m_bn); |
401 |
– |
return; |
402 |
– |
} |
403 |
– |
|
404 |
– |
modp = ptr->data; |
405 |
– |
|
406 |
– |
if (modp->core == 1) |
407 |
– |
{ |
408 |
– |
sendto_one(source_p, |
409 |
– |
":%s NOTICE %s :Module %s is a core module and may not be unloaded", |
410 |
– |
me.name, source_p->name, m_bn); |
411 |
– |
return; |
412 |
– |
} |
413 |
– |
|
414 |
– |
/* XXX might want to simply un dlink it here */ |
415 |
– |
|
416 |
– |
if (unload_one_module(m_bn, 1) == -1) |
417 |
– |
{ |
418 |
– |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
419 |
– |
me.name, source_p->name, m_bn); |
420 |
– |
} |
421 |
– |
} |
422 |
– |
|
423 |
– |
/* unload and load in one! */ |
424 |
– |
static void |
425 |
– |
mo_modreload(struct Client *client_p, struct Client *source_p, |
426 |
– |
int parc, char *parv[]) |
427 |
– |
{ |
428 |
– |
const char *m_bn = NULL; |
429 |
– |
dlink_node *ptr; |
430 |
– |
struct module *modp; |
431 |
– |
int check_core; |
432 |
– |
|
433 |
– |
if (!IsAdmin(source_p)) |
434 |
– |
{ |
435 |
– |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
436 |
– |
me.name, source_p->name); |
437 |
– |
return; |
438 |
– |
} |
439 |
– |
|
440 |
– |
m_bn = libio_basename(parv[1]); |
441 |
– |
|
442 |
– |
if ((ptr = findmodule_byname(m_bn)) == NULL) |
443 |
– |
{ |
444 |
– |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
445 |
– |
me.name, source_p->name, m_bn); |
446 |
– |
return; |
447 |
– |
} |
448 |
– |
|
449 |
– |
modp = ptr->data; |
450 |
– |
check_core = modp->core; |
451 |
– |
|
452 |
– |
if (unload_one_module(m_bn, 1) == -1) |
453 |
– |
{ |
454 |
– |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
455 |
– |
me.name, source_p->name, m_bn); |
456 |
– |
return; |
457 |
– |
} |
458 |
– |
|
459 |
– |
if ((load_one_module(parv[1], check_core) == -1) && check_core) |
460 |
– |
{ |
461 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core " |
462 |
– |
"module: %s: terminating ircd", parv[1]); |
463 |
– |
ilog(L_CRIT, "Error loading core module %s: terminating ircd", parv[1]); |
464 |
– |
exit(0); |
465 |
– |
} |
466 |
– |
} |
467 |
– |
|
468 |
– |
/* list modules .. */ |
469 |
– |
static void |
470 |
– |
mo_modlist(struct Client *client_p, struct Client *source_p, |
471 |
– |
int parc, char *parv[]) |
472 |
– |
{ |
473 |
– |
const dlink_node *ptr = NULL; |
474 |
– |
|
475 |
– |
if (!IsAdmin(source_p)) |
476 |
– |
{ |
477 |
– |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
478 |
– |
me.name, source_p->name); |
479 |
– |
return; |
480 |
– |
} |
481 |
– |
|
482 |
– |
DLINK_FOREACH(ptr, mod_list.head) |
483 |
– |
{ |
484 |
– |
const struct module *modp = ptr->data; |
485 |
– |
|
486 |
– |
if (parc > 1 && !match(parv[1], modp->name)) |
487 |
– |
continue; |
488 |
– |
|
489 |
– |
sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0], |
490 |
– |
modp->name, modp->handle, |
491 |
– |
modp->version, modp->core?"(core)":""); |
492 |
– |
} |
493 |
– |
|
494 |
– |
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), |
495 |
– |
me.name, source_p->name); |
496 |
– |
} |
497 |
– |
|
498 |
– |
/* unload and reload all modules */ |
499 |
– |
static void |
500 |
– |
mo_modrestart(struct Client *client_p, struct Client *source_p, |
501 |
– |
int parc, char *parv[]) |
502 |
– |
{ |
503 |
– |
unsigned int modnum = 0; |
504 |
– |
dlink_node *ptr = NULL, *ptr_next = NULL; |
505 |
– |
|
506 |
– |
if (!IsAdmin(source_p)) |
507 |
– |
{ |
508 |
– |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
509 |
– |
me.name, source_p->name); |
510 |
– |
return; |
511 |
– |
} |
512 |
– |
|
513 |
– |
sendto_one(source_p, ":%s NOTICE %s :Reloading all modules", |
514 |
– |
me.name, source_p->name); |
515 |
– |
|
516 |
– |
modnum = dlink_list_length(&mod_list); |
517 |
– |
|
518 |
– |
DLINK_FOREACH_SAFE(ptr, ptr_next, mod_list.head) |
519 |
– |
{ |
520 |
– |
struct module *modp = ptr->data; |
521 |
– |
unload_one_module(modp->name, 0); |
522 |
– |
} |
523 |
– |
|
524 |
– |
load_all_modules(0); |
525 |
– |
load_conf_modules(); |
526 |
– |
load_core_modules(0); |
527 |
– |
|
528 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, |
529 |
– |
"Module Restart: %u modules unloaded, %u modules loaded", |
530 |
– |
modnum, dlink_list_length(&mod_list)); |
531 |
– |
ilog(L_WARN, "Module Restart: %u modules unloaded, %u modules loaded", |
532 |
– |
modnum, dlink_list_length(&mod_list)); |
533 |
– |
} |