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

Comparing:
ircd-hybrid-7.2/contrib/ip_cloaking.c (file contents), Revision 34 by lusky, Sun Oct 2 21:05:51 2005 UTC vs.
ircd-hybrid-8/contrib/ip_cloaking.c (file contents), Revision 1309 by michael, Sun Mar 25 11:24:18 2012 UTC

# Line 52 | Line 52
52   #include "whowas.h"
53   #include "channel_mode.h"
54   #include "client.h"
55 #include "common.h"
55   #include "hash.h"
56   #include "hook.h"
57   #include "irc_string.h"
# Line 62 | Line 61
61   #include "s_serv.h"
62   #include "s_user.h"
63   #include "send.h"
64 < #include "s_conf.h"
64 > #include "conf.h"
65   #include "modules.h"
66   #include "memory.h"
67 < #include "s_log.h"
67 > #include "log.h"
68   #include "sprintf_irc.h"
69  
70   static unsigned int umode_vhost = 0;
71   static int vhost_ipv6_err;
72   static dlink_node *prev_enter_umode;
73   static dlink_node *prev_umode;
75
76 const char *_version = "$Revision$";
77
74   static void *reset_ipv6err_flag(va_list);
75   static void *h_set_user_mode(va_list);
76  
81 void _modinit(void)
82 {
83  if (!user_modes['h'])
84  {
85    unsigned int all_umodes = 0, i;
86
87    for (i = 0; i < 128; i++)
88      all_umodes |= user_modes[i];
89
90    for (umode_vhost = 1; umode_vhost && (all_umodes & umode_vhost);
91         umode_vhost <<= 1);
92
93    if (!umode_vhost)
94    {
95      ilog(L_ERROR, "You have more than 32 usermodes, "
96           "IP cloaking not installed");
97      sendto_realops_flags(UMODE_ALL, L_ALL, "You have more than "
98                           "32 usermodes, IP cloaking not installed");
99      return;
100    }
101
102    user_modes['h'] = umode_vhost;
103    assemble_umode_buffer();
104  }
105  else
106  {
107    ilog(L_ERROR, "Usermode +h already in use, IP cloaking not installed");
108    sendto_realops_flags(UMODE_ALL, L_ALL, "Usermode +h already in use, "
109                         "IP cloaking not installed");
110    return;
111  }
112
113  prev_enter_umode = install_hook(entering_umode_cb, reset_ipv6err_flag);
114  prev_umode = install_hook(umode_cb, h_set_user_mode);
115 }
116
117 void _moddeinit(void)
118 {
119  if (umode_vhost)
120  {
121    dlink_node *ptr;
122
123    DLINK_FOREACH(ptr, local_client_list.head)
124    {
125      struct Client *cptr = ptr->data;
126      cptr->umodes &= ~umode_vhost;
127    }
128
129    user_modes['h'] = 0;
130    assemble_umode_buffer();
131
132    uninstall_hook(entering_umode_cb, reset_ipv6err_flag);
133    uninstall_hook(umode_cb, h_set_user_mode);
134  }
135 }
136
77   /*
78   * The implementation originally comes from Gary S. Brown. The tables
79   * are a direct transplant of his original concept and have been
# Line 242 | Line 182 | static unsigned long crc32_tab[] = {
182   };
183  
184   static unsigned long
185 < crc32 (const unsigned char *s, unsigned int len)
185 > crc32(const char *s, unsigned int len)
186   {
187    unsigned int i;
188 <  unsigned long crc32val;
188 >  unsigned long crc32val = 0;
189  
250  crc32val = 0;
190    for (i = 0; i < len; i++)
252  {
191      crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8);
192 <  }
192 >
193    return crc32val;
194   }
195  
# Line 266 | Line 204 | crc32 (const unsigned char *s, unsigned
204   * side effects - not IPv6 friendly
205   */
206   static int
207 < str2arr (char **pparv, char *string, char *delim)
207 > str2arr(char **pparv, char *string, const char *delim)
208   {
209    char *tok;
210    int pparc = 0;
211  
212    /* Diane had suggested to use this method rather than while() -- knight */
213 <  for (tok = strtok (string, delim); tok != NULL; tok = strtok (NULL, delim))
213 >  for (tok = strtok(string, delim); tok != NULL; tok = strtok(NULL, delim))
214    {
215      pparv[pparc++] = tok;
216    }
# Line 288 | Line 226 | str2arr (char **pparv, char *string, cha
226   * new = encrypted hostname/ip
227   */
228   static void
229 < make_virthost (char *curr, char *host, char *new)
229 > make_virthost(char *curr, char *host, char *new)
230   {
231 <  static char mask[HOSTLEN + 1];
231 >  char mask[HOSTLEN + 1];
232    char *parv[HOSTLEN + 1], *parv2[HOSTLEN + 1], s[HOSTLEN + 1], s2[HOSTLEN + 1];
233    int parc = 0, parc2 = 0, len = 0;
234    unsigned long hash[8];
# Line 301 | Line 239 | make_virthost (char *curr, char *host, c
239    parc  = str2arr(parv, s, ".");
240    parc2 = str2arr(parv2, s2, ".");
241  
242 +  if (!parc2)
243 +    return;
244 +
245    hash[0] = ((crc32 (parv[3], strlen (parv[3])) + KEY) ^ KEY2) ^ KEY3;
246    hash[1] = ((KEY2 ^ crc32 (parv[2], strlen (parv[2]))) + KEY3) ^ KEY;
247    hash[2] = ((crc32 (parv[1], strlen (parv[1])) + KEY3) ^ KEY) ^ KEY2;
# Line 391 | Line 332 | set_vhost(struct Client *client_p, struc
332    make_virthost(target_p->host, target_p->sockhost, target_p->host);
333  
334    if (IsClient(target_p))
335 <    sendto_server(client_p, source_p, NULL, CAP_ENCAP, NOCAPS, LL_ICLIENT,
335 >    sendto_server(client_p, NULL, CAP_ENCAP, NOCAPS,
336                    ":%s ENCAP * CHGHOST %s %s",
337                    me.name, target_p->name, target_p->host);
338  
339 <    sendto_one(target_p, form_str(RPL_HOSTHIDDEN),
340 <               me.name, target_p->name, target_p->host);
339 >  sendto_one(target_p, form_str(RPL_HOSTHIDDEN),
340 >             me.name, target_p->name, target_p->host);
341   }
342  
343   static void *
# Line 405 | Line 346 | reset_ipv6err_flag(va_list args)
346    struct Client *client_p = va_arg(args, struct Client *);
347    struct Client *source_p = va_arg(args, struct Client *);
348  
349 <  vhost_ipv6_err = NO;
349 >  vhost_ipv6_err = 0;
350  
351    return pass_callback(prev_enter_umode, client_p, source_p);
352   }
# Line 440 | Line 381 | h_set_user_mode(va_list args)
381          {
382            sendto_one(target_p, ":%s NOTICE %s :*** Sorry, IP cloaking "
383                       "does not support IPv6 users!", me.name, target_p->name);
384 <          vhost_ipv6_err = YES;
384 >          vhost_ipv6_err = 1;
385          }
386        }
387        else
# Line 453 | Line 394 | h_set_user_mode(va_list args)
394  
395    return pass_callback(prev_umode, client_p, target_p, what, flag);
396   }
397 +
398 + static void
399 + module_init(void)
400 + {
401 +  if (!user_modes['h'])
402 +  {
403 +    unsigned int all_umodes = 0, i;
404 +
405 +    for (i = 0; i < 128; i++)
406 +      all_umodes |= user_modes[i];
407 +
408 +    for (umode_vhost = 1; umode_vhost && (all_umodes & umode_vhost);
409 +         umode_vhost <<= 1);
410 +
411 +    if (!umode_vhost)
412 +    {
413 +      ilog(LOG_TYPE_IRCD, "You have more than 32 usermodes, "
414 +           "IP cloaking not installed");
415 +      sendto_realops_flags(UMODE_ALL, L_ALL, "You have more than "
416 +                           "32 usermodes, IP cloaking not installed");
417 +      return;
418 +    }
419 +
420 +    user_modes['h'] = umode_vhost;
421 +    assemble_umode_buffer();
422 +  }
423 +  else
424 +  {
425 +    ilog(LOG_TYPE_IRCD, "Usermode +h already in use, IP cloaking not installed");
426 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Usermode +h already in use, "
427 +                         "IP cloaking not installed");
428 +    return;
429 +  }
430 +
431 +  prev_enter_umode = install_hook(entering_umode_cb, reset_ipv6err_flag);
432 +  prev_umode = install_hook(umode_cb, h_set_user_mode);
433 + }
434 +
435 + static void
436 + module_exit(void)
437 + {
438 +  if (umode_vhost)
439 +  {
440 +    dlink_node *ptr;
441 +
442 +    DLINK_FOREACH(ptr, local_client_list.head)
443 +    {
444 +      struct Client *cptr = ptr->data;
445 +      cptr->umodes &= ~umode_vhost;
446 +    }
447 +
448 +    user_modes['h'] = 0;
449 +    assemble_umode_buffer();
450 +
451 +    uninstall_hook(entering_umode_cb, reset_ipv6err_flag);
452 +    uninstall_hook(umode_cb, h_set_user_mode);
453 +  }
454 + }
455 +
456 + struct module module_entry = {
457 +  .node    = { NULL, NULL, NULL },
458 +  .name    = NULL,
459 +  .version = "$Revision$",
460 +  .handle  = NULL,
461 +  .modinit = module_init,
462 +  .modexit = module_exit,
463 +  .flags   = 0
464 + };

Diff Legend

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