2 * ircd-ratbox: A slightly useful ircd.
3 * m_resv.c: Reserves(jupes) a nickname or channel.
5 * Copyright (C) 2001-2002 Hybrid Development Team
6 * Copyright (C) 2002-2005 ircd-ratbox development team
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.
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.
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
35 #include "s_newconf.h"
41 static const char resv_desc
[] =
42 "Provides management of reserved nicknames and channels using (UN)RESV";
44 static void mo_resv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
45 static void ms_resv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
46 static void me_resv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static void mo_unresv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static void ms_unresv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
49 static void me_unresv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
51 struct Message resv_msgtab
= {
53 {mg_ignore
, mg_not_oper
, {ms_resv
, 4}, {ms_resv
, 4}, {me_resv
, 5}, {mo_resv
, 3}}
56 struct Message unresv_msgtab
= {
58 {mg_ignore
, mg_not_oper
, {ms_unresv
, 3}, {ms_unresv
, 3}, {me_unresv
, 2}, {mo_unresv
, 2}}
61 mapi_clist_av1 resv_clist
[] = { &resv_msgtab
, &unresv_msgtab
, NULL
};
63 DECLARE_MODULE_AV2(resv
, NULL
, NULL
, resv_clist
, NULL
, NULL
, NULL
, NULL
, resv_desc
);
65 static void parse_resv(struct Client
*source_p
, const char *name
,
66 const char *reason
, int temp_time
, int propagated
);
67 static void propagate_resv(struct Client
*source_p
, const char *target
,
68 int temp_time
, const char *name
, const char *reason
);
69 static void cluster_resv(struct Client
*source_p
, int temp_time
,
70 const char *name
, const char *reason
);
72 static void remove_resv(struct Client
*source_p
, const char *name
, int propagated
);
76 * parv[1] = channel/nick to forbid
80 mo_resv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
84 const char *target_server
= NULL
;
87 int propagated
= ConfigFileEntry
.use_propagated_bans
;
89 if(!IsOperResv(source_p
))
91 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
95 /* RESV [time] <name> [ON <server>] :<reason> */
97 if((temp_time
= valid_temp_time(parv
[loc
])) >= 0)
99 /* we just set temp_time to -1! */
106 if((parc
>= loc
+ 2) && (irccmp(parv
[loc
], "ON") == 0))
108 if(!IsOperRemoteBan(source_p
))
110 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
111 me
.name
, source_p
->name
, "remoteban");
115 target_server
= parv
[loc
+ 1];
118 /* Set as local-only. */
122 if(parc
<= loc
|| EmptyString(parv
[loc
]))
124 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "RESV");
133 propagate_resv(source_p
, target_server
, temp_time
, name
, reason
);
135 if(match(target_server
, me
.name
) == 0)
138 else if(!propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
139 cluster_resv(source_p
, temp_time
, name
, reason
);
141 if(propagated
&& temp_time
== 0)
143 sendto_one_notice(source_p
, ":Cannot set a permanent global ban");
147 parse_resv(source_p
, name
, reason
, temp_time
, propagated
);
151 * parv[1] = target server
152 * parv[2] = channel/nick to forbid
156 ms_resv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
158 /* parv[0] parv[1] parv[2] parv[3]
159 * oper target server resv reason
161 propagate_resv(source_p
, parv
[1], 0, parv
[2], parv
[3]);
163 if(!match(parv
[1], me
.name
))
166 if(!IsPerson(source_p
))
169 parse_resv(source_p
, parv
[2], parv
[3], 0, 0);
173 me_resv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
175 /* time name 0 :reason */
176 if(!IsPerson(source_p
))
179 parse_resv(source_p
, parv
[2], parv
[4], atoi(parv
[1]), 0);
184 * inputs - source_p if error messages wanted
188 * side effects - will parse the resv and create it if valid
191 parse_resv(struct Client
*source_p
, const char *name
, const char *reason
, int temp_time
, int propagated
)
193 struct ConfItem
*aconf
;
195 if(IsChannelName(name
))
197 if(hash_find_resv(name
))
199 sendto_one_notice(source_p
,
200 ":A RESV has already been placed on channel: %s", name
);
204 if(strlen(name
) > CHANNELLEN
)
206 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
211 aconf
->status
= CONF_RESV_CHANNEL
;
213 aconf
->created
= rb_current_time();
214 aconf
->host
= rb_strdup(name
);
215 aconf
->passwd
= rb_strdup(reason
);
216 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
220 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
221 aconf
->hold
= rb_current_time() + temp_time
;
222 aconf
->lifetime
= aconf
->hold
;
223 replace_old_ban(aconf
);
224 rb_dlinkAddAlloc(aconf
, &prop_bans
);
226 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
227 "%s added global %d min. RESV for [%s] [%s]",
228 get_oper_name(source_p
), temp_time
/ 60,
230 ilog(L_KLINE
, "R %s %d %s %s",
231 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
232 sendto_one_notice(source_p
, ":Added global %d min. RESV [%s]",
233 temp_time
/ 60, name
);
234 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
235 ":%s BAN R * %s %lu %d %d * :%s",
236 source_p
->id
, aconf
->host
,
237 (unsigned long)aconf
->created
,
238 (int)(aconf
->hold
- aconf
->created
),
239 (int)(aconf
->lifetime
- aconf
->created
),
242 else if(temp_time
> 0)
244 aconf
->hold
= rb_current_time() + temp_time
;
246 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
247 "%s added temporary %d min. RESV for [%s] [%s]",
248 get_oper_name(source_p
), temp_time
/ 60,
250 ilog(L_KLINE
, "R %s %d %s %s",
251 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
252 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
253 temp_time
/ 60, name
);
257 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
258 "%s added RESV for [%s] [%s]",
259 get_oper_name(source_p
), name
, reason
);
260 ilog(L_KLINE
, "R %s 0 %s %s",
261 get_oper_name(source_p
), name
, reason
);
262 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
264 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
267 add_to_resv_hash(aconf
->host
, aconf
);
268 resv_chan_forcepart(aconf
->host
, aconf
->passwd
, temp_time
);
270 else if(clean_resv_nick(name
))
272 if(strlen(name
) > NICKLEN
* 2)
274 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
278 if(!valid_wild_card_simple(name
))
280 sendto_one_notice(source_p
,
281 ":Please include at least %d non-wildcard "
282 "characters with the resv",
283 ConfigFileEntry
.min_nonwildcard_simple
);
287 if(find_nick_resv_mask(name
))
289 sendto_one_notice(source_p
,
290 ":A RESV has already been placed on nick: %s", name
);
295 aconf
->status
= CONF_RESV_NICK
;
297 aconf
->created
= rb_current_time();
298 aconf
->host
= rb_strdup(name
);
299 aconf
->passwd
= rb_strdup(reason
);
300 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
304 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
305 aconf
->hold
= rb_current_time() + temp_time
;
306 aconf
->lifetime
= aconf
->hold
;
307 replace_old_ban(aconf
);
308 rb_dlinkAddAlloc(aconf
, &prop_bans
);
310 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
311 "%s added global %d min. RESV for [%s] [%s]",
312 get_oper_name(source_p
), temp_time
/ 60,
314 ilog(L_KLINE
, "R %s %d %s %s",
315 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
316 sendto_one_notice(source_p
, ":Added global %d min. RESV [%s]",
317 temp_time
/ 60, name
);
318 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
319 ":%s BAN R * %s %lu %d %d * :%s",
320 source_p
->id
, aconf
->host
,
321 (unsigned long)aconf
->created
,
322 (int)(aconf
->hold
- aconf
->created
),
323 (int)(aconf
->lifetime
- aconf
->created
),
326 else if(temp_time
> 0)
328 aconf
->hold
= rb_current_time() + temp_time
;
330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
331 "%s added temporary %d min. RESV for [%s] [%s]",
332 get_oper_name(source_p
), temp_time
/ 60,
334 ilog(L_KLINE
, "R %s %d %s %s",
335 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
336 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
337 temp_time
/ 60, name
);
341 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
342 "%s added RESV for [%s] [%s]",
343 get_oper_name(source_p
), name
, reason
);
344 ilog(L_KLINE
, "R %s 0 %s %s",
345 get_oper_name(source_p
), name
, reason
);
346 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
348 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
351 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
352 resv_nick_fnc(aconf
->host
, aconf
->passwd
, temp_time
);
355 sendto_one_notice(source_p
, ":You have specified an invalid resv: [%s]", name
);
359 propagate_resv(struct Client
*source_p
, const char *target
,
360 int temp_time
, const char *name
, const char *reason
)
364 sendto_match_servs(source_p
, target
,
365 CAP_CLUSTER
, NOCAPS
, "RESV %s %s :%s", target
, name
, reason
);
366 sendto_match_servs(source_p
, target
,
367 CAP_ENCAP
, CAP_CLUSTER
,
368 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
371 sendto_match_servs(source_p
, target
,
373 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
377 cluster_resv(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
379 struct remote_conf
*shared_p
;
382 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
384 shared_p
= ptr
->data
;
386 /* old protocol cant handle temps, and we dont really want
387 * to convert them to perm.. --fl
391 if(!(shared_p
->flags
& SHARED_PRESV
))
394 sendto_match_servs(source_p
, shared_p
->server
,
396 "RESV %s %s :%s", shared_p
->server
, name
, reason
);
397 sendto_match_servs(source_p
, shared_p
->server
,
398 CAP_ENCAP
, CAP_CLUSTER
,
399 "ENCAP %s RESV 0 %s 0 :%s",
400 shared_p
->server
, name
, reason
);
402 else if(shared_p
->flags
& SHARED_TRESV
)
403 sendto_match_servs(source_p
, shared_p
->server
,
405 "ENCAP %s RESV %d %s 0 :%s",
406 shared_p
->server
, temp_time
, name
, reason
);
413 * parv[1] = channel/nick to unforbid
416 mo_unresv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
420 if(!IsOperResv(source_p
))
422 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
426 if((parc
== 4) && (irccmp(parv
[2], "ON") == 0))
428 if(!IsOperRemoteBan(source_p
))
430 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
431 me
.name
, source_p
->name
, "remoteban");
435 propagate_generic(source_p
, "UNRESV", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
437 if(match(parv
[3], me
.name
) == 0)
443 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
444 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", parv
[1]);
446 /* cluster{} moved to remove_resv */
448 remove_resv(source_p
, parv
[1], propagated
);
452 * parv[1] = target server
453 * parv[2] = resv to remove
456 ms_unresv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
458 /* parv[0] parv[1] parv[2]
459 * oper target server resv to remove
461 propagate_generic(source_p
, "UNRESV", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
463 if(!match(parv
[1], me
.name
))
466 if(!IsPerson(source_p
))
469 remove_resv(source_p
, parv
[2], 0);
473 me_unresv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
476 if(!IsPerson(source_p
))
479 remove_resv(source_p
, parv
[1], 0);
483 remove_resv(struct Client
*source_p
, const char *name
, int propagated
)
485 struct ConfItem
*aconf
= NULL
;
489 if(IsChannelName(name
))
491 if((aconf
= hash_find_resv(name
)) == NULL
)
493 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
494 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
496 sendto_one_notice(source_p
, ":No RESV for %s", name
);
504 sendto_one_notice(source_p
, ":Cannot remove global RESV %s on specific servers", name
);
507 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
510 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
511 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
512 "%s has removed the global RESV for: [%s]",
513 get_oper_name(source_p
), name
);
514 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
515 now
= rb_current_time();
516 if(aconf
->created
< now
)
517 aconf
->created
= now
;
520 aconf
->hold
= aconf
->created
;
521 operhash_delete(aconf
->info
.oper
);
522 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
523 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
524 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
525 ":%s BAN R * %s %lu %d %d * :*",
526 source_p
->id
, aconf
->host
,
527 (unsigned long)aconf
->created
,
529 (int)(aconf
->lifetime
- aconf
->created
));
530 deactivate_conf(aconf
, ptr
, now
);
533 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
534 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
536 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
537 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
540 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
541 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
542 "%s has removed the RESV for: [%s]",
543 get_oper_name(source_p
), name
);
547 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
548 "%s has removed the temporary RESV for: [%s]",
549 get_oper_name(source_p
), name
);
551 del_from_resv_hash(name
, aconf
);
555 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
559 if(irccmp(aconf
->host
, name
))
567 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
568 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
570 sendto_one_notice(source_p
, ":No RESV for %s", name
);
578 sendto_one_notice(source_p
, ":Cannot remove global RESV %s on specific servers", name
);
581 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
584 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
585 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
586 "%s has removed the global RESV for: [%s]",
587 get_oper_name(source_p
), name
);
588 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
589 now
= rb_current_time();
590 if(aconf
->created
< now
)
591 aconf
->created
= now
;
594 aconf
->hold
= aconf
->created
;
595 operhash_delete(aconf
->info
.oper
);
596 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
597 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
598 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
599 ":%s BAN R * %s %lu %d %d * :*",
600 source_p
->id
, aconf
->host
,
601 (unsigned long)aconf
->created
,
603 (int)(aconf
->lifetime
- aconf
->created
));
604 deactivate_conf(aconf
, ptr
, now
);
607 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
608 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
610 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
611 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
614 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
615 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
616 "%s has removed the RESV for: [%s]",
617 get_oper_name(source_p
), name
);
621 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
622 "%s has removed the temporary RESV for: [%s]",
623 get_oper_name(source_p
), name
);
625 /* already have ptr from the loop above.. */
626 rb_dlinkDestroy(ptr
, &resv_conf_list
);