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 2888 by michael, Tue Jan 21 17:47:11 2014 UTC vs.
ircd-hybrid/branches/8.2.x/modules/m_dline.c (file contents), Revision 3377 by michael, Thu Apr 24 16:15:51 2014 UTC

# Line 20 | Line 20
20   */
21  
22   /*! \file m_dline.c
23 < * \brief Includes required functions for processing the DLINE/UNDLINE command.
23 > * \brief Includes required functions for processing the DLINE command.
24   * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29 #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"
36 #include "fdlist.h"
37 #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 63 | 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),
68 <               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 74 | 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]",
78 <               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
79 <               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 88 | Line 82 | apply_dline(struct Client *source_p, str
82    rehashed_klines = 1;
83   }
84  
91 /* static int remove_tdline_match(const char *host, const char *user)
92 * Input: An ip to undline.
93 * Output: returns YES on success, NO if no tdline removed.
94 * Side effects: Any matching tdlines are removed.
95 */
96 static int
97 remove_dline_match(const char *host)
98 {
99  struct irc_ssaddr iphost, *piphost;
100  struct MaskItem *conf;
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      aftype = AF_INET6;
109    else
110 #endif
111      aftype = AF_INET;
112    piphost = &iphost;
113  }
114  else
115    piphost = NULL;
116
117  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
118  {
119    if (IsConfDatabase(conf))
120    {
121      delete_one_address_conf(host, conf);
122      return 1;
123    }
124  }
125
126  return 0;
127 }
128
85   /* mo_dline()
86   *
87   * inputs       - pointer to server
# Line 137 | Line 93 | remove_dline_match(const char *host)
93   *
94   */
95   static int
96 < mo_dline(struct Client *client_p, struct Client *source_p,
141 <         int parc, char *parv[])
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 150 | 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;
153  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), me.name,
160 <               source_p->name, "dline");
113 >    sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
114      return 0;
115    }
116  
# Line 165 | Line 118 | mo_dline(struct Client *client_p, struct
118                    NULL, &tkline_time, &target_server, &reason) < 0)
119      return 0;
120  
121 <  if (target_server != NULL)
121 >  if (target_server)
122    {
123      sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
124                         target_server, (unsigned long)tkline_time,
# Line 181 | 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(source_p, dlhost, NULL)) == NULL)
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,
190 <                 ":%s NOTICE %s :Can't DLINE nick on another server",
191 <                 me.name, source_p->name);
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, ":%s NOTICE %s :%s is E-lined",
149 <                 me.name, source_p->name, target_p->name);
148 >      sendto_one_notice(source_p, &me, ":%s is E-lined",
149 >                        target_p->name);
150        return 0;
151      }
152  
# Line 209 | Line 160 | mo_dline(struct Client *client_p, struct
160  
161    if (bits < 8)
162    {
163 <    sendto_one(source_p,
213 <               ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
214 <               me.name, source_p->name);
163 >    sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
164      return 0;
165    }
166  
# Line 224 | Line 173 | mo_dline(struct Client *client_p, struct
173  
174    parse_netmask(dlhost, &daddr, NULL);
175  
176 <  if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
176 >  if ((conf = find_dline_conf(&daddr, aftype)))
177    {
178      creason = conf->reason ? conf->reason : def_reason;
179  
180      if (IsConfExemptKline(conf))
181 <      sendto_one(source_p, ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
182 <                 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, ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
185 <                 me.name, source_p->name, dlhost, conf->host, creason);
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;
241 <  current_date = smalldate(cur_time);
189 >  current_date = smalldate(0);
190  
191    if (!valid_comment(source_p, reason, 1))
192      return 0;
# Line 246 | Line 194 | mo_dline(struct Client *client_p, struct
194    conf = conf_make(CONF_DLINE);
195    conf->host = xstrdup(dlhost);
196  
197 <  if (tkline_time != 0)
197 >  if (tkline_time)
198      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
199               (int)(tkline_time/60), reason, current_date);
200    else
# Line 259 | Line 207 | mo_dline(struct Client *client_p, struct
207   }
208  
209   static int
210 < ms_dline(struct Client *client_p, struct Client *source_p,
263 <         int parc, char *parv[])
210 > ms_dline(struct Client *source_p, int parc, char *parv[])
211   {
212    char def_reason[] = CONF_NOREASON;
213    char *dlhost, *reason;
# Line 271 | 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;
274  time_t cur_time;
221    char hostip[HOSTIPLEN + 1];
222    char buffer[IRCD_BUFSIZE];
223  
# Line 301 | Line 247 | ms_dline(struct Client *client_p, struct
247  
248      if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
249      {
250 <      if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
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,
310 <                   ":%s NOTICE %s :Can't DLINE nick on another server",
311 <                   me.name, source_p->name);
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,
318 <                   ":%s NOTICE %s :%s is E-lined", me.name,
319 <                   source_p->name, target_p->name);
261 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
262          return 0;
263        }
264  
# Line 330 | Line 272 | ms_dline(struct Client *client_p, struct
272  
273      if (bits < 8)
274      {
275 <      sendto_one(source_p,
334 <                 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
335 <                 me.name, source_p->name);
275 >      sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
276        return 0;
277      }
278  
# Line 345 | Line 285 | ms_dline(struct Client *client_p, struct
285  
286      parse_netmask(dlhost, &daddr, NULL);
287  
288 <    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
288 >    if ((conf = find_dline_conf(&daddr, aftype)))
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",
354 <                   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",
358 <                   me.name, source_p->name, dlhost, conf->host, creason);
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;
363 <    current_date = smalldate(cur_time);
300 >    current_date = smalldate(0);
301  
302      if (!valid_comment(source_p, reason, 1))
303        return 0;
# Line 368 | Line 305 | ms_dline(struct Client *client_p, struct
305      conf = conf_make(CONF_DLINE);
306      conf->host = xstrdup(dlhost);
307  
308 <    if (tkline_time != 0)
308 >    if (tkline_time)
309        snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
310                 (int)(tkline_time/60), reason, current_date);
311      else
# Line 382 | Line 319 | ms_dline(struct Client *client_p, struct
319    return 0;
320   }
321  
385 /*
386 ** m_undline
387 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
388 ** based totally on m_unkline
389 ** added to hybrid-7 7/11/2000 --is
390 **
391 **      parv[0] = sender nick
392 **      parv[1] = dline to remove
393 */
394 static int
395 mo_undline(struct Client *client_p, struct Client *source_p,
396           int parc, char *parv[])
397 {
398  char *addr = NULL, *user = NULL;
399  char *target_server = NULL;
400
401  if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
402  {
403    sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
404               source_p->name, "undline");
405    return 0;
406  }
407
408  if (parc < 2 || EmptyString(parv[1]))
409  {
410    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
411               me.name, source_p->name, "UNDLINE");
412    return 0;
413  }
414
415  if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
416                  &addr, NULL, &target_server, NULL) < 0)
417    return 0;
418
419  if (target_server != NULL)
420  {
421    sendto_match_servs(source_p, target_server, CAP_UNDLN,
422                       "UNDLINE %s %s", target_server, addr);
423
424    /* Allow ON to apply local unkline as well if it matches */
425    if (match(target_server, me.name))
426      return 0;
427  }
428  else
429    cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
430                   "%s", addr);
431
432  if (remove_dline_match(addr))
433  {
434    sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
435               me.name, source_p->name, addr);
436    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
437                         "%s has removed the D-Line for: [%s]",
438                         get_oper_name(source_p), addr);
439    ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
440         get_oper_name(source_p), addr);
441  }
442  else
443    sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
444               me.name, source_p->name, addr);
445  return 0;
446 }
447
448 static int
449 ms_undline(struct Client *client_p, struct Client *source_p,
450           int parc, char *parv[])
451 {
452  const char *addr = parv[1];
453
454  if (parc != 3 || EmptyString(parv[2]))
455    return 0;
456
457  sendto_match_servs(source_p, parv[1], CAP_UNDLN,
458                     "UNDLINE %s %s",
459                     parv[1], parv[2]);
460
461  if (!IsClient(source_p) || match(parv[1], me.name))
462    return 0;
463
464  if (HasFlag(source_p, FLAGS_SERVICE) ||
465      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
466                              source_p->username, source_p->host,
467                              SHARED_UNDLINE))
468  {
469    if (remove_dline_match(addr))
470    {
471      sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
472                 me.name, source_p->name, addr);
473      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
474                           "%s has removed the D-Line for: [%s]",
475                           get_oper_name(source_p), addr);
476      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
477           get_oper_name(source_p), addr);
478    }
479    else
480      sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
481                 me.name, source_p->name, addr);
482  }
483
484  return 0;
485 }
486
322   static struct Message dline_msgtab =
323   {
324    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
325    { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
326   };
327  
493 static struct Message undline_msgtab =
494 {
495  "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
496  { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
497 };
498
328   static void
329   module_init(void)
330   {
331    mod_add_cmd(&dline_msgtab);
503  mod_add_cmd(&undline_msgtab);
332    add_capability("DLN", CAP_DLN, 1);
505  add_capability("UNDLN", CAP_UNDLN, 1);
333   }
334  
335   static void
336   module_exit(void)
337   {
338    mod_del_cmd(&dline_msgtab);
512  mod_del_cmd(&undline_msgtab);
513  delete_capability("UNDLN");
339    delete_capability("DLN");
340   }
341  

Diff Legend

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