ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_module.c
Revision: 1566
Committed: Mon Oct 15 18:31:05 2012 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_module.c
File size: 7368 byte(s)
Log Message:
- m_module.c: if we cannot find a available option, yell at the user

File Contents

# Content
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
43 /*! \brief MODULE command handler (called by operators)
44 *
45 * \param client_p Pointer to allocated Client struct with physical connection
46 * to this server, i.e. with an open socket connected.
47 * \param source_p Pointer to allocated Client struct from which the message
48 * originally comes from. This can be a local or remote client.
49 * \param parc Integer holding the number of supplied arguments.
50 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
51 * pointers.
52 * \note Valid arguments for this command are:
53 * - parv[0] = sender prefix
54 * - parv[1] = action [LOAD, UNLOAD, RELOAD, LIST]
55 * - parv[2] = module name
56 */
57 static void
58 mo_module(struct Client *client_p, struct Client *source_p,
59 int parc, char *parv[])
60 {
61 const char *m_bn = NULL;
62 struct module *modp = NULL;
63 int check_core;
64
65 if (!HasOFlag(source_p, OPER_FLAG_MODULE))
66 {
67 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
68 me.name, source_p->name);
69 return;
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;
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;
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;
93 }
94
95 load_one_module(parv[2]);
96 return;
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;
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;
113 }
114
115 if (modp->flags & MODULE_FLAG_CORE)
116 {
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;
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;
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;
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;
144 }
145
146 if (!strcmp(parv[2], "*"))
147 {
148 unsigned int modnum = 0;
149 dlink_node *ptr = NULL, *ptr_next = NULL;
150
151 sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
152 me.name, source_p->name);
153
154 modnum = dlink_list_length(&modules_list);
155
156 DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
157 {
158 modp = ptr->data;
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,
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;
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;
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;
189 }
190
191 check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
192
193 if (unload_one_module(m_bn, 1) == -1)
194 {
195 sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
196 me.name, source_p->name, m_bn);
197 return;
198 }
199
200 if ((load_one_module(parv[2]) == -1) && check_core)
201 {
202 sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core "
203 "module: %s: terminating ircd", parv[2]);
204 ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[2]);
205 exit(0);
206 }
207
208 return;
209 }
210
211 if (!irccmp(parv[1], "LIST"))
212 {
213 const dlink_node *ptr = NULL;
214
215 DLINK_FOREACH(ptr, modules_list.head)
216 {
217 modp = ptr->data;
218
219 if (parc > 2 && !match(parv[2], modp->name))
220 continue;
221
222 sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
223 modp->name, modp->handle,
224 modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
225 }
226
227 sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
228 me.name, source_p->name);
229 return;
230 }
231
232 sendto_one(source_p, ":%s NOTICE %s :%s is not a valid option. "
233 "Choose from LOAD, UNLOAD, RELOAD, LIST",
234 me.name, source_p->name, parv[1]);
235 }
236
237
238 static struct Message module_msgtab = {
239 "MODULE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
240 {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_module, m_ignore}
241 };
242
243 static void
244 module_init(void)
245 {
246 mod_add_cmd(&module_msgtab);
247 }
248
249 static void
250 module_exit(void)
251 {
252 mod_del_cmd(&module_msgtab);
253 }
254
255 struct module module_entry = {
256 .node = { NULL, NULL, NULL },
257 .name = NULL,
258 .version = "$Revision$",
259 .handle = NULL,
260 .modinit = module_init,
261 .modexit = module_exit,
262 .flags = MODULE_FLAG_NOUNLOAD
263 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision