Changeset 1206

Show
Ignore:
Timestamp:
03/04/10 12:41:30 (2 years ago)
Author:
Gary
Message:

unxsBind IPv6 input validation and conversion work continues.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/unxsBind/tresourcefunc.h

    r1205 r1206  
    200200        else if(!strcmp(cRRType,"AAAA")) 
    201201        { 
     202                register int i; 
    202203                unsigned h1=0; 
    203204                unsigned h2=0; 
     
    209210                unsigned h8=0; 
    210211                char *cp; 
     212                unsigned uColonCount=0; 
     213                unsigned uRead=0; 
    211214 
    212215                //Insure these are empty 
     
    216219                        tResource("Can not add AAAA records to arpa zones"); 
    217220 
    218                 //This is not going to work for all cases. 
    219                 //if cParam1 has no consecutive colons 
    220                 if(!(cp=strstr(cParam1,"::"))) 
    221                 { 
    222                         sscanf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",&h1,&h2,&h3,&h4,&h5,&h6,&h7,&h8); 
    223                 } 
    224                 else 
    225                 { 
    226                         unsigned uPos=0; 
    227  
     221                //if cParam1 has no consecutive colons we can simply: 
     222                if((cp=strstr(cParam1,"::"))) 
     223                { 
    228224                        if(strstr(cp+2,"::")) 
    229225                        { 
    230226                                guMode=uMode; 
    231                                 tResource("IPv6 number can not have more than one double colons."); 
    232                         } 
    233  
    234                         uPos=sscanf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",&h1,&h2,&h3,&h4,&h5,&h6,&h7,&h8); 
    235                         //All first position cases, i.e. 2,3,4,5 and 6 word cases 
    236                         if(uPos==1) 
    237                         { 
    238                                 uPos=sscanf(cParam1,"%x::%x:%x:%x:%x:%x:%x",&h1, &h3,&h4,&h5,&h6,&h7,&h8); 
    239                                 if(uPos==2) 
    240                                         uPos=sscanf(cParam1,"%x:%x::%x:%x:%x:%x:%x",&h1,&h2, &h4,&h5,&h6,&h7,&h8); 
    241                         } 
    242                                  
    243                 } 
    244  
    245                 //Leading 0's. Done via sprintf below. 
    246  
    247                 //First checks 
     227                                tResource("<blink>IPv6 number can not have more than one double colon!</blink>"); 
     228                        } 
     229                } 
     230 
     231                //Now for the hard work 
     232                for(i=0;cParam1[i];i++) 
     233                { 
     234                        if(cParam1[i]==':') 
     235                                uColonCount++; 
     236                        if(cParam1[i]!=':' && !isxdigit(cParam1[i])) 
     237                        { 
     238                                guMode=uMode; 
     239                                tResource("<blink>IPv6 number can only have hexadecimal digits and colons!</blink>"); 
     240                        } 
     241                } 
     242 
     243                switch(uColonCount) 
     244                { 
     245                        case 0: 
     246                        case 1: 
     247                                guMode=uMode; 
     248                                tResource("<blink>IPv6 too few colons: Min is 2!</blink>"); 
     249                        break; 
     250 
     251                        case 2: 
     252                                uRead=sscanf(cParam1,"%x::%x",&h1,&h8); 
     253                                if(uRead!=2) 
     254                                { 
     255                                        guMode=uMode; 
     256                                        tResource("<blink>IPv6 sscanf case 2 error!</blink>"); 
     257                                } 
     258                        break; 
     259 
     260                        case 3: 
     261                                uRead=sscanf(cParam1,"%x::%x:%x",&h1,&h7,&h8); 
     262                                if(uRead!=3) 
     263                                { 
     264                                        uRead=sscanf(cParam1,"%x:%x::%x",&h1,&h2,&h8); 
     265                                        if(uRead!=3) 
     266                                        { 
     267                                                guMode=uMode; 
     268                                                tResource("<blink>IPv6 sscanf case 3 error!</blink>"); 
     269                                        } 
     270                                } 
     271                        break; 
     272 
     273                        case 4: 
     274                                uRead=sscanf(cParam1,"%x::%x:%x:%x",&h1,&h6,&h7,&h8); 
     275                                if(uRead!=4) 
     276                                { 
     277                                        uRead=sscanf(cParam1,"%x:%x::%x:%x",&h1,&h2,&h7,&h8); 
     278                                        if(uRead!=4) 
     279                                        { 
     280                                                uRead=sscanf(cParam1,"%x:%x:%x::%x",&h1,&h2,&h3,&h8); 
     281                                                if(uRead!=4) 
     282                                                { 
     283                                                        guMode=uMode; 
     284                                                        tResource("<blink>IPv6 sscanf case 4 error!</blink>"); 
     285                                                } 
     286                                        } 
     287                                } 
     288                        break; 
     289 
     290                        case 5: 
     291                                uRead=sscanf(cParam1,"%x::%x:%x:%x:%x",&h1,&h5,&h6,&h7,&h8); 
     292                                if(uRead!=5) 
     293                                { 
     294                                        uRead=sscanf(cParam1,"%x:%x::%x:%x:%x",&h1,&h2,&h6,&h7,&h8); 
     295                                        if(uRead!=5) 
     296                                        { 
     297                                                uRead=sscanf(cParam1,"%x:%x:%x::%x:%x",&h1,&h2,&h3,&h7,&h8); 
     298                                                if(uRead!=5) 
     299                                                { 
     300                                                        uRead=sscanf(cParam1,"%x:%x:%x:%x::%x",&h1,&h2,&h3,&h4,&h8); 
     301                                                        if(uRead!=5) 
     302                                                        { 
     303                                                                guMode=uMode; 
     304                                                                tResource("<blink>IPv6 sscanf case 5 error!</blink>"); 
     305                                                        } 
     306                                                } 
     307                                        } 
     308                                } 
     309                        break; 
     310 
     311                        case 6: 
     312                                uRead=sscanf(cParam1,"%x::%x:%x:%x:%x:%x",&h1,&h4,&h5,&h6,&h7,&h8); 
     313                                if(uRead!=6) 
     314                                { 
     315                                        uRead=sscanf(cParam1,"%x:%x::%x:%x:%x:%x",&h1,&h2,&h5,&h6,&h7,&h8); 
     316                                        if(uRead!=6) 
     317                                        { 
     318                                                uRead=sscanf(cParam1,"%x:%x:%x::%x:%x:%x",&h1,&h2,&h3,&h6,&h7,&h8); 
     319                                                if(uRead!=6) 
     320                                                { 
     321                                                        uRead=sscanf(cParam1,"%x:%x:%x:%x::%x:%x",&h1,&h2,&h3,&h4,&h7,&h8); 
     322                                                        if(uRead!=6) 
     323                                                        { 
     324                                                                uRead=sscanf(cParam1,"%x:%x:%x:%x:%x::%x", 
     325                                                                                        &h1,&h2,&h3,&h4,&h5,&h8); 
     326                                                                if(uRead!=6) 
     327                                                                { 
     328                                                                        guMode=uMode; 
     329                                                                        tResource("<blink>IPv6 sscanf case 6 error!</blink>"); 
     330                                                                } 
     331                                                        } 
     332                                                } 
     333                                        } 
     334                                } 
     335                        break; 
     336 
     337                        case 7: 
     338                                uRead=sscanf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",&h1,&h2,&h3,&h4,&h5,&h6,&h7,&h8); 
     339                                if(uRead!=7) 
     340                                { 
     341                                        guMode=uMode; 
     342                                        tResource("<blink>IPv6 sscanf case 7 error!</blink>"); 
     343                                } 
     344 
     345                        default: 
     346                                guMode=uMode; 
     347                                tResource("<blink>IPv6 too many colons: Max is 7!</blink>"); 
     348                         
     349                } 
     350 
     351                //First basic checks for AAAA hosts 
    248352                if(!h1) 
    249353                { 
     
    260364                } 
    261365 
     366                //Mandatory rewrite in shortest possible IPv6 format. 
     367                //This is needed to speed up DNSSEC and reduce BIND zone file size. 
     368                //This may not be a good idea. Need to research further: If someone wants to 
     369                //write a bunch of 0's why not? 
    262370                //Compress empty words: Double colon. Can only be used once. 
    263                 //Trying KISS method here 
     371                //Trying KISS method here. sprintf does the leading 0 removal for us. 
    264372                //6 consecutive 0 case 
    265373                if(!h2 && !h3 && !h4 && !h5 && !h6 && !h7) 
     
    300408                else if(1) 
    301409                        sprintf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",h1,h2,h3,h4,h5,h6,h7,h8); 
    302                  
    303  
    304410        } 
    305411        else if(!strcmp(cRRType,"PTR"))