]> git.ipfire.org Git - people/stevee/network.git/commitdiff
wireless: Validate regulatory domain before setting and saving
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Sep 2016 12:25:41 +0000 (14:25 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Sep 2016 12:25:41 +0000 (14:25 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne.fitzenreiter@ipfire.org>
src/functions/functions.settings
src/functions/functions.wireless

index fe9c6f04c019f3ec63762378e1669505f3a1435b..0e50bf1fe6dea685e8125a217e7fc9c01663b7df 100644 (file)
@@ -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}
index 92519f0482b50939a71ee7cff95f9fbf41f4a0b9..38b1936919b052a527f4fbe9c088964c3e295c77 100644 (file)
@@ -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