ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_dline.c
(Generate patch)

Comparing ircd-hybrid/trunk/modules/m_dline.c (file contents):
Revision 2340 by michael, Wed Jul 3 13:31:23 2013 UTC vs.
Revision 3348 by michael, Sun Apr 20 14:09:22 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_dline.c: Bans a user.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 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
# Line 18 | Line 17
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 < *  $Id$
20 > */
21 >
22 > /*! \file m_dline.c
23 > * \brief Includes required functions for processing the DLINE command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
27 #include "channel.h"
29   #include "client.h"
30   #include "irc_string.h"
31   #include "conf.h"
32   #include "ircd.h"
33   #include "hostmask.h"
34   #include "numeric.h"
34 #include "fdlist.h"
35 #include "s_bsd.h"
35   #include "log.h"
36 < #include "s_misc.h"
36 > #include "misc.h"
37   #include "send.h"
38   #include "hash.h"
39 < #include "s_serv.h"
39 > #include "server.h"
40   #include "parse.h"
41   #include "modules.h"
42   #include "conf_db.h"
# Line 61 | Line 60 | apply_dline(struct Client *source_p, str
60                           "%s added temporary %d min. D-Line for [%s] [%s]",
61                           get_oper_name(source_p), tkline_time/60,
62                           conf->host, conf->reason);
63 <    sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
64 <               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
66 <               source_p->name, tkline_time/60, conf->host);
63 >    sendto_one_notice(source_p, &me, ":Added temporary %d min. D-Line [%s]",
64 >                      tkline_time/60, conf->host);
65      ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
66           get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
67    }
# Line 72 | Line 70 | apply_dline(struct Client *source_p, str
70      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
71                           "%s added D-Line for [%s] [%s]",
72                           get_oper_name(source_p), conf->host, conf->reason);
73 <    sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
76 <               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
77 <               source_p->name, conf->host);
73 >    sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
74      ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
75           get_oper_name(source_p), conf->host, conf->reason);
76  
# Line 86 | Line 82 | apply_dline(struct Client *source_p, str
82    rehashed_klines = 1;
83   }
84  
89 /* static int remove_tdline_match(const char *host, const char *user)
90 * Input: An ip to undline.
91 * Output: returns YES on success, NO if no tdline removed.
92 * Side effects: Any matching tdlines are removed.
93 */
94 static int
95 remove_dline_match(const char *host)
96 {
97  struct irc_ssaddr iphost, *piphost;
98  struct MaskItem *conf;
99  int t = 0;
100  int aftype = 0;
101
102  if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
103  {
104 #ifdef IPV6
105    if (t == HM_IPV6)
106      aftype = AF_INET6;
107    else
108 #endif
109      aftype = AF_INET;
110    piphost = &iphost;
111  }
112  else
113    piphost = NULL;
114
115  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
116  {
117    if (IsConfDatabase(conf))
118    {
119      delete_one_address_conf(host, conf);
120      return 1;
121    }
122  }
123
124  return 0;
125 }
126
85   /* mo_dline()
86   *
87   * inputs       - pointer to server
# Line 134 | Line 92 | remove_dline_match(const char *host)
92   * side effects - D line is added
93   *
94   */
95 < static void
96 < mo_dline(struct Client *client_p, struct Client *source_p,
139 <         int parc, char *parv[])
95 > static int
96 > mo_dline(struct Client *source_p, int parc, char *parv[])
97   {
98    char def_reason[] = CONF_NOREASON;
99    char *dlhost = NULL, *reason = NULL;
# Line 148 | Line 105 | mo_dline(struct Client *client_p, struct
105    time_t tkline_time=0;
106    int bits = 0, aftype = 0, t = 0;
107    const char *current_date = NULL;
151  time_t cur_time;
108    char hostip[HOSTIPLEN + 1];
109    char buffer[IRCD_BUFSIZE];
110  
111    if (!HasOFlag(source_p, OPER_FLAG_DLINE))
112    {
113 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
114 <               me.name, source_p->name, "dline");
159 <    return;
113 >    sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
114 >    return 0;
115    }
116  
117    if (parse_aline("DLINE", source_p,  parc, parv, AWILD, &dlhost,
118                    NULL, &tkline_time, &target_server, &reason) < 0)
119 <    return;
119 >    return 0;
120  
121    if (target_server != NULL)
122    {
123 <    if (HasID(source_p))
124 <    {
125 <      sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
171 <                    ":%s DLINE %s %lu %s :%s",
172 <                    source_p->id, target_server, (unsigned long)tkline_time,
173 <                    dlhost, reason);
174 <      sendto_server(NULL, CAP_DLN, CAP_TS6,
175 <                    ":%s DLINE %s %lu %s :%s",
176 <                    source_p->name, target_server, (unsigned long)tkline_time,
177 <                    dlhost, reason);
178 <    }
179 <    else
180 <      sendto_server(NULL, CAP_DLN, NOCAPS,
181 <                    ":%s DLINE %s %lu %s :%s",
182 <                    source_p->name, target_server, (unsigned long)tkline_time,
183 <                    dlhost, reason);
123 >    sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
124 >                       target_server, (unsigned long)tkline_time,
125 >                       dlhost, reason);
126  
127      /* Allow ON to apply local kline as well if it matches */
128      if (match(target_server, me.name))
129 <      return;
129 >      return 0;
130    }
131    else
132      cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
# Line 192 | Line 134 | mo_dline(struct Client *client_p, struct
134  
135    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
136    {
137 <    if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
138 <      return;
137 >    if ((target_p = find_chasing(source_p, dlhost)) == NULL)
138 >      return 0;
139  
140      if (!MyConnect(target_p))
141      {
142 <      sendto_one(source_p,
143 <                 ":%s NOTICE %s :Can't DLINE nick on another server",
202 <                 me.name, source_p->name);
203 <      return;
142 >      sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
143 >      return 0;
144      }
145  
146      if (IsExemptKline(target_p))
147      {
148 <      sendto_one(source_p,
149 <                 ":%s NOTICE %s :%s is E-lined", me.name,
150 <                 source_p->name, target_p->name);
211 <      return;
148 >      sendto_one_notice(source_p, &me, ":%s is E-lined",
149 >                        target_p->name);
150 >      return 0;
151      }
152  
153      getnameinfo((struct sockaddr *)&target_p->localClient->ip,
# Line 221 | Line 160 | mo_dline(struct Client *client_p, struct
160  
161    if (bits < 8)
162    {
163 <    sendto_one(source_p,
164 <               ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
226 <               me.name, source_p->name);
227 <    return;
163 >    sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
164 >    return 0;
165    }
166  
167   #ifdef IPV6
# Line 239 | Line 176 | mo_dline(struct Client *client_p, struct
176    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
177    {
178      creason = conf->reason ? conf->reason : def_reason;
179 +
180      if (IsConfExemptKline(conf))
181 <      sendto_one(source_p,
182 <                 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
245 <                 me.name, source_p->name, dlhost, conf->host, creason);
181 >      sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
182 >                        dlhost, conf->host, creason);
183      else
184 <      sendto_one(source_p,
185 <                 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
186 <                 me.name, source_p->name, dlhost, conf->host, creason);
250 <    return;
184 >      sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
185 >                        dlhost, conf->host, creason);
186 >    return 0;
187    }
188  
189 <  cur_time = CurrentTime;
254 <  current_date = smalldate(cur_time);
189 >  current_date = smalldate(0);
190  
191    if (!valid_comment(source_p, reason, 1))
192 <    return;
192 >    return 0;
193  
194    conf = conf_make(CONF_DLINE);
195    conf->host = xstrdup(dlhost);
# Line 268 | Line 203 | mo_dline(struct Client *client_p, struct
203    conf->reason = xstrdup(buffer);
204    apply_dline(source_p, conf, tkline_time);
205    rehashed_klines = 1;
206 +  return 0;
207   }
208  
209 < static void
210 < ms_dline(struct Client *client_p, struct Client *source_p,
275 <         int parc, char *parv[])
209 > static int
210 > ms_dline(struct Client *source_p, int parc, char *parv[])
211   {
212    char def_reason[] = CONF_NOREASON;
213    char *dlhost, *reason;
# Line 283 | Line 218 | ms_dline(struct Client *client_p, struct
218    time_t tkline_time=0;
219    int bits = 0, aftype = 0, t = 0;
220    const char *current_date = NULL;
286  time_t cur_time;
221    char hostip[HOSTIPLEN + 1];
222    char buffer[IRCD_BUFSIZE];
223  
224    if (parc != 5 || EmptyString(parv[4]))
225 <    return;
225 >    return 0;
226  
227    /* parv[0]  parv[1]        parv[2]      parv[3]  parv[4] */
228    /* oper     target_server  tkline_time  host     reason  */
# Line 297 | Line 231 | ms_dline(struct Client *client_p, struct
231                       parv[1], parv[2], parv[3], parv[4]);
232  
233    if (match(parv[1], me.name))
234 <    return;
234 >    return 0;
235  
236    tkline_time = valid_tkline(parv[2], TK_SECONDS);
237    dlhost = parv[3];
238    reason = parv[4];
239  
240 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
240 >  if (HasFlag(source_p, FLAGS_SERVICE) ||
241 >      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
242                                source_p->username, source_p->host,
243                                SHARED_DLINE))
244    {
245      if (!IsClient(source_p))
246 <      return;
246 >      return 0;
247 >
248      if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
249      {
250 <      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
251 <        return;
250 >      if ((target_p = find_chasing(source_p, dlhost)) == NULL)
251 >        return 0;
252  
253        if (!MyConnect(target_p))
254        {
255 <        sendto_one(source_p,
256 <                   ":%s NOTICE %s :Can't DLINE nick on another server",
321 <                   me.name, source_p->name);
322 <        return;
255 >        sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
256 >        return 0;
257        }
258  
259        if (IsExemptKline(target_p))
260        {
261 <        sendto_one(source_p,
262 <                   ":%s NOTICE %s :%s is E-lined", me.name,
329 <                   source_p->name, target_p->name);
330 <        return;
261 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
262 >        return 0;
263        }
264  
265        getnameinfo((struct sockaddr *)&target_p->localClient->ip,
# Line 340 | Line 272 | ms_dline(struct Client *client_p, struct
272  
273      if (bits < 8)
274      {
275 <      sendto_one(source_p,
276 <                 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
345 <                 me.name, source_p->name);
346 <      return;
275 >      sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
276 >      return 0;
277      }
278  
279   #ifdef IPV6
# Line 359 | Line 289 | ms_dline(struct Client *client_p, struct
289      {
290        creason = conf->reason ? conf->reason : def_reason;
291        if (IsConfExemptKline(conf))
292 <        sendto_one(source_p,
293 <                   ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
364 <                   me.name, source_p->name, dlhost, conf->host, creason);
292 >        sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
293 >                          dlhost, conf->host, creason);
294        else
295 <        sendto_one(source_p,
296 <                   ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
297 <                   me.name, source_p->name, dlhost, conf->host, creason);
369 <      return;
295 >        sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
296 >                          dlhost, conf->host, creason);
297 >      return 0;
298      }
299  
300 <    cur_time = CurrentTime;
373 <    current_date = smalldate(cur_time);
300 >    current_date = smalldate(0);
301  
302      if (!valid_comment(source_p, reason, 1))
303 <      return;
303 >      return 0;
304  
305      conf = conf_make(CONF_DLINE);
306      conf->host = xstrdup(dlhost);
# Line 388 | Line 315 | ms_dline(struct Client *client_p, struct
315      apply_dline(source_p, conf, tkline_time);
316      rehashed_klines = 1;
317    }
391 }
392
393 /*
394 ** m_undline
395 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
396 ** based totally on m_unkline
397 ** added to hybrid-7 7/11/2000 --is
398 **
399 **      parv[0] = sender nick
400 **      parv[1] = dline to remove
401 */
402 static void
403 mo_undline(struct Client *client_p, struct Client *source_p,
404           int parc, char *parv[])
405 {
406  char *addr = NULL, *user = NULL;
407  char *target_server = NULL;
408
409  if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
410  {
411    sendto_one(source_p, form_str(ERR_NOPRIVS),
412               me.name, source_p->name, "undline");
413    return;
414  }
415
416  if (parc < 2 || EmptyString(parv[1]))
417  {
418    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
419               me.name, source_p->name, "UNDLINE");
420    return;
421  }
422
423  if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
424                  &addr, NULL, &target_server, NULL) < 0)
425    return;
426
427  if (target_server != NULL)
428  {
429    sendto_match_servs(source_p, target_server, CAP_UNDLN,
430                       "UNDLINE %s %s", target_server, addr);
431
432    /* Allow ON to apply local unkline as well if it matches */
433    if (match(target_server, me.name))
434      return;
435  }
436  else
437    cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
438                   "%s", addr);
439
440  if (remove_dline_match(addr))
441  {
442    sendto_one(source_p,
443               ":%s NOTICE %s :D-Line for [%s] is removed",
444               me.name, source_p->name, addr);
445    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
446                         "%s has removed the D-Line for: [%s]",
447                         get_oper_name(source_p), addr);
448    ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
449         get_oper_name(source_p), addr);
450  }
451  else
452    sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
453               me.name, source_p->name, addr);
454 }
318  
319 < static void
457 < me_undline(struct Client *client_p, struct Client *source_p,
458 <           int parc, char *parv[])
459 < {
460 <  const char *addr = NULL;
461 <
462 <  if (parc != 3 || EmptyString(parv[2]))
463 <    return;
464 <
465 <  addr = parv[2];
466 <
467 <  if (!IsClient(source_p) || match(parv[1], me.name))
468 <    return;
469 <
470 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
471 <                                   source_p->servptr->name,
472 <                                   source_p->username, source_p->host,
473 <                                   SHARED_UNDLINE))
474 <  {
475 <    if (remove_dline_match(addr))
476 <    {
477 <      sendto_one(source_p,
478 <                 ":%s NOTICE %s :D-Line for [%s] is removed",
479 <                 me.name, source_p->name, addr);
480 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
481 <                           "%s has removed the D-Line for: [%s]",
482 <                           get_oper_name(source_p), addr);
483 <      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
484 <           get_oper_name(source_p), addr);
485 <    }
486 <    else
487 <      sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
488 <                 me.name, source_p->name, addr);
489 <  }
319 >  return 0;
320   }
321  
322 < static void
493 < ms_undline(struct Client *client_p, struct Client *source_p,
494 <           int parc, char *parv[])
322 > static struct Message dline_msgtab =
323   {
496  if (parc != 3 || EmptyString(parv[2]))
497    return;
498
499  sendto_match_servs(source_p, parv[1], CAP_UNDLN,
500                     "UNDLINE %s %s",
501                     parv[1], parv[2]);
502
503  me_undline(client_p, source_p, parc, parv);
504 }
505
506 static struct Message dline_msgtab = {
324    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
325 <   {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
509 < };
510 <
511 < static struct Message undline_msgtab = {
512 <  "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
513 <   {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
325 >  { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
326   };
327  
328   static void
329   module_init(void)
330   {
331    mod_add_cmd(&dline_msgtab);
520  mod_add_cmd(&undline_msgtab);
332    add_capability("DLN", CAP_DLN, 1);
522  add_capability("UNDLN", CAP_UNDLN, 1);
333   }
334  
335   static void
336   module_exit(void)
337   {
338    mod_del_cmd(&dline_msgtab);
529  mod_del_cmd(&undline_msgtab);
530  delete_capability("UNDLN");
339    delete_capability("DLN");
340   }
341  
342 < struct module module_entry = {
342 > struct module module_entry =
343 > {
344    .node    = { NULL, NULL, NULL },
345    .name    = NULL,
346    .version = "$Revision$",

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)