From: Michael Tremer Date: Mon, 5 Sep 2016 12:25:41 +0000 (+0200) Subject: wireless: Validate regulatory domain before setting and saving X-Git-Url: http://git.ipfire.org/?p=people%2Fstevee%2Fnetwork.git;a=commitdiff_plain;h=ab9e0fd086e9c2c1781cc2dcba7199bb8392ec9c wireless: Validate regulatory domain before setting and saving Signed-off-by: Michael Tremer Signed-off-by: Arne Fitzenreiter --- diff --git a/src/functions/functions.settings b/src/functions/functions.settings index fe9c6f04..0e50bf1f 100644 --- a/src/functions/functions.settings +++ b/src/functions/functions.settings @@ -257,15 +257,15 @@ network_settings_write() { } network_settings_set() { - # Save all settings first - settings_set $@ || return $? - # Process any settings that require immediate actin while [ $# -gt 0 ]; do - case "${1}" in + local arg=${1} + shift + + case "${arg}" in *=*) - local key=$(cli_get_key ${1}) - local val=$(cli_get_val ${1}) + local key=$(cli_get_key ${arg}) + local val=$(cli_get_val ${arg}) case "${key}" in DNS_RANDOMIZE|DNS_SEARCH_DOMAIN|DNS_USE_LOCAL_RESOLVER) @@ -273,12 +273,21 @@ network_settings_set() { ;; WIRELESS_REGULATORY_DOMAIN) - wireless_set_reg_domain "${val}" + if ! wireless_valid_reg_domain "${val}"; then + warning "Ignoring invalid wireless regulatory domain: ${val}" + continue + fi + + if ! wireless_set_reg_domain "${val}"; then + error "Error setting wireless regulatory domain: ${val}" + fi ;; esac ;; esac - shift + + # Save setting + settings_set ${arg} done return ${EXIT_OK} diff --git a/src/functions/functions.wireless b/src/functions/functions.wireless index 92519f04..38b19369 100644 --- a/src/functions/functions.wireless +++ b/src/functions/functions.wireless @@ -23,6 +23,8 @@ WIRELESS_REGULATORY_DOMAIN="00" NETWORK_SETTINGS_FILE_PARAMS="${NETWORK_SETTINGS_FILE_PARAMS} WIRELESS_REGULATORY_DOMAIN" +WIRELESS_REGULATORY_DOMAIN_DATABASE="/usr/lib/crda/regulatory.bin" + wireless_create() { local device=${1} assert isset device @@ -130,7 +132,11 @@ wireless_set_reg_domain() { shift done - assert isset country_code + # Check if configuration value is valid + if ! wireless_valid_reg_domain "${country_code}"; then + log ERROR "Invalid wireless regulatory domain: ${country_code}" + return ${EXIT_ERROR} + fi # Before the wireless reg domain is set, it helps to reset to 00 first. if enabled reset; then @@ -141,6 +147,37 @@ wireless_set_reg_domain() { iw reg set "${country_code}" } +wireless_valid_reg_domain() { + local country_code="${1}" + + # Empty country codes are invalid + isset country_code || return ${EXIT_FALSE} + + local valid_country_codes="$(wireless_list_reg_domains)" + + if list_match "${country_code}" ${valid_country_codes}; then + return ${EXIT_TRUE} + fi + + return ${EXIT_FALSE} +} + +wireless_list_reg_domains() { + if [ ! -r "${WIRELESS_REGULATORY_DOMAIN_DATABASE}" ]; then + log ERROR "Could not read ${WIRELESS_REGULATORY_DOMAIN_DATABASE}" + return ${EXIT_ERROR} + fi + + local line + while read line; do + # Check if line starts with "country" + [ "${line:0:7}" = "country" ] || continue + + # Print country code + print "${line:8:2}" + done <<< "$(regdbdump ${WIRELESS_REGULATORY_DOMAIN_DATABASE})" +} + wireless_channel_to_frequency() { # http://en.wikipedia.org/wiki/List_of_WLAN_channels