]>
jfr.im git - solanum.git/blob - modules/core/m_ban.c
2 * charybdis: An advanced ircd.
3 * m_ban.c: Propagates network bans across servers.
5 * Copyright (C) 2010 Jilles Tjoelker
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
39 #include "s_newconf.h"
48 static int m_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
49 static int ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
51 struct Message ban_msgtab
= {
52 "BAN", 0, 0, 0, MFLG_SLOW
,
53 {mg_unreg
, {m_ban
, 0}, {ms_ban
, 9}, {ms_ban
, 9}, mg_ignore
, {m_ban
, 0}}
56 mapi_clist_av1 ban_clist
[] = { &ban_msgtab
, NULL
};
57 DECLARE_MODULE_AV1(ban
, NULL
, NULL
, ban_clist
, NULL
, NULL
, "$Revision: 1349 $");
60 m_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
62 sendto_one_notice(source_p
, ":The BAN command is not user-accessible.");
63 sendto_one_notice(source_p
, ":To ban a user from a channel, see /QUOTE HELP CMODE");
65 sendto_one_notice(source_p
, ":To ban a user from a server or from the network, see /QUOTE HELP KLINE");
72 * parv[2] - username mask or *
73 * parv[3] - hostname mask
74 * parv[4] - creation TS
75 * parv[5] - duration (relative to creation)
76 * parv[6] - lifetime (relative to creation)
78 * parv[8] - reason (possibly with |operreason)
81 ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
84 struct ConfItem
*aconf
;
86 const char *oper
, *stype
;
87 time_t created
, hold
, lifetime
;
92 if (strlen(parv
[1]) != 1)
94 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
95 "Unknown BAN type %s from %s",
96 parv
[1], source_p
->name
);
110 ntype
= IsChannelName(parv
[3]) ? CONF_RESV_CHANNEL
:
115 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
116 "Unknown BAN type %s from %s",
117 parv
[1], source_p
->name
);
120 created
= atol(parv
[4]);
121 hold
= created
+ atoi(parv
[5]);
122 lifetime
= created
+ atoi(parv
[6]);
123 if (!strcmp(parv
[7], "*"))
124 oper
= IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
);
127 ptr
= find_prop_ban(ntype
, parv
[2], parv
[3]);
130 /* We already know about this ban mask. */
132 if (aconf
->created
> created
||
133 (aconf
->created
== created
&&
134 aconf
->lifetime
>= lifetime
))
136 if (IsPerson(source_p
))
137 sendto_one_notice(source_p
,
138 ":Your %s [%s%s%s] has been superseded",
140 aconf
->user
? aconf
->user
: "",
141 aconf
->user
? "@" : "",
145 /* act indicates if something happened (from the oper's
146 * point of view). This is the case if the ban was
147 * previously active (not deleted) or if the new ban
148 * is not a removal and not already expired.
150 act
= !(aconf
->status
& CONF_ILLEGAL
) || (hold
!= created
&&
151 hold
> rb_current_time());
152 if (lifetime
> aconf
->lifetime
)
153 aconf
->lifetime
= lifetime
;
154 /* already expired, hmm */
155 if (aconf
->lifetime
<= rb_current_time())
157 /* Deactivate, it will be reactivated later if appropriate. */
158 deactivate_conf(aconf
, ptr
);
159 rb_free(aconf
->user
);
161 rb_free(aconf
->host
);
163 operhash_delete(aconf
->info
.oper
);
164 aconf
->info
.oper
= NULL
;
165 rb_free(aconf
->passwd
);
166 aconf
->passwd
= NULL
;
167 rb_free(aconf
->spasswd
);
168 aconf
->spasswd
= NULL
;
174 aconf
->status
= CONF_ILLEGAL
| ntype
;
175 aconf
->lifetime
= lifetime
;
176 rb_dlinkAddAlloc(aconf
, &prop_bans
);
177 act
= hold
!= created
&& hold
> rb_current_time();
179 aconf
->flags
&= ~CONF_FLAGS_MYOPER
;
180 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
181 aconf
->user
= ntype
== CONF_KILL
? rb_strdup(parv
[2]) : NULL
;
182 aconf
->host
= rb_strdup(parv
[3]);
183 aconf
->info
.oper
= operhash_add(oper
);
184 aconf
->created
= created
;
186 if (ntype
!= CONF_KILL
|| (p
= strchr(parv
[parc
- 1], '|')) == NULL
)
187 aconf
->passwd
= rb_strdup(parv
[parc
- 1]);
190 aconf
->passwd
= rb_strndup(parv
[parc
- 1], p
- parv
[parc
- 1] + 1);
191 aconf
->spasswd
= rb_strdup(p
+ 1);
193 /* The ban is fully filled in and in the prop_bans list
194 * but still deactivated. Now determine if it should be activated
195 * and send the server notices.
197 /* We only reject *@* and the like here.
198 * Otherwise malformed bans are fairly harmless and can be removed.
203 valid
= valid_wild_card(aconf
->user
, aconf
->host
);
205 case CONF_RESV_CHANNEL
:
209 valid
= valid_wild_card_simple(aconf
->host
);
212 if (act
&& hold
!= created
&& !valid
)
214 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
215 "Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters",
216 (int)((hold
- rb_current_time()) / 60),
218 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
219 strcmp(parv
[7], "*") ? " on behalf of " : "",
220 strcmp(parv
[7], "*") ? parv
[7] : "",
221 aconf
->user
? aconf
->user
: "",
222 aconf
->user
? "@" : "",
224 if(IsPerson(source_p
))
225 sendto_one_notice(source_p
,
226 ":Your %s [%s%s%s] has too few non-wildcard characters",
228 aconf
->user
? aconf
->user
: "",
229 aconf
->user
? "@" : "",
231 /* Propagate it, but do not apply it locally. */
233 else if (act
&& hold
!= created
)
235 /* Keep the notices in sync with modules/m_kline.c etc. */
236 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
237 "%s added global %d min. %s%s%s for [%s%s%s] [%s]",
238 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
239 (int)((hold
- rb_current_time()) / 60),
241 strcmp(parv
[7], "*") ? " from " : "",
242 strcmp(parv
[7], "*") ? parv
[7] : "",
243 aconf
->user
? aconf
->user
: "",
244 aconf
->user
? "@" : "",
247 ilog(L_KLINE
, "%s %s %d %s%s%s %s", parv
[1],
248 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
249 (int)((hold
- rb_current_time()) / 60),
250 aconf
->user
? aconf
->user
: "",
251 aconf
->user
? " " : "",
254 aconf
->status
&= ~CONF_ILLEGAL
;
258 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
259 "%s has removed the global %s for: [%s%s%s]%s%s",
260 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
262 aconf
->user
? aconf
->user
: "",
263 aconf
->user
? "@" : "",
265 strcmp(parv
[7], "*") ? " on behalf of " : "",
266 strcmp(parv
[7], "*") ? parv
[7] : "");
267 ilog(L_KLINE
, "U%s %s %s%s %s", parv
[1],
268 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
269 aconf
->user
? aconf
->user
: "",
270 aconf
->user
? " " : "",
273 /* If CONF_ILLEGAL is still set at this point, remove entries from the
274 * reject cache (for klines and xlines).
275 * If CONF_ILLEGAL is not set, add the ban to the type-specific data
276 * structure and take action on matched clients/channels.
281 if (aconf
->status
& CONF_ILLEGAL
)
282 remove_reject_mask(aconf
->user
, aconf
->host
);
285 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
286 if(ConfigFileEntry
.kline_delay
||
287 (IsServer(source_p
) &&
288 !HasSentEob(source_p
)))
290 if(kline_queued
== 0)
292 rb_event_addonce("check_klines", check_klines_event
, NULL
,
293 ConfigFileEntry
.kline_delay
);
302 if (aconf
->status
& CONF_ILLEGAL
)
303 remove_reject_mask(aconf
->host
, NULL
);
306 rb_dlinkAddAlloc(aconf
, &xline_conf_list
);
310 case CONF_RESV_CHANNEL
:
311 if (!(aconf
->status
& CONF_ILLEGAL
))
313 add_to_resv_hash(aconf
->host
, aconf
);
314 resv_chan_forcepart(aconf
->host
, aconf
->passwd
, hold
- rb_current_time());
318 if (!(aconf
->status
& CONF_ILLEGAL
))
319 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
322 sendto_server(client_p
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
323 ":%s BAN %s %s %s %s %s %s %s :%s",