]>
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.
38 #include "s_newconf.h"
47 static int ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
49 struct Message ban_msgtab
= {
50 "BAN", 0, 0, 0, MFLG_SLOW
,
51 {mg_unreg
, mg_ignore
, {ms_ban
, 9}, {ms_ban
, 9}, mg_ignore
, mg_ignore
}
54 mapi_clist_av1 ban_clist
[] = { &ban_msgtab
, NULL
};
55 DECLARE_MODULE_AV1(ban
, NULL
, NULL
, ban_clist
, NULL
, NULL
, "$Revision: 1349 $");
60 * parv[2] - username mask or *
61 * parv[3] - hostname mask
62 * parv[4] - creation TS
63 * parv[5] - duration (relative to creation)
64 * parv[6] - lifetime (relative to creation)
66 * parv[8] - reason (possibly with |operreason)
69 ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
72 struct ConfItem
*aconf
;
74 const char *oper
, *stype
;
75 time_t created
, hold
, lifetime
;
79 if (strlen(parv
[1]) != 1)
81 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
82 "Unknown BAN type %s from %s",
83 parv
[1], source_p
->name
);
97 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
98 "Unknown BAN type %s from %s",
99 parv
[1], source_p
->name
);
102 created
= atol(parv
[4]);
103 hold
= created
+ atoi(parv
[5]);
104 lifetime
= created
+ atoi(parv
[6]);
105 if (!strcmp(parv
[7], "*"))
106 oper
= IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
);
109 ptr
= find_prop_ban(ntype
, parv
[2], parv
[3]);
113 if (aconf
->created
> created
||
114 (aconf
->created
== created
&&
115 aconf
->lifetime
>= lifetime
))
117 if (IsPerson(source_p
))
118 sendto_one_notice(source_p
,
119 ":Your %s [%s%s%s] has been superseded",
121 aconf
->user
? aconf
->user
: "",
122 aconf
->user
? "@" : "",
126 act
= !(aconf
->status
& CONF_ILLEGAL
) || (hold
!= created
&&
127 hold
> rb_current_time());
128 if (lifetime
> aconf
->lifetime
)
129 aconf
->lifetime
= lifetime
;
130 /* already expired, hmm */
131 if (aconf
->lifetime
<= rb_current_time())
133 deactivate_conf(aconf
, ptr
);
134 rb_free(aconf
->user
);
136 rb_free(aconf
->host
);
138 operhash_delete(aconf
->info
.oper
);
139 aconf
->info
.oper
= NULL
;
140 rb_free(aconf
->passwd
);
141 aconf
->passwd
= NULL
;
142 rb_free(aconf
->spasswd
);
143 aconf
->spasswd
= NULL
;
148 aconf
->status
= CONF_ILLEGAL
| ntype
;
149 aconf
->lifetime
= lifetime
;
150 rb_dlinkAddAlloc(aconf
, &prop_bans
);
151 act
= hold
!= created
&& hold
> rb_current_time();
153 aconf
->flags
&= ~CONF_FLAGS_MYOPER
;
154 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
155 aconf
->user
= ntype
== CONF_KILL
? rb_strdup(parv
[2]) : NULL
;
156 aconf
->host
= rb_strdup(parv
[3]);
157 aconf
->info
.oper
= operhash_add(oper
);
158 aconf
->created
= created
;
160 p
= strchr(parv
[parc
- 1], '|');
162 aconf
->passwd
= rb_strdup(parv
[parc
- 1]);
165 aconf
->passwd
= rb_strndup(parv
[parc
- 1], p
- parv
[parc
- 1] + 1);
166 aconf
->spasswd
= rb_strdup(p
+ 1);
168 if (act
&& hold
!= created
&&
169 !(ntype
== CONF_KILL
?
170 valid_wild_card(aconf
->user
, aconf
->host
) :
171 valid_wild_card_simple(aconf
->host
)))
173 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
174 "Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters",
175 (hold
- rb_current_time()) / 60,
177 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
178 strcmp(parv
[7], "*") ? " on behalf of " : "",
179 strcmp(parv
[7], "*") ? parv
[7] : "",
180 aconf
->user
? aconf
->user
: "",
181 aconf
->user
? "@" : "",
183 if(IsPerson(source_p
))
184 sendto_one_notice(source_p
,
185 ":Your %s [%s%s%s] has too few non-wildcard characters",
187 aconf
->user
? aconf
->user
: "",
188 aconf
->user
? "@" : "",
190 /* Propagate it, but do not apply it locally. */
192 else if (act
&& hold
!= created
)
194 /* Keep the notices in sync with modules/m_kline.c etc. */
195 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
196 "%s added global %d min. %s%s%s for [%s%s%s] [%s]",
197 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
198 (hold
- rb_current_time()) / 60,
200 strcmp(parv
[7], "*") ? " from " : "",
201 strcmp(parv
[7], "*") ? parv
[7] : "",
202 aconf
->user
? aconf
->user
: "",
203 aconf
->user
? "@" : "",
206 ilog(L_KLINE
, "%s %s %d %s%s%s %s", parv
[1],
207 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
208 (hold
- rb_current_time()) / 60,
209 aconf
->user
? aconf
->user
: "",
210 aconf
->user
? " " : "",
213 aconf
->status
&= ~CONF_ILLEGAL
;
217 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
218 "%s has removed the global %s for: [%s%s%s]%s%s",
219 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
221 aconf
->user
? aconf
->user
: "",
222 aconf
->user
? "@" : "",
224 strcmp(parv
[7], "*") ? " on behalf of " : "",
225 strcmp(parv
[7], "*") ? parv
[7] : "");
226 ilog(L_KLINE
, "U%s %s %s%s %s", parv
[1],
227 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
228 aconf
->user
? aconf
->user
: "",
229 aconf
->user
? " " : "",
235 if (aconf
->status
& CONF_ILLEGAL
)
236 remove_reject_mask(aconf
->user
, aconf
->host
);
239 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
240 if(ConfigFileEntry
.kline_delay
||
241 (IsServer(source_p
) &&
242 !HasSentEob(source_p
)))
244 if(kline_queued
== 0)
246 rb_event_addonce("check_klines", check_klines_event
, NULL
,
247 ConfigFileEntry
.kline_delay
);
256 if (aconf
->status
& CONF_ILLEGAL
)
257 remove_reject_mask(aconf
->host
, NULL
);
260 rb_dlinkAddAlloc(aconf
, &xline_conf_list
);
265 sendto_server(client_p
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
266 ":%s BAN %s %s %s %s %s %s %s :%s",