summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-10-15 10:39:02 -0500
committerDan Williams <dcbw@redhat.com>2014-10-15 10:43:02 -0500
commit72208ef6685392b59b9a55b463409f604bb02ad8 (patch)
tree11e06392b705245bd85df0bb67cf3d2c9eae14ae
parentb69143b5085c58e51ab8077ee5cbe6fafe73e041 (diff)
downloadNetworkManager-dcbw/keyfile-enum-flags.tar.gz
keyfile: fix handling of enum/flags properties after fcfb4b40dcbw/keyfile-enum-flags
When some properties got converted to G_TYPE_ENUM and G_TYPE_FLAGS the keyfile plugin was not updated to handle these types.
-rw-r--r--src/settings/plugins/keyfile/reader.c21
-rw-r--r--src/settings/plugins/keyfile/tests/keyfiles/Makefile.am4
-rw-r--r--src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property8
-rw-r--r--src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property11
-rw-r--r--src/settings/plugins/keyfile/tests/test-keyfile.c181
-rw-r--r--src/settings/plugins/keyfile/utils.c1
-rw-r--r--src/settings/plugins/keyfile/utils.h1
-rw-r--r--src/settings/plugins/keyfile/writer.c6
8 files changed, 231 insertions, 2 deletions
diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c
index c925dc5028..ccb4ea4b4d 100644
--- a/src/settings/plugins/keyfile/reader.c
+++ b/src/settings/plugins/keyfile/reader.c
@@ -1214,6 +1214,27 @@ read_one_setting_value (NMSetting *setting,
nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (read): '%s/%s' : '%s'",
setting_name, key, G_VALUE_TYPE_NAME (value));
}
+ } else if (G_VALUE_HOLDS_FLAGS (value)) {
+ guint64 uint_val;
+
+ uint_val = nm_keyfile_plugin_kf_get_uint64 (info->keyfile, setting_name, key, &err);
+ if (!err) {
+ /* Flags are 32-bit but GKeyFile only has uint64 functions */
+ if (uint_val <= G_MAXUINT32)
+ g_object_set (setting, key, uint_val, NULL);
+ else {
+ nm_log_warn (LOGD_SETTINGS, "Too large FLAGS property (read): '%s/%s' : '%s'",
+ setting_name, key, G_VALUE_TYPE_NAME (value));
+ }
+ }
+ g_clear_error (&err);
+ } else if (G_VALUE_HOLDS_ENUM (value)) {
+ int int_val;
+
+ int_val = nm_keyfile_plugin_kf_get_integer (info->keyfile, setting_name, key, &err);
+ if (!err)
+ g_object_set (setting, key, int_val, NULL);
+ g_clear_error (&err);
} else {
nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (read): '%s/%s' : '%s'",
setting_name, key, G_VALUE_TYPE_NAME (value));
diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am
index c6ed0dbb15..4ca4c3faa5 100644
--- a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am
+++ b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am
@@ -28,7 +28,9 @@ KEYFILES = \
Test_minimal_slave_3 \
Test_minimal_slave_4 \
Test_Missing_Vlan_Setting \
- Test_Missing_ID_UUID
+ Test_Missing_ID_UUID \
+ Test_Enum_Property \
+ Test_Flags_Property
CERTS = \
test-ca-cert.pem \
diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property b/src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property
new file mode 100644
index 0000000000..52b395b3ab
--- /dev/null
+++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property
@@ -0,0 +1,8 @@
+[connection]
+id=Test Wired Connection IP6
+uuid=4e80a56d-c99f-4aad-a6dd-b449bc398c57
+type=802-3-ethernet
+
+[ipv6]
+method=auto
+ip6-privacy=2
diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property b/src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property
new file mode 100644
index 0000000000..3a46611d4d
--- /dev/null
+++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property
@@ -0,0 +1,11 @@
+[connection]
+id=Test Flags Property
+uuid=05a5ec81-fa72-4b7c-9f85-4a0dfd36c84f
+type=gsm
+
+[gsm]
+number=*99#
+username=username
+password-flags=5
+apn=my.apn
+
diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c
index ab705503bb..ceb48fc42e 100644
--- a/src/settings/plugins/keyfile/tests/test-keyfile.c
+++ b/src/settings/plugins/keyfile/tests/test-keyfile.c
@@ -3458,6 +3458,182 @@ test_read_minimal_slave ()
g_clear_object (&connection);
}
+static void
+test_read_enum_property (void)
+{
+ NMConnection *connection;
+ NMSettingIP6Config *s_ip6;
+ GError *error = NULL;
+ gboolean success;
+
+ connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error);
+ g_assert_no_error (error);
+ g_assert (connection);
+ success = nm_connection_verify (connection, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ /* IPv6 setting */
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ g_assert (s_ip6);
+ g_assert_cmpint (nm_setting_ip6_config_get_ip6_privacy (s_ip6), ==, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR);
+
+ g_object_unref (connection);
+}
+
+static void
+test_write_enum_property (void)
+{
+ NMConnection *connection;
+ NMSettingConnection *s_con;
+ NMSettingWired *s_wired;
+ NMSettingIP6Config *s_ip6;
+ char *uuid;
+ gboolean success;
+ NMConnection *reread;
+ char *testfile = NULL;
+ GError *error = NULL;
+ pid_t owner_grp;
+ uid_t owner_uid;
+
+ connection = nm_simple_connection_new ();
+
+ /* Connection setting */
+
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_ID, "Test Write Enum Property",
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
+ NULL);
+ g_free (uuid);
+
+ /* Wired setting */
+ s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_wired));
+
+ /* IP6 setting */
+ s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_ip6));
+ g_object_set (s_ip6,
+ NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP6_CONFIG_IP6_PRIVACY, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR,
+ NULL);
+
+ nmtst_connection_normalize (connection);
+
+ /* Write out the connection */
+ owner_uid = geteuid ();
+ owner_grp = getegid ();
+ success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (testfile);
+
+ /* Read the connection back in and compare it to the one we just wrote out */
+ reread = nm_keyfile_plugin_connection_from_file (testfile, &error);
+ g_assert_no_error (error);
+ g_assert (reread);
+
+ nmtst_assert_connection_equals (reread, FALSE, connection, FALSE);
+
+ unlink (testfile);
+ g_free (testfile);
+
+ g_object_unref (reread);
+ g_object_unref (connection);
+}
+
+static void
+test_read_flags_property (void)
+{
+ NMConnection *connection;
+ NMSettingGsm *s_gsm;
+ GError *error = NULL;
+ gboolean success;
+
+ connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error);
+ g_assert_no_error (error);
+ g_assert (connection);
+ success = nm_connection_verify (connection, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ /* GSM setting */
+ s_gsm = nm_connection_get_setting_gsm (connection);
+ g_assert (s_gsm);
+ g_assert_cmpint (nm_setting_gsm_get_password_flags (s_gsm), ==,
+ NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
+
+ g_object_unref (connection);
+}
+
+static void
+test_write_flags_property (void)
+{
+ NMConnection *connection;
+ NMSettingConnection *s_con;
+ NMSetting *s_gsm;
+ char *uuid;
+ gboolean success;
+ NMConnection *reread;
+ char *testfile = NULL;
+ GError *error = NULL;
+ pid_t owner_grp;
+ uid_t owner_uid;
+
+ connection = nm_simple_connection_new ();
+
+ /* Connection setting */
+
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_ID, "Test Write Flags Property",
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME,
+ NULL);
+ g_free (uuid);
+
+ /* GSM setting */
+ s_gsm = nm_setting_gsm_new ();
+ nm_connection_add_setting (connection, s_gsm);
+ g_object_set (s_gsm,
+ NM_SETTING_GSM_NUMBER, "#99*",
+ NM_SETTING_GSM_APN, "myapn",
+ NM_SETTING_GSM_USERNAME, "adfasdfasdf",
+ NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED,
+ NULL);
+
+ nmtst_connection_normalize (connection);
+
+ /* Write out the connection */
+ owner_uid = geteuid ();
+ owner_grp = getegid ();
+ success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (testfile);
+
+ /* Read the connection back in and compare it to the one we just wrote out */
+ reread = nm_keyfile_plugin_connection_from_file (testfile, &error);
+ g_assert_no_error (error);
+ g_assert (reread);
+
+ nmtst_assert_connection_equals (reread, FALSE, connection, FALSE);
+
+ unlink (testfile);
+ g_free (testfile);
+
+ g_object_unref (reread);
+ g_object_unref (connection);
+}
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -3523,6 +3699,11 @@ int main (int argc, char **argv)
g_test_add_func ("/keyfile/test_read_minimal", test_read_minimal);
g_test_add_func ("/keyfile/test_read_minimal_slave", test_read_minimal_slave);
+ g_test_add_func ("/keyfile/test_read_enum_property ", test_read_enum_property);
+ g_test_add_func ("/keyfile/test_write_enum_property ", test_write_enum_property);
+ g_test_add_func ("/keyfile/test_read_flags_property ", test_read_flags_property);
+ g_test_add_func ("/keyfile/test_write_flags_property ", test_write_flags_property);
+
return g_test_run ();
}
diff --git a/src/settings/plugins/keyfile/utils.c b/src/settings/plugins/keyfile/utils.c
index e2bfc38c15..844d9c08c9 100644
--- a/src/settings/plugins/keyfile/utils.c
+++ b/src/settings/plugins/keyfile/utils.c
@@ -229,6 +229,7 @@ nm_keyfile_plugin_kf_set_##stype (GKeyFile *kf, \
DEFINE_KF_WRAPPER(string, gchar*, const gchar*);
DEFINE_KF_WRAPPER(integer, gint, gint);
+DEFINE_KF_WRAPPER(uint64, guint64, guint64);
DEFINE_KF_WRAPPER(boolean, gboolean, gboolean);
DEFINE_KF_WRAPPER(value, gchar*, const gchar*);
diff --git a/src/settings/plugins/keyfile/utils.h b/src/settings/plugins/keyfile/utils.h
index 9a2e485bc6..1a7c2502b0 100644
--- a/src/settings/plugins/keyfile/utils.h
+++ b/src/settings/plugins/keyfile/utils.h
@@ -61,6 +61,7 @@ void nm_keyfile_plugin_kf_set_##stype (GKeyFile *kf, \
set_ctype value);
DEFINE_KF_WRAPPER_PROTO(string, gchar*, const gchar*)
DEFINE_KF_WRAPPER_PROTO(integer, gint, gint)
+DEFINE_KF_WRAPPER_PROTO(uint64, guint64, guint64)
DEFINE_KF_WRAPPER_PROTO(boolean, gboolean, gboolean)
DEFINE_KF_WRAPPER_PROTO(value, gchar*, const gchar*)
diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c
index 2661d50066..bc5fb5cf50 100644
--- a/src/settings/plugins/keyfile/writer.c
+++ b/src/settings/plugins/keyfile/writer.c
@@ -863,7 +863,11 @@ write_setting_value (NMSetting *setting,
nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (write) '%s/%s' : '%s'",
setting_name, key, g_type_name (type));
}
- } else {
+ } else if (G_VALUE_HOLDS_FLAGS (value))
+ nm_keyfile_plugin_kf_set_uint64 (info->keyfile, setting_name, key, (guint64) g_value_get_flags (value));
+ else if (G_VALUE_HOLDS_ENUM (value))
+ nm_keyfile_plugin_kf_set_integer (info->keyfile, setting_name, key, g_value_get_enum (value));
+ else {
nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (write) '%s/%s' : '%s'",
setting_name, key, g_type_name (type));
}