match.h File Reference


Detailed Description

Provides wildcard checks.

Definition in file match.h.

#include "sock_shared.h"
#include "win_sock.h"

Include dependency graph for match.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const char * inet_ntop (int af, const void *src, char *dst, size_t size)
const char * inet_ntop6 (const u_char *src, char *dst, size_t size)
int inet_pton (int af, const char *src, void *dst)
int inetpton (int af, const char *src, void *dst)
const char * ipv6_decompress (char *src)
 Decompresses "::" from IPv6 numeric address; if other address (or possibly hostname given) returns untouched.
int match (char *mask, char *name)
int match_ipmask (char *mask, char *username, in_addr6_ u_addr, int maskwithusername)


Function Documentation

const char* inet_ntop int  af,
const void *  src,
char *  dst,
size_t  size
 

Definition at line 417 of file match.cpp.

References inet_ntop4(), inet_ntop6(), and u_char.

Referenced by dcc_loop(), dcc_send_file(), inetntop(), and irc_quoted_callback().

00418 {
00419     switch (af)
00420     {
00421         case AF_INET:
00422             return inet_ntop4 ((const u_char*)src, dst, size);
00423         case AF_INET6:
00424             return inet_ntop6 ((const u_char*)src, dst, size);
00425         default:
00426             return (NULL);
00427     }
00428 }

Here is the call graph for this function:

const char* inet_ntop6 const u_char *  src,
char *  dst,
size_t  size
 

int inet_pton int  af,
const char *  src,
void *  dst
 

Definition at line 746 of file match.cpp.

References inet_pton4(), and inet_pton6().

Referenced by dcc_loop(), dcc_make_server(), dcc_send_file(), inetpton(), irc_await_dcc_chat(), irc_loop_process_input(), irc_quoted_callback(), irc_RPL_ENDOFWHOIS(), and match_ipmask().

00747 {
00748 
00749         switch (af) {
00750         case AF_INET:
00751                 return (inet_pton4(src, (unsigned char*)dst, 1));
00752         case AF_INET6:
00753                 return (inet_pton6(src, (unsigned char*)dst));
00754         default:
00755                 //errno = EAFNOSUPPORT;
00756                 return (-1);
00757         }
00758         /* NOTREACHED */
00759 }

Here is the call graph for this function:

int inetpton int  af,
const char *  src,
void *  dst
 

Definition at line 766 of file match.cpp.

References inet_pton().

Referenced by logic_check_mask(), sock_get_remote_addr6(), and sock_resolve6().

00767 {
00768   int  i;
00769 
00770   /* an empty string should listen to all */
00771   if (af == AF_INET6 && *src && !strchr(src, ':'))
00772       {
00773     i = inet_pton(AF_INET, src, dst);
00774 
00775     /* ugly hack */
00776     memcpy((char *)dst + 12, dst, 4);
00777     memset(dst, 0, 10);
00778     memset((char *)dst + 10, 0xff, 2);
00779     return i;
00780       }
00781   return inet_pton(af, src, dst);
00782 }

Here is the call graph for this function:

const char* ipv6_decompress char *  src  ) 
 

Decompresses "::" from IPv6 numeric address; if other address (or possibly hostname given) returns untouched.

Author:
VooDooMan
Version:
1
Date:
2005
Parameters:
src Source address
Returns:
Returns uncompressed address

Definition at line 153 of file match.cpp.

Referenced by inet_pton6(), and logic_hostmask_ipv6_decompress().

