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

Comparing:
ircd-hybrid-8/modules/m_kline.c (file contents), Revision 1276 by michael, Mon Jan 30 23:55:11 2012 UTC vs.
ircd-hybrid/trunk/modules/m_kline.c (file contents), Revision 1622 by michael, Thu Nov 1 13:16:37 2012 UTC

# Line 33 | Line 33
33   #include "numeric.h"
34   #include "fdlist.h"
35   #include "s_bsd.h"
36 < #include "s_conf.h"
37 < #include "s_log.h"
36 > #include "conf.h"
37 > #include "log.h"
38   #include "s_misc.h"
39   #include "send.h"
40   #include "hash.h"
# Line 42 | Line 42
42   #include "s_gline.h"
43   #include "parse.h"
44   #include "modules.h"
45 + #include "conf_db.h"
46  
47  
48   static int already_placed_kline(struct Client *, const char *, const char *, int);
49 < static void apply_kline(struct Client *, struct ConfItem *, const char *, time_t);
49 < static void apply_tkline(struct Client *, struct ConfItem *, int);
49 > static void m_kline_add_kline(struct Client *, struct AccessItem *, time_t);
50  
51   static char buffer[IRCD_BUFSIZE];
52 < static int remove_tkline_match(const char *, const char *);
52 > static int remove_kline_match(const char *, const char *);
53  
54  
55   /* mo_kline()
# Line 63 | Line 63 | static int remove_tkline_match(const cha
63   */
64   static void
65   mo_kline(struct Client *client_p, struct Client *source_p,
66 <         int parc, char **parv)
66 >         int parc, char *parv[])
67   {
68    char *reason = NULL;
69 –  char *oper_reason;
69    char *user = NULL;
70    char *host = NULL;
71    const char *current_date;
# Line 91 | Line 90 | mo_kline(struct Client *client_p, struct
90    {
91      if (HasID(source_p))
92      {
93 <      sendto_server(NULL, NULL, CAP_KLN|CAP_TS6, NOCAPS,
93 >      sendto_server(NULL, CAP_KLN|CAP_TS6, NOCAPS,
94                      ":%s KLINE %s %lu %s %s :%s",
95                      source_p->id, target_server, (unsigned long)tkline_time,
96                      user, host, reason);
97 <      sendto_server(NULL, NULL, CAP_KLN, CAP_TS6,
97 >      sendto_server(NULL, CAP_KLN, CAP_TS6,
98                      ":%s KLINE %s %lu %s %s :%s",
99                      source_p->name, target_server, (unsigned long)tkline_time,
100                      user, host, reason);
101      }
102      else
103 <      sendto_server(NULL, NULL, CAP_KLN, NOCAPS,
103 >      sendto_server(NULL, CAP_KLN, NOCAPS,
104                      ":%s KLINE %s %lu %s %s :%s",
105                      source_p->name, target_server, (unsigned long)tkline_time,
106                      user, host, reason);
# Line 117 | Line 116 | mo_kline(struct Client *client_p, struct
116    if (already_placed_kline(source_p, user, host, 1))
117      return;
118  
120 –  /* Look for an oper reason */
121 –  if ((oper_reason = strchr(reason, '|')) != NULL)
122 –    *oper_reason++ = '\0';
123 –
119    cur_time = CurrentTime;
120    current_date = smalldate(cur_time);
121    conf = make_conf_item(KLINE_TYPE);
# Line 135 | Line 130 | mo_kline(struct Client *client_p, struct
130               (int)(tkline_time/60), reason, current_date);
131      DupString(aconf->reason, buffer);
132  
133 <    if (oper_reason != NULL)
139 <      DupString(aconf->oper_reason, oper_reason);
140 <    apply_tkline(source_p, conf, tkline_time);
133 >    m_kline_add_kline(source_p, aconf, tkline_time);
134    }
135    else
136    {
137      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
138      DupString(aconf->reason, buffer);
139  
140 <    if (oper_reason != NULL)
148 <      DupString(aconf->oper_reason, oper_reason);
149 <    apply_kline(source_p, conf, current_date, cur_time);
140 >    m_kline_add_kline(source_p, aconf, 0);
141    }
142   }
143  
# Line 160 | Line 151 | me_kline(struct Client *client_p, struct
151    int tkline_time;
152    const char* current_date;
153    time_t cur_time;
154 <  char *kuser, *khost, *kreason, *oper_reason;
154 >  char *kuser, *khost, *kreason;
155  
156    if (parc != 6 || EmptyString(parv[5]))
157      return;
# Line 173 | Line 164 | me_kline(struct Client *client_p, struct
164    khost = parv[4];
165    kreason = parv[5];
166  
176 –  if ((oper_reason = strchr(kreason, '|')) != NULL)
177 –    *oper_reason++ = '\0';
178 –
167    cur_time = CurrentTime;
168    current_date = smalldate(cur_time);
169  
# Line 198 | Line 186 | me_kline(struct Client *client_p, struct
186                 (int)(tkline_time/60), kreason, current_date);
187        DupString(aconf->reason, buffer);
188  
189 <      if (oper_reason != NULL)
202 <        DupString(aconf->oper_reason, oper_reason);
203 <      apply_tkline(source_p, conf, tkline_time);
189 >      m_kline_add_kline(source_p, aconf, tkline_time);
190      }
191      else
192      {
193        snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
194        DupString(aconf->reason, buffer);
195  
196 <      if (oper_reason != NULL)
211 <        DupString(aconf->oper_reason, oper_reason);
212 <      apply_kline(source_p, conf, current_date, cur_time);
196 >      m_kline_add_kline(source_p, aconf, 0);
197      }
198    }
199   }
# Line 230 | Line 214 | ms_kline(struct Client *client_p, struct
214    me_kline(client_p, source_p, parc, parv);
215   }
216  
233 – /* apply_kline()
234 – *
235 – * inputs       -
236 – * output       - NONE
237 – * side effects - kline as given, is added to the hashtable
238 – *                and conf file
239 – */
240 – static void
241 – apply_kline(struct Client *source_p, struct ConfItem *conf,
242 –            const char *current_date, time_t cur_time)
243 – {
244 –  struct AccessItem *aconf = map_to_conf(conf);
245 –
246 –  add_conf_by_address(CONF_KILL, aconf);
247 –  write_conf_line(source_p, conf, current_date, cur_time);
248 –  /* Now, activate kline against current online clients */
249 –  rehashed_klines = 1;
250 – }
251 –
217   /* apply_tkline()
218   *
219   * inputs       -
# Line 256 | Line 221 | apply_kline(struct Client *source_p, str
221   * side effects - tkline as given is placed
222   */
223   static void
224 < apply_tkline(struct Client *source_p, struct ConfItem *conf,
225 <             int tkline_time)
224 > m_kline_add_kline(struct Client *source_p, struct AccessItem *aconf,
225 >                  time_t tkline_time)
226   {
227 <  struct AccessItem *aconf;
227 >  aconf->setat = CurrentTime;
228 >
229 >  if (tkline_time)
230 >  {
231 >    aconf->hold = CurrentTime + tkline_time;
232 >    SetConfTemporary(aconf);
233  
234 <  aconf = (struct AccessItem *)map_to_conf(conf);
235 <  aconf->hold = CurrentTime + tkline_time;
236 <  add_temp_line(conf);
237 <  sendto_realops_flags(UMODE_ALL, L_ALL,
238 <                       "%s added temporary %d min. K-Line for [%s@%s] [%s]",
239 <                       get_oper_name(source_p), tkline_time/60,
240 <                       aconf->user, aconf->host,
241 <                       aconf->reason);
242 <  sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
243 <             MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
244 <             source_p->name, tkline_time/60, aconf->user, aconf->host);
245 <  ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
246 <       source_p->name, tkline_time/60,
247 <       aconf->user, aconf->host, aconf->reason);
234 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
235 >                         "%s added temporary %d min. K-Line for [%s@%s] [%s]",
236 >                         get_oper_name(source_p), tkline_time/60,
237 >                         aconf->user, aconf->host,
238 >                         aconf->reason);
239 >    sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
240 >                 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
241 >                 source_p->name, tkline_time/60, aconf->user, aconf->host);
242 >    ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
243 >         source_p->name, tkline_time/60,
244 >         aconf->user, aconf->host, aconf->reason);
245 >  }
246 >  else
247 >  {
248 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
249 >                         "%s added K-Line for [%s@%s] [%s]",
250 >                         get_oper_name(source_p),
251 >                         aconf->user, aconf->host, aconf->reason);
252 >    sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
253 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
254 >                 source_p->name, aconf->user, aconf->host);
255 >    ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
256 >         source_p->name, aconf->user, aconf->host, aconf->reason);
257 >  }
258  
259 +  add_conf_by_address(CONF_KLINE, aconf);
260 +  save_kline_database();
261    rehashed_klines = 1;
262   }
263  
# Line 313 | Line 295 | already_placed_kline(struct Client *sour
295      piphost = NULL;
296    }
297  
298 <  if ((aconf = find_conf_by_address(lhost, piphost, CONF_KILL, t, luser, NULL)))
298 >  if ((aconf = find_conf_by_address(lhost, piphost, CONF_KLINE, t, luser, NULL, 0)))
299    {
300      if (warn)
301      {
# Line 323 | Line 305 | already_placed_kline(struct Client *sour
305                   me.name, source_p->name, luser, lhost, aconf->user,
306                   aconf->host, reason);
307      }
308 <    return(1);
308 >
309 >    return 1;
310    }
311  
312 <  return(0);
312 >  return 0;
313   }
314  
315   /*
# Line 353 | Line 336 | mo_unkline(struct Client *client_p,struc
336      return;
337    }
338  
339 <  if (parc < 2 || EmptyString(parv[1]))
339 >  if (EmptyString(parv[1]))
340    {
341      sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
342                 me.name, source_p->name, "UNKLINE");
# Line 378 | Line 361 | mo_unkline(struct Client *client_p,struc
361      cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
362                     "%s %s", user, host);
363  
364 <  if (remove_tkline_match(host, user))
364 >  if (remove_kline_match(host, user))
365    {
366      sendto_one(source_p,
367 <               ":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines",
367 >               ":%s NOTICE %s :K-Line for [%s@%s] is removed",
368                 me.name, source_p->name, user, host);
369 <    sendto_realops_flags(UMODE_ALL, L_ALL,
387 <                         "%s has removed the temporary K-Line for: [%s@%s]",
388 <                         get_oper_name(source_p), user, host);
389 <    ilog(LOG_TYPE_KLINE, "%s removed temporary K-Line for [%s@%s]",
390 <         source_p->name, user, host);
391 <    return;
392 <  }
393 <
394 <  if (remove_conf_line(KLINE_TYPE, source_p, user, host) > 0)
395 <  {
396 <    sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
397 <               me.name, source_p->name, user,host);
398 <    sendto_realops_flags(UMODE_ALL, L_ALL,
369 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
370                           "%s has removed the K-Line for: [%s@%s]",
371                           get_oper_name(source_p), user, host);
372      ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
# Line 436 | Line 407 | me_unkline(struct Client *client_p, stru
407                                     source_p->username, source_p->host,
408                                     SHARED_UNKLINE))
409    {
410 <    if (remove_tkline_match(khost, kuser))
410 >    if (remove_kline_match(khost, kuser))
411      {
412        sendto_one(source_p,
413 <                 ":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines",
443 <                 me.name, source_p->name, kuser, khost);
444 <      sendto_realops_flags(UMODE_ALL, L_ALL,  
445 <                           "%s has removed the temporary K-Line for: [%s@%s]",
446 <                           get_oper_name(source_p), kuser, khost);
447 <      ilog(LOG_TYPE_KLINE, "%s removed temporary K-Line for [%s@%s]",
448 <           source_p->name, kuser, khost);
449 <      return;
450 <    }
451 <
452 <    if (remove_conf_line(KLINE_TYPE, source_p, kuser, khost) > 0)
453 <    {
454 <      sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
413 >                 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
414                   me.name, source_p->name, kuser, khost);
415 <      sendto_realops_flags(UMODE_ALL, L_ALL,
415 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
416                             "%s has removed the K-Line for: [%s@%s]",
417 <                         get_oper_name(source_p), kuser, khost);
459 <
417 >                           get_oper_name(source_p), kuser, khost);
418        ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
419             source_p->name, kuser, khost);
420      }
# Line 487 | Line 445 | ms_unkline(struct Client *client_p, stru
445   * Side effects: Any matching tklines are removed.
446   */
447   static int
448 < remove_tkline_match(const char *host, const char *user)
448 > remove_kline_match(const char *host, const char *user)
449   {
450 <  struct AccessItem *tk_c;
451 <  dlink_node *tk_n;
452 <  struct irc_ssaddr addr, caddr;
453 <  int nm_t, cnm_t, bits, cbits;
454 <  nm_t = parse_netmask(host, &addr, &bits);
455 <
498 <  DLINK_FOREACH(tk_n, temporary_klines.head)
499 <  {
500 <    tk_c = map_to_conf(tk_n->data);
501 <    cnm_t = parse_netmask(tk_c->host, &caddr, &cbits);
502 <    if (cnm_t != nm_t || irccmp(user, tk_c->user))
503 <      continue;
504 <    if ((nm_t==HM_HOST && !irccmp(tk_c->host, host)) ||
505 <        (nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits))
450 >  struct irc_ssaddr iphost, *piphost;
451 >  struct AccessItem *aconf;
452 >  int t;
453 >
454 >  if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
455 >  {
456   #ifdef IPV6
457 <       || (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits))
457 >    if (t == HM_IPV6)
458 >      t = AF_INET6;
459 >    else
460   #endif
461 <       )
462 <      {
463 <        dlinkDelete(tk_n, &temporary_klines);
464 <        delete_one_address_conf(tk_c->host, tk_c);
465 <        return 1;
466 <      }
461 >      t = AF_INET;
462 >    piphost = &iphost;
463 >  }
464 >  else
465 >  {
466 >    t = 0;
467 >    piphost = NULL;
468 >  }
469 >
470 >  if ((aconf = find_conf_by_address(host, piphost, CONF_KLINE, t, user, NULL, 0)))
471 >  {
472 >    if (!IsConfMain(aconf))
473 >    {
474 >      delete_one_address_conf(host, aconf);
475 >      save_kline_database();
476 >      return 1;
477 >    }
478    }
479  
480    return 0;

Diff Legend

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