/[svn]/ircd-hybrid/trunk/modules/m_kline.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/m_kline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1622 - (show annotations)
Thu Nov 1 13:16:37 2012 UTC (7 years, 10 months ago) by michael
File MIME type: text/x-chdr
File size: 14298 byte(s)
- klines, dlines, xlines, glines and resv now make use of the new database;
  also, temporary *lines are now stored, so they're not lost after
  restarting the ircd. This also applies to G-lines.

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_kline.c: Bans a user.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "channel.h"
28 #include "client.h"
29 #include "irc_string.h"
30 #include "sprintf_irc.h"
31 #include "ircd.h"
32 #include "hostmask.h"
33 #include "numeric.h"
34 #include "fdlist.h"
35 #include "s_bsd.h"
36 #include "conf.h"
37 #include "log.h"
38 #include "s_misc.h"
39 #include "send.h"
40 #include "hash.h"
41 #include "s_serv.h"
42 #include "s_gline.h"
43 #include "parse.h"
44 #include "modules.h"
45 #include "conf_db.h"
46
47
48 static int already_placed_kline(struct Client *, const char *, const char *, int);
49 static void m_kline_add_kline(struct Client *, struct AccessItem *, time_t);
50
51 static char buffer[IRCD_BUFSIZE];
52 static int remove_kline_match(const char *, const char *);
53
54
55 /* mo_kline()
56 *
57 * inputs - pointer to server
58 * - pointer to client
59 * - parameter count
60 * - parameter list
61 * output -
62 * side effects - k line is added
63 */
64 static void
65 mo_kline(struct Client *client_p, struct Client *source_p,
66 int parc, char *parv[])
67 {
68 char *reason = NULL;
69 char *user = NULL;
70 char *host = NULL;
71 const char *current_date;
72 char *target_server = NULL;
73 struct ConfItem *conf;
74 struct AccessItem *aconf;
75 time_t tkline_time = 0;
76 time_t cur_time;
77
78 if (!HasOFlag(source_p, OPER_FLAG_K))
79 {
80 sendto_one(source_p, form_str(ERR_NOPRIVS),
81 me.name, source_p->name, "kline");
82 return;
83 }
84
85 if (parse_aline("KLINE", source_p, parc, parv,
86 AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0)
87 return;
88
89 if (target_server != NULL)
90 {
91 if (HasID(source_p))
92 {
93 sendto_server(NULL, CAP_KLN|CAP_TS6, NOCAPS,
94 ":%s KLINE %s %lu %s %s :%s",
95 source_p->id, target_server, (unsigned long)tkline_time,
96 user, host, reason);
97 sendto_server(NULL, CAP_KLN, CAP_TS6,
98 ":%s KLINE %s %lu %s %s :%s",
99 source_p->name, target_server, (unsigned long)tkline_time,
100 user, host, reason);
101 }
102 else
103 sendto_server(NULL, CAP_KLN, NOCAPS,
104 ":%s KLINE %s %lu %s %s :%s",
105 source_p->name, target_server, (unsigned long)tkline_time,
106 user, host, reason);
107
108 /* Allow ON to apply local kline as well if it matches */
109 if (!match(target_server, me.name))
110 return;
111 }
112 else
113 cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
114 "%d %s %s :%s", tkline_time, user, host, reason);
115
116 if (already_placed_kline(source_p, user, host, 1))
117 return;
118
119 cur_time = CurrentTime;
120 current_date = smalldate(cur_time);
121 conf = make_conf_item(KLINE_TYPE);
122 aconf = map_to_conf(conf);
123
124 DupString(aconf->host, host);
125 DupString(aconf->user, user);
126
127 if (tkline_time != 0)
128 {
129 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
130 (int)(tkline_time/60), reason, current_date);
131 DupString(aconf->reason, buffer);
132
133 m_kline_add_kline(source_p, aconf, tkline_time);
134 }
135 else
136 {
137 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
138 DupString(aconf->reason, buffer);
139
140 m_kline_add_kline(source_p, aconf, 0);
141 }
142 }
143
144 /* me_kline - handle remote kline. no propagation */
145 static void
146 me_kline(struct Client *client_p, struct Client *source_p,
147 int parc, char *parv[])
148 {
149 struct ConfItem *conf=NULL;
150 struct AccessItem *aconf=NULL;
151 int tkline_time;
152 const char* current_date;
153 time_t cur_time;
154 char *kuser, *khost, *kreason;
155
156 if (parc != 6 || EmptyString(parv[5]))
157 return;
158
159 if (!match(parv[1], me.name))
160 return;
161
162 tkline_time = valid_tkline(parv[2], TK_SECONDS);
163 kuser = parv[3];
164 khost = parv[4];
165 kreason = parv[5];
166
167 cur_time = CurrentTime;
168 current_date = smalldate(cur_time);
169
170 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
171 source_p->username, source_p->host,
172 SHARED_KLINE))
173 {
174 if (!IsClient(source_p) ||
175 already_placed_kline(source_p, kuser, khost, 1))
176 return;
177
178 conf = make_conf_item(KLINE_TYPE);
179 aconf = map_to_conf(conf);
180 DupString(aconf->host, khost);
181 DupString(aconf->user, kuser);
182
183 if (tkline_time != 0)
184 {
185 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
186 (int)(tkline_time/60), kreason, current_date);
187 DupString(aconf->reason, buffer);
188
189 m_kline_add_kline(source_p, aconf, tkline_time);
190 }
191 else
192 {
193 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
194 DupString(aconf->reason, buffer);
195
196 m_kline_add_kline(source_p, aconf, 0);
197 }
198 }
199 }
200
201 static void
202 ms_kline(struct Client *client_p, struct Client *source_p,
203 int parc, char *parv[])
204 {
205 if (parc != 6 || EmptyString(parv[5]))
206 return;
207
208 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
209 /* oper target_server tkline_time user host reason */
210 sendto_match_servs(source_p, parv[1], CAP_KLN,
211 "KLINE %s %s %s %s :%s",
212 parv[1], parv[2], parv[3], parv[4], parv[5]);
213
214 me_kline(client_p, source_p, parc, parv);
215 }
216
217 /* apply_tkline()
218 *
219 * inputs -
220 * output - NONE
221 * side effects - tkline as given is placed
222 */
223 static void
224 m_kline_add_kline(struct Client *source_p, struct AccessItem *aconf,
225 time_t tkline_time)
226 {
227 aconf->setat = CurrentTime;
228
229 if (tkline_time)
230 {
231 aconf->hold = CurrentTime + tkline_time;
232 SetConfTemporary(aconf);
233
234 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
235 "%s added temporary %d min. K-Line for [%s@%s] [%s]",
236 get_oper_name(source_p), tkline_time/60,
237 aconf->user, aconf->host,
238 aconf->reason);
239 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
240 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
241 source_p->name, tkline_time/60, aconf->user, aconf->host);
242 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
243 source_p->name, tkline_time/60,
244 aconf->user, aconf->host, aconf->reason);
245 }
246 else
247 {
248 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
249 "%s added K-Line for [%s@%s] [%s]",
250 get_oper_name(source_p),
251 aconf->user, aconf->host, aconf->reason);
252 sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
253 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
254 source_p->name, aconf->user, aconf->host);
255 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
256 source_p->name, aconf->user, aconf->host, aconf->reason);
257 }
258
259 add_conf_by_address(CONF_KLINE, aconf);
260 save_kline_database();
261 rehashed_klines = 1;
262 }
263
264 /* already_placed_kline()
265 * inputs - user to complain to, username & host to check for
266 * outputs - returns 1 on existing K-line, 0 if doesn't exist
267 * side effects - notifies source_p if the K-line already exists
268 */
269 /*
270 * Note: This currently works if the new K-line is a special case of an
271 * existing K-line, but not the other way round. To do that we would
272 * have to walk the hash and check every existing K-line. -A1kmm.
273 */
274 static int
275 already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
276 {
277 const char *reason;
278 struct irc_ssaddr iphost, *piphost;
279 struct AccessItem *aconf;
280 int t;
281
282 if ((t = parse_netmask(lhost, &iphost, &t)) != HM_HOST)
283 {
284 #ifdef IPV6
285 if (t == HM_IPV6)
286 t = AF_INET6;
287 else
288 #endif
289 t = AF_INET;
290 piphost = &iphost;
291 }
292 else
293 {
294 t = 0;
295 piphost = NULL;
296 }
297
298 if ((aconf = find_conf_by_address(lhost, piphost, CONF_KLINE, t, luser, NULL, 0)))
299 {
300 if (warn)
301 {
302 reason = aconf->reason ? aconf->reason : "No reason";
303 sendto_one(source_p,
304 ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
305 me.name, source_p->name, luser, lhost, aconf->user,
306 aconf->host, reason);
307 }
308
309 return 1;
310 }
311
312 return 0;
313 }
314
315 /*
316 ** mo_unkline
317 ** Added Aug 31, 1997
318 ** common (Keith Fralick) fralick@gate.net
319 **
320 ** parv[0] = sender
321 ** parv[1] = address to remove
322 *
323 *
324 */
325 static void
326 mo_unkline(struct Client *client_p,struct Client *source_p,
327 int parc, char *parv[])
328 {
329 char *target_server = NULL;
330 char *user, *host;
331
332 if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
333 {
334 sendto_one(source_p, form_str(ERR_NOPRIVS),
335 me.name, source_p->name, "unkline");
336 return;
337 }
338
339 if (EmptyString(parv[1]))
340 {
341 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
342 me.name, source_p->name, "UNKLINE");
343 return;
344 }
345
346 if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
347 &host, NULL, &target_server, NULL) < 0)
348 return;
349
350 if (target_server != NULL)
351 {
352 sendto_match_servs(source_p, target_server, CAP_UNKLN,
353 "UNKLINE %s %s %s",
354 target_server, user, host);
355
356 /* Allow ON to apply local unkline as well if it matches */
357 if (!match(target_server, me.name))
358 return;
359 }
360 else
361 cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
362 "%s %s", user, host);
363
364 if (remove_kline_match(host, user))
365 {
366 sendto_one(source_p,
367 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
368 me.name, source_p->name, user, host);
369 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
370 "%s has removed the K-Line for: [%s@%s]",
371 get_oper_name(source_p), user, host);
372 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
373 source_p->name, user, host);
374 }
375 else
376 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
377 me.name, source_p->name, user, host);
378 }
379
380 /* me_unkline()
381 *
382 * inputs - server
383 * - client
384 * - parc
385 * - parv
386 * outputs - none
387 * side effects - if server is authorized, kline is removed
388 * does not propagate message
389 */
390 static void
391 me_unkline(struct Client *client_p, struct Client *source_p,
392 int parc, char *parv[])
393 {
394 const char *kuser, *khost;
395
396 if (parc != 4)
397 return;
398
399 kuser = parv[2];
400 khost = parv[3];
401
402 if (!IsClient(source_p) || !match(parv[1], me.name))
403 return;
404
405 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE,
406 source_p->servptr->name,
407 source_p->username, source_p->host,
408 SHARED_UNKLINE))
409 {
410 if (remove_kline_match(khost, kuser))
411 {
412 sendto_one(source_p,
413 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
414 me.name, source_p->name, kuser, khost);
415 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
416 "%s has removed the K-Line for: [%s@%s]",
417 get_oper_name(source_p), kuser, khost);
418 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
419 source_p->name, kuser, khost);
420 }
421 else
422 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
423 me.name, source_p->name, kuser, khost);
424 }
425 }
426
427 /* ms_unkline - propagates and handles a remote unkline message */
428 static void
429 ms_unkline(struct Client *client_p, struct Client *source_p,
430 int parc, char *parv[])
431 {
432 if (parc != 4)
433 return;
434
435 sendto_match_servs(source_p, parv[1], CAP_UNKLN,
436 "UNKLINE %s %s %s",
437 parv[1], parv[2], parv[3]);
438
439 me_unkline(client_p, source_p, parc, parv);
440 }
441
442 /* static int remove_tkline_match(const char *host, const char *user)
443 * Input: A hostname, a username to unkline.
444 * Output: returns YES on success, NO if no tkline removed.
445 * Side effects: Any matching tklines are removed.
446 */
447 static int
448 remove_kline_match(const char *host, const char *user)
449 {
450 struct irc_ssaddr iphost, *piphost;
451 struct AccessItem *aconf;
452 int t;
453
454 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
455 {
456 #ifdef IPV6
457 if (t == HM_IPV6)
458 t = AF_INET6;
459 else
460 #endif
461 t = AF_INET;
462 piphost = &iphost;
463 }
464 else
465 {
466 t = 0;
467 piphost = NULL;
468 }
469
470 if ((aconf = find_conf_by_address(host, piphost, CONF_KLINE, t, user, NULL, 0)))
471 {
472 if (!IsConfMain(aconf))
473 {
474 delete_one_address_conf(host, aconf);
475 save_kline_database();
476 return 1;
477 }
478 }
479
480 return 0;
481 }
482
483 static struct Message kline_msgtab = {
484 "KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
485 {m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore}
486 };
487
488 static struct Message unkline_msgtab = {
489 "UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
490 {m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore}
491 };
492
493 static void
494 module_init(void)
495 {
496 mod_add_cmd(&kline_msgtab);
497 mod_add_cmd(&unkline_msgtab);
498 add_capability("KLN", CAP_KLN, 1);
499 add_capability("UNKLN", CAP_UNKLN, 1);
500 }
501
502 static void
503 module_exit(void)
504 {
505 mod_del_cmd(&kline_msgtab);
506 mod_del_cmd(&unkline_msgtab);
507 delete_capability("UNKLN");
508 delete_capability("KLN");
509 }
510
511 struct module module_entry = {
512 .node = { NULL, NULL, NULL },
513 .name = NULL,
514 .version = "$Revision$",
515 .handle = NULL,
516 .modinit = module_init,
517 .modexit = module_exit,
518 .flags = 0
519 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28