diff options
| author | Michael Biebl <biebl@debian.org> | 2019-08-06 22:46:20 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2019-08-06 22:46:20 +0200 |
| commit | 5c79b900b59a5ad162ecc836e424468207ff031e (patch) | |
| tree | 2f529ff5c2d8531a2bf2973d96e316786eee9799 /src/supplicant | |
| parent | 2e5fa45ddfbb5cffa1e78221f1cea706e2f298af (diff) | |
New upstream version 1.20.0 upstream/1.20.0
Diffstat (limited to 'src/supplicant')
| -rw-r--r-- | src/supplicant/nm-supplicant-config.c | 14 | ||||
| -rw-r--r-- | src/supplicant/nm-supplicant-settings-verify.c | 100 |
2 files changed, 63 insertions, 51 deletions
diff --git a/src/supplicant/nm-supplicant-config.c b/src/supplicant/nm-supplicant-config.c index 806c087c..f6e3c7da 100644 --- a/src/supplicant/nm-supplicant-config.c +++ b/src/supplicant/nm-supplicant-config.c @@ -139,11 +139,17 @@ nm_supplicant_config_add_option_with_type (NMSupplicantConfig *self, else { type = nm_supplicant_settings_verify_setting (key, value, len); if (type == TYPE_INVALID) { - char buf[255]; - memset (&buf[0], 0, sizeof (buf)); - memcpy (&buf[0], value, len > 254 ? 254 : len); + gs_free char *str_free = NULL; + const char *str; + + str = nm_utils_buf_utf8safe_escape (value, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &str_free); + + str = nm_strquote_a (255, str); + g_set_error (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG, - "key '%s' and/or value '%s' invalid", key, hidden ?: buf); + "key '%s' and/or value %s invalid", + key, + hidden ?: str); return FALSE; } } diff --git a/src/supplicant/nm-supplicant-settings-verify.c b/src/supplicant/nm-supplicant-settings-verify.c index 1bd71320..b37fae9e 100644 --- a/src/supplicant/nm-supplicant-settings-verify.c +++ b/src/supplicant/nm-supplicant-settings-verify.c @@ -30,7 +30,7 @@ struct Opt { const gint32 int_low; /* Inclusive */ const gint32 int_high; /* Inclusive; max length for strings */ const gboolean str_allowed_multiple; - const char ** str_allowed; + const char *const*str_allowed; }; static gboolean validate_type_int (const struct Opt * opt, @@ -63,31 +63,31 @@ static const struct validate_entry validate_table[] = { { TYPE_KEYWORD, validate_type_keyword }, }; -const char * pairwise_allowed[] = { "CCMP", "TKIP", "NONE", NULL }; -const char * group_allowed[] = { "CCMP", "TKIP", "WEP104", "WEP40", NULL }; -const char * proto_allowed[] = { "WPA", "RSN", NULL }; -const char * key_mgmt_allowed[] = { "WPA-PSK", "WPA-PSK-SHA256", "FT-PSK", - "WPA-EAP", "WPA-EAP-SHA256", "FT-EAP", "FT-EAP-SHA384", - "FILS-SHA256", "FILS-SHA384", - "IEEE8021X", "WPA-NONE", "SAE", - "NONE", NULL }; -const char * auth_alg_allowed[] = { "OPEN", "SHARED", "LEAP", NULL }; -const char * eap_allowed[] = { "LEAP", "MD5", "TLS", "PEAP", "TTLS", "SIM", - "PSK", "FAST", "PWD", NULL }; - -const char * phase1_allowed[] = {"peapver=0", "peapver=1", "peaplabel=1", - "peap_outer_success=0", "include_tls_length=1", - "sim_min_num_chal=3", "fast_provisioning=0", - "fast_provisioning=1", "fast_provisioning=2", - "fast_provisioning=3", "tls_disable_tlsv1_0=0", - "tls_disable_tlsv1_0=1", "tls_disable_tlsv1_1=0", - "tls_disable_tlsv1_1=1", "tls_disable_tlsv1_2=0", - "tls_disable_tlsv1_2=1", NULL }; -const char * phase2_allowed[] = {"auth=PAP", "auth=CHAP", "auth=MSCHAP", - "auth=MSCHAPV2", "auth=GTC", "auth=OTP", - "auth=MD5", "auth=TLS", "autheap=MD5", - "autheap=MSCHAPV2", "autheap=OTP", - "autheap=GTC", "autheap=TLS", NULL }; +static const char *const pairwise_allowed[] = { "CCMP", "TKIP", "NONE", NULL }; +static const char *const group_allowed[] = { "CCMP", "TKIP", "WEP104", "WEP40", NULL }; +static const char *const proto_allowed[] = { "WPA", "RSN", NULL }; +static const char *const key_mgmt_allowed[] = { "WPA-PSK", "WPA-PSK-SHA256", "FT-PSK", + "WPA-EAP", "WPA-EAP-SHA256", "FT-EAP", "FT-EAP-SHA384", + "FILS-SHA256", "FILS-SHA384", + "IEEE8021X", "WPA-NONE", "SAE", + "NONE", NULL }; +static const char *const auth_alg_allowed[] = { "OPEN", "SHARED", "LEAP", NULL }; +static const char *const eap_allowed[] = { "LEAP", "MD5", "TLS", "PEAP", "TTLS", "SIM", + "PSK", "FAST", "PWD", NULL }; + +static const char *const phase1_allowed[] = { "peapver=0", "peapver=1", "peaplabel=1", + "peap_outer_success=0", "include_tls_length=1", + "sim_min_num_chal=3", "fast_provisioning=0", + "fast_provisioning=1", "fast_provisioning=2", + "fast_provisioning=3", "tls_disable_tlsv1_0=0", + "tls_disable_tlsv1_0=1", "tls_disable_tlsv1_1=0", + "tls_disable_tlsv1_1=1", "tls_disable_tlsv1_2=0", + "tls_disable_tlsv1_2=1", NULL }; +static const char *const phase2_allowed[] = { "auth=PAP", "auth=CHAP", "auth=MSCHAP", + "auth=MSCHAPV2", "auth=GTC", "auth=OTP", + "auth=MD5", "auth=TLS", "autheap=MD5", + "autheap=MSCHAPV2", "autheap=OTP", + "autheap=GTC", "autheap=TLS", NULL }; static const struct Opt opt_table[] = { { "ssid", TYPE_BYTES, 0, 32,FALSE, NULL }, @@ -206,10 +206,7 @@ validate_type_keyword (const struct Opt * opt, const char * value, const guint32 len) { - char **allowed; - char **candidates = NULL; - char **candidate; - gboolean found = FALSE; + gs_free char *value_free = NULL; g_return_val_if_fail (opt != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); @@ -218,26 +215,33 @@ validate_type_keyword (const struct Opt * opt, if (!opt->str_allowed) return TRUE; - candidates = g_strsplit (value, " ", 0); - if (!candidates) - goto out; + value = nm_strndup_a (300, value, len, &value_free); /* validate each space-separated word in 'value' */ - for (candidate = candidates; *candidate; candidate++) { - found = FALSE; - for (allowed = (char **) opt->str_allowed; *allowed; allowed++) { - if (strcmp (*candidate, *allowed) == 0) { - found = TRUE; - break; - } + + while (TRUE) { + char *s; + + while (value[0] == ' ') + value++; + + if (value[0] == '\0') + return TRUE; + + s = strchr (value, ' '); + if (s) { + s[0] = '\0'; + s++; } - if (!found) - break; - } -out: - g_strfreev (candidates); - return found; + if (nm_utils_strv_find_first ((char **) opt->str_allowed, -1, value) < 0) + return FALSE; + + if (!s) + return TRUE; + + value = s; + } } OptType @@ -254,7 +258,9 @@ nm_supplicant_settings_verify_setting (const char * key, g_return_val_if_fail (value != NULL, FALSE); if (strcmp (key, "mode") == 0) { - if (strcmp (value, "1") && strcmp (value, "2") && strcmp (value, "5")) + if (len != 1) + return TYPE_INVALID; + if (!NM_IN_SET (value[0], '1', '2', '5')) return TYPE_INVALID; return TYPE_INT; } |