]>
jfr.im git - irc/rqf/shadowircd.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 ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
50 struct Message ban_msgtab
= {
51 "BAN", 0, 0, 0, MFLG_SLOW
,
52 {mg_unreg
, mg_ignore
, {ms_ban
, 9}, {ms_ban
, 9}, mg_ignore
, mg_ignore
}
55 mapi_clist_av1 ban_clist
[] = { &ban_msgtab
, NULL
};
56 DECLARE_MODULE_AV1(ban
, NULL
, NULL
, ban_clist
, NULL
, NULL
, "$Revision: 1349 $");
61 * parv[2] - username mask or *
62 * parv[3] - hostname mask
63 * parv[4] - creation TS
64 * parv[5] - duration (relative to creation)
65 * parv[6] - lifetime (relative to creation)
67 * parv[8] - reason (possibly with |operreason)
70 ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
73 struct ConfItem
*aconf
;
75 const char *oper
, *stype
;
76 time_t created
, hold
, lifetime
;
81 if (strlen(parv
[1]) != 1)
83 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
84 "Unknown BAN type %s from %s",
85 parv
[1], source_p
->name
);
99 ntype
= IsChannelName(parv
[3]) ? CONF_RESV_CHANNEL
:
104 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
105 "Unknown BAN type %s from %s",
106 parv
[1], source_p
->name
);
109 created
= atol(parv
[4]);
110 hold
= created
+ atoi(parv
[5]);
111 lifetime
= created
+ atoi(parv
[6]);
112 if (!strcmp(parv
[7], "*"))
113 oper
= IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
);
116 ptr
= find_prop_ban(ntype
, parv
[2], parv
[3]);
120 if (aconf
->created
> created
||
121 (aconf
->created
== created
&&
122 aconf
->lifetime
>= lifetime
))
124 if (IsPerson(source_p
))
125 sendto_one_notice(source_p
,
126 ":Your %s [%s%s%s] has been superseded",
128 aconf
->user
? aconf
->user
: "",
129 aconf
->user
? "@" : "",
133 act
= !(aconf
->status
& CONF_ILLEGAL
) || (hold
!= created
&&
134 hold
> rb_current_time());
135 if (lifetime
> aconf
->lifetime
)
136 aconf
->lifetime
= lifetime
;
137 /* already expired, hmm */
138 if (aconf
->lifetime
<= rb_current_time())
140 deactivate_conf(aconf
, ptr
);
141 rb_free(aconf
->user
);
143 rb_free(aconf
->host
);
145 operhash_delete(aconf
->info
.oper
);
146 aconf
->info
.oper
= NULL
;
147 rb_free(aconf
->passwd
);
148 aconf
->passwd
= NULL
;
149 rb_free(aconf
->spasswd
);
150 aconf
->spasswd
= NULL
;
155 aconf
->status
= CONF_ILLEGAL
| ntype
;
156 aconf
->lifetime
= lifetime
;
157 rb_dlinkAddAlloc(aconf
, &prop_bans
);
158 act
= hold
!= created
&& hold
> rb_current_time();
160 aconf
->flags
&= ~CONF_FLAGS_MYOPER
;
161 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
162 aconf
->user
= ntype
== CONF_KILL
? rb_strdup(parv
[2]) : NULL
;
163 aconf
->host
= rb_strdup(parv
[3]);
164 aconf
->info
.oper
= operhash_add(oper
);
165 aconf
->created
= created
;
167 if (ntype
!= CONF_KILL
|| (p
= strchr(parv
[parc
- 1], '|')) == NULL
)
168 aconf
->passwd
= rb_strdup(parv
[parc
- 1]);
171 aconf
->passwd
= rb_strndup(parv
[parc
- 1], p
- parv
[parc
- 1] + 1);
172 aconf
->spasswd
= rb_strdup(p
+ 1);
177 valid
= valid_wild_card(aconf
->user
, aconf
->host
);
179 case CONF_RESV_CHANNEL
:
183 valid
= valid_wild_card_simple(aconf
->host
);
186 if (act
&& hold
!= created
&& !valid
)
188 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
189 "Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters",
190 (hold
- rb_current_time()) / 60,
192 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
193 strcmp(parv
[7], "*") ? " on behalf of " : "",
194 strcmp(parv
[7], "*") ? parv
[7] : "",
195 aconf
->user
? aconf
->user
: "",
196 aconf
->user
? "@" : "",
198 if(IsPerson(source_p
))
199 sendto_one_notice(source_p
,
200 ":Your %s [%s%s%s] has too few non-wildcard characters",
202 aconf
->user
? aconf
->user
: "",
203 aconf
->user
? "@" : "",
205 /* Propagate it, but do not apply it locally. */
207 else if (act
&& hold
!= created
)
209 /* Keep the notices in sync with modules/m_kline.c etc. */
210 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
211 "%s added global %d min. %s%s%s for [%s%s%s] [%s]",
212 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
213 (hold
- rb_current_time()) / 60,
215 strcmp(parv
[7], "*") ? " from " : "",
216 strcmp(parv
[7], "*") ? parv
[7] : "",
217 aconf
->user
? aconf
->user
: "",
218 aconf
->user
? "@" : "",
221 ilog(L_KLINE
, "%s %s %d %s%s%s %s", parv
[1],
222 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
223 (hold
- rb_current_time()) / 60,
224 aconf
->user
? aconf
->user
: "",
225 aconf
->user
? " " : "",
228 aconf
->status
&= ~CONF_ILLEGAL
;
232 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
233 "%s has removed the global %s for: [%s%s%s]%s%s",
234 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
236 aconf
->user
? aconf
->user
: "",
237 aconf
->user
? "@" : "",
239 strcmp(parv
[7], "*") ? " on behalf of " : "",
240 strcmp(parv
[7], "*") ? parv
[7] : "");
241 ilog(L_KLINE
, "U%s %s %s%s %s", parv
[1],
242 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
243 aconf
->user
? aconf
->user
: "",
244 aconf
->user
? " " : "",
250 if (aconf
->status
& CONF_ILLEGAL
)
251 remove_reject_mask(aconf
->user
, aconf
->host
);
254 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
255 if(ConfigFileEntry
.kline_delay
||
256 (IsServer(source_p
) &&
257 !HasSentEob(source_p
)))
259 if(kline_queued
== 0)
261 rb_event_addonce("check_klines", check_klines_event
, NULL
,
262 ConfigFileEntry
.kline_delay
);
271 if (aconf
->status
& CONF_ILLEGAL
)
272 remove_reject_mask(aconf
->host
, NULL
);
275 rb_dlinkAddAlloc(aconf
, &xline_conf_list
);
279 case CONF_RESV_CHANNEL
:
280 if (!(aconf
->status
& CONF_ILLEGAL
))
282 add_to_resv_hash(aconf
->host
, aconf
);
283 resv_chan_forcepart(aconf
->host
, aconf
->passwd
, hold
- rb_current_time());
287 if (!(aconf
->status
& CONF_ILLEGAL
))
288 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
291 sendto_server(client_p
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
292 ":%s BAN %s %s %s %s %s %s %s :%s",