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