Changeset 764

Show
Ignore:
Timestamp:
09/24/05 23:05:49 (3 years ago)
Author:
minaguib
Message:

Pre-emptive bugfix - harsh lockdown of parsing trusted MAC addresses from config file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wifidog/ChangeLog

    r763 r764  
    11# $Header$ 
     2 
     32005-09-24 Mina Naguib <mina@ilesansfil.org> 
     4        * conf.c: Pre-emptive bugfix - harsh lockdown of parsing trusted MAC 
     5        addresses from config file 
     6 
    272005-09-24 Philippe April <philippe@ilesansfil.org> 
    38        * (finally) Added {Saul Albert,Jo Walsh,Schuyler}'s patch (thank you!) to send 
  • trunk/wifidog/src/conf.c

    r763 r764  
    8686        oFirewallRule, 
    8787        oFirewallRuleSet, 
    88     oTrustedMACList 
     88       oTrustedMACList 
    8989} OpCodes; 
    9090 
     
    156156        config.wdctl_sock = safe_strdup(DEFAULT_WDCTL_SOCK); 
    157157        config.rulesets = NULL; 
    158     config.trustedmaclist = NULL; 
     158       config.trustedmaclist = NULL; 
    159159} 
    160160 
     
    640640                                        break; 
    641641                                case oFirewallRuleSet: 
    642                                         parse_firewall_ruleset(p1, fd, 
    643                                                         filename, &linenum); 
    644                                         break; 
    645                 case oTrustedMACList: 
    646                     parse_trusted_mac_list(p1); 
    647                     break; 
     642                                        parse_firewall_ruleset(p1, fd, filename, &linenum); 
     643                                        break; 
     644                                case oTrustedMACList: 
     645                                        parse_trusted_mac_list(p1); 
     646                                        break; 
    648647                                case oHTTPDName: 
    649648                                        config.httpdname = safe_strdup(p1); 
     
    705704} 
    706705 
    707 void 
    708 parse_trusted_mac_list(char *ptr) 
    709 
    710     char *mac; 
    711     mac = (char *)safe_malloc(18); 
    712     t_trusted_mac *p; 
    713  
    714     while (1 == sscanf(ptr, "%17s", mac)) { 
    715         if (config.trustedmaclist == NULL) { 
    716             config.trustedmaclist = safe_malloc(sizeof(t_trusted_mac)); 
    717             config.trustedmaclist->mac = mac; 
    718             config.trustedmaclist->next = NULL; 
    719         } else { 
    720             /* Advance to the last entry */ 
    721             for (p = config.trustedmaclist; p->next != NULL; p = p->next); 
    722             p->next = safe_malloc(sizeof(t_trusted_mac)); 
    723             p = p->next; 
    724             p->mac = mac; 
    725             p->next = NULL; 
    726         } 
    727  
    728         /* We put our pointer in the structure, re-allocate memory */ 
    729         mac = (char *)safe_malloc(18); 
    730  
    731         while (*ptr != '\n' && *ptr != ',') 
    732             ptr++; 
    733         /* Advance one more to actually begin the next MAC */ 
    734         ptr++; 
    735     } 
    736  
    737     free(mac); 
     706void parse_trusted_mac_list(char *ptr) { 
     707        char *ptrcopy = NULL; 
     708        char *possiblemac = NULL; 
     709        char *mac = NULL; 
     710        t_trusted_mac *p = NULL; 
     711 
     712        debug(LOG_DEBUG, "Parsing string [%s] for trusted MAC addresses", ptr); 
     713 
     714        mac = safe_malloc(18); 
     715 
     716        /* strsep modifies original, so let's make a copy */ 
     717        ptrcopy = safe_strdup(ptr); 
     718 
     719        while ((possiblemac = strsep(&ptrcopy, ", "))) { 
     720                if (sscanf(possiblemac, " %17[A-Fa-f0-9:]", mac) == 1) { 
     721                        /* Copy mac to the list */ 
     722 
     723                        debug(LOG_DEBUG, "Adding MAC address [%s] to trusted list", mac); 
     724 
     725                        if (config.trustedmaclist == NULL) { 
     726                                config.trustedmaclist = safe_malloc(sizeof(t_trusted_mac)); 
     727                                config.trustedmaclist->mac = safe_strdup(mac); 
     728                                config.trustedmaclist->next = NULL; 
     729                        } 
     730                        else { 
     731                                /* Advance to the last entry */ 
     732                                for (p = config.trustedmaclist; p->next != NULL; p = p->next); 
     733                                p->next = safe_malloc(sizeof(t_trusted_mac)); 
     734                                p = p->next; 
     735                                p->mac = safe_strdup(mac); 
     736                                p->next = NULL; 
     737                        } 
     738 
     739                } 
     740        } 
     741 
     742        free(ptrcopy); 
     743 
     744        free(mac); 
     745 
    738746} 
    739747