1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2001-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 |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_resv.c |
23 |
* \brief Includes required functions for processing the RESV command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "ircd.h" |
30 |
#include "irc_string.h" |
31 |
#include "numeric.h" |
32 |
#include "server.h" |
33 |
#include "send.h" |
34 |
#include "parse.h" |
35 |
#include "modules.h" |
36 |
#include "conf.h" |
37 |
#include "log.h" |
38 |
#include "resv.h" |
39 |
#include "hash.h" |
40 |
|
41 |
|
42 |
/* parse_resv() |
43 |
* |
44 |
* inputs - source_p, NULL supported |
45 |
* - thing to resv |
46 |
* - time_t if tkline |
47 |
* - reason |
48 |
* outputs - none |
49 |
* side effects - parse resv, create if valid |
50 |
*/ |
51 |
static void |
52 |
parse_resv(struct Client *source_p, char *name, int tkline_time, char *reason) |
53 |
{ |
54 |
if (IsChanPrefix(*name)) |
55 |
{ |
56 |
struct MaskItem *conf = NULL; |
57 |
|
58 |
if ((conf = create_resv(name, reason, NULL)) == NULL) |
59 |
{ |
60 |
if (IsClient(source_p)) |
61 |
sendto_one_notice(source_p, &me, ":A RESV has already been placed on channel: %s", name); |
62 |
|
63 |
return; |
64 |
} |
65 |
|
66 |
conf->setat = CurrentTime; |
67 |
SetConfDatabase(conf); |
68 |
|
69 |
if (tkline_time) |
70 |
{ |
71 |
if (IsClient(source_p)) |
72 |
sendto_one_notice(source_p, &me, ":A %d minute %s RESV has been placed on channel: %s", |
73 |
tkline_time/60, (MyClient(source_p) ? "local" : "remote"), name); |
74 |
|
75 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
76 |
"%s has placed a %d minute %s RESV on channel: %s [%s]", |
77 |
get_oper_name(source_p), |
78 |
tkline_time/60, |
79 |
(MyClient(source_p) ? "local" : "remote"), |
80 |
conf->name, conf->reason); |
81 |
ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]", |
82 |
get_oper_name(source_p), (int)tkline_time/60, |
83 |
conf->name, conf->reason); |
84 |
conf->until = CurrentTime + tkline_time; |
85 |
} |
86 |
else |
87 |
{ |
88 |
if (IsClient(source_p)) |
89 |
sendto_one_notice(source_p, &me, ":A %s RESV has been placed on channel %s", |
90 |
(MyClient(source_p) ? "local" : "remote"), name); |
91 |
|
92 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
93 |
"%s has placed a %s RESV on channel %s : [%s]", |
94 |
get_oper_name(source_p), |
95 |
(MyClient(source_p) ? "local" : "remote"), |
96 |
conf->name, conf->reason); |
97 |
ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]", |
98 |
get_oper_name(source_p), conf->name, conf->reason); |
99 |
} |
100 |
} |
101 |
else |
102 |
{ |
103 |
struct MaskItem *conf = NULL; |
104 |
|
105 |
if (!valid_wild_card_simple(name)) |
106 |
{ |
107 |
if (IsClient(source_p)) |
108 |
sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the resv", |
109 |
ConfigGeneral.min_nonwildcard_simple); |
110 |
|
111 |
return; |
112 |
} |
113 |
|
114 |
if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(name)) |
115 |
{ |
116 |
if (IsClient(source_p)) |
117 |
sendto_one_notice(source_p, &me, ":You must be an admin to perform a wildcard RESV"); |
118 |
|
119 |
return; |
120 |
} |
121 |
|
122 |
if ((conf = create_resv(name, reason, NULL)) == NULL) |
123 |
{ |
124 |
if (IsClient(source_p)) |
125 |
sendto_one_notice(source_p, &me, ":A RESV has already been placed on nick %s", name); |
126 |
|
127 |
return; |
128 |
} |
129 |
|
130 |
conf->setat = CurrentTime; |
131 |
SetConfDatabase(conf); |
132 |
|
133 |
if (tkline_time) |
134 |
{ |
135 |
if (IsClient(source_p)) |
136 |
sendto_one_notice(source_p, &me, ":A %d minute %s RESV has been placed on nick %s : [%s]", |
137 |
tkline_time/60, (MyClient(source_p) ? "local" : "remote"), |
138 |
conf->name, conf->reason); |
139 |
|
140 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
141 |
"%s has placed a %d minute %s RESV on nick %s : [%s]", |
142 |
get_oper_name(source_p), tkline_time/60, |
143 |
(MyClient(source_p) ? "local" : "remote"), |
144 |
conf->name, conf->reason); |
145 |
ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]", |
146 |
get_oper_name(source_p), (int)tkline_time/60, conf->name, conf->reason); |
147 |
conf->until = CurrentTime + tkline_time; |
148 |
} |
149 |
else |
150 |
{ |
151 |
if (IsClient(source_p)) |
152 |
sendto_one_notice(source_p, &me, ":A %s RESV has been placed on nick %s : [%s]", |
153 |
(MyClient(source_p) ? "local" : "remote"), conf->name, conf->reason); |
154 |
|
155 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
156 |
"%s has placed a %s RESV on nick %s : [%s]", |
157 |
get_oper_name(source_p), |
158 |
(MyClient(source_p) ? "local" : "remote"), |
159 |
conf->name, conf->reason); |
160 |
ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]", |
161 |
get_oper_name(source_p), conf->name, conf->reason); |
162 |
} |
163 |
} |
164 |
} |
165 |
|
166 |
/* mo_resv() |
167 |
* parv[0] = command |
168 |
* parv[1] = channel/nick to forbid |
169 |
*/ |
170 |
static int |
171 |
mo_resv(struct Client *source_p, int parc, char *parv[]) |
172 |
{ |
173 |
char *resv = NULL; |
174 |
char *reason = NULL; |
175 |
char *target_server = NULL; |
176 |
time_t tkline_time = 0; |
177 |
|
178 |
/* RESV #channel ON irc.server.com :abuse |
179 |
* RESV kiddie ON irc.server.com :abuse |
180 |
*/ |
181 |
if (parse_aline("RESV", source_p, parc, parv, 0, &resv, NULL, |
182 |
&tkline_time, &target_server, &reason) < 0) |
183 |
return 0; |
184 |
|
185 |
if (target_server) |
186 |
{ |
187 |
/* if a given expire time is given, ENCAP it */ |
188 |
if (tkline_time) |
189 |
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
190 |
"ENCAP %s RESV %d %s 0 :%s", |
191 |
target_server, (int)tkline_time, resv, reason); |
192 |
else |
193 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
194 |
"RESV %s %s :%s", |
195 |
target_server, resv, reason); |
196 |
/* Allow ON to apply local resv as well if it matches */ |
197 |
if (match(target_server, me.name)) |
198 |
return 0; |
199 |
} |
200 |
else |
201 |
{ |
202 |
/* RESV #channel :abuse |
203 |
* RESV kiddie :abuse |
204 |
*/ |
205 |
if (tkline_time) |
206 |
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_RESV, |
207 |
"RESV %d %s 0 :%s", (int)tkline_time, resv, reason); |
208 |
else |
209 |
cluster_a_line(source_p, "RESV", CAP_KLN, SHARED_RESV, |
210 |
"%s :%s", resv, reason); |
211 |
} |
212 |
|
213 |
parse_resv(source_p, resv, (int)tkline_time, reason); |
214 |
return 0; |
215 |
} |
216 |
|
217 |
/* me_resv() |
218 |
* |
219 |
* inputs - server |
220 |
* - client (oper) |
221 |
* - parc number of arguments |
222 |
* - parv list of arguments |
223 |
* via parv[] |
224 |
* parv[0] = command |
225 |
* parv[1] = tkline_time |
226 |
* parv[2] = name |
227 |
* parv[3] = 0 |
228 |
* parv[4] = reason |
229 |
* parc should be 5 |
230 |
* |
231 |
* outputs - NONE |
232 |
* side effects - |
233 |
*/ |
234 |
static int |
235 |
me_resv(struct Client *source_p, int parc, char *parv[]) |
236 |
{ |
237 |
if (parc != 5 || EmptyString(parv[4])) |
238 |
return 0; |
239 |
|
240 |
parse_resv(source_p, parv[2], atoi(parv[1]), parv[4]); |
241 |
return 0; |
242 |
} |
243 |
|
244 |
/* ms_resv() |
245 |
* parv[0] = command |
246 |
* parv[1] = target server |
247 |
* parv[2] = channel/nick to resv |
248 |
* parv[3] = reason |
249 |
*/ |
250 |
static int |
251 |
ms_resv(struct Client *source_p, int parc, char *parv[]) |
252 |
{ |
253 |
if (parc != 4 || EmptyString(parv[3])) |
254 |
return 0; |
255 |
|
256 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "RESV %s %s :%s", |
257 |
parv[1], parv[2], parv[3]); |
258 |
|
259 |
if (match(parv[1], me.name)) |
260 |
return 0; |
261 |
|
262 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
263 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
264 |
source_p->username, source_p->host, |
265 |
SHARED_RESV)) |
266 |
parse_resv(source_p, parv[2], 0, parv[3]); |
267 |
return 0; |
268 |
} |
269 |
|
270 |
static struct Message resv_msgtab = |
271 |
{ |
272 |
"RESV", NULL, 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
273 |
{ m_ignore, m_not_oper, ms_resv, me_resv, mo_resv, m_ignore } |
274 |
}; |
275 |
|
276 |
static void |
277 |
module_init(void) |
278 |
{ |
279 |
mod_add_cmd(&resv_msgtab); |
280 |
} |
281 |
|
282 |
static void |
283 |
module_exit(void) |
284 |
{ |
285 |
mod_del_cmd(&resv_msgtab); |
286 |
} |
287 |
|
288 |
struct module module_entry = |
289 |
{ |
290 |
.node = { NULL, NULL, NULL }, |
291 |
.name = NULL, |
292 |
.version = "$Revision$", |
293 |
.handle = NULL, |
294 |
.modinit = module_init, |
295 |
.modexit = module_exit, |
296 |
.flags = 0 |
297 |
}; |