/[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 1652 - (show annotations)
Tue Nov 13 20:28:53 2012 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 13887 byte(s)
- changed match() polarity. match() now returns 0 on match and 1 on non-match
  This cleans up several places where function pointers of different matching
  functions like irccmp/strcmp/match are passed to other functions.
- added improved collapse() to match.c

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 "conf.h"
33 #include "hostmask.h"
34 #include "numeric.h"
35 #include "fdlist.h"
36 #include "s_bsd.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 MaskItem *, 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 MaskItem *conf;
74 time_t tkline_time = 0;
75 time_t cur_time;
76
77 if (!HasOFlag(source_p, OPER_FLAG_K))
78 {
79 sendto_one(source_p, form_str(ERR_NOPRIVS),
80 me.name, source_p->name, "kline");
81 return;
82 }
83
84 if (parse_aline("KLINE", source_p, parc, parv,
85 AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0)
86 return;
87
88 if (target_server != NULL)
89 {
90 if (HasID(source_p))
91 {
92 sendto_server(NULL, CAP_KLN|CAP_TS6, NOCAPS,
93 ":%s KLINE %s %lu %s %s :%s",
94 source_p->id, target_server, (unsigned long)tkline_time,
95 user, host, reason);
96 sendto_server(NULL, CAP_KLN, CAP_TS6,
97 ":%s KLINE %s %lu %s %s :%s",
98 source_p->name, target_server, (unsigned long)tkline_time,
99 user, host, reason);
100 }
101 else
102 sendto_server(NULL, CAP_KLN, NOCAPS,
103 ":%s KLINE %s %lu %s %s :%s",
104 source_p->name, target_server, (unsigned long)tkline_time,
105 user, host, reason);
106
107 /* Allow ON to apply local kline as well if it matches */
108 if (match(target_server, me.name))
109 return;
110 }
111 else
112 cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
113 "%d %s %s :%s", tkline_time, user, host, reason);
114
115 if (already_placed_kline(source_p, user, host, 1))
116 return;
117
118 cur_time = CurrentTime;
119 current_date = smalldate(cur_time);
120 conf = conf_make(CONF_KLINE);
121
122 conf->host = xstrdup(host);
123 conf->user = xstrdup(user);
124
125 if (tkline_time != 0)
126 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
127 (int)(tkline_time/60), reason, current_date);
128 else
129 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
130
131 conf->reason = xstrdup(buffer);
132 m_kline_add_kline(source_p, conf, tkline_time);
133 }
134
135 /* me_kline - handle remote kline. no propagation */
136 static void
137 me_kline(struct Client *client_p, struct Client *source_p,
138 int parc, char *parv[])
139 {
140 struct MaskItem *conf = NULL;
141 int tkline_time = 0;
142 const char* current_date;
143 time_t cur_time;
144 char *kuser, *khost, *kreason;
145
146 if (parc != 6 || EmptyString(parv[5]))
147 return;
148
149 if (match(parv[1], me.name))
150 return;
151
152 tkline_time = valid_tkline(parv[2], TK_SECONDS);
153 kuser = parv[3];
154 khost = parv[4];
155 kreason = parv[5];
156
157 cur_time = CurrentTime;
158 current_date = smalldate(cur_time);
159
160 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
161 source_p->username, source_p->host,
162 SHARED_KLINE))
163 {
164 if (!IsClient(source_p) ||
165 already_placed_kline(source_p, kuser, khost, 1))
166 return;
167
168 conf = conf_make(CONF_KLINE);
169 conf->host = xstrdup(khost);
170 conf->user = xstrdup(kuser);
171
172 if (tkline_time != 0)
173 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
174 (int)(tkline_time/60), kreason, current_date);
175 else
176 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
177
178 conf->reason = xstrdup(buffer);
179 m_kline_add_kline(source_p, conf, tkline_time);
180 }
181 }
182
183 static void
184 ms_kline(struct Client *client_p, struct Client *source_p,
185 int parc, char *parv[])
186 {
187 if (parc != 6 || EmptyString(parv[5]))
188 return;
189
190 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
191 /* oper target_server tkline_time user host reason */
192 sendto_match_servs(source_p, parv[1], CAP_KLN,
193 "KLINE %s %s %s %s :%s",
194 parv[1], parv[2], parv[3], parv[4], parv[5]);
195
196 me_kline(client_p, source_p, parc, parv);
197 }
198
199 /* apply_tkline()
200 *
201 * inputs -
202 * output - NONE
203 * side effects - tkline as given is placed
204 */
205 static void
206 m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
207 time_t tkline_time)
208 {
209 if (tkline_time)
210 {
211 conf->until = CurrentTime + tkline_time;
212 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
213 "%s added temporary %d min. K-Line for [%s@%s] [%s]",
214 get_oper_name(source_p), tkline_time/60,
215 conf->user, conf->host,
216 conf->reason);
217 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
218 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
219 source_p->name, tkline_time/60, conf->user, conf->host);
220 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
221 source_p->name, tkline_time/60,
222 conf->user, conf->host, conf->reason);
223 }
224 else
225 {
226 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
227 "%s added K-Line for [%s@%s] [%s]",
228 get_oper_name(source_p),
229 conf->user, conf->host, conf->reason);
230 sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
231 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
232 source_p->name, conf->user, conf->host);
233 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
234 source_p->name, conf->user, conf->host, conf->reason);
235 }
236
237 conf->setat = CurrentTime;
238 SetConfDatabase(conf);
239
240 add_conf_by_address(CONF_KLINE, conf);
241 rehashed_klines = 1;
242 }
243
244 /* already_placed_kline()
245 * inputs - user to complain to, username & host to check for
246 * outputs - returns 1 on existing K-line, 0 if doesn't exist
247 * side effects - notifies source_p if the K-line already exists
248 */
249 /*
250 * Note: This currently works if the new K-line is a special case of an
251 * existing K-line, but not the other way round. To do that we would
252 * have to walk the hash and check every existing K-line. -A1kmm.
253 */
254 static int
255 already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
256 {
257 const char *reason;
258 struct irc_ssaddr iphost, *piphost;
259 struct MaskItem *conf = NULL;
260 int t = 0;
261 int aftype = 0;
262
263 if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
264 {
265 #ifdef IPV6
266 if (t == HM_IPV6)
267 aftype = AF_INET6;
268 else
269 #endif
270 aftype = AF_INET;
271 piphost = &iphost;
272 }
273 else
274 piphost = NULL;
275
276 if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
277 {
278 if (warn)
279 {
280 reason = conf->reason ? conf->reason : "No reason";
281 sendto_one(source_p,
282 ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
283 me.name, source_p->name, luser, lhost, conf->user,
284 conf->host, reason);
285 }
286
287 return 1;
288 }
289
290 return 0;
291 }
292
293 /*
294 ** mo_unkline
295 ** Added Aug 31, 1997
296 ** common (Keith Fralick) fralick@gate.net
297 **
298 ** parv[0] = sender
299 ** parv[1] = address to remove
300 *
301 *
302 */
303 static void
304 mo_unkline(struct Client *client_p,struct Client *source_p,
305 int parc, char *parv[])
306 {
307 char *target_server = NULL;
308 char *user, *host;
309
310 if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
311 {
312 sendto_one(source_p, form_str(ERR_NOPRIVS),
313 me.name, source_p->name, "unkline");
314 return;
315 }
316
317 if (EmptyString(parv[1]))
318 {
319 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
320 me.name, source_p->name, "UNKLINE");
321 return;
322 }
323
324 if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
325 &host, NULL, &target_server, NULL) < 0)
326 return;
327
328 if (target_server != NULL)
329 {
330 sendto_match_servs(source_p, target_server, CAP_UNKLN,
331 "UNKLINE %s %s %s",
332 target_server, user, host);
333
334 /* Allow ON to apply local unkline as well if it matches */
335 if (match(target_server, me.name))
336 return;
337 }
338 else
339 cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
340 "%s %s", user, host);
341
342 if (remove_kline_match(host, user))
343 {
344 sendto_one(source_p,
345 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
346 me.name, source_p->name, user, host);
347 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
348 "%s has removed the K-Line for: [%s@%s]",
349 get_oper_name(source_p), user, host);
350 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
351 source_p->name, user, host);
352 }
353 else
354 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
355 me.name, source_p->name, user, host);
356 }
357
358 /* me_unkline()
359 *
360 * inputs - server
361 * - client
362 * - parc
363 * - parv
364 * outputs - none
365 * side effects - if server is authorized, kline is removed
366 * does not propagate message
367 */
368 static void
369 me_unkline(struct Client *client_p, struct Client *source_p,
370 int parc, char *parv[])
371 {
372 const char *kuser, *khost;
373
374 if (parc != 4)
375 return;
376
377 kuser = parv[2];
378 khost = parv[3];
379
380 if (!IsClient(source_p) || match(parv[1], me.name))
381 return;
382
383 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
384 source_p->servptr->name,
385 source_p->username, source_p->host,
386 SHARED_UNKLINE))
387 {
388 if (remove_kline_match(khost, kuser))
389 {
390 sendto_one(source_p,
391 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
392 me.name, source_p->name, kuser, khost);
393 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
394 "%s has removed the K-Line for: [%s@%s]",
395 get_oper_name(source_p), kuser, khost);
396 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
397 source_p->name, kuser, khost);
398 }
399 else
400 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
401 me.name, source_p->name, kuser, khost);
402 }
403 }
404
405 /* ms_unkline - propagates and handles a remote unkline message */
406 static void
407 ms_unkline(struct Client *client_p, struct Client *source_p,
408 int parc, char *parv[])
409 {
410 if (parc != 4)
411 return;
412
413 sendto_match_servs(source_p, parv[1], CAP_UNKLN,
414 "UNKLINE %s %s %s",
415 parv[1], parv[2], parv[3]);
416
417 me_unkline(client_p, source_p, parc, parv);
418 }
419
420 /* static int remove_tkline_match(const char *host, const char *user)
421 * Input: A hostname, a username to unkline.
422 * Output: returns YES on success, NO if no tkline removed.
423 * Side effects: Any matching tklines are removed.
424 */
425 static int
426 remove_kline_match(const char *host, const char *user)
427 {
428 struct irc_ssaddr iphost, *piphost;
429 struct MaskItem *conf;
430 int t = 0;
431 int aftype = 0;
432
433 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
434 {
435 #ifdef IPV6
436 if (t == HM_IPV6)
437 aftype = AF_INET6;
438 else
439 #endif
440 aftype = AF_INET;
441 piphost = &iphost;
442 }
443 else
444 piphost = NULL;
445
446 if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
447 {
448 if (IsConfDatabase(conf))
449 {
450 delete_one_address_conf(host, conf);
451 return 1;
452 }
453 }
454
455 return 0;
456 }
457
458 static struct Message kline_msgtab = {
459 "KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
460 {m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore}
461 };
462
463 static struct Message unkline_msgtab = {
464 "UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
465 {m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore}
466 };
467
468 static void
469 module_init(void)
470 {
471 mod_add_cmd(&kline_msgtab);
472 mod_add_cmd(&unkline_msgtab);
473 add_capability("KLN", CAP_KLN, 1);
474 add_capability("UNKLN", CAP_UNKLN, 1);
475 }
476
477 static void
478 module_exit(void)
479 {
480 mod_del_cmd(&kline_msgtab);
481 mod_del_cmd(&unkline_msgtab);
482 delete_capability("UNKLN");
483 delete_capability("KLN");
484 }
485
486 struct module module_entry = {
487 .node = { NULL, NULL, NULL },
488 .name = NULL,
489 .version = "$Revision$",
490 .handle = NULL,
491 .modinit = module_init,
492 .modexit = module_exit,
493 .flags = 0
494 };

Properties

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

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