ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 3208
Committed: Tue Mar 25 15:31:30 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 13576 byte(s)
Log Message:
- Minor cleanup to m_dline.c, m_gline.c, m_kline.c

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2810 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2818 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2810 /*! \file m_kline.c
23     * \brief Includes required functions for processing the KLINE/UNKLINE command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32 michael 1632 #include "conf.h"
33 adx 30 #include "hostmask.h"
34     #include "numeric.h"
35 michael 1309 #include "log.h"
36 adx 30 #include "s_misc.h"
37     #include "send.h"
38     #include "hash.h"
39     #include "s_serv.h"
40     #include "s_gline.h"
41     #include "parse.h"
42     #include "modules.h"
43 michael 1622 #include "conf_db.h"
44 michael 1666 #include "memory.h"
45 adx 30
46 michael 1058
47 michael 2811 static void
48     check_kline(struct AddressRec *arec)
49     {
50     dlink_node *ptr = NULL, *ptr_next = NULL;
51    
52     DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
53     {
54     struct Client *client_p = ptr->data;
55    
56 michael 2812 if (IsDead(client_p))
57 michael 2811 continue;
58    
59     if (match(arec->username, client_p->username))
60     continue;
61    
62     switch (arec->masktype)
63     {
64     case HM_IPV4:
65     if (client_p->localClient->aftype == AF_INET)
66     if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
67 michael 2813 conf_try_ban(client_p, arec->conf);
68 michael 2811 break;
69     case HM_IPV6:
70     if (client_p->localClient->aftype == AF_INET6)
71     if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
72 michael 2813 conf_try_ban(client_p, arec->conf);
73 michael 2811 break;
74     default: /* HM_HOST */
75     if (!match(arec->Mask.hostname, client_p->host))
76 michael 2813 conf_try_ban(client_p, arec->conf);
77 michael 2811 break;
78     }
79     }
80     }
81    
82 michael 2810 /* apply_tkline()
83     *
84     * inputs -
85     * output - NONE
86     * side effects - tkline as given is placed
87     */
88     static void
89     m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
90     time_t tkline_time)
91     {
92     if (tkline_time)
93     {
94     conf->until = CurrentTime + tkline_time;
95     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
96     "%s added temporary %d min. K-Line for [%s@%s] [%s]",
97     get_oper_name(source_p), tkline_time/60,
98     conf->user, conf->host,
99     conf->reason);
100 michael 3110 sendto_one_notice(source_p, &me, ":Added temporary %d min. K-Line [%s@%s]",
101     tkline_time/60, conf->user, conf->host);
102 michael 2810 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
103     get_oper_name(source_p), tkline_time/60,
104     conf->user, conf->host, conf->reason);
105     }
106     else
107     {
108     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
109     "%s added K-Line for [%s@%s] [%s]",
110     get_oper_name(source_p),
111     conf->user, conf->host, conf->reason);
112 michael 3110 sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
113     conf->user, conf->host);
114 michael 2810 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
115     get_oper_name(source_p), conf->user, conf->host, conf->reason);
116     }
117 adx 30
118 michael 2810 conf->setat = CurrentTime;
119     SetConfDatabase(conf);
120 adx 30
121 michael 2811 check_kline(add_conf_by_address(CONF_KLINE, conf));
122 michael 2810 }
123    
124     /* static int remove_tkline_match(const char *host, const char *user)
125     * Input: A hostname, a username to unkline.
126     * Output: returns YES on success, NO if no tkline removed.
127     * Side effects: Any matching tklines are removed.
128     */
129     static int
130     remove_kline_match(const char *host, const char *user)
131     {
132     struct irc_ssaddr iphost, *piphost;
133     struct MaskItem *conf;
134     int t = 0;
135     int aftype = 0;
136    
137     if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
138     {
139     #ifdef IPV6
140     if (t == HM_IPV6)
141     aftype = AF_INET6;
142     else
143     #endif
144     aftype = AF_INET;
145     piphost = &iphost;
146     }
147     else
148     piphost = NULL;
149    
150     if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
151     {
152     if (IsConfDatabase(conf))
153     {
154     delete_one_address_conf(host, conf);
155     return 1;
156     }
157     }
158    
159     return 0;
160     }
161    
162     /* already_placed_kline()
163     * inputs - user to complain to, username & host to check for
164     * outputs - returns 1 on existing K-line, 0 if doesn't exist
165     * side effects - notifies source_p if the K-line already exists
166     */
167     /*
168     * Note: This currently works if the new K-line is a special case of an
169     * existing K-line, but not the other way round. To do that we would
170     * have to walk the hash and check every existing K-line. -A1kmm.
171     */
172     static int
173     already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
174     {
175     const char *reason;
176     struct irc_ssaddr iphost, *piphost;
177     struct MaskItem *conf = NULL;
178     int t = 0;
179     int aftype = 0;
180    
181     if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
182     {
183     #ifdef IPV6
184     if (t == HM_IPV6)
185     aftype = AF_INET6;
186     else
187     #endif
188     aftype = AF_INET;
189     piphost = &iphost;
190     }
191     else
192     piphost = NULL;
193    
194     if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
195     {
196     if (warn)
197     {
198     reason = conf->reason ? conf->reason : CONF_NOREASON;
199 michael 3110 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
200     luser, lhost, conf->user, conf->host, reason);
201 michael 2810 }
202    
203     return 1;
204     }
205    
206     return 0;
207     }
208    
209 adx 30 /* mo_kline()
210     *
211     * inputs - pointer to server
212     * - pointer to client
213     * - parameter count
214     * - parameter list
215     * output -
216     * side effects - k line is added
217     */
218 michael 2820 static int
219 michael 3156 mo_kline(struct Client *source_p, int parc, char *parv[])
220 adx 30 {
221 michael 2810 char buffer[IRCD_BUFSIZE];
222 adx 30 char *reason = NULL;
223     char *user = NULL;
224     char *host = NULL;
225     const char *current_date;
226     char *target_server = NULL;
227 michael 1632 struct MaskItem *conf;
228 adx 30 time_t tkline_time = 0;
229    
230 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_K))
231 adx 30 {
232 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
233 michael 2820 return 0;
234 adx 30 }
235    
236 michael 2810 if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
237     &tkline_time, &target_server, &reason) < 0)
238 michael 2820 return 0;
239 adx 30
240     if (target_server != NULL)
241     {
242 michael 2804 sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %lu %s %s :%s",
243     target_server, (unsigned long)tkline_time,
244     user, host, reason);
245 adx 30
246     /* Allow ON to apply local kline as well if it matches */
247 michael 1652 if (match(target_server, me.name))
248 michael 2820 return 0;
249 adx 30 }
250     else
251     cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
252 michael 1058 "%d %s %s :%s", tkline_time, user, host, reason);
253 adx 30
254 michael 1243 if (already_placed_kline(source_p, user, host, 1))
255 michael 2820 return 0;
256 adx 30
257 michael 3208 current_date = smalldate(0);
258 michael 1632 conf = conf_make(CONF_KLINE);
259 adx 30
260 michael 1646 conf->host = xstrdup(host);
261     conf->user = xstrdup(user);
262 adx 30
263     if (tkline_time != 0)
264 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
265     (int)(tkline_time/60), reason, current_date);
266 adx 30 else
267 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
268 adx 30
269 michael 1646 conf->reason = xstrdup(buffer);
270 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
271 michael 2820 return 0;
272 adx 30 }
273    
274     /* me_kline - handle remote kline. no propagation */
275 michael 2820 static int
276 michael 3156 me_kline(struct Client *source_p, int parc, char *parv[])
277 adx 30 {
278 michael 2810 char buffer[IRCD_BUFSIZE];
279 michael 1632 struct MaskItem *conf = NULL;
280 michael 1628 int tkline_time = 0;
281 michael 2810 const char *current_date;
282 michael 1622 char *kuser, *khost, *kreason;
283 adx 30
284 michael 352 if (parc != 6 || EmptyString(parv[5]))
285 michael 2820 return 0;
286 adx 30
287 michael 1652 if (match(parv[1], me.name))
288 michael 2820 return 0;
289 adx 30
290     tkline_time = valid_tkline(parv[2], TK_SECONDS);
291     kuser = parv[3];
292     khost = parv[4];
293     kreason = parv[5];
294    
295 michael 3208 current_date = smalldate(0);
296 adx 30
297 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
298     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
299 adx 30 source_p->username, source_p->host,
300     SHARED_KLINE))
301     {
302     if (!IsClient(source_p) ||
303 michael 1243 already_placed_kline(source_p, kuser, khost, 1))
304 michael 2820 return 0;
305 adx 30
306 michael 1632 conf = conf_make(CONF_KLINE);
307 michael 1646 conf->host = xstrdup(khost);
308     conf->user = xstrdup(kuser);
309 adx 30
310     if (tkline_time != 0)
311 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
312     (int)(tkline_time/60), kreason, current_date);
313 adx 30 else
314 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
315 adx 30
316 michael 1646 conf->reason = xstrdup(buffer);
317 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
318 adx 30 }
319 michael 2820
320     return 0;
321 adx 30 }
322    
323 michael 2820 static int
324 michael 3156 ms_kline(struct Client *source_p, int parc, char *parv[])
325 adx 30 {
326 michael 352 if (parc != 6 || EmptyString(parv[5]))
327 michael 2820 return 0;
328 adx 30
329     /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
330     /* oper target_server tkline_time user host reason */
331 michael 2820 sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s",
332 adx 30 parv[1], parv[2], parv[3], parv[4], parv[5]);
333    
334 michael 3156 return me_kline(source_p, parc, parv);
335 adx 30 }
336    
337     /*
338     ** mo_unkline
339     ** Added Aug 31, 1997
340     ** common (Keith Fralick) fralick@gate.net
341     **
342 michael 3096 ** parv[0] = command
343 adx 30 ** parv[1] = address to remove
344     *
345     *
346     */
347 michael 2820 static int
348 michael 3156 mo_unkline(struct Client *source_p, int parc, char *parv[])
349 adx 30 {
350     char *target_server = NULL;
351     char *user, *host;
352    
353 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
354 adx 30 {
355 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "unkline");
356 michael 2820 return 0;
357 adx 30 }
358    
359 michael 1622 if (EmptyString(parv[1]))
360 adx 30 {
361 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNKLINE");
362 michael 2820 return 0;
363 adx 30 }
364    
365     if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
366     &host, NULL, &target_server, NULL) < 0)
367 michael 2820 return 0;
368 adx 30
369     if (target_server != NULL)
370     {
371     sendto_match_servs(source_p, target_server, CAP_UNKLN,
372     "UNKLINE %s %s %s",
373     target_server, user, host);
374    
375     /* Allow ON to apply local unkline as well if it matches */
376 michael 1652 if (match(target_server, me.name))
377 michael 2820 return 0;
378 adx 30 }
379     else
380     cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
381 michael 1058 "%s %s", user, host);
382 adx 30
383 michael 1622 if (remove_kline_match(host, user))
384 adx 30 {
385 michael 3110 sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed",
386     user, host);
387 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
388 michael 1058 "%s has removed the K-Line for: [%s@%s]",
389     get_oper_name(source_p), user, host);
390 michael 1247 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
391 michael 2340 get_oper_name(source_p), user, host);
392 adx 30 }
393     else
394 michael 3110 sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found",
395     user, host);
396 michael 2820 return 0;
397 adx 30 }
398    
399     /* me_unkline()
400     *
401     * inputs - server
402     * - client
403     * - parc
404     * - parv
405     * outputs - none
406     * side effects - if server is authorized, kline is removed
407     * does not propagate message
408     */
409 michael 2820 static int
410 michael 3156 me_unkline(struct Client *source_p, int parc, char *parv[])
411 adx 30 {
412     const char *kuser, *khost;
413    
414     if (parc != 4)
415 michael 2820 return 0;
416 adx 30
417     kuser = parv[2];
418     khost = parv[3];
419    
420 michael 1652 if (!IsClient(source_p) || match(parv[1], me.name))
421 michael 2820 return 0;
422 adx 30
423 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
424     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
425     source_p->username, source_p->host,
426     SHARED_UNKLINE))
427 adx 30 {
428 michael 1622 if (remove_kline_match(khost, kuser))
429 adx 30 {
430 michael 3110 sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed",
431     kuser, khost);
432 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
433 michael 1622 "%s has removed the K-Line for: [%s@%s]",
434 adx 30 get_oper_name(source_p), kuser, khost);
435 michael 1247 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
436 michael 2340 get_oper_name(source_p), kuser, khost);
437 adx 30 }
438     else
439 michael 3110 sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found",
440     kuser, khost);
441 adx 30 }
442 michael 2820
443     return 0;
444 adx 30 }
445    
446     /* ms_unkline - propagates and handles a remote unkline message */
447 michael 2820 static int
448 michael 3156 ms_unkline(struct Client *source_p, int parc, char *parv[])
449 adx 30 {
450     if (parc != 4)
451 michael 2820 return 0;
452 adx 30
453     sendto_match_servs(source_p, parv[1], CAP_UNKLN,
454     "UNKLINE %s %s %s",
455     parv[1], parv[2], parv[3]);
456    
457 michael 3156 return me_unkline(source_p, parc, parv);
458 adx 30 }
459    
460 michael 2810 static struct Message kline_msgtab =
461 adx 30 {
462 michael 1230 "KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
463 michael 2810 { m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore }
464 michael 1230 };
465    
466 michael 2810 static struct Message unkline_msgtab =
467     {
468 michael 1230 "UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
469 michael 2810 { m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore }
470 michael 1230 };
471    
472     static void
473     module_init(void)
474     {
475     mod_add_cmd(&kline_msgtab);
476     mod_add_cmd(&unkline_msgtab);
477     add_capability("KLN", CAP_KLN, 1);
478     add_capability("UNKLN", CAP_UNKLN, 1);
479     }
480    
481     static void
482     module_exit(void)
483     {
484     mod_del_cmd(&kline_msgtab);
485     mod_del_cmd(&unkline_msgtab);
486     delete_capability("UNKLN");
487     delete_capability("KLN");
488     }
489    
490 michael 2810 struct module module_entry =
491     {
492 michael 1230 .node = { NULL, NULL, NULL },
493     .name = NULL,
494     .version = "$Revision$",
495     .handle = NULL,
496     .modinit = module_init,
497     .modexit = module_exit,
498     .flags = 0
499     };

Properties

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