📄 config.c
字号:
printf("Line %d: invalid WEP key len %d " "(= %d bits)\n", line, bss->individual_wep_key_len, bss->individual_wep_key_len * 8); errors++; } } else if (strcmp(buf, "wep_rekey_period") == 0) { bss->wep_rekeying_period = atoi(pos); if (bss->wep_rekeying_period < 0) { printf("Line %d: invalid period %d\n", line, bss->wep_rekeying_period); errors++; } } else if (strcmp(buf, "eap_reauth_period") == 0) { bss->eap_reauth_period = atoi(pos); if (bss->eap_reauth_period < 0) { printf("Line %d: invalid period %d\n", line, bss->eap_reauth_period); errors++; } } else if (strcmp(buf, "eapol_key_index_workaround") == 0) { bss->eapol_key_index_workaround = atoi(pos);#ifdef CONFIG_IAPP } else if (strcmp(buf, "iapp_interface") == 0) { bss->ieee802_11f = 1; snprintf(bss->iapp_iface, sizeof(bss->iapp_iface), "%s", pos);#endif /* CONFIG_IAPP */ } else if (strcmp(buf, "own_ip_addr") == 0) { if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) { printf("Line %d: invalid IP address '%s'\n", line, pos); errors++; } } else if (strcmp(buf, "nas_identifier") == 0) { bss->nas_identifier = strdup(pos); } else if (strcmp(buf, "auth_server_addr") == 0) { if (hostapd_config_read_radius_addr( &bss->radius->auth_servers, &bss->radius->num_auth_servers, pos, 1812, &bss->radius->auth_server)) { printf("Line %d: invalid IP address '%s'\n", line, pos); errors++; } } else if (bss->radius->auth_server && strcmp(buf, "auth_server_port") == 0) { bss->radius->auth_server->port = atoi(pos); } else if (bss->radius->auth_server && strcmp(buf, "auth_server_shared_secret") == 0) { int len = strlen(pos); if (len == 0) { /* RFC 2865, Ch. 3 */ printf("Line %d: empty shared secret is not " "allowed.\n", line); errors++; } bss->radius->auth_server->shared_secret = (u8 *) strdup(pos); bss->radius->auth_server->shared_secret_len = len; } else if (strcmp(buf, "acct_server_addr") == 0) { if (hostapd_config_read_radius_addr( &bss->radius->acct_servers, &bss->radius->num_acct_servers, pos, 1813, &bss->radius->acct_server)) { printf("Line %d: invalid IP address '%s'\n", line, pos); errors++; } } else if (bss->radius->acct_server && strcmp(buf, "acct_server_port") == 0) { bss->radius->acct_server->port = atoi(pos); } else if (bss->radius->acct_server && strcmp(buf, "acct_server_shared_secret") == 0) { int len = strlen(pos); if (len == 0) { /* RFC 2865, Ch. 3 */ printf("Line %d: empty shared secret is not " "allowed.\n", line); errors++; } bss->radius->acct_server->shared_secret = (u8 *) strdup(pos); bss->radius->acct_server->shared_secret_len = len; } else if (strcmp(buf, "radius_retry_primary_interval") == 0) { bss->radius->retry_primary_interval = atoi(pos); } else if (strcmp(buf, "radius_acct_interim_interval") == 0) { bss->radius->acct_interim_interval = atoi(pos); } else if (strcmp(buf, "auth_algs") == 0) { bss->auth_algs = atoi(pos); if (bss->auth_algs == 0) { printf("Line %d: no authentication algorithms " "allowed\n", line); errors++; } } else if (strcmp(buf, "wpa") == 0) { bss->wpa = atoi(pos); } else if (strcmp(buf, "wpa_group_rekey") == 0) { bss->wpa_group_rekey = atoi(pos); } else if (strcmp(buf, "wpa_strict_rekey") == 0) { bss->wpa_strict_rekey = atoi(pos); } else if (strcmp(buf, "wpa_gmk_rekey") == 0) { bss->wpa_gmk_rekey = atoi(pos); } else if (strcmp(buf, "wpa_passphrase") == 0) { int len = strlen(pos); if (len < 8 || len > 63) { printf("Line %d: invalid WPA passphrase length" " %d (expected 8..63)\n", line, len); errors++; } else { free(bss->ssid.wpa_passphrase); bss->ssid.wpa_passphrase = strdup(pos); } } else if (strcmp(buf, "wpa_psk") == 0) { free(bss->ssid.wpa_psk); bss->ssid.wpa_psk = wpa_zalloc(sizeof(struct hostapd_wpa_psk)); if (bss->ssid.wpa_psk == NULL) errors++; else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') { printf("Line %d: Invalid PSK '%s'.\n", line, pos); errors++; } else { bss->ssid.wpa_psk->group = 1; } } else if (strcmp(buf, "wpa_psk_file") == 0) { free(bss->ssid.wpa_psk_file); bss->ssid.wpa_psk_file = strdup(pos); if (!bss->ssid.wpa_psk_file) { printf("Line %d: allocation failed\n", line); errors++; } } else if (strcmp(buf, "wpa_key_mgmt") == 0) { bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos); if (bss->wpa_key_mgmt == -1) errors++; } else if (strcmp(buf, "wpa_pairwise") == 0) { bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos); if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0) errors++; else if (bss->wpa_pairwise & (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) { printf("Line %d: unsupported pairwise " "cipher suite '%s'\n", bss->wpa_pairwise, pos); errors++; } else { if (bss->wpa_pairwise & WPA_CIPHER_TKIP) bss->wpa_group = WPA_CIPHER_TKIP; else bss->wpa_group = WPA_CIPHER_CCMP; }#ifdef CONFIG_RSN_PREAUTH } else if (strcmp(buf, "rsn_preauth") == 0) { bss->rsn_preauth = atoi(pos); } else if (strcmp(buf, "rsn_preauth_interfaces") == 0) { bss->rsn_preauth_interfaces = strdup(pos);#endif /* CONFIG_RSN_PREAUTH */#ifdef CONFIG_STAKEY } else if (strcmp(buf, "stakey") == 0) { bss->stakey = atoi(pos);#endif /* CONFIG_STAKEY */ } else if (strcmp(buf, "ctrl_interface") == 0) { free(bss->ctrl_interface); bss->ctrl_interface = strdup(pos); } else if (strcmp(buf, "ctrl_interface_group") == 0) {#ifndef CONFIG_NATIVE_WINDOWS struct group *grp; char *endp; const char *group = pos; grp = getgrnam(group); if (grp) { bss->ctrl_interface_gid = grp->gr_gid; bss->ctrl_interface_gid_set = 1; wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d" " (from group name '%s')", bss->ctrl_interface_gid, group); continue; } /* Group name not found - try to parse this as gid */ bss->ctrl_interface_gid = strtol(group, &endp, 10); if (*group == '\0' || *endp != '\0') { wpa_printf(MSG_DEBUG, "Line %d: Invalid group " "'%s'", line, group); errors++; continue; } bss->ctrl_interface_gid_set = 1; wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d", bss->ctrl_interface_gid);#endif /* CONFIG_NATIVE_WINDOWS */#ifdef RADIUS_SERVER } else if (strcmp(buf, "radius_server_clients") == 0) { free(bss->radius_server_clients); bss->radius_server_clients = strdup(pos); } else if (strcmp(buf, "radius_server_auth_port") == 0) { bss->radius_server_auth_port = atoi(pos); } else if (strcmp(buf, "radius_server_ipv6") == 0) { bss->radius_server_ipv6 = atoi(pos);#endif /* RADIUS_SERVER */ } else if (strcmp(buf, "test_socket") == 0) { free(bss->test_socket); bss->test_socket = strdup(pos); } else if (strcmp(buf, "use_pae_group_addr") == 0) { bss->use_pae_group_addr = atoi(pos); } else if (strcmp(buf, "hw_mode") == 0) { if (strcmp(pos, "a") == 0) conf->hw_mode = HOSTAPD_MODE_IEEE80211A; else if (strcmp(pos, "b") == 0) conf->hw_mode = HOSTAPD_MODE_IEEE80211B; else if (strcmp(pos, "g") == 0) conf->hw_mode = HOSTAPD_MODE_IEEE80211G; else { printf("Line %d: unknown hw_mode '%s'\n", line, pos); errors++; } } else if (strcmp(buf, "channel") == 0) { conf->channel = atoi(pos); } else if (strcmp(buf, "beacon_int") == 0) { int val = atoi(pos); /* MIB defines range as 1..65535, but very small values * cause problems with the current implementation. * Since it is unlikely that this small numbers are * useful in real life scenarios, do not allow beacon * period to be set below 15 TU. */ if (val < 15 || val > 65535) { printf("Line %d: invalid beacon_int %d " "(expected 15..65535)\n", line, val); errors++; } else conf->beacon_int = val; } else if (strcmp(buf, "supported_rates") == 0) { if (hostapd_parse_rates(&conf->supported_rates, pos)) { printf("Line %d: invalid rate list\n", line); errors++; } } else if (strcmp(buf, "basic_rates") == 0) { if (hostapd_parse_rates(&conf->basic_rates, pos)) { printf("Line %d: invalid rate list\n", line); errors++; } } else if (strcmp(buf, "ignore_broadcast_ssid") == 0) { bss->ignore_broadcast_ssid = atoi(pos); } else if (strcmp(buf, "wep_default_key") == 0) { bss->ssid.wep.idx = atoi(pos); if (bss->ssid.wep.idx > 3) { printf("Invalid wep_default_key index %d\n", bss->ssid.wep.idx); errors++; } } else if (strcmp(buf, "wep_key0") == 0 || strcmp(buf, "wep_key1") == 0 || strcmp(buf, "wep_key2") == 0 || strcmp(buf, "wep_key3") == 0) { if (hostapd_config_read_wep(&bss->ssid.wep, buf[7] - '0', pos)) { printf("Line %d: invalid WEP key '%s'\n", line, buf); errors++; } } else if (strcmp(buf, "dynamic_vlan") == 0) { bss->ssid.dynamic_vlan = atoi(pos); } else { printf("Line %d: unknown configuration item '%s'\n", line, buf); errors++; } } fclose(f); for (i = 0; i < conf->num_bss; i++) { bss = &conf->bss[i]; bss->radius->auth_server = bss->radius->auth_servers; bss->radius->acct_server = bss->radius->acct_servers; if (bss->wpa && bss->ieee802_1x) { bss->ssid.security_policy = SECURITY_WPA; } else if (bss->wpa) { bss->ssid.security_policy = SECURITY_WPA_PSK; } else if (bss->ieee802_1x) { bss->ssid.security_policy = SECURITY_IEEE_802_1X; bss->ssid.wep.default_len = bss->default_wep_key_len; } else if (bss->ssid.wep.keys_set) bss->ssid.security_policy = SECURITY_STATIC_WEP; else bss->ssid.security_policy = SECURITY_PLAINTEXT; if (hostapd_config_check(bss)) errors++; } if (errors) { printf("%d errors found in configuration file '%s'\n", errors, fname); hostapd_config_free(conf); conf = NULL; } return conf;}static void hostapd_config_free_radius(struct hostapd_radius_server *servers, int num_servers){ int i; for (i = 0; i < num_servers; i++) { free(servers[i].shared_secret); } free(servers);}static void hostapd_config_free_eap_user(struct hostapd_eap_user *user){ free(user->identity); free(user->password); free(user);}static void hostapd_config_free_bss(struct hostapd_bss_config *conf){ struct hostapd_wpa_psk *psk, *prev; struct hostapd_eap_user *user, *prev_user; if (conf == NULL) return; psk = conf->ssid.wpa_psk; while (psk) { prev = psk; psk = psk->next; free(prev); } free(conf->ssid.wpa_passphrase); free(conf->ssid.wpa_psk_file); user = conf->eap_user; while (user) { prev_user = user; user = user->next; hostapd_config_free_eap_user(prev_user); } free(conf->dump_log_name); free(conf->eap_req_id_text); free(conf->accept_mac); free(conf->deny_mac); free(conf->nas_identifier); hostapd_config_free_radius(conf->radius->auth_servers, conf->radius->num_auth_servers); hostapd_config_free_radius(conf->radius->acct_servers, conf->radius->num_acct_servers); free(conf->rsn_preauth_interfaces); free(conf->ctrl_interface); free(conf->ca_cert); free(conf->server_cert); free(conf->private_key); free(conf->private_key_passwd); free(conf->eap_sim_db); free(conf->radius_server_clients); free(conf->test_socket);}void hostapd_config_free(struct hostapd_config *conf){ int i; if (conf == NULL) return; for (i = 0; i < conf->num_bss; i++) hostapd_config_free_bss(&conf->bss[i]); free(conf->bss); free(conf);}/* Perform a binary search for given MAC address from a pre-sorted list. * Returns 1 if address is in the list or 0 if not. */int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr){ int start, end, middle, res; start = 0; end = num_entries - 1; while (start <= end) { middle = (start + end) / 2; res = memcmp(list[middle], addr, ETH_ALEN); if (res == 0) return 1; if (res < 0) start = middle + 1; else end = middle - 1; } return 0;}int hostapd_rate_found(int *list, int rate){ int i; if (list == NULL) return 0; for (i = 0; list[i] >= 0; i++) if (list[i] == rate) return 1; return 0;}const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, const u8 *addr, const u8 *prev_psk){ struct hostapd_wpa_psk *psk; int next_ok = prev_psk == NULL; for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) { if (next_ok && (psk->group || memcmp(psk->addr, addr, ETH_ALEN) == 0)) return psk->psk; if (psk->psk == prev_psk) next_ok = 1; } return NULL;}const struct hostapd_eap_user *hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity, size_t identity_len, int phase2){ struct hostapd_eap_user *user = conf->eap_user; while (user) { if (!phase2 && user->identity == NULL) { /* Wildcard match */ break; } if (!phase2 && user->wildcard_prefix && identity_len >= user->identity_len && memcmp(user->identity, identity, user->identity_len) == 0) { /* Wildcard prefix match */ break; } if (user->phase2 == !!phase2 && user->identity_len == identity_len && memcmp(user->identity, identity, identity_len) == 0) break; user = user->next; } return user;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -