]>
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
, 10}, {ms_ban
, 10}, 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 $");
60 * parv[3] - username mask or *
61 * parv[4] - hostname mask
62 * parv[5] - creation TS
63 * parv[6] - duration (relative to creation)
64 * parv[7] - lifetime (relative to creation)
66 * parv[9] - 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 (strcmp(parv
[1], "+") && strcmp(parv
[1], "-"))
81 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
82 "Unknown BAN operation %s from %s",
83 parv
[1], source_p
->name
);
86 if (strlen(parv
[2]) != 1)
88 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
89 "Unknown BAN type %s from %s",
90 parv
[2], source_p
->name
);
100 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
101 "Unknown BAN type %s from %s",
102 parv
[2], source_p
->name
);
105 created
= atol(parv
[5]);
106 hold
= created
+ atoi(parv
[6]);
107 lifetime
= created
+ atoi(parv
[7]);
108 if (!strcmp(parv
[8], "*"))
109 oper
= IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
);
112 ptr
= find_prop_ban(ntype
, parv
[3], parv
[4]);
116 if (aconf
->created
>= created
)
118 if (IsPerson(source_p
))
119 sendto_one_notice(source_p
,
120 ":Your %s [%s%s%s] has been superseded",
122 aconf
->user
? aconf
->user
: "",
123 aconf
->user
? "@" : "",
127 act
= !(aconf
->status
& CONF_ILLEGAL
) || !strcmp(parv
[1], "+");
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
= !strcmp(parv
[1], "+");
153 aconf
->flags
&= ~CONF_FLAGS_MYOPER
;
154 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
155 aconf
->user
= ntype
== CONF_KILL
? rb_strdup(parv
[3]) : NULL
;
156 aconf
->host
= rb_strdup(parv
[4]);
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 (!strcmp(parv
[1], "+"))
170 /* Keep the notices in sync with modules/m_kline.c etc. */
171 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
172 "%s added global %d min. %s%s%s for [%s%s%s] [%s]",
173 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
174 (hold
- rb_current_time()) / 60,
176 strcmp(parv
[8], "*") ? " from " : "",
177 strcmp(parv
[8], "*") ? parv
[8] : "",
178 aconf
->user
? aconf
->user
: "",
179 aconf
->user
? "@" : "",
182 aconf
->status
&= ~CONF_ILLEGAL
;
183 ilog(L_KLINE
, "%s %s %d %s %s %s", parv
[2],
184 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
185 (hold
- rb_current_time()) / 60,
186 aconf
->user
, aconf
->host
,
191 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
192 "%s has removed the global %s for: [%s%s%s]%s%s",
193 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
195 aconf
->user
? aconf
->user
: "",
196 aconf
->user
? "@" : "",
198 strcmp(parv
[8], "*") ? " on behalf of " : "",
199 strcmp(parv
[8], "*") ? parv
[8] : "");
200 ilog(L_KLINE
, "U%s %s %s %s", parv
[2],
201 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
202 aconf
->user
, aconf
->host
);
207 if (aconf
->status
& CONF_ILLEGAL
)
208 remove_reject_mask(aconf
->user
, aconf
->host
);
211 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
212 if(ConfigFileEntry
.kline_delay
||
213 (IsServer(source_p
) &&
214 !HasSentEob(source_p
)))
216 if(kline_queued
== 0)
218 rb_event_addonce("check_klines", check_klines_event
, NULL
,
219 ConfigFileEntry
.kline_delay
);
228 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
229 ":%s BAN %s %s %s %s %s %s %s %s :%s",