39 |
|
#include "packet.h" |
40 |
|
|
41 |
|
|
42 |
+ |
|
43 |
|
/*! \brief MODULE command handler (called by operators) |
44 |
|
* |
45 |
|
* \param client_p Pointer to allocated Client struct with physical connection |
54 |
|
* - parv[1] = action [LOAD, UNLOAD, RELOAD, LIST] |
55 |
|
* - parv[2] = module name |
56 |
|
*/ |
57 |
< |
static void |
57 |
> |
static int |
58 |
|
mo_module(struct Client *client_p, struct Client *source_p, |
59 |
|
int parc, char *parv[]) |
60 |
|
{ |
66 |
|
{ |
67 |
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
68 |
|
me.name, source_p->name); |
69 |
< |
return; |
69 |
> |
return 0; |
70 |
|
} |
71 |
|
|
72 |
|
if (EmptyString(parv[1])) |
73 |
|
{ |
74 |
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
75 |
|
me.name, source_p->name, "MODULE"); |
76 |
< |
return; |
76 |
> |
return 0; |
77 |
|
} |
78 |
|
|
79 |
|
if (!irccmp(parv[1], "LOAD")) |
80 |
|
{ |
81 |
+ |
if (EmptyString(parv[2])) |
82 |
+ |
{ |
83 |
+ |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
84 |
+ |
me.name, source_p->name, "MODULE"); |
85 |
+ |
return 0; |
86 |
+ |
} |
87 |
+ |
|
88 |
|
if (findmodule_byname((m_bn = libio_basename(parv[2]))) != NULL) |
89 |
|
{ |
90 |
|
sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded", |
91 |
|
me.name, source_p->name, m_bn); |
92 |
< |
return; |
92 |
> |
return 0; |
93 |
|
} |
94 |
|
|
95 |
|
load_one_module(parv[2]); |
96 |
< |
return; |
96 |
> |
return 0; |
97 |
|
} |
98 |
|
|
99 |
|
if (!irccmp(parv[1], "UNLOAD")) |
100 |
|
{ |
101 |
+ |
if (EmptyString(parv[2])) |
102 |
+ |
{ |
103 |
+ |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
104 |
+ |
me.name, source_p->name, "MODULE"); |
105 |
+ |
return 0; |
106 |
+ |
} |
107 |
+ |
|
108 |
|
if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL) |
109 |
|
{ |
110 |
|
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
111 |
|
me.name, source_p->name, m_bn); |
112 |
< |
return; |
112 |
> |
return 0; |
113 |
|
} |
114 |
|
|
115 |
|
if (modp->flags & MODULE_FLAG_CORE) |
117 |
|
sendto_one(source_p, |
118 |
|
":%s NOTICE %s :Module %s is a core module and may not be unloaded", |
119 |
|
me.name, source_p->name, m_bn); |
120 |
< |
return; |
120 |
> |
return 0; |
121 |
> |
} |
122 |
> |
|
123 |
> |
if (modp->flags & MODULE_FLAG_NOUNLOAD) |
124 |
> |
{ |
125 |
> |
sendto_one(source_p, |
126 |
> |
":%s NOTICE %s :Module %s is a resident module and may not be unloaded", |
127 |
> |
me.name, source_p->name, m_bn); |
128 |
> |
return 0; |
129 |
|
} |
130 |
|
|
131 |
|
if (unload_one_module(m_bn, 1) == -1) |
132 |
|
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
133 |
|
me.name, source_p->name, m_bn); |
134 |
< |
return; |
134 |
> |
return 0; |
135 |
|
} |
136 |
|
|
137 |
|
if (!irccmp(parv[1], "RELOAD")) |
138 |
|
{ |
139 |
+ |
if (EmptyString(parv[2])) |
140 |
+ |
{ |
141 |
+ |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
142 |
+ |
me.name, source_p->name, "MODULE"); |
143 |
+ |
return 0; |
144 |
+ |
} |
145 |
+ |
|
146 |
|
if (!strcmp(parv[2], "*")) |
147 |
|
{ |
148 |
|
unsigned int modnum = 0; |
156 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head) |
157 |
|
{ |
158 |
|
modp = ptr->data; |
159 |
< |
unload_one_module(modp->name, 0); |
159 |
> |
|
160 |
> |
if (!(modp->flags & MODULE_FLAG_NOUNLOAD)) |
161 |
> |
unload_one_module(modp->name, 0); |
162 |
|
} |
163 |
|
|
164 |
|
load_all_modules(0); |
165 |
|
load_conf_modules(); |
166 |
|
load_core_modules(0); |
167 |
|
|
168 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
168 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
169 |
|
"Module Restart: %u modules unloaded, %u modules loaded", |
170 |
|
modnum, dlink_list_length(&modules_list)); |
171 |
|
ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded", |
172 |
|
modnum, dlink_list_length(&modules_list)); |
173 |
< |
return; |
173 |
> |
return 0; |
174 |
|
} |
175 |
|
|
176 |
|
if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL) |
177 |
|
{ |
178 |
|
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
179 |
|
me.name, source_p->name, m_bn); |
180 |
< |
return; |
180 |
> |
return 0; |
181 |
> |
} |
182 |
> |
|
183 |
> |
if (modp->flags & MODULE_FLAG_NOUNLOAD) |
184 |
> |
{ |
185 |
> |
sendto_one(source_p, |
186 |
> |
":%s NOTICE %s :Module %s is a resident module and may not be unloaded", |
187 |
> |
me.name, source_p->name, m_bn); |
188 |
> |
return 0; |
189 |
|
} |
190 |
|
|
191 |
|
check_core = (modp->flags & MODULE_FLAG_CORE) != 0; |
194 |
|
{ |
195 |
|
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
196 |
|
me.name, source_p->name, m_bn); |
197 |
< |
return; |
197 |
> |
return 0; |
198 |
|
} |
199 |
|
|
200 |
|
if ((load_one_module(parv[2]) == -1) && check_core) |
201 |
|
{ |
202 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core " |
202 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
203 |
> |
"Error reloading core " |
204 |
|
"module: %s: terminating ircd", parv[2]); |
205 |
|
ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[2]); |
206 |
|
exit(0); |
207 |
|
} |
208 |
|
|
209 |
< |
return; |
209 |
> |
return 0; |
210 |
|
} |
211 |
|
|
212 |
|
if (!irccmp(parv[1], "LIST")) |
215 |
|
|
216 |
|
DLINK_FOREACH(ptr, modules_list.head) |
217 |
|
{ |
218 |
< |
if (parc > 2 && !match(parv[2], modp->name)) |
218 |
> |
modp = ptr->data; |
219 |
> |
|
220 |
> |
if (!EmptyString(parv[2]) && match(parv[2], modp->name)) |
221 |
|
continue; |
222 |
|
|
223 |
|
sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name, |
227 |
|
|
228 |
|
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), |
229 |
|
me.name, source_p->name); |
230 |
< |
return; |
230 |
> |
return 0; |
231 |
|
} |
189 |
– |
} |
232 |
|
|
233 |
+ |
sendto_one(source_p, ":%s NOTICE %s :%s is not a valid option. " |
234 |
+ |
"Choose from LOAD, UNLOAD, RELOAD, LIST", |
235 |
+ |
me.name, source_p->name, parv[1]); |
236 |
+ |
return 0; |
237 |
+ |
} |
238 |
|
|
239 |
< |
static struct Message module_msgtab = { |
240 |
< |
"MODULE", 0, 0, 2, 0, MFLG_SLOW, 0, |
239 |
> |
static struct Message module_msgtab = |
240 |
> |
{ |
241 |
> |
"MODULE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
242 |
|
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_module, m_ignore} |
243 |
|
}; |
244 |
|
|
254 |
|
mod_del_cmd(&module_msgtab); |
255 |
|
} |
256 |
|
|
257 |
< |
struct module module_entry = { |
257 |
> |
struct module module_entry = |
258 |
> |
{ |
259 |
|
.node = { NULL, NULL, NULL }, |
260 |
|
.name = NULL, |
261 |
|
.version = "$Revision$", |
262 |
|
.handle = NULL, |
263 |
|
.modinit = module_init, |
264 |
|
.modexit = module_exit, |
265 |
< |
.flags = MODULE_FLAG_CORE |
265 |
> |
.flags = MODULE_FLAG_NOUNLOAD |
266 |
|
}; |