00154 {
00155     static char res[1024];
00156     if(strstr(src,":")==NULL)
00157         return src;
00158     if(strstr(src,"::")==NULL)
00159         return src;
00160     //bool ok=true;
00161     int expected_num_frags=8;
00162     if(strstr(src,".")!=NULL)
00163         expected_num_frags=7;
00164     int num_frags=0;
00165     int num_size=0;
00166     bool got=false;
00167     unsigned int i1;
00168     for(i1=0; i1<strlen(src)+1; i1++) { // +1 here is not typo! we need to process zero-terminator as well!
00169         if(src[i1]==':' || src[i1]==0) {
00170             if(/*num_size>4 ||*/ num_frags>expected_num_frags)
00171                 return src; // error
00172             num_size=0;
00173             if(i1>0 && src[i1-1]==':')
00174                 got=true;
00175             else
00176                 if((i1>0 && src[i1-1]!=':') && i1>0)
00177                     num_frags++;
00178         } else {
00179             num_size++;
00180         }
00181     }
00182     if(!got)
00183         return src;
00184     if(num_frags>8)
00185         return src;
00186     bool need_colon=false;
00187     int i2=0;
00188     for(i1=0; i1<strlen(src); i1++) {
00189         if(i2>sizeof(res)-8)
00190             return src;
00191         if(src[i1]==':' && i1>0 && src[i1-1]==':') {
00192             for(int i3=0; i3<expected_num_frags-num_frags; i3++) {
00193                 if(i2>sizeof(res)-8)
00194                     return src;
00195                 if(i2>0 && res[i2-1]!=':')
00196                     res[i2++]=':';
00197                 res[i2++]='0';
00198                 need_colon=true;
00199             }
00200         } else {
00201             if(!(i1==0 && src[i1]==':')) {
00202                 if(need_colon)
00203                     res[i2++]=':';
00204                 if(!need_colon)
00205                     res[i2++]=src[i1];
00206                 if(need_colon && src[i1]!=':')
00207                     res[i2++]=src[i1];
00208             }
00209             need_colon=false;
00210         }
00211     }
00212     res[i2++]=0;
00213     return res;
00214 }

int match char *  mask,
char *  name
 

Definition at line 824 of file match.cpp.

References MAX_ITERATIONS, Reg, and u_char.

Referenced by botnet_partyline_event(), dcc_broadcast(), dcc_loop(), irc_check_flood(), irc_check_for_not_invited(), irc_check_for_not_reopped(), logic_exec(), logic_match1(), logic_partyline_whois(), and match_ipmask().

00825 {
00826   Reg  u_char  *m = (u_char *)mask, *n = (u_char *)name;
00827   char  *ma = mask, *na = name;
00828   int  wild = 0, q = 0, calls = 0;
00829 
00830   if (!*mask)
00831     return 1;
00832 
00833   if (mask[0]=='*' && mask[1]=='\0')
00834     return 0;
00835 
00836   while (1)
00837       {
00838 #ifdef  MAX_ITERATIONS
00839           if (calls++ > MAX_ITERATIONS)
00840       break;               
00841 #endif
00842 
00843     if (*m == '*')
00844        {
00845       while (*m == '*')
00846         m++;
00847       wild = 1;
00848       ma = (char *)m;
00849       na = (char *)n;
00850         }
00851 
00852     if (!*m)
00853         {
00854         if (!*n)
00855         return 0;
00856         for (m--; (m > (u_char *)mask) && (*m == '?'); m--)
00857         ;
00858       if ((m > (u_char *)mask) && (*m == '*') &&
00859           (m[-1] != '\\'))
00860         return 0;
00861       if (!wild) 
00862         return 1;
00863       m = (u_char *)ma;
00864       n = (u_char *)++na;
00865         }
00866     else if (!*n)
00867       return 1;
00868     if ((*m == '\\') &&
00869       ((m[1] == '*') || (m[1] == '?') || (m[1] == '#')))
00870         {
00871       m++;
00872       q = 1;
00873         }
00874     else
00875       q = 0;
00876 
00877     if ((tolower(*m) == tolower(*n))
00878       || (*m == '?' && !q)
00879       || (*m == '#' && !q && isdigit(*n)))
00880         {
00881       if (*m)
00882         m++;
00883       if (*n)
00884         n++;
00885         }
00886     else
00887         {
00888       if (!wild)
00889         return 1;
00890       m = (u_char *)ma;
00891       n = (u_char *)++na;
00892         }
00893       }
00894 
00895   return 1;
00896 }

