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