List:General Discussion« Previous MessageNext Message »
From:Jim Faucette Date:April 1 1999 12:38am
Subject:ip masking - corrected diff
View as plain text  
Oops, there was an OBO in the first submission. Here's a corrected diff.

  jim...

399a400,443
> //
> //   Handles masked IPs
> //
> 
> const uint ip_masks[] = {
> 0,0x00000080,0x000000c0,0x000000e0,0x000000f0,0x000000f8,
> 0x000000fc,0x000000fe,0x000000ff,0x000080ff,0x0000c0ff,0x0000e0ff,
> 0x0000f0ff,0x0000f8ff,0x0000fcff,0x0000feff,0x0000ffff,0x0080ffff,
> 0x00c0ffff,0x00e0ffff,0x00f0ffff,0x00f8ffff,0x00fcffff,0x00feffff,
> 0x00ffffff,0x80ffffff,0xc0ffffff,0xe0ffffff,0xf0ffffff,0xf8ffffff,
> 0xfcffffff,0xfeffffff,0xffffffff};
> 
> int ip_mask_compare(const char *ip, const char *wild) {
>   char *ch = NULL;
>   uint bits, ip_val = 1, wild_val = 0;
>   
>   if((ch = strchr(wild, '/')) != NULL && 
>      (bits = atoi(ch+1)) > 0 && bits < 33) {
> 
>      ch = (char *)ip;
>      ip_val = atoi(ch);
>      if((ch = strchr(ch, '.')) != NULL)
>        ip_val += (atoi(++ch) << 8);
>      if(ch != NULL && *ch && (ch = strchr(ch, '.')) != NULL) 
>        ip_val += (atoi(++ch) << 16);
>      if(ch != NULL && *ch && (ch = strchr(ch, '.')) != NULL) 
>        ip_val += (atoi(++ch) << 24);
>      ip_val &= ip_masks[bits];
> 
>      ch = (char *)wild;
>      wild_val = atoi(ch);
>      if((ch = strchr(ch, '.')) != NULL)
>        wild_val += (atoi(++ch) << 8);
>      if(ch != NULL && *ch && (ch = strchr(ch, '.')) != NULL) 
>        wild_val += (atoi(++ch) << 16);
>      if(ch != NULL && *ch && (ch = strchr(ch, '.')) != NULL) 
>        wild_val += (atoi(++ch) << 24);
>      wild_val &= ip_masks[bits];
>   }
> //  sql_print_error(
> //		"ip: '%s' %u -- wild: '%s' %u", ip, ip_val, wild, wild_val);
> 
>   return( (ip_val == wild_val) ? 0 : 1);
> }
418a463
> 
426c471,472
< 	  (ip && !wild_compare(ip,acl_user->host)))
---
> 	  (ip && (!wild_compare(ip,acl_user->host) ||
>                   !ip_mask_compare(ip,acl_user->host))))
592c638,639
< 	  (ip && !wild_compare(ip,acl_db->host)))
---
> 	  (ip && (!wild_compare(ip,acl_db->host) ||
>                   !ip_mask_compare(ip,acl_db->host))))
616c663,664
< 	(ip && !wild_compare(ip,acl_host->host)))
---
> 	(ip && (!wild_compare(ip,acl_host->host) ||
>                   !ip_mask_compare(ip,acl_host->host))))
699c747,748
< 	  strchr(acl_user->host,wild_many))
---
> 	  strchr(acl_user->host,wild_one) ||
>           strchr(acl_user->host, '/'))
735c784
<     if (!wild_case_compare(host,*acl))
---
>     if (!wild_case_compare(host,*acl) || !ip_mask_compare(host,*acl))
Thread
ip masking - corrected diffJim Faucette1 Apr