]>
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.
46 static int ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
48 struct Message ban_msgtab
= {
49 "BAN", 0, 0, 0, MFLG_SLOW
,
50 {mg_unreg
, mg_ignore
, {ms_ban
, 9}, {ms_ban
, 9}, mg_ignore
, mg_ignore
}
53 mapi_clist_av1 ban_clist
[] = { &ban_msgtab
, NULL
};
54 DECLARE_MODULE_AV1(ban
, NULL
, NULL
, ban_clist
, NULL
, NULL
, "$Revision: 1349 $");
59 * parv[2] - username mask or *
60 * parv[3] - hostname mask
61 * parv[4] - creation TS
62 * parv[5] - duration (relative to creation)
63 * parv[6] - lifetime (relative to creation)
65 * parv[8] - reason (possibly with |operreason)
68 ms_ban(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
71 struct ConfItem
*aconf
;
73 const char *oper
, *stype
;
74 time_t created
, hold
, lifetime
;
78 if (strlen(parv
[1]) != 1)
80 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
81 "Unknown BAN type %s from %s",
82 parv
[1], source_p
->name
);
92 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
93 "Unknown BAN type %s from %s",
94 parv
[1], source_p
->name
);
97 created
= atol(parv
[4]);
98 hold
= created
+ atoi(parv
[5]);
99 lifetime
= created
+ atoi(parv
[6]);
100 if (!strcmp(parv
[7], "*"))
101 oper
= IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
);
104 ptr
= find_prop_ban(ntype
, parv
[2], parv
[3]);
108 if (aconf
->created
> created
||
109 (aconf
->created
== created
&&
110 aconf
->lifetime
>= lifetime
))
112 if (IsPerson(source_p
))
113 sendto_one_notice(source_p
,
114 ":Your %s [%s%s%s] has been superseded",
116 aconf
->user
? aconf
->user
: "",
117 aconf
->user
? "@" : "",
121 act
= !(aconf
->status
& CONF_ILLEGAL
) || (hold
!= created
&&
122 hold
> rb_current_time());
123 if (lifetime
> aconf
->lifetime
)
124 aconf
->lifetime
= lifetime
;
125 /* already expired, hmm */
126 if (aconf
->lifetime
<= rb_current_time())
128 deactivate_conf(aconf
, ptr
);
129 rb_free(aconf
->user
);
131 rb_free(aconf
->host
);
133 operhash_delete(aconf
->info
.oper
);
134 aconf
->info
.oper
= NULL
;
135 rb_free(aconf
->passwd
);
136 aconf
->passwd
= NULL
;
137 rb_free(aconf
->spasswd
);
138 aconf
->spasswd
= NULL
;
143 aconf
->status
= CONF_ILLEGAL
| ntype
;
144 aconf
->lifetime
= lifetime
;
145 rb_dlinkAddAlloc(aconf
, &prop_bans
);
146 act
= hold
!= created
&& hold
> rb_current_time();
148 aconf
->flags
&= ~CONF_FLAGS_MYOPER
;
149 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
150 aconf
->user
= ntype
== CONF_KILL
? rb_strdup(parv
[2]) : NULL
;
151 aconf
->host
= rb_strdup(parv
[3]);
152 aconf
->info
.oper
= operhash_add(oper
);
153 aconf
->created
= created
;
155 p
= strchr(parv
[parc
- 1], '|');
157 aconf
->passwd
= rb_strdup(parv
[parc
- 1]);
160 aconf
->passwd
= rb_strndup(parv
[parc
- 1], p
- parv
[parc
- 1] + 1);
161 aconf
->spasswd
= rb_strdup(p
+ 1);
163 if (act
&& hold
!= created
)
165 /* Keep the notices in sync with modules/m_kline.c etc. */
166 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
167 "%s added global %d min. %s%s%s for [%s%s%s] [%s]",
168 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
169 (hold
- rb_current_time()) / 60,
171 strcmp(parv
[7], "*") ? " from " : "",
172 strcmp(parv
[7], "*") ? parv
[7] : "",
173 aconf
->user
? aconf
->user
: "",
174 aconf
->user
? "@" : "",
177 ilog(L_KLINE
, "%s %s %d %s %s %s", parv
[1],
178 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
179 (hold
- rb_current_time()) / 60,
180 aconf
->user
, aconf
->host
,
182 aconf
->status
&= ~CONF_ILLEGAL
;
186 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
187 "%s has removed the global %s for: [%s%s%s]%s%s",
188 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
190 aconf
->user
? aconf
->user
: "",
191 aconf
->user
? "@" : "",
193 strcmp(parv
[7], "*") ? " on behalf of " : "",
194 strcmp(parv
[7], "*") ? parv
[7] : "");
195 ilog(L_KLINE
, "U%s %s %s %s", parv
[1],
196 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
197 aconf
->user
, aconf
->host
);
202 if (aconf
->status
& CONF_ILLEGAL
)
203 remove_reject_mask(aconf
->user
, aconf
->host
);
206 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
207 if(ConfigFileEntry
.kline_delay
||
208 (IsServer(source_p
) &&
209 !HasSentEob(source_p
)))
211 if(kline_queued
== 0)
213 rb_event_addonce("check_klines", check_klines_event
, NULL
,
214 ConfigFileEntry
.kline_delay
);
223 sendto_server(client_p
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
224 ":%s BAN %s %s %s %s %s %s %s :%s",