diff options
| author | Michael Biebl <biebl@debian.org> | 2018-09-08 17:44:06 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2018-09-08 17:44:06 +0200 |
| commit | 8f7a3cbbdd0c0a48277c341dd3a8ec8743ae9735 (patch) | |
| tree | 4353551fcb59cc822c3cadf2f4888f70601e8fbf /src/settings/plugins/keyfile | |
| parent | caf1db9d6fbc056cc6c76a24574890f6c7895f3d (diff) | |
New upstream version 1.13.90 upstream/1.13.90
Diffstat (limited to 'src/settings/plugins/keyfile')
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-connection.c | 12 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-plugin.c | 58 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-reader.c | 8 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-utils.h | 4 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-writer.c | 11 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/tests/meson.build | 1 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/tests/test-keyfile.c | 55 |
7 files changed, 59 insertions, 90 deletions
diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c index 5f72a9fa..64e94b26 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -75,9 +75,7 @@ commit_changes (NMSettingsConnection *connection, error)) return FALSE; - /* Update the filename if it changed */ - if ( path - && g_strcmp0 (path, nm_settings_connection_get_filename (connection)) != 0) { + if (!nm_streq0 (path, nm_settings_connection_get_filename (connection))) { gs_free char *old_path = g_strdup (nm_settings_connection_get_filename (connection)); nm_settings_connection_set_filename (connection, path); @@ -142,7 +140,7 @@ nms_keyfile_connection_new (NMConnection *source, if (!tmp) return NULL; - uuid = nm_connection_get_uuid (NM_CONNECTION (tmp)); + uuid = nm_connection_get_uuid (tmp); if (!uuid) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Connection in file %s had no UUID", full_path); @@ -154,9 +152,9 @@ nms_keyfile_connection_new (NMConnection *source, update_unsaved = FALSE; } - object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION, - NM_SETTINGS_CONNECTION_FILENAME, full_path, - NULL); + object = g_object_new (NMS_TYPE_KEYFILE_CONNECTION, + NM_SETTINGS_CONNECTION_FILENAME, full_path, + NULL); /* Update our settings with what was read from the file */ if (!nm_settings_connection_update (NM_SETTINGS_CONNECTION (object), diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index 3723db94..89b89467 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -56,19 +56,15 @@ typedef struct { } NMSKeyfilePluginPrivate; struct _NMSKeyfilePlugin { - GObject parent; + NMSettingsPlugin parent; NMSKeyfilePluginPrivate _priv; }; struct _NMSKeyfilePluginClass { - GObjectClass parent; + NMSettingsPluginClass parent; }; -static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); - -G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, - settings_plugin_interface_init)) +G_DEFINE_TYPE (NMSKeyfilePlugin, nms_keyfile_plugin, NM_TYPE_SETTINGS_PLUGIN) #define NMS_KEYFILE_PLUGIN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMSKeyfilePlugin, NMS_IS_KEYFILE_PLUGIN) @@ -85,10 +81,10 @@ G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0, /*****************************************************************************/ static void -connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) +connection_removed_cb (NMSettingsConnection *sett_conn, NMSKeyfilePlugin *self) { - g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) user_data)->connections, - nm_connection_get_uuid (NM_CONNECTION (obj))); + g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections, + nm_settings_connection_get_uuid (sett_conn)); } /* Monitoring */ @@ -106,7 +102,7 @@ remove_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection) g_object_ref (connection); g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self); removed = g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections, - nm_connection_get_uuid (NM_CONNECTION (connection))); + nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection))); nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection)); g_object_unref (connection); @@ -197,7 +193,7 @@ update_connection (NMSKeyfilePlugin *self, return NULL; } - uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new)); + uuid = nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_new)); connection_by_uuid = g_hash_table_lookup (priv->connections, uuid); if ( connection @@ -240,8 +236,8 @@ update_connection (NMSKeyfilePlugin *self, old_path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)); - if (nm_connection_compare (NM_CONNECTION (connection_by_uuid), - NM_CONNECTION (connection_new), + if (nm_connection_compare (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_by_uuid)), + nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_new)), NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { /* Nothing to do... except updating the path. */ @@ -259,7 +255,7 @@ update_connection (NMSKeyfilePlugin *self, _LOGI ("update and persist "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); if (!nm_settings_connection_update (NM_SETTINGS_CONNECTION (connection_by_uuid), - NM_CONNECTION (connection_new), + nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_new)), NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED, NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE, "keyfile-update", @@ -287,8 +283,10 @@ update_connection (NMSKeyfilePlugin *self, if (!source) { /* Only raise the signal if we were called without source, i.e. if we read the connection from file. * Otherwise, we were called by add_connection() which does not expect the signal. */ - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_new); + _nm_settings_plugin_emit_signal_connection_added (NM_SETTINGS_PLUGIN (self), + NM_SETTINGS_CONNECTION (connection_new)); } + return connection_new; } } @@ -341,13 +339,14 @@ config_changed_cb (NMConfig *config, NMConfigData *old_data, NMSKeyfilePlugin *self) { - gs_free char *old_value = NULL, *new_value = NULL; + gs_free char *old_value = NULL; + gs_free char *new_value = NULL; old_value = nm_config_data_get_value (old_data, NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES, NM_CONFIG_GET_VALUE_TYPE_SPEC); new_value = nm_config_data_get_value (config_data, NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES, NM_CONFIG_GET_VALUE_TYPE_SPEC); - if (g_strcmp0 (old_value, new_value) != 0) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); + if (!nm_streq0 (old_value, new_value)) + _nm_settings_plugin_emit_signal_unmanaged_specs_changed (NM_SETTINGS_PLUGIN (self)); } static void @@ -616,20 +615,17 @@ dispose (GObject *object) } static void -nms_keyfile_plugin_class_init (NMSKeyfilePluginClass *req_class) +nms_keyfile_plugin_class_init (NMSKeyfilePluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (req_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMSettingsPluginClass *plugin_class = NM_SETTINGS_PLUGIN_CLASS (klass); object_class->constructed = constructed; - object_class->dispose = dispose; -} + object_class->dispose = dispose; -static void -settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface) -{ - plugin_iface->get_connections = get_connections; - plugin_iface->load_connection = load_connection; - plugin_iface->reload_connections = reload_connections; - plugin_iface->add_connection = add_connection; - plugin_iface->get_unmanaged_specs = get_unmanaged_specs; + plugin_class->get_connections = get_connections; + plugin_class->load_connection = load_connection; + plugin_class->reload_connections = reload_connections; + plugin_class->add_connection = add_connection; + plugin_class->get_unmanaged_specs = get_unmanaged_specs; } diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c index cb4b8379..71578686 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -115,7 +115,7 @@ nms_keyfile_reader_from_keyfile (GKeyFile *key_file, NMConnection * nms_keyfile_reader_from_file (const char *filename, GError **error) { - GKeyFile *key_file; + gs_unref_keyfile GKeyFile *key_file = NULL; struct stat statbuf; NMConnection *connection = NULL; GError *verify_error = NULL; @@ -144,11 +144,11 @@ nms_keyfile_reader_from_file (const char *filename, GError **error) key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error)) - goto out; + return NULL; connection = nms_keyfile_reader_from_keyfile (key_file, filename, TRUE, error); if (!connection) - goto out; + return NULL; /* Normalize and verify the connection */ if (!nm_connection_normalize (connection, NULL, NULL, &verify_error)) { @@ -160,8 +160,6 @@ nms_keyfile_reader_from_file (const char *filename, GError **error) connection = NULL; } -out: - g_key_file_free (key_file); return connection; } diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h index cd3f42b9..d5ddb8d5 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.h +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h @@ -25,9 +25,9 @@ #define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") #define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")" -#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) +#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)) #define NMS_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" -#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con) +#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)), (con) gboolean nms_keyfile_utils_should_ignore_file (const char *filename); diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index 270a217e..194b97d4 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -34,6 +34,8 @@ #include "nms-keyfile-utils.h" #include "nms-keyfile-reader.h" +#include "nm-utils/nm-io-utils.h" + /*****************************************************************************/ typedef struct { @@ -127,7 +129,7 @@ cert_writer (NMConnection *connection, new_path = g_strdup_printf ("%s/%s-%s.%s", info->keyfile_dir, nm_connection_get_uuid (connection), cert_data->vtable->file_suffix, ext); - success = nm_utils_file_set_contents (new_path, (const gchar *) blob_data, + success = nm_utils_file_set_contents (new_path, (const char *) blob_data, blob_len, 0600, &local); if (success) { /* Write the path value to the keyfile. @@ -297,11 +299,6 @@ _internal_write_connection (NMConnection *connection, return FALSE; } - if (out_path && g_strcmp0 (existing_path, path)) { - *out_path = path; /* pass path out to caller */ - path = NULL; - } - if (out_reread || out_reread_same) { gs_unref_object NMConnection *reread = NULL; @@ -333,6 +330,8 @@ _internal_write_connection (NMConnection *connection, NM_SET_OUT (out_reread_same, reread_same); } + NM_SET_OUT (out_path, g_steal_pointer (&path)); + return TRUE; } diff --git a/src/settings/plugins/keyfile/tests/meson.build b/src/settings/plugins/keyfile/tests/meson.build index 33aaa264..8b94b256 100644 --- a/src/settings/plugins/keyfile/tests/meson.build +++ b/src/settings/plugins/keyfile/tests/meson.build @@ -6,7 +6,6 @@ exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: nm_build_cflags, ) test( diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index a3045f7d..b4c6b1e2 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -960,7 +960,7 @@ test_write_intlist_ssid (void) unsigned char tmpssid[] = { 65, 49, 50, 51, 0, 50, 50 }; gs_free_error GError *error = NULL; gs_unref_keyfile GKeyFile *keyfile = NULL; - gint *intlist; + int *intlist; gsize len = 0, i; connection = nm_simple_connection_new (); @@ -1018,27 +1018,20 @@ test_read_intlike_ssid (void) gs_free_error GError *error = NULL; gboolean success; GBytes *ssid; - const guint8 *ssid_data; - gsize ssid_len; const char *expected_ssid = "101"; connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error); - g_assert_no_error (error); - g_assert (connection); + nmtst_assert_success (connection, error); success = nm_connection_verify (connection, &error); - g_assert_no_error (error); - g_assert (success); + nmtst_assert_success (success, error); - /* SSID */ s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); ssid = nm_setting_wireless_get_ssid (s_wifi); - g_assert (ssid != NULL); - ssid_data = g_bytes_get_data (ssid, &ssid_len); - g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); + g_assert (ssid); + g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid))); } static void @@ -1049,27 +1042,20 @@ test_read_intlike_ssid_2 (void) gs_free_error GError *error = NULL; gboolean success; GBytes *ssid; - const guint8 *ssid_data; - gsize ssid_len; const char *expected_ssid = "11;12;13;"; connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error); - g_assert_no_error (error); - g_assert (connection); + nmtst_assert_success (connection, error); success = nm_connection_verify (connection, &error); - g_assert_no_error (error); - g_assert (success); + nmtst_assert_success (success, error); - /* SSID */ s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); ssid = nm_setting_wireless_get_ssid (s_wifi); - g_assert (ssid != NULL); - ssid_data = g_bytes_get_data (ssid, &ssid_len); - g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); + g_assert (ssid); + g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid))); } static void @@ -1787,7 +1773,8 @@ test_write_wired_8021x_tls_connection_blob (void) const char *uuid; gboolean reread_same = FALSE; gs_free_error GError *error = NULL; - GBytes *password_raw = NULL; + GBytes *password_raw; + #define PASSWORD_RAW "password-raw\0test" connection = create_wired_tls_connection (NM_SETTING_802_1X_CK_SCHEME_BLOB); @@ -1846,8 +1833,7 @@ test_write_wired_8021x_tls_connection_blob (void) password_raw = nm_setting_802_1x_get_password_raw (s_8021x); g_assert (password_raw); - g_assert (g_bytes_get_size (password_raw) == NM_STRLEN (PASSWORD_RAW)); - g_assert (!memcmp (g_bytes_get_data (password_raw, NULL), PASSWORD_RAW, NM_STRLEN (PASSWORD_RAW))); + g_assert (nm_utils_gbytes_equal_mem (password_raw, PASSWORD_RAW, NM_STRLEN (PASSWORD_RAW))); unlink (testfile); @@ -2186,7 +2172,7 @@ test_write_new_wired_group_name (void) gs_free char *testfile = NULL; gs_free_error GError *error = NULL; char *s; - gint mtu; + int mtu; connection = nm_simple_connection_new (); g_assert (connection); @@ -2234,32 +2220,25 @@ test_read_new_wireless_group_names (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; GBytes *ssid; - const guint8 *ssid_data; - gsize ssid_len; const char *expected_ssid = "foobar"; gs_free_error GError *error = NULL; gboolean success; connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error); - g_assert_no_error (error); - g_assert (connection); + nmtst_assert_success (connection, error); + success = nm_connection_verify (connection, &error); - g_assert_no_error (error); - g_assert (success); + nmtst_assert_success (success, error); - /* Wifi setting */ s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); ssid = nm_setting_wireless_get_ssid (s_wifi); g_assert (ssid); - ssid_data = g_bytes_get_data (ssid, &ssid_len); - g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (ssid_data, expected_ssid, ssid_len), ==, 0); + g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid))); g_assert_cmpstr (nm_setting_wireless_get_mode (s_wifi), ==, NM_SETTING_WIRELESS_MODE_INFRA); - /* Wifi security setting */ s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); g_assert_cmpstr (nm_setting_wireless_security_get_key_mgmt (s_wsec), ==, "wpa-psk"); |