1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* modules.c: A module loader. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id: /local/oftc-hybrid/branches/oftc-hybrid-1.5/src/modules.c 865 2006-06-08T22:35:55.339311Z stu $ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "conf/conf.h" |
27 |
#include "client.h" |
28 |
#include "ircd_defs.h" |
29 |
#include "send.h" |
30 |
#include "restart.h" |
31 |
#include "msg.h" |
32 |
#include "handlers.h" |
33 |
#include "numeric.h" |
34 |
#include "parse.h" |
35 |
|
36 |
#ifndef STATIC_MODULES |
37 |
|
38 |
static void mo_modload(struct Client *, struct Client *, int, char *[]); |
39 |
static void mo_modlist(struct Client *, struct Client *, int, char *[]); |
40 |
static void mo_modreload(struct Client *, struct Client *, int, char *[]); |
41 |
static void mo_modunload(struct Client *, struct Client *, int, char *[]); |
42 |
static void mo_modrestart(struct Client *, struct Client *, int, char *[]); |
43 |
|
44 |
struct Message modload_msgtab = { |
45 |
"MODLOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
46 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modload, m_ignore} |
47 |
}; |
48 |
|
49 |
struct Message modunload_msgtab = { |
50 |
"MODUNLOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
51 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modunload, m_ignore} |
52 |
}; |
53 |
|
54 |
struct Message modreload_msgtab = { |
55 |
"MODRELOAD", 0, 0, 2, 0, MFLG_SLOW, 0, |
56 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modreload, m_ignore} |
57 |
}; |
58 |
|
59 |
struct Message modlist_msgtab = { |
60 |
"MODLIST", 0, 0, 0, 0, MFLG_SLOW, 0, |
61 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modlist, m_ignore} |
62 |
}; |
63 |
|
64 |
struct Message modrestart_msgtab = { |
65 |
"MODRESTART", 0, 0, 0, 0, MFLG_SLOW, 0, |
66 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modrestart, m_ignore} |
67 |
}; |
68 |
|
69 |
/* |
70 |
* modules_init |
71 |
* |
72 |
* input - NONE |
73 |
* output - NONE |
74 |
* side effects - The basic module manipulation modules are loaded |
75 |
*/ |
76 |
void |
77 |
modules_init(void) |
78 |
{ |
79 |
mod_add_cmd(&modload_msgtab); |
80 |
mod_add_cmd(&modunload_msgtab); |
81 |
mod_add_cmd(&modreload_msgtab); |
82 |
mod_add_cmd(&modlist_msgtab); |
83 |
mod_add_cmd(&modrestart_msgtab); |
84 |
} |
85 |
|
86 |
/* load a module .. */ |
87 |
static void |
88 |
mo_modload(struct Client *client_p, struct Client *source_p, |
89 |
int parc, char *parv[]) |
90 |
{ |
91 |
char *m_bn; |
92 |
|
93 |
if (!IsAdmin(source_p)) |
94 |
{ |
95 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
96 |
me.name, source_p->name); |
97 |
return; |
98 |
} |
99 |
|
100 |
m_bn = basename(parv[1]); |
101 |
|
102 |
if (find_module(m_bn, 1) != NULL) |
103 |
{ |
104 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded", |
105 |
me.name, source_p->name, m_bn); |
106 |
return; |
107 |
} |
108 |
|
109 |
load_module(parv[1]); |
110 |
} |
111 |
|
112 |
/* unload a module .. */ |
113 |
static void |
114 |
mo_modunload(struct Client *client_p, struct Client *source_p, |
115 |
int parc, char *parv[]) |
116 |
{ |
117 |
char *m_bn; |
118 |
struct Module *modp; |
119 |
|
120 |
if (!IsAdmin(source_p)) |
121 |
{ |
122 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
123 |
me.name, source_p->name); |
124 |
return; |
125 |
} |
126 |
|
127 |
m_bn = basename(parv[1]); |
128 |
|
129 |
if ((modp = find_module(m_bn, 1)) == NULL) |
130 |
{ |
131 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
132 |
me.name, source_p->name, m_bn); |
133 |
return; |
134 |
} |
135 |
|
136 |
/* XXX might want to simply un dlink it here */ |
137 |
|
138 |
unload_module(modp); |
139 |
} |
140 |
|
141 |
/* unload and load in one! */ |
142 |
static void |
143 |
mo_modreload(struct Client *client_p, struct Client *source_p, |
144 |
int parc, char *parv[]) |
145 |
{ |
146 |
char *m_bn; |
147 |
struct Module *modp; |
148 |
int check_core; |
149 |
|
150 |
if (!IsAdmin(source_p)) |
151 |
{ |
152 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
153 |
me.name, source_p->name); |
154 |
return; |
155 |
} |
156 |
|
157 |
m_bn = basename(parv[1]); |
158 |
|
159 |
if ((modp = find_module(m_bn, 1)) == NULL) |
160 |
{ |
161 |
sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded", |
162 |
me.name, source_p->name, m_bn); |
163 |
return; |
164 |
} |
165 |
|
166 |
unload_module(modp); |
167 |
load_module(parv[1]); |
168 |
} |
169 |
|
170 |
/* list modules .. */ |
171 |
static void |
172 |
mo_modlist(struct Client *client_p, struct Client *source_p, |
173 |
int parc, char *parv[]) |
174 |
{ |
175 |
dlink_node *ptr; |
176 |
struct Module *modp; |
177 |
|
178 |
if (!IsAdmin(source_p)) |
179 |
{ |
180 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
181 |
me.name, source_p->name); |
182 |
return; |
183 |
} |
184 |
|
185 |
DLINK_FOREACH(ptr, loaded_modules.head) |
186 |
{ |
187 |
modp = ptr->data; |
188 |
|
189 |
if (parc > 1) |
190 |
{ |
191 |
if (match(parv[1], modp->name)) |
192 |
{ |
193 |
sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0], |
194 |
modp->name, modp->address, |
195 |
modp->version, ""); |
196 |
} |
197 |
} |
198 |
else |
199 |
{ |
200 |
sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0], |
201 |
modp->name, modp->address, |
202 |
modp->version, ""); |
203 |
} |
204 |
} |
205 |
|
206 |
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), |
207 |
me.name, source_p->name); |
208 |
} |
209 |
|
210 |
/* unload and reload all modules */ |
211 |
static void |
212 |
mo_modrestart(struct Client *client_p, struct Client *source_p, |
213 |
int parc, char *parv[]) |
214 |
{ |
215 |
unsigned int modnum = 0; |
216 |
dlink_node *ptr; |
217 |
dlink_node *tptr; |
218 |
struct Module *modp; |
219 |
|
220 |
if (!IsAdmin(source_p)) |
221 |
{ |
222 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
223 |
me.name, source_p->name); |
224 |
return; |
225 |
} |
226 |
|
227 |
sendto_one(source_p, ":%s NOTICE %s :Reloading all modules", |
228 |
me.name, source_p->name); |
229 |
|
230 |
modnum = dlink_list_length(&loaded_modules); |
231 |
|
232 |
DLINK_FOREACH_SAFE(ptr, tptr, loaded_modules.head) |
233 |
{ |
234 |
modp = ptr->data; |
235 |
unload_module(modp); |
236 |
} |
237 |
|
238 |
boot_modules(1); |
239 |
|
240 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
241 |
"Module Restart: %u modules unloaded, %lu modules loaded", |
242 |
modnum, dlink_list_length(&loaded_modules)); |
243 |
ilog(L_WARN, "Module Restart: %u modules unloaded, %lu modules loaded", |
244 |
modnum, dlink_list_length(&loaded_modules)); |
245 |
} |
246 |
#endif /* STATIC_MODULES */ |