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