ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.3.x/modules/m_kline.c
Revision: 6783
Committed: Sun Nov 15 18:50:00 2015 UTC (8 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 9923 byte(s)
Log Message:
- Use the %ju conversion specifier for time_t and get rid of these non-portable (unsigned long) casts; replace some uint64_t with uintmax_t

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_kline.c
23 * \brief Includes required functions for processing the KLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "ircd.h"
32 #include "conf.h"
33 #include "hostmask.h"
34 #include "numeric.h"
35 #include "log.h"
36 #include "misc.h"
37 #include "send.h"
38 #include "server.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "memory.h"
42
43
44 static void
45 kline_check(struct AddressRec *arec)
46 {
47 dlink_node *node = NULL, *node_next = NULL;
48
49 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
50 {
51 struct Client *client_p = node->data;
52
53 if (IsDead(client_p))
54 continue;
55
56 if (match(arec->username, client_p->username))
57 continue;
58
59 switch (arec->masktype)
60 {
61 case HM_IPV4:
62 if (client_p->connection->aftype == AF_INET)
63 if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
64 conf_try_ban(client_p, arec->conf);
65 break;
66 case HM_IPV6:
67 if (client_p->connection->aftype == AF_INET6)
68 if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
69 conf_try_ban(client_p, arec->conf);
70 break;
71 default: /* HM_HOST */
72 if (!match(arec->Mask.hostname, client_p->host) || !match(arec->Mask.hostname, client_p->sockhost))
73 conf_try_ban(client_p, arec->conf);
74 break;
75 }
76 }
77 }
78
79 /* apply_tkline()
80 *
81 * inputs -
82 * output - NONE
83 * side effects - tkline as given is placed
84 */
85 static void
86 kline_add(struct Client *source_p, const char *user, const char *host,
87 const char *reason, time_t duration)
88 {
89 char buf[IRCD_BUFSIZE];
90 struct MaskItem *conf;
91
92 if (duration)
93 snprintf(buf, sizeof(buf), "Temporary K-line %ju min. - %.*s (%s)",
94 duration / 60, REASONLEN, reason, date_iso8601(0));
95 else
96 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0));
97
98 conf = conf_make(CONF_KLINE);
99 conf->host = xstrdup(host);
100 conf->user = xstrdup(user);
101 conf->setat = CurrentTime;
102 conf->reason = xstrdup(buf);
103 SetConfDatabase(conf);
104
105 if (duration)
106 {
107 conf->until = CurrentTime + duration;
108
109 if (IsClient(source_p))
110 sendto_one_notice(source_p, &me, ":Added temporary %ju min. K-Line [%s@%s]",
111 duration / 60, conf->user, conf->host);
112
113 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
114 "%s added temporary %ju min. K-Line for [%s@%s] [%s]",
115 get_oper_name(source_p), duration / 60,
116 conf->user, conf->host,
117 conf->reason);
118 ilog(LOG_TYPE_KLINE, "%s added temporary %ju min. K-Line for [%s@%s] [%s]",
119 get_oper_name(source_p), duration / 60,
120 conf->user, conf->host, conf->reason);
121 }
122 else
123 {
124 if (IsClient(source_p))
125 sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
126 conf->user, conf->host);
127
128 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
129 "%s added K-Line for [%s@%s] [%s]",
130 get_oper_name(source_p),
131 conf->user, conf->host, conf->reason);
132 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
133 get_oper_name(source_p), conf->user, conf->host, conf->reason);
134 }
135
136 kline_check(add_conf_by_address(CONF_KLINE, conf));
137 }
138
139 /* already_placed_kline()
140 * inputs - user to complain to, username & host to check for
141 * outputs - returns 1 on existing K-line, 0 if doesn't exist
142 * side effects - notifies source_p if the K-line already exists
143 */
144 /*
145 * Note: This currently works if the new K-line is a special case of an
146 * existing K-line, but not the other way round. To do that we would
147 * have to walk the hash and check every existing K-line. -A1kmm.
148 */
149 static int
150 already_placed_kline(struct Client *source_p, const char *user, const char *host)
151 {
152 struct irc_ssaddr iphost, *piphost;
153 struct MaskItem *conf = NULL;
154 int t = 0;
155 int aftype = 0;
156
157 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
158 {
159 if (t == HM_IPV6)
160 aftype = AF_INET6;
161 else
162 aftype = AF_INET;
163
164 piphost = &iphost;
165 }
166 else
167 piphost = NULL;
168
169 if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
170 {
171 if (IsClient(source_p))
172 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
173 user, host, conf->user, conf->host, conf->reason);
174 return 1;
175 }
176
177 return 0;
178 }
179
180 /* mo_kline()
181 *
182 * inputs - pointer to server
183 * - pointer to client
184 * - parameter count
185 * - parameter list
186 * output -
187 * side effects - k line is added
188 */
189 static int
190 mo_kline(struct Client *source_p, int parc, char *parv[])
191 {
192 char *reason = NULL;
193 char *user = NULL;
194 char *host = NULL;
195 char *target_server = NULL;
196 time_t duration = 0;
197 int bits = 0;
198
199 if (!HasOFlag(source_p, OPER_FLAG_KLINE))
200 {
201 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
202 return 0;
203 }
204
205 if (!parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
206 &duration, &target_server, &reason))
207 return 0;
208
209 if (target_server)
210 {
211 sendto_match_servs(source_p, target_server, CAPAB_KLN, "KLINE %s %ju %s %s :%s",
212 target_server, duration,
213 user, host, reason);
214
215 /* Allow ON to apply local kline as well if it matches */
216 if (match(target_server, me.name))
217 return 0;
218 }
219 else
220 cluster_a_line(source_p, "KLINE", CAPAB_KLN, SHARED_KLINE,
221 "%ju %s %s :%s", duration, user, host, reason);
222
223 if (already_placed_kline(source_p, user, host))
224 return 0;
225
226 switch (parse_netmask(host, NULL, &bits))
227 {
228 case HM_IPV4:
229 if ((unsigned int)bits < ConfigGeneral.kline_min_cidr)
230 {
231 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
232 ConfigGeneral.kline_min_cidr);
233 return 0;
234 }
235
236 break;
237 case HM_IPV6:
238 if ((unsigned int)bits < ConfigGeneral.kline_min_cidr6)
239 {
240 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
241 ConfigGeneral.kline_min_cidr6);
242 return 0;
243 }
244
245 break;
246 default: /* HM_HOST */
247 break;
248 }
249
250 kline_add(source_p, user, host, reason, duration);
251 return 0;
252 }
253
254 /* me_kline - handle remote kline. no propagation */
255 static int
256 ms_kline(struct Client *source_p, int parc, char *parv[])
257 {
258 time_t duration = 0;
259 const char *user, *host, *reason;
260 int bits = 0;
261
262 if (parc != 6 || EmptyString(parv[5]))
263 return 0;
264
265 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
266 /* command target_server duration user host reason */
267 sendto_match_servs(source_p, parv[1], CAPAB_KLN, "KLINE %s %s %s %s :%s",
268 parv[1], parv[2], parv[3], parv[4], parv[5]);
269
270 if (match(parv[1], me.name))
271 return 0;
272
273 duration = valid_tkline(parv[2], TK_SECONDS);
274 user = parv[3];
275 host = parv[4];
276 reason = parv[5];
277
278 if (HasFlag(source_p, FLAGS_SERVICE) ||
279 find_matching_name_conf(CONF_SHARED, source_p->servptr->name,
280 source_p->username, source_p->host,
281 SHARED_KLINE))
282 {
283 if (!valid_wild_card(source_p, 2, user, host))
284 return 0;
285
286 if (already_placed_kline(source_p, user, host))
287 return 0;
288
289 switch (parse_netmask(host, NULL, &bits))
290 {
291 case HM_IPV4:
292 if ((unsigned int)bits < ConfigGeneral.kline_min_cidr)
293 {
294 if (IsClient(source_p))
295 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
296 ConfigGeneral.kline_min_cidr);
297 return 0;
298 }
299
300 break;
301 case HM_IPV6:
302 if ((unsigned int)bits < ConfigGeneral.kline_min_cidr6)
303 {
304 if (IsClient(source_p))
305 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
306 ConfigGeneral.kline_min_cidr6);
307 return 0;
308 }
309
310 break;
311 default: /* HM_HOST */
312 break;
313 }
314
315 kline_add(source_p, user, host, reason, duration);
316 }
317
318 return 0;
319 }
320
321 static struct Message kline_msgtab =
322 {
323 .cmd = "KLINE",
324 .args_min = 2,
325 .args_max = MAXPARA,
326 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
327 .handlers[CLIENT_HANDLER] = m_not_oper,
328 .handlers[SERVER_HANDLER] = ms_kline,
329 .handlers[ENCAP_HANDLER] = m_ignore,
330 .handlers[OPER_HANDLER] = mo_kline
331 };
332
333 static void
334 module_init(void)
335 {
336 mod_add_cmd(&kline_msgtab);
337 add_capability("KLN", CAPAB_KLN);
338 }
339
340 static void
341 module_exit(void)
342 {
343 mod_del_cmd(&kline_msgtab);
344 delete_capability("KLN");
345 }
346
347 struct module module_entry =
348 {
349 .version = "$Revision$",
350 .modinit = module_init,
351 .modexit = module_exit,
352 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision