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

Comparing ircd-hybrid/trunk/modules/m_dline.c (file contents):
Revision 1632 by michael, Sun Nov 4 15:37:10 2012 UTC vs.
Revision 2818 by michael, Tue Jan 14 18:29:05 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/UNDLINE command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 27 | Line 29
29   #include "channel.h"
30   #include "client.h"
31   #include "irc_string.h"
30 #include "sprintf_irc.h"
32   #include "conf.h"
33   #include "ircd.h"
34   #include "hostmask.h"
# Line 42 | Line 43
43   #include "parse.h"
44   #include "modules.h"
45   #include "conf_db.h"
46 + #include "memory.h"
47  
48  
49   /* apply_tdline()
# Line 56 | Line 58 | apply_dline(struct Client *source_p, str
58   {
59    if (tkline_time)
60    {
61 <    conf->hold = CurrentTime + tkline_time;
61 >    conf->until = CurrentTime + tkline_time;
62      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
63                           "%s added temporary %d min. D-Line for [%s] [%s]",
64                           get_oper_name(source_p), tkline_time/60,
# Line 96 | Line 98 | remove_dline_match(const char *host)
98   {
99    struct irc_ssaddr iphost, *piphost;
100    struct MaskItem *conf;
101 <  int t;
101 >  int t = 0;
102 >  int aftype = 0;
103  
104    if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
105    {
106   #ifdef IPV6
107      if (t == HM_IPV6)
108 <      t = AF_INET6;
108 >      aftype = AF_INET6;
109      else
110   #endif
111 <      t = AF_INET;
111 >      aftype = AF_INET;
112      piphost = &iphost;
113    }
114    else
112  {
113    t = 0;
115      piphost = NULL;
115  }
116  
117 <  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
117 >  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
118    {
119      if (IsConfDatabase(conf))
120      {
# Line 140 | Line 140 | static void
140   mo_dline(struct Client *client_p, struct Client *source_p,
141           int parc, char *parv[])
142   {
143 <  char def_reason[] = "<No reason specified>";
143 >  char def_reason[] = CONF_NOREASON;
144    char *dlhost = NULL, *reason = NULL;
145    char *target_server = NULL;
146    const char *creason;
# Line 148 | Line 148 | mo_dline(struct Client *client_p, struct
148    struct irc_ssaddr daddr;
149    struct MaskItem *conf=NULL;
150    time_t tkline_time=0;
151 <  int bits, t;
151 >  int bits = 0, aftype = 0, t = 0;
152    const char *current_date = NULL;
153    time_t cur_time;
154    char hostip[HOSTIPLEN + 1];
# Line 156 | Line 156 | mo_dline(struct Client *client_p, struct
156  
157    if (!HasOFlag(source_p, OPER_FLAG_DLINE))
158    {
159 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
160 <               me.name, source_p->name, "dline");
159 >    sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
160 >               source_p->name, "dline");
161      return;
162    }
163  
# Line 167 | Line 167 | mo_dline(struct Client *client_p, struct
167  
168    if (target_server != NULL)
169    {
170 <    if (HasID(source_p))
171 <    {
172 <      sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
173 <                    ":%s DLINE %s %lu %s :%s",
174 <                    source_p->id, target_server, (unsigned long)tkline_time,
175 <                    dlhost, reason);
176 <      sendto_server(NULL, CAP_DLN, CAP_TS6,
177 <                    ":%s DLINE %s %lu %s :%s",
178 <                    source_p->name, target_server, (unsigned long)tkline_time,
179 <                    dlhost, reason);
180 <    }
181 <    else
182 <      sendto_server(NULL, CAP_DLN, NOCAPS,
183 <                    ":%s DLINE %s %lu %s :%s",
184 <                    source_p->name, target_server, (unsigned long)tkline_time,
185 <                    dlhost, reason);
170 >    sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
171 >                       target_server, (unsigned long)tkline_time,
172 >                       dlhost, reason);
173  
174      /* Allow ON to apply local kline as well if it matches */
175 <    if (!match(target_server, me.name))
175 >    if (match(target_server, me.name))
176        return;
177    }
178    else
# Line 194 | Line 181 | mo_dline(struct Client *client_p, struct
181  
182    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
183    {
184 <    if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
184 >    if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
185        return;
186  
187      if (!MyConnect(target_p))
# Line 207 | Line 194 | mo_dline(struct Client *client_p, struct
194  
195      if (IsExemptKline(target_p))
196      {
197 <      sendto_one(source_p,
198 <                 ":%s NOTICE %s :%s is E-lined", me.name,
212 <                 source_p->name, target_p->name);
197 >      sendto_one(source_p, ":%s NOTICE %s :%s is E-lined",
198 >                 me.name, source_p->name, target_p->name);
199        return;
200      }
201  
# Line 231 | Line 217 | mo_dline(struct Client *client_p, struct
217  
218   #ifdef IPV6
219    if (t == HM_IPV6)
220 <    t = AF_INET6;
220 >    aftype = AF_INET6;
221    else
222   #endif
223 <    t = AF_INET;
223 >    aftype = AF_INET;
224  
225    parse_netmask(dlhost, &daddr, NULL);
226  
227 <  if ((conf = find_dline_conf(&daddr, t)) != NULL)
227 >  if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
228    {
229      creason = conf->reason ? conf->reason : def_reason;
230 +
231      if (IsConfExemptKline(conf))
232 <      sendto_one(source_p,
233 <                 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
247 <                 me.name, source_p->name, dlhost, conf->host, creason);
232 >      sendto_one(source_p, ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
233 >                 me.name, source_p->name, dlhost, conf->host, creason);
234      else
235 <      sendto_one(source_p,
236 <                 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
251 <                 me.name, source_p->name, dlhost, conf->host, creason);
235 >      sendto_one(source_p, ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
236 >                 me.name, source_p->name, dlhost, conf->host, creason);
237      return;
238    }
239  
# Line 259 | Line 244 | mo_dline(struct Client *client_p, struct
244      return;
245  
246    conf = conf_make(CONF_DLINE);
247 <  DupString(conf->host, dlhost);
247 >  conf->host = xstrdup(dlhost);
248  
249    if (tkline_time != 0)
250      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
# Line 267 | Line 252 | mo_dline(struct Client *client_p, struct
252    else
253      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
254  
255 <  DupString(conf->reason, buffer);
255 >  conf->reason = xstrdup(buffer);
256    apply_dline(source_p, conf, tkline_time);
257    rehashed_klines = 1;
258   }
# Line 276 | Line 261 | static void
261   ms_dline(struct Client *client_p, struct Client *source_p,
262           int parc, char *parv[])
263   {
264 <  char def_reason[] = "<No reason specified>";
264 >  char def_reason[] = CONF_NOREASON;
265    char *dlhost, *reason;
266    const char *creason;
267    const struct Client *target_p = NULL;
268    struct irc_ssaddr daddr;
269    struct MaskItem *conf=NULL;
270    time_t tkline_time=0;
271 <  int bits, t;
271 >  int bits = 0, aftype = 0, t = 0;
272    const char *current_date = NULL;
273    time_t cur_time;
274    char hostip[HOSTIPLEN + 1];
# Line 298 | Line 283 | ms_dline(struct Client *client_p, struct
283                       "DLINE %s %s %s :%s",
284                       parv[1], parv[2], parv[3], parv[4]);
285  
286 <  if (!match(parv[1], me.name))
286 >  if (match(parv[1], me.name))
287      return;
288  
289    tkline_time = valid_tkline(parv[2], TK_SECONDS);
290    dlhost = parv[3];
291    reason = parv[4];
292  
293 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
293 >  if (HasFlag(source_p, FLAGS_SERVICE) ||
294 >      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
295                                source_p->username, source_p->host,
296                                SHARED_DLINE))
297    {
# Line 313 | Line 299 | ms_dline(struct Client *client_p, struct
299        return;
300      if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
301      {
302 <      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
302 >      if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
303          return;
304  
305        if (!MyConnect(target_p))
# Line 350 | Line 336 | ms_dline(struct Client *client_p, struct
336  
337   #ifdef IPV6
338      if (t == HM_IPV6)
339 <      t = AF_INET6;
339 >      aftype= AF_INET6;
340      else
341   #endif
342 <      t = AF_INET;
342 >      aftype = AF_INET;
343  
344      parse_netmask(dlhost, &daddr, NULL);
345  
346 <    if ((conf = find_dline_conf(&daddr, t)) != NULL)
346 >    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
347      {
348        creason = conf->reason ? conf->reason : def_reason;
349        if (IsConfExemptKline(conf))
# Line 378 | Line 364 | ms_dline(struct Client *client_p, struct
364        return;
365  
366      conf = conf_make(CONF_DLINE);
367 <    DupString(conf->host, dlhost);
367 >    conf->host = xstrdup(dlhost);
368  
369      if (tkline_time != 0)
370        snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
# Line 386 | Line 372 | ms_dline(struct Client *client_p, struct
372      else
373        snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
374  
375 <    DupString(conf->reason, buffer);
375 >    conf->reason = xstrdup(buffer);
376      apply_dline(source_p, conf, tkline_time);
377      rehashed_klines = 1;
378    }
# Line 410 | Line 396 | mo_undline(struct Client *client_p, stru
396  
397    if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
398    {
399 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
400 <               me.name, source_p->name, "undline");
399 >    sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
400 >               source_p->name, "undline");
401      return;
402    }
403  
# Line 432 | Line 418 | mo_undline(struct Client *client_p, stru
418                         "UNDLINE %s %s", target_server, addr);
419  
420      /* Allow ON to apply local unkline as well if it matches */
421 <    if (!match(target_server, me.name))
421 >    if (match(target_server, me.name))
422        return;
423    }
424    else
# Line 441 | Line 427 | mo_undline(struct Client *client_p, stru
427  
428    if (remove_dline_match(addr))
429    {
430 <    sendto_one(source_p,
445 <               ":%s NOTICE %s :D-Line for [%s] is removed",
430 >    sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
431                 me.name, source_p->name, addr);
432      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
433                           "%s has removed the D-Line for: [%s]",
# Line 466 | Line 451 | me_undline(struct Client *client_p, stru
451  
452    addr = parv[2];
453  
454 <  if (!IsClient(source_p) || !match(parv[1], me.name))
454 >  if (!IsClient(source_p) || match(parv[1], me.name))
455      return;
456  
457 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
458 <                                   source_p->servptr->name,
459 <                                   source_p->username, source_p->host,
460 <                                   SHARED_UNDLINE))
457 >  if (HasFlag(source_p, FLAGS_SERVICE) ||
458 >      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
459 >                              source_p->username, source_p->host,
460 >                              SHARED_UNDLINE))
461    {
462      if (remove_dline_match(addr))
463      {
464 <      sendto_one(source_p,
480 <                 ":%s NOTICE %s :D-Line for [%s] is removed",
464 >      sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
465                   me.name, source_p->name, addr);
466        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
467                             "%s has removed the D-Line for: [%s]",
468                             get_oper_name(source_p), addr);
469 <      ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
469 >      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
470             get_oper_name(source_p), addr);
471      }
472      else
# Line 499 | Line 483 | ms_undline(struct Client *client_p, stru
483      return;
484  
485    sendto_match_servs(source_p, parv[1], CAP_UNDLN,
486 <                     "UNDLINE %s %s %s",
486 >                     "UNDLINE %s %s",
487                       parv[1], parv[2]);
488  
489    me_undline(client_p, source_p, parc, parv);
490   }
491  
492 < static struct Message dline_msgtab = {
492 > static struct Message dline_msgtab =
493 > {
494    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
495 <   {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
495 >  { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
496   };
497  
498 < static struct Message undline_msgtab = {
498 > static struct Message undline_msgtab =
499 > {
500    "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
501 <   {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
501 >  { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
502   };
503  
504   static void
# Line 533 | Line 519 | module_exit(void)
519    delete_capability("DLN");
520   }
521  
522 < struct module module_entry = {
522 > struct module module_entry =
523 > {
524    .node    = { NULL, NULL, NULL },
525    .name    = NULL,
526    .version = "$Revision$",

Diff Legend

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