Annotation of embedaddon/coova-chilli/src/options.c, revision 1.1.1.1

1.1       misho       1: /* 
                      2:  *
                      3:  * chilli - ChilliSpot.org. A Wireless LAN Access Point Controller.
                      4:  * Copyright (C) 2003, 2004, 2005 Mondru AB.
                      5:  * Copyright (C) 2006 PicoPoint B.V.
                      6:  * Copyright (c) 2006-2007 David Bird <david@coova.com>
                      7:  *
                      8:  * The contents of this file may be used under the terms of the GNU
                      9:  * General Public License Version 2, provided that the above copyright
                     10:  * notice and this permission notice is included in all copies or
                     11:  * substantial portions of the software.
                     12:  * 
                     13:  */
                     14: 
                     15: #include "system.h"
                     16: #include "tun.h"
                     17: #include "ippool.h"
                     18: #include "radius.h"
                     19: #include "radius_wispr.h"
                     20: #include "radius_chillispot.h"
                     21: #include "redir.h"
                     22: #include "syserr.h"
                     23: #include "dhcp.h"
                     24: #include "cmdline.h"
                     25: #include "chilli.h"
                     26: #include "options.h"
                     27: 
                     28: struct options_t options;
                     29: 
                     30: char *STRDUP(char *s) {
                     31:   if (!s) return 0;
                     32:   while (isspace(*s)) s++;
                     33:   if (!*s) return 0;
                     34:   return strdup(s);
                     35: }
                     36: 
                     37: /* Get IP address and mask */
                     38: int option_aton(struct in_addr *addr, struct in_addr *mask,
                     39:                char *pool, int number) {
                     40: 
                     41:   /* Parse only first instance of network for now */
                     42:   /* Eventually "number" will indicate the token which we want to parse */
                     43: 
                     44:   unsigned int a1, a2, a3, a4;
                     45:   unsigned int m1, m2, m3, m4;
                     46:   unsigned int m;
                     47:   int masklog;
                     48:   int c;
                     49: 
                     50:   c = sscanf(pool, "%u.%u.%u.%u/%u.%u.%u.%u",
                     51:             &a1, &a2, &a3, &a4,
                     52:             &m1, &m2, &m3, &m4);
                     53: 
                     54:   switch (c) {
                     55:   case 4:
                     56:     mask->s_addr = 0xffffffff;
                     57:     break;
                     58:   case 5:
                     59:     if (m1 > 32) {
                     60:       log_err(0, "Invalid mask");
                     61:       return -1; /* Invalid mask */
                     62:     }
                     63:     mask->s_addr = htonl(0xffffffff << (32 - m1));
                     64:     break;
                     65:   case 8:
                     66:     if (m1 >= 256 ||  m2 >= 256 || m3 >= 256 || m4 >= 256) {
                     67:       log_err(0, "Invalid mask");
                     68:       return -1; /* Wrong mask format */
                     69:     }
                     70:     m = m1 * 0x1000000 + m2 * 0x10000 + m3 * 0x100 + m4;
                     71:     for (masklog = 0; ((1 << masklog) < ((~m)+1)); masklog++);
                     72:     if (((~m)+1) != (1 << masklog)) {
                     73:       log_err(0, "Invalid mask");
                     74:       return -1; /* Wrong mask format (not all ones followed by all zeros)*/
                     75:     }
                     76:     mask->s_addr = htonl(m);
                     77:     break;
                     78:   default:
                     79:     log_err(0, "Invalid mask");
                     80:     return -1; /* Invalid mask */
                     81:   }
                     82: 
                     83:   if (a1 >= 256 ||  a2 >= 256 || a3 >= 256 || a4 >= 256) {
                     84:     log_err(0, "Wrong IP address format");
                     85:     return -1;
                     86:   }
                     87:   else
                     88:     addr->s_addr = htonl(a1 * 0x1000000 + a2 * 0x10000 + a3 * 0x100 + a4);
                     89: 
                     90:   return 0;
                     91: }
                     92: 
                     93: static const char *description = 
                     94:   "CoovaChilli - A Wireless LAN Access Point Controller.\n"
                     95:   "  For more information on this project, visit: \n"
                     96:   "  http://coova.org/wiki/index.php/CoovaChilli\n";
                     97: 
                     98: static const char *copyright = 
                     99:   "Copyright (c) 2003-2005 Mondru AB., 2006-2007 David Bird, and others.\n"
                    100:   "Licensed under the Gnu Public License (GPL).\n";
                    101: 
                    102: static const char *usage = \
                    103:   "Usage: chilli [OPTIONS]...\n";
                    104: 
                    105: extern const char *gengetopt_args_info_help[];
                    106: 
                    107: static void
                    108: options_print_version (void) {
                    109:   printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
                    110: }
                    111: 
                    112: static void
                    113: options_print_help (void) {
                    114:   int i = 0;
                    115:   options_print_version();
                    116: 
                    117:   printf("\n%s", description);
                    118:   printf("\n%s\n", usage);
                    119: 
                    120:   while (gengetopt_args_info_help[i])
                    121:     printf("%s\n", gengetopt_args_info_help[i++]);
                    122: 
                    123:   printf("\n%s\n", copyright);
                    124: }
                    125: 
                    126: 
                    127: /* Extract domain name and port from URL */
                    128: int static get_namepart(char *src, char *host, int hostsize, int *port) {
                    129:   char *slashslash = NULL;
                    130:   char *slash = NULL;
                    131:   char *colon = NULL;
                    132:   int hostlen;
                    133:   
                    134:   *port = 0;
                    135: 
                    136:   if (!memcmp(src, "http://", 7)) {
                    137:     *port = DHCP_HTTP;
                    138:   }
                    139:   else   if (!memcmp(src, "https://", 8)) {
                    140:     *port = DHCP_HTTPS;
                    141:   }
                    142:   else {
                    143:     log_err(0, "URL must start with http:// or https:// %s!", src);
                    144:     return -1;
                    145:   }
                    146:   
                    147:   /* The host name must be initiated by "//" and terminated by /, :  or \0 */
                    148:   if (!(slashslash = strstr(src, "//"))) {
                    149:     log_err(0, "// not found in url: %s!", src);
                    150:     return -1;
                    151:   }
                    152:   slashslash+=2;
                    153:   
                    154:   slash = strstr(slashslash, "/");
                    155:   colon = strstr(slashslash, ":");
                    156:   
                    157:   if ((slash != NULL) && (colon != NULL) &&
                    158:       (slash < colon)) {
                    159:     hostlen = slash - slashslash;
                    160:   }
                    161:   else if ((slash != NULL) && (colon == NULL)) {
                    162:     hostlen = slash - slashslash;
                    163:   }
                    164:   else if (colon != NULL) {
                    165:     hostlen = colon - slashslash;
                    166:     if (1 != sscanf(colon+1, "%d", port)) {
                    167:       log_err(0, "Not able to parse URL port: %s!", src);
                    168:       return -1;
                    169:     }
                    170:   }
                    171:   else {
                    172:     hostlen = strlen(src);
                    173:   }
                    174: 
                    175:   if (hostlen > (hostsize-1)) {
                    176:     log_err(0, "URL hostname larger than %d: %s!", hostsize-1, src);
                    177:     return -1;
                    178:   }
                    179: 
                    180:   strncpy(host, slashslash, hostsize);
                    181:   host[hostlen] = 0;
                    182: 
                    183:   return 0;
                    184: }
                    185: 
                    186: int process_options(int argc, char **argv, int minimal) {
                    187:   int reconfiguring = options.initialized;
                    188:   struct gengetopt_args_info args_info;
                    189:   struct hostent *host;
                    190:   char hostname[USERURLSIZE];
                    191:   int numargs;
                    192:   int ret = -1;
                    193: 
                    194:   if (!reconfiguring)
                    195:     memset(&options, 0, sizeof(options));
                    196: 
                    197:   memset(&args_info, 0, sizeof(args_info));
                    198: 
                    199:   if (cmdline_parser(argc, argv, &args_info) != 0) {
                    200:     log_err(0, "Failed to parse command line options");
                    201:     goto end_processing;
                    202:   }
                    203: 
                    204:   if (args_info.version_given) {
                    205:     options_print_version();
                    206:     exit(0);
                    207:   }
                    208: 
                    209:   if (args_info.help_given) {
                    210:     options_print_help();
                    211:     exit(0);
                    212:   }
                    213: 
                    214:   if (cmdline_parser_configfile(args_info.conf_arg ? 
                    215:                                args_info.conf_arg : 
                    216:                                DEFCHILLICONF, 
                    217:                                &args_info, 0, 0, 0)) {
                    218:     log_err(0, "Failed to parse configuration file: %s!", 
                    219:            args_info.conf_arg);
                    220:     goto end_processing;
                    221:   }
                    222: 
                    223:   /* Get the system default DNS entries */
                    224:   if (!reconfiguring && res_init()) {
                    225:     log_err(0, "Failed to update system DNS settings (res_init()!");
                    226:     goto end_processing;
                    227:   }
                    228: 
                    229:   /* Handle each option */
                    230:   options.initialized = 1;
                    231: 
                    232:   if (args_info.debug_flag) 
                    233:     options.debug = args_info.debugfacility_arg;
                    234:   else 
                    235:     options.debug = 0;
                    236: 
                    237:   /** simple configuration parameters **/
                    238:   options.usetap = args_info.usetap_flag;
                    239:   options.foreground = args_info.fg_flag;
                    240:   options.interval = args_info.interval_arg;
                    241:   options.lease = args_info.lease_arg;
                    242:   options.dhcpstart = args_info.dhcpstart_arg;
                    243:   options.dhcpend = args_info.dhcpend_arg;
                    244:   options.eapolenable = args_info.eapolenable_flag;
                    245:   options.swapoctets = args_info.swapoctets_flag;
                    246:   options.usestatusfile = args_info.usestatusfile_flag;
                    247:   options.logfacility = args_info.logfacility_arg;
                    248:   options.chillixml = args_info.chillixml_flag;
                    249:   options.macauth = args_info.macauth_flag;
                    250:   options.macauthdeny = args_info.macauthdeny_flag;
                    251:   options.uamport = args_info.uamport_arg;
                    252:   options.uamuiport = args_info.uamuiport_arg;
                    253:   options.macallowlocal = args_info.macallowlocal_flag;
                    254:   options.no_uamsuccess = args_info.nouamsuccess_flag;
                    255:   options.no_uamwispr = args_info.nouamwispr_flag;
                    256:   options.wpaguests = args_info.wpaguests_flag;
                    257:   options.openidauth = args_info.openidauth_flag;
                    258:   options.defsessiontimeout = args_info.defsessiontimeout_arg;
                    259:   options.definteriminterval = args_info.definteriminterval_arg;
                    260:   options.defbandwidthmaxdown = args_info.defbandwidthmaxdown_arg;
                    261:   options.defbandwidthmaxup = args_info.defbandwidthmaxup_arg;
                    262:   options.defidletimeout = args_info.defidletimeout_arg;
                    263:   options.radiusnasporttype = args_info.radiusnasporttype_arg;
                    264:   options.radiusauthport = args_info.radiusauthport_arg;
                    265:   options.radiusacctport = args_info.radiusacctport_arg;
                    266:   options.coaport = args_info.coaport_arg;
                    267:   options.coanoipcheck = args_info.coanoipcheck_flag;
                    268:   options.radiustimeout = args_info.radiustimeout_arg;
                    269:   options.radiusretry = args_info.radiusretry_arg;
                    270:   options.radiusretrysec = args_info.radiusretrysec_arg;
                    271:   options.proxyport = args_info.proxyport_arg;
                    272:   options.txqlen = args_info.txqlen_arg;
                    273:   options.postauth_proxyport = args_info.postauthproxyport_arg;
                    274:   options.pap_always_ok = args_info.papalwaysok_flag;
                    275:   options.acct_update = args_info.acctupdate_flag;
                    276:   options.dhcpradius = args_info.dhcpradius_flag;
                    277:   options.dhcpgwport = args_info.dhcpgatewayport_arg;
                    278: 
                    279:   if (args_info.dhcpgateway_arg &&
                    280:       !inet_aton(args_info.dhcpgateway_arg, &options.dhcpgwip)) {
                    281:     log_err(0, "Invalid DHCP gateway IP address: %s!", args_info.dhcpgateway_arg);
                    282:     goto end_processing;
                    283:   }
                    284: 
                    285:   if (args_info.dhcprelayagent_arg &&
                    286:       !inet_aton(args_info.dhcprelayagent_arg, &options.dhcprelayip)) {
                    287:     log_err(0, "Invalid DHCP gateway relay IP address: %s!", args_info.dhcprelayagent_arg);
                    288:     goto end_processing;
                    289:   }
                    290: 
                    291:   if (!reconfiguring) {
                    292:     options.dhcpif = STRDUP(args_info.dhcpif_arg);
                    293:   }
                    294: 
                    295:   if (!args_info.radiussecret_arg) {
                    296:     log_err(0, "radiussecret must be specified!");
                    297:     goto end_processing;
                    298:   }
                    299: 
                    300:   if (!args_info.dhcpmac_arg) {
                    301:     memset(options.dhcpmac, 0, PKT_ETH_ALEN);
                    302:     options.dhcpusemac  = 0;
                    303:   }
                    304:   else {
                    305:     unsigned int temp[PKT_ETH_ALEN];
                    306:     char macstr[RADIUS_ATTR_VLEN];
                    307:     int macstrlen;
                    308:     int        i;
                    309: 
                    310:     if ((macstrlen = strlen(args_info.dhcpmac_arg)) >= (RADIUS_ATTR_VLEN-1)) {
                    311:       log_err(0,
                    312:              "MAC address too long");
                    313:       goto end_processing;
                    314:     }
                    315: 
                    316:     memcpy(macstr, args_info.dhcpmac_arg, macstrlen);
                    317:     macstr[macstrlen] = 0;
                    318: 
                    319:     /* Replace anything but hex with space */
                    320:     for (i=0; i<macstrlen; i++) 
                    321:       if (!isxdigit(macstr[i])) macstr[i] = 0x20;
                    322: 
                    323:     if (sscanf (macstr, "%2x %2x %2x %2x %2x %2x", 
                    324:                &temp[0], &temp[1], &temp[2], 
                    325:                &temp[3], &temp[4], &temp[5]) != 6) {
                    326:       log_err(0, "MAC conversion failed!");
                    327:       return -1;
                    328:     }
                    329:     
                    330:     for(i = 0; i < PKT_ETH_ALEN; i++) 
                    331:       options.dhcpmac[i] = temp[i];
                    332: 
                    333:     options.dhcpusemac  = 1;
                    334:   }
                    335: 
                    336:   if (!reconfiguring) {
                    337:     if (args_info.net_arg) {
                    338:       if (option_aton(&options.net, &options.mask, args_info.net_arg, 0)) {
                    339:        log_err(0, "Invalid network address: %s!", args_info.net_arg);
                    340:        goto end_processing;
                    341:       }
                    342:       if (!args_info.uamlisten_arg) {
                    343:        options.uamlisten.s_addr = htonl(ntohl(options.net.s_addr)+1);
                    344:       }
                    345:       else if (!inet_aton(args_info.uamlisten_arg, &options.uamlisten)) {
                    346:        log_err(0, "Invalid UAM IP address: %s!", args_info.uamlisten_arg);
                    347:        goto end_processing;
                    348:       }
                    349:       options.dhcplisten.s_addr = options.uamlisten.s_addr;
                    350:     }
                    351:     else if (!minimal) {
                    352:       log_err(0, "Network address must be specified ('net' parameter)!");
                    353:       goto end_processing;
                    354:     }
                    355:   }
                    356: 
                    357:   log_dbg("DHCP Listen: %s", inet_ntoa(options.dhcplisten));
                    358:   log_dbg("UAM Listen: %s", inet_ntoa(options.uamlisten));
                    359: 
                    360:   if (!args_info.uamserver_arg && !minimal) {
                    361:     log_err(0, "WARNING: No uamserver defiend!");
                    362:   }
                    363: 
                    364:   if (args_info.uamserver_arg) {
                    365:     if (options.debug & DEBUG_CONF) {
                    366:       log_dbg("Uamserver: %s\n", args_info.uamserver_arg);
                    367:     }
                    368:     memset(options.uamserver, 0, sizeof(options.uamserver));
                    369:     options.uamserverlen = 0;
                    370:     if (get_namepart(args_info.uamserver_arg, hostname, USERURLSIZE, 
                    371:                     &options.uamserverport)) {
                    372:       log_err(0, "Failed to parse uamserver: %s!", args_info.uamserver_arg);
                    373:       goto end_processing;
                    374:     }
                    375:   
                    376:     if (!(host = gethostbyname(hostname))) {
                    377:       log_err(0, 
                    378:              "Could not resolve IP address of uamserver: %s! [%s]", 
                    379:              args_info.uamserver_arg, strerror(errno));
                    380:       goto end_processing;
                    381:     }
                    382:     else {
                    383:       int j = 0;
                    384:       while (host->h_addr_list[j] != NULL) {
                    385:        if (options.debug & DEBUG_CONF) {
                    386:          log_dbg("Uamserver IP address #%d: %s\n", j,
                    387:                 inet_ntoa(*(struct in_addr*) host->h_addr_list[j]));
                    388:        }
                    389:        if (options.uamserverlen>=UAMSERVER_MAX) {
                    390:          log_err(0,
                    391:                  "Too many IPs in uamserver %s!",
                    392:                  args_info.uamserver_arg);
                    393:          goto end_processing;
                    394:        }
                    395:        else {
                    396:          options.uamserver[options.uamserverlen++] = 
                    397:            *((struct in_addr*) host->h_addr_list[j++]);
                    398:        }
                    399:       }
                    400:     }
                    401:   }
                    402: 
                    403:   if (args_info.uamhomepage_arg) {
                    404:     if (get_namepart(args_info.uamhomepage_arg, hostname, USERURLSIZE, 
                    405:                     &options.uamhomepageport)) {
                    406:       log_err(0,
                    407:              "Failed to parse uamhomepage: %s!", args_info.uamhomepage_arg);
                    408:       goto end_processing;
                    409:     }
                    410: 
                    411:     if (!(host = gethostbyname(hostname))) {
                    412:       log_err(0, 
                    413:              "Invalid uamhomepage: %s! [%s]", 
                    414:              args_info.uamhomepage_arg, strerror(errno));
                    415:       goto end_processing;
                    416:     }
                    417:     else {
                    418:       int j = 0;
                    419:       while (host->h_addr_list[j] != NULL) {
                    420:        if (options.uamserverlen>=UAMSERVER_MAX) {
                    421:          log_err(0,
                    422:                  "Too many IPs in uamhomepage %s!",
                    423:                  args_info.uamhomepage_arg);
                    424:          goto end_processing;
                    425:        }
                    426:        else {
                    427:          options.uamserver[options.uamserverlen++] = 
                    428:            *((struct in_addr*) host->h_addr_list[j++]);
                    429:        }
                    430:       }
                    431:     }
                    432:   }
                    433: 
                    434:   options.uamanydns = args_info.uamanydns_flag;
                    435:   options.uamanyip = args_info.uamanyip_flag;
                    436:   options.dnsparanoia = args_info.dnsparanoia_flag;
                    437:   options.radiusoriginalurl = args_info.radiusoriginalurl_flag;
                    438: 
                    439:   /* pass-throughs */
                    440:   memset(options.pass_throughs, 0, sizeof(options.pass_throughs));
                    441:   options.num_pass_throughs = 0;
                    442: 
                    443:   for (numargs = 0; numargs < args_info.uamallowed_given; ++numargs) {
                    444:     pass_throughs_from_string(options.pass_throughs,
                    445:                              MAX_PASS_THROUGHS,
                    446:                              &options.num_pass_throughs,
                    447:                              args_info.uamallowed_arg[numargs]);
                    448:   }
                    449: 
                    450:   if (options.uamdomains) {
                    451:     for (numargs = 0; options.uamdomains[numargs]; ++numargs) 
                    452:       free(options.uamdomains[numargs]);
                    453:     free(options.uamdomains);
                    454:   }
                    455:   options.uamdomains=0;
                    456: 
                    457:   if (args_info.uamdomain_given) {
                    458:     options.uamdomains = calloc(args_info.uamdomain_given+1, sizeof(char *));
                    459:     for (numargs = 0; numargs < args_info.uamdomain_given; ++numargs) 
                    460:       options.uamdomains[numargs] = STRDUP(args_info.uamdomain_arg[numargs]);
                    461:   }
                    462: 
                    463:   if (!reconfiguring) {
                    464:     options.allowdyn = 1;
                    465: 
                    466:     if (args_info.nodynip_flag) {
                    467:       options.allowdyn = 0;
                    468:     } else {
                    469:       if (!args_info.dynip_arg) {
                    470:        options.dynip = STRDUP(args_info.net_arg);
                    471:       }
                    472:       else {
                    473:        struct in_addr addr;
                    474:        struct in_addr mask;
                    475:        options.dynip = STRDUP(args_info.dynip_arg);
                    476:        if (option_aton(&addr, &mask, options.dynip, 0)) {
                    477:          log_err(0, "Failed to parse dynamic IP address pool!");
                    478:          goto end_processing;
                    479:        }
                    480:       }
                    481:     }
                    482:     
                    483:     /* statip */
                    484:     if (args_info.statip_arg) {
                    485:       struct in_addr addr;
                    486:       struct in_addr mask;
                    487:       options.statip = STRDUP(args_info.statip_arg);
                    488:       if (option_aton(&addr, &mask, options.statip, 0)) {
                    489:        log_err(0, "Failed to parse static IP address pool!");
                    490:        return -1;
                    491:       }
                    492:       options.allowstat = 1;
                    493:     } else {
                    494:       options.allowstat = 0;
                    495:     }
                    496:   }
                    497: 
                    498:   if (args_info.dns1_arg) {
                    499:     if (!inet_aton(args_info.dns1_arg, &options.dns1)) {
                    500:       log_err(0,
                    501:              "Invalid primary DNS address: %s!", 
                    502:              args_info.dns1_arg);
                    503:       goto end_processing;
                    504:     }
                    505:   }
                    506:   else if (_res.nscount >= 1) {
                    507:     options.dns1 = _res.nsaddr_list[0].sin_addr;
                    508:   }
                    509:   else {
                    510:     options.dns1.s_addr = 0;
                    511:   }
                    512: 
                    513:   if (args_info.dns2_arg) {
                    514:     if (!inet_aton(args_info.dns2_arg, &options.dns2)) {
                    515:       log_err(0,
                    516:              "Invalid secondary DNS address: %s!", 
                    517:              args_info.dns1_arg);
                    518:       goto end_processing;
                    519:     }
                    520:   }
                    521:   else if (_res.nscount >= 2) {
                    522:     options.dns2 = _res.nsaddr_list[1].sin_addr;
                    523:   }
                    524:   else {
                    525:     options.dns2.s_addr = options.dns1.s_addr;
                    526:   }
                    527: 
                    528: 
                    529:   /* If no listen option is specified listen to any local port    */
                    530:   /* Do hostname lookup to translate hostname to IP address       */
                    531:   if (!reconfiguring) {
                    532:     if (args_info.radiuslisten_arg) {
                    533:       if (!(host = gethostbyname(args_info.radiuslisten_arg))) {
                    534:        log_err(0, "Invalid listening address: %s! [%s]", 
                    535:                args_info.radiuslisten_arg, strerror(errno));
                    536:        goto end_processing;
                    537:       }
                    538:       else {
                    539:        memcpy(&options.radiuslisten.s_addr, host->h_addr, host->h_length);
                    540:       }
                    541:     }
                    542:     else {
                    543:       options.radiuslisten.s_addr = htonl(INADDR_ANY);
                    544:     }
                    545:   }
                    546: 
                    547:   if (args_info.uamlogoutip_arg) {
                    548:     if (!(host = gethostbyname(args_info.uamlogoutip_arg))) {
                    549:       log_warn(0, "Invalid uamlogoutup address: %s! [%s]", 
                    550:               args_info.uamlogoutip_arg, strerror(errno));
                    551:     }
                    552:     else {
                    553:       memcpy(&options.uamlogout.s_addr, host->h_addr, host->h_length);
                    554:     }
                    555:   }
                    556: 
                    557:   if (args_info.postauthproxy_arg) {
                    558:     if (!(host = gethostbyname(args_info.postauthproxy_arg))) {
                    559:       log_warn(0, "Invalid postauthproxy address: %s! [%s]", 
                    560:               args_info.postauthproxy_arg, strerror(errno));
                    561:     }
                    562:     else {
                    563:       memcpy(&options.postauth_proxyip.s_addr, host->h_addr, host->h_length);
                    564:     }
                    565:   }
                    566: 
                    567:   /* If no option is specified terminate                          */
                    568:   /* Do hostname lookup to translate hostname to IP address       */
                    569:   if (args_info.radiusserver1_arg) {
                    570:     if (!(host = gethostbyname(args_info.radiusserver1_arg))) {
                    571:       log_err(0, "Invalid radiusserver1 address: %s! [%s]", 
                    572:              args_info.radiusserver1_arg, strerror(errno));
                    573:       goto end_processing;
                    574:     }
                    575:     else {
                    576:       memcpy(&options.radiusserver1.s_addr, host->h_addr, host->h_length);
                    577:     }
                    578:   }
                    579:   else {
                    580:     log_err(0,
                    581:            "No radiusserver1 address given!");
                    582:     goto end_processing;
                    583:   }
                    584: 
                    585:   /* radiusserver2 */
                    586:   /* If no option is specified terminate                          */
                    587:   /* Do hostname lookup to translate hostname to IP address       */
                    588:   if (args_info.radiusserver2_arg) {
                    589:     if (!(host = gethostbyname(args_info.radiusserver2_arg))) {
                    590:       log_err(0, "Invalid radiusserver2 address: %s! [%s]", 
                    591:              args_info.radiusserver2_arg, strerror(errno));
                    592:       goto end_processing;
                    593:     }
                    594:     else {
                    595:       memcpy(&options.radiusserver2.s_addr, host->h_addr, host->h_length);
                    596:     }
                    597:   }
                    598:   else {
                    599:     options.radiusserver2.s_addr = 0;
                    600:   }
                    601: 
                    602:   /* If no listen option is specified listen to any local port    */
                    603:   /* Do hostname lookup to translate hostname to IP address       */
                    604:   if (!reconfiguring) {
                    605:     if (args_info.proxylisten_arg) {
                    606:       if (!(host = gethostbyname(args_info.proxylisten_arg))) {
                    607:        log_err(0, 
                    608:                "Invalid listening address: %s! [%s]", 
                    609:                args_info.proxylisten_arg, strerror(errno));
                    610:        goto end_processing;
                    611:       }
                    612:       else {
                    613:        memcpy(&options.proxylisten.s_addr, host->h_addr, host->h_length);
                    614:       }
                    615:     }
                    616:     else {
                    617:       options.proxylisten.s_addr = htonl(INADDR_ANY);
                    618:     }
                    619: 
                    620:     /* Store proxyclient as in_addr net and mask                       */
                    621:     if (args_info.proxyclient_arg) {
                    622:       if(option_aton(&options.proxyaddr, &options.proxymask, 
                    623:                     args_info.proxyclient_arg, 0)) {
                    624:        log_err(0,
                    625:                "Invalid proxy client address: %s!", args_info.proxyclient_arg);
                    626:        goto end_processing;
                    627:       }
                    628:     }
                    629:     else {
                    630:       options.proxyaddr.s_addr = ~0; /* Let nobody through */
                    631:       options.proxymask.s_addr = 0; 
                    632:     }
                    633:   }
                    634: 
                    635: 
                    636:   memset(options.macok, 0, sizeof(options.macok));
                    637:   options.macoklen = 0;
                    638:   for (numargs = 0; numargs < args_info.macallowed_given; ++numargs) {
                    639:     if (options.debug & DEBUG_CONF) {
                    640:       log_dbg("Macallowed #%d: %s\n", numargs, 
                    641:              args_info.macallowed_arg[numargs]);
                    642:     }
                    643:     char *p1 = NULL;
                    644:     char *p2 = NULL;
                    645:     char *p3 = malloc(strlen(args_info.macallowed_arg[numargs])+1);
                    646:     int i;
                    647:     strcpy(p3, args_info.macallowed_arg[numargs]);
                    648:     p1 = p3;
                    649:     if ((p2 = strchr(p1, ','))) {
                    650:       *p2 = '\0';
                    651:     }
                    652:     while (p1) {
                    653:       if (options.macoklen>=MACOK_MAX) {
                    654:        log_err(0,
                    655:                "Too many addresses in macallowed %s!",
                    656:                args_info.macallowed_arg);
                    657:       }
                    658:       else {
                    659:        /* Replace anything but hex and comma with space */
                    660:        for (i=0; i<strlen(p1); i++) 
                    661:          if (!isxdigit(p1[i])) p1[i] = 0x20;
                    662:       
                    663:        if (sscanf (p1, "%2x %2x %2x %2x %2x %2x",
                    664:                    &options.macok[options.macoklen][0], 
                    665:                    &options.macok[options.macoklen][1], 
                    666:                    &options.macok[options.macoklen][2], 
                    667:                    &options.macok[options.macoklen][3], 
                    668:                    &options.macok[options.macoklen][4], 
                    669:                    &options.macok[options.macoklen][5]) != 6) {
                    670:          log_err(0, "Failed to convert macallowed option to MAC Address");
                    671:        }
                    672:        else {
                    673:          if (options.debug & DEBUG_CONF) {
                    674:            log_dbg("Macallowed address #%d: %.2X-%.2X-%.2X-%.2X-%.2X-%.2X\n", 
                    675:                   options.macoklen,
                    676:                   options.macok[options.macoklen][0],
                    677:                   options.macok[options.macoklen][1],
                    678:                   options.macok[options.macoklen][2],
                    679:                   options.macok[options.macoklen][3],
                    680:                   options.macok[options.macoklen][4],
                    681:                   options.macok[options.macoklen][5]);
                    682:          }
                    683:          options.macoklen++;
                    684:        }
                    685:       }
                    686:       
                    687:       if (p2) {
                    688:        p1 = p2+1;
                    689:        if ((p2 = strchr(p1, ','))) {
                    690:          *p2 = '\0';
                    691:        }
                    692:       }
                    693:       else {
                    694:        p1 = NULL;
                    695:       }
                    696:     }
                    697:     free(p3);
                    698:   }
                    699: 
                    700:   /** string parameters **/
                    701:   if (options.routeif) free(options.routeif);
                    702:   options.routeif = STRDUP(args_info.routeif_arg);
                    703: 
                    704:   if (options.wwwdir) free(options.wwwdir);
                    705:   options.wwwdir = STRDUP(args_info.wwwdir_arg);
                    706: 
                    707:   if (options.wwwbin) free(options.wwwbin);
                    708:   options.wwwbin = STRDUP(args_info.wwwbin_arg);
                    709: 
                    710:   if (options.uamui) free(options.uamui);
                    711:   options.uamui = STRDUP(args_info.uamui_arg);
                    712: 
                    713:   if (options.localusers) free(options.localusers);
                    714:   options.localusers = STRDUP(args_info.localusers_arg);
                    715: 
                    716:   if (options.uamurl) free(options.uamurl);
                    717:   options.uamurl = STRDUP(args_info.uamserver_arg);
                    718: 
                    719:   if (options.uamhomepage) free(options.uamhomepage);
                    720:   options.uamhomepage = STRDUP(args_info.uamhomepage_arg);
                    721: 
                    722:   if (options.wisprlogin) free(options.wisprlogin);
                    723:   options.wisprlogin = STRDUP(args_info.wisprlogin_arg);
                    724: 
                    725:   if (options.uamsecret) free(options.uamsecret);
                    726:   options.uamsecret = STRDUP(args_info.uamsecret_arg);
                    727: 
                    728:   if (options.proxysecret) free(options.proxysecret);
                    729:   if (!args_info.proxysecret_arg) {
                    730:     options.proxysecret = STRDUP(args_info.radiussecret_arg);
                    731:   }
                    732:   else {
                    733:     options.proxysecret = STRDUP(args_info.proxysecret_arg);
                    734:   }
                    735: 
                    736:   if (options.macsuffix) free(options.macsuffix);
                    737:   options.macsuffix = STRDUP(args_info.macsuffix_arg);
                    738: 
                    739:   if (options.macpasswd) free(options.macpasswd);
                    740:   options.macpasswd = STRDUP(args_info.macpasswd_arg);
                    741: 
                    742:   if (options.adminuser) free(options.adminuser);
                    743:   options.adminuser = STRDUP(args_info.adminuser_arg);
                    744: 
                    745:   if (options.adminpasswd) free(options.adminpasswd);
                    746:   options.adminpasswd = STRDUP(args_info.adminpasswd_arg);
                    747: 
                    748:   if (options.ssid) free(options.ssid);
                    749:   options.ssid = STRDUP(args_info.ssid_arg);
                    750: 
                    751:   if (options.nasmac) free(options.nasmac);
                    752:   options.nasmac = STRDUP(args_info.nasmac_arg);
                    753: 
                    754:   if (options.nasip) free(options.nasip);
                    755:   options.nasip = STRDUP(args_info.nasip_arg);
                    756: 
                    757:   if (options.tundev) free(options.tundev);
                    758:   options.tundev = STRDUP(args_info.tundev_arg);
                    759: 
                    760:   if (options.radiusnasid) free(options.radiusnasid);
                    761:   options.radiusnasid = STRDUP(args_info.radiusnasid_arg);
                    762: 
                    763:   if (options.radiuslocationid) free(options.radiuslocationid);
                    764:   options.radiuslocationid = STRDUP(args_info.radiuslocationid_arg);
                    765: 
                    766:   if (options.radiuslocationname) free(options.radiuslocationname);
                    767:   options.radiuslocationname = STRDUP(args_info.radiuslocationname_arg);
                    768: 
                    769:   if (options.locationname) free(options.locationname);
                    770:   options.locationname = STRDUP(args_info.locationname_arg);
                    771: 
                    772:   if (options.radiussecret) free(options.radiussecret);
                    773:   options.radiussecret = STRDUP(args_info.radiussecret_arg);
                    774: 
                    775:   if (options.cmdsocket) free(options.cmdsocket);
                    776:   options.cmdsocket = STRDUP(args_info.cmdsocket_arg);
                    777: 
                    778:   if (options.domain) free(options.domain);
                    779:   options.domain = STRDUP(args_info.domain_arg);
                    780: 
                    781:   if (options.ipup) free(options.ipup);
                    782:   options.ipup = STRDUP(args_info.ipup_arg);
                    783: 
                    784:   if (options.ipdown) free(options.ipdown);
                    785:   options.ipdown = STRDUP(args_info.ipdown_arg);
                    786: 
                    787:   if (options.conup) free(options.conup);
                    788:   options.conup = STRDUP(args_info.conup_arg);
                    789: 
                    790:   if (options.condown) free(options.condown);
                    791:   options.condown = STRDUP(args_info.condown_arg);
                    792: 
                    793:   if (options.pidfile) free(options.pidfile);
                    794:   options.pidfile = STRDUP(args_info.pidfile_arg);
                    795: 
                    796:   if (options.statedir) free(options.statedir);
                    797:   options.statedir = STRDUP(args_info.statedir_arg);
                    798: 
                    799:   ret = 0;
                    800: 
                    801:  end_processing:
                    802:   cmdline_parser_free (&args_info);
                    803: 
                    804:   return ret;
                    805: }
                    806: 
                    807: void reprocess_options(int argc, char **argv) {
                    808:   struct options_t options2;
                    809:   log_err(0, "Rereading configuration file and doing DNS lookup");
                    810: 
                    811:   memcpy(&options2, &options, sizeof(options)); /* Save original */
                    812:   if (process_options(argc, argv, 0)) {
                    813:     log_err(0, "Error reading configuration file!");
                    814:     memcpy(&options, &options2, sizeof(options));
                    815:   }
                    816: }
                    817: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>