diff options
Diffstat (limited to 'src/nmtui/nm-editor-bindings.c')
-rw-r--r-- | src/nmtui/nm-editor-bindings.c | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/src/nmtui/nm-editor-bindings.c b/src/nmtui/nm-editor-bindings.c index f1d92adebc..360cf3ad97 100644 --- a/src/nmtui/nm-editor-bindings.c +++ b/src/nmtui/nm-editor-bindings.c @@ -54,6 +54,51 @@ nm_editor_bindings_init(void) g_value_register_transform_func(G_TYPE_STRING, G_TYPE_UINT, value_transform_string_uint); } +gboolean +certificate_to_string(GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + GBytes *bytes; + char *utf8; + + bytes = g_value_get_boxed(source_value); + if (bytes) + utf8 = nm_utils_ssid_to_utf8(g_bytes_get_data(bytes, NULL), g_bytes_get_size(bytes)); + else + utf8 = g_strdup(""); + g_value_take_string(target_value, utf8); + return TRUE; +} + +gboolean +certificate_from_string(GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + const char *text; + gs_free char *cert = NULL; + GBytes *bytes = NULL; + + text = g_value_get_string(source_value); + + if (text[0]) { + /* Consider anything without a scheme prefix as an absolute path */ + if (!g_str_has_prefix(text, "file://") && !g_str_has_prefix(text, "blob://") + && !g_str_has_prefix(text, "pkcs11://")) { + cert = g_strdup_printf("file://%s%s", text[0] == '/' ? "" : "/", text); + text = cert; + } + + bytes = g_bytes_new(text, strlen(text) + 1); + } + g_value_take_boxed(target_value, bytes); + + return TRUE; +} + static gboolean ip_addresses_with_prefix_to_strv(GBinding *binding, const GValue *source_value, @@ -803,7 +848,9 @@ peer_transform_from_persistent_keepalive_string(GBinding *binding, typedef struct { NMConnection *connection; NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; gboolean s_wsec_in_use; + gboolean s_8021x_in_use; GObject *target; char *target_property; @@ -891,6 +938,7 @@ wireless_security_target_changed(GObject *object, GParamSpec *pspec, gpointer us { NMEditorWirelessSecurityMethodBinding *binding = user_data; char *method; + gboolean need_8021x = FALSE; if (binding->updating) return; @@ -900,11 +948,14 @@ wireless_security_target_changed(GObject *object, GParamSpec *pspec, gpointer us binding->updating = TRUE; if (!strcmp(method, "none")) { - if (!binding->s_wsec_in_use) - return; - binding->s_wsec_in_use = FALSE; - nm_connection_remove_setting(binding->connection, NM_TYPE_SETTING_WIRELESS_SECURITY); - + if (binding->s_wsec_in_use) { + binding->s_wsec_in_use = FALSE; + nm_connection_remove_setting(binding->connection, NM_TYPE_SETTING_WIRELESS_SECURITY); + } + if (binding->s_8021x_in_use) { + binding->s_8021x_in_use = FALSE; + nm_connection_remove_setting(binding->connection, NM_TYPE_SETTING_802_1X); + } binding->updating = FALSE; return; } @@ -985,10 +1036,21 @@ wireless_security_target_changed(GObject *object, GParamSpec *pspec, gpointer us NULL, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_UNKNOWN, + NM_SETTING_WIRELESS_SECURITY_PSK, + NULL, NULL); + need_8021x = TRUE; } else g_warn_if_reached(); + if (need_8021x != binding->s_8021x_in_use) { + binding->s_8021x_in_use = need_8021x; + if (need_8021x) + nm_connection_add_setting(binding->connection, NM_SETTING(binding->s_8021x)); + else + nm_connection_remove_setting(binding->connection, NM_TYPE_SETTING_802_1X); + } + binding->updating = FALSE; } @@ -1031,6 +1093,7 @@ wireless_security_target_destroyed(gpointer user_data, GObject *ex_target) void nm_editor_bind_wireless_security_method(NMConnection *connection, NMSettingWirelessSecurity *s_wsec, + NMSetting8021x *s_8021x, gpointer target, const char *target_property, GBindingFlags flags) @@ -1054,9 +1117,11 @@ nm_editor_bind_wireless_security_method(NMConnection *connection, NM_CONNECTION_CHANGED, G_CALLBACK(wireless_connection_changed), binding); - binding->s_wsec_in_use = (nm_connection_get_setting_wireless_security(connection) != NULL); + binding->s_wsec_in_use = (nm_connection_get_setting_wireless_security(connection) != NULL); + binding->s_wsec = g_object_ref(s_wsec); + binding->s_8021x_in_use = (nm_connection_get_setting_802_1x(connection) != NULL); + binding->s_8021x = g_object_ref(s_8021x); - binding->s_wsec = g_object_ref(s_wsec); g_signal_connect(s_wsec, "notify::" NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, G_CALLBACK(wireless_security_changed), |