]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_resv.c: Reserves(jupes) a nickname or channel. | |
4 | * | |
5 | * Copyright (C) 2001-2002 Hybrid Development Team | |
6 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
21 | * USA | |
212380e3 AC |
22 | */ |
23 | ||
24 | #include "stdinc.h" | |
25 | #include "client.h" | |
26 | #include "channel.h" | |
27 | #include "ircd.h" | |
28 | #include "numeric.h" | |
29 | #include "s_serv.h" | |
30 | #include "send.h" | |
31 | #include "msg.h" | |
32 | #include "parse.h" | |
33 | #include "modules.h" | |
34 | #include "s_conf.h" | |
35 | #include "s_newconf.h" | |
36 | #include "hash.h" | |
4016731b | 37 | #include "logger.h" |
8bbeb278 | 38 | #include "bandbi.h" |
27f616dd | 39 | #include "operhash.h" |
212380e3 | 40 | |
428ca87b AC |
41 | static int mo_resv(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
42 | static int ms_resv(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
43 | static int me_resv(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
44 | static int mo_unresv(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
45 | static int ms_unresv(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
46 | static int me_unresv(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
47 | |
48 | struct Message resv_msgtab = { | |
7baa37a9 | 49 | "RESV", 0, 0, 0, 0, |
212380e3 AC |
50 | {mg_ignore, mg_not_oper, {ms_resv, 4}, {ms_resv, 4}, {me_resv, 5}, {mo_resv, 3}} |
51 | }; | |
8bbeb278 | 52 | |
212380e3 | 53 | struct Message unresv_msgtab = { |
7baa37a9 | 54 | "UNRESV", 0, 0, 0, 0, |
212380e3 AC |
55 | {mg_ignore, mg_not_oper, {ms_unresv, 3}, {ms_unresv, 3}, {me_unresv, 2}, {mo_unresv, 2}} |
56 | }; | |
57 | ||
8bbeb278 AC |
58 | mapi_clist_av1 resv_clist[] = { &resv_msgtab, &unresv_msgtab, NULL }; |
59 | ||
105a4985 | 60 | DECLARE_MODULE_AV2(resv, NULL, NULL, resv_clist, NULL, NULL, NULL, NULL, NULL); |
212380e3 AC |
61 | |
62 | static void parse_resv(struct Client *source_p, const char *name, | |
dca9e552 | 63 | const char *reason, int temp_time, int propagated); |
212380e3 | 64 | static void propagate_resv(struct Client *source_p, const char *target, |
8bbeb278 AC |
65 | int temp_time, const char *name, const char *reason); |
66 | static void cluster_resv(struct Client *source_p, int temp_time, | |
67 | const char *name, const char *reason); | |
212380e3 AC |
68 | |
69 | static void handle_remote_unresv(struct Client *source_p, const char *name); | |
dca9e552 | 70 | static void remove_resv(struct Client *source_p, const char *name, int propagated); |
212380e3 AC |
71 | |
72 | /* | |
73 | * mo_resv() | |
212380e3 AC |
74 | * parv[1] = channel/nick to forbid |
75 | * parv[2] = reason | |
76 | */ | |
77 | static int | |
428ca87b | 78 | mo_resv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
79 | { |
80 | const char *name; | |
81 | const char *reason; | |
82 | const char *target_server = NULL; | |
83 | int temp_time; | |
84 | int loc = 1; | |
dca9e552 | 85 | int propagated = ConfigFileEntry.use_propagated_bans; |
212380e3 | 86 | |
1ebe6ffc JT |
87 | if(!IsOperResv(source_p)) |
88 | { | |
8bbeb278 | 89 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv"); |
1ebe6ffc JT |
90 | return 0; |
91 | } | |
92 | ||
212380e3 AC |
93 | /* RESV [time] <name> [ON <server>] :<reason> */ |
94 | ||
95 | if((temp_time = valid_temp_time(parv[loc])) >= 0) | |
96 | loc++; | |
97 | /* we just set temp_time to -1! */ | |
98 | else | |
99 | temp_time = 0; | |
100 | ||
101 | name = parv[loc]; | |
102 | loc++; | |
103 | ||
8bbeb278 | 104 | if((parc >= loc + 2) && (irccmp(parv[loc], "ON") == 0)) |
212380e3 AC |
105 | { |
106 | if(!IsOperRemoteBan(source_p)) | |
107 | { | |
108 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 109 | me.name, source_p->name, "remoteban"); |
212380e3 AC |
110 | return 0; |
111 | } | |
112 | ||
8bbeb278 | 113 | target_server = parv[loc + 1]; |
212380e3 | 114 | loc += 2; |
dca9e552 JT |
115 | |
116 | /* Set as local-only. */ | |
117 | propagated = 0; | |
212380e3 AC |
118 | } |
119 | ||
120 | if(parc <= loc || EmptyString(parv[loc])) | |
121 | { | |
8bbeb278 | 122 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "RESV"); |
212380e3 AC |
123 | return 0; |
124 | } | |
125 | ||
126 | reason = parv[loc]; | |
127 | ||
128 | /* remote resv.. */ | |
129 | if(target_server) | |
130 | { | |
131 | propagate_resv(source_p, target_server, temp_time, name, reason); | |
132 | ||
133 | if(match(target_server, me.name) == 0) | |
134 | return 0; | |
135 | } | |
dca9e552 | 136 | else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) |
212380e3 AC |
137 | cluster_resv(source_p, temp_time, name, reason); |
138 | ||
dca9e552 JT |
139 | if(propagated && temp_time == 0) |
140 | { | |
141 | sendto_one_notice(source_p, ":Cannot set a permanent global ban"); | |
142 | return 0; | |
143 | } | |
144 | ||
145 | parse_resv(source_p, name, reason, temp_time, propagated); | |
212380e3 AC |
146 | |
147 | return 0; | |
148 | } | |
149 | ||
150 | /* ms_resv() | |
212380e3 AC |
151 | * parv[1] = target server |
152 | * parv[2] = channel/nick to forbid | |
153 | * parv[3] = reason | |
154 | */ | |
155 | static int | |
428ca87b | 156 | ms_resv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 157 | { |
8bbeb278 AC |
158 | /* parv[0] parv[1] parv[2] parv[3] |
159 | * oper target server resv reason | |
212380e3 AC |
160 | */ |
161 | propagate_resv(source_p, parv[1], 0, parv[2], parv[3]); | |
162 | ||
163 | if(!match(parv[1], me.name)) | |
164 | return 0; | |
165 | ||
166 | if(!IsPerson(source_p)) | |
167 | return 0; | |
168 | ||
dca9e552 | 169 | parse_resv(source_p, parv[2], parv[3], 0, 0); |
212380e3 AC |
170 | return 0; |
171 | } | |
172 | ||
173 | static int | |
428ca87b | 174 | me_resv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
175 | { |
176 | /* time name 0 :reason */ | |
177 | if(!IsPerson(source_p)) | |
178 | return 0; | |
179 | ||
dca9e552 | 180 | parse_resv(source_p, parv[2], parv[4], atoi(parv[1]), 0); |
212380e3 AC |
181 | return 0; |
182 | } | |
183 | ||
184 | /* parse_resv() | |
185 | * | |
186 | * inputs - source_p if error messages wanted | |
187 | * - thing to resv | |
188 | * - reason for resv | |
189 | * outputs - | |
190 | * side effects - will parse the resv and create it if valid | |
191 | */ | |
192 | static void | |
dca9e552 | 193 | parse_resv(struct Client *source_p, const char *name, const char *reason, int temp_time, int propagated) |
212380e3 AC |
194 | { |
195 | struct ConfItem *aconf; | |
196 | ||
8bbeb278 | 197 | if(!MyClient(source_p) && |
212380e3 | 198 | !find_shared_conf(source_p->username, source_p->host, |
8bbeb278 AC |
199 | source_p->servptr->name, |
200 | (temp_time > 0) ? SHARED_TRESV : SHARED_PRESV)) | |
212380e3 AC |
201 | return; |
202 | ||
203 | if(IsChannelName(name)) | |
204 | { | |
205 | if(hash_find_resv(name)) | |
206 | { | |
207 | sendto_one_notice(source_p, | |
8bbeb278 | 208 | ":A RESV has already been placed on channel: %s", name); |
212380e3 AC |
209 | return; |
210 | } | |
211 | ||
212 | if(strlen(name) > CHANNELLEN) | |
213 | { | |
8bbeb278 | 214 | sendto_one_notice(source_p, ":Invalid RESV length: %s", name); |
b0f30fa1 JT |
215 | return; |
216 | } | |
212380e3 | 217 | |
212380e3 AC |
218 | aconf = make_conf(); |
219 | aconf->status = CONF_RESV_CHANNEL; | |
220 | aconf->port = 0; | |
b52c2949 | 221 | aconf->created = rb_current_time(); |
23959371 | 222 | aconf->host = rb_strdup(name); |
47a03750 | 223 | aconf->passwd = rb_strdup(reason); |
27f616dd | 224 | aconf->info.oper = operhash_add(get_oper_name(source_p)); |
212380e3 | 225 | |
dca9e552 JT |
226 | if(propagated) |
227 | { | |
228 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
229 | aconf->hold = rb_current_time() + temp_time; | |
230 | aconf->lifetime = aconf->hold; | |
231 | replace_old_ban(aconf); | |
232 | rb_dlinkAddAlloc(aconf, &prop_bans); | |
233 | ||
234 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
235 | "%s added global %d min. RESV for [%s] [%s]", | |
236 | get_oper_name(source_p), temp_time / 60, | |
237 | name, reason); | |
238 | ilog(L_KLINE, "R %s %d %s %s", | |
239 | get_oper_name(source_p), temp_time / 60, name, reason); | |
240 | sendto_one_notice(source_p, ":Added global %d min. RESV [%s]", | |
241 | temp_time / 60, name); | |
242 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
243 | ":%s BAN R * %s %lu %d %d * :%s", | |
244 | source_p->id, aconf->host, | |
245 | (unsigned long)aconf->created, | |
246 | (int)(aconf->hold - aconf->created), | |
247 | (int)(aconf->lifetime - aconf->created), | |
248 | reason); | |
249 | } | |
250 | else if(temp_time > 0) | |
212380e3 | 251 | { |
e3354945 | 252 | aconf->hold = rb_current_time() + temp_time; |
212380e3 AC |
253 | |
254 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
255 | "%s added temporary %d min. RESV for [%s] [%s]", |
256 | get_oper_name(source_p), temp_time / 60, | |
257 | name, reason); | |
212380e3 | 258 | ilog(L_KLINE, "R %s %d %s %s", |
8bbeb278 | 259 | get_oper_name(source_p), temp_time / 60, name, reason); |
212380e3 | 260 | sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]", |
8bbeb278 | 261 | temp_time / 60, name); |
212380e3 AC |
262 | } |
263 | else | |
00c036b1 AC |
264 | { |
265 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
266 | "%s added RESV for [%s] [%s]", | |
267 | get_oper_name(source_p), name, reason); | |
268 | ilog(L_KLINE, "R %s 0 %s %s", | |
269 | get_oper_name(source_p), name, reason); | |
270 | sendto_one_notice(source_p, ":Added RESV [%s]", name); | |
271 | ||
23959371 | 272 | bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); |
00c036b1 | 273 | } |
dca9e552 JT |
274 | |
275 | add_to_resv_hash(aconf->host, aconf); | |
276 | resv_chan_forcepart(aconf->host, aconf->passwd, temp_time); | |
212380e3 AC |
277 | } |
278 | else if(clean_resv_nick(name)) | |
279 | { | |
8bbeb278 | 280 | if(strlen(name) > NICKLEN * 2) |
212380e3 | 281 | { |
8bbeb278 | 282 | sendto_one_notice(source_p, ":Invalid RESV length: %s", name); |
212380e3 AC |
283 | return; |
284 | } | |
285 | ||
212380e3 AC |
286 | if(!valid_wild_card_simple(name)) |
287 | { | |
288 | sendto_one_notice(source_p, | |
8bbeb278 AC |
289 | ":Please include at least %d non-wildcard " |
290 | "characters with the resv", | |
291 | ConfigFileEntry.min_nonwildcard_simple); | |
212380e3 AC |
292 | return; |
293 | } | |
294 | ||
0fdb2570 | 295 | if(find_nick_resv_mask(name)) |
212380e3 AC |
296 | { |
297 | sendto_one_notice(source_p, | |
8bbeb278 | 298 | ":A RESV has already been placed on nick: %s", name); |
212380e3 AC |
299 | return; |
300 | } | |
301 | ||
302 | aconf = make_conf(); | |
303 | aconf->status = CONF_RESV_NICK; | |
304 | aconf->port = 0; | |
b52c2949 | 305 | aconf->created = rb_current_time(); |
23959371 | 306 | aconf->host = rb_strdup(name); |
47a03750 | 307 | aconf->passwd = rb_strdup(reason); |
27f616dd | 308 | aconf->info.oper = operhash_add(get_oper_name(source_p)); |
212380e3 | 309 | |
dca9e552 JT |
310 | if(propagated) |
311 | { | |
312 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
313 | aconf->hold = rb_current_time() + temp_time; | |
314 | aconf->lifetime = aconf->hold; | |
315 | replace_old_ban(aconf); | |
316 | rb_dlinkAddAlloc(aconf, &prop_bans); | |
317 | ||
318 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
319 | "%s added global %d min. RESV for [%s] [%s]", | |
320 | get_oper_name(source_p), temp_time / 60, | |
321 | name, reason); | |
322 | ilog(L_KLINE, "R %s %d %s %s", | |
323 | get_oper_name(source_p), temp_time / 60, name, reason); | |
324 | sendto_one_notice(source_p, ":Added global %d min. RESV [%s]", | |
325 | temp_time / 60, name); | |
326 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
327 | ":%s BAN R * %s %lu %d %d * :%s", | |
328 | source_p->id, aconf->host, | |
329 | (unsigned long)aconf->created, | |
330 | (int)(aconf->hold - aconf->created), | |
331 | (int)(aconf->lifetime - aconf->created), | |
332 | reason); | |
333 | } | |
334 | else if(temp_time > 0) | |
212380e3 | 335 | { |
e3354945 | 336 | aconf->hold = rb_current_time() + temp_time; |
212380e3 AC |
337 | |
338 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
339 | "%s added temporary %d min. RESV for [%s] [%s]", |
340 | get_oper_name(source_p), temp_time / 60, | |
341 | name, reason); | |
212380e3 | 342 | ilog(L_KLINE, "R %s %d %s %s", |
8bbeb278 | 343 | get_oper_name(source_p), temp_time / 60, name, reason); |
212380e3 | 344 | sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]", |
8bbeb278 | 345 | temp_time / 60, name); |
212380e3 AC |
346 | } |
347 | else | |
00c036b1 AC |
348 | { |
349 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
350 | "%s added RESV for [%s] [%s]", | |
351 | get_oper_name(source_p), name, reason); | |
352 | ilog(L_KLINE, "R %s 0 %s %s", | |
353 | get_oper_name(source_p), name, reason); | |
354 | sendto_one_notice(source_p, ":Added RESV [%s]", name); | |
355 | ||
23959371 | 356 | bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); |
00c036b1 | 357 | } |
dca9e552 JT |
358 | |
359 | rb_dlinkAddAlloc(aconf, &resv_conf_list); | |
330692a1 | 360 | resv_nick_fnc(aconf->host, aconf->passwd, temp_time); |
212380e3 AC |
361 | } |
362 | else | |
8bbeb278 | 363 | sendto_one_notice(source_p, ":You have specified an invalid resv: [%s]", name); |
212380e3 AC |
364 | } |
365 | ||
8bbeb278 | 366 | static void |
212380e3 | 367 | propagate_resv(struct Client *source_p, const char *target, |
8bbeb278 | 368 | int temp_time, const char *name, const char *reason) |
212380e3 AC |
369 | { |
370 | if(!temp_time) | |
371 | { | |
372 | sendto_match_servs(source_p, target, | |
8bbeb278 | 373 | CAP_CLUSTER, NOCAPS, "RESV %s %s :%s", target, name, reason); |
212380e3 | 374 | sendto_match_servs(source_p, target, |
8bbeb278 AC |
375 | CAP_ENCAP, CAP_CLUSTER, |
376 | "ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason); | |
212380e3 AC |
377 | } |
378 | else | |
379 | sendto_match_servs(source_p, target, | |
8bbeb278 AC |
380 | CAP_ENCAP, NOCAPS, |
381 | "ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason); | |
212380e3 AC |
382 | } |
383 | ||
384 | static void | |
8bbeb278 | 385 | cluster_resv(struct Client *source_p, int temp_time, const char *name, const char *reason) |
212380e3 AC |
386 | { |
387 | struct remote_conf *shared_p; | |
5b96d9a6 | 388 | rb_dlink_node *ptr; |
212380e3 | 389 | |
5b96d9a6 | 390 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) |
212380e3 AC |
391 | { |
392 | shared_p = ptr->data; | |
393 | ||
394 | /* old protocol cant handle temps, and we dont really want | |
395 | * to convert them to perm.. --fl | |
396 | */ | |
397 | if(!temp_time) | |
398 | { | |
399 | if(!(shared_p->flags & SHARED_PRESV)) | |
400 | continue; | |
401 | ||
402 | sendto_match_servs(source_p, shared_p->server, | |
8bbeb278 AC |
403 | CAP_CLUSTER, NOCAPS, |
404 | "RESV %s %s :%s", shared_p->server, name, reason); | |
212380e3 | 405 | sendto_match_servs(source_p, shared_p->server, |
8bbeb278 AC |
406 | CAP_ENCAP, CAP_CLUSTER, |
407 | "ENCAP %s RESV 0 %s 0 :%s", | |
408 | shared_p->server, name, reason); | |
212380e3 AC |
409 | } |
410 | else if(shared_p->flags & SHARED_TRESV) | |
411 | sendto_match_servs(source_p, shared_p->server, | |
8bbeb278 AC |
412 | CAP_ENCAP, NOCAPS, |
413 | "ENCAP %s RESV %d %s 0 :%s", | |
414 | shared_p->server, temp_time, name, reason); | |
212380e3 AC |
415 | } |
416 | } | |
417 | ||
418 | ||
419 | /* | |
420 | * mo_unresv() | |
212380e3 AC |
421 | * parv[1] = channel/nick to unforbid |
422 | */ | |
423 | static int | |
428ca87b | 424 | mo_unresv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 425 | { |
dca9e552 JT |
426 | int propagated = 1; |
427 | ||
1ebe6ffc JT |
428 | if(!IsOperResv(source_p)) |
429 | { | |
8bbeb278 | 430 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv"); |
1ebe6ffc JT |
431 | return 0; |
432 | } | |
433 | ||
212380e3 AC |
434 | if((parc == 4) && (irccmp(parv[2], "ON") == 0)) |
435 | { | |
436 | if(!IsOperRemoteBan(source_p)) | |
437 | { | |
438 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 439 | me.name, source_p->name, "remoteban"); |
212380e3 AC |
440 | return 0; |
441 | } | |
442 | ||
8bbeb278 | 443 | propagate_generic(source_p, "UNRESV", parv[3], CAP_CLUSTER, "%s", parv[1]); |
212380e3 AC |
444 | |
445 | if(match(parv[3], me.name) == 0) | |
446 | return 0; | |
dca9e552 JT |
447 | |
448 | propagated = 0; | |
212380e3 | 449 | } |
dca9e552 | 450 | #if 0 |
5b96d9a6 | 451 | else if(rb_dlink_list_length(&cluster_conf_list) > 0) |
8bbeb278 | 452 | cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", parv[1]); |
dca9e552 JT |
453 | #endif |
454 | /* cluster{} moved to remove_resv */ | |
212380e3 | 455 | |
dca9e552 | 456 | remove_resv(source_p, parv[1], propagated); |
212380e3 AC |
457 | return 0; |
458 | } | |
459 | ||
460 | /* ms_unresv() | |
212380e3 AC |
461 | * parv[1] = target server |
462 | * parv[2] = resv to remove | |
463 | */ | |
464 | static int | |
428ca87b | 465 | ms_unresv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 466 | { |
8bbeb278 AC |
467 | /* parv[0] parv[1] parv[2] |
468 | * oper target server resv to remove | |
212380e3 | 469 | */ |
8bbeb278 | 470 | propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER, "%s", parv[2]); |
212380e3 AC |
471 | |
472 | if(!match(parv[1], me.name)) | |
473 | return 0; | |
474 | ||
475 | if(!IsPerson(source_p)) | |
476 | return 0; | |
477 | ||
478 | handle_remote_unresv(source_p, parv[2]); | |
479 | return 0; | |
480 | } | |
481 | ||
482 | static int | |
428ca87b | 483 | me_unresv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
484 | { |
485 | /* name */ | |
486 | if(!IsPerson(source_p)) | |
487 | return 0; | |
488 | ||
489 | handle_remote_unresv(source_p, parv[1]); | |
490 | return 0; | |
491 | } | |
492 | ||
493 | static void | |
494 | handle_remote_unresv(struct Client *source_p, const char *name) | |
495 | { | |
496 | if(!find_shared_conf(source_p->username, source_p->host, | |
8bbeb278 | 497 | source_p->servptr->name, SHARED_UNRESV)) |
212380e3 AC |
498 | return; |
499 | ||
dca9e552 | 500 | remove_resv(source_p, name, 0); |
212380e3 AC |
501 | |
502 | return; | |
503 | } | |
504 | ||
1328da86 | 505 | static void |
dca9e552 | 506 | remove_resv(struct Client *source_p, const char *name, int propagated) |
212380e3 AC |
507 | { |
508 | struct ConfItem *aconf = NULL; | |
dca9e552 | 509 | rb_dlink_node *ptr; |
483987a4 | 510 | time_t now; |
212380e3 AC |
511 | |
512 | if(IsChannelName(name)) | |
513 | { | |
514 | if((aconf = hash_find_resv(name)) == NULL) | |
1328da86 | 515 | { |
dca9e552 | 516 | if(propagated && rb_dlink_list_length(&cluster_conf_list)) |
22204726 | 517 | cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); |
dca9e552 | 518 | |
1328da86 JT |
519 | sendto_one_notice(source_p, ":No RESV for %s", name); |
520 | return; | |
521 | } | |
212380e3 | 522 | |
dca9e552 JT |
523 | if(aconf->lifetime) |
524 | { | |
525 | if(!propagated) | |
526 | { | |
527 | sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name); | |
528 | return; | |
529 | } | |
530 | ptr = rb_dlinkFind(aconf, &prop_bans); | |
531 | if(ptr == NULL) | |
532 | return; | |
533 | sendto_one_notice(source_p, ":RESV for [%s] is removed", name); | |
534 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
535 | "%s has removed the global RESV for: [%s]", | |
536 | get_oper_name(source_p), name); | |
537 | ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); | |
483987a4 JT |
538 | now = rb_current_time(); |
539 | if(aconf->created < now) | |
540 | aconf->created = now; | |
dca9e552 JT |
541 | else |
542 | aconf->created++; | |
543 | aconf->hold = aconf->created; | |
544 | operhash_delete(aconf->info.oper); | |
545 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
546 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
547 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
548 | ":%s BAN R * %s %lu %d %d * :*", | |
549 | source_p->id, aconf->host, | |
550 | (unsigned long)aconf->created, | |
551 | 0, | |
552 | (int)(aconf->lifetime - aconf->created)); | |
483987a4 | 553 | deactivate_conf(aconf, ptr, now); |
dca9e552 JT |
554 | return; |
555 | } | |
556 | else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0) | |
557 | cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); | |
558 | ||
a990586f JT |
559 | sendto_one_notice(source_p, ":RESV for [%s] is removed", name); |
560 | ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); | |
212380e3 | 561 | if(!aconf->hold) |
1a9ea263 | 562 | { |
8bbeb278 | 563 | bandb_del(BANDB_RESV, aconf->host, NULL); |
1a9ea263 JT |
564 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
565 | "%s has removed the RESV for: [%s]", | |
566 | get_oper_name(source_p), name); | |
1a9ea263 | 567 | } |
1328da86 JT |
568 | else |
569 | { | |
1328da86 | 570 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
a990586f | 571 | "%s has removed the temporary RESV for: [%s]", |
8bbeb278 | 572 | get_oper_name(source_p), name); |
1328da86 | 573 | } |
212380e3 | 574 | del_from_resv_hash(name, aconf); |
212380e3 AC |
575 | } |
576 | else | |
577 | { | |
5b96d9a6 | 578 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
212380e3 AC |
579 | { |
580 | aconf = ptr->data; | |
581 | ||
23959371 | 582 | if(irccmp(aconf->host, name)) |
212380e3 AC |
583 | aconf = NULL; |
584 | else | |
585 | break; | |
586 | } | |
587 | ||
588 | if(aconf == NULL) | |
1328da86 | 589 | { |
dca9e552 | 590 | if(propagated && rb_dlink_list_length(&cluster_conf_list)) |
22204726 | 591 | cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); |
dca9e552 | 592 | |
1328da86 JT |
593 | sendto_one_notice(source_p, ":No RESV for %s", name); |
594 | return; | |
595 | } | |
212380e3 | 596 | |
dca9e552 JT |
597 | if(aconf->lifetime) |
598 | { | |
599 | if(!propagated) | |
600 | { | |
601 | sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name); | |
602 | return; | |
603 | } | |
604 | ptr = rb_dlinkFind(aconf, &prop_bans); | |
605 | if(ptr == NULL) | |
606 | return; | |
607 | sendto_one_notice(source_p, ":RESV for [%s] is removed", name); | |
608 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
609 | "%s has removed the global RESV for: [%s]", | |
610 | get_oper_name(source_p), name); | |
611 | ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); | |
483987a4 JT |
612 | now = rb_current_time(); |
613 | if(aconf->created < now) | |
614 | aconf->created = now; | |
dca9e552 JT |
615 | else |
616 | aconf->created++; | |
617 | aconf->hold = aconf->created; | |
618 | operhash_delete(aconf->info.oper); | |
619 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
620 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
621 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
622 | ":%s BAN R * %s %lu %d %d * :*", | |
623 | source_p->id, aconf->host, | |
624 | (unsigned long)aconf->created, | |
625 | 0, | |
626 | (int)(aconf->lifetime - aconf->created)); | |
483987a4 | 627 | deactivate_conf(aconf, ptr, now); |
dca9e552 JT |
628 | return; |
629 | } | |
630 | else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0) | |
631 | cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); | |
632 | ||
5bd874eb JT |
633 | sendto_one_notice(source_p, ":RESV for [%s] is removed", name); |
634 | ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); | |
212380e3 | 635 | if(!aconf->hold) |
5bd874eb | 636 | { |
8bbeb278 | 637 | bandb_del(BANDB_RESV, aconf->host, NULL); |
5bd874eb JT |
638 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
639 | "%s has removed the RESV for: [%s]", | |
640 | get_oper_name(source_p), name); | |
641 | } | |
1328da86 JT |
642 | else |
643 | { | |
1328da86 | 644 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
5bd874eb | 645 | "%s has removed the temporary RESV for: [%s]", |
8bbeb278 | 646 | get_oper_name(source_p), name); |
1328da86 | 647 | } |
212380e3 | 648 | /* already have ptr from the loop above.. */ |
555ac41f | 649 | rb_dlinkDestroy(ptr, &resv_conf_list); |
212380e3 | 650 | } |
1328da86 | 651 | free_conf(aconf); |
212380e3 | 652 | |
1328da86 | 653 | return; |
212380e3 | 654 | } |