]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * charybdis: An advanced ircd. | |
3 | * m_ban.c: Propagates network bans across servers. | |
4 | * | |
5 | * Copyright (C) 2010 Jilles Tjoelker | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions are | |
9 | * met: | |
10 | * | |
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. | |
16 | * | |
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. | |
28 | */ | |
29 | ||
30 | #include "stdinc.h" | |
31 | #include "send.h" | |
32 | #include "client.h" | |
33 | #include "common.h" | |
34 | #include "config.h" | |
35 | #include "ircd.h" | |
36 | #include "match.h" | |
37 | #include "s_conf.h" | |
38 | #include "msg.h" | |
39 | #include "modules.h" | |
40 | #include "hash.h" | |
41 | #include "s_serv.h" | |
42 | #include "operhash.h" | |
43 | #include "reject.h" | |
44 | #include "hostmask.h" | |
45 | ||
46 | static int ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
47 | ||
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} | |
51 | }; | |
52 | ||
53 | mapi_clist_av1 ban_clist[] = { &ban_msgtab, NULL }; | |
54 | DECLARE_MODULE_AV1(ban, NULL, NULL, ban_clist, NULL, NULL, "$Revision: 1349 $"); | |
55 | ||
56 | /* ms_ban() | |
57 | * | |
58 | * parv[1] - +/- | |
59 | * parv[2] - type | |
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) | |
65 | * parv[8] - oper or * | |
66 | * parv[9] - reason (possibly with |operreason) | |
67 | */ | |
68 | static int | |
69 | ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
70 | { | |
71 | rb_dlink_node *ptr; | |
72 | struct ConfItem *aconf; | |
73 | unsigned int ntype; | |
74 | const char *oper, *stype; | |
75 | time_t created, hold, lifetime; | |
76 | char *p; | |
77 | int act; | |
78 | ||
79 | if (strcmp(parv[1], "+") && strcmp(parv[1], "-")) | |
80 | { | |
81 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
82 | "Unknown BAN operation %s from %s", | |
83 | parv[1], source_p->name); | |
84 | return 0; | |
85 | } | |
86 | if (strlen(parv[2]) != 1) | |
87 | { | |
88 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
89 | "Unknown BAN type %s from %s", | |
90 | parv[2], source_p->name); | |
91 | return 0; | |
92 | } | |
93 | switch (parv[2][0]) | |
94 | { | |
95 | case 'K': | |
96 | ntype = CONF_KILL; | |
97 | stype = "K-Line"; | |
98 | break; | |
99 | default: | |
100 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
101 | "Unknown BAN type %s from %s", | |
102 | parv[2], source_p->name); | |
103 | return 0; | |
104 | } | |
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); | |
110 | else | |
111 | oper = parv[8]; | |
112 | ptr = find_prop_ban(ntype, parv[3], parv[4]); | |
113 | if (ptr != NULL) | |
114 | { | |
115 | aconf = ptr->data; | |
116 | if (aconf->created >= created) | |
117 | { | |
118 | if (IsPerson(source_p)) | |
119 | sendto_one_notice(source_p, | |
120 | ":Your %s [%s%s%s] has been superseded", | |
121 | stype, | |
122 | aconf->user ? aconf->user : "", | |
123 | aconf->user ? "@" : "", | |
124 | aconf->host); | |
125 | return 0; | |
126 | } | |
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()) | |
132 | return 0; | |
133 | deactivate_conf(aconf, ptr); | |
134 | rb_free(aconf->user); | |
135 | aconf->user = NULL; | |
136 | rb_free(aconf->host); | |
137 | aconf->host = NULL; | |
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; | |
144 | } | |
145 | else | |
146 | { | |
147 | aconf = make_conf(); | |
148 | aconf->status = CONF_ILLEGAL | ntype; | |
149 | aconf->lifetime = lifetime; | |
150 | rb_dlinkAddAlloc(aconf, &prop_bans); | |
151 | act = !strcmp(parv[1], "+"); | |
152 | } | |
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; | |
159 | aconf->hold = hold; | |
160 | p = strchr(parv[parc - 1], '|'); | |
161 | if (p == NULL) | |
162 | aconf->passwd = rb_strdup(parv[parc - 1]); | |
163 | else | |
164 | { | |
165 | aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1); | |
166 | aconf->spasswd = rb_strdup(p + 1); | |
167 | } | |
168 | if (!strcmp(parv[1], "+")) | |
169 | { | |
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, | |
175 | stype, | |
176 | strcmp(parv[8], "*") ? " from " : "", | |
177 | strcmp(parv[8], "*") ? parv[8] : "", | |
178 | aconf->user ? aconf->user : "", | |
179 | aconf->user ? "@" : "", | |
180 | aconf->host, | |
181 | parv[parc - 1]); | |
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, | |
187 | parv[parc - 1]); | |
188 | } | |
189 | else if (act) | |
190 | { | |
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), | |
194 | stype, | |
195 | aconf->user ? aconf->user : "", | |
196 | aconf->user ? "@" : "", | |
197 | aconf->host, | |
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); | |
203 | } | |
204 | switch (ntype) | |
205 | { | |
206 | case CONF_KILL: | |
207 | if (aconf->status & CONF_ILLEGAL) | |
208 | remove_reject_mask(aconf->user, aconf->host); | |
209 | else | |
210 | { | |
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))) | |
215 | { | |
216 | if(kline_queued == 0) | |
217 | { | |
218 | rb_event_addonce("check_klines", check_klines_event, NULL, | |
219 | ConfigFileEntry.kline_delay); | |
220 | kline_queued = 1; | |
221 | } | |
222 | } | |
223 | else | |
224 | check_klines(); | |
225 | } | |
226 | break; | |
227 | } | |
228 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
229 | ":%s BAN %s %s %s %s %s %s %s %s :%s", | |
230 | source_p->id, | |
231 | parv[1], | |
232 | parv[2], | |
233 | parv[3], | |
234 | parv[4], | |
235 | parv[5], | |
236 | parv[6], | |
237 | parv[7], | |
238 | parv[8], | |
239 | parv[parc - 1]); | |
240 | return 0; | |
241 | } |