int match_ipmask char *  mask,
char *  username,
in_addr6_  u_addr,
int  maskwithusername
 

Definition at line 919 of file match.cpp.

References in_addr6_::bytes, IN6_IS_ADDR_V4MAPPED, index(), inet_pton(), match(), strncpyzt, u_int32_t, and u_long.

Referenced by logic_check_mask().

00921 {
00922   int  m;
00923   char  *p;
00924 // BEGIN CHANGE - VooDooMan 2004/10/18 - changed
00925 //  struct  IN_ADDR addr;
00926   struct  in_addr6_ addr;
00927 // END   CHANGE - VooDooMan 2004/10/18 - changed
00928   char  dummy[128];
00929   char  *omask;
00930   u_long  lmask;
00931 #ifdef  INET6
00932   int  j;
00933 #endif
00934 
00935   omask = mask;
00936   strncpyzt(dummy, mask, sizeof(dummy));
00937   mask = dummy;
00938   if (maskwithusername && (p = index(mask, '@')))
00939   {
00940     *p = '\0';
00941 // BEGIN CHANGE - VooDooMan 2004/10/18 - changed
00942 //    if (match(mask, cptr->username))
00943     if (match(mask, username))
00944 // END   CHANGE - VooDooMan 2004/10/18 - changed
00945       return 1;
00946     mask = p + 1;
00947   }
00948   if (!(p = index(mask, '/')))
00949     goto badmask;
00950   *p = '\0';
00951   
00952   if (sscanf(p + 1, "%d", &m) != 1)
00953   {
00954     goto badmask;
00955   }
00956   if (!m)
00957     return 0;       /* x.x.x.x/0 always matches */
00958 #ifndef  INET6
00959   if (m < 0 || m > 32)
00960     goto badmask;
00961   lmask = htonl((u_long)0xffffffffL << (32 - m));
00962 // BEGIN CHANGE - VooDooMan 2004/10/18 - changed
00963 //  addr.s_addr = inetaddr(mask);
00964 //  return ((addr.s_addr ^ cptr->ip.s_addr) & lmask) ? 1 : 0;
00965   addr.s_addr=inet_addr(mask);
00966   return ((addr.s_addr ^ u_addr) & lmask) ? 1 : 0;
00967 // END   CHANGE - VooDooMan 2004/10/18 - changed
00968 #else
00969   if (m < 0 || m > 128)
00970     goto badmask;
00971   if (inet_pton(AF_INET6, mask, (void *)addr.bytes) != 1)
00972   {
00973     return -1;
00974   }
00975 
00976   /* Make sure that the ipv4 notation still works. */
00977   if (IN6_IS_ADDR_V4MAPPED(&addr) && m < 96)
00978   {
00979     m += 96;
00980   }
00981 
00982   j = m & 0x1F;  /* number not mutliple of 32 bits */
00983   m >>= 5;  /* number of 32 bits */
00984 
00985   if (m && memcmp((void *)(addr.bytes), 
00986       (void *)(/*cptr->ip.s6_addr*/&(u_addr.bytes)), m << 2))
00987     return 1;
00988 
00989   if (j)
00990   {
00991     lmask = htonl((u_long)0xffffffffL << (32 - j));
00992     if ((((u_int32_t *)(addr.bytes))[m] ^
00993         ((u_int32_t *)(/*cptr->ip.s6_addr*/&(u_addr.bytes)))[m]) & lmask)
00994       return 1;
00995   }
00996 
00997   return 0;
00998 #endif
00999 badmask:
01000 // BEGIN CHANGE - VooDooMan 2004/10/18 - changed
01001 /*  if (maskwithusername)
01002   sendto_flag(SCH_ERROR, "Ignoring bad mask: %s", omask);*/
01003 // END   CHANGE - VooDooMan 2004/10/18 - changed
01004   return -1;
01005 }

Here is the call graph for this function:


Generated on Sun Jul 10 05:37:31 2005 for VooDoo cIRCle by doxygen 1.4.3

Hosted by SourceForge.net Logo