diff options
| author | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
| commit | 2c032d8f1c6292c1338a615e6ec40252889ba85c (patch) | |
| tree | 1f77182220b2b0264288ba4a476ab47e5bc48716 /src/supplicant-manager/nm-supplicant-config.c | |
| parent | 33491bc4279481db8ae47213e34a6d695a0e8830 (diff) | |
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'src/supplicant-manager/nm-supplicant-config.c')
| -rw-r--r-- | src/supplicant-manager/nm-supplicant-config.c | 115 |
1 files changed, 63 insertions, 52 deletions
diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c index 438b436e..9ae87095 100644 --- a/src/supplicant-manager/nm-supplicant-config.c +++ b/src/supplicant-manager/nm-supplicant-config.c @@ -19,14 +19,11 @@ * Copyright (C) 2007 - 2008 Novell, Inc. */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif +#include "config.h" #include <string.h> #include <stdlib.h> #include <glib.h> -#include <netinet/ether.h> #include <dbus/dbus-glib.h> #include "nm-supplicant-config.h" @@ -166,7 +163,7 @@ nm_supplicant_config_add_option (NMSupplicantConfig *self, static gboolean nm_supplicant_config_add_blob (NMSupplicantConfig *self, const char *key, - const GByteArray *value, + GBytes *value, const char *blobid) { NMSupplicantConfigPrivate *priv; @@ -174,16 +171,20 @@ nm_supplicant_config_add_blob (NMSupplicantConfig *self, ConfigOption *opt; OptType type; GByteArray *blob; + const guint8 *data; + gsize data_len; g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); - g_return_val_if_fail (value->len > 0, FALSE); g_return_val_if_fail (blobid != NULL, FALSE); + data = g_bytes_get_data (value, &data_len); + g_return_val_if_fail (data_len > 0, FALSE); + priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self); - type = nm_supplicant_settings_verify_setting (key, (const char *) value->data, value->len); + type = nm_supplicant_settings_verify_setting (key, (const char *) data, data_len); if (type == TYPE_INVALID) { nm_log_warn (LOGD_SUPPLICANT, "Key '%s' and/or it's contained value is invalid.", key); return FALSE; @@ -195,8 +196,8 @@ nm_supplicant_config_add_blob (NMSupplicantConfig *self, return FALSE; } - blob = g_byte_array_sized_new (value->len); - g_byte_array_append (blob, value->data, value->len); + blob = g_byte_array_sized_new (data_len); + g_byte_array_append (blob, data, data_len); opt = g_slice_new0 (ConfigOption); opt->value = g_strdup_printf ("blob://%s", blobid); @@ -328,9 +329,6 @@ nm_supplicant_config_get_blobs (NMSupplicantConfig * self) return NM_SUPPLICANT_CONFIG_GET_PRIVATE (self)->blobs; } -#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" -#define MAC_ARG(x) ((guint8*)(x))[0],((guint8*)(x))[1],((guint8*)(x))[2],((guint8*)(x))[3],((guint8*)(x))[4],((guint8*)(x))[5] - #define TWO_GHZ_FREQS "2412,2417,2422,2427,2432,2437,2442,2447,2452,2457,2462,2467,2472,2484" #define FIVE_GHZ_FREQS "4915,4920,4925,4935,4940,4945,4960,4980,5035,5040,5045,5055,5060,5080," \ "5170,5180,5190,5200,5210,5220,5230,5240,5260,5280,5300,5320,5500," \ @@ -346,7 +344,8 @@ nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self, NMSupplicantConfigPrivate *priv; gboolean is_adhoc, is_ap; const char *mode, *band; - const GByteArray *id; + GBytes *ssid; + const char *bssid; g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE); g_return_val_if_fail (setting != NULL, FALSE); @@ -361,8 +360,11 @@ nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self, else priv->ap_scan = 1; - id = nm_setting_wireless_get_ssid (setting); - if (!nm_supplicant_config_add_option (self, "ssid", (char *) id->data, id->len, FALSE)) { + ssid = nm_setting_wireless_get_ssid (setting); + if (!nm_supplicant_config_add_option (self, "ssid", + (char *) g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid), + FALSE)) { nm_log_warn (LOGD_SUPPLICANT, "Error adding SSID to supplicant config."); return FALSE; } @@ -401,19 +403,14 @@ nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self, return FALSE; } - id = nm_setting_wireless_get_bssid (setting); - if (id && id->len) { - char *str_bssid; - - str_bssid = g_strdup_printf (MAC_FMT, MAC_ARG (id->data)); + bssid = nm_setting_wireless_get_bssid (setting); + if (bssid) { if (!nm_supplicant_config_add_option (self, "bssid", - str_bssid, strlen (str_bssid), + bssid, strlen (bssid), FALSE)) { - g_free (str_bssid); nm_log_warn (LOGD_SUPPLICANT, "Error adding BSSID to supplicant config."); return FALSE; } - g_free (str_bssid); } band = nm_setting_wireless_get_band (setting); @@ -496,7 +493,7 @@ get_blob_id (const char *name, const char *seed_uid) } #define ADD_BLOB_VAL(field, name, con_uid) \ - if (field && field->len) { \ + if (field && g_bytes_get_size (field)) { \ char *uid = get_blob_id (name, con_uid); \ success = nm_supplicant_config_add_blob (self, name, field, uid); \ g_free (uid); \ @@ -543,8 +540,8 @@ add_wep_key (NMSupplicantConfig *self, const char *name, NMWepKeyType wep_type) { - char *value; - gboolean success; + GBytes *bytes; + gboolean success = FALSE; size_t key_len = key ? strlen (key) : 0; if (!key || !key_len) @@ -553,9 +550,15 @@ add_wep_key (NMSupplicantConfig *self, if ( (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) || (wep_type == NM_WEP_KEY_TYPE_KEY)) { if ((key_len == 10) || (key_len == 26)) { - value = nm_utils_hexstr2bin (key, strlen (key)); - success = nm_supplicant_config_add_option (self, name, value, key_len / 2, TRUE); - g_free (value); + bytes = nm_utils_hexstr2bin (key); + if (bytes) { + success = nm_supplicant_config_add_option (self, + name, + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), + TRUE); + g_bytes_unref (bytes); + } if (!success) { nm_log_warn (LOGD_SUPPLICANT, "Error adding %s to supplicant config.", name); return FALSE; @@ -591,8 +594,7 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self, NMSetting8021x *setting_8021x, const char *con_uuid) { - char *value; - gboolean success; + gboolean success = FALSE; const char *key_mgmt, *auth_alg; const char *psk; @@ -613,10 +615,18 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self, size_t psk_len = strlen (psk); if (psk_len == 64) { + GBytes *bytes; + /* Hex PSK */ - value = nm_utils_hexstr2bin (psk, psk_len); - success = nm_supplicant_config_add_option (self, "psk", value, psk_len / 2, TRUE); - g_free (value); + bytes = nm_utils_hexstr2bin (psk); + if (bytes) { + success = nm_supplicant_config_add_option (self, + "psk", + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), + TRUE); + g_bytes_unref (bytes); + } if (!success) { nm_log_warn (LOGD_SUPPLICANT, "Error adding 'psk' to supplicant config."); return FALSE; @@ -654,6 +664,7 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self, const char *wep1 = nm_setting_wireless_security_get_wep_key (setting, 1); const char *wep2 = nm_setting_wireless_security_get_wep_key (setting, 2); const char *wep3 = nm_setting_wireless_security_get_wep_key (setting, 3); + char *value; if (!add_wep_key (self, wep0, "wep_key0", wep_type)) return FALSE; @@ -732,7 +743,7 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, const char *peapver, *value, *path; gboolean success, added; GString *phase1, *phase2; - const GByteArray *array; + GBytes *bytes; gboolean fast = FALSE; guint32 i, num_eap; gboolean fast_provisoning_allowed = FALSE; @@ -748,12 +759,12 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, if (!add_string_val (self, value, "password", FALSE, TRUE)) return FALSE; } else { - array = nm_setting_802_1x_get_password_raw (setting); - if (array) { + bytes = nm_setting_802_1x_get_password_raw (setting); + if (bytes) { success = nm_supplicant_config_add_option (self, "password", - (const char *)array->data, - array->len, + (const char *) g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), TRUE); if (!success) { nm_log_warn (LOGD_SUPPLICANT, "Error adding password-raw to supplicant config."); @@ -894,8 +905,8 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, /* CA certificate */ switch (nm_setting_802_1x_get_ca_cert_scheme (setting)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - array = nm_setting_802_1x_get_ca_cert_blob (setting); - ADD_BLOB_VAL (array, "ca_cert", con_uuid); + bytes = nm_setting_802_1x_get_ca_cert_blob (setting); + ADD_BLOB_VAL (bytes, "ca_cert", con_uuid); break; case NM_SETTING_802_1X_CK_SCHEME_PATH: path = nm_setting_802_1x_get_ca_cert_path (setting); @@ -909,8 +920,8 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, /* Phase 2 CA certificate */ switch (nm_setting_802_1x_get_phase2_ca_cert_scheme (setting)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - array = nm_setting_802_1x_get_phase2_ca_cert_blob (setting); - ADD_BLOB_VAL (array, "ca_cert2", con_uuid); + bytes = nm_setting_802_1x_get_phase2_ca_cert_blob (setting); + ADD_BLOB_VAL (bytes, "ca_cert2", con_uuid); break; case NM_SETTING_802_1X_CK_SCHEME_PATH: path = nm_setting_802_1x_get_phase2_ca_cert_path (setting); @@ -937,8 +948,8 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, added = FALSE; switch (nm_setting_802_1x_get_private_key_scheme (setting)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - array = nm_setting_802_1x_get_private_key_blob (setting); - ADD_BLOB_VAL (array, "private_key", con_uuid); + bytes = nm_setting_802_1x_get_private_key_blob (setting); + ADD_BLOB_VAL (bytes, "private_key", con_uuid); added = TRUE; break; case NM_SETTING_802_1X_CK_SCHEME_PATH: @@ -975,8 +986,8 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, */ switch (nm_setting_802_1x_get_client_cert_scheme (setting)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - array = nm_setting_802_1x_get_client_cert_blob (setting); - ADD_BLOB_VAL (array, "client_cert", con_uuid); + bytes = nm_setting_802_1x_get_client_cert_blob (setting); + ADD_BLOB_VAL (bytes, "client_cert", con_uuid); break; case NM_SETTING_802_1X_CK_SCHEME_PATH: path = nm_setting_802_1x_get_client_cert_path (setting); @@ -993,8 +1004,8 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, added = FALSE; switch (nm_setting_802_1x_get_phase2_private_key_scheme (setting)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - array = nm_setting_802_1x_get_phase2_private_key_blob (setting); - ADD_BLOB_VAL (array, "private_key2", con_uuid); + bytes = nm_setting_802_1x_get_phase2_private_key_blob (setting); + ADD_BLOB_VAL (bytes, "private_key2", con_uuid); added = TRUE; break; case NM_SETTING_802_1X_CK_SCHEME_PATH: @@ -1021,7 +1032,7 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, * isn't decrypted at all. */ value = nm_setting_802_1x_get_phase2_private_key_password (setting); - if (!add_string_val (self, value, "private_key_passwd2", FALSE, TRUE)) + if (!add_string_val (self, value, "private_key2_passwd", FALSE, TRUE)) return FALSE; } @@ -1031,8 +1042,8 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, */ switch (nm_setting_802_1x_get_phase2_client_cert_scheme (setting)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - array = nm_setting_802_1x_get_phase2_client_cert_blob (setting); - ADD_BLOB_VAL (array, "client_cert2", con_uuid); + bytes = nm_setting_802_1x_get_phase2_client_cert_blob (setting); + ADD_BLOB_VAL (bytes, "client_cert2", con_uuid); break; case NM_SETTING_802_1X_CK_SCHEME_PATH: path = nm_setting_802_1x_get_phase2_client_cert_path (setting); |