1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* |
4 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
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 |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
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 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_module.c |
23 |
* \brief Includes required functions for processing the MODULE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "irc_string.h" |
31 |
#include "ircd.h" |
32 |
#include "numeric.h" |
33 |
#include "conf.h" |
34 |
#include "log.h" |
35 |
#include "s_user.h" |
36 |
#include "send.h" |
37 |
#include "parse.h" |
38 |
#include "modules.h" |
39 |
#include "packet.h" |
40 |
|
41 |
|
42 |
/*! \brief MODULE command handler (called by operators) |
43 |
* |
44 |
* \param client_p Pointer to allocated Client struct with physical connection |
45 |
* to this server, i.e. with an open socket connected. |
46 |
* \param source_p Pointer to allocated Client struct from which the message |
47 |
* originally comes from. This can be a local or remote client. |
48 |
* \param parc Integer holding the number of supplied arguments. |
49 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
50 |
* pointers. |
51 |
* \note Valid arguments for this command are: |
52 |
* - parv[0] = sender prefix |
53 |
* - parv[1] = action [LOAD, UNLOAD, RELOAD, LIST] |
54 |
* - parv[2] = module name |
55 |
*/ |
56 |
static void |
57 |
mo_module(struct Client *client_p, struct Client *source_p, |
58 |
int parc, char *parv[]) |
59 |
{ |
60 |
const char *m_bn = NULL; |
61 |
struct module *modp = NULL; |
62 |
int check_core; |
63 |
|
64 |
if (!HasOFlag(source_p, OPER_FLAG_MODULE)) |
65 |
{ |
66 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
67 |
me.name, source_p->name); |
68 |
return; |
69 |
} |
70 |
|
71 |
if (EmptyString(parv[1])) |
72 |
{ |
73 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
74 |
me.name, source_p->name, "MODULE"); |
75 |
return; |
76 |
} |
77 |
|
78 |
if (!irccmp(parv[1], "LOAD")) |
79 |
{ |
80 |
if (findmodule_byname((m_bn = libio_basename(parv[2]))) != NULL) |
81 |
{ |
82 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded", |
83 |
me.name, source_p->name, m_bn); |
84 |
return; |
85 |
} |
86 |
|
87 |
load_one_module(parv[2]); |
88 |
return; |
89 |
} |
90 |
|
91 |
if (!irccmp(parv[1], "UNLOAD")) |
92 |
{ |
93 |
if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL) |
94 |
{ |
95 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
96 |
me.name, source_p->name, m_bn); |
97 |
return; |
98 |
} |
99 |
|
100 |
if (modp->flags & MODULE_FLAG_CORE) |
101 |
{ |
102 |
sendto_one(source_p, |
103 |
":%s NOTICE %s :Module %s is a core module and may not be unloaded", |
104 |
me.name, source_p->name, m_bn); |
105 |
return; |
106 |
} |
107 |
|
108 |
if (unload_one_module(m_bn, 1) == -1) |
109 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
110 |
me.name, source_p->name, m_bn); |
111 |
return; |
112 |
} |
113 |
|
114 |
if (!irccmp(parv[1], "RELOAD")) |
115 |
{ |
116 |
if (!strcmp(parv[2], "*")) |
117 |
{ |
118 |
unsigned int modnum = 0; |
119 |
dlink_node *ptr = NULL, *ptr_next = NULL; |
120 |
|
121 |
sendto_one(source_p, ":%s NOTICE %s :Reloading all modules", |
122 |
me.name, source_p->name); |
123 |
|
124 |
modnum = dlink_list_length(&modules_list); |
125 |
|
126 |
DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head) |
127 |
{ |
128 |
modp = ptr->data; |
129 |
unload_one_module(modp->name, 0); |
130 |
} |
131 |
|
132 |
load_all_modules(0); |
133 |
load_conf_modules(); |
134 |
load_core_modules(0); |
135 |
|
136 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
137 |
"Module Restart: %u modules unloaded, %u modules loaded", |
138 |
modnum, dlink_list_length(&modules_list)); |
139 |
ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded", |
140 |
modnum, dlink_list_length(&modules_list)); |
141 |
return; |
142 |
} |
143 |
|
144 |
if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL) |
145 |
{ |
146 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
147 |
me.name, source_p->name, m_bn); |
148 |
return; |
149 |
} |
150 |
|
151 |
check_core = (modp->flags & MODULE_FLAG_CORE) != 0; |
152 |
|
153 |
if (unload_one_module(m_bn, 1) == -1) |
154 |
{ |
155 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
156 |
me.name, source_p->name, m_bn); |
157 |
return; |
158 |
} |
159 |
|
160 |
if ((load_one_module(parv[2]) == -1) && check_core) |
161 |
{ |
162 |
sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core " |
163 |
"module: %s: terminating ircd", parv[2]); |
164 |
ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[2]); |
165 |
exit(0); |
166 |
} |
167 |
|
168 |
return; |
169 |
} |
170 |
|
171 |
if (!irccmp(parv[1], "LIST")) |
172 |
{ |
173 |
const dlink_node *ptr = NULL; |
174 |
|
175 |
DLINK_FOREACH(ptr, modules_list.head) |
176 |
{ |
177 |
if (parc > 2 && !match(parv[2], modp->name)) |
178 |
continue; |
179 |
|
180 |
sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name, |
181 |
modp->name, modp->handle, |
182 |
modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":""); |
183 |
} |
184 |
|
185 |
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), |
186 |
me.name, source_p->name); |
187 |
return; |
188 |
} |
189 |
} |
190 |
|
191 |
|
192 |
static struct Message module_msgtab = { |
193 |
"MODULE", 0, 0, 2, 0, MFLG_SLOW, 0, |
194 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_module, m_ignore} |
195 |
}; |
196 |
|
197 |
static void |
198 |
module_init(void) |
199 |
{ |
200 |
mod_add_cmd(&module_msgtab); |
201 |
} |
202 |
|
203 |
static void |
204 |
module_exit(void) |
205 |
{ |
206 |
mod_del_cmd(&module_msgtab); |
207 |
} |
208 |
|
209 |
struct module module_entry = { |
210 |
.node = { NULL, NULL, NULL }, |
211 |
.name = NULL, |
212 |
.version = "$Revision$", |
213 |
.handle = NULL, |
214 |
.modinit = module_init, |
215 |
.modexit = module_exit, |
216 |
.flags = MODULE_FLAG_CORE |
217 |
}; |