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-8/modules/m_dline.c (file contents), Revision 1298 by michael, Tue Feb 28 18:51:13 2012 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 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 "sprintf_irc.h"
31 > #include "conf.h"
32   #include "ircd.h"
33   #include "hostmask.h"
34   #include "numeric.h"
35 < #include "fdlist.h"
36 < #include "s_bsd.h"
36 < #include "s_conf.h"
37 < #include "s_log.h"
38 < #include "s_misc.h"
35 > #include "log.h"
36 > #include "misc.h"
37   #include "send.h"
38   #include "hash.h"
39 < #include "s_serv.h"
42 < #include "s_gline.h"
39 > #include "server.h"
40   #include "parse.h"
41   #include "modules.h"
42 + #include "conf_db.h"
43 + #include "memory.h"
44  
45  
46   /* apply_tdline()
# Line 51 | Line 50
50   * side effects - tkline as given is placed
51   */
52   static void
53 < apply_tdline(struct Client *source_p, struct ConfItem *conf,
54 <             const char *current_date, int tkline_time)
53 > apply_dline(struct Client *source_p, struct MaskItem *conf,
54 >            time_t tkline_time)
55   {
56 <  struct AccessItem *aconf;
58 <
59 <  aconf = map_to_conf(conf);
60 <  aconf->hold = CurrentTime + tkline_time;
61 <
62 <  add_temp_line(conf);
63 <  sendto_realops_flags(UMODE_ALL, L_ALL,
64 <                       "%s added temporary %d min. D-Line for [%s] [%s]",
65 <                       get_oper_name(source_p), tkline_time/60,
66 <                       aconf->host, aconf->reason);
67 <
68 <  sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
69 <             MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
70 <             source_p->name, tkline_time/60, aconf->host);
71 <  ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
72 <       source_p->name, tkline_time/60, aconf->host, aconf->reason);
73 <
74 <  rehashed_klines = 1;
75 < }
76 <
77 < /* static int remove_tdline_match(const char *host, const char *user)
78 < * Input: An ip to undline.
79 < * Output: returns YES on success, NO if no tdline removed.
80 < * Side effects: Any matching tdlines are removed.
81 < */
82 < static int
83 < remove_tdline_match(const char *host)
84 < {
85 <  struct AccessItem *td_conf;
86 <  dlink_node *td_node;
87 <  struct irc_ssaddr addr, caddr;
88 <  int nm_t, cnm_t, bits, cbits;
89 <
90 <  nm_t = parse_netmask(host, &addr, &bits);
91 <
92 <  DLINK_FOREACH(td_node, temporary_dlines.head)
56 >  if (tkline_time)
57    {
58 <    td_conf = map_to_conf(td_node->data);
59 <    cnm_t   = parse_netmask(td_conf->host, &caddr, &cbits);
60 <
61 <    if (cnm_t != nm_t)
62 <      continue;
58 >    conf->until = CurrentTime + tkline_time;
59 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
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_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 >  }
68 >  else
69 >  {
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_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  
100    if ((nm_t == HM_HOST && !irccmp(td_conf->host, host)) ||
101        (nm_t == HM_IPV4 && bits == cbits && match_ipv4(&addr, &caddr, bits))
102 #ifdef IPV6
103     || (nm_t == HM_IPV6 && bits == cbits && match_ipv6(&addr, &caddr, bits))
104 #endif
105      )
106    {
107      dlinkDelete(td_node, &temporary_dlines);
108      delete_one_address_conf(td_conf->host, td_conf);
109      return 1;
110    }
77    }
78  
79 <  return 0;
79 >  SetConfDatabase(conf);
80 >  conf->setat = CurrentTime;
81 >  add_conf_by_address(CONF_DLINE, conf);
82 >  rehashed_klines = 1;
83   }
84  
85   /* mo_dline()
# Line 123 | Line 92 | remove_tdline_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,
128 <         int parc, char *parv[])
95 > static int
96 > mo_dline(struct Client *source_p, int parc, char *parv[])
97   {
98 <  char def_reason[] = "No reason";
99 <  char *dlhost, *oper_reason, *reason;
98 >  char def_reason[] = CONF_NOREASON;
99 >  char *dlhost = NULL, *reason = NULL;
100 >  char *target_server = NULL;
101    const char *creason;
102    const struct Client *target_p = NULL;
103    struct irc_ssaddr daddr;
104 <  struct ConfItem *conf=NULL;
136 <  struct AccessItem *aconf=NULL;
104 >  struct MaskItem *conf=NULL;
105    time_t tkline_time=0;
106 <  int bits, t;
106 >  int bits = 0, aftype = 0, t = 0;
107    const char *current_date = NULL;
108 <  time_t cur_time;
141 <  char hostip[HOSTIPLEN];
108 >  char hostip[HOSTIPLEN + 1];
109    char buffer[IRCD_BUFSIZE];
110  
111 <  if (!HasOFlag(source_p, OPER_FLAG_K))
111 >  if (!HasOFlag(source_p, OPER_FLAG_DLINE))
112    {
113 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
114 <               me.name, source_p->name, "kline");
148 <    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, NULL, &reason) < 0)
119 <    return;
118 >                  NULL, &tkline_time, &target_server, &reason) < 0)
119 >    return 0;
120 >
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,
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 0;
130 >  }
131 >  else
132 >    cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
133 >                   "%d %s :%s", tkline_time, dlhost, reason);
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",
164 <                 me.name, source_p->name);
165 <      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);
173 <      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 183 | 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.",
188 <               me.name, source_p->name);
189 <    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
168    if (t == HM_IPV6)
169 <    t = AF_INET6;
169 >    aftype = AF_INET6;
170    else
171   #endif
172 <    t = AF_INET;
172 >    aftype = AF_INET;
173  
174    parse_netmask(dlhost, &daddr, NULL);
175  
176 <  if ((aconf = find_dline_conf(&daddr, t)) != NULL)
176 >  if ((conf = find_dline_conf(&daddr, aftype)))
177    {
178 <    creason = aconf->reason ? aconf->reason : def_reason;
179 <    if (IsConfExemptKline(aconf))
180 <      sendto_one(source_p,
181 <                 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
182 <                 me.name, source_p->name, dlhost, aconf->host, creason);
178 >    creason = conf->reason ? conf->reason : def_reason;
179 >
180 >    if (IsConfExemptKline(conf))
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, aconf->host, creason);
212 <    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;
216 <  current_date = smalldate(cur_time);
217 <
218 <  /* Look for an oper reason */
219 <  if ((oper_reason = strchr(reason, '|')) != NULL)
220 <    *oper_reason++ = '\0';
189 >  current_date = smalldate(0);
190  
191    if (!valid_comment(source_p, reason, 1))
192 <    return;
192 >    return 0;
193  
194 <  conf = make_conf_item(DLINE_TYPE);
195 <  aconf = map_to_conf(conf);
227 <  DupString(aconf->host, dlhost);
194 >  conf = conf_make(CONF_DLINE);
195 >  conf->host = xstrdup(dlhost);
196  
197 <  if (tkline_time != 0)
230 <  {
197 >  if (tkline_time)
198      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
199               (int)(tkline_time/60), reason, current_date);
233    DupString(aconf->reason, buffer);
234    if (oper_reason != NULL)
235      DupString(aconf->oper_reason, oper_reason);
236    apply_tdline(source_p, conf, current_date, tkline_time);
237  }
200    else
239  {
201      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
241    DupString(aconf->reason, buffer);
242    if (oper_reason != NULL)
243      DupString(aconf->oper_reason, oper_reason);
244    add_conf_by_address(CONF_DLINE, aconf);
245    write_conf_line(source_p, conf, current_date, cur_time);
246  }
202  
203 +  conf->reason = xstrdup(buffer);
204 +  apply_dline(source_p, conf, tkline_time);
205    rehashed_klines = 1;
206 +  return 0;
207   }
208  
209 < /*
210 < ** m_undline
253 < ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
254 < ** based totally on m_unkline
255 < ** added to hybrid-7 7/11/2000 --is
256 < **
257 < **      parv[0] = sender nick
258 < **      parv[1] = dline to remove
259 < */
260 < static void
261 < mo_undline(struct Client *client_p, struct Client *source_p,
262 <           int parc, char *parv[])
209 > static int
210 > ms_dline(struct Client *source_p, int parc, char *parv[])
211   {
212 <  const char *addr = NULL;
212 >  char def_reason[] = CONF_NOREASON;
213 >  char *dlhost, *reason;
214 >  const char *creason;
215 >  const struct Client *target_p = NULL;
216 >  struct irc_ssaddr daddr;
217 >  struct MaskItem *conf=NULL;
218 >  time_t tkline_time=0;
219 >  int bits = 0, aftype = 0, t = 0;
220 >  const char *current_date = NULL;
221 >  char hostip[HOSTIPLEN + 1];
222 >  char buffer[IRCD_BUFSIZE];
223  
224 <  if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
224 >  if (parc != 5 || EmptyString(parv[4]))
225 >    return 0;
226 >
227 >  /* parv[0]  parv[1]        parv[2]      parv[3]  parv[4] */
228 >  /* oper     target_server  tkline_time  host     reason  */
229 >  sendto_match_servs(source_p, parv[1], CAP_DLN,
230 >                     "DLINE %s %s %s :%s",
231 >                     parv[1], parv[2], parv[3], parv[4]);
232 >
233 >  if (match(parv[1], me.name))
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) ||
241 >      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
242 >                              source_p->username, source_p->host,
243 >                              SHARED_DLINE))
244    {
245 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
246 <               me.name, source_p->name, "undline");
270 <    return;
271 <  }
245 >    if (!IsClient(source_p))
246 >      return 0;
247  
248 <  addr = parv[1];
248 >    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
249 >    {
250 >      if ((target_p = find_chasing(source_p, dlhost)) == NULL)
251 >        return 0;
252  
253 <  if (remove_tdline_match(addr))
254 <  {
255 <    sendto_one(source_p,
256 <              ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
257 <              me.name, source_p->name, addr);
258 <    sendto_realops_flags(UMODE_ALL, L_ALL,
259 <                         "%s has removed the temporary D-Line for: [%s]",
260 <                         get_oper_name(source_p), addr);
261 <    ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]", source_p->name, addr);
262 <    return;
263 <  }
253 >      if (!MyConnect(target_p))
254 >      {
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_notice(source_p, &me, ":%s is E-lined", target_p->name);
262 >        return 0;
263 >      }
264 >
265 >      getnameinfo((struct sockaddr *)&target_p->localClient->ip,
266 >                  target_p->localClient->ip.ss_len, hostip,
267 >                  sizeof(hostip), NULL, 0, NI_NUMERICHOST);
268 >      dlhost = hostip;
269 >      t = parse_netmask(dlhost, NULL, &bits);
270 >      assert(t == HM_IPV4 || t == HM_IPV6);
271 >    }
272  
273 <  if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
274 <  {
275 <    sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
276 <               me.name, source_p->name, addr);
277 <    sendto_realops_flags(UMODE_ALL, L_ALL,
278 <                         "%s has removed the D-Line for: [%s]",
279 <                         get_oper_name(source_p), addr);
280 <    ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
281 <         get_oper_name(source_p), addr);
273 >    if (bits < 8)
274 >    {
275 >      sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
276 >      return 0;
277 >    }
278 >
279 > #ifdef IPV6
280 >    if (t == HM_IPV6)
281 >      aftype= AF_INET6;
282 >    else
283 > #endif
284 >      aftype = AF_INET;
285 >
286 >    parse_netmask(dlhost, &daddr, NULL);
287 >
288 >    if ((conf = find_dline_conf(&daddr, aftype)))
289 >    {
290 >      creason = conf->reason ? conf->reason : def_reason;
291 >      if (IsConfExemptKline(conf))
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_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
296 >                          dlhost, conf->host, creason);
297 >      return 0;
298 >    }
299 >
300 >    current_date = smalldate(0);
301 >
302 >    if (!valid_comment(source_p, reason, 1))
303 >      return 0;
304 >
305 >    conf = conf_make(CONF_DLINE);
306 >    conf->host = xstrdup(dlhost);
307 >
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
312 >      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
313 >
314 >    conf->reason = xstrdup(buffer);
315 >    apply_dline(source_p, conf, tkline_time);
316 >    rehashed_klines = 1;
317    }
318 <  else
319 <    sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
299 <               me.name, source_p->name, addr);
318 >
319 >  return 0;
320   }
321  
322 < static struct Message dline_msgtab = {
322 > static struct Message dline_msgtab =
323 > {
324    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
325 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore}
305 < };
306 <
307 < static struct Message undline_msgtab = {
308 <  "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
309 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, 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);
332 <  mod_add_cmd(&undline_msgtab);
332 >  add_capability("DLN", CAP_DLN, 1);
333   }
334  
335   static void
336   module_exit(void)
337   {
338    mod_del_cmd(&dline_msgtab);
339 <  mod_del_cmd(&undline_msgtab);
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)