From 30c66b6f79266b24b029ad01523e5a666ab3578b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Nov 2016 18:27:37 +0100 Subject: [PATCH 01/39] libnm: disable assertions in crypto_md5_hash() in non-debug builds --- libnm-core/crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnm-core/crypto.c b/libnm-core/crypto.c index e734f40d8..4663457cb 100644 --- a/libnm-core/crypto.c +++ b/libnm-core/crypto.c @@ -777,7 +777,7 @@ crypto_md5_hash (const char *salt, char digest[16]; char *p = buffer; - g_assert_cmpint (g_checksum_type_get_length (G_CHECKSUM_MD5), ==, sizeof (digest)); + nm_assert (g_checksum_type_get_length (G_CHECKSUM_MD5) == sizeof (digest)); g_return_if_fail (password_len == 0 || password); g_return_if_fail (buffer != NULL); @@ -804,7 +804,7 @@ crypto_md5_hash (const char *salt, digest_len = sizeof (digest); g_checksum_get_digest (ctx, (guchar *) digest, &digest_len); - g_assert (digest_len == sizeof (digest)); + nm_assert (digest_len == sizeof (digest)); while (nkey && (i < sizeof (digest))) { *(p++) = digest[i++]; From fedee13c372dfb94775345d78f137487612bbeb7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Nov 2016 12:03:34 +0100 Subject: [PATCH 02/39] libnm: refactor loop in crypto_md5_hash() Break the loop in the middle and avoid g_checksum_reset() call. In many cases, we only want one MD5 sum, not a longer digest. --- libnm-core/crypto.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libnm-core/crypto.c b/libnm-core/crypto.c index 4663457cb..c4e48475f 100644 --- a/libnm-core/crypto.c +++ b/libnm-core/crypto.c @@ -771,11 +771,10 @@ crypto_md5_hash (const char *salt, gsize buflen) { GChecksum *ctx; - int nkey = buflen; gsize digest_len; - int count = 0; char digest[16]; - char *p = buffer; + gsize bufidx = 0; + int i; nm_assert (g_checksum_type_get_length (G_CHECKSUM_MD5) == sizeof (digest)); @@ -791,12 +790,7 @@ crypto_md5_hash (const char *salt, if (password_len < 0) password_len = strlen (password); - while (nkey > 0) { - int i = 0; - - g_checksum_reset (ctx); - if (count++) - g_checksum_update (ctx, (const guchar *) digest, sizeof (digest)); + for (;;) { if (password_len > 0) g_checksum_update (ctx, (const guchar *) password, password_len); if (salt_len > 0) @@ -806,12 +800,17 @@ crypto_md5_hash (const char *salt, g_checksum_get_digest (ctx, (guchar *) digest, &digest_len); nm_assert (digest_len == sizeof (digest)); - while (nkey && (i < sizeof (digest))) { - *(p++) = digest[i++]; - nkey--; + for (i = 0; i < sizeof (digest); i++) { + if (bufidx >= buflen) + goto done; + buffer[bufidx++] = digest[i]; } + + g_checksum_reset (ctx); + g_checksum_update (ctx, (const guchar *) digest, sizeof (digest)); } +done: memset (digest, 0, sizeof (digest)); g_checksum_free (ctx); } From 37bf6432134ca8ea3a2b6a15d035ff4721feb887 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Nov 2016 08:19:58 +0100 Subject: [PATCH 03/39] libnm: don't initialize buffer for uuid_unparse_lower() with zeros --- libnm-core/nm-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 4be430af6..cfd97149c 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2212,7 +2212,7 @@ nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_type, g g_return_val_if_reached (NULL); } - buf = g_malloc0 (37); + buf = g_malloc (37); uuid_unparse_lower (uuid, &buf[0]); return buf; From e36f6a7e52737aedafed6ba55b0cc224eca7ac52 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Nov 2016 17:39:26 +0100 Subject: [PATCH 04/39] libnm: add nm_utils_uuid_generate_buf() util --- libnm-core/nm-core-internal.h | 8 ++++++++ libnm-core/nm-utils.c | 24 +++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 8fba35716..1b4c46942 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -194,6 +194,14 @@ char *nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_t char *_nm_utils_uuid_generate_from_strings (const char *string1, ...) G_GNUC_NULL_TERMINATED; +char *nm_utils_uuid_generate_buf_ (char *buf); +#define nm_utils_uuid_generate_buf(buf) \ + ({ \ + G_STATIC_ASSERT (sizeof (buf) == G_N_ELEMENTS (buf) && sizeof (buf) >= 37); \ + nm_utils_uuid_generate_buf_ (buf); \ + }) +#define nm_utils_uuid_generate_a() (nm_utils_uuid_generate_buf_ (g_alloca (37))) + void _nm_dbus_errors_init (void); extern gboolean _nm_utils_is_manager_process; diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index cfd97149c..41b6304c8 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2146,6 +2146,22 @@ next: /*****************************************************************************/ +/** + * nm_utils_uuid_generate_buf_: + * @buf: input buffer, must contain at least 37 bytes + * + * Returns: generates a new random UUID, writes it to @buf and returns @buf. + **/ +char * +nm_utils_uuid_generate_buf_ (char *buf) +{ + uuid_t uuid; + + uuid_generate_random (uuid); + uuid_unparse_lower (uuid, buf); + return buf; +} + /** * nm_utils_uuid_generate: * @@ -2155,13 +2171,7 @@ next: char * nm_utils_uuid_generate (void) { - uuid_t uuid; - char *buf; - - buf = g_malloc0 (37); - uuid_generate_random (uuid); - uuid_unparse_lower (uuid, &buf[0]); - return buf; + return nm_utils_uuid_generate_buf_ (g_malloc (37)); } /** From 858daf57bc2d5d572bd661d81650c40198a42428 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Oct 2016 18:16:02 +0200 Subject: [PATCH 05/39] shared: add NM_STRCHAR_ALL() and NM_STRCHAR_ANY() macros --- shared/nm-utils/nm-macros-internal.h | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 658b3b92a..fdb45f929 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -258,6 +258,52 @@ _NM_IN_STRSET_streq (const char *x, const char *s) * side-effects. */ #define NM_IN_STRSET_SE(x, ...) _NM_IN_STRSET_EVAL_N(|, x, NM_NARG (__VA_ARGS__), __VA_ARGS__) +#define NM_STRCHAR_ALL(str, ch_iter, predicate) \ + ({ \ + gboolean _val = TRUE; \ + const char *_str = (str); \ + \ + if (_str) { \ + for (;;) { \ + const char ch_iter = _str[0]; \ + \ + if (ch_iter != '\0') { \ + if (predicate) {\ + _str++; \ + continue; \ + } \ + _val = FALSE; \ + } \ + break; \ + } \ + } \ + _val; \ + }) + +#define NM_STRCHAR_ANY(str, ch_iter, predicate) \ + ({ \ + gboolean _val = FALSE; \ + const char *_str = (str); \ + \ + if (_str) { \ + for (;;) { \ + const char ch_iter = _str[0]; \ + \ + if (ch_iter != '\0') { \ + if (predicate) { \ + ; \ + } else { \ + _str++; \ + continue; \ + } \ + _val = TRUE; \ + } \ + break; \ + } \ + } \ + _val; \ + }) + /*****************************************************************************/ #define nm_streq(s1, s2) (strcmp (s1, s2) == 0) From b204801b7e966656979f039111113d2c67352477 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 10:41:04 +0100 Subject: [PATCH 06/39] shared: add nmtst_file_get_contents() --- shared/nm-utils/nm-test-utils.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 75d01bb63..556768ef2 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1144,6 +1144,20 @@ nmtst_file_resolve_relative_path (const char *rel, const char *cwd) return g_build_filename (cwd, rel, NULL); } +inline static char * +nmtst_file_get_contents (const char *filename) +{ + GError *error = NULL; + gboolean success; + char *contents = NULL; + gsize len; + + success = g_file_get_contents (filename, &contents, &len, &error); + nmtst_assert_success (success && contents, error); + g_assert_cmpint (strlen (contents), ==, len); + return contents; +} + inline static void _nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, const char *file, int line) { From f5e6f1d65bb3178852c1a8644b0771d7f4291bbd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Nov 2016 12:19:52 +0100 Subject: [PATCH 07/39] shared: add nmtst_auto_unlinkfile cleanup macro --- shared/nm-utils/nm-test-utils.h | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 556768ef2..7e712dcd7 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1158,6 +1158,48 @@ nmtst_file_get_contents (const char *filename) return contents; } +/*****************************************************************************/ + +inline static void +nmtst_file_unlink_if_exists (const char *name) +{ + int errsv; + + g_assert (name && name[0]); + + if (unlink (name) != 0) { + errsv = errno; + if (errsv != ENOENT) + g_error ("nmtst_file_unlink_if_exists(%s): failed with %s", name, strerror (errsv)); + } +} + +inline static void +nmtst_file_unlink (const char *name) +{ + int errsv; + + g_assert (name && name[0]); + + if (unlink (name) != 0) { + errsv = errno; + g_error ("nmtst_file_unlink(%s): failed with %s", name, strerror (errsv)); + } +} + +inline static void +_nmtst_auto_unlinkfile (char **p_name) +{ + if (*p_name) { + nmtst_file_unlink (*p_name); + nm_clear_g_free (p_name); + } +} + +#define nmtst_auto_unlinkfile nm_auto(_nmtst_auto_unlinkfile) + +/*****************************************************************************/ + inline static void _nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, const char *file, int line) { From f950f7922e15b3eeb8f9e908bd43f204d09ad62c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Nov 2016 12:44:56 +0100 Subject: [PATCH 08/39] ifcfg-rh/tests: use cleanup macros in ifcfg-rh test --- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 66 ++++++------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index df332b240..d5e47e8e3 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -1495,9 +1495,10 @@ test_read_wired_8021x_tls_secret_flags (gconstpointer test_data) static void test_read_write_802_1X_subj_matches (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *written = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSetting8021x *s_8021x; - char *written = NULL; g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*missing IEEE_8021X_CA_CERT*peap*"); @@ -1529,8 +1530,6 @@ test_read_write_802_1X_subj_matches (void) "*missing IEEE_8021X_CA_CERT*peap*"); reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); - unlink (written); - g_free (written); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -1549,9 +1548,6 @@ test_read_write_802_1X_subj_matches (void) g_assert_cmpint (nm_setting_802_1x_get_num_phase2_altsubject_matches (s_8021x), ==, 2); g_assert_cmpstr (nm_setting_802_1x_get_phase2_altsubject_match (s_8021x, 0), ==, "x.yourdomain.tld"); g_assert_cmpstr (nm_setting_802_1x_get_phase2_altsubject_match (s_8021x, 1), ==, "y.yourdomain.tld"); - - g_object_unref (connection); - g_object_unref (reread); } static void @@ -1743,10 +1739,11 @@ test_read_dns_options (void) static void test_clear_master (void) { + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; - NMConnection *connection; char *unmanaged = NULL; - char *testfile = NULL, *keyfile; GError *error = NULL; gboolean success; shvarFile *f; @@ -1778,16 +1775,14 @@ test_clear_master (void) g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NULL); /* 4. update the connection on disk */ - keyfile = utils_get_keys_path (testfile); success = writer_update_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", testfile, - keyfile, + NULL, &error); - g_assert_no_error (error); - g_assert (success); - unlink (keyfile); - g_free (keyfile); + nmtst_assert_success (success, error); + keyfile = utils_get_keys_path (testfile); + g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); /* 5. check that BRIDGE variable has been removed */ f = svOpenFile (testfile, &error); @@ -1797,17 +1792,14 @@ test_clear_master (void) val = svGetValue (f, "BRIDGE", FALSE); g_assert (!val); svCloseFile (f); - - unlink (testfile); - g_free (testfile); - g_object_unref (connection); } static void test_write_dns_options (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; @@ -1818,7 +1810,6 @@ test_write_dns_options (void) NMIPAddress *addr; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -1884,7 +1875,6 @@ test_write_dns_options (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); /* RES_OPTIONS is copied to both IPv4 and IPv6 settings */ nm_setting_ip_config_clear_dns_options (s_ip4, TRUE); @@ -1896,10 +1886,6 @@ test_write_dns_options (void) nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3"); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -4167,8 +4153,10 @@ test_write_wired_static_routes (void) static void test_write_wired_dhcp_8021x_peap_mschapv2 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; @@ -4177,8 +4165,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; connection = nm_simple_connection_new (); @@ -4243,17 +4229,10 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8607,11 +8586,13 @@ test_read_team_port (gconstpointer user_data) static void test_write_team_port (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingTeamPort *s_team_port; NMSettingWired *s_wired; - char *uuid, *testfile = NULL, *val; + char *uuid, *val; GError *error = NULL; const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; const char *escaped_expected_config = "\"{ \\\"p4p1\\\": { \\\"prio\\\": -10, \\\"sticky\\\": true } }\""; @@ -8671,13 +8652,8 @@ test_write_team_port (void) reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void From 8f9432327c2717a260286075c568ebf95d98d512 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Oct 2016 19:05:01 +0200 Subject: [PATCH 09/39] ifcfg-rh/trivial: coding style/white-space --- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 0d59063b0..870526c37 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -208,7 +208,7 @@ make_connection_setting (const char *file, } - zone = svGetValue(ifcfg, "ZONE", FALSE); + zone = svGetValue (ifcfg, "ZONE", FALSE); if (!zone || !strlen (zone)) { g_free (zone); zone = NULL; From 22ef66e6bb95d16a6febdeae8ea908d5b3c3e63f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Oct 2016 19:12:30 +0200 Subject: [PATCH 10/39] ifcfg-rh: unescape ifcfg value for CIPHER_GROUP/CIPHER_PAIRWISE It's not clear why we would read the CIPHER_GROUP/CIPHER_PAIRWISE verbatim=TRUE (without shell unescaping). Especially since ifcfg-rh writer does svSetValue (ifcfg, "CIPHER_PAIRWISE", str->str, FALSE); --- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 870526c37..2c7128388 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -2358,16 +2358,10 @@ fill_wpa_ciphers (shvarFile *ifcfg, char **list = NULL, **iter; int i = 0; - p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", TRUE); + p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", FALSE); if (!value) return TRUE; - /* Strip quotes */ - if (p[0] == '"') - p++; - if (p[strlen (p) - 1] == '"') - p[strlen (p) - 1] = '\0'; - list = g_strsplit_set (p, " ", 0); for (iter = list; iter && *iter; iter++, i++) { /* Ad-Hoc configurations cannot have pairwise ciphers, and can only From 912a866353426adc124e5138467f2a6a404e77c7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Oct 2016 19:28:31 +0200 Subject: [PATCH 11/39] ifcfg-rh: read team key non-verbatim from ifcfg-rh svUnescape() has no problem with extremely long strings. It does not allocate any memory and has O(n) complexity. No problem. If somebody has a problem with extremely large files it's shvarFile itself which caches the entire file in memory. Also, libnm-core allows team configs to be 1 MB in size. So, allow that here too. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 2c7128388..5ad1f43ad 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -4291,33 +4291,26 @@ static char * read_team_config (shvarFile *ifcfg, const char *key, GError **error) { gs_free_error GError *local_error = NULL; - char *value; + gs_free char *value = NULL; size_t l; - /* FIXME: validate the JSON at some point */ - value = svGetValue (ifcfg, key, TRUE); + value = svGetValue (ifcfg, key, FALSE); if (!value) return NULL; - /* No reason Team config should be over 20k. The config is read - * verbatim, length-checked, then unescaped. svUnescape() does not - * deal well with extremely long strings. - */ l = strlen (value); - if (l > 20000) { + if (l > 1*1024*1024) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "%s too long (size %zd)", key, l); - g_free (value); return NULL; } - svUnescape (value); - if (value && value[0] && !nm_utils_is_json_object (value, &local_error)) { + if (!nm_utils_is_json_object (value, &local_error)) { PARSE_WARNING ("ignoring invalid team configuration: %s", local_error->message); - g_clear_pointer (&value, g_free); + return NULL; } - return value; + return g_steal_pointer (&value); } static NMSetting * From 5a43b733b9897e1ba7563e3555edfdd2b168183a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Oct 2016 18:19:20 +0200 Subject: [PATCH 12/39] ifcfg-rh: change ESSID handling Let shvar.h do the escaping/unescaping of the ESSID. We should not treat a value differently whether it is quoted or not. Also, cutting away double quotes and calling svUnescape() is just wrong. Now, we write a value in hex if it contains non-printable characters or if the reader would treat it like a hex value. Reader treats ESSID now as hex if it starts with "0x" followed by pairs of hex digits. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 40 ++++------------- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 45 ++++++++++--------- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 27 ++++++++++- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 5ad1f43ad..dbfdf7447 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -3437,39 +3437,19 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "ESSID", TRUE); + value = svGetValue (ifcfg, "ESSID", FALSE); if (value) { - GBytes *bytes = NULL; + gs_unref_bytes GBytes *bytes = NULL; gsize ssid_len = 0; gsize value_len = strlen (value); - if ( (value_len >= 2) - && (value[0] == '"') - && (value[value_len - 1] == '"')) { - /* Strip the quotes and unescape */ - char *p = value + 1; - - value[value_len - 1] = '\0'; - svUnescape (p); - bytes = g_bytes_new (p, strlen (p)); - } else if ((value_len > 2) && (strncmp (value, "0x", 2) == 0)) { - /* Hex representation */ - if (value_len % 2) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid SSID '%s' size (looks like hex but length not multiple of 2)", - value); - g_free (value); - goto error; - } - - bytes = nm_utils_hexstr2bin (value); - if (!bytes) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid SSID '%s' (looks like hex SSID but isn't)", - value); - g_free (value); - goto error; - } + if ( value_len > 2 + && (value_len % 2) == 0 + && g_str_has_prefix (value, "0x") + && NM_STRCHAR_ALL (&value[2], ch, g_ascii_isxdigit (ch))) { + /* interpret the value as hex-digits iff value starts + * with "0x" followed by pairs of hex digits */ + bytes = nm_utils_hexstr2bin (&value[2]); } else bytes = g_bytes_new (value, value_len); @@ -3478,13 +3458,11 @@ make_wireless_setting (shvarFile *ifcfg, g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)", value, ssid_len); - g_bytes_unref (bytes); g_free (value); goto error; } g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, bytes, NULL); - g_bytes_unref (bytes); g_free (value); } diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 0b6ed52cd..ffdce42dd 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -774,13 +774,12 @@ write_wireless_setting (NMConnection *connection, GError **error) { NMSettingWireless *s_wireless; - char *tmp, *tmp2; + char *tmp; GBytes *ssid; const guint8 *ssid_data; gsize ssid_len; const char *mode, *bssid; const char *device_mac, *cloned_mac; - char buf[33]; guint32 mtu, chan, i; gboolean adhoc = FALSE, hex_ssid = FALSE; const char * const *macaddr_blacklist; @@ -836,10 +835,23 @@ write_wireless_setting (NMConnection *connection, /* If the SSID contains any non-printable characters, we need to use the * hex notation of the SSID instead. */ - for (i = 0; i < ssid_len; i++) { - if (!g_ascii_isprint (ssid_data[i])) { - hex_ssid = TRUE; - break; + if ( ssid_len > 2 + && ssid_data[0] == '0' + && ssid_data[1] == 'x') { + hex_ssid = TRUE; + for (i = 2; i < ssid_len; i++) { + if (!g_ascii_isxdigit (ssid_data[i])) { + hex_ssid = FALSE; + break; + } + } + } + if (!hex_ssid) { + for (i = 0; i < ssid_len; i++) { + if (!g_ascii_isprint (ssid_data[i])) { + hex_ssid = TRUE; + break; + } } } @@ -851,26 +863,15 @@ write_wireless_setting (NMConnection *connection, g_string_append (str, "0x"); for (i = 0; i < ssid_len; i++) g_string_append_printf (str, "%02X", ssid_data[i]); - svSetValue (ifcfg, "ESSID", str->str, TRUE); + svSetValue (ifcfg, "ESSID", str->str, FALSE); g_string_free (str, TRUE); } else { - const char *tmp_escaped; + char buf[33]; - /* Printable SSIDs always get quoted */ - memset (buf, 0, sizeof (buf)); + nm_assert (ssid_len <= 32); memcpy (buf, ssid_data, ssid_len); - tmp_escaped = svEscape (buf, &tmp); - - /* svEscape will usually quote the string, but just for consistency, - * if svEscape doesn't quote the ESSID, we quote it ourselves. - */ - if (tmp_escaped[0] != '"' && tmp_escaped[strlen (tmp_escaped) - 1] != '"') { - tmp2 = g_strdup_printf ("\"%s\"", tmp_escaped); - svSetValue (ifcfg, "ESSID", tmp2, TRUE); - g_free (tmp2); - } else - svSetValue (ifcfg, "ESSID", tmp_escaped, TRUE); - g_free (tmp); + buf[ssid_len] = '\0'; + svSetValue (ifcfg, "ESSID", buf, FALSE); } mode = nm_setting_wireless_get_mode (s_wireless); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index d5e47e8e3..cd0a698ec 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -2010,6 +2010,30 @@ test_read_wifi_open_ssid_hex (void) g_object_unref (connection); } +static void +test_read_wifi_open_ssid_hex_bad (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + GBytes *ssid; + const char *expected_ssid = "0x626cxx"; + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex", + NULL, TYPE_WIRELESS, NULL); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System 0x626cxx (test-wifi-open-ssid-bad-hex)"); + + s_wireless = nm_connection_get_setting_wireless (connection); + g_assert (s_wireless); + + ssid = nm_setting_wireless_get_ssid (s_wireless); + g_assert (ssid); + g_assert_cmpmem (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), expected_ssid, strlen (expected_ssid)); +} + static void test_read_wifi_open_ssid_bad (gconstpointer data) { @@ -8946,7 +8970,6 @@ test_utils_ignore (void) #define TPATH "/settings/plugins/ifcfg-rh/" -#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex" #define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted" #define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-hex" @@ -9023,7 +9046,7 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wifi/read/open", test_read_wifi_open); g_test_add_func (TPATH "wifi/read/open/auto", test_read_wifi_open_auto); g_test_add_func (TPATH "wifi/read/open/hex-ssid", test_read_wifi_open_ssid_hex); - g_test_add_data_func (TPATH "wifi/read/open-ssid/bad-hex", TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX, test_read_wifi_open_ssid_bad); + g_test_add_func (TPATH "wifi/read/open-ssid/bad-hex", test_read_wifi_open_ssid_hex_bad); g_test_add_data_func (TPATH "wifi/read/open-ssid/long-hex", TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX, test_read_wifi_open_ssid_bad); g_test_add_data_func (TPATH "wifi/read/open-ssid/long-quoted", TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED, test_read_wifi_open_ssid_bad); g_test_add_func (TPATH "wifi/read/open/quoted-ssid", test_read_wifi_open_ssid_quoted); From 39a79b0ee72ce8e66e87829ec7e3b67f3bbcef27 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Oct 2016 21:26:24 +0200 Subject: [PATCH 13/39] ifcfg-rh: handle quotes of WPA_PSK key inside shvar.h It is wrong to move the handling of quotes outside of shvar.h. The ifcfg-rh core library (shvar.h) should handle quotation transparently. It is also wrong to encode meaning of the WPA_PSK depending on whether the value is quoted or not. A psk that is 64 chars *must* be in hex representation, and anything else is taken literal. Also, the special handling of bash-syntax with $' was wrong. Including the unit test "keys-test-wifi-wpa-psk-2" which contained invalid shell. Support for $' must be done inside of shvar.h, for all properties alike not just for WPA_PSK. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 53 +++++-------------- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 34 ++++-------- .../network-scripts/keys-test-wifi-wpa-psk-2 | 2 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 10 ++-- 4 files changed, 27 insertions(+), 72 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index dbfdf7447..6af19072f 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -2416,9 +2416,8 @@ parse_wpa_psk (shvarFile *ifcfg, GError **error) { shvarFile *keys_ifcfg; - char *psk = NULL, *p, *hashed = NULL; + gs_free char *psk = NULL; size_t plen; - gboolean quoted = FALSE; /* Passphrase must be between 10 and 66 characters in length because WPA * hex keys are exactly 64 characters (no quoting), and WPA passphrases @@ -2429,64 +2428,36 @@ parse_wpa_psk (shvarFile *ifcfg, /* Try to get keys from the "shadow" key file */ keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); if (keys_ifcfg) { - psk = svGetValue (keys_ifcfg, "WPA_PSK", TRUE); + psk = svGetValue (keys_ifcfg, "WPA_PSK", FALSE); svCloseFile (keys_ifcfg); } /* Fall back to the original ifcfg */ if (!psk) - psk = svGetValue (ifcfg, "WPA_PSK", TRUE); + psk = svGetValue (ifcfg, "WPA_PSK", FALSE); if (!psk) return NULL; - p = psk; - plen = strlen (p); + plen = strlen (psk); - if ( (plen >= 2 && (p[0] == '"' || p[0] == '\'') && p[0] == p[plen - 1]) - || (plen >= 3 && p[0] == '$' && p[1] == '\'' && p[1] == p[plen - 1])) - quoted = TRUE; - - if (!quoted && (strlen (psk) == 64)) { + if (plen == 64) { /* Verify the hex PSK; 64 digits */ - while (*p) { - if (!g_ascii_isxdigit (*p++)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WPA_PSK (contains non-hexadecimal characters)"); - goto out; - } + if (!NM_STRCHAR_ALL (psk, ch, g_ascii_isxdigit (ch))) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WPA_PSK (contains non-hexadecimal characters)"); + return NULL; } - hashed = g_strdup (psk); } else { - /* Prior to 4f6eef9e77265484555663cf666cde4fa8323469 and - * 28e2e446868b94b92edc4a82aa0bf1e3eda8ec54 the writer may not have - * properly quoted passphrases, so just handle anything that's unquoted - * and between 8 and 63 characters as a passphrase. - */ - - /* Get rid of the quotes */ - hashed = utils_single_unquote_string (p); - - /* Length check */ - if (strlen (hashed) < 8 || strlen (hashed) > 63) { + if (plen < 8 || plen > 63) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WPA_PSK (passphrases must be between " "8 and 63 characters long (inclusive))"); - g_free (hashed); - hashed = NULL; - goto out; + return NULL; } } - if (!hashed) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WPA_PSK (doesn't look like a passphrase or hex key)"); - goto out; - } - -out: - g_free (psk); - return hashed; + return g_steal_pointer (&psk); } static gboolean diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index ffdce42dd..fd03d5695 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -562,7 +562,8 @@ write_wireless_security_setting (NMConnection *connection, GError **error) { NMSettingWirelessSecurity *s_wsec; - const char *key_mgmt, *auth_alg, *key, *proto, *cipher, *psk; + const char *key_mgmt, *auth_alg, *key, *proto, *cipher; + const char *psk = NULL; gboolean wep = FALSE, wpa = FALSE, dynamic_wep = FALSE; char *tmp; guint32 i, num; @@ -739,30 +740,15 @@ write_wireless_security_setting (NMConnection *connection, svSetValue (ifcfg, "CIPHER_GROUP", str->str, FALSE); g_string_free (str, TRUE); - /* WPA Passphrase */ - if (wpa) { - char *quoted = NULL; - + if (wpa) psk = nm_setting_wireless_security_get_psk (s_wsec); - if (psk && (strlen (psk) != 64)) { - /* Quote the PSK since it's a passphrase */ - quoted = utils_single_quote_string (psk); - } - set_secret (ifcfg, - "WPA_PSK", - quoted ? quoted : psk, - "WPA_PSK_FLAGS", - nm_setting_wireless_security_get_psk_flags (s_wsec), - TRUE); - g_free (quoted); - } else { - set_secret (ifcfg, - "WPA_PSK", - NULL, - "WPA_PSK_FLAGS", - NM_SETTING_SECRET_FLAG_NONE, - FALSE); - } + + set_secret (ifcfg, + "WPA_PSK", + psk, + "WPA_PSK_FLAGS", + wpa ? nm_setting_wireless_security_get_psk_flags (s_wsec) : NM_SETTING_SECRET_FLAG_NONE, + FALSE); return TRUE; } diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 index 6a63e817f..995721ddb 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 @@ -1,2 +1,2 @@ -WPA_PSK=$'They\'re really saying I love you. >>`<< \' +WPA_PSK="They're really saying I love you. >>\`<< '" diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index cd0a698ec..ee27f194e 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -2547,7 +2547,7 @@ test_read_wifi_wpa_psk_2 (void) s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); - g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "They're really saying I love you. >>`<< \\"); + g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "They're really saying I love you. >>`<< '"); g_object_unref (connection); } @@ -2586,12 +2586,10 @@ test_read_wifi_wpa_psk_unquoted (void) static void test_read_wifi_wpa_psk_unquoted2 (void) { - /* Ensure a quoted 64-character WPA passphrase will fail since passphrases - * must be between 8 and 63 ASCII characters inclusive per the WPA spec. - */ + gs_unref_object NMConnection *connection = NULL; - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2", - NULL, TYPE_WIRELESS, NULL); + connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2", + NULL, TYPE_WIRELESS, NULL); } static void From 58b69e2f90a8573e19a9ae60b424a93b56d08a83 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 22:47:41 +0100 Subject: [PATCH 14/39] ifcfg-rh/trivial: remove unused functions utils_single_quote_string() and unquote --- .../plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 81 ------------------- .../plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 4 - 2 files changed, 85 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index 9cb44b19c..d1c009764 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -30,87 +30,6 @@ #include "nms-ifcfg-rh-common.h" -/* - * utils_single_quote_string - * - * Put string inside single quotes and remove CR, LF characters. If single quote - * is present, escape it with a backslash and prepend the whole string with $ - * in order to have $'string'. That allows us to use single quote inside - * single quotes without breaking bash syntax. (man bash, section QUOTING). - * - * Caller is responsible for freeing the returned string. - */ -char * -utils_single_quote_string (const char *str) -{ - static const char *drop_chars = "\r\n"; /* drop CR and LF */ - static const char escape_char = '\\'; /* escape char is backslash */ - static const char quote_char = '\''; /* quote char is single quote */ - size_t i, slen, j = 0; - size_t drop = 0, extra = 0; - char *new_str; - - slen = strlen (str); - for (i = 0; i < slen; i++) { - if (str[i] == quote_char) - extra++; - if (strchr (drop_chars, str[i])) - drop++; - } - new_str = g_malloc0 (slen + extra - drop + 4); /* 4 is for $''\0*/ - - if (extra > 0) - new_str[j++] = '$'; - new_str[j++] = quote_char; - for (i = 0; i < slen; i++) { - if (strchr (drop_chars, str[i])) - continue; - if (str[i] == quote_char) - new_str[j++] = escape_char; - new_str[j++] = str[i]; - } - new_str[j] = quote_char; - - return new_str; -} - -/* - * utils_single_unquote_string - * - * Remove string from single (or double) quotes, and remove escaping of '. - * Also remove first $ if the string is in the form of $'string'. - * - * Caller is responsible for freeing the returned string. - */ -char * -utils_single_unquote_string (const char *str) -{ - static const char escape_char = '\\'; /* escape char is backslash */ - static const char q_char = '\''; /* quote char is single quote */ - static const char dq_char = '"'; /* double quote char */ - size_t i, slen, j = 0, quote = 0, dollar = 0; - char *new_str; - - slen = strlen (str); - new_str = g_malloc0 (slen + 1); - - if ( (slen >= 2 && (str[0] == dq_char || str[0] == q_char) && str[0] == str[slen-1]) - || (slen >= 3 && str[0] == '$' && str[1] == q_char && str[1] == str[slen-1])) { - quote = 1; - if (str[0] == '$') dollar = 1; - } - - i = quote + dollar; - while (i < slen - quote) { - if (str[i] == escape_char && str[i+1] == q_char && i+1 < slen-quote) - i++; - new_str[j++] = str[i++]; - } - new_str[j] = '\0'; - - return new_str; -} - /* * Check ';[a-fA-F0-9]{8}' file suffix used for temporary files by rpm when * installing packages. diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index c105487ac..af0469e66 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -31,10 +31,6 @@ #define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" #define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con) -char *utils_single_quote_string (const char *str); - -char *utils_single_unquote_string (const char *str); - char *utils_cert_path (const char *parent, const char *suffix); const char *utils_get_ifcfg_name (const char *file, gboolean only_ifcfg); From 1fb3d5d7944e20e3fd70296f763af5b23bb0efe1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 12:44:27 +0100 Subject: [PATCH 15/39] ifcfg-rh: don't call svSetValue with verbatim=TRUE This is at best a performance optimization. In the next step get rid of the verbatim argument, so ensure we pass FALSE everwhere. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index fd03d5695..22a66b570 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -934,17 +934,17 @@ write_wireless_setting (NMConnection *connection, g_free (keys_path); } - svSetValue (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL, TRUE); + svSetValue (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL, FALSE); switch (nm_setting_wireless_get_powersave (s_wireless)) { case NM_SETTING_WIRELESS_POWERSAVE_IGNORE: - svSetValue (ifcfg, "POWERSAVE", "ignore", TRUE); + svSetValue (ifcfg, "POWERSAVE", "ignore", FALSE); break; case NM_SETTING_WIRELESS_POWERSAVE_DISABLE: - svSetValue (ifcfg, "POWERSAVE", "disable", TRUE); + svSetValue (ifcfg, "POWERSAVE", "disable", FALSE); break; case NM_SETTING_WIRELESS_POWERSAVE_ENABLE: - svSetValue (ifcfg, "POWERSAVE", "enable", TRUE); + svSetValue (ifcfg, "POWERSAVE", "enable", FALSE); break; default: case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT: @@ -955,14 +955,14 @@ write_wireless_setting (NMConnection *connection, svUnsetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); switch (nm_setting_wireless_get_mac_address_randomization (s_wireless)) { case NM_SETTING_MAC_RANDOMIZATION_DEFAULT: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default", TRUE); + svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default", FALSE); break; case NM_SETTING_MAC_RANDOMIZATION_ALWAYS: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always", TRUE); + svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always", FALSE); break; default: case NM_SETTING_MAC_RANDOMIZATION_NEVER: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never", TRUE); + svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never", FALSE); break; } From b473256cfdc1e21b056d78597999734ad0f8e200 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 12:23:41 +0100 Subject: [PATCH 16/39] ifcfg-rh: remove unused argument "verbatim" from shvar.h API It is wrong to allow access to unquoted ifcfg-rh values. All users of this ~feature~ misused it to encode meaning in the type of quotation, which is wrong. Also, shvar.h is not able to fully parse shell. We can improve that, but it should be handled internally, in one place. Not by callers applying some quirks after getting a "verbatim" value. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 312 ++++++------ .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 459 ++++++++---------- src/settings/plugins/ifcfg-rh/shvar.c | 40 +- src/settings/plugins/ifcfg-rh/shvar.h | 8 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 74 ++- 5 files changed, 425 insertions(+), 468 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 6af19072f..61b273c63 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -97,7 +97,7 @@ make_connection_name (shvarFile *ifcfg, char *full_name = NULL, *name; /* If the ifcfg file already has a NAME, always use that */ - name = svGetValue (ifcfg, "NAME", FALSE); + name = svGetValue (ifcfg, "NAME"); if (name && strlen (name)) return name; @@ -142,13 +142,13 @@ make_connection_setting (const char *file, g_free (new_id); /* Try for a UUID key before falling back to hashing the file name */ - uuid = svGetValue (ifcfg, "UUID", FALSE); + uuid = svGetValue (ifcfg, "UUID"); if (!uuid || !strlen (uuid)) { g_free (uuid); uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } - stable_id = svGetValue (ifcfg, "STABLE_ID", FALSE); + stable_id = svGetValue (ifcfg, "STABLE_ID"); g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, type, @@ -157,7 +157,7 @@ make_connection_setting (const char *file, NULL); g_free (uuid); - value = svGetValue (ifcfg, "DEVICE", FALSE); + value = svGetValue (ifcfg, "DEVICE"); if (value) { if (nm_utils_iface_valid_name (value)) { g_object_set (s_con, @@ -168,7 +168,7 @@ make_connection_setting (const char *file, g_free (value); } - value = svGetValue (ifcfg, "LLDP", FALSE); + value = svGetValue (ifcfg, "LLDP"); if (!g_strcmp0 (value, "rx")) lldp = NM_SETTING_CONNECTION_LLDP_ENABLE_RX; else @@ -192,7 +192,7 @@ make_connection_setting (const char *file, NM_SETTING_CONNECTION_LLDP, lldp, NULL); - value = svGetValue (ifcfg, "USERS", FALSE); + value = svGetValue (ifcfg, "USERS"); if (value) { char **items, **iter; @@ -208,7 +208,7 @@ make_connection_setting (const char *file, } - zone = svGetValue (ifcfg, "ZONE", FALSE); + zone = svGetValue (ifcfg, "ZONE"); if (!zone || !strlen (zone)) { g_free (zone); zone = NULL; @@ -216,7 +216,7 @@ make_connection_setting (const char *file, g_object_set (s_con, NM_SETTING_CONNECTION_ZONE, zone, NULL); g_free (zone); - value = svGetValue (ifcfg, "SECONDARY_UUIDS", FALSE); + value = svGetValue (ifcfg, "SECONDARY_UUIDS"); if (value) { char **items, **iter; @@ -231,7 +231,7 @@ make_connection_setting (const char *file, g_strfreev (items); } - value = svGetValue (ifcfg, "BRIDGE", FALSE); + value = svGetValue (ifcfg, "BRIDGE"); if (value) { const char *old_value; @@ -246,7 +246,7 @@ make_connection_setting (const char *file, g_free (value); } - value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT", FALSE); + value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT"); if (value) { gint64 tmp; @@ -286,7 +286,7 @@ read_ip4_address (shvarFile *ifcfg, *out_addr = NULL; - value = svGetValue (ifcfg, tag, FALSE); + value = svGetValue (ifcfg, tag); if (!value) return TRUE; @@ -321,7 +321,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) char *value; tag = get_numbered_tag ("IPADDR", i); - value = svGetValue (ifcfg, tag, FALSE); + value = svGetValue (ifcfg, tag); g_free (tag); if (value) { g_free (value); @@ -330,7 +330,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) } tag = get_numbered_tag ("PREFIX", i); - value = svGetValue (ifcfg, tag, FALSE); + value = svGetValue (ifcfg, tag); g_free(tag); if (value) { g_free (value); @@ -339,7 +339,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) } tag = get_numbered_tag ("NETMASK", i); - value = svGetValue (ifcfg, tag, FALSE); + value = svGetValue (ifcfg, tag); g_free(tag); if (value) { g_free (value); @@ -396,7 +396,7 @@ read_full_ip4_address (shvarFile *ifcfg, } /* Prefix */ - value = svGetValue (ifcfg, prefix_tag, FALSE); + value = svGetValue (ifcfg, prefix_tag); if (value) { prefix = _nm_utils_ascii_str_to_int64 (value, 10, 0, 32, -1); if (prefix < 0) { @@ -474,7 +474,7 @@ read_one_ip4_route (shvarFile *ifcfg, if (!dest) { /* Check whether IP is missing or 0.0.0.0 */ char *val; - val = svGetValue (ifcfg, ip_tag, FALSE); + val = svGetValue (ifcfg, ip_tag); if (!val) { *out_route = NULL; success = TRUE; /* missing route = success */ @@ -509,7 +509,7 @@ read_one_ip4_route (shvarFile *ifcfg, } /* Metric */ - value = svGetValue (ifcfg, metric_tag, FALSE); + value = svGetValue (ifcfg, metric_tag); if (value) { metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); if (metric < 0) { @@ -910,7 +910,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error) char *value = NULL; NMSettingProxyMethod method; - value = svGetValue (ifcfg, "PROXY_METHOD", FALSE); + value = svGetValue (ifcfg, "PROXY_METHOD"); if (!value) return NULL; @@ -928,14 +928,14 @@ make_proxy_setting (shvarFile *ifcfg, GError **error) NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_AUTO, NULL); - value = svGetValue (ifcfg, "PAC_URL", FALSE); + value = svGetValue (ifcfg, "PAC_URL"); if (value) { value = g_strstrip (value); g_object_set (s_proxy, NM_SETTING_PROXY_PAC_URL, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "PAC_SCRIPT", FALSE); + value = svGetValue (ifcfg, "PAC_SCRIPT"); if (value) { value = g_strstrip (value); g_object_set (s_proxy, NM_SETTING_PROXY_PAC_SCRIPT, value, NULL); @@ -950,7 +950,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error) break; } - value = svGetValue (ifcfg, "BROWSER_ONLY", FALSE); + value = svGetValue (ifcfg, "BROWSER_ONLY"); if (value) { if (!g_ascii_strcasecmp (value, "yes")) g_object_set (s_proxy, NM_SETTING_PROXY_BROWSER_ONLY, TRUE, NULL); @@ -993,9 +993,9 @@ make_ip4_setting (shvarFile *ifcfg, char *gatewaydev; /* Get the connection ifcfg device name and the global gateway device */ - value = svGetValue (ifcfg, "DEVICE", FALSE); - gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV", FALSE); - dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE); + value = svGetValue (ifcfg, "DEVICE"); + gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV"); + dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS"); /* If there was a global gateway device specified, then only connections * for that device can be the default connection. @@ -1008,7 +1008,7 @@ make_ip4_setting (shvarFile *ifcfg, svCloseFile (network_ifcfg); } - value = svGetValue (ifcfg, "BOOTPROTO", FALSE); + value = svGetValue (ifcfg, "BOOTPROTO"); if (!value || !*value || !g_ascii_strcasecmp (value, "none")) { if (is_any_ip4_address_defined (ifcfg, NULL)) @@ -1070,12 +1070,12 @@ make_ip4_setting (shvarFile *ifcfg, /* Handle DHCP settings */ if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE); + value = svGetValue (ifcfg, "DHCP_HOSTNAME"); if (value && *value) g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); - value = svGetValue (ifcfg, "DHCP_FQDN", FALSE); + value = svGetValue (ifcfg, "DHCP_FQDN"); if (value && *value) { g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NULL, @@ -1089,7 +1089,7 @@ make_ip4_setting (shvarFile *ifcfg, NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, svGetValueInt64 (ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), NULL); - value = svGetValue (ifcfg, "DHCP_CLIENT_ID", FALSE); + value = svGetValue (ifcfg, "DHCP_CLIENT_ID"); if (value && strlen (value)) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, value, NULL); g_free (value); @@ -1152,7 +1152,7 @@ make_ip4_setting (shvarFile *ifcfg, char *tag; tag = g_strdup_printf ("DNS%u", i); - value = svGetValue (ifcfg, tag, FALSE); + value = svGetValue (ifcfg, tag); if (value) { if (nm_utils_ipaddr_valid (AF_INET, value)) { if (!nm_setting_ip_config_add_dns (s_ip4, value)) @@ -1173,7 +1173,7 @@ make_ip4_setting (shvarFile *ifcfg, } /* DNS searches */ - value = svGetValue (ifcfg, "DOMAIN", FALSE); + value = svGetValue (ifcfg, "DOMAIN"); if (value) { char **searches = NULL; @@ -1192,7 +1192,7 @@ make_ip4_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE); + value = svGetValueFull (ifcfg, "RES_OPTIONS"); parse_dns_options (s_ip4, value); parse_dns_options (s_ip4, dns_options); g_free (value); @@ -1240,7 +1240,7 @@ make_ip4_setting (shvarFile *ifcfg, /* Legacy value NM used for a while but is incorrect (rh #459370) */ if (!nm_setting_ip_config_get_num_dns_searches (s_ip4)) { - value = svGetValue (ifcfg, "SEARCH", FALSE); + value = svGetValue (ifcfg, "SEARCH"); if (value) { char **searches = NULL; @@ -1328,7 +1328,7 @@ read_aliases (NMSettingIPConfig *s_ip4, const char *filename) continue; } - device = svGetValue (parsed, "DEVICE", FALSE); + device = svGetValue (parsed, "DEVICE"); if (!device) { PARSE_WARNING ("alias file '%s' has no DEVICE", full_path); svCloseFile (parsed); @@ -1415,10 +1415,10 @@ make_ip6_setting (shvarFile *ifcfg, char *default_dev = NULL; /* Get the connection ifcfg device name and the global default route device */ - value = svGetValue (ifcfg, "DEVICE", FALSE); - ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); - ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV", FALSE); - dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE); + value = svGetValue (ifcfg, "DEVICE"); + ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW"); + ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV"); + dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS"); if (ipv6_defaultgw) { default_dev = strchr (ipv6_defaultgw, '%'); @@ -1442,7 +1442,7 @@ make_ip6_setting (shvarFile *ifcfg, /* Find out method property */ /* Is IPV6 enabled? Set method to "ignored", when not enabled */ - str_value = svGetValue (ifcfg, "IPV6INIT", FALSE); + str_value = svGetValue (ifcfg, "IPV6INIT"); ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE); if (!str_value) { network_ifcfg = svOpenFile (network_file, NULL); @@ -1466,9 +1466,9 @@ make_ip6_setting (shvarFile *ifcfg, method = NM_SETTING_IP6_CONFIG_METHOD_DHCP; else { /* IPV6_AUTOCONF=no and no IPv6 address -> method 'link-local' */ - str_value = svGetValue (ifcfg, "IPV6ADDR", FALSE); + str_value = svGetValue (ifcfg, "IPV6ADDR"); if (!str_value) - str_value = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE); + str_value = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES"); if (!str_value) method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; @@ -1478,7 +1478,7 @@ make_ip6_setting (shvarFile *ifcfg, /* TODO - handle other methods */ /* Read IPv6 Privacy Extensions configuration */ - tmp = svGetValue (ifcfg, "IPV6_PRIVACY", FALSE); + tmp = svGetValue (ifcfg, "IPV6_PRIVACY"); if (tmp) { ip6_privacy = svGetValueBoolean (ifcfg, "IPV6_PRIVACY", FALSE); if (!ip6_privacy) @@ -1511,7 +1511,7 @@ make_ip6_setting (shvarFile *ifcfg, if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { /* METHOD_AUTO may trigger DHCPv6, so save the hostname to send to DHCP */ - value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE); + value = svGetValue (ifcfg, "DHCP_HOSTNAME"); if (value && value[0]) g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); @@ -1522,8 +1522,8 @@ make_ip6_setting (shvarFile *ifcfg, * added to the automatic ones. Note that this is not currently supported by * the legacy 'network' service (ifup-eth). */ - ipv6addr = svGetValue (ifcfg, "IPV6ADDR", FALSE); - ipv6addr_secondaries = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE); + ipv6addr = svGetValue (ifcfg, "IPV6ADDR"); + ipv6addr_secondaries = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES"); value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL, ipv6addr ? ipv6addr : "", @@ -1550,12 +1550,12 @@ make_ip6_setting (shvarFile *ifcfg, /* Gateway */ if (nm_setting_ip_config_get_num_addresses (s_ip6)) { - value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE); + value = svGetValue (ifcfg, "IPV6_DEFAULTGW"); if (!value) { /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */ network_ifcfg = svOpenFile (network_file, NULL); if (network_ifcfg) { - value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); + value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW"); svCloseFile (network_ifcfg); } } @@ -1576,7 +1576,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* IPv6 addressing mode configuration */ - tmp = svGetValue (ifcfg, "IPV6_ADDR_GEN_MODE", FALSE); + tmp = svGetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); if (tmp) { if (nm_utils_enum_from_str (nm_setting_ip6_config_addr_gen_mode_get_type (), tmp, (int *) &addr_gen_mode, NULL)) @@ -1592,7 +1592,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* IPv6 tokenized interface identifier */ - tmp = svGetValue (ifcfg, "IPV6_TOKEN", FALSE); + tmp = svGetValue (ifcfg, "IPV6_TOKEN"); if (tmp) { g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, tmp, NULL); g_free (tmp); @@ -1605,7 +1605,7 @@ make_ip6_setting (shvarFile *ifcfg, char *tag; tag = g_strdup_printf ("DNS%u", i); - value = svGetValue (ifcfg, tag, FALSE); + value = svGetValue (ifcfg, tag); if (!value) { g_free (tag); break; /* all done */ @@ -1639,7 +1639,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE); + value = svGetValueFull (ifcfg, "RES_OPTIONS"); parse_dns_options (s_ip6, value); parse_dns_options (s_ip6, dns_options); g_free (value); @@ -1667,7 +1667,7 @@ check_if_bond_slave (shvarFile *ifcfg, { char *value; - value = svGetValue (ifcfg, "MASTER", FALSE); + value = svGetValue (ifcfg, "MASTER"); if (value) { g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); g_object_set (s_con, @@ -1687,7 +1687,7 @@ check_if_team_slave (shvarFile *ifcfg, { gs_free char *value = NULL; - value = svGetValue (ifcfg, "TEAM_MASTER", FALSE); + value = svGetValue (ifcfg, "TEAM_MASTER"); if (!value) return FALSE; g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); @@ -1762,7 +1762,7 @@ read_dcb_app (shvarFile *ifcfg, /* Priority */ tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app); - val = svGetValue (ifcfg, tmp, FALSE); + val = svGetValue (ifcfg, tmp); if (val) { priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1); if (priority < 0) { @@ -1803,7 +1803,7 @@ read_dcb_bool_array (shvarFile *ifcfg, gboolean success = FALSE; guint i; - val = svGetValue (ifcfg, prop, FALSE); + val = svGetValue (ifcfg, prop); if (!val) return TRUE; @@ -1854,7 +1854,7 @@ read_dcb_uint_array (shvarFile *ifcfg, gboolean success = FALSE; guint i; - val = svGetValue (ifcfg, prop, FALSE); + val = svGetValue (ifcfg, prop); if (!val) return TRUE; @@ -1908,7 +1908,7 @@ read_dcb_percent_array (shvarFile *ifcfg, char **split = NULL, **iter; guint i, sum = 0; - val = svGetValue (ifcfg, prop, FALSE); + val = svGetValue (ifcfg, prop); if (!val) return TRUE; @@ -1986,7 +1986,7 @@ make_dcb_setting (shvarFile *ifcfg, return FALSE; } if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) { - val = svGetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, FALSE); + val = svGetValue (ifcfg, KEY_DCB_APP_FCOE_MODE); if (val) { if (strcmp (val, NM_SETTING_DCB_FCOE_MODE_FABRIC) == 0 || strcmp (val, NM_SETTING_DCB_FCOE_MODE_VN2VN) == 0) @@ -2123,7 +2123,7 @@ add_one_wep_key (shvarFile *ifcfg, g_return_val_if_fail (key_idx <= 3, FALSE); g_return_val_if_fail (s_wsec != NULL, FALSE); - value = svGetValue (ifcfg, shvar_key, FALSE); + value = svGetValue (ifcfg, shvar_key); if (!value || !strlen (value)) { g_free (value); return TRUE; @@ -2230,7 +2230,7 @@ read_secret_flags (shvarFile *ifcfg, const char *flags_key) g_return_val_if_fail (flags_key[0] != '\0', NM_SETTING_SECRET_FLAG_NONE); g_return_val_if_fail (g_str_has_suffix (flags_key, "_FLAGS"), NM_SETTING_SECRET_FLAG_NONE); - val = svGetValue (ifcfg, flags_key, FALSE); + val = svGetValue (ifcfg, flags_key); if (val) { if (strstr (val, SECRET_FLAG_AGENT)) flags |= NM_SETTING_SECRET_FLAG_AGENT_OWNED; @@ -2259,7 +2259,7 @@ make_wep_setting (shvarFile *ifcfg, s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); - value = svGetValue (ifcfg, "DEFAULTKEY", FALSE); + value = svGetValue (ifcfg, "DEFAULTKEY"); if (value) { default_key_idx = _nm_utils_ascii_str_to_int64 (value, 0, 1, 4, 0); if (default_key_idx == 0) { @@ -2295,7 +2295,7 @@ make_wep_setting (shvarFile *ifcfg, } } - value = svGetValue (ifcfg, "SECURITYMODE", FALSE); + value = svGetValue (ifcfg, "SECURITYMODE"); if (value) { char *lcase; @@ -2358,7 +2358,7 @@ fill_wpa_ciphers (shvarFile *ifcfg, char **list = NULL, **iter; int i = 0; - p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", FALSE); + p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE"); if (!value) return TRUE; @@ -2428,13 +2428,13 @@ parse_wpa_psk (shvarFile *ifcfg, /* Try to get keys from the "shadow" key file */ keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); if (keys_ifcfg) { - psk = svGetValue (keys_ifcfg, "WPA_PSK", FALSE); + psk = svGetValue (keys_ifcfg, "WPA_PSK"); svCloseFile (keys_ifcfg); } /* Fall back to the original ifcfg */ if (!psk) - psk = svGetValue (ifcfg, "WPA_PSK", FALSE); + psk = svGetValue (ifcfg, "WPA_PSK"); if (!psk) return NULL; @@ -2471,7 +2471,7 @@ eap_simple_reader (const char *eap_method, NMSettingSecretFlags flags; char *value; - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY"); if (!value) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", @@ -2486,10 +2486,10 @@ eap_simple_reader (const char *eap_method, /* Only read the password if it's system-owned */ if (flags == NM_SETTING_SECRET_FLAG_NONE) { - value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD"); if (!value && keys) { /* Try the lookaside keys file */ - value = svGetValue (keys, "IEEE_8021X_PASSWORD", FALSE); + value = svGetValue (keys, "IEEE_8021X_PASSWORD"); } if (!value) { @@ -2552,7 +2552,7 @@ eap_tls_reader (const char *eap_method, const char *pk_pw_flags_prop = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS : NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS; NMSettingSecretFlags flags; - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY"); if (!value) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", @@ -2562,7 +2562,7 @@ eap_tls_reader (const char *eap_method, g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, value, NULL); g_free (value); - ca_cert = svGetValue (ifcfg, ca_cert_key, FALSE); + ca_cert = svGetValue (ifcfg, ca_cert_key); if (ca_cert) { real_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (phase2) { @@ -2594,10 +2594,10 @@ eap_tls_reader (const char *eap_method, /* Read the private key password if it's system-owned */ if (flags == NM_SETTING_SECRET_FLAG_NONE) { /* Private key password */ - privkey_password = svGetValue (ifcfg, pk_pw_key, FALSE); + privkey_password = svGetValue (ifcfg, pk_pw_key); if (!privkey_password && keys) { /* Try the lookaside keys file */ - privkey_password = svGetValue (keys, pk_pw_key, FALSE); + privkey_password = svGetValue (keys, pk_pw_key); } if (!privkey_password) { @@ -2610,7 +2610,7 @@ eap_tls_reader (const char *eap_method, } /* The private key itself */ - privkey = svGetValue (ifcfg, pk_key, FALSE); + privkey = svGetValue (ifcfg, pk_key); if (!privkey) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", @@ -2647,7 +2647,7 @@ eap_tls_reader (const char *eap_method, */ if ( privkey_format == NM_SETTING_802_1X_CK_FORMAT_RAW_KEY || privkey_format == NM_SETTING_802_1X_CK_FORMAT_X509) { - client_cert = svGetValue (ifcfg, cli_cert_key, FALSE); + client_cert = svGetValue (ifcfg, cli_cert_key); if (!client_cert) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", @@ -2704,7 +2704,7 @@ eap_peap_reader (const char *eap_method, char **list = NULL, **iter; gboolean success = FALSE; - ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT", FALSE); + ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT"); if (ca_cert) { real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (!nm_setting_802_1x_set_ca_cert (s_8021x, @@ -2718,7 +2718,7 @@ eap_peap_reader (const char *eap_method, eap_method); } - peapver = svGetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", FALSE); + peapver = svGetValue (ifcfg, "IEEE_8021X_PEAP_VERSION"); if (peapver) { if (!strcmp (peapver, "0")) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "0", NULL); @@ -2735,11 +2735,11 @@ eap_peap_reader (const char *eap_method, if (svGetValueBoolean (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", FALSE)) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPLABEL, "1", NULL); - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE); + anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY"); if (anon_ident && strlen (anon_ident)) g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); + inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); if (!inner_auth) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); @@ -2808,7 +2808,7 @@ eap_ttls_reader (const char *eap_method, char *tmp; char **list = NULL, **iter; - ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT", FALSE); + ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT"); if (ca_cert) { real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (!nm_setting_802_1x_set_ca_cert (s_8021x, @@ -2822,11 +2822,11 @@ eap_ttls_reader (const char *eap_method, eap_method); } - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE); + anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY"); if (anon_ident && strlen (anon_ident)) g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - tmp = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); + tmp = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); if (!tmp) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); @@ -2899,13 +2899,13 @@ eap_fast_reader (const char *eap_method, gboolean allow_unauth = FALSE, allow_auth = FALSE; gboolean success = FALSE; - pac_file = svGetValue (ifcfg, "IEEE_8021X_PAC_FILE", FALSE); + pac_file = svGetValue (ifcfg, "IEEE_8021X_PAC_FILE"); if (pac_file) { real_pac_path = get_full_file_path (svFileGetName (ifcfg), pac_file); g_object_set (s_8021x, NM_SETTING_802_1X_PAC_FILE, real_pac_path, NULL); } - fast_provisioning = svGetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", FALSE); + fast_provisioning = svGetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); if (fast_provisioning) { list = g_strsplit_set (fast_provisioning, " \t", 0); for (iter = list; iter && *iter; iter++) { @@ -2933,11 +2933,11 @@ eap_fast_reader (const char *eap_method, goto done; } - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE); + anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY"); if (anon_ident && strlen (anon_ident)) g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); + inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); if (!inner_auth) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); @@ -3024,7 +3024,7 @@ read_8021x_list_value (shvarFile *ifcfg, g_return_if_fail (ifcfg_var_name != NULL); g_return_if_fail (prop_name != NULL); - value = svGetValue (ifcfg, ifcfg_var_name, FALSE); + value = svGetValue (ifcfg, ifcfg_var_name); if (!value) return; @@ -3047,7 +3047,7 @@ fill_8021x (shvarFile *ifcfg, char *value; char **list = NULL, **iter; - value = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS"); if (!value) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_EAP_METHODS for key management '%s'", @@ -3108,11 +3108,11 @@ fill_8021x (shvarFile *ifcfg, goto error; } - value = svGetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_SUBJECT_MATCH, value, NULL); g_free (value); - value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH, value, NULL); g_free (value); @@ -3121,10 +3121,10 @@ fill_8021x (shvarFile *ifcfg, read_8021x_list_value (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", s_8021x, NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES); - value = svGetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, value, NULL); g_free (value); - value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH, value, NULL); g_free (value); @@ -3157,7 +3157,7 @@ make_wpa_setting (shvarFile *ifcfg, wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - value = svGetValue (ifcfg, "KEY_MGMT", FALSE); + value = svGetValue (ifcfg, "KEY_MGMT"); wpa_psk = !g_strcmp0 (value, "WPA-PSK"); wpa_eap = !g_strcmp0 (value, "WPA-EAP"); ieee8021x = !g_strcmp0 (value, "IEEE8021X"); @@ -3177,8 +3177,8 @@ make_wpa_setting (shvarFile *ifcfg, } else { char *allow_wpa, *allow_rsn; - allow_wpa = svGetValue (ifcfg, "WPA_ALLOW_WPA", FALSE); - allow_rsn = svGetValue (ifcfg, "WPA_ALLOW_WPA2", FALSE); + allow_wpa = svGetValue (ifcfg, "WPA_ALLOW_WPA"); + allow_rsn = svGetValue (ifcfg, "WPA_ALLOW_WPA2"); if (allow_wpa && svGetValueBoolean (ifcfg, "WPA_ALLOW_WPA", TRUE)) nm_setting_wireless_security_add_proto (wsec, "wpa"); @@ -3232,7 +3232,7 @@ make_wpa_setting (shvarFile *ifcfg, g_free (value); - value = svGetValue (ifcfg, "SECURITYMODE", FALSE); + value = svGetValue (ifcfg, "SECURITYMODE"); if (NM_IN_STRSET (value, NULL, "open")) g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, value, NULL); @@ -3258,12 +3258,12 @@ make_leap_setting (shvarFile *ifcfg, wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - value = svGetValue (ifcfg, "KEY_MGMT", FALSE); + value = svGetValue (ifcfg, "KEY_MGMT"); if (!value || strcmp (value, "IEEE8021X")) goto error; /* Not LEAP */ g_free (value); - value = svGetValue (ifcfg, "SECURITYMODE", FALSE); + value = svGetValue (ifcfg, "SECURITYMODE"); if (!value || strcasecmp (value, "leap")) goto error; /* Not LEAP */ @@ -3274,12 +3274,12 @@ make_leap_setting (shvarFile *ifcfg, /* Read LEAP password if it's system-owned */ if (flags == NM_SETTING_SECRET_FLAG_NONE) { - value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD"); if (!value) { /* Try to get keys from the "shadow" key file */ keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); if (keys_ifcfg) { - value = svGetValue (keys_ifcfg, "IEEE_8021X_PASSWORD", FALSE); + value = svGetValue (keys_ifcfg, "IEEE_8021X_PASSWORD"); svCloseFile (keys_ifcfg); } } @@ -3288,7 +3288,7 @@ make_leap_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); + value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing LEAP identity"); @@ -3380,25 +3380,25 @@ make_wireless_setting (shvarFile *ifcfg, s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); - value = svGetValue (ifcfg, "HWADDR", FALSE); + value = svGetValue (ifcfg, "HWADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "MACADDR", FALSE); + value = svGetValue (ifcfg, "MACADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", FALSE); + value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); g_object_set (s_wireless, NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, value, NULL); g_free (value); - value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); + value = svGetValue (ifcfg, "HWADDR_BLACKLIST"); if (value) { char **strv; @@ -3408,7 +3408,7 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "ESSID", FALSE); + value = svGetValue (ifcfg, "ESSID"); if (value) { gs_unref_bytes GBytes *bytes = NULL; gsize ssid_len = 0; @@ -3437,7 +3437,7 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "MODE", FALSE); + value = svGetValue (ifcfg, "MODE"); if (value) { char *lcase; const char *mode = NULL; @@ -3463,14 +3463,14 @@ make_wireless_setting (shvarFile *ifcfg, g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, mode, NULL); } - value = svGetValue (ifcfg, "BSSID", FALSE); + value = svGetValue (ifcfg, "BSSID"); if (value) { value = g_strstrip (value); g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "CHANNEL", FALSE); + value = svGetValue (ifcfg, "CHANNEL"); if (value) { errno = 0; chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0); @@ -3484,7 +3484,7 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "BAND", FALSE); + value = svGetValue (ifcfg, "BAND"); if (value) { if (!strcmp (value, "a")) { if (chan && chan <= 14) { @@ -3515,7 +3515,7 @@ make_wireless_setting (shvarFile *ifcfg, g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); } - value = svGetValue (ifcfg, "MTU", FALSE); + value = svGetValue (ifcfg, "MTU"); if (value) { int mtu; @@ -3535,7 +3535,7 @@ make_wireless_setting (shvarFile *ifcfg, svGetValueBoolean (ifcfg, "SSID_HIDDEN", FALSE), NULL); - value = svGetValueFull (ifcfg, "POWERSAVE", FALSE); + value = svGetValueFull (ifcfg, "POWERSAVE"); if (value) { if (!strcmp (value, "default")) powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; @@ -3559,7 +3559,7 @@ make_wireless_setting (shvarFile *ifcfg, powersave, NULL); - value = svGetValueFull (ifcfg, "MAC_ADDRESS_RANDOMIZATION", FALSE); + value = svGetValueFull (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); if (value) { if (strcmp (value, "default") == 0) mac_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT; @@ -3792,7 +3792,7 @@ make_wired_setting (shvarFile *ifcfg, s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); - value = svGetValue (ifcfg, "MTU", FALSE); + value = svGetValue (ifcfg, "MTU"); if (value) { int mtu; @@ -3804,14 +3804,14 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "HWADDR", FALSE); + value = svGetValue (ifcfg, "HWADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "SUBCHANNELS", FALSE); + value = svGetValue (ifcfg, "SUBCHANNELS"); if (value) { const char *p = value; gboolean success = TRUE; @@ -3842,18 +3842,18 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "PORTNAME", FALSE); + value = svGetValue (ifcfg, "PORTNAME"); if (value && strlen (value)) { nm_setting_wired_add_s390_option (s_wired, "portname", value); } g_free (value); - value = svGetValue (ifcfg, "CTCPROT", FALSE); + value = svGetValue (ifcfg, "CTCPROT"); if (value && strlen (value)) nm_setting_wired_add_s390_option (s_wired, "ctcprot", value); g_free (value); - nettype = svGetValue (ifcfg, "NETTYPE", FALSE); + nettype = svGetValue (ifcfg, "NETTYPE"); if (nettype && strlen (nettype)) { if (!strcmp (nettype, "qeth") || !strcmp (nettype, "lcs") || !strcmp (nettype, "ctc")) g_object_set (s_wired, NM_SETTING_WIRED_S390_NETTYPE, nettype, NULL); @@ -3862,7 +3862,7 @@ make_wired_setting (shvarFile *ifcfg, } g_free (nettype); - value = svGetValue (ifcfg, "OPTIONS", FALSE); + value = svGetValue (ifcfg, "OPTIONS"); if (value && strlen (value)) { char **options, **iter; @@ -3883,18 +3883,18 @@ make_wired_setting (shvarFile *ifcfg, } g_free (value); - value = svGetValue (ifcfg, "MACADDR", FALSE); + value = svGetValue (ifcfg, "MACADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", FALSE); + value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); g_object_set (s_wired, NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, value, NULL); g_free (value); - value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); + value = svGetValue (ifcfg, "HWADDR_BLACKLIST"); if (value) { char **strv; @@ -3904,7 +3904,7 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "KEY_MGMT", FALSE); + value = svGetValue (ifcfg, "KEY_MGMT"); if (value) { if (!strcmp (value, "IEEE8021X")) { *s_8021x = fill_8021x (ifcfg, file, value, FALSE, error); @@ -3918,7 +3918,7 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValueFull (ifcfg, "ETHTOOL_OPTS", FALSE); + value = svGetValueFull (ifcfg, "ETHTOOL_OPTS"); parse_ethtool_options (ifcfg, s_wired, value); g_free (value); @@ -3979,19 +3979,19 @@ parse_infiniband_p_key (shvarFile *ifcfg, int id; gboolean ret = FALSE; - device = svGetValue (ifcfg, "DEVICE", FALSE); + device = svGetValue (ifcfg, "DEVICE"); if (!device) { PARSE_WARNING ("InfiniBand connection specified PKEY but not DEVICE"); goto done; } - physdev = svGetValue (ifcfg, "PHYSDEV", FALSE); + physdev = svGetValue (ifcfg, "PHYSDEV"); if (!physdev) { PARSE_WARNING ("InfiniBand connection specified PKEY but not PHYSDEV"); goto done; } - pkey_id = svGetValue (ifcfg, "PKEY_ID", FALSE); + pkey_id = svGetValue (ifcfg, "PKEY_ID"); if (!pkey_id) { PARSE_WARNING ("InfiniBand connection specified PKEY but not PKEY_ID"); goto done; @@ -4039,7 +4039,7 @@ make_infiniband_setting (shvarFile *ifcfg, s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ()); - value = svGetValue (ifcfg, "MTU", FALSE); + value = svGetValue (ifcfg, "MTU"); if (value) { int mtu; @@ -4051,7 +4051,7 @@ make_infiniband_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "HWADDR", FALSE); + value = svGetValue (ifcfg, "HWADDR"); if (value) { value = g_strstrip (value); g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, value, NULL); @@ -4151,7 +4151,7 @@ make_bond_setting (shvarFile *ifcfg, s_bond = NM_SETTING_BOND (nm_setting_bond_new ()); - value = svGetValue (ifcfg, "DEVICE", FALSE); + value = svGetValue (ifcfg, "DEVICE"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "mandatory DEVICE keyword missing"); @@ -4159,7 +4159,7 @@ make_bond_setting (shvarFile *ifcfg, } g_free (value); - value = svGetValue (ifcfg, "BONDING_OPTS", FALSE); + value = svGetValue (ifcfg, "BONDING_OPTS"); if (value) { char **items, **iter; @@ -4243,7 +4243,7 @@ read_team_config (shvarFile *ifcfg, const char *key, GError **error) gs_free char *value = NULL; size_t l; - value = svGetValue (ifcfg, key, FALSE); + value = svGetValue (ifcfg, key); if (!value) return NULL; @@ -4273,7 +4273,7 @@ make_team_setting (shvarFile *ifcfg, s_team = NM_SETTING_TEAM (nm_setting_team_new ()); - value = svGetValue (ifcfg, "DEVICE", FALSE); + value = svGetValue (ifcfg, "DEVICE"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "mandatory DEVICE keyword missing"); @@ -4430,7 +4430,7 @@ make_bridge_setting (shvarFile *ifcfg, s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ()); - value = svGetValue (ifcfg, "DEVICE", FALSE); + value = svGetValue (ifcfg, "DEVICE"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "mandatory DEVICE keyword missing"); @@ -4438,14 +4438,14 @@ make_bridge_setting (shvarFile *ifcfg, } g_free (value); - value = svGetValue (ifcfg, "MACADDR", FALSE); + value = svGetValue (ifcfg, "MACADDR"); if (value) { value = g_strstrip (value); g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "STP", FALSE); + value = svGetValue (ifcfg, "STP"); if (value) { if (!strcasecmp (value, "on") || !strcasecmp (value, "yes")) { g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, TRUE, NULL); @@ -4464,7 +4464,7 @@ make_bridge_setting (shvarFile *ifcfg, g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL); } - value = svGetValue (ifcfg, "DELAY", FALSE); + value = svGetValue (ifcfg, "DELAY"); if (value) { if (stp) { if (get_uint (value, &u)) @@ -4476,7 +4476,7 @@ make_bridge_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE); + value = svGetValue (ifcfg, "BRIDGING_OPTS"); if (value) { handle_bridging_opts (NM_SETTING (s_bridge), stp, value, handle_bridge_option); g_free (value); @@ -4559,12 +4559,12 @@ make_bridge_port_setting (shvarFile *ifcfg) g_return_val_if_fail (ifcfg != NULL, FALSE); - value = svGetValue (ifcfg, "BRIDGE", FALSE); + value = svGetValue (ifcfg, "BRIDGE"); if (value) { g_free (value); s_port = nm_setting_bridge_port_new (); - value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE); + value = svGetValue (ifcfg, "BRIDGING_OPTS"); if (value) handle_bridging_opts (s_port, FALSE, value, handle_bridge_port_option); g_free (value); @@ -4641,7 +4641,7 @@ parse_prio_map_list (NMSettingVlan *s_vlan, char *value; gchar **list = NULL, **iter; - value = svGetValue (ifcfg, key, FALSE); + value = svGetValue (ifcfg, key); if (!value) return; @@ -4672,7 +4672,7 @@ make_vlan_setting (shvarFile *ifcfg, guint32 vlan_flags = 0; gint gvrp, reorder_hdr; - value = svGetValue (ifcfg, "VLAN_ID", FALSE); + value = svGetValue (ifcfg, "VLAN_ID"); if (value) { vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1); if (vlan_id == -1) { @@ -4685,7 +4685,7 @@ make_vlan_setting (shvarFile *ifcfg, } /* Need DEVICE if we don't have a separate VLAN_ID property */ - iface_name = svGetValue (ifcfg, "DEVICE", FALSE); + iface_name = svGetValue (ifcfg, "DEVICE"); if (!iface_name && vlan_id < 0) { g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing DEVICE property; cannot determine VLAN ID."); @@ -4695,7 +4695,7 @@ make_vlan_setting (shvarFile *ifcfg, s_vlan = NM_SETTING_VLAN (nm_setting_vlan_new ()); /* Parent interface from PHYSDEV takes precedence if it exists */ - parent = svGetValue (ifcfg, "PHYSDEV", FALSE); + parent = svGetValue (ifcfg, "PHYSDEV"); if (iface_name) { p = strchr (iface_name, '.'); @@ -4751,7 +4751,7 @@ make_vlan_setting (shvarFile *ifcfg, if (gvrp > 0) vlan_flags |= NM_VLAN_FLAG_GVRP; - value = svGetValue (ifcfg, "VLAN_FLAGS", FALSE); + value = svGetValue (ifcfg, "VLAN_FLAGS"); if (value) { gs_strfreev char **strv = NULL; char **ptr; @@ -4862,7 +4862,7 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg, nm_connection_add_setting (connection, nm_setting_generic_new ()); /* Get a spec */ - value = svGetValue (ifcfg, "HWADDR", FALSE); + value = svGetValue (ifcfg, "HWADDR"); if (value) { char *lower = g_ascii_strdown (value, -1); *out_spec = g_strdup_printf ("%s:mac:%s", type, lower); @@ -4871,14 +4871,14 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg, return connection; } - value = svGetValue (ifcfg, "SUBCHANNELS", FALSE); + value = svGetValue (ifcfg, "SUBCHANNELS"); if (value) { *out_spec = g_strdup_printf ("%s:s390-subchannels:%s", type, value); g_free (value); return connection; } - value = svGetValue (ifcfg, "DEVICE", FALSE); + value = svGetValue (ifcfg, "DEVICE"); if (value) { *out_spec = g_strdup_printf ("%s:interface-name:%s", type, value); g_free (value); @@ -4907,7 +4907,7 @@ uuid_from_file (const char *filename) return NULL; /* Try for a UUID key before falling back to hashing the file name */ - uuid = svGetValue (ifcfg, "UUID", FALSE); + uuid = svGetValue (ifcfg, "UUID"); if (!uuid || !strlen (uuid)) { g_free (uuid); uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); @@ -4928,7 +4928,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) */ if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches (NM_SETTING_IP_CONFIG (s_ip4)) == 0) { /* DNS searches */ - char *value = svGetValue (ifcfg, "DOMAIN", FALSE); + char *value = svGetValue (ifcfg, "DOMAIN"); if (value) { char **searches = g_strsplit (value, " ", 0); if (searches) { @@ -4988,7 +4988,7 @@ connection_from_file_full (const char *filename, } /* iBFT is handled by the iBFT settings plugin */ - bootproto = svGetValue (parsed, "BOOTPROTO", FALSE); + bootproto = svGetValue (parsed, "BOOTPROTO"); if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) { if (out_ignore_error) *out_ignore_error = TRUE; @@ -4999,7 +4999,7 @@ connection_from_file_full (const char *filename, } g_free (bootproto); - devtype = svGetValue (parsed, "DEVICETYPE", FALSE); + devtype = svGetValue (parsed, "DEVICETYPE"); if (devtype) { if (!strcasecmp (devtype, TYPE_TEAM)) type = g_strdup (TYPE_TEAM); @@ -5013,19 +5013,19 @@ connection_from_file_full (const char *filename, /* Team and TeamPort types are also accepted by the mere * presense of TEAM_CONFIG/TEAM_MASTER. They don't require * DEVICETYPE. */ - t = svGetValue (parsed, "TEAM_CONFIG", FALSE); + t = svGetValue (parsed, "TEAM_CONFIG"); if (t) type = g_strdup (TYPE_TEAM); } if (!type) - type = svGetValue (parsed, "TYPE", FALSE); + type = svGetValue (parsed, "TYPE"); if (!type) { gs_free char *tmp = NULL; char *device; - if ((tmp = svGetValue (parsed, "IPV6TUNNELIPV4", FALSE))) { + if ((tmp = svGetValue (parsed, "IPV6TUNNELIPV4"))) { if (out_ignore_error) *out_ignore_error = TRUE; g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -5033,7 +5033,7 @@ connection_from_file_full (const char *filename, goto done; } - device = svGetValue (parsed, "DEVICE", FALSE); + device = svGetValue (parsed, "DEVICE"); if (!device) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "File '%s' had neither TYPE nor DEVICE keys.", filename); @@ -5247,7 +5247,7 @@ devtimeout_from_file (const char *filename) if (!ifcfg) return 0; - devtimeout_str = svGetValue (ifcfg, "DEVTIMEOUT", FALSE); + devtimeout_str = svGetValue (ifcfg, "DEVTIMEOUT"); if (devtimeout_str) { devtimeout = _nm_utils_ascii_str_to_int64 (devtimeout_str, 10, 0, G_MAXUINT, 0); g_free (devtimeout_str); diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 22a66b570..b302b6e7b 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -98,7 +98,7 @@ save_secret_flags (shvarFile *ifcfg, g_string_append (str, SECRET_FLAG_NOT_REQUIRED); } - svSetValue (ifcfg, key, str->len ? str->str : NULL, FALSE); + svSetValue (ifcfg, key, str->len ? str->str : NULL); g_string_free (str, TRUE); } @@ -107,8 +107,7 @@ set_secret (shvarFile *ifcfg, const char *key, const char *value, const char *flags_key, - NMSettingSecretFlags flags, - gboolean verbatim) + NMSettingSecretFlags flags) { shvarFile *keyfile; GError *error = NULL; @@ -127,7 +126,7 @@ set_secret (shvarFile *ifcfg, /* Only write the secret if it's system owned and supposed to be saved */ if (flags == NM_SETTING_SECRET_FLAG_NONE) - svSetValue (keyfile, key, value, verbatim); + svSetValue (keyfile, key, value); else svUnsetValue (keyfile, key); @@ -143,7 +142,7 @@ set_secret (shvarFile *ifcfg, error: /* Try setting the secret in the actual ifcfg */ - svSetValue (ifcfg, key, value, FALSE); + svSetValue (ifcfg, key, value); } typedef struct ObjectType { @@ -278,7 +277,7 @@ write_object (NMSetting8021x *s_8021x, * may have been sent. */ if (path) { - svSetValue (ifcfg, objtype->ifcfg_key, path, FALSE); + svSetValue (ifcfg, objtype->ifcfg_key, path); return TRUE; } @@ -306,7 +305,7 @@ write_object (NMSetting8021x *s_8021x, 0600, &write_error); if (success) { - svSetValue (ifcfg, objtype->ifcfg_key, new_file, FALSE); + svSetValue (ifcfg, objtype->ifcfg_key, new_file); g_free (new_file); return TRUE; } else { @@ -366,15 +365,13 @@ write_8021x_certs (NMSetting8021x *s_8021x, "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD", password, "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD_FLAGS", - flags, - FALSE); + flags); } else { set_secret (ifcfg, "IEEE_8021X_PRIVATE_KEY_PASSWORD", password, "IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS", - flags, - FALSE); + flags); } /* Client certificate */ @@ -384,7 +381,7 @@ write_8021x_certs (NMSetting8021x *s_8021x, */ svSetValue (ifcfg, phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT", - NULL, FALSE); + NULL); } else { /* Save the client certificate */ if (!write_object (s_8021x, ifcfg, phase2 ? &phase2_client_type : &client_type, error)) @@ -421,7 +418,7 @@ write_8021x_setting (NMConnection *connection, /* If wired, write KEY_MGMT */ if (wired) - svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X", FALSE); + svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X"); /* EAP method */ if (nm_setting_802_1x_get_num_eap_methods (s_8021x)) { @@ -429,52 +426,49 @@ write_8021x_setting (NMConnection *connection, if (value) tmp = g_ascii_strup (value, -1); } - svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp, FALSE); + svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp); g_free (tmp); svSetValue (ifcfg, "IEEE_8021X_IDENTITY", - nm_setting_802_1x_get_identity (s_8021x), - FALSE); + nm_setting_802_1x_get_identity (s_8021x)); svSetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", - nm_setting_802_1x_get_anonymous_identity (s_8021x), - FALSE); + nm_setting_802_1x_get_anonymous_identity (s_8021x)); set_secret (ifcfg, "IEEE_8021X_PASSWORD", nm_setting_802_1x_get_password (s_8021x), "IEEE_8021X_PASSWORD_FLAGS", - nm_setting_802_1x_get_password_flags (s_8021x), - FALSE); + nm_setting_802_1x_get_password_flags (s_8021x)); /* PEAP version */ value = nm_setting_802_1x_get_phase1_peapver (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_PEAP_VERSION"); if (value && (!strcmp (value, "0") || !strcmp (value, "1"))) - svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", value, FALSE); + svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", value); /* Force new PEAP label */ value = nm_setting_802_1x_get_phase1_peaplabel (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL"); if (value && !strcmp (value, "1")) - svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes", FALSE); + svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes"); /* PAC file */ value = nm_setting_802_1x_get_pac_file (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_PAC_FILE"); if (value) - svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", value, FALSE); + svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", value); /* FAST PAC provisioning */ value = nm_setting_802_1x_get_phase1_fast_provisioning (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); if (value) { if (strcmp (value, "1") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth", FALSE); + svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth"); else if (strcmp (value, "2") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth", FALSE); + svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth"); else if (strcmp (value, "3") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth", FALSE); + svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth"); } /* Phase2 auth methods */ @@ -499,18 +493,15 @@ write_8021x_setting (NMConnection *connection, } svSetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", - phase2_auth->len ? phase2_auth->str : NULL, - FALSE); + phase2_auth->len ? phase2_auth->str : NULL); g_string_free (phase2_auth, TRUE); svSetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH", - nm_setting_802_1x_get_subject_match (s_8021x), - FALSE); + nm_setting_802_1x_get_subject_match (s_8021x)); svSetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", - nm_setting_802_1x_get_phase2_subject_match (s_8021x), - FALSE); + nm_setting_802_1x_get_phase2_subject_match (s_8021x)); svUnsetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES"); str = g_string_new (NULL); @@ -522,7 +513,7 @@ write_8021x_setting (NMConnection *connection, g_string_append (str, match); } if (str->len > 0) - svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str, FALSE); + svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str); g_string_free (str, TRUE); svUnsetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES"); @@ -535,15 +526,13 @@ write_8021x_setting (NMConnection *connection, g_string_append (str, match); } if (str->len > 0) - svSetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", str->str, FALSE); + svSetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", str->str); g_string_free (str, TRUE); svSetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", - nm_setting_802_1x_get_domain_suffix_match (s_8021x), - FALSE); + nm_setting_802_1x_get_domain_suffix_match (s_8021x)); svSetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", - nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x), - FALSE); + nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x)); success = write_8021x_certs (s_8021x, FALSE, ifcfg, error); if (success) { @@ -588,34 +577,32 @@ write_wireless_security_setting (NMConnection *connection, wep = TRUE; *no_8021x = TRUE; } else if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) { - svSetValue (ifcfg, "KEY_MGMT", "WPA-PSK", FALSE); + svSetValue (ifcfg, "KEY_MGMT", "WPA-PSK"); wpa = TRUE; *no_8021x = TRUE; } else if (!strcmp (key_mgmt, "ieee8021x")) { - svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X", FALSE); + svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X"); dynamic_wep = TRUE; } else if (!strcmp (key_mgmt, "wpa-eap")) { - svSetValue (ifcfg, "KEY_MGMT", "WPA-EAP", FALSE); + svSetValue (ifcfg, "KEY_MGMT", "WPA-EAP"); wpa = TRUE; } svUnsetValue (ifcfg, "SECURITYMODE"); if (auth_alg) { if (!strcmp (auth_alg, "shared")) - svSetValue (ifcfg, "SECURITYMODE", "restricted", FALSE); + svSetValue (ifcfg, "SECURITYMODE", "restricted"); else if (!strcmp (auth_alg, "open")) - svSetValue (ifcfg, "SECURITYMODE", "open", FALSE); + svSetValue (ifcfg, "SECURITYMODE", "open"); else if (!strcmp (auth_alg, "leap")) { - svSetValue (ifcfg, "SECURITYMODE", "leap", FALSE); + svSetValue (ifcfg, "SECURITYMODE", "leap"); svSetValue (ifcfg, "IEEE_8021X_IDENTITY", - nm_setting_wireless_security_get_leap_username (s_wsec), - FALSE); + nm_setting_wireless_security_get_leap_username (s_wsec)); set_secret (ifcfg, "IEEE_8021X_PASSWORD", nm_setting_wireless_security_get_leap_password (s_wsec), "IEEE_8021X_PASSWORD_FLAGS", - nm_setting_wireless_security_get_leap_password_flags (s_wsec), - FALSE); + nm_setting_wireless_security_get_leap_password_flags (s_wsec)); *no_8021x = TRUE; } } @@ -623,16 +610,16 @@ write_wireless_security_setting (NMConnection *connection, /* WEP keys */ /* Clear any default key */ - set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); /* Clear existing keys */ for (i = 0; i < 4; i++) { tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); g_free (tmp); tmp = g_strdup_printf ("KEY%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); g_free (tmp); } @@ -640,7 +627,7 @@ write_wireless_security_setting (NMConnection *connection, if (wep) { /* Default WEP TX key index */ tmp = g_strdup_printf ("%d", nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec) + 1); - svSetValue (ifcfg, "DEFAULTKEY", tmp, FALSE); + svSetValue (ifcfg, "DEFAULTKEY", tmp); g_free (tmp); for (i = 0; i < 4; i++) { @@ -681,8 +668,7 @@ write_wireless_security_setting (NMConnection *connection, tmp, key, "WEP_KEY_FLAGS", - nm_setting_wireless_security_get_wep_key_flags (s_wsec), - FALSE); + nm_setting_wireless_security_get_wep_key_flags (s_wsec)); } g_free (tmp); g_free (ascii_key); @@ -697,9 +683,9 @@ write_wireless_security_setting (NMConnection *connection, for (i = 0; i < num; i++) { proto = nm_setting_wireless_security_get_proto (s_wsec, i); if (proto && !strcmp (proto, "wpa")) - svSetValue (ifcfg, "WPA_ALLOW_WPA", "yes", FALSE); + svSetValue (ifcfg, "WPA_ALLOW_WPA", "yes"); else if (proto && !strcmp (proto, "rsn")) - svSetValue (ifcfg, "WPA_ALLOW_WPA2", "yes", FALSE); + svSetValue (ifcfg, "WPA_ALLOW_WPA2", "yes"); } /* WPA Pairwise ciphers */ @@ -721,7 +707,7 @@ write_wireless_security_setting (NMConnection *connection, } } if (strlen (str->str) && (dynamic_wep == FALSE)) - svSetValue (ifcfg, "CIPHER_PAIRWISE", str->str, FALSE); + svSetValue (ifcfg, "CIPHER_PAIRWISE", str->str); g_string_free (str, TRUE); /* WPA Group ciphers */ @@ -737,7 +723,7 @@ write_wireless_security_setting (NMConnection *connection, g_free (tmp); } if (strlen (str->str) && (dynamic_wep == FALSE)) - svSetValue (ifcfg, "CIPHER_GROUP", str->str, FALSE); + svSetValue (ifcfg, "CIPHER_GROUP", str->str); g_string_free (str, TRUE); if (wpa) @@ -747,8 +733,7 @@ write_wireless_security_setting (NMConnection *connection, "WPA_PSK", psk, "WPA_PSK_FLAGS", - wpa ? nm_setting_wireless_security_get_psk_flags (s_wsec) : NM_SETTING_SECRET_FLAG_NONE, - FALSE); + wpa ? nm_setting_wireless_security_get_psk_flags (s_wsec) : NM_SETTING_SECRET_FLAG_NONE); return TRUE; } @@ -778,14 +763,13 @@ write_wireless_setting (NMConnection *connection, } device_mac = nm_setting_wireless_get_mac_address (s_wireless); - svSetValue (ifcfg, "HWADDR", device_mac, FALSE); + svSetValue (ifcfg, "HWADDR", device_mac); cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); - svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); + svSetValue (ifcfg, "MACADDR", cloned_mac); svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wireless_get_generate_mac_address_mask (s_wireless), - FALSE); + nm_setting_wireless_get_generate_mac_address_mask (s_wireless)); svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); macaddr_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); @@ -793,7 +777,7 @@ write_wireless_setting (NMConnection *connection, char *blacklist_str; blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str, FALSE); + svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str); g_free (blacklist_str); } @@ -801,7 +785,7 @@ write_wireless_setting (NMConnection *connection, mtu = nm_setting_wireless_get_mtu (s_wireless); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); + svSetValue (ifcfg, "MTU", tmp); g_free (tmp); } @@ -849,7 +833,7 @@ write_wireless_setting (NMConnection *connection, g_string_append (str, "0x"); for (i = 0; i < ssid_len; i++) g_string_append_printf (str, "%02X", ssid_data[i]); - svSetValue (ifcfg, "ESSID", str->str, FALSE); + svSetValue (ifcfg, "ESSID", str->str); g_string_free (str, TRUE); } else { char buf[33]; @@ -857,17 +841,17 @@ write_wireless_setting (NMConnection *connection, nm_assert (ssid_len <= 32); memcpy (buf, ssid_data, ssid_len); buf[ssid_len] = '\0'; - svSetValue (ifcfg, "ESSID", buf, FALSE); + svSetValue (ifcfg, "ESSID", buf); } mode = nm_setting_wireless_get_mode (s_wireless); if (!mode || !strcmp (mode, "infrastructure")) { - svSetValue (ifcfg, "MODE", "Managed", FALSE); + svSetValue (ifcfg, "MODE", "Managed"); } else if (!strcmp (mode, "adhoc")) { - svSetValue (ifcfg, "MODE", "Ad-Hoc", FALSE); + svSetValue (ifcfg, "MODE", "Ad-Hoc"); adhoc = TRUE; } else if (!strcmp (mode, "ap")) { - svSetValue (ifcfg, "MODE", "Ap", FALSE); + svSetValue (ifcfg, "MODE", "Ap"); } else { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Invalid mode '%s' in '%s' setting", @@ -880,15 +864,15 @@ write_wireless_setting (NMConnection *connection, chan = nm_setting_wireless_get_channel (s_wireless); if (chan) { tmp = g_strdup_printf ("%u", chan); - svSetValue (ifcfg, "CHANNEL", tmp, FALSE); + svSetValue (ifcfg, "CHANNEL", tmp); g_free (tmp); } else { /* Band only set if channel is not, since channel implies band */ - svSetValue (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless), FALSE); + svSetValue (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless)); } bssid = nm_setting_wireless_get_bssid (s_wireless); - svSetValue (ifcfg, "BSSID", bssid, FALSE); + svSetValue (ifcfg, "BSSID", bssid); /* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security; * otherwise there's no way to detect WEP vs. open when WEP keys aren't @@ -906,18 +890,18 @@ write_wireless_setting (NMConnection *connection, /* Clear out wifi security keys */ svUnsetValue (ifcfg, "KEY_MGMT"); svUnsetValue (ifcfg, "IEEE_8021X_IDENTITY"); - set_secret (ifcfg, "IEEE_8021X_PASSWORD", NULL, "IEEE_8021X_PASSWORD_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, "IEEE_8021X_PASSWORD", NULL, "IEEE_8021X_PASSWORD_FLAGS", NM_SETTING_SECRET_FLAG_NONE); svUnsetValue (ifcfg, "SECURITYMODE"); /* Clear existing keys */ - set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); for (i = 0; i < 4; i++) { tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); g_free (tmp); tmp = g_strdup_printf ("KEY%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); g_free (tmp); } @@ -926,7 +910,7 @@ write_wireless_setting (NMConnection *connection, svUnsetValue (ifcfg, "WPA_ALLOW_WPA2"); svUnsetValue (ifcfg, "CIPHER_PAIRWISE"); svUnsetValue (ifcfg, "CIPHER_GROUP"); - set_secret (ifcfg, "WPA_PSK", NULL, "WPA_PSK_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); + set_secret (ifcfg, "WPA_PSK", NULL, "WPA_PSK_FLAGS", NM_SETTING_SECRET_FLAG_NONE); /* Kill any old keys file */ keys_path = utils_get_keys_path (svFileGetName (ifcfg)); @@ -934,17 +918,17 @@ write_wireless_setting (NMConnection *connection, g_free (keys_path); } - svSetValue (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL, FALSE); + svSetValue (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL); switch (nm_setting_wireless_get_powersave (s_wireless)) { case NM_SETTING_WIRELESS_POWERSAVE_IGNORE: - svSetValue (ifcfg, "POWERSAVE", "ignore", FALSE); + svSetValue (ifcfg, "POWERSAVE", "ignore"); break; case NM_SETTING_WIRELESS_POWERSAVE_DISABLE: - svSetValue (ifcfg, "POWERSAVE", "disable", FALSE); + svSetValue (ifcfg, "POWERSAVE", "disable"); break; case NM_SETTING_WIRELESS_POWERSAVE_ENABLE: - svSetValue (ifcfg, "POWERSAVE", "enable", FALSE); + svSetValue (ifcfg, "POWERSAVE", "enable"); break; default: case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT: @@ -955,18 +939,18 @@ write_wireless_setting (NMConnection *connection, svUnsetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); switch (nm_setting_wireless_get_mac_address_randomization (s_wireless)) { case NM_SETTING_MAC_RANDOMIZATION_DEFAULT: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default", FALSE); + svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default"); break; case NM_SETTING_MAC_RANDOMIZATION_ALWAYS: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always", FALSE); + svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always"); break; default: case NM_SETTING_MAC_RANDOMIZATION_NEVER: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never", FALSE); + svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never"); break; } - svSetValue (ifcfg, "TYPE", TYPE_WIRELESS, FALSE); + svSetValue (ifcfg, "TYPE", TYPE_WIRELESS); return TRUE; } @@ -988,34 +972,33 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e } mac = nm_setting_infiniband_get_mac_address (s_infiniband); - svSetValue (ifcfg, "HWADDR", mac, FALSE); + svSetValue (ifcfg, "HWADDR", mac); svUnsetValue (ifcfg, "MTU"); mtu = nm_setting_infiniband_get_mtu (s_infiniband); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); + svSetValue (ifcfg, "MTU", tmp); g_free (tmp); } transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); svSetValue (ifcfg, "CONNECTED_MODE", - strcmp (transport_mode, "connected") == 0 ? "yes" : "no", - FALSE); + strcmp (transport_mode, "connected") == 0 ? "yes" : "no"); p_key = nm_setting_infiniband_get_p_key (s_infiniband); if (p_key != -1) { - svSetValue (ifcfg, "PKEY", "yes", FALSE); + svSetValue (ifcfg, "PKEY", "yes"); tmp = g_strdup_printf ("%u", p_key); - svSetValue (ifcfg, "PKEY_ID", tmp, FALSE); + svSetValue (ifcfg, "PKEY_ID", tmp); g_free (tmp); parent = nm_setting_infiniband_get_parent (s_infiniband); if (parent) - svSetValue (ifcfg, "PHYSDEV", parent, FALSE); + svSetValue (ifcfg, "PHYSDEV", parent); } - svSetValue (ifcfg, "TYPE", TYPE_INFINIBAND, FALSE); + svSetValue (ifcfg, "TYPE", TYPE_INFINIBAND); return TRUE; } @@ -1042,14 +1025,13 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } device_mac = nm_setting_wired_get_mac_address (s_wired); - svSetValue (ifcfg, "HWADDR", device_mac, FALSE); + svSetValue (ifcfg, "HWADDR", device_mac); cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); + svSetValue (ifcfg, "MACADDR", cloned_mac); svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask (s_wired), - FALSE); + nm_setting_wired_get_generate_mac_address_mask (s_wired)); svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); @@ -1057,7 +1039,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) char *blacklist_str; blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str, FALSE); + svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str); g_free (blacklist_str); } @@ -1065,7 +1047,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) mtu = nm_setting_wired_get_mtu (s_wired); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); + svSetValue (ifcfg, "MTU", tmp); g_free (tmp); } @@ -1081,24 +1063,24 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) tmp = g_strdup_printf ("%s,%s,%s", s390_subchannels[0], s390_subchannels[1], s390_subchannels[2]); } - svSetValue (ifcfg, "SUBCHANNELS", tmp, FALSE); + svSetValue (ifcfg, "SUBCHANNELS", tmp); g_free (tmp); } svUnsetValue (ifcfg, "NETTYPE"); nettype = nm_setting_wired_get_s390_nettype (s_wired); if (nettype) - svSetValue (ifcfg, "NETTYPE", nettype, FALSE); + svSetValue (ifcfg, "NETTYPE", nettype); svUnsetValue (ifcfg, "PORTNAME"); portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname"); if (portname) - svSetValue (ifcfg, "PORTNAME", portname, FALSE); + svSetValue (ifcfg, "PORTNAME", portname); svUnsetValue (ifcfg, "CTCPROT"); ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot"); if (ctcprot) - svSetValue (ifcfg, "CTCPROT", ctcprot, FALSE); + svSetValue (ifcfg, "CTCPROT", ctcprot); svUnsetValue (ifcfg, "OPTIONS"); num_opts = nm_setting_wired_get_num_s390_options (s_wired); @@ -1116,14 +1098,14 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_string_append_printf (str, "%s=%s", s390_key, s390_val); } if (str->len) - svSetValue (ifcfg, "OPTIONS", str->str, FALSE); + svSetValue (ifcfg, "OPTIONS", str->str); g_string_free (str, TRUE); } wol = nm_setting_wired_get_wake_on_lan (s_wired); wol_password = nm_setting_wired_get_wake_on_lan_password (s_wired); if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) - svSetValueFull (ifcfg, "ETHTOOL_OPTS", "", FALSE); + svSetValueFull (ifcfg, "ETHTOOL_OPTS", ""); else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) svUnsetValue (ifcfg, "ETHTOOL_OPTS"); else { @@ -1149,11 +1131,11 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (wol_password && NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) g_string_append_printf (str, "s sopass %s", wol_password); - svSetValue (ifcfg, "ETHTOOL_OPTS", str->str, FALSE); + svSetValue (ifcfg, "ETHTOOL_OPTS", str->str); g_string_free (str, TRUE); } - svSetValue (ifcfg, "TYPE", TYPE_ETHERNET, FALSE); + svSetValue (ifcfg, "TYPE", TYPE_ETHERNET); return TRUE; } @@ -1195,19 +1177,18 @@ write_wired_for_virtual (NMConnection *connection, shvarFile *ifcfg) has_wired = TRUE; device_mac = nm_setting_wired_get_mac_address (s_wired); - svSetValue (ifcfg, "HWADDR", device_mac, FALSE); + svSetValue (ifcfg, "HWADDR", device_mac); cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); + svSetValue (ifcfg, "MACADDR", cloned_mac); svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask (s_wired), - FALSE); + nm_setting_wired_get_generate_mac_address_mask (s_wired)); mtu = nm_setting_wired_get_mtu (s_wired); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); + svSetValue (ifcfg, "MTU", tmp); g_free (tmp); } else svUnsetValue (ifcfg, "MTU"); @@ -1239,22 +1220,22 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, return FALSE; } - svSetValue (ifcfg, "VLAN", "yes", FALSE); - svSetValue (ifcfg, "TYPE", TYPE_VLAN, FALSE); - svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con), FALSE); - svSetValue (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan), FALSE); + svSetValue (ifcfg, "VLAN", "yes"); + svSetValue (ifcfg, "TYPE", TYPE_VLAN); + svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); + svSetValue (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan)); tmp = g_strdup_printf ("%d", nm_setting_vlan_get_id (s_vlan)); - svSetValue (ifcfg, "VLAN_ID", tmp, FALSE); + svSetValue (ifcfg, "VLAN_ID", tmp); g_free (tmp); vlan_flags = nm_setting_vlan_get_flags (s_vlan); if (vlan_flags & NM_VLAN_FLAG_REORDER_HEADERS) - svSetValue (ifcfg, "REORDER_HDR", "yes", FALSE); + svSetValue (ifcfg, "REORDER_HDR", "yes"); else - svSetValue (ifcfg, "REORDER_HDR", "no", FALSE); + svSetValue (ifcfg, "REORDER_HDR", "no"); - svSetValue (ifcfg, "GVRP", vlan_flags & NM_VLAN_FLAG_GVRP ? "yes" : "no", FALSE); + svSetValue (ifcfg, "GVRP", vlan_flags & NM_VLAN_FLAG_GVRP ? "yes" : "no"); nm_utils_strbuf_init (s_buf, &s_buf_ptr, &s_buf_len); @@ -1263,16 +1244,16 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, if (!NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) nm_utils_strbuf_append (&s_buf_ptr, &s_buf_len, "%sNO_REORDER_HDR", s_buf[0] ? "," : ""); - svSetValue (ifcfg, "VLAN_FLAGS", s_buf, FALSE); + svSetValue (ifcfg, "VLAN_FLAGS", s_buf); - svSetValue (ifcfg, "MVRP", vlan_flags & NM_VLAN_FLAG_MVRP ? "yes" : "no", FALSE); + svSetValue (ifcfg, "MVRP", vlan_flags & NM_VLAN_FLAG_MVRP ? "yes" : "no"); tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); - svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp, FALSE); + svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp); g_free (tmp); tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP); - svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp, FALSE); + svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp); g_free (tmp); svUnsetValue (ifcfg, "HWADDR"); @@ -1305,7 +1286,7 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir return FALSE; } - svSetValue (ifcfg, "DEVICE", iface, FALSE); + svSetValue (ifcfg, "DEVICE", iface); svUnsetValue (ifcfg, "BONDING_OPTS"); num_opts = nm_setting_bond_get_num_options (s_bond); @@ -1325,13 +1306,13 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir } if (str->len) - svSetValue (ifcfg, "BONDING_OPTS", str->str, FALSE); + svSetValue (ifcfg, "BONDING_OPTS", str->str); g_string_free (str, TRUE); } - svSetValue (ifcfg, "TYPE", TYPE_BOND, FALSE); - svSetValue (ifcfg, "BONDING_MASTER", "yes", FALSE); + svSetValue (ifcfg, "TYPE", TYPE_BOND); + svSetValue (ifcfg, "BONDING_MASTER", "yes"); *wired = write_wired_for_virtual (connection, ifcfg); @@ -1359,9 +1340,9 @@ write_team_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, return FALSE; } - svSetValue (ifcfg, "DEVICE", iface, FALSE); + svSetValue (ifcfg, "DEVICE", iface); config = nm_setting_team_get_config (s_team); - svSetValue (ifcfg, "TEAM_CONFIG", config, FALSE); + svSetValue (ifcfg, "TEAM_CONFIG", config); *wired = write_wired_for_virtual (connection, ifcfg); @@ -1427,24 +1408,24 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error return FALSE; } - svSetValue (ifcfg, "DEVICE", iface, FALSE); + svSetValue (ifcfg, "DEVICE", iface); svUnsetValue (ifcfg, "BRIDGING_OPTS"); - svSetValue (ifcfg, "STP", "no", FALSE); + svSetValue (ifcfg, "STP", "no"); svUnsetValue (ifcfg, "DELAY"); mac = nm_setting_bridge_get_mac_address (s_bridge); - svSetValue (ifcfg, "MACADDR", mac, FALSE); + svSetValue (ifcfg, "MACADDR", mac); /* Bridge options */ opts = g_string_sized_new (32); if (nm_setting_bridge_get_stp (s_bridge)) { - svSetValue (ifcfg, "STP", "yes", FALSE); + svSetValue (ifcfg, "STP", "yes"); i = nm_setting_bridge_get_forward_delay (s_bridge); if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_FORWARD_DELAY)) { s = g_strdup_printf ("%u", i); - svSetValue (ifcfg, "DELAY", s, FALSE); + svSetValue (ifcfg, "DELAY", s); g_free (s); } @@ -1480,10 +1461,10 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error } if (opts->len) - svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE); + svSetValue (ifcfg, "BRIDGING_OPTS", opts->str); g_string_free (opts, TRUE); - svSetValue (ifcfg, "TYPE", TYPE_BRIDGE, FALSE); + svSetValue (ifcfg, "TYPE", TYPE_BRIDGE); return TRUE; } @@ -1522,7 +1503,7 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError ** } if (opts->len) - svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE); + svSetValue (ifcfg, "BRIDGING_OPTS", opts->str); g_string_free (opts, TRUE); return TRUE; @@ -1539,7 +1520,7 @@ write_team_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **er return TRUE; config = nm_setting_team_port_get_config (s_port); - svSetValue (ifcfg, "TEAM_PORT_CONFIG", config, FALSE); + svSetValue (ifcfg, "TEAM_PORT_CONFIG", config); return TRUE; } @@ -1550,13 +1531,13 @@ write_dcb_flags (shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags) char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")]; nm_sprintf_buf (prop, "DCB_%s_ENABLE", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL, FALSE); + svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL); nm_sprintf_buf (prop, "DCB_%s_ADVERTISE", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL, FALSE); + svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL); nm_sprintf_buf (prop, "DCB_%s_WILLING", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL, FALSE); + svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL); } static void @@ -1596,7 +1577,7 @@ write_dcb_bool_array (shvarFile *ifcfg, str[8] = 0; for (i = 0; i < 8; i++) str[i] = get_func (s_dcb, i) ? '1' : '0'; - svSetValue (ifcfg, key, str, FALSE); + svSetValue (ifcfg, key, str); } typedef guint (*DcbGetUintFunc) (NMSettingDcb *, guint); @@ -1626,7 +1607,7 @@ write_dcb_uint_array (shvarFile *ifcfg, else g_assert_not_reached (); } - svSetValue (ifcfg, key, str, FALSE); + svSetValue (ifcfg, key, str); } static void @@ -1650,7 +1631,7 @@ write_dcb_percent_array (shvarFile *ifcfg, g_string_append_c (str, ','); g_string_append_printf (str, "%d", get_func (s_dcb, i)); } - svSetValue (ifcfg, key, str->str, FALSE); + svSetValue (ifcfg, key, str->str); g_string_free (str, TRUE); } @@ -1694,13 +1675,13 @@ write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) return TRUE; } - svSetValue (ifcfg, "DCB", "yes", FALSE); + svSetValue (ifcfg, "DCB", "yes"); write_dcb_app (ifcfg, "APP_FCOE", nm_setting_dcb_get_app_fcoe_flags (s_dcb), nm_setting_dcb_get_app_fcoe_priority (s_dcb)); if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) - svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb), FALSE); + svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb)); else svUnsetValue (ifcfg, KEY_DCB_APP_FCOE_MODE); @@ -1740,23 +1721,22 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) const char *v_bridge = NULL; const char *v_team_master = NULL; - svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con), FALSE); - svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con), FALSE); - svSetValue (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con), FALSE); - svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con), FALSE); + svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con)); + svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con)); + svSetValue (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con)); + svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); svSetValue (ifcfg, "ONBOOT", - nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no", - FALSE); + nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no"); i_int = nm_setting_connection_get_autoconnect_priority (s_con); tmp = i_int != NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT ? g_strdup_printf ("%d", i_int) : NULL; - svSetValue (ifcfg, "AUTOCONNECT_PRIORITY", tmp, FALSE); + svSetValue (ifcfg, "AUTOCONNECT_PRIORITY", tmp); g_free (tmp); i_int = nm_setting_connection_get_autoconnect_retries (s_con); tmp = i_int != -1 ? g_strdup_printf ("%d", i_int) : NULL; - svSetValue (ifcfg, "AUTOCONNECT_RETRIES", tmp, FALSE); + svSetValue (ifcfg, "AUTOCONNECT_RETRIES", tmp); g_free (tmp); /* Only save the value for master connections */ @@ -1769,8 +1749,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) autoconnect_slaves = nm_setting_connection_get_autoconnect_slaves (s_con); svSetValue (ifcfg, "AUTOCONNECT_SLAVES", autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES ? "yes" : - autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL, - FALSE); + autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL); } switch (nm_setting_connection_get_lldp (s_con)) { @@ -1783,7 +1762,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) default: tmp = NULL; } - svSetValue (ifcfg, "LLDP", tmp, FALSE); + svSetValue (ifcfg, "LLDP", tmp); /* Permissions */ svUnsetValue (ifcfg, "USERS"); @@ -1803,11 +1782,11 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) if (nm_setting_connection_get_permission (s_con, i, NULL, &puser, NULL)) g_string_append (str, puser); } - svSetValue (ifcfg, "USERS", str->str, FALSE); + svSetValue (ifcfg, "USERS", str->str); g_string_free (str, TRUE); } - svSetValue (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con), FALSE); + svSetValue (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con)); master = nm_setting_connection_get_master (s_con); if (master) { @@ -1822,15 +1801,15 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) } } - svSetValue (ifcfg, "MASTER", v_master, FALSE); - svSetValue (ifcfg, "SLAVE", v_slave, FALSE); - svSetValue (ifcfg, "BRIDGE", v_bridge, FALSE); - svSetValue (ifcfg, "TEAM_MASTER", v_team_master, FALSE); + svSetValue (ifcfg, "MASTER", v_master); + svSetValue (ifcfg, "SLAVE", v_slave); + svSetValue (ifcfg, "BRIDGE", v_bridge); + svSetValue (ifcfg, "TEAM_MASTER", v_team_master); if (nm_streq0 (type, NM_SETTING_TEAM_SETTING_NAME)) - svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM, FALSE); + svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM); else if (master && nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) - svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT, FALSE); + svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT); else svUnsetValue (ifcfg, "DEVICETYPE"); @@ -1852,23 +1831,23 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) if ((uuid = nm_setting_connection_get_secondary (s_con, i)) != NULL) g_string_append (str, uuid); } - svSetValue (ifcfg, "SECONDARY_UUIDS", str->str, FALSE); + svSetValue (ifcfg, "SECONDARY_UUIDS", str->str); g_string_free (str, TRUE); } svUnsetValue (ifcfg, "GATEWAY_PING_TIMEOUT"); if (nm_setting_connection_get_gateway_ping_timeout (s_con)) { tmp = g_strdup_printf ("%" G_GUINT32_FORMAT, nm_setting_connection_get_gateway_ping_timeout (s_con)); - svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", tmp, FALSE); + svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", tmp); g_free (tmp); } switch (nm_setting_connection_get_metered (s_con)) { case NM_METERED_YES: - svSetValue (ifcfg, "CONNECTION_METERED", "yes", FALSE); + svSetValue (ifcfg, "CONNECTION_METERED", "yes"); break; case NM_METERED_NO: - svSetValue (ifcfg, "CONNECTION_METERED", "no", FALSE); + svSetValue (ifcfg, "CONNECTION_METERED", "no"); break; default: svUnsetValue (ifcfg, "CONNECTION_METERED"); @@ -1949,27 +1928,27 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) method = nm_setting_proxy_get_method (s_proxy); switch (method) { case NM_SETTING_PROXY_METHOD_AUTO: - svSetValue (ifcfg, "PROXY_METHOD", "auto", FALSE); + svSetValue (ifcfg, "PROXY_METHOD", "auto"); pac_url = nm_setting_proxy_get_pac_url (s_proxy); if (pac_url) - svSetValue (ifcfg, "PAC_URL", pac_url, FALSE); + svSetValue (ifcfg, "PAC_URL", pac_url); pac_script = nm_setting_proxy_get_pac_script (s_proxy); if (pac_script) - svSetValue (ifcfg, "PAC_SCRIPT", pac_script, FALSE); + svSetValue (ifcfg, "PAC_SCRIPT", pac_script); break; case NM_SETTING_PROXY_METHOD_NONE: - svSetValue (ifcfg, "PROXY_METHOD", "none", FALSE); + svSetValue (ifcfg, "PROXY_METHOD", "none"); break; } browser_only = nm_setting_proxy_get_browser_only (s_proxy); if (browser_only) - svSetValue (ifcfg, "BROWSER_ONLY", "yes", FALSE); + svSetValue (ifcfg, "BROWSER_ONLY", "yes"); else - svSetValue (ifcfg, "BROWSER_ONLY", "no", FALSE); + svSetValue (ifcfg, "BROWSER_ONLY", "no"); return TRUE; } @@ -2051,13 +2030,13 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) - svSetValue (ifcfg, "BOOTPROTO", "dhcp", FALSE); + svSetValue (ifcfg, "BOOTPROTO", "dhcp"); else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) - svSetValue (ifcfg, "BOOTPROTO", "none", FALSE); + svSetValue (ifcfg, "BOOTPROTO", "none"); else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) - svSetValue (ifcfg, "BOOTPROTO", "autoip", FALSE); + svSetValue (ifcfg, "BOOTPROTO", "autoip"); else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) - svSetValue (ifcfg, "BOOTPROTO", "shared", FALSE); + svSetValue (ifcfg, "BOOTPROTO", "shared"); /* Clear out un-numbered IP address fields */ svUnsetValue (ifcfg, "IPADDR"); @@ -2104,10 +2083,10 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) gw_key = g_strdup_printf ("GATEWAY%d", n); } - svSetValue (ifcfg, addr_key, nm_ip_address_get_address (addr), FALSE); + svSetValue (ifcfg, addr_key, nm_ip_address_get_address (addr)); tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); - svSetValue (ifcfg, prefix_key, tmp, FALSE); + svSetValue (ifcfg, prefix_key, tmp); g_free (tmp); svUnsetValue (ifcfg, netmask_key); @@ -2138,7 +2117,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (gw_key); } - svSetValue (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4), FALSE); + svSetValue (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4)); num = nm_setting_ip_config_get_num_dns (s_ip4); for (i = 0; i < 254; i++) { @@ -2150,7 +2129,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, addr_key); else { dns = nm_setting_ip_config_get_dns (s_ip4, i); - svSetValue (ifcfg, addr_key, dns, FALSE); + svSetValue (ifcfg, addr_key, dns); } g_free (addr_key); } @@ -2163,60 +2142,55 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_string_append_c (searches, ' '); g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip4, i)); } - svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); + svSetValue (ifcfg, "DOMAIN", searches->str); g_string_free (searches, TRUE); } else svUnsetValue (ifcfg, "DOMAIN"); /* DEFROUTE; remember that it has the opposite meaning from never-default */ svSetValue (ifcfg, "DEFROUTE", - nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes"); svUnsetValue (ifcfg, "PEERDNS"); svUnsetValue (ifcfg, "PEERROUTES"); svUnsetValue (ifcfg, "DHCP_CLIENT_ID"); if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "PEERDNS", - nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes"); svSetValue (ifcfg, "PEERROUTES", - nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes"); value = nm_setting_ip_config_get_dhcp_hostname (s_ip4); if (value) - svSetValue (ifcfg, "DHCP_HOSTNAME", value, FALSE); + svSetValue (ifcfg, "DHCP_HOSTNAME", value); value = nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)); if (value) - svSetValue (ifcfg, "DHCP_FQDN", value, FALSE); + svSetValue (ifcfg, "DHCP_FQDN", value); /* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly * in that case, because it is NM-specific variable */ svSetValue (ifcfg, "DHCP_SEND_HOSTNAME", - nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no", - FALSE); + nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no"); value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)); if (value) - svSetValue (ifcfg, "DHCP_CLIENT_ID", value, FALSE); + svSetValue (ifcfg, "DHCP_CLIENT_ID", value); timeout = nm_setting_ip_config_get_dhcp_timeout (s_ip4); tmp = timeout ? g_strdup_printf ("%d", timeout) : NULL; - svSetValue (ifcfg, "IPV4_DHCP_TIMEOUT", tmp, FALSE); + svSetValue (ifcfg, "IPV4_DHCP_TIMEOUT", tmp); g_free (tmp); } svSetValue (ifcfg, "IPV4_FAILURE_FATAL", - nm_setting_ip_config_get_may_fail (s_ip4) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_may_fail (s_ip4) ? "no" : "yes"); route_metric = nm_setting_ip_config_get_route_metric (s_ip4); tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; - svSetValue (ifcfg, "IPV4_ROUTE_METRIC", tmp, FALSE); + svSetValue (ifcfg, "IPV4_ROUTE_METRIC", tmp); g_free (tmp); /* Static routes - route- file */ @@ -2259,14 +2233,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } else { route = nm_setting_ip_config_get_route (s_ip4, i); - svSetValue (routefile, addr_key, nm_ip_route_get_dest (route), FALSE); + svSetValue (routefile, addr_key, nm_ip_route_get_dest (route)); memset (buf, 0, sizeof (buf)); netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf)); - svSetValue (routefile, netmask_key, &buf[0], FALSE); + svSetValue (routefile, netmask_key, &buf[0]); - svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route), FALSE); + svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route)); memset (buf, 0, sizeof (buf)); metric = nm_ip_route_get_metric (route); @@ -2274,7 +2248,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (routefile, metric_key); else { tmp = g_strdup_printf ("%u", (guint32) metric); - svSetValue (routefile, metric_key, tmp, FALSE); + svSetValue (routefile, metric_key, tmp); g_free (tmp); } } @@ -2300,7 +2274,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (timeout < 0) svUnsetValue (ifcfg, "ARPING_WAIT"); else if (timeout == 0) - svSetValue (ifcfg, "ARPING_WAIT", "0", FALSE); + svSetValue (ifcfg, "ARPING_WAIT", "0"); else { /* Round the value up to next integer */ svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1); @@ -2387,13 +2361,13 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) ifcfg = svCreateFile (path); g_free (path); - svSetValue (ifcfg, "DEVICE", label, FALSE); + svSetValue (ifcfg, "DEVICE", label); addr = nm_setting_ip_config_get_address (s_ip4, i); - svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr), FALSE); + svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr)); tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); - svSetValue (ifcfg, "PREFIX", tmp, FALSE); + svSetValue (ifcfg, "PREFIX", tmp); g_free (tmp); svWriteFile (ifcfg, 0644, NULL); @@ -2494,31 +2468,31 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) value = nm_setting_ip_config_get_method (s_ip6); g_assert (value); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { - svSetValue (ifcfg, "IPV6INIT", "no", FALSE); + svSetValue (ifcfg, "IPV6INIT", "no"); svUnsetValue (ifcfg, "DHCPV6C"); return TRUE; } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "yes", FALSE); + svSetValue (ifcfg, "IPV6INIT", "yes"); + svSetValue (ifcfg, "IPV6_AUTOCONF", "yes"); svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { const char *hostname; - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", "yes", FALSE); + svSetValue (ifcfg, "IPV6INIT", "yes"); + svSetValue (ifcfg, "IPV6_AUTOCONF", "no"); + svSetValue (ifcfg, "DHCPV6C", "yes"); hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); if (hostname) - svSetValue (ifcfg, "DHCP_HOSTNAME", hostname, FALSE); + svSetValue (ifcfg, "DHCP_HOSTNAME", hostname); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); + svSetValue (ifcfg, "IPV6INIT", "yes"); + svSetValue (ifcfg, "IPV6_AUTOCONF", "no"); svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); + svSetValue (ifcfg, "IPV6INIT", "yes"); + svSetValue (ifcfg, "IPV6_AUTOCONF", "no"); svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); + svSetValue (ifcfg, "IPV6INIT", "yes"); svUnsetValue (ifcfg, "DHCPV6C"); /* TODO */ } @@ -2541,9 +2515,9 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) nm_ip_address_get_address (addr), nm_ip_address_get_prefix (addr)); } - svSetValue (ifcfg, "IPV6ADDR", ip_str1->str, FALSE); - svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str, FALSE); - svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6), FALSE); + svSetValue (ifcfg, "IPV6ADDR", ip_str1->str); + svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str); + svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6)); g_string_free (ip_str1, TRUE); g_string_free (ip_str2, TRUE); @@ -2558,7 +2532,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, addr_key); else { dns = nm_setting_ip_config_get_dns (s_ip6, i); - svSetValue (ifcfg, addr_key, dns, FALSE); + svSetValue (ifcfg, addr_key, dns); } g_free (addr_key); } @@ -2567,14 +2541,14 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) num = nm_setting_ip_config_get_num_dns_searches (s_ip6); if (num > 0) { char *ip4_domains; - ip4_domains = svGetValue (ifcfg, "DOMAIN", FALSE); + ip4_domains = svGetValue (ifcfg, "DOMAIN"); searches = g_string_new (ip4_domains); for (i = 0; i < num; i++) { if (searches->len > 0) g_string_append_c (searches, ' '); g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i)); } - svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); + svSetValue (ifcfg, "DOMAIN", searches->str); g_string_free (searches, TRUE); g_free (ip4_domains); } @@ -2582,29 +2556,26 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* handle IPV6_DEFROUTE */ /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ if (nm_setting_ip_config_get_never_default(s_ip6)) - svSetValue (ifcfg, "IPV6_DEFROUTE", "no", FALSE); + svSetValue (ifcfg, "IPV6_DEFROUTE", "no"); else - svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE); + svSetValue (ifcfg, "IPV6_DEFROUTE", "yes"); svUnsetValue (ifcfg, "IPV6_PEERDNS"); svUnsetValue (ifcfg, "IPV6_PEERROUTES"); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "IPV6_PEERDNS", - nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes"); svSetValue (ifcfg, "IPV6_PEERROUTES", - nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes"); } svSetValue (ifcfg, "IPV6_FAILURE_FATAL", - nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes", - FALSE); + nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes"); route_metric = nm_setting_ip_config_get_route_metric (s_ip6); tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; - svSetValue (ifcfg, "IPV6_ROUTE_METRIC", tmp, FALSE); + svSetValue (ifcfg, "IPV6_ROUTE_METRIC", tmp); g_free (tmp); /* IPv6 Privacy Extensions */ @@ -2612,14 +2583,14 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP"); switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){ case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: - svSetValue (ifcfg, "IPV6_PRIVACY", "no", FALSE); + svSetValue (ifcfg, "IPV6_PRIVACY", "no"); break; case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: - svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041", FALSE); - svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", "yes", FALSE); + svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041"); + svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", "yes"); break; case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: - svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041", FALSE); + svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041"); break; default: break; @@ -2630,7 +2601,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (addr_gen_mode != NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) { tmp = nm_utils_enum_to_str (nm_setting_ip6_config_addr_gen_mode_get_type (), addr_gen_mode); - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", tmp, FALSE); + svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", tmp); g_free (tmp); } else { svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); @@ -2638,7 +2609,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* IPv6 tokenized interface identifier */ value = nm_setting_ip6_config_get_token (NM_SETTING_IP6_CONFIG (s_ip6)); - svSetValue (ifcfg, "IPV6_TOKEN", value, FALSE); + svSetValue (ifcfg, "IPV6_TOKEN", value); priority = nm_setting_ip_config_get_dns_priority (s_ip6); if (priority) @@ -2715,7 +2686,7 @@ write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) g_string_append_c (value, ' '); g_string_append (value, array->pdata[i]); } - svSetValueFull (ifcfg, "RES_OPTIONS", value->str, FALSE); + svSetValueFull (ifcfg, "RES_OPTIONS", value->str); g_string_free (value, TRUE); } else svUnsetValue (ifcfg, "RES_OPTIONS"); diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index cc0eefeba..3e2e24712 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -328,7 +328,7 @@ find_line (shvarFile *s, const char *key) * svGetValue() will never return an empty value (but %NULL instead). * svGetValueFull() will return empty values if that is the value for the @key. */ char * -svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) +svGetValueFull (shvarFile *s, const char *key) { const char *line_val; char *value; @@ -341,8 +341,7 @@ svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) return NULL; value = g_strchomp (g_strdup (line_val)); - if (!verbatim) - svUnescape (value); + svUnescape (value); return value; } @@ -351,11 +350,11 @@ svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) * be freed by the caller. */ char * -svGetValue (shvarFile *s, const char *key, gboolean verbatim) +svGetValue (shvarFile *s, const char *key) { char *value; - value = svGetValueFull (s, key, verbatim); + value = svGetValueFull (s, key); if (value && !*value) { g_free (value); return NULL; @@ -377,7 +376,7 @@ svGetValueBoolean (shvarFile *s, const char *key, gint fallback) { gs_free char *tmp = NULL; - tmp = svGetValue (s, key, FALSE); + tmp = svGetValue (s, key); return svParseBoolean (tmp, fallback); } @@ -398,7 +397,7 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m gint64 result; int errsv; - tmp = svGetValueFull (s, key, FALSE); + tmp = svGetValueFull (s, key); if (!tmp) { errno = 0; return fallback; @@ -418,23 +417,16 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m /* Same as svSetValue() but it preserves empty @value -- contrary to * svSetValue() for which "" effectively means to remove the value. */ void -svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim) +svSetValueFull (shvarFile *s, const char *key, const char *value) { gs_free char *newval_free = NULL; gs_free char *oldval = NULL; - const char *newval; char *keyValue; g_return_if_fail (s != NULL); g_return_if_fail (key != NULL); - /* value may be NULL */ - if (!value || verbatim) - newval = value; - else - newval = svEscape (value, &newval_free); - - if (!newval) { + if (!value) { /* delete value */ if (find_line (s, key)) { /* delete line */ @@ -446,9 +438,10 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba return; } - oldval = svGetValueFull (s, key, FALSE); + value = svEscape (value, &newval_free); + oldval = svGetValueFull (s, key); - keyValue = g_strdup_printf ("%s=%s", key, newval); + keyValue = g_strdup_printf ("%s=%s", key, value); if (!oldval) { /* append line */ s->lineList = g_list_append (s->lineList, keyValue); @@ -456,7 +449,7 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba return; } - if (strcmp (oldval, newval) != 0) { + if (strcmp (oldval, value) != 0) { /* change line */ if (s->current) { g_free (s->current->data); @@ -474,9 +467,9 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba * to the bottom of the file. */ void -svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim) +svSetValue (shvarFile *s, const char *key, const char *value) { - svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim); + svSetValueFull (s, key, value && value[0] ? value : NULL); } void @@ -485,14 +478,13 @@ svSetValueInt64 (shvarFile *s, const char *key, gint64 value) char buf[NM_DECIMAL_STR_MAX (value)]; svSetValueFull (s, key, - nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value), - TRUE); + nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value)); } void svUnsetValue (shvarFile *s, const char *key) { - svSetValueFull (s, key, NULL, FALSE); + svSetValueFull (s, key, NULL); } /*****************************************************************************/ diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 14b2c5e8b..d5a46a4bb 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -45,8 +45,8 @@ shvarFile *svOpenFile (const char *name, GError **error); * pointing at the line containing the value. The char* returned MUST * be freed by the caller. */ -char *svGetValue (shvarFile *s, const char *key, gboolean verbatim); -char *svGetValueFull (shvarFile *s, const char *key, gboolean verbatim); +char *svGetValue (shvarFile *s, const char *key); +char *svGetValueFull (shvarFile *s, const char *key); gint svParseBoolean (const char *value, gint def); @@ -63,8 +63,8 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g * the key=value pair after that line. Otherwise, prepend the pair * to the top of the file. */ -void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim); -void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim); +void svSetValue (shvarFile *s, const char *key, const char *value); +void svSetValueFull (shvarFile *s, const char *key, const char *value); void svSetValueInt64 (shvarFile *s, const char *key, gint64 value); void svUnsetValue (shvarFile *s, const char *key); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index ee27f194e..5000c2c7e 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -1789,7 +1789,7 @@ test_clear_master (void) g_assert_no_error (error); g_assert (f); - val = svGetValue (f, "BRIDGE", FALSE); + val = svGetValue (f, "BRIDGE"); g_assert (!val); svCloseFile (f); } @@ -3014,7 +3014,7 @@ test_write_wifi_hidden (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "SSID_HIDDEN", FALSE); + val = svGetValue (f, "SSID_HIDDEN"); g_assert (val); g_assert_cmpstr (val, ==, "yes"); g_free (val); @@ -3113,7 +3113,7 @@ test_write_wifi_mac_random (gconstpointer user_data) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "MAC_ADDRESS_RANDOMIZATION", FALSE); + val = svGetValue (f, "MAC_ADDRESS_RANDOMIZATION"); g_assert_cmpstr (val, ==, write_expected); g_free (val); svCloseFile (f); @@ -3177,7 +3177,7 @@ test_write_wired_wake_on_lan (void) g_assert (f); /* re-read the file to check that the key was written. */ - val = svGetValue (f, "ETHTOOL_OPTS", FALSE); + val = svGetValue (f, "ETHTOOL_OPTS"); g_assert (val); g_assert (strstr (val, "wol")); g_assert (strstr (val, "sopass 00:00:00:11:22:33")); @@ -3266,7 +3266,7 @@ test_write_wifi_band_a (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "BAND", FALSE); + val = svGetValue (f, "BAND"); g_assert (val); g_assert_cmpstr (val, ==, "a"); g_free (val); @@ -3975,7 +3975,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) g_assert_no_error (error); g_assert (ifcfg); - written_ifcfg_gateway = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE); + written_ifcfg_gateway = svGetValue (ifcfg, "IPV6_DEFAULTGW"); svCloseFile (ifcfg); } @@ -4499,15 +4499,15 @@ test_write_wired_aliases (void) /* Create some pre-existing alias files, to make sure they get overwritten / deleted. */ ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":2"); - svSetValue (ifcfg, "DEVICE", "alias0:2", FALSE); - svSetValue (ifcfg, "IPADDR", "192.168.1.2", FALSE); + svSetValue (ifcfg, "DEVICE", "alias0:2"); + svSetValue (ifcfg, "IPADDR", "192.168.1.2"); svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":2", G_FILE_TEST_EXISTS)); ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":5"); - svSetValue (ifcfg, "DEVICE", "alias0:5", FALSE); - svSetValue (ifcfg, "IPADDR", "192.168.1.5", FALSE); + svSetValue (ifcfg, "DEVICE", "alias0:5"); + svSetValue (ifcfg, "IPADDR", "192.168.1.5"); svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); @@ -4628,41 +4628,41 @@ test_write_gateway (void) g_assert (f); /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ - val = svGetValue (f, "IPADDR", FALSE); + val = svGetValue (f, "IPADDR"); g_assert (val); g_assert_cmpstr (val, ==, "1.1.1.3"); g_free (val); - val = svGetValue (f, "IPADDR1", FALSE); + val = svGetValue (f, "IPADDR1"); g_assert (val); g_assert_cmpstr (val, ==, "2.2.2.5"); g_free (val); - val = svGetValue (f, "IPADDR0", FALSE); + val = svGetValue (f, "IPADDR0"); g_assert (val == NULL); - val = svGetValue (f, "PREFIX", FALSE); + val = svGetValue (f, "PREFIX"); g_assert (val); g_assert_cmpstr (val, ==, "24"); g_free (val); - val = svGetValue (f, "PREFIX1", FALSE); + val = svGetValue (f, "PREFIX1"); g_assert (val); g_assert_cmpstr (val, ==, "24"); g_free (val); - val = svGetValue (f, "PREFIX0", FALSE); + val = svGetValue (f, "PREFIX0"); g_assert (val == NULL); - val = svGetValue (f, "GATEWAY", FALSE); + val = svGetValue (f, "GATEWAY"); g_assert (val); g_assert_cmpstr (val, ==, "1.1.1.254"); g_free (val); - val = svGetValue (f, "GATEWAY0", FALSE); + val = svGetValue (f, "GATEWAY0"); g_assert (val == NULL); - val = svGetValue (f, "GATEWAY1", FALSE); + val = svGetValue (f, "GATEWAY1"); g_assert (val == NULL); svCloseFile (f); @@ -4756,10 +4756,8 @@ test_write_wifi_open (void) g_assert_no_error (error); g_assert (ifcfg != NULL); - tmp = svGetValue (ifcfg, "ESSID", TRUE); - g_assert (tmp); - - g_assert (strncmp (tmp, "\"\"", 2) != 0); + tmp = svGetValue (ifcfg, "ESSID"); + g_assert_cmpstr (tmp, ==, "Test SSID"); g_free (tmp); svCloseFile (ifcfg); @@ -6508,11 +6506,11 @@ test_write_wifi_dynamic_wep_leap (void) ifcfg = svOpenFile (testfile, &error); g_assert_no_error (error); g_assert (ifcfg); - tmp = svGetValue (ifcfg, "SECURITYMODE", FALSE); + tmp = svGetValue (ifcfg, "SECURITYMODE"); g_assert_cmpstr (tmp, ==, NULL); g_free (tmp); - tmp = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE); + tmp = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS"); g_assert_cmpstr (tmp, ==, "LEAP"); g_free (tmp); @@ -6674,13 +6672,13 @@ test_write_wired_ctc_dhcp (void) g_assert_no_error (error); g_assert (ifcfg); - tmp = svGetValue (ifcfg, "CTCPROT", TRUE); + tmp = svGetValue (ifcfg, "CTCPROT"); g_assert (tmp); g_assert_cmpstr (tmp, ==, "0"); g_free (tmp); /* And that it's not in the generic OPTIONS string */ - tmp = svGetValue (ifcfg, "OPTIONS", TRUE); + tmp = svGetValue (ifcfg, "OPTIONS"); g_assert (tmp == NULL); g_free (tmp); @@ -8423,7 +8421,7 @@ test_write_fcoe_mode (gconstpointer user_data) g_assert_no_error (error); g_assert (ifcfg); - written_mode = svGetValue (ifcfg, "DCB_APP_FCOE_MODE", FALSE); + written_mode = svGetValue (ifcfg, "DCB_APP_FCOE_MODE"); svCloseFile (ifcfg); g_assert_cmpstr (written_mode, ==, expected_mode); g_free (written_mode); @@ -8500,7 +8498,6 @@ test_write_team_master (void) char *uuid, *testfile = NULL, *val; GError *error = NULL; const char *expected_config = "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"; - const char *escaped_expected_config = "\"{ \\\"device\\\": \\\"team0\\\", \\\"link_watch\\\": { \\\"name\\\": \\\"ethtool\\\" } }\""; shvarFile *f; connection = nm_simple_connection_new (); @@ -8561,13 +8558,13 @@ test_write_team_master (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "DEVICETYPE", FALSE); + val = svGetValue (f, "DEVICETYPE"); g_assert (val); g_assert_cmpstr (val, ==, "Team"); g_free (val); - val = svGetValue (f, "TEAM_CONFIG", TRUE); + val = svGetValue (f, "TEAM_CONFIG"); g_assert (val); - g_assert_cmpstr (val, ==, escaped_expected_config); + g_assert_cmpstr (val, ==, expected_config); g_free (val); svCloseFile (f); @@ -8617,7 +8614,6 @@ test_write_team_port (void) char *uuid, *val; GError *error = NULL; const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; - const char *escaped_expected_config = "\"{ \\\"p4p1\\\": { \\\"prio\\\": -10, \\\"sticky\\\": true } }\""; shvarFile *f; connection = nm_simple_connection_new (); @@ -8656,18 +8652,16 @@ test_write_team_port (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "TYPE", FALSE); + val = svGetValue (f, "TYPE"); g_assert (!val); - val = svGetValue (f, "DEVICETYPE", FALSE); + val = svGetValue (f, "DEVICETYPE"); g_assert (val); g_assert_cmpstr (val, ==, "TeamPort"); g_free (val); - val = svGetValue (f, "TEAM_PORT_CONFIG", TRUE); - g_assert (val); - g_assert_cmpstr (val, ==, escaped_expected_config); + val = svGetValue (f, "TEAM_PORT_CONFIG"); + g_assert_cmpstr (val, ==, expected_config); g_free (val); - val = svGetValue (f, "TEAM_MASTER", TRUE); - g_assert (val); + val = svGetValue (f, "TEAM_MASTER"); g_assert_cmpstr (val, ==, "team0"); g_free (val); svCloseFile (f); From 2a3b238d493fcd9a5049727e18f7e0e9dac5b14e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 12:58:34 +0100 Subject: [PATCH 17/39] ifcfg-rh: add and use svSetValueBoolean() --- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 42 ++++++------------- src/settings/plugins/ifcfg-rh/shvar.c | 6 +++ src/settings/plugins/ifcfg-rh/shvar.h | 1 + 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index b302b6e7b..e8cf3d231 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -983,8 +983,7 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e } transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); - svSetValue (ifcfg, "CONNECTED_MODE", - strcmp (transport_mode, "connected") == 0 ? "yes" : "no"); + svSetValueBoolean (ifcfg, "CONNECTED_MODE", nm_streq (transport_mode, "connected")); p_key = nm_setting_infiniband_get_p_key (s_infiniband); if (p_key != -1) { @@ -1230,12 +1229,8 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, g_free (tmp); vlan_flags = nm_setting_vlan_get_flags (s_vlan); - if (vlan_flags & NM_VLAN_FLAG_REORDER_HEADERS) - svSetValue (ifcfg, "REORDER_HDR", "yes"); - else - svSetValue (ifcfg, "REORDER_HDR", "no"); - - svSetValue (ifcfg, "GVRP", vlan_flags & NM_VLAN_FLAG_GVRP ? "yes" : "no"); + svSetValueBoolean (ifcfg, "REORDER_HDR", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)); + svSetValueBoolean (ifcfg, "GVRP", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_GVRP)); nm_utils_strbuf_init (s_buf, &s_buf_ptr, &s_buf_len); @@ -1246,7 +1241,7 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, svSetValue (ifcfg, "VLAN_FLAGS", s_buf); - svSetValue (ifcfg, "MVRP", vlan_flags & NM_VLAN_FLAG_MVRP ? "yes" : "no"); + svSetValueBoolean (ifcfg, "MVRP", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_MVRP)); tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp); @@ -1410,7 +1405,7 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error svSetValue (ifcfg, "DEVICE", iface); svUnsetValue (ifcfg, "BRIDGING_OPTS"); - svSetValue (ifcfg, "STP", "no"); + svSetValueBoolean (ifcfg, "STP", FALSE); svUnsetValue (ifcfg, "DELAY"); mac = nm_setting_bridge_get_mac_address (s_bridge); @@ -1725,8 +1720,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con)); svSetValue (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con)); svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); - svSetValue (ifcfg, "ONBOOT", - nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no"); + svSetValueBoolean (ifcfg, "ONBOOT", nm_setting_connection_get_autoconnect (s_con)); i_int = nm_setting_connection_get_autoconnect_priority (s_con); tmp = i_int != NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT @@ -1740,7 +1734,6 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) g_free (tmp); /* Only save the value for master connections */ - svUnsetValue (ifcfg, "AUTOCONNECT_SLAVES"); type = nm_setting_connection_get_connection_type (s_con); if ( !g_strcmp0 (type, NM_SETTING_BOND_SETTING_NAME) || !g_strcmp0 (type, NM_SETTING_TEAM_SETTING_NAME) @@ -1750,7 +1743,8 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) svSetValue (ifcfg, "AUTOCONNECT_SLAVES", autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES ? "yes" : autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL); - } + } else + svUnsetValue (ifcfg, "AUTOCONNECT_SLAVES"); switch (nm_setting_connection_get_lldp (s_con)) { case NM_SETTING_CONNECTION_LLDP_ENABLE_RX: @@ -1915,7 +1909,6 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) NMSettingProxy *s_proxy; NMSettingProxyMethod method; const char *pac_url, *pac_script; - gboolean browser_only; s_proxy = nm_connection_get_setting_proxy (connection); if (!s_proxy) @@ -1944,11 +1937,7 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) break; } - browser_only = nm_setting_proxy_get_browser_only (s_proxy); - if (browser_only) - svSetValue (ifcfg, "BROWSER_ONLY", "yes"); - else - svSetValue (ifcfg, "BROWSER_ONLY", "no"); + svSetValueBoolean (ifcfg, "BROWSER_ONLY", nm_setting_proxy_get_browser_only (s_proxy)); return TRUE; } @@ -2148,18 +2137,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, "DOMAIN"); /* DEFROUTE; remember that it has the opposite meaning from never-default */ - svSetValue (ifcfg, "DEFROUTE", - nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes"); + svSetValueBoolean (ifcfg, "DEFROUTE", !nm_setting_ip_config_get_never_default (s_ip4)); svUnsetValue (ifcfg, "PEERDNS"); svUnsetValue (ifcfg, "PEERROUTES"); svUnsetValue (ifcfg, "DHCP_CLIENT_ID"); if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "PEERDNS", - nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes"); - - svSetValue (ifcfg, "PEERROUTES", - nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes"); + svSetValueBoolean (ifcfg, "PEERDNS", !nm_setting_ip_config_get_ignore_auto_dns (s_ip4)); + svSetValueBoolean (ifcfg, "PEERROUTES", !nm_setting_ip_config_get_ignore_auto_routes (s_ip4)); value = nm_setting_ip_config_get_dhcp_hostname (s_ip4); if (value) @@ -2185,8 +2170,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (tmp); } - svSetValue (ifcfg, "IPV4_FAILURE_FATAL", - nm_setting_ip_config_get_may_fail (s_ip4) ? "no" : "yes"); + svSetValueBoolean (ifcfg, "IPV4_FAILURE_FATAL", !nm_setting_ip_config_get_may_fail (s_ip4)); route_metric = nm_setting_ip_config_get_route_metric (s_ip4); tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 3e2e24712..fbc5d1f9e 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -481,6 +481,12 @@ svSetValueInt64 (shvarFile *s, const char *key, gint64 value) nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value)); } +void +svSetValueBoolean (shvarFile *s, const char *key, gboolean value) +{ + svSetValueFull (s, key, value ? "yes" : "no"); +} + void svUnsetValue (shvarFile *s, const char *key) { diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index d5a46a4bb..9daa004d1 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -65,6 +65,7 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g */ void svSetValue (shvarFile *s, const char *key, const char *value); void svSetValueFull (shvarFile *s, const char *key, const char *value); +void svSetValueBoolean (shvarFile *s, const char *key, gboolean value); void svSetValueInt64 (shvarFile *s, const char *key, gint64 value); void svUnsetValue (shvarFile *s, const char *key); From 917ab8334b5ece09027d692d0e693e6a3ffa423a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 13:10:55 +0100 Subject: [PATCH 18/39] ifcfg-rh/trivial: rename svGetValue() and related svGetValue() had the meaning of returning a string, except the empty word "" was coerced to NULL. svGetValueFull() had the meaing of returing the value as string, including the empty word. Rename those functions to better express what they do. Same for svSetValue*(). --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 312 ++++++------- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 412 +++++++++--------- src/settings/plugins/ifcfg-rh/shvar.c | 35 +- src/settings/plugins/ifcfg-rh/shvar.h | 4 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 62 +-- 5 files changed, 412 insertions(+), 413 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 61b273c63..140e7be0a 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -97,7 +97,7 @@ make_connection_name (shvarFile *ifcfg, char *full_name = NULL, *name; /* If the ifcfg file already has a NAME, always use that */ - name = svGetValue (ifcfg, "NAME"); + name = svGetValueString (ifcfg, "NAME"); if (name && strlen (name)) return name; @@ -142,13 +142,13 @@ make_connection_setting (const char *file, g_free (new_id); /* Try for a UUID key before falling back to hashing the file name */ - uuid = svGetValue (ifcfg, "UUID"); + uuid = svGetValueString (ifcfg, "UUID"); if (!uuid || !strlen (uuid)) { g_free (uuid); uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } - stable_id = svGetValue (ifcfg, "STABLE_ID"); + stable_id = svGetValueString (ifcfg, "STABLE_ID"); g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, type, @@ -157,7 +157,7 @@ make_connection_setting (const char *file, NULL); g_free (uuid); - value = svGetValue (ifcfg, "DEVICE"); + value = svGetValueString (ifcfg, "DEVICE"); if (value) { if (nm_utils_iface_valid_name (value)) { g_object_set (s_con, @@ -168,7 +168,7 @@ make_connection_setting (const char *file, g_free (value); } - value = svGetValue (ifcfg, "LLDP"); + value = svGetValueString (ifcfg, "LLDP"); if (!g_strcmp0 (value, "rx")) lldp = NM_SETTING_CONNECTION_LLDP_ENABLE_RX; else @@ -192,7 +192,7 @@ make_connection_setting (const char *file, NM_SETTING_CONNECTION_LLDP, lldp, NULL); - value = svGetValue (ifcfg, "USERS"); + value = svGetValueString (ifcfg, "USERS"); if (value) { char **items, **iter; @@ -208,7 +208,7 @@ make_connection_setting (const char *file, } - zone = svGetValue (ifcfg, "ZONE"); + zone = svGetValueString (ifcfg, "ZONE"); if (!zone || !strlen (zone)) { g_free (zone); zone = NULL; @@ -216,7 +216,7 @@ make_connection_setting (const char *file, g_object_set (s_con, NM_SETTING_CONNECTION_ZONE, zone, NULL); g_free (zone); - value = svGetValue (ifcfg, "SECONDARY_UUIDS"); + value = svGetValueString (ifcfg, "SECONDARY_UUIDS"); if (value) { char **items, **iter; @@ -231,7 +231,7 @@ make_connection_setting (const char *file, g_strfreev (items); } - value = svGetValue (ifcfg, "BRIDGE"); + value = svGetValueString (ifcfg, "BRIDGE"); if (value) { const char *old_value; @@ -246,7 +246,7 @@ make_connection_setting (const char *file, g_free (value); } - value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT"); + value = svGetValueString (ifcfg, "GATEWAY_PING_TIMEOUT"); if (value) { gint64 tmp; @@ -286,7 +286,7 @@ read_ip4_address (shvarFile *ifcfg, *out_addr = NULL; - value = svGetValue (ifcfg, tag); + value = svGetValueString (ifcfg, tag); if (!value) return TRUE; @@ -321,7 +321,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) char *value; tag = get_numbered_tag ("IPADDR", i); - value = svGetValue (ifcfg, tag); + value = svGetValueString (ifcfg, tag); g_free (tag); if (value) { g_free (value); @@ -330,7 +330,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) } tag = get_numbered_tag ("PREFIX", i); - value = svGetValue (ifcfg, tag); + value = svGetValueString (ifcfg, tag); g_free(tag); if (value) { g_free (value); @@ -339,7 +339,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) } tag = get_numbered_tag ("NETMASK", i); - value = svGetValue (ifcfg, tag); + value = svGetValueString (ifcfg, tag); g_free(tag); if (value) { g_free (value); @@ -396,7 +396,7 @@ read_full_ip4_address (shvarFile *ifcfg, } /* Prefix */ - value = svGetValue (ifcfg, prefix_tag); + value = svGetValueString (ifcfg, prefix_tag); if (value) { prefix = _nm_utils_ascii_str_to_int64 (value, 10, 0, 32, -1); if (prefix < 0) { @@ -474,7 +474,7 @@ read_one_ip4_route (shvarFile *ifcfg, if (!dest) { /* Check whether IP is missing or 0.0.0.0 */ char *val; - val = svGetValue (ifcfg, ip_tag); + val = svGetValueString (ifcfg, ip_tag); if (!val) { *out_route = NULL; success = TRUE; /* missing route = success */ @@ -509,7 +509,7 @@ read_one_ip4_route (shvarFile *ifcfg, } /* Metric */ - value = svGetValue (ifcfg, metric_tag); + value = svGetValueString (ifcfg, metric_tag); if (value) { metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); if (metric < 0) { @@ -910,7 +910,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error) char *value = NULL; NMSettingProxyMethod method; - value = svGetValue (ifcfg, "PROXY_METHOD"); + value = svGetValueString (ifcfg, "PROXY_METHOD"); if (!value) return NULL; @@ -928,14 +928,14 @@ make_proxy_setting (shvarFile *ifcfg, GError **error) NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_AUTO, NULL); - value = svGetValue (ifcfg, "PAC_URL"); + value = svGetValueString (ifcfg, "PAC_URL"); if (value) { value = g_strstrip (value); g_object_set (s_proxy, NM_SETTING_PROXY_PAC_URL, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "PAC_SCRIPT"); + value = svGetValueString (ifcfg, "PAC_SCRIPT"); if (value) { value = g_strstrip (value); g_object_set (s_proxy, NM_SETTING_PROXY_PAC_SCRIPT, value, NULL); @@ -950,7 +950,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error) break; } - value = svGetValue (ifcfg, "BROWSER_ONLY"); + value = svGetValueString (ifcfg, "BROWSER_ONLY"); if (value) { if (!g_ascii_strcasecmp (value, "yes")) g_object_set (s_proxy, NM_SETTING_PROXY_BROWSER_ONLY, TRUE, NULL); @@ -993,9 +993,9 @@ make_ip4_setting (shvarFile *ifcfg, char *gatewaydev; /* Get the connection ifcfg device name and the global gateway device */ - value = svGetValue (ifcfg, "DEVICE"); - gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV"); - dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS"); + value = svGetValueString (ifcfg, "DEVICE"); + gatewaydev = svGetValueString (network_ifcfg, "GATEWAYDEV"); + dns_options = svGetValue (network_ifcfg, "RES_OPTIONS"); /* If there was a global gateway device specified, then only connections * for that device can be the default connection. @@ -1008,7 +1008,7 @@ make_ip4_setting (shvarFile *ifcfg, svCloseFile (network_ifcfg); } - value = svGetValue (ifcfg, "BOOTPROTO"); + value = svGetValueString (ifcfg, "BOOTPROTO"); if (!value || !*value || !g_ascii_strcasecmp (value, "none")) { if (is_any_ip4_address_defined (ifcfg, NULL)) @@ -1070,12 +1070,12 @@ make_ip4_setting (shvarFile *ifcfg, /* Handle DHCP settings */ if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - value = svGetValue (ifcfg, "DHCP_HOSTNAME"); + value = svGetValueString (ifcfg, "DHCP_HOSTNAME"); if (value && *value) g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); - value = svGetValue (ifcfg, "DHCP_FQDN"); + value = svGetValueString (ifcfg, "DHCP_FQDN"); if (value && *value) { g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NULL, @@ -1089,7 +1089,7 @@ make_ip4_setting (shvarFile *ifcfg, NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, svGetValueInt64 (ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), NULL); - value = svGetValue (ifcfg, "DHCP_CLIENT_ID"); + value = svGetValueString (ifcfg, "DHCP_CLIENT_ID"); if (value && strlen (value)) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, value, NULL); g_free (value); @@ -1152,7 +1152,7 @@ make_ip4_setting (shvarFile *ifcfg, char *tag; tag = g_strdup_printf ("DNS%u", i); - value = svGetValue (ifcfg, tag); + value = svGetValueString (ifcfg, tag); if (value) { if (nm_utils_ipaddr_valid (AF_INET, value)) { if (!nm_setting_ip_config_add_dns (s_ip4, value)) @@ -1173,7 +1173,7 @@ make_ip4_setting (shvarFile *ifcfg, } /* DNS searches */ - value = svGetValue (ifcfg, "DOMAIN"); + value = svGetValueString (ifcfg, "DOMAIN"); if (value) { char **searches = NULL; @@ -1192,7 +1192,7 @@ make_ip4_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValueFull (ifcfg, "RES_OPTIONS"); + value = svGetValue (ifcfg, "RES_OPTIONS"); parse_dns_options (s_ip4, value); parse_dns_options (s_ip4, dns_options); g_free (value); @@ -1240,7 +1240,7 @@ make_ip4_setting (shvarFile *ifcfg, /* Legacy value NM used for a while but is incorrect (rh #459370) */ if (!nm_setting_ip_config_get_num_dns_searches (s_ip4)) { - value = svGetValue (ifcfg, "SEARCH"); + value = svGetValueString (ifcfg, "SEARCH"); if (value) { char **searches = NULL; @@ -1328,7 +1328,7 @@ read_aliases (NMSettingIPConfig *s_ip4, const char *filename) continue; } - device = svGetValue (parsed, "DEVICE"); + device = svGetValueString (parsed, "DEVICE"); if (!device) { PARSE_WARNING ("alias file '%s' has no DEVICE", full_path); svCloseFile (parsed); @@ -1415,10 +1415,10 @@ make_ip6_setting (shvarFile *ifcfg, char *default_dev = NULL; /* Get the connection ifcfg device name and the global default route device */ - value = svGetValue (ifcfg, "DEVICE"); - ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW"); - ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV"); - dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS"); + value = svGetValueString (ifcfg, "DEVICE"); + ipv6_defaultgw = svGetValueString (network_ifcfg, "IPV6_DEFAULTGW"); + ipv6_defaultdev = svGetValueString (network_ifcfg, "IPV6_DEFAULTDEV"); + dns_options = svGetValue (network_ifcfg, "RES_OPTIONS"); if (ipv6_defaultgw) { default_dev = strchr (ipv6_defaultgw, '%'); @@ -1442,7 +1442,7 @@ make_ip6_setting (shvarFile *ifcfg, /* Find out method property */ /* Is IPV6 enabled? Set method to "ignored", when not enabled */ - str_value = svGetValue (ifcfg, "IPV6INIT"); + str_value = svGetValueString (ifcfg, "IPV6INIT"); ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE); if (!str_value) { network_ifcfg = svOpenFile (network_file, NULL); @@ -1466,9 +1466,9 @@ make_ip6_setting (shvarFile *ifcfg, method = NM_SETTING_IP6_CONFIG_METHOD_DHCP; else { /* IPV6_AUTOCONF=no and no IPv6 address -> method 'link-local' */ - str_value = svGetValue (ifcfg, "IPV6ADDR"); + str_value = svGetValueString (ifcfg, "IPV6ADDR"); if (!str_value) - str_value = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES"); + str_value = svGetValueString (ifcfg, "IPV6ADDR_SECONDARIES"); if (!str_value) method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; @@ -1478,7 +1478,7 @@ make_ip6_setting (shvarFile *ifcfg, /* TODO - handle other methods */ /* Read IPv6 Privacy Extensions configuration */ - tmp = svGetValue (ifcfg, "IPV6_PRIVACY"); + tmp = svGetValueString (ifcfg, "IPV6_PRIVACY"); if (tmp) { ip6_privacy = svGetValueBoolean (ifcfg, "IPV6_PRIVACY", FALSE); if (!ip6_privacy) @@ -1511,7 +1511,7 @@ make_ip6_setting (shvarFile *ifcfg, if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { /* METHOD_AUTO may trigger DHCPv6, so save the hostname to send to DHCP */ - value = svGetValue (ifcfg, "DHCP_HOSTNAME"); + value = svGetValueString (ifcfg, "DHCP_HOSTNAME"); if (value && value[0]) g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); @@ -1522,8 +1522,8 @@ make_ip6_setting (shvarFile *ifcfg, * added to the automatic ones. Note that this is not currently supported by * the legacy 'network' service (ifup-eth). */ - ipv6addr = svGetValue (ifcfg, "IPV6ADDR"); - ipv6addr_secondaries = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES"); + ipv6addr = svGetValueString (ifcfg, "IPV6ADDR"); + ipv6addr_secondaries = svGetValueString (ifcfg, "IPV6ADDR_SECONDARIES"); value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL, ipv6addr ? ipv6addr : "", @@ -1550,12 +1550,12 @@ make_ip6_setting (shvarFile *ifcfg, /* Gateway */ if (nm_setting_ip_config_get_num_addresses (s_ip6)) { - value = svGetValue (ifcfg, "IPV6_DEFAULTGW"); + value = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); if (!value) { /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */ network_ifcfg = svOpenFile (network_file, NULL); if (network_ifcfg) { - value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW"); + value = svGetValueString (network_ifcfg, "IPV6_DEFAULTGW"); svCloseFile (network_ifcfg); } } @@ -1576,7 +1576,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* IPv6 addressing mode configuration */ - tmp = svGetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); + tmp = svGetValueString (ifcfg, "IPV6_ADDR_GEN_MODE"); if (tmp) { if (nm_utils_enum_from_str (nm_setting_ip6_config_addr_gen_mode_get_type (), tmp, (int *) &addr_gen_mode, NULL)) @@ -1592,7 +1592,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* IPv6 tokenized interface identifier */ - tmp = svGetValue (ifcfg, "IPV6_TOKEN"); + tmp = svGetValueString (ifcfg, "IPV6_TOKEN"); if (tmp) { g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, tmp, NULL); g_free (tmp); @@ -1605,7 +1605,7 @@ make_ip6_setting (shvarFile *ifcfg, char *tag; tag = g_strdup_printf ("DNS%u", i); - value = svGetValue (ifcfg, tag); + value = svGetValueString (ifcfg, tag); if (!value) { g_free (tag); break; /* all done */ @@ -1639,7 +1639,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValueFull (ifcfg, "RES_OPTIONS"); + value = svGetValue (ifcfg, "RES_OPTIONS"); parse_dns_options (s_ip6, value); parse_dns_options (s_ip6, dns_options); g_free (value); @@ -1667,7 +1667,7 @@ check_if_bond_slave (shvarFile *ifcfg, { char *value; - value = svGetValue (ifcfg, "MASTER"); + value = svGetValueString (ifcfg, "MASTER"); if (value) { g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); g_object_set (s_con, @@ -1687,7 +1687,7 @@ check_if_team_slave (shvarFile *ifcfg, { gs_free char *value = NULL; - value = svGetValue (ifcfg, "TEAM_MASTER"); + value = svGetValueString (ifcfg, "TEAM_MASTER"); if (!value) return FALSE; g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); @@ -1762,7 +1762,7 @@ read_dcb_app (shvarFile *ifcfg, /* Priority */ tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app); - val = svGetValue (ifcfg, tmp); + val = svGetValueString (ifcfg, tmp); if (val) { priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1); if (priority < 0) { @@ -1803,7 +1803,7 @@ read_dcb_bool_array (shvarFile *ifcfg, gboolean success = FALSE; guint i; - val = svGetValue (ifcfg, prop); + val = svGetValueString (ifcfg, prop); if (!val) return TRUE; @@ -1854,7 +1854,7 @@ read_dcb_uint_array (shvarFile *ifcfg, gboolean success = FALSE; guint i; - val = svGetValue (ifcfg, prop); + val = svGetValueString (ifcfg, prop); if (!val) return TRUE; @@ -1908,7 +1908,7 @@ read_dcb_percent_array (shvarFile *ifcfg, char **split = NULL, **iter; guint i, sum = 0; - val = svGetValue (ifcfg, prop); + val = svGetValueString (ifcfg, prop); if (!val) return TRUE; @@ -1986,7 +1986,7 @@ make_dcb_setting (shvarFile *ifcfg, return FALSE; } if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) { - val = svGetValue (ifcfg, KEY_DCB_APP_FCOE_MODE); + val = svGetValueString (ifcfg, KEY_DCB_APP_FCOE_MODE); if (val) { if (strcmp (val, NM_SETTING_DCB_FCOE_MODE_FABRIC) == 0 || strcmp (val, NM_SETTING_DCB_FCOE_MODE_VN2VN) == 0) @@ -2123,7 +2123,7 @@ add_one_wep_key (shvarFile *ifcfg, g_return_val_if_fail (key_idx <= 3, FALSE); g_return_val_if_fail (s_wsec != NULL, FALSE); - value = svGetValue (ifcfg, shvar_key); + value = svGetValueString (ifcfg, shvar_key); if (!value || !strlen (value)) { g_free (value); return TRUE; @@ -2230,7 +2230,7 @@ read_secret_flags (shvarFile *ifcfg, const char *flags_key) g_return_val_if_fail (flags_key[0] != '\0', NM_SETTING_SECRET_FLAG_NONE); g_return_val_if_fail (g_str_has_suffix (flags_key, "_FLAGS"), NM_SETTING_SECRET_FLAG_NONE); - val = svGetValue (ifcfg, flags_key); + val = svGetValueString (ifcfg, flags_key); if (val) { if (strstr (val, SECRET_FLAG_AGENT)) flags |= NM_SETTING_SECRET_FLAG_AGENT_OWNED; @@ -2259,7 +2259,7 @@ make_wep_setting (shvarFile *ifcfg, s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); - value = svGetValue (ifcfg, "DEFAULTKEY"); + value = svGetValueString (ifcfg, "DEFAULTKEY"); if (value) { default_key_idx = _nm_utils_ascii_str_to_int64 (value, 0, 1, 4, 0); if (default_key_idx == 0) { @@ -2295,7 +2295,7 @@ make_wep_setting (shvarFile *ifcfg, } } - value = svGetValue (ifcfg, "SECURITYMODE"); + value = svGetValueString (ifcfg, "SECURITYMODE"); if (value) { char *lcase; @@ -2358,7 +2358,7 @@ fill_wpa_ciphers (shvarFile *ifcfg, char **list = NULL, **iter; int i = 0; - p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE"); + p = value = svGetValueString (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE"); if (!value) return TRUE; @@ -2428,13 +2428,13 @@ parse_wpa_psk (shvarFile *ifcfg, /* Try to get keys from the "shadow" key file */ keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); if (keys_ifcfg) { - psk = svGetValue (keys_ifcfg, "WPA_PSK"); + psk = svGetValueString (keys_ifcfg, "WPA_PSK"); svCloseFile (keys_ifcfg); } /* Fall back to the original ifcfg */ if (!psk) - psk = svGetValue (ifcfg, "WPA_PSK"); + psk = svGetValueString (ifcfg, "WPA_PSK"); if (!psk) return NULL; @@ -2471,7 +2471,7 @@ eap_simple_reader (const char *eap_method, NMSettingSecretFlags flags; char *value; - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY"); + value = svGetValueString (ifcfg, "IEEE_8021X_IDENTITY"); if (!value) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", @@ -2486,10 +2486,10 @@ eap_simple_reader (const char *eap_method, /* Only read the password if it's system-owned */ if (flags == NM_SETTING_SECRET_FLAG_NONE) { - value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD"); + value = svGetValueString (ifcfg, "IEEE_8021X_PASSWORD"); if (!value && keys) { /* Try the lookaside keys file */ - value = svGetValue (keys, "IEEE_8021X_PASSWORD"); + value = svGetValueString (keys, "IEEE_8021X_PASSWORD"); } if (!value) { @@ -2552,7 +2552,7 @@ eap_tls_reader (const char *eap_method, const char *pk_pw_flags_prop = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS : NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS; NMSettingSecretFlags flags; - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY"); + value = svGetValueString (ifcfg, "IEEE_8021X_IDENTITY"); if (!value) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", @@ -2562,7 +2562,7 @@ eap_tls_reader (const char *eap_method, g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, value, NULL); g_free (value); - ca_cert = svGetValue (ifcfg, ca_cert_key); + ca_cert = svGetValueString (ifcfg, ca_cert_key); if (ca_cert) { real_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (phase2) { @@ -2594,10 +2594,10 @@ eap_tls_reader (const char *eap_method, /* Read the private key password if it's system-owned */ if (flags == NM_SETTING_SECRET_FLAG_NONE) { /* Private key password */ - privkey_password = svGetValue (ifcfg, pk_pw_key); + privkey_password = svGetValueString (ifcfg, pk_pw_key); if (!privkey_password && keys) { /* Try the lookaside keys file */ - privkey_password = svGetValue (keys, pk_pw_key); + privkey_password = svGetValueString (keys, pk_pw_key); } if (!privkey_password) { @@ -2610,7 +2610,7 @@ eap_tls_reader (const char *eap_method, } /* The private key itself */ - privkey = svGetValue (ifcfg, pk_key); + privkey = svGetValueString (ifcfg, pk_key); if (!privkey) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", @@ -2647,7 +2647,7 @@ eap_tls_reader (const char *eap_method, */ if ( privkey_format == NM_SETTING_802_1X_CK_FORMAT_RAW_KEY || privkey_format == NM_SETTING_802_1X_CK_FORMAT_X509) { - client_cert = svGetValue (ifcfg, cli_cert_key); + client_cert = svGetValueString (ifcfg, cli_cert_key); if (!client_cert) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", @@ -2704,7 +2704,7 @@ eap_peap_reader (const char *eap_method, char **list = NULL, **iter; gboolean success = FALSE; - ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT"); + ca_cert = svGetValueString (ifcfg, "IEEE_8021X_CA_CERT"); if (ca_cert) { real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (!nm_setting_802_1x_set_ca_cert (s_8021x, @@ -2718,7 +2718,7 @@ eap_peap_reader (const char *eap_method, eap_method); } - peapver = svGetValue (ifcfg, "IEEE_8021X_PEAP_VERSION"); + peapver = svGetValueString (ifcfg, "IEEE_8021X_PEAP_VERSION"); if (peapver) { if (!strcmp (peapver, "0")) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "0", NULL); @@ -2735,11 +2735,11 @@ eap_peap_reader (const char *eap_method, if (svGetValueBoolean (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", FALSE)) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPLABEL, "1", NULL); - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY"); + anon_ident = svGetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY"); if (anon_ident && strlen (anon_ident)) g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + inner_auth = svGetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); if (!inner_auth) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); @@ -2808,7 +2808,7 @@ eap_ttls_reader (const char *eap_method, char *tmp; char **list = NULL, **iter; - ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT"); + ca_cert = svGetValueString (ifcfg, "IEEE_8021X_CA_CERT"); if (ca_cert) { real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (!nm_setting_802_1x_set_ca_cert (s_8021x, @@ -2822,11 +2822,11 @@ eap_ttls_reader (const char *eap_method, eap_method); } - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY"); + anon_ident = svGetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY"); if (anon_ident && strlen (anon_ident)) g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - tmp = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + tmp = svGetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); if (!tmp) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); @@ -2899,13 +2899,13 @@ eap_fast_reader (const char *eap_method, gboolean allow_unauth = FALSE, allow_auth = FALSE; gboolean success = FALSE; - pac_file = svGetValue (ifcfg, "IEEE_8021X_PAC_FILE"); + pac_file = svGetValueString (ifcfg, "IEEE_8021X_PAC_FILE"); if (pac_file) { real_pac_path = get_full_file_path (svFileGetName (ifcfg), pac_file); g_object_set (s_8021x, NM_SETTING_802_1X_PAC_FILE, real_pac_path, NULL); } - fast_provisioning = svGetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); + fast_provisioning = svGetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); if (fast_provisioning) { list = g_strsplit_set (fast_provisioning, " \t", 0); for (iter = list; iter && *iter; iter++) { @@ -2933,11 +2933,11 @@ eap_fast_reader (const char *eap_method, goto done; } - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY"); + anon_ident = svGetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY"); if (anon_ident && strlen (anon_ident)) g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + inner_auth = svGetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); if (!inner_auth) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); @@ -3024,7 +3024,7 @@ read_8021x_list_value (shvarFile *ifcfg, g_return_if_fail (ifcfg_var_name != NULL); g_return_if_fail (prop_name != NULL); - value = svGetValue (ifcfg, ifcfg_var_name); + value = svGetValueString (ifcfg, ifcfg_var_name); if (!value) return; @@ -3047,7 +3047,7 @@ fill_8021x (shvarFile *ifcfg, char *value; char **list = NULL, **iter; - value = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS"); + value = svGetValueString (ifcfg, "IEEE_8021X_EAP_METHODS"); if (!value) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_EAP_METHODS for key management '%s'", @@ -3108,11 +3108,11 @@ fill_8021x (shvarFile *ifcfg, goto error; } - value = svGetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH"); + value = svGetValueString (ifcfg, "IEEE_8021X_SUBJECT_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_SUBJECT_MATCH, value, NULL); g_free (value); - value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH"); + value = svGetValueString (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH, value, NULL); g_free (value); @@ -3121,10 +3121,10 @@ fill_8021x (shvarFile *ifcfg, read_8021x_list_value (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", s_8021x, NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES); - value = svGetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH"); + value = svGetValueString (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, value, NULL); g_free (value); - value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH"); + value = svGetValueString (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH"); g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH, value, NULL); g_free (value); @@ -3157,7 +3157,7 @@ make_wpa_setting (shvarFile *ifcfg, wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - value = svGetValue (ifcfg, "KEY_MGMT"); + value = svGetValueString (ifcfg, "KEY_MGMT"); wpa_psk = !g_strcmp0 (value, "WPA-PSK"); wpa_eap = !g_strcmp0 (value, "WPA-EAP"); ieee8021x = !g_strcmp0 (value, "IEEE8021X"); @@ -3177,8 +3177,8 @@ make_wpa_setting (shvarFile *ifcfg, } else { char *allow_wpa, *allow_rsn; - allow_wpa = svGetValue (ifcfg, "WPA_ALLOW_WPA"); - allow_rsn = svGetValue (ifcfg, "WPA_ALLOW_WPA2"); + allow_wpa = svGetValueString (ifcfg, "WPA_ALLOW_WPA"); + allow_rsn = svGetValueString (ifcfg, "WPA_ALLOW_WPA2"); if (allow_wpa && svGetValueBoolean (ifcfg, "WPA_ALLOW_WPA", TRUE)) nm_setting_wireless_security_add_proto (wsec, "wpa"); @@ -3232,7 +3232,7 @@ make_wpa_setting (shvarFile *ifcfg, g_free (value); - value = svGetValue (ifcfg, "SECURITYMODE"); + value = svGetValueString (ifcfg, "SECURITYMODE"); if (NM_IN_STRSET (value, NULL, "open")) g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, value, NULL); @@ -3258,12 +3258,12 @@ make_leap_setting (shvarFile *ifcfg, wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - value = svGetValue (ifcfg, "KEY_MGMT"); + value = svGetValueString (ifcfg, "KEY_MGMT"); if (!value || strcmp (value, "IEEE8021X")) goto error; /* Not LEAP */ g_free (value); - value = svGetValue (ifcfg, "SECURITYMODE"); + value = svGetValueString (ifcfg, "SECURITYMODE"); if (!value || strcasecmp (value, "leap")) goto error; /* Not LEAP */ @@ -3274,12 +3274,12 @@ make_leap_setting (shvarFile *ifcfg, /* Read LEAP password if it's system-owned */ if (flags == NM_SETTING_SECRET_FLAG_NONE) { - value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD"); + value = svGetValueString (ifcfg, "IEEE_8021X_PASSWORD"); if (!value) { /* Try to get keys from the "shadow" key file */ keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); if (keys_ifcfg) { - value = svGetValue (keys_ifcfg, "IEEE_8021X_PASSWORD"); + value = svGetValueString (keys_ifcfg, "IEEE_8021X_PASSWORD"); svCloseFile (keys_ifcfg); } } @@ -3288,7 +3288,7 @@ make_leap_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY"); + value = svGetValueString (ifcfg, "IEEE_8021X_IDENTITY"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing LEAP identity"); @@ -3380,25 +3380,25 @@ make_wireless_setting (shvarFile *ifcfg, s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); - value = svGetValue (ifcfg, "HWADDR"); + value = svGetValueString (ifcfg, "HWADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "MACADDR"); + value = svGetValueString (ifcfg, "MACADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); + value = svGetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); g_object_set (s_wireless, NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, value, NULL); g_free (value); - value = svGetValue (ifcfg, "HWADDR_BLACKLIST"); + value = svGetValueString (ifcfg, "HWADDR_BLACKLIST"); if (value) { char **strv; @@ -3408,7 +3408,7 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "ESSID"); + value = svGetValueString (ifcfg, "ESSID"); if (value) { gs_unref_bytes GBytes *bytes = NULL; gsize ssid_len = 0; @@ -3437,7 +3437,7 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "MODE"); + value = svGetValueString (ifcfg, "MODE"); if (value) { char *lcase; const char *mode = NULL; @@ -3463,14 +3463,14 @@ make_wireless_setting (shvarFile *ifcfg, g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, mode, NULL); } - value = svGetValue (ifcfg, "BSSID"); + value = svGetValueString (ifcfg, "BSSID"); if (value) { value = g_strstrip (value); g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "CHANNEL"); + value = svGetValueString (ifcfg, "CHANNEL"); if (value) { errno = 0; chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0); @@ -3484,7 +3484,7 @@ make_wireless_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "BAND"); + value = svGetValueString (ifcfg, "BAND"); if (value) { if (!strcmp (value, "a")) { if (chan && chan <= 14) { @@ -3515,7 +3515,7 @@ make_wireless_setting (shvarFile *ifcfg, g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); } - value = svGetValue (ifcfg, "MTU"); + value = svGetValueString (ifcfg, "MTU"); if (value) { int mtu; @@ -3535,7 +3535,7 @@ make_wireless_setting (shvarFile *ifcfg, svGetValueBoolean (ifcfg, "SSID_HIDDEN", FALSE), NULL); - value = svGetValueFull (ifcfg, "POWERSAVE"); + value = svGetValue (ifcfg, "POWERSAVE"); if (value) { if (!strcmp (value, "default")) powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; @@ -3559,7 +3559,7 @@ make_wireless_setting (shvarFile *ifcfg, powersave, NULL); - value = svGetValueFull (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); + value = svGetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); if (value) { if (strcmp (value, "default") == 0) mac_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT; @@ -3792,7 +3792,7 @@ make_wired_setting (shvarFile *ifcfg, s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); - value = svGetValue (ifcfg, "MTU"); + value = svGetValueString (ifcfg, "MTU"); if (value) { int mtu; @@ -3804,14 +3804,14 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "HWADDR"); + value = svGetValueString (ifcfg, "HWADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "SUBCHANNELS"); + value = svGetValueString (ifcfg, "SUBCHANNELS"); if (value) { const char *p = value; gboolean success = TRUE; @@ -3842,18 +3842,18 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "PORTNAME"); + value = svGetValueString (ifcfg, "PORTNAME"); if (value && strlen (value)) { nm_setting_wired_add_s390_option (s_wired, "portname", value); } g_free (value); - value = svGetValue (ifcfg, "CTCPROT"); + value = svGetValueString (ifcfg, "CTCPROT"); if (value && strlen (value)) nm_setting_wired_add_s390_option (s_wired, "ctcprot", value); g_free (value); - nettype = svGetValue (ifcfg, "NETTYPE"); + nettype = svGetValueString (ifcfg, "NETTYPE"); if (nettype && strlen (nettype)) { if (!strcmp (nettype, "qeth") || !strcmp (nettype, "lcs") || !strcmp (nettype, "ctc")) g_object_set (s_wired, NM_SETTING_WIRED_S390_NETTYPE, nettype, NULL); @@ -3862,7 +3862,7 @@ make_wired_setting (shvarFile *ifcfg, } g_free (nettype); - value = svGetValue (ifcfg, "OPTIONS"); + value = svGetValueString (ifcfg, "OPTIONS"); if (value && strlen (value)) { char **options, **iter; @@ -3883,18 +3883,18 @@ make_wired_setting (shvarFile *ifcfg, } g_free (value); - value = svGetValue (ifcfg, "MACADDR"); + value = svGetValueString (ifcfg, "MACADDR"); if (value) { value = g_strstrip (value); g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); + value = svGetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); g_object_set (s_wired, NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, value, NULL); g_free (value); - value = svGetValue (ifcfg, "HWADDR_BLACKLIST"); + value = svGetValueString (ifcfg, "HWADDR_BLACKLIST"); if (value) { char **strv; @@ -3904,7 +3904,7 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "KEY_MGMT"); + value = svGetValueString (ifcfg, "KEY_MGMT"); if (value) { if (!strcmp (value, "IEEE8021X")) { *s_8021x = fill_8021x (ifcfg, file, value, FALSE, error); @@ -3918,7 +3918,7 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValueFull (ifcfg, "ETHTOOL_OPTS"); + value = svGetValue (ifcfg, "ETHTOOL_OPTS"); parse_ethtool_options (ifcfg, s_wired, value); g_free (value); @@ -3979,19 +3979,19 @@ parse_infiniband_p_key (shvarFile *ifcfg, int id; gboolean ret = FALSE; - device = svGetValue (ifcfg, "DEVICE"); + device = svGetValueString (ifcfg, "DEVICE"); if (!device) { PARSE_WARNING ("InfiniBand connection specified PKEY but not DEVICE"); goto done; } - physdev = svGetValue (ifcfg, "PHYSDEV"); + physdev = svGetValueString (ifcfg, "PHYSDEV"); if (!physdev) { PARSE_WARNING ("InfiniBand connection specified PKEY but not PHYSDEV"); goto done; } - pkey_id = svGetValue (ifcfg, "PKEY_ID"); + pkey_id = svGetValueString (ifcfg, "PKEY_ID"); if (!pkey_id) { PARSE_WARNING ("InfiniBand connection specified PKEY but not PKEY_ID"); goto done; @@ -4039,7 +4039,7 @@ make_infiniband_setting (shvarFile *ifcfg, s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ()); - value = svGetValue (ifcfg, "MTU"); + value = svGetValueString (ifcfg, "MTU"); if (value) { int mtu; @@ -4051,7 +4051,7 @@ make_infiniband_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "HWADDR"); + value = svGetValueString (ifcfg, "HWADDR"); if (value) { value = g_strstrip (value); g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, value, NULL); @@ -4151,7 +4151,7 @@ make_bond_setting (shvarFile *ifcfg, s_bond = NM_SETTING_BOND (nm_setting_bond_new ()); - value = svGetValue (ifcfg, "DEVICE"); + value = svGetValueString (ifcfg, "DEVICE"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "mandatory DEVICE keyword missing"); @@ -4159,7 +4159,7 @@ make_bond_setting (shvarFile *ifcfg, } g_free (value); - value = svGetValue (ifcfg, "BONDING_OPTS"); + value = svGetValueString (ifcfg, "BONDING_OPTS"); if (value) { char **items, **iter; @@ -4243,7 +4243,7 @@ read_team_config (shvarFile *ifcfg, const char *key, GError **error) gs_free char *value = NULL; size_t l; - value = svGetValue (ifcfg, key); + value = svGetValueString (ifcfg, key); if (!value) return NULL; @@ -4273,7 +4273,7 @@ make_team_setting (shvarFile *ifcfg, s_team = NM_SETTING_TEAM (nm_setting_team_new ()); - value = svGetValue (ifcfg, "DEVICE"); + value = svGetValueString (ifcfg, "DEVICE"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "mandatory DEVICE keyword missing"); @@ -4430,7 +4430,7 @@ make_bridge_setting (shvarFile *ifcfg, s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ()); - value = svGetValue (ifcfg, "DEVICE"); + value = svGetValueString (ifcfg, "DEVICE"); if (!value || !strlen (value)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "mandatory DEVICE keyword missing"); @@ -4438,14 +4438,14 @@ make_bridge_setting (shvarFile *ifcfg, } g_free (value); - value = svGetValue (ifcfg, "MACADDR"); + value = svGetValueString (ifcfg, "MACADDR"); if (value) { value = g_strstrip (value); g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, value, NULL); g_free (value); } - value = svGetValue (ifcfg, "STP"); + value = svGetValueString (ifcfg, "STP"); if (value) { if (!strcasecmp (value, "on") || !strcasecmp (value, "yes")) { g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, TRUE, NULL); @@ -4464,7 +4464,7 @@ make_bridge_setting (shvarFile *ifcfg, g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL); } - value = svGetValue (ifcfg, "DELAY"); + value = svGetValueString (ifcfg, "DELAY"); if (value) { if (stp) { if (get_uint (value, &u)) @@ -4476,7 +4476,7 @@ make_bridge_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "BRIDGING_OPTS"); + value = svGetValueString (ifcfg, "BRIDGING_OPTS"); if (value) { handle_bridging_opts (NM_SETTING (s_bridge), stp, value, handle_bridge_option); g_free (value); @@ -4559,12 +4559,12 @@ make_bridge_port_setting (shvarFile *ifcfg) g_return_val_if_fail (ifcfg != NULL, FALSE); - value = svGetValue (ifcfg, "BRIDGE"); + value = svGetValueString (ifcfg, "BRIDGE"); if (value) { g_free (value); s_port = nm_setting_bridge_port_new (); - value = svGetValue (ifcfg, "BRIDGING_OPTS"); + value = svGetValueString (ifcfg, "BRIDGING_OPTS"); if (value) handle_bridging_opts (s_port, FALSE, value, handle_bridge_port_option); g_free (value); @@ -4641,7 +4641,7 @@ parse_prio_map_list (NMSettingVlan *s_vlan, char *value; gchar **list = NULL, **iter; - value = svGetValue (ifcfg, key); + value = svGetValueString (ifcfg, key); if (!value) return; @@ -4672,7 +4672,7 @@ make_vlan_setting (shvarFile *ifcfg, guint32 vlan_flags = 0; gint gvrp, reorder_hdr; - value = svGetValue (ifcfg, "VLAN_ID"); + value = svGetValueString (ifcfg, "VLAN_ID"); if (value) { vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1); if (vlan_id == -1) { @@ -4685,7 +4685,7 @@ make_vlan_setting (shvarFile *ifcfg, } /* Need DEVICE if we don't have a separate VLAN_ID property */ - iface_name = svGetValue (ifcfg, "DEVICE"); + iface_name = svGetValueString (ifcfg, "DEVICE"); if (!iface_name && vlan_id < 0) { g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing DEVICE property; cannot determine VLAN ID."); @@ -4695,7 +4695,7 @@ make_vlan_setting (shvarFile *ifcfg, s_vlan = NM_SETTING_VLAN (nm_setting_vlan_new ()); /* Parent interface from PHYSDEV takes precedence if it exists */ - parent = svGetValue (ifcfg, "PHYSDEV"); + parent = svGetValueString (ifcfg, "PHYSDEV"); if (iface_name) { p = strchr (iface_name, '.'); @@ -4751,7 +4751,7 @@ make_vlan_setting (shvarFile *ifcfg, if (gvrp > 0) vlan_flags |= NM_VLAN_FLAG_GVRP; - value = svGetValue (ifcfg, "VLAN_FLAGS"); + value = svGetValueString (ifcfg, "VLAN_FLAGS"); if (value) { gs_strfreev char **strv = NULL; char **ptr; @@ -4862,7 +4862,7 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg, nm_connection_add_setting (connection, nm_setting_generic_new ()); /* Get a spec */ - value = svGetValue (ifcfg, "HWADDR"); + value = svGetValueString (ifcfg, "HWADDR"); if (value) { char *lower = g_ascii_strdown (value, -1); *out_spec = g_strdup_printf ("%s:mac:%s", type, lower); @@ -4871,14 +4871,14 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg, return connection; } - value = svGetValue (ifcfg, "SUBCHANNELS"); + value = svGetValueString (ifcfg, "SUBCHANNELS"); if (value) { *out_spec = g_strdup_printf ("%s:s390-subchannels:%s", type, value); g_free (value); return connection; } - value = svGetValue (ifcfg, "DEVICE"); + value = svGetValueString (ifcfg, "DEVICE"); if (value) { *out_spec = g_strdup_printf ("%s:interface-name:%s", type, value); g_free (value); @@ -4907,7 +4907,7 @@ uuid_from_file (const char *filename) return NULL; /* Try for a UUID key before falling back to hashing the file name */ - uuid = svGetValue (ifcfg, "UUID"); + uuid = svGetValueString (ifcfg, "UUID"); if (!uuid || !strlen (uuid)) { g_free (uuid); uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); @@ -4928,7 +4928,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) */ if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches (NM_SETTING_IP_CONFIG (s_ip4)) == 0) { /* DNS searches */ - char *value = svGetValue (ifcfg, "DOMAIN"); + char *value = svGetValueString (ifcfg, "DOMAIN"); if (value) { char **searches = g_strsplit (value, " ", 0); if (searches) { @@ -4988,7 +4988,7 @@ connection_from_file_full (const char *filename, } /* iBFT is handled by the iBFT settings plugin */ - bootproto = svGetValue (parsed, "BOOTPROTO"); + bootproto = svGetValueString (parsed, "BOOTPROTO"); if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) { if (out_ignore_error) *out_ignore_error = TRUE; @@ -4999,7 +4999,7 @@ connection_from_file_full (const char *filename, } g_free (bootproto); - devtype = svGetValue (parsed, "DEVICETYPE"); + devtype = svGetValueString (parsed, "DEVICETYPE"); if (devtype) { if (!strcasecmp (devtype, TYPE_TEAM)) type = g_strdup (TYPE_TEAM); @@ -5013,19 +5013,19 @@ connection_from_file_full (const char *filename, /* Team and TeamPort types are also accepted by the mere * presense of TEAM_CONFIG/TEAM_MASTER. They don't require * DEVICETYPE. */ - t = svGetValue (parsed, "TEAM_CONFIG"); + t = svGetValueString (parsed, "TEAM_CONFIG"); if (t) type = g_strdup (TYPE_TEAM); } if (!type) - type = svGetValue (parsed, "TYPE"); + type = svGetValueString (parsed, "TYPE"); if (!type) { gs_free char *tmp = NULL; char *device; - if ((tmp = svGetValue (parsed, "IPV6TUNNELIPV4"))) { + if ((tmp = svGetValueString (parsed, "IPV6TUNNELIPV4"))) { if (out_ignore_error) *out_ignore_error = TRUE; g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -5033,7 +5033,7 @@ connection_from_file_full (const char *filename, goto done; } - device = svGetValue (parsed, "DEVICE"); + device = svGetValueString (parsed, "DEVICE"); if (!device) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "File '%s' had neither TYPE nor DEVICE keys.", filename); @@ -5247,7 +5247,7 @@ devtimeout_from_file (const char *filename) if (!ifcfg) return 0; - devtimeout_str = svGetValue (ifcfg, "DEVTIMEOUT"); + devtimeout_str = svGetValueString (ifcfg, "DEVTIMEOUT"); if (devtimeout_str) { devtimeout = _nm_utils_ascii_str_to_int64 (devtimeout_str, 10, 0, G_MAXUINT, 0); g_free (devtimeout_str); diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index e8cf3d231..f098f1295 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -98,7 +98,7 @@ save_secret_flags (shvarFile *ifcfg, g_string_append (str, SECRET_FLAG_NOT_REQUIRED); } - svSetValue (ifcfg, key, str->len ? str->str : NULL); + svSetValueString (ifcfg, key, str->len ? str->str : NULL); g_string_free (str, TRUE); } @@ -126,7 +126,7 @@ set_secret (shvarFile *ifcfg, /* Only write the secret if it's system owned and supposed to be saved */ if (flags == NM_SETTING_SECRET_FLAG_NONE) - svSetValue (keyfile, key, value); + svSetValueString (keyfile, key, value); else svUnsetValue (keyfile, key); @@ -142,7 +142,7 @@ set_secret (shvarFile *ifcfg, error: /* Try setting the secret in the actual ifcfg */ - svSetValue (ifcfg, key, value); + svSetValueString (ifcfg, key, value); } typedef struct ObjectType { @@ -277,7 +277,7 @@ write_object (NMSetting8021x *s_8021x, * may have been sent. */ if (path) { - svSetValue (ifcfg, objtype->ifcfg_key, path); + svSetValueString (ifcfg, objtype->ifcfg_key, path); return TRUE; } @@ -305,7 +305,7 @@ write_object (NMSetting8021x *s_8021x, 0600, &write_error); if (success) { - svSetValue (ifcfg, objtype->ifcfg_key, new_file); + svSetValueString (ifcfg, objtype->ifcfg_key, new_file); g_free (new_file); return TRUE; } else { @@ -379,9 +379,9 @@ write_8021x_certs (NMSetting8021x *s_8021x, /* Don't need a client certificate with PKCS#12 since the file is both * the client certificate and the private key in one file. */ - svSetValue (ifcfg, - phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT", - NULL); + svSetValueString (ifcfg, + phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT", + NULL); } else { /* Save the client certificate */ if (!write_object (s_8021x, ifcfg, phase2 ? &phase2_client_type : &client_type, error)) @@ -418,7 +418,7 @@ write_8021x_setting (NMConnection *connection, /* If wired, write KEY_MGMT */ if (wired) - svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X"); + svSetValueString (ifcfg, "KEY_MGMT", "IEEE8021X"); /* EAP method */ if (nm_setting_802_1x_get_num_eap_methods (s_8021x)) { @@ -426,14 +426,14 @@ write_8021x_setting (NMConnection *connection, if (value) tmp = g_ascii_strup (value, -1); } - svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp); + svSetValueString (ifcfg, "IEEE_8021X_EAP_METHODS", tmp); g_free (tmp); - svSetValue (ifcfg, "IEEE_8021X_IDENTITY", - nm_setting_802_1x_get_identity (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_IDENTITY", + nm_setting_802_1x_get_identity (s_8021x)); - svSetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", - nm_setting_802_1x_get_anonymous_identity (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY", + nm_setting_802_1x_get_anonymous_identity (s_8021x)); set_secret (ifcfg, "IEEE_8021X_PASSWORD", @@ -445,30 +445,30 @@ write_8021x_setting (NMConnection *connection, value = nm_setting_802_1x_get_phase1_peapver (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_PEAP_VERSION"); if (value && (!strcmp (value, "0") || !strcmp (value, "1"))) - svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", value); + svSetValueString (ifcfg, "IEEE_8021X_PEAP_VERSION", value); /* Force new PEAP label */ value = nm_setting_802_1x_get_phase1_peaplabel (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL"); if (value && !strcmp (value, "1")) - svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes"); + svSetValueString (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes"); /* PAC file */ value = nm_setting_802_1x_get_pac_file (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_PAC_FILE"); if (value) - svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", value); + svSetValueString (ifcfg, "IEEE_8021X_PAC_FILE", value); /* FAST PAC provisioning */ value = nm_setting_802_1x_get_phase1_fast_provisioning (s_8021x); svUnsetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); if (value) { if (strcmp (value, "1") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth"); + svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth"); else if (strcmp (value, "2") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth"); + svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth"); else if (strcmp (value, "3") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth"); + svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth"); } /* Phase2 auth methods */ @@ -492,16 +492,16 @@ write_8021x_setting (NMConnection *connection, g_free (tmp); } - svSetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", - phase2_auth->len ? phase2_auth->str : NULL); + svSetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", + phase2_auth->len ? phase2_auth->str : NULL); g_string_free (phase2_auth, TRUE); - svSetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH", - nm_setting_802_1x_get_subject_match (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_SUBJECT_MATCH", + nm_setting_802_1x_get_subject_match (s_8021x)); - svSetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", - nm_setting_802_1x_get_phase2_subject_match (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", + nm_setting_802_1x_get_phase2_subject_match (s_8021x)); svUnsetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES"); str = g_string_new (NULL); @@ -513,7 +513,7 @@ write_8021x_setting (NMConnection *connection, g_string_append (str, match); } if (str->len > 0) - svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str); + svSetValueString (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str); g_string_free (str, TRUE); svUnsetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES"); @@ -526,13 +526,13 @@ write_8021x_setting (NMConnection *connection, g_string_append (str, match); } if (str->len > 0) - svSetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", str->str); + svSetValueString (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", str->str); g_string_free (str, TRUE); - svSetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", - nm_setting_802_1x_get_domain_suffix_match (s_8021x)); - svSetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", - nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", + nm_setting_802_1x_get_domain_suffix_match (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", + nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x)); success = write_8021x_certs (s_8021x, FALSE, ifcfg, error); if (success) { @@ -577,27 +577,27 @@ write_wireless_security_setting (NMConnection *connection, wep = TRUE; *no_8021x = TRUE; } else if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) { - svSetValue (ifcfg, "KEY_MGMT", "WPA-PSK"); + svSetValueString (ifcfg, "KEY_MGMT", "WPA-PSK"); wpa = TRUE; *no_8021x = TRUE; } else if (!strcmp (key_mgmt, "ieee8021x")) { - svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X"); + svSetValueString (ifcfg, "KEY_MGMT", "IEEE8021X"); dynamic_wep = TRUE; } else if (!strcmp (key_mgmt, "wpa-eap")) { - svSetValue (ifcfg, "KEY_MGMT", "WPA-EAP"); + svSetValueString (ifcfg, "KEY_MGMT", "WPA-EAP"); wpa = TRUE; } svUnsetValue (ifcfg, "SECURITYMODE"); if (auth_alg) { if (!strcmp (auth_alg, "shared")) - svSetValue (ifcfg, "SECURITYMODE", "restricted"); + svSetValueString (ifcfg, "SECURITYMODE", "restricted"); else if (!strcmp (auth_alg, "open")) - svSetValue (ifcfg, "SECURITYMODE", "open"); + svSetValueString (ifcfg, "SECURITYMODE", "open"); else if (!strcmp (auth_alg, "leap")) { - svSetValue (ifcfg, "SECURITYMODE", "leap"); - svSetValue (ifcfg, "IEEE_8021X_IDENTITY", - nm_setting_wireless_security_get_leap_username (s_wsec)); + svSetValueString (ifcfg, "SECURITYMODE", "leap"); + svSetValueString (ifcfg, "IEEE_8021X_IDENTITY", + nm_setting_wireless_security_get_leap_username (s_wsec)); set_secret (ifcfg, "IEEE_8021X_PASSWORD", nm_setting_wireless_security_get_leap_password (s_wsec), @@ -627,7 +627,7 @@ write_wireless_security_setting (NMConnection *connection, if (wep) { /* Default WEP TX key index */ tmp = g_strdup_printf ("%d", nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec) + 1); - svSetValue (ifcfg, "DEFAULTKEY", tmp); + svSetValueString (ifcfg, "DEFAULTKEY", tmp); g_free (tmp); for (i = 0; i < 4; i++) { @@ -683,9 +683,9 @@ write_wireless_security_setting (NMConnection *connection, for (i = 0; i < num; i++) { proto = nm_setting_wireless_security_get_proto (s_wsec, i); if (proto && !strcmp (proto, "wpa")) - svSetValue (ifcfg, "WPA_ALLOW_WPA", "yes"); + svSetValueString (ifcfg, "WPA_ALLOW_WPA", "yes"); else if (proto && !strcmp (proto, "rsn")) - svSetValue (ifcfg, "WPA_ALLOW_WPA2", "yes"); + svSetValueString (ifcfg, "WPA_ALLOW_WPA2", "yes"); } /* WPA Pairwise ciphers */ @@ -707,7 +707,7 @@ write_wireless_security_setting (NMConnection *connection, } } if (strlen (str->str) && (dynamic_wep == FALSE)) - svSetValue (ifcfg, "CIPHER_PAIRWISE", str->str); + svSetValueString (ifcfg, "CIPHER_PAIRWISE", str->str); g_string_free (str, TRUE); /* WPA Group ciphers */ @@ -723,7 +723,7 @@ write_wireless_security_setting (NMConnection *connection, g_free (tmp); } if (strlen (str->str) && (dynamic_wep == FALSE)) - svSetValue (ifcfg, "CIPHER_GROUP", str->str); + svSetValueString (ifcfg, "CIPHER_GROUP", str->str); g_string_free (str, TRUE); if (wpa) @@ -763,13 +763,13 @@ write_wireless_setting (NMConnection *connection, } device_mac = nm_setting_wireless_get_mac_address (s_wireless); - svSetValue (ifcfg, "HWADDR", device_mac); + svSetValueString (ifcfg, "HWADDR", device_mac); cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); - svSetValue (ifcfg, "MACADDR", cloned_mac); + svSetValueString (ifcfg, "MACADDR", cloned_mac); - svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wireless_get_generate_mac_address_mask (s_wireless)); + svSetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK", + nm_setting_wireless_get_generate_mac_address_mask (s_wireless)); svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); macaddr_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); @@ -777,7 +777,7 @@ write_wireless_setting (NMConnection *connection, char *blacklist_str; blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str); + svSetValueString (ifcfg, "HWADDR_BLACKLIST", blacklist_str); g_free (blacklist_str); } @@ -785,7 +785,7 @@ write_wireless_setting (NMConnection *connection, mtu = nm_setting_wireless_get_mtu (s_wireless); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp); + svSetValueString (ifcfg, "MTU", tmp); g_free (tmp); } @@ -833,7 +833,7 @@ write_wireless_setting (NMConnection *connection, g_string_append (str, "0x"); for (i = 0; i < ssid_len; i++) g_string_append_printf (str, "%02X", ssid_data[i]); - svSetValue (ifcfg, "ESSID", str->str); + svSetValueString (ifcfg, "ESSID", str->str); g_string_free (str, TRUE); } else { char buf[33]; @@ -841,17 +841,17 @@ write_wireless_setting (NMConnection *connection, nm_assert (ssid_len <= 32); memcpy (buf, ssid_data, ssid_len); buf[ssid_len] = '\0'; - svSetValue (ifcfg, "ESSID", buf); + svSetValueString (ifcfg, "ESSID", buf); } mode = nm_setting_wireless_get_mode (s_wireless); if (!mode || !strcmp (mode, "infrastructure")) { - svSetValue (ifcfg, "MODE", "Managed"); + svSetValueString (ifcfg, "MODE", "Managed"); } else if (!strcmp (mode, "adhoc")) { - svSetValue (ifcfg, "MODE", "Ad-Hoc"); + svSetValueString (ifcfg, "MODE", "Ad-Hoc"); adhoc = TRUE; } else if (!strcmp (mode, "ap")) { - svSetValue (ifcfg, "MODE", "Ap"); + svSetValueString (ifcfg, "MODE", "Ap"); } else { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Invalid mode '%s' in '%s' setting", @@ -864,15 +864,15 @@ write_wireless_setting (NMConnection *connection, chan = nm_setting_wireless_get_channel (s_wireless); if (chan) { tmp = g_strdup_printf ("%u", chan); - svSetValue (ifcfg, "CHANNEL", tmp); + svSetValueString (ifcfg, "CHANNEL", tmp); g_free (tmp); } else { /* Band only set if channel is not, since channel implies band */ - svSetValue (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless)); + svSetValueString (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless)); } bssid = nm_setting_wireless_get_bssid (s_wireless); - svSetValue (ifcfg, "BSSID", bssid); + svSetValueString (ifcfg, "BSSID", bssid); /* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security; * otherwise there's no way to detect WEP vs. open when WEP keys aren't @@ -918,17 +918,17 @@ write_wireless_setting (NMConnection *connection, g_free (keys_path); } - svSetValue (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL); + svSetValueString (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL); switch (nm_setting_wireless_get_powersave (s_wireless)) { case NM_SETTING_WIRELESS_POWERSAVE_IGNORE: - svSetValue (ifcfg, "POWERSAVE", "ignore"); + svSetValueString (ifcfg, "POWERSAVE", "ignore"); break; case NM_SETTING_WIRELESS_POWERSAVE_DISABLE: - svSetValue (ifcfg, "POWERSAVE", "disable"); + svSetValueString (ifcfg, "POWERSAVE", "disable"); break; case NM_SETTING_WIRELESS_POWERSAVE_ENABLE: - svSetValue (ifcfg, "POWERSAVE", "enable"); + svSetValueString (ifcfg, "POWERSAVE", "enable"); break; default: case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT: @@ -939,18 +939,18 @@ write_wireless_setting (NMConnection *connection, svUnsetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); switch (nm_setting_wireless_get_mac_address_randomization (s_wireless)) { case NM_SETTING_MAC_RANDOMIZATION_DEFAULT: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default"); + svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default"); break; case NM_SETTING_MAC_RANDOMIZATION_ALWAYS: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always"); + svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always"); break; default: case NM_SETTING_MAC_RANDOMIZATION_NEVER: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never"); + svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never"); break; } - svSetValue (ifcfg, "TYPE", TYPE_WIRELESS); + svSetValueString (ifcfg, "TYPE", TYPE_WIRELESS); return TRUE; } @@ -972,13 +972,13 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e } mac = nm_setting_infiniband_get_mac_address (s_infiniband); - svSetValue (ifcfg, "HWADDR", mac); + svSetValueString (ifcfg, "HWADDR", mac); svUnsetValue (ifcfg, "MTU"); mtu = nm_setting_infiniband_get_mtu (s_infiniband); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp); + svSetValueString (ifcfg, "MTU", tmp); g_free (tmp); } @@ -987,17 +987,17 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e p_key = nm_setting_infiniband_get_p_key (s_infiniband); if (p_key != -1) { - svSetValue (ifcfg, "PKEY", "yes"); + svSetValueString (ifcfg, "PKEY", "yes"); tmp = g_strdup_printf ("%u", p_key); - svSetValue (ifcfg, "PKEY_ID", tmp); + svSetValueString (ifcfg, "PKEY_ID", tmp); g_free (tmp); parent = nm_setting_infiniband_get_parent (s_infiniband); if (parent) - svSetValue (ifcfg, "PHYSDEV", parent); + svSetValueString (ifcfg, "PHYSDEV", parent); } - svSetValue (ifcfg, "TYPE", TYPE_INFINIBAND); + svSetValueString (ifcfg, "TYPE", TYPE_INFINIBAND); return TRUE; } @@ -1024,13 +1024,13 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } device_mac = nm_setting_wired_get_mac_address (s_wired); - svSetValue (ifcfg, "HWADDR", device_mac); + svSetValueString (ifcfg, "HWADDR", device_mac); cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - svSetValue (ifcfg, "MACADDR", cloned_mac); + svSetValueString (ifcfg, "MACADDR", cloned_mac); - svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask (s_wired)); + svSetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK", + nm_setting_wired_get_generate_mac_address_mask (s_wired)); svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); @@ -1038,7 +1038,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) char *blacklist_str; blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str); + svSetValueString (ifcfg, "HWADDR_BLACKLIST", blacklist_str); g_free (blacklist_str); } @@ -1046,7 +1046,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) mtu = nm_setting_wired_get_mtu (s_wired); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp); + svSetValueString (ifcfg, "MTU", tmp); g_free (tmp); } @@ -1062,24 +1062,24 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) tmp = g_strdup_printf ("%s,%s,%s", s390_subchannels[0], s390_subchannels[1], s390_subchannels[2]); } - svSetValue (ifcfg, "SUBCHANNELS", tmp); + svSetValueString (ifcfg, "SUBCHANNELS", tmp); g_free (tmp); } svUnsetValue (ifcfg, "NETTYPE"); nettype = nm_setting_wired_get_s390_nettype (s_wired); if (nettype) - svSetValue (ifcfg, "NETTYPE", nettype); + svSetValueString (ifcfg, "NETTYPE", nettype); svUnsetValue (ifcfg, "PORTNAME"); portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname"); if (portname) - svSetValue (ifcfg, "PORTNAME", portname); + svSetValueString (ifcfg, "PORTNAME", portname); svUnsetValue (ifcfg, "CTCPROT"); ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot"); if (ctcprot) - svSetValue (ifcfg, "CTCPROT", ctcprot); + svSetValueString (ifcfg, "CTCPROT", ctcprot); svUnsetValue (ifcfg, "OPTIONS"); num_opts = nm_setting_wired_get_num_s390_options (s_wired); @@ -1097,14 +1097,14 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_string_append_printf (str, "%s=%s", s390_key, s390_val); } if (str->len) - svSetValue (ifcfg, "OPTIONS", str->str); + svSetValueString (ifcfg, "OPTIONS", str->str); g_string_free (str, TRUE); } wol = nm_setting_wired_get_wake_on_lan (s_wired); wol_password = nm_setting_wired_get_wake_on_lan_password (s_wired); if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) - svSetValueFull (ifcfg, "ETHTOOL_OPTS", ""); + svSetValue (ifcfg, "ETHTOOL_OPTS", ""); else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) svUnsetValue (ifcfg, "ETHTOOL_OPTS"); else { @@ -1130,11 +1130,11 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (wol_password && NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) g_string_append_printf (str, "s sopass %s", wol_password); - svSetValue (ifcfg, "ETHTOOL_OPTS", str->str); + svSetValueString (ifcfg, "ETHTOOL_OPTS", str->str); g_string_free (str, TRUE); } - svSetValue (ifcfg, "TYPE", TYPE_ETHERNET); + svSetValueString (ifcfg, "TYPE", TYPE_ETHERNET); return TRUE; } @@ -1176,18 +1176,18 @@ write_wired_for_virtual (NMConnection *connection, shvarFile *ifcfg) has_wired = TRUE; device_mac = nm_setting_wired_get_mac_address (s_wired); - svSetValue (ifcfg, "HWADDR", device_mac); + svSetValueString (ifcfg, "HWADDR", device_mac); cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - svSetValue (ifcfg, "MACADDR", cloned_mac); + svSetValueString (ifcfg, "MACADDR", cloned_mac); - svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask (s_wired)); + svSetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK", + nm_setting_wired_get_generate_mac_address_mask (s_wired)); mtu = nm_setting_wired_get_mtu (s_wired); if (mtu) { tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp); + svSetValueString (ifcfg, "MTU", tmp); g_free (tmp); } else svUnsetValue (ifcfg, "MTU"); @@ -1219,13 +1219,13 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, return FALSE; } - svSetValue (ifcfg, "VLAN", "yes"); - svSetValue (ifcfg, "TYPE", TYPE_VLAN); - svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); - svSetValue (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan)); + svSetValueString (ifcfg, "VLAN", "yes"); + svSetValueString (ifcfg, "TYPE", TYPE_VLAN); + svSetValueString (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); + svSetValueString (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan)); tmp = g_strdup_printf ("%d", nm_setting_vlan_get_id (s_vlan)); - svSetValue (ifcfg, "VLAN_ID", tmp); + svSetValueString (ifcfg, "VLAN_ID", tmp); g_free (tmp); vlan_flags = nm_setting_vlan_get_flags (s_vlan); @@ -1239,16 +1239,16 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, if (!NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) nm_utils_strbuf_append (&s_buf_ptr, &s_buf_len, "%sNO_REORDER_HDR", s_buf[0] ? "," : ""); - svSetValue (ifcfg, "VLAN_FLAGS", s_buf); + svSetValueString (ifcfg, "VLAN_FLAGS", s_buf); svSetValueBoolean (ifcfg, "MVRP", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_MVRP)); tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); - svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp); + svSetValueString (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp); g_free (tmp); tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP); - svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp); + svSetValueString (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp); g_free (tmp); svUnsetValue (ifcfg, "HWADDR"); @@ -1281,7 +1281,7 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir return FALSE; } - svSetValue (ifcfg, "DEVICE", iface); + svSetValueString (ifcfg, "DEVICE", iface); svUnsetValue (ifcfg, "BONDING_OPTS"); num_opts = nm_setting_bond_get_num_options (s_bond); @@ -1301,13 +1301,13 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir } if (str->len) - svSetValue (ifcfg, "BONDING_OPTS", str->str); + svSetValueString (ifcfg, "BONDING_OPTS", str->str); g_string_free (str, TRUE); } - svSetValue (ifcfg, "TYPE", TYPE_BOND); - svSetValue (ifcfg, "BONDING_MASTER", "yes"); + svSetValueString (ifcfg, "TYPE", TYPE_BOND); + svSetValueString (ifcfg, "BONDING_MASTER", "yes"); *wired = write_wired_for_virtual (connection, ifcfg); @@ -1335,9 +1335,9 @@ write_team_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, return FALSE; } - svSetValue (ifcfg, "DEVICE", iface); + svSetValueString (ifcfg, "DEVICE", iface); config = nm_setting_team_get_config (s_team); - svSetValue (ifcfg, "TEAM_CONFIG", config); + svSetValueString (ifcfg, "TEAM_CONFIG", config); *wired = write_wired_for_virtual (connection, ifcfg); @@ -1403,24 +1403,24 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error return FALSE; } - svSetValue (ifcfg, "DEVICE", iface); + svSetValueString (ifcfg, "DEVICE", iface); svUnsetValue (ifcfg, "BRIDGING_OPTS"); svSetValueBoolean (ifcfg, "STP", FALSE); svUnsetValue (ifcfg, "DELAY"); mac = nm_setting_bridge_get_mac_address (s_bridge); - svSetValue (ifcfg, "MACADDR", mac); + svSetValueString (ifcfg, "MACADDR", mac); /* Bridge options */ opts = g_string_sized_new (32); if (nm_setting_bridge_get_stp (s_bridge)) { - svSetValue (ifcfg, "STP", "yes"); + svSetValueString (ifcfg, "STP", "yes"); i = nm_setting_bridge_get_forward_delay (s_bridge); if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_FORWARD_DELAY)) { s = g_strdup_printf ("%u", i); - svSetValue (ifcfg, "DELAY", s); + svSetValueString (ifcfg, "DELAY", s); g_free (s); } @@ -1456,10 +1456,10 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error } if (opts->len) - svSetValue (ifcfg, "BRIDGING_OPTS", opts->str); + svSetValueString (ifcfg, "BRIDGING_OPTS", opts->str); g_string_free (opts, TRUE); - svSetValue (ifcfg, "TYPE", TYPE_BRIDGE); + svSetValueString (ifcfg, "TYPE", TYPE_BRIDGE); return TRUE; } @@ -1498,7 +1498,7 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError ** } if (opts->len) - svSetValue (ifcfg, "BRIDGING_OPTS", opts->str); + svSetValueString (ifcfg, "BRIDGING_OPTS", opts->str); g_string_free (opts, TRUE); return TRUE; @@ -1515,7 +1515,7 @@ write_team_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **er return TRUE; config = nm_setting_team_port_get_config (s_port); - svSetValue (ifcfg, "TEAM_PORT_CONFIG", config); + svSetValueString (ifcfg, "TEAM_PORT_CONFIG", config); return TRUE; } @@ -1526,13 +1526,13 @@ write_dcb_flags (shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags) char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")]; nm_sprintf_buf (prop, "DCB_%s_ENABLE", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL); + svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL); nm_sprintf_buf (prop, "DCB_%s_ADVERTISE", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL); + svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL); nm_sprintf_buf (prop, "DCB_%s_WILLING", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL); + svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL); } static void @@ -1572,7 +1572,7 @@ write_dcb_bool_array (shvarFile *ifcfg, str[8] = 0; for (i = 0; i < 8; i++) str[i] = get_func (s_dcb, i) ? '1' : '0'; - svSetValue (ifcfg, key, str); + svSetValueString (ifcfg, key, str); } typedef guint (*DcbGetUintFunc) (NMSettingDcb *, guint); @@ -1602,7 +1602,7 @@ write_dcb_uint_array (shvarFile *ifcfg, else g_assert_not_reached (); } - svSetValue (ifcfg, key, str); + svSetValueString (ifcfg, key, str); } static void @@ -1626,7 +1626,7 @@ write_dcb_percent_array (shvarFile *ifcfg, g_string_append_c (str, ','); g_string_append_printf (str, "%d", get_func (s_dcb, i)); } - svSetValue (ifcfg, key, str->str); + svSetValueString (ifcfg, key, str->str); g_string_free (str, TRUE); } @@ -1670,13 +1670,13 @@ write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) return TRUE; } - svSetValue (ifcfg, "DCB", "yes"); + svSetValueString (ifcfg, "DCB", "yes"); write_dcb_app (ifcfg, "APP_FCOE", nm_setting_dcb_get_app_fcoe_flags (s_dcb), nm_setting_dcb_get_app_fcoe_priority (s_dcb)); if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) - svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb)); + svSetValueString (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb)); else svUnsetValue (ifcfg, KEY_DCB_APP_FCOE_MODE); @@ -1716,21 +1716,21 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) const char *v_bridge = NULL; const char *v_team_master = NULL; - svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con)); - svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con)); - svSetValue (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con)); - svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); + svSetValueString (ifcfg, "NAME", nm_setting_connection_get_id (s_con)); + svSetValueString (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con)); + svSetValueString (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con)); + svSetValueString (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); svSetValueBoolean (ifcfg, "ONBOOT", nm_setting_connection_get_autoconnect (s_con)); i_int = nm_setting_connection_get_autoconnect_priority (s_con); tmp = i_int != NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT ? g_strdup_printf ("%d", i_int) : NULL; - svSetValue (ifcfg, "AUTOCONNECT_PRIORITY", tmp); + svSetValueString (ifcfg, "AUTOCONNECT_PRIORITY", tmp); g_free (tmp); i_int = nm_setting_connection_get_autoconnect_retries (s_con); tmp = i_int != -1 ? g_strdup_printf ("%d", i_int) : NULL; - svSetValue (ifcfg, "AUTOCONNECT_RETRIES", tmp); + svSetValueString (ifcfg, "AUTOCONNECT_RETRIES", tmp); g_free (tmp); /* Only save the value for master connections */ @@ -1740,9 +1740,9 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) || !g_strcmp0 (type, NM_SETTING_BRIDGE_SETTING_NAME)) { NMSettingConnectionAutoconnectSlaves autoconnect_slaves; autoconnect_slaves = nm_setting_connection_get_autoconnect_slaves (s_con); - svSetValue (ifcfg, "AUTOCONNECT_SLAVES", - autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES ? "yes" : - autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL); + svSetValueString (ifcfg, "AUTOCONNECT_SLAVES", + autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES ? "yes" : + autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL); } else svUnsetValue (ifcfg, "AUTOCONNECT_SLAVES"); @@ -1756,7 +1756,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) default: tmp = NULL; } - svSetValue (ifcfg, "LLDP", tmp); + svSetValueString (ifcfg, "LLDP", tmp); /* Permissions */ svUnsetValue (ifcfg, "USERS"); @@ -1776,11 +1776,11 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) if (nm_setting_connection_get_permission (s_con, i, NULL, &puser, NULL)) g_string_append (str, puser); } - svSetValue (ifcfg, "USERS", str->str); + svSetValueString (ifcfg, "USERS", str->str); g_string_free (str, TRUE); } - svSetValue (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con)); + svSetValueString (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con)); master = nm_setting_connection_get_master (s_con); if (master) { @@ -1795,15 +1795,15 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) } } - svSetValue (ifcfg, "MASTER", v_master); - svSetValue (ifcfg, "SLAVE", v_slave); - svSetValue (ifcfg, "BRIDGE", v_bridge); - svSetValue (ifcfg, "TEAM_MASTER", v_team_master); + svSetValueString (ifcfg, "MASTER", v_master); + svSetValueString (ifcfg, "SLAVE", v_slave); + svSetValueString (ifcfg, "BRIDGE", v_bridge); + svSetValueString (ifcfg, "TEAM_MASTER", v_team_master); if (nm_streq0 (type, NM_SETTING_TEAM_SETTING_NAME)) - svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM); + svSetValueString (ifcfg, "DEVICETYPE", TYPE_TEAM); else if (master && nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) - svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT); + svSetValueString (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT); else svUnsetValue (ifcfg, "DEVICETYPE"); @@ -1825,23 +1825,23 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) if ((uuid = nm_setting_connection_get_secondary (s_con, i)) != NULL) g_string_append (str, uuid); } - svSetValue (ifcfg, "SECONDARY_UUIDS", str->str); + svSetValueString (ifcfg, "SECONDARY_UUIDS", str->str); g_string_free (str, TRUE); } svUnsetValue (ifcfg, "GATEWAY_PING_TIMEOUT"); if (nm_setting_connection_get_gateway_ping_timeout (s_con)) { tmp = g_strdup_printf ("%" G_GUINT32_FORMAT, nm_setting_connection_get_gateway_ping_timeout (s_con)); - svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", tmp); + svSetValueString (ifcfg, "GATEWAY_PING_TIMEOUT", tmp); g_free (tmp); } switch (nm_setting_connection_get_metered (s_con)) { case NM_METERED_YES: - svSetValue (ifcfg, "CONNECTION_METERED", "yes"); + svSetValueString (ifcfg, "CONNECTION_METERED", "yes"); break; case NM_METERED_NO: - svSetValue (ifcfg, "CONNECTION_METERED", "no"); + svSetValueString (ifcfg, "CONNECTION_METERED", "no"); break; default: svUnsetValue (ifcfg, "CONNECTION_METERED"); @@ -1921,19 +1921,19 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) method = nm_setting_proxy_get_method (s_proxy); switch (method) { case NM_SETTING_PROXY_METHOD_AUTO: - svSetValue (ifcfg, "PROXY_METHOD", "auto"); + svSetValueString (ifcfg, "PROXY_METHOD", "auto"); pac_url = nm_setting_proxy_get_pac_url (s_proxy); if (pac_url) - svSetValue (ifcfg, "PAC_URL", pac_url); + svSetValueString (ifcfg, "PAC_URL", pac_url); pac_script = nm_setting_proxy_get_pac_script (s_proxy); if (pac_script) - svSetValue (ifcfg, "PAC_SCRIPT", pac_script); + svSetValueString (ifcfg, "PAC_SCRIPT", pac_script); break; case NM_SETTING_PROXY_METHOD_NONE: - svSetValue (ifcfg, "PROXY_METHOD", "none"); + svSetValueString (ifcfg, "PROXY_METHOD", "none"); break; } @@ -2019,13 +2019,13 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) - svSetValue (ifcfg, "BOOTPROTO", "dhcp"); + svSetValueString (ifcfg, "BOOTPROTO", "dhcp"); else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) - svSetValue (ifcfg, "BOOTPROTO", "none"); + svSetValueString (ifcfg, "BOOTPROTO", "none"); else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) - svSetValue (ifcfg, "BOOTPROTO", "autoip"); + svSetValueString (ifcfg, "BOOTPROTO", "autoip"); else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) - svSetValue (ifcfg, "BOOTPROTO", "shared"); + svSetValueString (ifcfg, "BOOTPROTO", "shared"); /* Clear out un-numbered IP address fields */ svUnsetValue (ifcfg, "IPADDR"); @@ -2072,10 +2072,10 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) gw_key = g_strdup_printf ("GATEWAY%d", n); } - svSetValue (ifcfg, addr_key, nm_ip_address_get_address (addr)); + svSetValueString (ifcfg, addr_key, nm_ip_address_get_address (addr)); tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); - svSetValue (ifcfg, prefix_key, tmp); + svSetValueString (ifcfg, prefix_key, tmp); g_free (tmp); svUnsetValue (ifcfg, netmask_key); @@ -2106,7 +2106,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (gw_key); } - svSetValue (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4)); + svSetValueString (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4)); num = nm_setting_ip_config_get_num_dns (s_ip4); for (i = 0; i < 254; i++) { @@ -2118,7 +2118,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, addr_key); else { dns = nm_setting_ip_config_get_dns (s_ip4, i); - svSetValue (ifcfg, addr_key, dns); + svSetValueString (ifcfg, addr_key, dns); } g_free (addr_key); } @@ -2131,7 +2131,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_string_append_c (searches, ' '); g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip4, i)); } - svSetValue (ifcfg, "DOMAIN", searches->str); + svSetValueString (ifcfg, "DOMAIN", searches->str); g_string_free (searches, TRUE); } else svUnsetValue (ifcfg, "DOMAIN"); @@ -2148,25 +2148,25 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) value = nm_setting_ip_config_get_dhcp_hostname (s_ip4); if (value) - svSetValue (ifcfg, "DHCP_HOSTNAME", value); + svSetValueString (ifcfg, "DHCP_HOSTNAME", value); value = nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)); if (value) - svSetValue (ifcfg, "DHCP_FQDN", value); + svSetValueString (ifcfg, "DHCP_FQDN", value); /* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly * in that case, because it is NM-specific variable */ - svSetValue (ifcfg, "DHCP_SEND_HOSTNAME", - nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no"); + svSetValueString (ifcfg, "DHCP_SEND_HOSTNAME", + nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no"); value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)); if (value) - svSetValue (ifcfg, "DHCP_CLIENT_ID", value); + svSetValueString (ifcfg, "DHCP_CLIENT_ID", value); timeout = nm_setting_ip_config_get_dhcp_timeout (s_ip4); tmp = timeout ? g_strdup_printf ("%d", timeout) : NULL; - svSetValue (ifcfg, "IPV4_DHCP_TIMEOUT", tmp); + svSetValueString (ifcfg, "IPV4_DHCP_TIMEOUT", tmp); g_free (tmp); } @@ -2174,7 +2174,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) route_metric = nm_setting_ip_config_get_route_metric (s_ip4); tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; - svSetValue (ifcfg, "IPV4_ROUTE_METRIC", tmp); + svSetValueString (ifcfg, "IPV4_ROUTE_METRIC", tmp); g_free (tmp); /* Static routes - route- file */ @@ -2217,14 +2217,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } else { route = nm_setting_ip_config_get_route (s_ip4, i); - svSetValue (routefile, addr_key, nm_ip_route_get_dest (route)); + svSetValueString (routefile, addr_key, nm_ip_route_get_dest (route)); memset (buf, 0, sizeof (buf)); netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf)); - svSetValue (routefile, netmask_key, &buf[0]); + svSetValueString (routefile, netmask_key, &buf[0]); - svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route)); + svSetValueString (routefile, gw_key, nm_ip_route_get_next_hop (route)); memset (buf, 0, sizeof (buf)); metric = nm_ip_route_get_metric (route); @@ -2232,7 +2232,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (routefile, metric_key); else { tmp = g_strdup_printf ("%u", (guint32) metric); - svSetValue (routefile, metric_key, tmp); + svSetValueString (routefile, metric_key, tmp); g_free (tmp); } } @@ -2258,7 +2258,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (timeout < 0) svUnsetValue (ifcfg, "ARPING_WAIT"); else if (timeout == 0) - svSetValue (ifcfg, "ARPING_WAIT", "0"); + svSetValueString (ifcfg, "ARPING_WAIT", "0"); else { /* Round the value up to next integer */ svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1); @@ -2345,13 +2345,13 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) ifcfg = svCreateFile (path); g_free (path); - svSetValue (ifcfg, "DEVICE", label); + svSetValueString (ifcfg, "DEVICE", label); addr = nm_setting_ip_config_get_address (s_ip4, i); - svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr)); + svSetValueString (ifcfg, "IPADDR", nm_ip_address_get_address (addr)); tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); - svSetValue (ifcfg, "PREFIX", tmp); + svSetValueString (ifcfg, "PREFIX", tmp); g_free (tmp); svWriteFile (ifcfg, 0644, NULL); @@ -2452,31 +2452,31 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) value = nm_setting_ip_config_get_method (s_ip6); g_assert (value); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { - svSetValue (ifcfg, "IPV6INIT", "no"); + svSetValueString (ifcfg, "IPV6INIT", "no"); svUnsetValue (ifcfg, "DHCPV6C"); return TRUE; } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "IPV6INIT", "yes"); - svSetValue (ifcfg, "IPV6_AUTOCONF", "yes"); + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "yes"); svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { const char *hostname; - svSetValue (ifcfg, "IPV6INIT", "yes"); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no"); - svSetValue (ifcfg, "DHCPV6C", "yes"); + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "no"); + svSetValueString (ifcfg, "DHCPV6C", "yes"); hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); if (hostname) - svSetValue (ifcfg, "DHCP_HOSTNAME", hostname); + svSetValueString (ifcfg, "DHCP_HOSTNAME", hostname); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { - svSetValue (ifcfg, "IPV6INIT", "yes"); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no"); + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "no"); svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { - svSetValue (ifcfg, "IPV6INIT", "yes"); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no"); + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "no"); svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { - svSetValue (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6INIT", "yes"); svUnsetValue (ifcfg, "DHCPV6C"); /* TODO */ } @@ -2499,9 +2499,9 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) nm_ip_address_get_address (addr), nm_ip_address_get_prefix (addr)); } - svSetValue (ifcfg, "IPV6ADDR", ip_str1->str); - svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str); - svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6)); + svSetValueString (ifcfg, "IPV6ADDR", ip_str1->str); + svSetValueString (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str); + svSetValueString (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6)); g_string_free (ip_str1, TRUE); g_string_free (ip_str2, TRUE); @@ -2516,7 +2516,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, addr_key); else { dns = nm_setting_ip_config_get_dns (s_ip6, i); - svSetValue (ifcfg, addr_key, dns); + svSetValueString (ifcfg, addr_key, dns); } g_free (addr_key); } @@ -2525,14 +2525,14 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) num = nm_setting_ip_config_get_num_dns_searches (s_ip6); if (num > 0) { char *ip4_domains; - ip4_domains = svGetValue (ifcfg, "DOMAIN"); + ip4_domains = svGetValueString (ifcfg, "DOMAIN"); searches = g_string_new (ip4_domains); for (i = 0; i < num; i++) { if (searches->len > 0) g_string_append_c (searches, ' '); g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i)); } - svSetValue (ifcfg, "DOMAIN", searches->str); + svSetValueString (ifcfg, "DOMAIN", searches->str); g_string_free (searches, TRUE); g_free (ip4_domains); } @@ -2540,26 +2540,26 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* handle IPV6_DEFROUTE */ /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ if (nm_setting_ip_config_get_never_default(s_ip6)) - svSetValue (ifcfg, "IPV6_DEFROUTE", "no"); + svSetValueString (ifcfg, "IPV6_DEFROUTE", "no"); else - svSetValue (ifcfg, "IPV6_DEFROUTE", "yes"); + svSetValueString (ifcfg, "IPV6_DEFROUTE", "yes"); svUnsetValue (ifcfg, "IPV6_PEERDNS"); svUnsetValue (ifcfg, "IPV6_PEERROUTES"); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "IPV6_PEERDNS", - nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes"); + svSetValueString (ifcfg, "IPV6_PEERDNS", + nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes"); - svSetValue (ifcfg, "IPV6_PEERROUTES", - nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes"); + svSetValueString (ifcfg, "IPV6_PEERROUTES", + nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes"); } - svSetValue (ifcfg, "IPV6_FAILURE_FATAL", - nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes"); + svSetValueString (ifcfg, "IPV6_FAILURE_FATAL", + nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes"); route_metric = nm_setting_ip_config_get_route_metric (s_ip6); tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; - svSetValue (ifcfg, "IPV6_ROUTE_METRIC", tmp); + svSetValueString (ifcfg, "IPV6_ROUTE_METRIC", tmp); g_free (tmp); /* IPv6 Privacy Extensions */ @@ -2567,14 +2567,14 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP"); switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){ case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: - svSetValue (ifcfg, "IPV6_PRIVACY", "no"); + svSetValueString (ifcfg, "IPV6_PRIVACY", "no"); break; case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: - svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041"); - svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", "yes"); + svSetValueString (ifcfg, "IPV6_PRIVACY", "rfc3041"); + svSetValueString (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", "yes"); break; case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: - svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041"); + svSetValueString (ifcfg, "IPV6_PRIVACY", "rfc3041"); break; default: break; @@ -2585,7 +2585,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (addr_gen_mode != NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) { tmp = nm_utils_enum_to_str (nm_setting_ip6_config_addr_gen_mode_get_type (), addr_gen_mode); - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", tmp); + svSetValueString (ifcfg, "IPV6_ADDR_GEN_MODE", tmp); g_free (tmp); } else { svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); @@ -2593,7 +2593,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* IPv6 tokenized interface identifier */ value = nm_setting_ip6_config_get_token (NM_SETTING_IP6_CONFIG (s_ip6)); - svSetValue (ifcfg, "IPV6_TOKEN", value); + svSetValueString (ifcfg, "IPV6_TOKEN", value); priority = nm_setting_ip_config_get_dns_priority (s_ip6); if (priority) @@ -2670,7 +2670,7 @@ write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) g_string_append_c (value, ' '); g_string_append (value, array->pdata[i]); } - svSetValueFull (ifcfg, "RES_OPTIONS", value->str); + svSetValue (ifcfg, "RES_OPTIONS", value->str); g_string_free (value, TRUE); } else svUnsetValue (ifcfg, "RES_OPTIONS"); diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index fbc5d1f9e..29bb8e97a 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -324,11 +324,11 @@ find_line (shvarFile *s, const char *key) return NULL; } -/* svGetValueFull() is identical to svGetValue() except that - * svGetValue() will never return an empty value (but %NULL instead). - * svGetValueFull() will return empty values if that is the value for the @key. */ +/* svGetValue() is identical to svGetValueString() except that + * svGetValueString() will never return an empty value (but %NULL instead). + * svGetValue() will return empty values if that is the value for the @key. */ char * -svGetValueFull (shvarFile *s, const char *key) +svGetValue (shvarFile *s, const char *key) { const char *line_val; char *value; @@ -350,11 +350,11 @@ svGetValueFull (shvarFile *s, const char *key) * be freed by the caller. */ char * -svGetValue (shvarFile *s, const char *key) +svGetValueString (shvarFile *s, const char *key) { char *value; - value = svGetValueFull (s, key); + value = svGetValue (s, key); if (value && !*value) { g_free (value); return NULL; @@ -376,7 +376,7 @@ svGetValueBoolean (shvarFile *s, const char *key, gint fallback) { gs_free char *tmp = NULL; - tmp = svGetValue (s, key); + tmp = svGetValueString (s, key); return svParseBoolean (tmp, fallback); } @@ -397,7 +397,7 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m gint64 result; int errsv; - tmp = svGetValueFull (s, key); + tmp = svGetValue (s, key); if (!tmp) { errno = 0; return fallback; @@ -414,10 +414,10 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m /*****************************************************************************/ -/* Same as svSetValue() but it preserves empty @value -- contrary to - * svSetValue() for which "" effectively means to remove the value. */ +/* Same as svSetValueString() but it preserves empty @value -- contrary to + * svSetValueString() for which "" effectively means to remove the value. */ void -svSetValueFull (shvarFile *s, const char *key, const char *value) +svSetValue (shvarFile *s, const char *key, const char *value) { gs_free char *newval_free = NULL; gs_free char *oldval = NULL; @@ -439,7 +439,7 @@ svSetValueFull (shvarFile *s, const char *key, const char *value) } value = svEscape (value, &newval_free); - oldval = svGetValueFull (s, key); + oldval = svGetValue (s, key); keyValue = g_strdup_printf ("%s=%s", key, value); if (!oldval) { @@ -467,9 +467,9 @@ svSetValueFull (shvarFile *s, const char *key, const char *value) * to the bottom of the file. */ void -svSetValue (shvarFile *s, const char *key, const char *value) +svSetValueString (shvarFile *s, const char *key, const char *value) { - svSetValueFull (s, key, value && value[0] ? value : NULL); + svSetValue (s, key, value && value[0] ? value : NULL); } void @@ -477,20 +477,19 @@ svSetValueInt64 (shvarFile *s, const char *key, gint64 value) { char buf[NM_DECIMAL_STR_MAX (value)]; - svSetValueFull (s, key, - nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value)); + svSetValue (s, key, nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value)); } void svSetValueBoolean (shvarFile *s, const char *key, gboolean value) { - svSetValueFull (s, key, value ? "yes" : "no"); + svSetValue (s, key, value ? "yes" : "no"); } void svUnsetValue (shvarFile *s, const char *key) { - svSetValueFull (s, key, NULL); + svSetValue (s, key, NULL); } /*****************************************************************************/ diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 9daa004d1..7525d17e1 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -45,8 +45,8 @@ shvarFile *svOpenFile (const char *name, GError **error); * pointing at the line containing the value. The char* returned MUST * be freed by the caller. */ +char *svGetValueString (shvarFile *s, const char *key); char *svGetValue (shvarFile *s, const char *key); -char *svGetValueFull (shvarFile *s, const char *key); gint svParseBoolean (const char *value, gint def); @@ -63,8 +63,8 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g * the key=value pair after that line. Otherwise, prepend the pair * to the top of the file. */ +void svSetValueString (shvarFile *s, const char *key, const char *value); void svSetValue (shvarFile *s, const char *key, const char *value); -void svSetValueFull (shvarFile *s, const char *key, const char *value); void svSetValueBoolean (shvarFile *s, const char *key, gboolean value); void svSetValueInt64 (shvarFile *s, const char *key, gint64 value); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 5000c2c7e..1704340c8 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -1789,7 +1789,7 @@ test_clear_master (void) g_assert_no_error (error); g_assert (f); - val = svGetValue (f, "BRIDGE"); + val = svGetValueString (f, "BRIDGE"); g_assert (!val); svCloseFile (f); } @@ -3014,7 +3014,7 @@ test_write_wifi_hidden (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "SSID_HIDDEN"); + val = svGetValueString (f, "SSID_HIDDEN"); g_assert (val); g_assert_cmpstr (val, ==, "yes"); g_free (val); @@ -3113,7 +3113,7 @@ test_write_wifi_mac_random (gconstpointer user_data) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "MAC_ADDRESS_RANDOMIZATION"); + val = svGetValueString (f, "MAC_ADDRESS_RANDOMIZATION"); g_assert_cmpstr (val, ==, write_expected); g_free (val); svCloseFile (f); @@ -3177,7 +3177,7 @@ test_write_wired_wake_on_lan (void) g_assert (f); /* re-read the file to check that the key was written. */ - val = svGetValue (f, "ETHTOOL_OPTS"); + val = svGetValueString (f, "ETHTOOL_OPTS"); g_assert (val); g_assert (strstr (val, "wol")); g_assert (strstr (val, "sopass 00:00:00:11:22:33")); @@ -3266,7 +3266,7 @@ test_write_wifi_band_a (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "BAND"); + val = svGetValueString (f, "BAND"); g_assert (val); g_assert_cmpstr (val, ==, "a"); g_free (val); @@ -3975,7 +3975,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) g_assert_no_error (error); g_assert (ifcfg); - written_ifcfg_gateway = svGetValue (ifcfg, "IPV6_DEFAULTGW"); + written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); svCloseFile (ifcfg); } @@ -4499,15 +4499,15 @@ test_write_wired_aliases (void) /* Create some pre-existing alias files, to make sure they get overwritten / deleted. */ ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":2"); - svSetValue (ifcfg, "DEVICE", "alias0:2"); - svSetValue (ifcfg, "IPADDR", "192.168.1.2"); + svSetValueString (ifcfg, "DEVICE", "alias0:2"); + svSetValueString (ifcfg, "IPADDR", "192.168.1.2"); svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":2", G_FILE_TEST_EXISTS)); ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":5"); - svSetValue (ifcfg, "DEVICE", "alias0:5"); - svSetValue (ifcfg, "IPADDR", "192.168.1.5"); + svSetValueString (ifcfg, "DEVICE", "alias0:5"); + svSetValueString (ifcfg, "IPADDR", "192.168.1.5"); svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); @@ -4628,41 +4628,41 @@ test_write_gateway (void) g_assert (f); /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ - val = svGetValue (f, "IPADDR"); + val = svGetValueString (f, "IPADDR"); g_assert (val); g_assert_cmpstr (val, ==, "1.1.1.3"); g_free (val); - val = svGetValue (f, "IPADDR1"); + val = svGetValueString (f, "IPADDR1"); g_assert (val); g_assert_cmpstr (val, ==, "2.2.2.5"); g_free (val); - val = svGetValue (f, "IPADDR0"); + val = svGetValueString (f, "IPADDR0"); g_assert (val == NULL); - val = svGetValue (f, "PREFIX"); + val = svGetValueString (f, "PREFIX"); g_assert (val); g_assert_cmpstr (val, ==, "24"); g_free (val); - val = svGetValue (f, "PREFIX1"); + val = svGetValueString (f, "PREFIX1"); g_assert (val); g_assert_cmpstr (val, ==, "24"); g_free (val); - val = svGetValue (f, "PREFIX0"); + val = svGetValueString (f, "PREFIX0"); g_assert (val == NULL); - val = svGetValue (f, "GATEWAY"); + val = svGetValueString (f, "GATEWAY"); g_assert (val); g_assert_cmpstr (val, ==, "1.1.1.254"); g_free (val); - val = svGetValue (f, "GATEWAY0"); + val = svGetValueString (f, "GATEWAY0"); g_assert (val == NULL); - val = svGetValue (f, "GATEWAY1"); + val = svGetValueString (f, "GATEWAY1"); g_assert (val == NULL); svCloseFile (f); @@ -4756,7 +4756,7 @@ test_write_wifi_open (void) g_assert_no_error (error); g_assert (ifcfg != NULL); - tmp = svGetValue (ifcfg, "ESSID"); + tmp = svGetValueString (ifcfg, "ESSID"); g_assert_cmpstr (tmp, ==, "Test SSID"); g_free (tmp); @@ -6506,11 +6506,11 @@ test_write_wifi_dynamic_wep_leap (void) ifcfg = svOpenFile (testfile, &error); g_assert_no_error (error); g_assert (ifcfg); - tmp = svGetValue (ifcfg, "SECURITYMODE"); + tmp = svGetValueString (ifcfg, "SECURITYMODE"); g_assert_cmpstr (tmp, ==, NULL); g_free (tmp); - tmp = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS"); + tmp = svGetValueString (ifcfg, "IEEE_8021X_EAP_METHODS"); g_assert_cmpstr (tmp, ==, "LEAP"); g_free (tmp); @@ -6672,13 +6672,13 @@ test_write_wired_ctc_dhcp (void) g_assert_no_error (error); g_assert (ifcfg); - tmp = svGetValue (ifcfg, "CTCPROT"); + tmp = svGetValueString (ifcfg, "CTCPROT"); g_assert (tmp); g_assert_cmpstr (tmp, ==, "0"); g_free (tmp); /* And that it's not in the generic OPTIONS string */ - tmp = svGetValue (ifcfg, "OPTIONS"); + tmp = svGetValueString (ifcfg, "OPTIONS"); g_assert (tmp == NULL); g_free (tmp); @@ -8421,7 +8421,7 @@ test_write_fcoe_mode (gconstpointer user_data) g_assert_no_error (error); g_assert (ifcfg); - written_mode = svGetValue (ifcfg, "DCB_APP_FCOE_MODE"); + written_mode = svGetValueString (ifcfg, "DCB_APP_FCOE_MODE"); svCloseFile (ifcfg); g_assert_cmpstr (written_mode, ==, expected_mode); g_free (written_mode); @@ -8558,11 +8558,11 @@ test_write_team_master (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "DEVICETYPE"); + val = svGetValueString (f, "DEVICETYPE"); g_assert (val); g_assert_cmpstr (val, ==, "Team"); g_free (val); - val = svGetValue (f, "TEAM_CONFIG"); + val = svGetValueString (f, "TEAM_CONFIG"); g_assert (val); g_assert_cmpstr (val, ==, expected_config); g_free (val); @@ -8652,16 +8652,16 @@ test_write_team_port (void) g_assert (f); /* re-read the file to check that what key was written. */ - val = svGetValue (f, "TYPE"); + val = svGetValueString (f, "TYPE"); g_assert (!val); - val = svGetValue (f, "DEVICETYPE"); + val = svGetValueString (f, "DEVICETYPE"); g_assert (val); g_assert_cmpstr (val, ==, "TeamPort"); g_free (val); - val = svGetValue (f, "TEAM_PORT_CONFIG"); + val = svGetValueString (f, "TEAM_PORT_CONFIG"); g_assert_cmpstr (val, ==, expected_config); g_free (val); - val = svGetValue (f, "TEAM_MASTER"); + val = svGetValueString (f, "TEAM_MASTER"); g_assert_cmpstr (val, ==, "team0"); g_free (val); svCloseFile (f); From 806ffbbe1431c2be5a3d1da8df44610016653028 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 14:22:07 +0100 Subject: [PATCH 19/39] ifcfg-rh: cleanup svEscape() Use size_t type for string length and have character sets as #define. --- src/settings/plugins/ifcfg-rh/shvar.c | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 29bb8e97a..e727e0a7a 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -85,28 +85,26 @@ svParseBoolean (const char *value, gint fallback) /*****************************************************************************/ -/* create a new string with all necessary characters escaped. - * caller must free returned string - */ -static const char escapees[] = "\"'\\$~`"; /* must be escaped */ -static const char spaces[] = " \t|&;()<>"; /* only require "" */ -static const char newlines[] = "\n\r"; /* will be removed */ +#define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ +#define ESC_SPACES " \t|&;()<>" /* only require "" */ +#define ESC_NEWLINES "\n\r" /* will be removed */ const char * svEscape (const char *s, char **to_free) { char *new; - int i, j, mangle = 0, space = 0, newline = 0; - int newlen, slen; + int mangle = 0, space = 0, newline = 0; + int newlen; + size_t i, j, slen; slen = strlen (s); for (i = 0; i < slen; i++) { - if (strchr (escapees, s[i])) + if (strchr (ESC_ESCAPEES, s[i])) mangle++; - if (strchr (spaces, s[i])) + if (strchr (ESC_SPACES, s[i])) space++; - if (strchr (newlines, s[i])) + if (strchr (ESC_NEWLINES, s[i])) newline++; } if (!mangle && !space && !newline) { @@ -114,22 +112,23 @@ svEscape (const char *s, char **to_free) return s; } - newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ + newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ new = g_malloc (newlen); j = 0; new[j++] = '"'; for (i = 0; i < slen; i++) { - if (strchr (newlines, s[i])) + if (strchr (ESC_NEWLINES, s[i])) continue; - if (strchr (escapees, s[i])) { + if (strchr (ESC_ESCAPEES, s[i])) { new[j++] = '\\'; } new[j++] = s[i]; } new[j++] = '"'; new[j++] = '\0'; - g_assert (j == slen + mangle - newline + 3); + + nm_assert (j == slen + mangle - newline + 3); *to_free = new; return new; From afc394b969fac882066eedb0876f680ee52183ee Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 14:44:31 +0100 Subject: [PATCH 20/39] ifcfg-rh: assert that keys are valid shell names --- src/settings/plugins/ifcfg-rh/shvar.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index e727e0a7a..88e57015b 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -85,6 +85,21 @@ svParseBoolean (const char *value, gint fallback) /*****************************************************************************/ +static gboolean +_shell_is_name (const char *key) +{ + /* whether @key is a valid identifier (name). */ + if (!key) + return FALSE; + if ( !g_ascii_isalpha (key[0]) + && key[0] != '_') + return FALSE; + return NM_STRCHAR_ALL (&key[1], ch, + g_ascii_isalnum (ch) || ch == '_'); +} + +/*****************************************************************************/ + #define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ #define ESC_SPACES " \t|&;()<>" /* only require "" */ #define ESC_NEWLINES "\n\r" /* will be removed */ @@ -312,6 +327,8 @@ find_line (shvarFile *s, const char *key) const char *line; gsize len; + nm_assert (_shell_is_name (key)); + len = strlen (key); for (s->current = s->lineList; s->current; s->current = s->current->next) { From 85beac6dd430e8d5b4c8eb4c4fbdd5e24c13e825 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 14:58:58 +0100 Subject: [PATCH 21/39] ifcfg-rh: allow leading spaces before variable names --- src/settings/plugins/ifcfg-rh/shvar.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 88e57015b..ae1dd5681 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -333,6 +333,11 @@ find_line (shvarFile *s, const char *key) for (s->current = s->lineList; s->current; s->current = s->current->next) { line = s->current->data; + + /* skip over leading spaces */ + while (g_ascii_isspace (line[0])) + line++; + if (!strncmp (key, line, len) && line[len] == '=') return line + len + 1; } From 1ae62854f58c3e66a598a9711c0d0dd959cf330a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 16:26:00 +0100 Subject: [PATCH 22/39] ifcfg-rh: refactor svUnescape() Move the g_strchomp() inside svUnescape(). It is part of the escaping process (although of course wrong to do, because it accepts "FOO= bar". That will be fixed later). Thereby, change the signature to allow in the future to do unescape without additional copy. --- src/settings/plugins/ifcfg-rh/shvar.c | 32 ++++++++------ src/settings/plugins/ifcfg-rh/shvar.h | 5 +-- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 43 ++----------------- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index ae1dd5681..5fe59ef8c 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -150,23 +150,31 @@ svEscape (const char *s, char **to_free) } /* remove escaped characters in place */ -void -svUnescape (char *s) +const char * +svUnescape (const char *value, char **to_free) { size_t len, idx_rd = 0, idx_wr = 0; char c; + char *s; + + nm_assert (value); + nm_assert (to_free); + + /* TODO: avoid copying the string if there is nothing to do. */ + s = g_strchomp (g_strdup (value)); + *to_free = s; len = strlen (s); if (len < 2) { if (s[0] == '\\') s[0] = '\0'; - return; + return s; } if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { if (len == 2) { s[0] = '\0'; - return; + return s; } if (len == 3) { if (s[1] == '\\') { @@ -175,7 +183,7 @@ svUnescape (char *s) s[0] = s[1]; s[1] = '\0'; } - return; + return s; } s[--len] = '\0'; idx_rd = 1; @@ -184,10 +192,10 @@ svUnescape (char *s) char *p = strchr (s, '\\'); if (!p) - return; + return s; if (p[1] == '\0') { p[0] = '\0'; - return; + return s; } idx_wr = idx_rd = (p - s); } @@ -199,7 +207,7 @@ svUnescape (char *s) if (c == '\\') { if (s[idx_rd] == '\0') { s[idx_wr] = '\0'; - return; + return s; } s[idx_wr++] = s[idx_rd++]; continue; @@ -207,6 +215,7 @@ svUnescape (char *s) s[idx_wr++] = c; } s[idx_wr] = '\0'; + return s; } /*****************************************************************************/ @@ -352,7 +361,7 @@ char * svGetValue (shvarFile *s, const char *key) { const char *line_val; - char *value; + char *copied; g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); @@ -361,9 +370,8 @@ svGetValue (shvarFile *s, const char *key) if (!line_val) return NULL; - value = g_strchomp (g_strdup (line_val)); - svUnescape (value); - return value; + line_val = svUnescape (line_val, &copied); + return copied ?: g_strdup (line_val); } /* Get the value associated with the key, and leave the current pointer diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 7525d17e1..43e796d0c 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -81,10 +81,7 @@ gboolean svWriteFile (shvarFile *s, int mode, GError **error); /* Close the file descriptor (if open) and free the shvarFile. */ void svCloseFile (shvarFile *s); -/* Return @s unmodified or an escaped string */ const char *svEscape (const char *s, char **to_free); - -/* Unescape a string in-place */ -void svUnescape (char *s); +const char *svUnescape (const char *s, char **to_free); #endif /* _SHVAR_H */ diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 1704340c8..ef43f2b79 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8695,50 +8695,13 @@ test_read_team_port_empty_config (void) g_object_unref (connection); } -/* Old algorithm for "remove escaped characters in place". - * - * This function is obsolete because it has O(n^2) runtime - * complexity and got replaced. Keep it here for testing, - * that both functions behave identical. - **/ -static void -svUnescape_On2 (char *s) -{ - int len, i; - - len = strlen(s); - if (len >= 2 && (s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { - i = len - 2; - if (i == 0) - s[0] = '\0'; - else { - memmove(s, s+1, i); - s[i+1] = '\0'; - len = i; - } - } - for (i = 0; i < len; i++) { - if (s[i] == '\\') { - memmove(s+i, s+i+1, len-(i+1)); - len--; - } - s[len] = '\0'; - } -} - static void test_svUnescape_assert (const char *str) { - char *s1 = g_strdup (str); - char *s2 = g_strdup (str); + gs_free char *to_free = NULL; + const char *s; - svUnescape (s1); - svUnescape_On2 (s2); - - g_assert_cmpstr (s1, ==, s2); - - g_free (s1); - g_free (s2); + s = svUnescape (str, &to_free); } static void From 9719988674a5ed045f89272061f9295a7f7c4099 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 16:22:54 +0100 Subject: [PATCH 23/39] ifcfg-rh: get rid of the internal "current" pointer It was not used and it is bad style. Especially, because in the next commit we want to remove multiple definitions of a key. Thus, we usually always iterate until the end. --- src/settings/plugins/ifcfg-rh/shvar.c | 113 +++++++++++++++----------- 1 file changed, 66 insertions(+), 47 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 5fe59ef8c..d4e74fc31 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -44,7 +44,6 @@ struct _shvarFile { char *fileName; /* read-only */ int fd; /* read-only */ GList *lineList; /* read-only */ - GList *current; /* set implicitly or explicitly, points to element of lineList */ gboolean modified; /* ignore */ }; @@ -330,30 +329,60 @@ svCreateFile (const char *name) /*****************************************************************************/ -static const char * -find_line (shvarFile *s, const char *key) +static const GList * +shlist_find (const GList *current, const char *key, const char **out_value) { - const char *line; gsize len; nm_assert (_shell_is_name (key)); - len = strlen (key); + if (current) { + len = strlen (key); + do { + const char *line = current->data; - for (s->current = s->lineList; s->current; s->current = s->current->next) { - line = s->current->data; + /* skip over leading spaces */ + while (g_ascii_isspace (line[0])) + line++; - /* skip over leading spaces */ - while (g_ascii_isspace (line[0])) - line++; - - if (!strncmp (key, line, len) && line[len] == '=') - return line + len + 1; + if (!strncmp (key, line, len) && line[len] == '=') { + NM_SET_OUT (out_value, line + len + 1); + return current; + } + current = current->next; + } while (current); } + NM_SET_OUT (out_value, NULL); return NULL; } +static void +shlist_delete (GList **head, GList *current) +{ + nm_assert (head && *head); + nm_assert (current); + nm_assert (current->data); + nm_assert (g_list_position (*head, current) >= 0); + + g_free (current->data); + *head = g_list_delete_link (*head, current); +} + +static char * +line_construct (const char *key, const char *value) +{ + gs_free char *newval_free = NULL; + + nm_assert (_shell_is_name (key)); + nm_assert (value); + + return g_strdup_printf ("%s=%s", key, + svEscape (value, &newval_free)); +} + +/*****************************************************************************/ + /* svGetValue() is identical to svGetValueString() except that * svGetValueString() will never return an empty value (but %NULL instead). * svGetValue() will return empty values if that is the value for the @key. */ @@ -361,17 +390,16 @@ char * svGetValue (shvarFile *s, const char *key) { const char *line_val; - char *copied; + char *to_free; g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); - line_val = find_line (s, key); - if (!line_val) + if (!shlist_find (s->lineList, key, &line_val)) return NULL; - line_val = svUnescape (line_val, &copied); - return copied ?: g_strdup (line_val); + line_val = svUnescape (line_val, &to_free); + return to_free ?: g_strdup (line_val); } /* Get the value associated with the key, and leave the current pointer @@ -448,46 +476,38 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m void svSetValue (shvarFile *s, const char *key, const char *value) { - gs_free char *newval_free = NULL; - gs_free char *oldval = NULL; - char *keyValue; + gs_free char *oldval_free = NULL; + const char *oldval; + GList *current; g_return_if_fail (s != NULL); g_return_if_fail (key != NULL); + nm_assert (_shell_is_name (key)); + if (!value) { - /* delete value */ - if (find_line (s, key)) { - /* delete line */ - s->lineList = g_list_remove_link (s->lineList, s->current); - g_free (s->current->data); - g_list_free_1 (s->current); + if ((current = (GList *) shlist_find (s->lineList, key, NULL))) { s->modified = TRUE; + shlist_delete (&s->lineList, current); } return; } - value = svEscape (value, &newval_free); - oldval = svGetValue (s, key); + current = (GList *) shlist_find (s->lineList, key, &oldval); - keyValue = g_strdup_printf ("%s=%s", key, value); - if (!oldval) { - /* append line */ - s->lineList = g_list_append (s->lineList, keyValue); + if (!current) { + s->lineList = g_list_append (s->lineList, + line_construct (key, value)); s->modified = TRUE; return; } - if (strcmp (oldval, value) != 0) { - /* change line */ - if (s->current) { - g_free (s->current->data); - s->current->data = keyValue; - } else - s->lineList = g_list_append (s->lineList, keyValue); + oldval = svUnescape (oldval, &oldval_free); + if (!nm_streq (oldval, value)) { + g_free (current->data); + current->data = line_construct (key, value); s->modified = TRUE; - } else - g_free (keyValue); + } } /* Set the variable equal to the value . @@ -534,6 +554,7 @@ svWriteFile (shvarFile *s, int mode, GError **error) { FILE *f; int tmpfd; + const GList *current; if (s->modified) { if (s->fd == -1) @@ -566,10 +587,8 @@ svWriteFile (shvarFile *s, int mode, GError **error) } f = fdopen (tmpfd, "w"); fseek (f, 0, SEEK_SET); - for (s->current = s->lineList; s->current; s->current = s->current->next) { - char *line = s->current->data; - fprintf (f, "%s\n", line); - } + for (current = s->lineList; current; current = current->next) + fprintf (f, "%s\n", (const char *) current->data); fclose (f); } @@ -587,6 +606,6 @@ svCloseFile (shvarFile *s) close (s->fd); g_free (s->fileName); - g_list_free_full (s->lineList, g_free); /* implicitly frees s->current */ + g_list_free_full (s->lineList, g_free); g_slice_free (shvarFile, s); } From f3c7d009b5bed7ac51e8a3e25dc72b0cfb42d6a3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 16:22:54 +0100 Subject: [PATCH 24/39] ifcfg-rh: handle multiple definitions of the same key When - reading a key that is defined multiple times, accept the last occurrence. - when deleting such a key, delete all occurrences. - when overwriting such a key, overwrite the last occurrence and delete any previous definitions. --- src/settings/plugins/ifcfg-rh/shvar.c | 55 +++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index d4e74fc31..f1973ee8d 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -369,6 +369,27 @@ shlist_delete (GList **head, GList *current) *head = g_list_delete_link (*head, current); } +static gboolean +shlist_delete_all (GList **head, const char *key, gboolean including_last) +{ + GList *current, *last; + gboolean changed = FALSE; + + last = (GList *) shlist_find (*head, key, NULL); + if (last) { + while ((current = (GList *) shlist_find (last->next, key, NULL))) { + shlist_delete (head, last); + changed = TRUE; + last = current; + } + if (including_last) { + shlist_delete (head, last); + changed = TRUE; + } + } + return changed; +} + static char * line_construct (const char *key, const char *value) { @@ -389,16 +410,24 @@ line_construct (const char *key, const char *value) char * svGetValue (shvarFile *s, const char *key) { + const GList *current; const char *line_val; + const char *last_val = NULL; char *to_free; g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); - if (!shlist_find (s->lineList, key, &line_val)) + current = s->lineList; + while ((current = shlist_find (current, key, &line_val))) { + last_val = line_val; + current = current->next; + } + + if (!last_val) return NULL; - line_val = svUnescape (line_val, &to_free); + line_val = svUnescape (last_val, &to_free); return to_free ?: g_strdup (line_val); } @@ -477,8 +506,9 @@ void svSetValue (shvarFile *s, const char *key, const char *value) { gs_free char *oldval_free = NULL; - const char *oldval; - GList *current; + const char *oldval, *oldval_tmp; + GList *current, *last; + gboolean has_multiple = FALSE; g_return_if_fail (s != NULL); g_return_if_fail (key != NULL); @@ -486,10 +516,8 @@ svSetValue (shvarFile *s, const char *key, const char *value) nm_assert (_shell_is_name (key)); if (!value) { - if ((current = (GList *) shlist_find (s->lineList, key, NULL))) { + if (shlist_delete_all (&s->lineList, key, TRUE)) s->modified = TRUE; - shlist_delete (&s->lineList, current); - } return; } @@ -502,12 +530,25 @@ svSetValue (shvarFile *s, const char *key, const char *value) return; } + last = current; + while ((current = (GList *) shlist_find (current->next, key, &oldval_tmp))) { + last = current; + oldval = oldval_tmp; + has_multiple = TRUE; + } + current = last; + oldval = svUnescape (oldval, &oldval_free); if (!nm_streq (oldval, value)) { g_free (current->data); current->data = line_construct (key, value); s->modified = TRUE; } + + if (has_multiple) { + if (shlist_delete_all (&s->lineList, key, FALSE)) + s->modified = TRUE; + } } /* Set the variable equal to the value . From 7b548fb9a806b0c2baf7f381d82c1c0ec484aee6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 17:48:15 +0100 Subject: [PATCH 25/39] ifcfg-rh: rework parsing of shell (svUnescape()) Better support parsing of shell. Now we support: - combining values, like FOO=a"b" FOO=$'\n'b - bash style ANSI C quotation ($''). This will allow us to properly handle newlines in string values. - comments at the end of a line (after whitespace) FOO=val #comment Note that this is different from a # without space FOO=val#with#hashes - trailing spaces are ignored like FOO=a[space] FOR=[space] - history expansion via ! is not done (this is not new). We don't support: - line continuation like FOO=' ' FOO=a\ b - any form of shell expansion via $, ``. FOO="$a" Such values are recognized to name a variable FOO, but with an empty value, like FOO=%{nil} which is not the same as a valid empty value FOO= - any other form of (unquoted) shell meta characters, like ; < > ( ). This especially means, that the command invocations are invalid, like ls -1 LANG=C ls -1 FOO1=a; FOO2=b This also means, that spaces immidiately after the assignment are invalid: FOO= val Also, svUnescape() can now return %NULL to signal an invalid line like FOO=' --- src/settings/plugins/ifcfg-rh/shvar.c | 350 +++++++++++++++--- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 305 ++++++++++++--- 2 files changed, 550 insertions(+), 105 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index f1973ee8d..5929811a1 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -148,73 +148,313 @@ svEscape (const char *s, char **to_free) return new; } -/* remove escaped characters in place */ +static gboolean +_ch_octal_is (char ch) +{ + return ch >= '0' && ch < '8'; +} + +static guint8 +_ch_octal_get (char ch) +{ + nm_assert (_ch_octal_is (ch)); + return (ch - '0'); +} + +static gboolean +_ch_hex_is (char ch) +{ + return g_ascii_isxdigit (ch); +} + +static guint8 +_ch_hex_get (char ch) +{ + nm_assert (_ch_hex_is (ch)); + return ch <= '9' ? ch - '0' : (ch & 0x4F) - 'A' + 10; +} + +static void +_gstr_init (GString **str, const char *value, gsize i) +{ + nm_assert (str); + nm_assert (value); + + if (!(*str)) { + /* if @str is not yet initialized, it allocates + * a new GString and copies @i characters from + * @value over. + * + * Unescaping usually does not extend the length of a string, + * so we might be tempted to allocate a fixed buffer of length + * (strlen(value)+CONST). + * However, due to $'\Ux' escapes, the maxium length is some + * (FACTOR*strlen(value) + CONST), which is non trivial to get + * right in all cases. Also, we would have to provision for the + * very unlikely extreme case. + * Instead, use a GString buffer which can grow as needed. But for an + * initial guess, strlen(value) is a good start */ + *str = g_string_new_len (NULL, strlen (value) + 3); + if (i) + g_string_append_len (*str, value, i); + } +} + const char * svUnescape (const char *value, char **to_free) { - size_t len, idx_rd = 0, idx_wr = 0; - char c; - char *s; + gsize i, j; + nm_auto_free_gstring GString *str = NULL; + + /* we handle bash syntax here (note that ifup has #!/bin/bash. + * Thus, see https://www.gnu.org/software/bash/manual/html_node/Quoting.html#Quoting */ + + /* @value shall start with the first character after "FOO=" */ nm_assert (value); nm_assert (to_free); - /* TODO: avoid copying the string if there is nothing to do. */ - s = g_strchomp (g_strdup (value)); - *to_free = s; + /* we don't expect any newlines. They must be filtered out before-hand. + * We also don't support line continuation. */ + nm_assert (!NM_STRCHAR_ANY (value, ch, ch == '\n')); - len = strlen (s); - if (len < 2) { - if (s[0] == '\\') - s[0] = '\0'; - return s; + i = 0; + while (TRUE) { + + if (value[i] == '\0') + goto out_value; + + if ( g_ascii_isspace (value[i]) + || value[i] == ';') { + gboolean has_semicolon = (value[i] == ';'); + + /* starting with space is only allowed, if the entire + * string consists of spaces (possibly terminated by a comment). + * This disallows for example + * LANG=C ls -1 + * LANG= ls -1 + * but allows + * LANG= #comment + * + * As a special case, we also allow one trailing semicolon, as long + * it is only followed by whitespace or a #-comment. + * FOO=; + * FOO=a; + * FOO=b ; #hallo + */ + j = i + 1; + while ( g_ascii_isspace (value[j]) + || ( !has_semicolon + && (has_semicolon = (value[j] == ';')))) + j++; + if (!NM_IN_SET (value[j], '\0', '#')) + goto out_error; + goto out_value; + } + + if (value[i] == '\\') { + /* backslash escape */ + _gstr_init (&str, value, i); + i++; + if (G_UNLIKELY (value[i] == '\0')) { + /* we don't support line continuation */ + goto out_error; + } + g_string_append_c (str, value[i]); + i++; + goto loop1_next; + } + + if (value[i] == '\'') { + /* single quotes */ + _gstr_init (&str, value, i); + i++; + j = i; + while (TRUE) { + if (value[j] == '\0') { + /* unterminated single quote. We don't support line continuation */ + goto out_error; + } + if (value[j] == '\'') + break; + j++; + } + g_string_append_len (str, &value[i], j - i); + i = j + 1; + goto loop1_next; + } + + if (value[i] == '"') { + /* double quotes */ + _gstr_init (&str, value, i); + i++; + while (TRUE) { + if (value[i] == '"') { + i++; + break; + } + if (value[i] == '\0') { + /* unterminated double quote. We don't support line continuation. */ + goto out_error; + } + if (NM_IN_SET (value[i], '`', '$')) { + /* we don't support shell expansion. */ + goto out_error; + } + if (value[i] == '\\') { + i++; + if (value[i] == '\0') { + /* we don't support line continuation */ + goto out_error; + } + if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) { + /* TODO: svEscape() is not yet ready to handle properly treating + * double quotes. */ + //g_string_append_c (str, '\\'); + } + } + g_string_append_c (str, value[i]); + i++; + } + goto loop1_next; + } + + if ( value[i] == '$' + && value[i + 1] == '\'') { + /* ANSI-C Quoting */ + _gstr_init (&str, value, i); + i += 2; + while (TRUE) { + char ch; + + if (value[i] == '\'') { + i++; + break; + } + if (value[i] == '\0') { + /* unterminated double quote. We don't support line continuation. */ + goto out_error; + } + if (value[i] == '\\') { + + i++; + if (value[i] == '\0') { + /* we don't support line continuation */ + goto out_error; + } + switch (value[i]) { + case 'a': ch = '\a'; break; + case 'b': ch = '\b'; break; + case 'e': ch = '\e'; break; + case 'E': ch = '\E'; break; + case 'f': ch = '\f'; break; + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'v': ch = '\v'; break; + case '?': ch = '\?'; break; + case '"': ch = '"'; break; + case '\\': ch = '\\'; break; + case '\'': ch = '\''; break; + default: + if (_ch_octal_is (value[i])) { + guint v; + + v = _ch_octal_get (value[i]); + i++; + if (_ch_octal_is (value[i])) { + v = (v * 8) + _ch_octal_get (value[i]); + i++; + if (_ch_octal_is (value[i])) { + v = (v * 8) + _ch_octal_get (value[i]); + i++; + } + } + /* like bash, we cut too large numbers off. E.g. A=$'\772' becomes 0xfa */ + g_string_append_c (str, (guint8) v); + } else if (NM_IN_SET (value[i], 'x', 'u', 'U')) { + const char escape_type = value[i]; + int max_digits = escape_type == 'x' ? 2 : escape_type == 'u' ? 4 : 8; + guint64 v; + + i++; + if (!_ch_hex_is (value[i])) { + /* missing hex value after "\x" escape. This is treated like no escaping. */ + g_string_append_c (str, '\\'); + g_string_append_c (str, escape_type); + } else { + v = _ch_hex_get (value[i]); + i++; + + while (--max_digits > 0) { + if (!_ch_hex_is (value[i])) + break; + v = v * 16 + _ch_hex_get (value[i]); + i++; + } + if (escape_type == 'x') + g_string_append_c (str, v); + else { + /* we treat the unicode escapes as utf-8 encoded values. */ + g_string_append_unichar (str, v); + } + } + } else { + g_string_append_c (str, '\\'); + g_string_append_c (str, value[i]); + i++; + } + goto loop_ansic_next; + } + } else + ch = value[i]; + g_string_append_c (str, ch); + i++; +loop_ansic_next: ; + } + goto loop1_next; + } + + if (NM_IN_SET (value[i], '|', '&', '(', ')', '<', '>')) { + /* shell metacharacters are not supported without quoting. + * Note that ';' is already handled above. */ + goto out_error; + } + + /* an unquoted, regular character. Just consume it directly. */ + if (str) + g_string_append_c (str, value[i]); + i++; + +loop1_next: ; } - if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { - if (len == 2) { - s[0] = '\0'; - return s; - } - if (len == 3) { - if (s[1] == '\\') { - s[0] = '\0'; - } else { - s[0] = s[1]; - s[1] = '\0'; - } - return s; - } - s[--len] = '\0'; - idx_rd = 1; + nm_assert_not_reached (); + +out_value: + if (str) { + *to_free = g_string_free (str, FALSE); + str = NULL; + return *to_free; + } else if (i == 0) { + *to_free = NULL; + /* we could just return "", but I prefer returning a + * pointer into @value for consistency. Thus, seek to the + * end. */ + while (value[0]) + value++; + return value; + } else if (value[i] != '\0') { + *to_free = g_strndup (value, i); + return *to_free; } else { - /* seek for the first escape... */ - char *p = strchr (s, '\\'); - - if (!p) - return s; - if (p[1] == '\0') { - p[0] = '\0'; - return s; - } - idx_wr = idx_rd = (p - s); + *to_free = NULL; + return value; } - /* idx_rd points to the first escape. Walk the string and shift the - * characters from idx_rd to idx_wr. - */ - while ((c = s[idx_rd++])) { - if (c == '\\') { - if (s[idx_rd] == '\0') { - s[idx_wr] = '\0'; - return s; - } - s[idx_wr++] = s[idx_rd++]; - continue; - } - s[idx_wr++] = c; - } - s[idx_wr] = '\0'; - return s; +out_error: + *to_free = NULL; + return NULL; } /*****************************************************************************/ @@ -539,7 +779,7 @@ svSetValue (shvarFile *s, const char *key, const char *value) current = last; oldval = svUnescape (oldval, &oldval_free); - if (!nm_streq (oldval, value)) { + if (!nm_streq0 (oldval, value)) { g_free (current->data); current->data = line_construct (key, value); s->modified = TRUE; diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index ef43f2b79..59d20e078 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -365,8 +365,8 @@ test_read_variables_corner_cases (void) /* ===== CONNECTION SETTING ===== */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "\""); - g_assert_cmpstr (nm_setting_connection_get_zone (s_con), ==, "'"); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-variables-corner-cases-1"); + g_assert_cmpstr (nm_setting_connection_get_zone (s_con), ==, NULL); g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); g_assert (nm_setting_connection_get_autoconnect (s_con)); @@ -451,7 +451,7 @@ test_read_unrecognized (void) /* ===== CONNECTION SETTING ===== */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "U Can't Touch This"); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-unrecognized"); g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, expected_timestamp); g_object_unref (connection); @@ -8695,71 +8695,276 @@ test_read_team_port_empty_config (void) g_object_unref (connection); } +/*****************************************************************************/ + +static const char * +_svUnescape (const char *str, char **to_free) +{ + const char *s; + + g_assert (str); + g_assert (to_free); + + s = svUnescape (str, to_free); + if (*to_free) + g_assert (s == *to_free); + else { + g_assert ( s == NULL + || (s >= str && s <= strchr (str, '\0'))); + } + return s; +} + +typedef struct { + const char *val; + const char *exp; + bool can_concat:1; + bool needs_ascii_separator:1; +} UnescapeTestData; + static void -test_svUnescape_assert (const char *str) +do_svUnescape_assert (const char *str, const char *expected) { gs_free char *to_free = NULL; const char *s; - s = svUnescape (str, &to_free); + s = _svUnescape (str, &to_free); + g_assert_cmpstr (s, ==, expected); +} + +static void +do_svUnescape_combine_ansi_append (GString *str_val, GString *str_exp, const UnescapeTestData *data, gboolean honor_needs_ascii_separator) +{ + g_string_append (str_val, data->val); + g_string_append (str_exp, data->exp); + if (honor_needs_ascii_separator && data->needs_ascii_separator) { + /* the string has an open escape sequence. We must ensure that when + * combining it with another sequence, that they don't merge into + * something diffent. for example "\xa" + "a" must not result in + * "\xaa". Instead, we add a space in between to get "\xa a". */ + g_string_append (str_val, " "); + g_string_append (str_exp, " "); + } +} + +static void +do_svUnescape_combine_ansi (GString *str_val, GString *str_exp, const UnescapeTestData *data_ansi, gsize data_len, gssize idx) +{ + gsize i, j; + + g_string_set_size (str_val, 0); + g_string_set_size (str_exp, 0); + g_string_append (str_val, "$'"); + if (idx < 0) { + for (i = -idx; i > 0; i--) { + j = nmtst_get_rand_int () % data_len; + if (!data_ansi[j].can_concat) { + i++; + continue; + } + do_svUnescape_combine_ansi_append (str_val, str_exp, &data_ansi[j], i > 1); + } + } else { + g_assert_cmpint (idx, <, data_len); + do_svUnescape_combine_ansi_append (str_val, str_exp, &data_ansi[idx], FALSE); + } + g_string_append (str_val, "'"); } static void test_svUnescape (void) { - int len, repeat, i, k; - GRand *r = g_rand_new (); - guint32 seed = g_random_int (); +#define V0(v_value, v_expected) { .val = ""v_value"", .exp = v_expected, .can_concat = FALSE, } +#define V1(v_value, v_expected) { .val = ""v_value"", .exp = v_expected, .can_concat = !!v_expected, } +#define V2(v_value, v_expected) { .val = ""v_value"", .exp = v_expected, .can_concat = TRUE, .needs_ascii_separator = TRUE, } + const UnescapeTestData data_full[] = { + V1 ("", ""), + V0 ("'", NULL), + V1 ("'x'", "x"), + V1 ("' '", " "), + V1 ("'x'", "x"), + V0 ("\"", NULL), + V0 ("\\", NULL), + V0 (" ", ""), + V0 (" ", ""), + V0 ("a; #", "a"), + V0 (" ; #", ""), + V0 ("; ", ""), + V0 ("; ;", NULL), + V0 (" ; a #", NULL), + V0 (" ; a;; #", NULL), + V0 ("a; ; #", NULL), + V0 ("\t # ", ""), + V0 ("\t #a", ""), + V0 ("\t #a\r", ""), + V0 ("\r", ""), + V0 ("ab\r", "ab"), + V0 ("a'b'\r ", "ab"), + V0 ("a'b' \r", "ab"), + V0 ("a#b", "a#b"), + V0 ("#b", "#b"), + V1 ("\'some string\'", "some string"), + V0 ("Bob outside LAN", NULL), + V1 ("x", "x"), + V1 ("'{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }'", + "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"), + V1 ("x\"\"b", "xb"), + V1 ("x\"c\"b", "xcb"), + V1 ("\"c\"b", "cb"), + V1 ("\"c\"\\'b", "c'b"), + V1 ("$''", ""), + V1 ("$'\\n'", "\n"), + V0 ("$'\\'", NULL), + V1 ("$'\\x'", "\\x"), + V1 ("$'\\xa'", "\xa"), + V0 ("$'\\x0'", ""), + V1 ("$'\\x12'", "\x12"), + V1 ("$'\\x12A'", "\x12""A"), + V1 ("$'\\x12t'", "\x12t"), + V1 ("\"aa\\\"\"", "aa\""), + V1 ("\"aa\\\"b\"c", "aa\"bc"), + V1 ("\"aa\\\"\"b", "aa\"b"), + }; + const UnescapeTestData data_ansi[] = { + /* strings inside $''. They cannot be compared directly, but must + * be wrapped by do_svUnescape_combine_ansi(). */ + V1 ("", ""), + V1 ("a", "a"), + V1 ("b", "b"), + V1 ("x", "x"), + V1 (" ", " "), + V1 ("\\a", "\a"), + V1 ("\\b", "\b"), + V1 ("\\e", "\e"), + V1 ("\\E", "\E"), + V1 ("\\f", "\f"), + V1 ("\\n", "\n"), + V1 ("\\r", "\r"), + V1 ("\\t", "\t"), + V1 ("\\v", "\v"), + V1 ("\\\\", "\\"), + V1 ("\\'", "'"), + V1 ("\\\"", "\""), + V1 ("\\?", "\?"), + V1 ("\\?", "?"), + V2 ("\\8", "\\8"), + V2 ("\\1", "\1"), + V1 ("\\1A", "\1A"), + V1 ("\\18", "\18"), + V2 ("\\01", "\1"), + V1 ("\\001", "\1"), + V0 ("\\008", ""), + V1 ("\\018", "\0018"), + V0 ("\\08", ""), + V1 ("\\18", "\0018"), + V1 ("\\x", "\\x"), + V2 ("\\xa", "\xa"), + V1 ("\\x12", "\x12"), + V1 ("\\x12A", "\x12""A"), + V1 ("\\x12a", "\x12""a"), + V1 ("\\x12t", "\x12t"), + V1 ("\\x1a", "\x1a"), + V1 ("\\x1A", "\x1A"), + V1 ("\\ut", "\\ut"), + V2 ("\\ua", "\xa"), + V1 ("\\uat", "\xat"), + V2 ("\\uab", "\xc2\xab"), + V1 ("\\uabt", "\xc2\xabt"), + V2 ("\\uabc", "\xe0\xaa\xbc"), + V1 ("\\uabct", "\xe0\xaa\xbct"), + V2 ("\\uabcd", "\xea\xaf\x8d"), + V1 ("\\uabcdt", "\xea\xaf\x8dt"), + V2 ("\\uabcde", "\xea\xaf\x8d""e"), + V1 ("\\uabcdet", "\xea\xaf\x8d""et"), + V1 ("\\Ut", "\\Ut"), + V2 ("\\Ua", "\xa"), + V1 ("\\Uat", "\xat"), + V2 ("\\Uab", "\xc2\xab"), + V1 ("\\Uabt", "\xc2\xabt"), + V2 ("\\Uabc", "\xe0\xaa\xbc"), + V1 ("\\Uabct", "\xe0\xaa\xbct"), + V2 ("\\Uabcd", "\xea\xaf\x8d"), + V1 ("\\Uabcdt", "\xea\xaf\x8dt"), + V2 ("\\Uabcde", "\xf2\xab\xb3\x9e"), + V1 ("\\Uabcdet", "\xf2\xab\xb3\x9et"), + V2 ("\\Uabcde0", "\xf8\xaa\xbc\xb7\xa0"), + V1 ("\\Uabcde0t", "\xf8\xaa\xbc\xb7\xa0t"), + V2 ("\\Uabcde01", "\xfc\x8a\xaf\x8d\xb8\x81"), + V1 ("\\Uabcde01t", "\xfc\x8a\xaf\x8d\xb8\x81t"), + V2 ("\\U0abcde01", "\xfc\x8a\xaf\x8d\xb8\x81"), + V1 ("\\U0abcde01t", "\xfc\x8a\xaf\x8d\xb8\x81t"), + V1 ("\\U00abcde01", "\xf8\xaa\xbc\xb7\xa0""1"), + V1 ("\\U00abcde01t", "\xf8\xaa\xbc\xb7\xa0""1t"), - g_rand_set_seed (r, seed); + /* control-x sequence is not supported */ + V1 ("\\c", "\\c"), + V1 ("\\c1", "\\c1"), + }; +#undef V0 +#undef V1 +#undef V2 + gsize i; + nm_auto_free_gstring GString *str_val = g_string_new (NULL); + nm_auto_free_gstring GString *str_val2 = g_string_new (NULL); + nm_auto_free_gstring GString *str_exp = g_string_new (NULL); + nm_auto_free_gstring GString *str_exp2 = g_string_new (NULL); - test_svUnescape_assert (""); - test_svUnescape_assert ("'"); - test_svUnescape_assert ("\""); - test_svUnescape_assert ("\\"); - test_svUnescape_assert ("x"); - test_svUnescape_assert (" "); - test_svUnescape_assert ("' '"); - test_svUnescape_assert ("'x'"); - test_svUnescape_assert ("\'some string\'"); - test_svUnescape_assert ("Bob outside LAN"); - test_svUnescape_assert ("{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"); + do_svUnescape_assert ( "' '' '", " "); - for (len = 1; len < 25; len++) { - char *s = g_new0 (char, len+1); + for (i = 0; i < G_N_ELEMENTS (data_full); i++) + do_svUnescape_assert (data_full[i].val, data_full[i].exp); - for (repeat = 0; repeat < MAX (4*len, 20); repeat++) { - - /* fill the entire string with random. */ - for (i = 0; i < len; i++) - s[i] = g_rand_int (r); - - /* randomly place escape characters into the string */ - k = g_rand_int (r) % (len); - while (k-- > 0) - s[g_rand_int (r) % len] = '\\'; - - if (len > 1) { - /* quote the string. */ - k = g_rand_int (r) % (10); - if (k < 4) { - char quote = k < 2 ? '"' : '\''; - - s[0] = quote; - s[len-1] = quote; - } - } - - /*g_message (">>%s<<", s);*/ - test_svUnescape_assert (s); - } - - g_free (s); + for (i = 0; i < G_N_ELEMENTS (data_ansi); i++) { + do_svUnescape_combine_ansi (str_val, str_exp, data_ansi, G_N_ELEMENTS (data_ansi), i); + do_svUnescape_assert (str_val->str, str_exp->str); + } + + /* different values can be just concatenated... */ + for (i = 0; i < 200; i++) { + gsize num_concat = (nmtst_get_rand_int () % 5) + 2; + + g_string_set_size (str_val, 0); + g_string_set_size (str_exp, 0); + + while (num_concat > 0) { + gsize idx; + + if ((nmtst_get_rand_int () % 3 == 0)) { + do_svUnescape_combine_ansi (str_val2, str_exp2, data_ansi, G_N_ELEMENTS (data_ansi), -((int) ((nmtst_get_rand_int () % 5) + 1))); + continue; + } + + idx = nmtst_get_rand_int () % G_N_ELEMENTS (data_full); + if (!data_full[idx].can_concat) + continue; + g_string_append (str_val, data_full[idx].val); + g_string_append (str_exp, data_full[idx].exp); + num_concat--; + } + + switch (nmtst_get_rand_int () % 3) { + case 0: + g_string_append (str_val, " "); + break; + case 1: + g_string_append (str_val, " "); + break; + } + switch (nmtst_get_rand_int () % 3) { + case 0: + g_string_append (str_val, " #"); + break; + case 1: + g_string_append (str_val, " #foo"); + break; + } + do_svUnescape_assert (str_val->str, str_exp->str); } - g_rand_free (r); } +/*****************************************************************************/ + static void test_read_vlan_trailing_spaces (void) { From c55b7e866efe069e01a4af6953a2fd783caf1c71 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 22:39:20 +0100 Subject: [PATCH 26/39] ifcfg-rh: support storing newline '\n' and other ANSI control caracters This is especially important for the team config JSON, which is expected to contain newlines. ANSI C quotation is bash specific, but initscripts already use #!/bin/bash. Unfortunately, g_strescape() doesn't escape '\'' and can thus not be used. Also add a test that svEscape() and svUnescape() do a round-trip. Not only consider \r and \n as candidates for ANSI C quotation, but all ANSI control characters. --- src/settings/plugins/ifcfg-rh/shvar.c | 96 +++++++++++++++++-- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 15 +++ 2 files changed, 101 insertions(+), 10 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 5929811a1..886e30165 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -99,15 +99,88 @@ _shell_is_name (const char *key) /*****************************************************************************/ +/* like g_strescape(), except that it also escapes '\''' *sigh*. + * + * While at it, add $''. */ +static char * +_escape_ansic (const char *source) +{ + const char *p; + gchar *dest; + gchar *q; + + nm_assert (source); + + p = (const char *) source; + /* Each source byte needs maximally four destination chars (\777) */ + q = dest = g_malloc (strlen (source) * 4 + 1 + 3); + + *q++ = '$'; + *q++ = '\''; + + while (*p) { + switch (*p) { + case '\b': + *q++ = '\\'; + *q++ = 'b'; + break; + case '\f': + *q++ = '\\'; + *q++ = 'f'; + break; + case '\n': + *q++ = '\\'; + *q++ = 'n'; + break; + case '\r': + *q++ = '\\'; + *q++ = 'r'; + break; + case '\t': + *q++ = '\\'; + *q++ = 't'; + break; + case '\v': + *q++ = '\\'; + *q++ = 'v'; + break; + case '\\': + case '"': + case '\'': + *q++ = '\\'; + *q++ = *p; + break; + default: + if ((*p < ' ') || (*p >= 0177)) { + *q++ = '\\'; + *q++ = '0' + (((*p) >> 6) & 07); + *q++ = '0' + (((*p) >> 3) & 07); + *q++ = '0' + ((*p) & 07); + } else + *q++ = *p; + break; + } + p++; + } + *q++ = '\''; + *q++ = '\0'; + + nm_assert (q - dest <= strlen (source) * 4 + 1 + 3); + + return dest; +} + +/*****************************************************************************/ + #define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ #define ESC_SPACES " \t|&;()<>" /* only require "" */ -#define ESC_NEWLINES "\n\r" /* will be removed */ const char * svEscape (const char *s, char **to_free) { char *new; - int mangle = 0, space = 0, newline = 0; + gsize mangle = 0; + gboolean has_space = FALSE; int newlen; size_t i, j, slen; @@ -117,23 +190,26 @@ svEscape (const char *s, char **to_free) if (strchr (ESC_ESCAPEES, s[i])) mangle++; if (strchr (ESC_SPACES, s[i])) - space++; - if (strchr (ESC_NEWLINES, s[i])) - newline++; + has_space = TRUE; + if (s[i] < ' ') { + /* if the string contains newline we can only express it using ANSI C quotation + * (as we don't support line continuation). + * Additionally, ANSI control characters look odd with regular quotation, so handle + * them too. */ + return (*to_free = _escape_ansic (s)); + } } - if (!mangle && !space && !newline) { + if (!mangle && !has_space) { *to_free = NULL; return s; } - newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ + newlen = slen + mangle + 3; /* 3 is extra ""\0 */ new = g_malloc (newlen); j = 0; new[j++] = '"'; for (i = 0; i < slen; i++) { - if (strchr (ESC_NEWLINES, s[i])) - continue; if (strchr (ESC_ESCAPEES, s[i])) { new[j++] = '\\'; } @@ -142,7 +218,7 @@ svEscape (const char *s, char **to_free) new[j++] = '"'; new[j++] = '\0'; - nm_assert (j == slen + mangle - newline + 3); + nm_assert (j == slen + mangle + 3); *to_free = new; return new; diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 59d20e078..960f16e30 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8730,6 +8730,21 @@ do_svUnescape_assert (const char *str, const char *expected) s = _svUnescape (str, &to_free); g_assert_cmpstr (s, ==, expected); + + /* check we can make a round-trip */ + if (expected) { + gs_free char *s1_free = NULL; + gs_free char *s2_free = NULL; + const char *s1, *s2; + + s1 = svEscape (expected, &s1_free); + g_assert (s1); + + s2 = _svUnescape (s1, &s2_free); + g_assert (s2); + + g_assert_cmpstr (s2, ==, expected); + } } static void From 337fc582b2d119200d71a7bfcc110e60a3ee2d77 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Nov 2016 18:42:29 +0100 Subject: [PATCH 27/39] ifcfg-rh: use macro _char_in_strset() for svEscape() --- src/settings/plugins/ifcfg-rh/shvar.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 886e30165..c49cda6a5 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -172,6 +172,8 @@ _escape_ansic (const char *source) /*****************************************************************************/ +#define _char_in_strset(ch, str) (!!strchr (""str"", (ch))) + #define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ #define ESC_SPACES " \t|&;()<>" /* only require "" */ @@ -187,11 +189,11 @@ svEscape (const char *s, char **to_free) slen = strlen (s); for (i = 0; i < slen; i++) { - if (strchr (ESC_ESCAPEES, s[i])) + if (_char_in_strset (s[i], ESC_ESCAPEES)) mangle++; - if (strchr (ESC_SPACES, s[i])) + else if (_char_in_strset (s[i], ESC_SPACES)) has_space = TRUE; - if (s[i] < ' ') { + else if (s[i] < ' ') { /* if the string contains newline we can only express it using ANSI C quotation * (as we don't support line continuation). * Additionally, ANSI control characters look odd with regular quotation, so handle @@ -210,7 +212,7 @@ svEscape (const char *s, char **to_free) j = 0; new[j++] = '"'; for (i = 0; i < slen; i++) { - if (strchr (ESC_ESCAPEES, s[i])) { + if (_char_in_strset (s[i], ESC_ESCAPEES)) { new[j++] = '\\'; } new[j++] = s[i]; From d8c465a3cd3379d4584c5cfc43a4e6c6fcd305df Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 22:53:26 +0100 Subject: [PATCH 28/39] ifcfg-rh: fix svEscape() to properly handle double quoting '\'', '~': must not be escaped with backslash. Also, within double quotes the backslash escape character is only removed before special caracters like '$' or '`'. Not in general. Yes, it means that older versions of svEscape produced invalid escape sequences that we now treat differently. But that is not realy avoidable, it was a bug that needs to be fixed. --- src/settings/plugins/ifcfg-rh/shvar.c | 11 ++++------- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index c49cda6a5..bf2077a7f 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -174,8 +174,8 @@ _escape_ansic (const char *source) #define _char_in_strset(ch, str) (!!strchr (""str"", (ch))) -#define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ -#define ESC_SPACES " \t|&;()<>" /* only require "" */ +#define ESC_ESCAPEES "\"\\$`" /* must be escaped */ +#define ESC_SPACES " '\t~|&;()<>" /* only require "" */ const char * svEscape (const char *s, char **to_free) @@ -385,11 +385,8 @@ svUnescape (const char *value, char **to_free) /* we don't support line continuation */ goto out_error; } - if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) { - /* TODO: svEscape() is not yet ready to handle properly treating - * double quotes. */ - //g_string_append_c (str, '\\'); - } + if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) + g_string_append_c (str, '\\'); } g_string_append_c (str, value[i]); i++; diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 960f16e30..8577d2f58 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8813,6 +8813,24 @@ test_svUnescape (void) V0 ("\t #a", ""), V0 ("\t #a\r", ""), V0 ("\r", ""), + V1 ("\\\"", "\""), + V1 ("\\`", "`"), + V1 ("\\$", "$"), + V1 ("\\\\", "\\"), + V1 ("\\a", "a"), + V1 ("\\b", "b"), + V1 ("\\'", "'"), + V1 ("\\~", "~"), + V1 ("\\\t", "\t"), + V1 ("\"\\\"\"", "\""), + V1 ("\"\\`\"", "`"), + V1 ("\"\\$\"", "$"), + V1 ("\"\\\\\"", "\\"), + V1 ("\"\\a\"", "\\a"), + V1 ("\"\\b\"", "\\b"), + V1 ("\"\\'\"", "\\'"), + V1 ("\"\\~\"", "\\~"), + V1 ("\"\\\t\"", "\\\t"), V0 ("ab\r", "ab"), V0 ("a'b'\r ", "ab"), V0 ("a'b' \r", "ab"), From 9843da7ce5cc6a8b981f2c593fe47e563da6aead Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 09:15:15 +0100 Subject: [PATCH 29/39] ifcfg-rh: comment out invalid lines during svWriteFile This is especially important because we don't support line continuation. Thus, with FOO='val bar=3' wrong line F2=b F3='b XXX=adf' XXX2=val2 ' we now write FOO= #NM: FOO='val bar= #NM: bar=3' #NM: wrong line F2=b F3= #NM: F3='b XXX= #NM: XXX=adf' XXX2=val2 #NM: ' Basically, the writer will comment out any line that is - not all-whitespace - not a '#' comment (possibly proceeded by whitespace) - not a valid variable assignment This avoids that writer writes lines that are not understood by ifcfg-rh plugin, but interferes with initscripts. E.g. NAME=old-name' rm -rf / ' becomes NAME=new-name #NM: rm -rf / #NM: ' --- Makefile.am | 8 ++- src/settings/plugins/ifcfg-rh/shvar.c | 61 ++++++++++++++++++- src/settings/plugins/ifcfg-rh/shvar.h | 3 + .../ifcfg-test-write-unknown-1 | 8 +++ .../ifcfg-test-write-unknown-1.expected | 12 ++++ .../ifcfg-test-write-unknown-2 | 3 + .../ifcfg-test-write-unknown-2.expected | 4 ++ .../ifcfg-test-write-unknown-3 | 3 + .../ifcfg-test-write-unknown-3.expected | 5 ++ .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 42 ++++++++++++- 10 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected diff --git a/Makefile.am b/Makefile.am index 6741cb495..377a5a5e5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1926,7 +1926,13 @@ EXTRA_DIST += \ src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces \ src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dns-options \ src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-wake-on-lan \ - src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1 + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1 \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected # make target dependencies can't have colons in their names, which ends up # meaning that we can't add the alias files to EXTRA_DIST. They are instead diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index bf2077a7f..381b4eddd 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -97,6 +97,25 @@ _shell_is_name (const char *key) g_ascii_isalnum (ch) || ch == '_'); } +static const char * +_shell_is_name_assignment (const char *key) +{ + /* whether @key is a valid identifier (name). */ + if (!key) + return NULL; + if ( !g_ascii_isalpha (key[0]) + && key[0] != '_') + return NULL; + while (TRUE) { + const char ch = (++key)[0]; + + if (ch == '=') + return &key[1]; + if (!g_ascii_isalnum (ch) && ch != '_') + return NULL; + } +} + /*****************************************************************************/ /* like g_strescape(), except that it also escapes '\''' *sigh*. @@ -542,6 +561,19 @@ svFileGetName (const shvarFile *s) return s->fileName; } +void +svFileSetName (shvarFile *s, const char *fileName) +{ + g_free (s->fileName); + s->fileName = g_strdup (fileName); +} + +void +svFileSetModified (shvarFile *s) +{ + s->modified = TRUE; +} + /*****************************************************************************/ /* Open the file , returning a shvarFile on success and NULL on failure. @@ -943,8 +975,33 @@ svWriteFile (shvarFile *s, int mode, GError **error) } f = fdopen (tmpfd, "w"); fseek (f, 0, SEEK_SET); - for (current = s->lineList; current; current = current->next) - fprintf (f, "%s\n", (const char *) current->data); + for (current = s->lineList; current; current = current->next) { + const char *line = current->data; + const char *str; + const char *value; + + str = line; + while (g_ascii_isspace (str[0])) + str++; + if (NM_IN_SET (str[0], '\0', '#')) + goto write_regular; + + value = _shell_is_name_assignment (str); + if (value) { + gs_free char *s_tmp = NULL; + + /* we check that the assignment can be properly unescaped. */ + if (svUnescape (value, &s_tmp)) + goto write_regular; + nm_clear_g_free (&s_tmp); + s_tmp = g_strndup (str, value - str); + fprintf (f, "%s\n", s_tmp); + } + fprintf (f, "#NM: %s\n", line); + continue; +write_regular: + fprintf (f, "%s\n", line); + } fclose (f); } diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 43e796d0c..b472e5b79 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -34,6 +34,9 @@ typedef struct _shvarFile shvarFile; const char *svFileGetName (const shvarFile *s); +void svFileSetName (shvarFile *s, const char *fileName); + +void svFileSetModified (shvarFile *s); /* Create the file , return a shvarFile (never fails) */ shvarFile *svCreateFile (const char *name); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 new file mode 100644 index 000000000..c927389e6 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 @@ -0,0 +1,8 @@ +FOO='val + bar=3' +wrong line + F2=b + F3='b +XXX=adf' + XXX2=val2 +' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected new file mode 100644 index 000000000..568b2efcd --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected @@ -0,0 +1,12 @@ +FOO= +#NM: FOO='val +bar= +#NM: bar=3' +#NM: wrong line + F2=b +F3= +#NM: F3='b +XXX= +#NM: XXX=adf' + XXX2=val2 +#NM: ' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 new file mode 100644 index 000000000..850149b21 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 @@ -0,0 +1,3 @@ +FOO=' +BAR=a +' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected new file mode 100644 index 000000000..6ec53c17e --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected @@ -0,0 +1,4 @@ +FOO= +#NM: FOO=' +BAR=a +#NM: ' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 new file mode 100644 index 000000000..3d198e005 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 @@ -0,0 +1,3 @@ +FOO=' +BAR=" +' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected new file mode 100644 index 000000000..d2b27eb33 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected @@ -0,0 +1,5 @@ +FOO= +#NM: FOO=' +BAR= +#NM: BAR=" +#NM: ' diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 8577d2f58..ac50ed9b6 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -57,6 +57,8 @@ #include "nm-test-utils-core.h" +#define TEST_SCRATCH_DIR_TMP TEST_SCRATCH_DIR"/network-scripts/tmp" + /*****************************************************************************/ static NMConnection * @@ -4048,7 +4050,7 @@ test_read_write_static_routes_legacy (void) * source tree and for 'make distcheck'. */ _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/tmp", + TEST_SCRATCH_DIR_TMP, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -8993,7 +8995,36 @@ test_svUnescape (void) } do_svUnescape_assert (str_val->str, str_exp->str); } +} +/*****************************************************************************/ + +static void +test_write_unknown (gconstpointer test_data) +{ + nmtst_auto_unlinkfile char *filename_tmp_1 = g_strdup (TEST_SCRATCH_DIR_TMP"/tmp-1"); + const char *testfile = test_data; + gs_free char *testfile_expected = g_strconcat (testfile, ".expected", NULL); + shvarFile *sv; + gs_free_error GError *error = NULL; + gboolean success; + gs_free char *file_contents_out = NULL; + gs_free char *file_contents_exp = NULL; + + sv = svOpenFile (testfile, &error); + nmtst_assert_success (sv, error); + + svFileSetName (sv, filename_tmp_1); + svFileSetModified (sv); + success = svWriteFile (sv, 0644, &error); + nmtst_assert_success (success, error); + + file_contents_out = nmtst_file_get_contents (filename_tmp_1); + file_contents_exp = nmtst_file_get_contents (testfile_expected); + + g_assert_cmpstr (file_contents_out, ==, file_contents_exp); + + svCloseFile (sv); } /*****************************************************************************/ @@ -9174,10 +9205,15 @@ int main (int argc, char **argv) { nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - if (g_mkdir_with_parents (TEST_SCRATCH_DIR"/network-scripts/tmp", 0755) != 0) - g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR"/network-scripts/tmp", g_strerror (errno)); + if (g_mkdir_with_parents (TEST_SCRATCH_DIR_TMP, 0755) != 0) + g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR_TMP, g_strerror (errno)); g_test_add_func (TPATH "svUnescape", test_svUnescape); + + g_test_add_data_func (TPATH "write-unknown/1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-1", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-2", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/3", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-3", test_write_unknown); + g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); g_test_add_func (TPATH "unmanaged", test_read_unmanaged); From 08a22f2eea8b906e0c5e050a3acec4f337824d7d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 12:33:55 +0100 Subject: [PATCH 30/39] ifcfg-rh: avoid copying temporary value after unescaping svUnescape() can return a pointer to the input argument (if the input argument requires no unescaping or truncation). That is actually the predominant case because most often we store values that don't require escaping. Optimize for that case. --- src/settings/plugins/ifcfg-rh/shvar.c | 78 +++++++++++++++++---------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 381b4eddd..f7e4ce4ff 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -751,19 +751,16 @@ line_construct (const char *key, const char *value) /*****************************************************************************/ -/* svGetValue() is identical to svGetValueString() except that - * svGetValueString() will never return an empty value (but %NULL instead). - * svGetValue() will return empty values if that is the value for the @key. */ -char * -svGetValue (shvarFile *s, const char *key) +static const char * +_svGetValue (shvarFile *s, const char *key, char **to_free) { const GList *current; const char *line_val; const char *last_val = NULL; - char *to_free; - g_return_val_if_fail (s != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); + nm_assert (s); + nm_assert (_shell_is_name (key)); + nm_assert (to_free); current = s->lineList; while ((current = shlist_find (current, key, &line_val))) { @@ -771,11 +768,28 @@ svGetValue (shvarFile *s, const char *key) current = current->next; } - if (!last_val) + if (!last_val) { + *to_free = NULL; return NULL; + } - line_val = svUnescape (last_val, &to_free); - return to_free ?: g_strdup (line_val); + return svUnescape (last_val, to_free); +} + +/* svGetValue() is identical to svGetValueString() except that + * svGetValueString() will never return an empty value (but %NULL instead). + * svGetValue() will return empty values if that is the value for the @key. */ +char * +svGetValue (shvarFile *s, const char *key) +{ + const char *value; + char *to_free; + + g_return_val_if_fail (s != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + value = _svGetValue (s, key, &to_free); + return to_free ?: (value ? g_strdup (value) : NULL); } /* Get the value associated with the key, and leave the current pointer @@ -785,14 +799,19 @@ svGetValue (shvarFile *s, const char *key) char * svGetValueString (shvarFile *s, const char *key) { - char *value; + char *to_free; + const char *value; - value = svGetValue (s, key); - if (value && !*value) { - g_free (value); + value = _svGetValue (s, key, &to_free); + if (!value) { + nm_assert (!to_free); return NULL; } - return value; + if (!value[0]) { + g_free (to_free); + return NULL; + } + return to_free ?: g_strdup (value); } /* svGetValueBoolean: @@ -807,10 +826,11 @@ svGetValueString (shvarFile *s, const char *key) gint svGetValueBoolean (shvarFile *s, const char *key, gint fallback) { - gs_free char *tmp = NULL; + gs_free char *to_free = NULL; + const char *value; - tmp = svGetValueString (s, key); - return svParseBoolean (tmp, fallback); + value = _svGetValue (s, key, &to_free); + return svParseBoolean (value, fallback); } /* svGetValueInt64: @@ -826,22 +846,24 @@ svGetValueBoolean (shvarFile *s, const char *key, gint fallback) gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback) { - char *tmp; + char *to_free; + const char *value; gint64 result; int errsv; - tmp = svGetValue (s, key); - if (!tmp) { + value = _svGetValue (s, key, &to_free); + if (!value) { + nm_assert (!to_free); errno = 0; return fallback; } - result = _nm_utils_ascii_str_to_int64 (tmp, base, min, max, fallback); - errsv = errno; - - g_free (tmp); - - errno = errsv; + result = _nm_utils_ascii_str_to_int64 (value, base, min, max, fallback); + if (to_free) { + errsv = errno; + g_free (to_free); + errno = errsv; + } return result; } From 82ccec22ca00dce8f094bc417f9f3cb386b475d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 12:50:53 +0100 Subject: [PATCH 31/39] ifcfg-rh: modify svGetString() signature to avoid copying of temporary value Modify the signature of svGetString() to allow getting the internal string without cloning the string after unescaping. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 54 +++++++++---------- src/settings/plugins/ifcfg-rh/shvar.c | 14 ++--- src/settings/plugins/ifcfg-rh/shvar.h | 2 +- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 140e7be0a..142c2251a 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -678,7 +678,7 @@ error: } static void -parse_dns_options (NMSettingIPConfig *ip_config, char *value) +parse_dns_options (NMSettingIPConfig *ip_config, const char *value) { char **options = NULL; @@ -969,7 +969,8 @@ make_ip4_setting (shvarFile *ifcfg, char *value = NULL; char *route_path = NULL; char *method; - char *dns_options = NULL; + gs_free char *dns_options_free = NULL; + const char *dns_options = NULL; gs_free char *gateway = NULL; gint32 i; shvarFile *network_ifcfg; @@ -995,7 +996,7 @@ make_ip4_setting (shvarFile *ifcfg, /* Get the connection ifcfg device name and the global gateway device */ value = svGetValueString (ifcfg, "DEVICE"); gatewaydev = svGetValueString (network_ifcfg, "GATEWAYDEV"); - dns_options = svGetValue (network_ifcfg, "RES_OPTIONS"); + dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", &dns_options_free); /* If there was a global gateway device specified, then only connections * for that device can be the default connection. @@ -1192,12 +1193,9 @@ make_ip4_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValue (ifcfg, "RES_OPTIONS"); - parse_dns_options (s_ip4, value); + parse_dns_options (s_ip4, svGetValue (ifcfg, "RES_OPTIONS", &value)); parse_dns_options (s_ip4, dns_options); g_free (value); - g_free (dns_options); - dns_options = NULL; /* DNS priority */ priority = svGetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); @@ -1267,7 +1265,6 @@ make_ip4_setting (shvarFile *ifcfg, return NM_SETTING (s_ip4); done: - g_free (dns_options); g_free (route_path); g_object_unref (s_ip4); return NULL; @@ -1382,7 +1379,8 @@ make_ip6_setting (shvarFile *ifcfg, char *value = NULL; char *str_value; char *route6_path = NULL; - char *dns_options = NULL; + gs_free char *dns_options_free = NULL; + const char *dns_options = NULL; gboolean ipv6init, ipv6forwarding, ipv6_autoconf, dhcp6 = FALSE; char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; char *ipv6addr, *ipv6addr_secondaries; @@ -1418,7 +1416,7 @@ make_ip6_setting (shvarFile *ifcfg, value = svGetValueString (ifcfg, "DEVICE"); ipv6_defaultgw = svGetValueString (network_ifcfg, "IPV6_DEFAULTGW"); ipv6_defaultdev = svGetValueString (network_ifcfg, "IPV6_DEFAULTDEV"); - dns_options = svGetValue (network_ifcfg, "RES_OPTIONS"); + dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", &dns_options_free); if (ipv6_defaultgw) { default_dev = strchr (ipv6_defaultgw, '%'); @@ -1639,11 +1637,9 @@ make_ip6_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValue (ifcfg, "RES_OPTIONS"); - parse_dns_options (s_ip6, value); + parse_dns_options (s_ip6, svGetValue (ifcfg, "RES_OPTIONS", &value)); parse_dns_options (s_ip6, dns_options); g_free (value); - g_free (dns_options); /* DNS priority */ priority = svGetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); @@ -1655,7 +1651,6 @@ make_ip6_setting (shvarFile *ifcfg, return NM_SETTING (s_ip6); error: - g_free (dns_options); g_free (route6_path); g_object_unref (s_ip6); return NULL; @@ -3373,6 +3368,7 @@ make_wireless_setting (shvarFile *ifcfg, GError **error) { NMSettingWireless *s_wireless; + const char *cvalue; char *value = NULL; gint64 chan = 0; NMSettingMacRandomization mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; @@ -3535,19 +3531,19 @@ make_wireless_setting (shvarFile *ifcfg, svGetValueBoolean (ifcfg, "SSID_HIDDEN", FALSE), NULL); - value = svGetValue (ifcfg, "POWERSAVE"); - if (value) { - if (!strcmp (value, "default")) + cvalue = svGetValue (ifcfg, "POWERSAVE", &value); + if (cvalue) { + if (!strcmp (cvalue, "default")) powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; - else if (!strcmp (value, "ignore")) + else if (!strcmp (cvalue, "ignore")) powersave = NM_SETTING_WIRELESS_POWERSAVE_IGNORE; - else if (!strcmp (value, "disable") || !strcmp (value, "no")) + else if (!strcmp (cvalue, "disable") || !strcmp (cvalue, "no")) powersave = NM_SETTING_WIRELESS_POWERSAVE_DISABLE; - else if (!strcmp (value, "enable") || !strcmp (value, "yes")) + else if (!strcmp (cvalue, "enable") || !strcmp (cvalue, "yes")) powersave = NM_SETTING_WIRELESS_POWERSAVE_ENABLE; else { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid POWERSAVE value '%s'", value); + "Invalid POWERSAVE value '%s'", cvalue); g_free (value); goto error; } @@ -3559,17 +3555,17 @@ make_wireless_setting (shvarFile *ifcfg, powersave, NULL); - value = svGetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); - if (value) { - if (strcmp (value, "default") == 0) + cvalue = svGetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", &value); + if (cvalue) { + if (strcmp (cvalue, "default") == 0) mac_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT; - else if (strcmp (value, "never") == 0) + else if (strcmp (cvalue, "never") == 0) mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; - else if (strcmp (value, "always") == 0) + else if (strcmp (cvalue, "always") == 0) mac_randomization = NM_SETTING_MAC_RANDOMIZATION_ALWAYS; else { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid MAC_ADDRESS_RANDOMIZATION value '%s'", value); + "Invalid MAC_ADDRESS_RANDOMIZATION value '%s'", cvalue); g_free (value); goto error; } @@ -3918,8 +3914,8 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "ETHTOOL_OPTS"); - parse_ethtool_options (ifcfg, s_wired, value); + parse_ethtool_options (ifcfg, s_wired, + svGetValue (ifcfg, "ETHTOOL_OPTS", &value)); g_free (value); return (NMSetting *) s_wired; diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index f7e4ce4ff..d92eaecee 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -776,20 +776,14 @@ _svGetValue (shvarFile *s, const char *key, char **to_free) return svUnescape (last_val, to_free); } -/* svGetValue() is identical to svGetValueString() except that - * svGetValueString() will never return an empty value (but %NULL instead). - * svGetValue() will return empty values if that is the value for the @key. */ -char * -svGetValue (shvarFile *s, const char *key) +const char * +svGetValue (shvarFile *s, const char *key, char **to_free) { - const char *value; - char *to_free; - g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (to_free, NULL); - value = _svGetValue (s, key, &to_free); - return to_free ?: (value ? g_strdup (value) : NULL); + return _svGetValue (s, key, to_free); } /* Get the value associated with the key, and leave the current pointer diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index b472e5b79..a6498fcea 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -48,8 +48,8 @@ shvarFile *svOpenFile (const char *name, GError **error); * pointing at the line containing the value. The char* returned MUST * be freed by the caller. */ +const char *svGetValue (shvarFile *s, const char *key, char **to_free); char *svGetValueString (shvarFile *s, const char *key); -char *svGetValue (shvarFile *s, const char *key); gint svParseBoolean (const char *value, gint def); From eb307bbbb6f2c6427b55502f5ed4881154d46569 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 15:50:31 +0100 Subject: [PATCH 32/39] ifcfg-rh: let reader preserve the last line even without newline at end of file --- src/settings/plugins/ifcfg-rh/shvar.c | 2 ++ .../network-scripts/ifcfg-test-wifi-wpa-psk | 2 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index d92eaecee..413ff309b 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -630,6 +630,8 @@ svOpenFileInternal (const char *name, gboolean create, GError **error) /* we'd use g_strsplit() here, but we want a list, not an array */ for (p = arena; (q = strchr (p, '\n')) != NULL; p = q + 1) s->lineList = g_list_append (s->lineList, g_strndup (p, q - p)); + if (p[0]) + s->lineList = g_list_append (s->lineList, g_strdup (p)); g_free (arena); /* closefd is set if we opened the file read-only, so go ahead and diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk index 2119ba8e6..a78051aad 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk @@ -16,4 +16,4 @@ CIPHER_GROUP="TKIP CCMP WEP40 WEP104" KEY_MGMT=WPA-PSK WPA_ALLOW_WPA=yes WPA_ALLOW_WPA2=yes - +LAST_ENTRY=no-newline \ No newline at end of file diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index ac50ed9b6..4cd7c4d27 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -2400,6 +2400,22 @@ test_read_wifi_leap_secret_flags (gconstpointer test_data) g_object_unref (connection); } +static void +test_ifcfg_no_trailing_newline (void) +{ + gs_free_error GError *error = NULL; + shvarFile *sv; + gs_free char *value = NULL; + + sv = svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk", &error); + nmtst_assert_success (sv, error); + + value = svGetValueString (sv, "LAST_ENTRY"); + g_assert_cmpstr (value, ==, "no-newline"); + + svCloseFile (sv); +} + static void test_read_wifi_wpa_psk (void) { @@ -9446,6 +9462,8 @@ int main (int argc, char **argv) g_test_add_data_func (TPATH "wwan/write-gsm", GUINT_TO_POINTER (TRUE), test_write_mobile_broadband); g_test_add_data_func (TPATH "wwan/write-cdma", GUINT_TO_POINTER (FALSE), test_write_mobile_broadband); + g_test_add_func (TPATH "no-trailing-newline", test_ifcfg_no_trailing_newline); + g_test_add_func (TPATH "utils/name", test_utils_name); g_test_add_func (TPATH "utils/path", test_utils_path); g_test_add_func (TPATH "utils/ignore", test_utils_ignore); From c20b7955474dbc04fd8bdb85b1e4bff4803cf9ee Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 15:53:04 +0100 Subject: [PATCH 33/39] ifcfg-rh: let reader create lineList in O(n) using g_list_prepend() and g_list_reverse() --- src/settings/plugins/ifcfg-rh/shvar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 413ff309b..ed0e1057b 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -629,10 +629,11 @@ svOpenFileInternal (const char *name, gboolean create, GError **error) /* we'd use g_strsplit() here, but we want a list, not an array */ for (p = arena; (q = strchr (p, '\n')) != NULL; p = q + 1) - s->lineList = g_list_append (s->lineList, g_strndup (p, q - p)); + s->lineList = g_list_prepend (s->lineList, g_strndup (p, q - p)); if (p[0]) - s->lineList = g_list_append (s->lineList, g_strdup (p)); + s->lineList = g_list_prepend (s->lineList, g_strdup (p)); g_free (arena); + s->lineList = g_list_reverse (s->lineList); /* closefd is set if we opened the file read-only, so go ahead and * close it, because we can't write to it anyway From 264e519779cf3fa361df33b6dd77ee205504804b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Nov 2016 21:48:57 +0100 Subject: [PATCH 34/39] ifcfg-rh/tests: add test for handling multiple occurances of a variable This tests commit "ifcfg-rh: handle multiple definitions of the same key". --- Makefile.am | 4 ++- .../ifcfg-test-write-unknown-4 | 32 +++++++++++++++++++ .../ifcfg-test-write-unknown-4.expected | 27 ++++++++++++++++ .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 27 ++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected diff --git a/Makefile.am b/Makefile.am index 377a5a5e5..643a7ff11 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1932,7 +1932,9 @@ EXTRA_DIST += \ src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 \ src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected \ src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 \ - src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 \ + src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected # make target dependencies can't have colons in their names, which ends up # meaning that we can't add the alias files to EXTRA_DIST. They are instead diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 new file mode 100644 index 000000000..2a0198d30 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 @@ -0,0 +1,32 @@ +# test what happens with multiple defines of a name. +# +# Note that svGetValue() will return "l4x", which +# isn't correct in terms of shell-parsing. But we +# don't consider only line-by-line, thus this is +# expected. +# +# Also note that setting NAME will replace the last +# occurance, and delete all previous once. + +#L1 +NAME=l2 + +#L2 +NAME=l3 + +#L4 +NAME=' +NAME=l4x +' + +#Lx-1 +NAME2=not-visible +#Lx-2 +NAME2='invalid +#Lx-3 + +#Ly-1 +NAME3='invalid +#Ly-2 +NAME3=name3-value +#Ly-3 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected new file mode 100644 index 000000000..7f9a2d061 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected @@ -0,0 +1,27 @@ +# test what happens with multiple defines of a name. +# +# Note that svGetValue() will return "l4x", which +# isn't correct in terms of shell-parsing. But we +# don't consider only line-by-line, thus this is +# expected. +# +# Also note that setting NAME will replace the last +# occurance, and delete all previous once. + +#L1 + +#L2 + +#L4 +NAME=set-by-test1 +#NM: ' + +#Lx-1 +#Lx-2 +NAME2=set-by-test2 +#Lx-3 + +#Ly-1 +#Ly-2 +NAME3=set-by-test3 +#Ly-3 diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 4cd7c4d27..0e7140e62 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -9026,12 +9026,38 @@ test_write_unknown (gconstpointer test_data) gboolean success; gs_free char *file_contents_out = NULL; gs_free char *file_contents_exp = NULL; + gs_free char *tmp = NULL; sv = svOpenFile (testfile, &error); nmtst_assert_success (sv, error); svFileSetName (sv, filename_tmp_1); svFileSetModified (sv); + + if (g_str_has_suffix (testfile, "ifcfg-test-write-unknown-4")) { + g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "l4x"); + nm_clear_g_free (&tmp); + + g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, NULL); + nm_clear_g_free (&tmp); + + g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "name3-value"); + nm_clear_g_free (&tmp); + + svSetValue (sv, "NAME", "set-by-test1"); + svSetValue (sv, "NAME2", "set-by-test2"); + svSetValue (sv, "NAME3", "set-by-test3"); + + g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "set-by-test1"); + nm_clear_g_free (&tmp); + + g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, "set-by-test2"); + nm_clear_g_free (&tmp); + + g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "set-by-test3"); + nm_clear_g_free (&tmp); + } + success = svWriteFile (sv, 0644, &error); nmtst_assert_success (success, error); @@ -9229,6 +9255,7 @@ int main (int argc, char **argv) g_test_add_data_func (TPATH "write-unknown/1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-1", test_write_unknown); g_test_add_data_func (TPATH "write-unknown/2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-2", test_write_unknown); g_test_add_data_func (TPATH "write-unknown/3", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-3", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/4", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-4", test_write_unknown); g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); From 1b03b59ac0517a39ea383445ab0d2c6053737b03 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 Nov 2016 10:54:25 +0100 Subject: [PATCH 35/39] ifcfg-rh: set errno in svGetValueInt64() in case key does not exist --- src/settings/plugins/ifcfg-rh/shvar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index ed0e1057b..ff294c7f4 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -851,7 +851,9 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m value = _svGetValue (s, key, &to_free); if (!value) { nm_assert (!to_free); - errno = 0; + /* indicate that the key does not exist (or has a syntax error + * and svUnescape() failed). */ + errno = ENOKEY; return fallback; } From 01f0e35b6911f2793f618dfd0caa5b6d7efcc4a0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Nov 2016 14:11:04 +0100 Subject: [PATCH 36/39] ifcfg-rh: remove unused keyfile argument from writer_update_connection() writer_update_connection() retrieves the keyfile name based on the ifcfg-name. No need to pass it in separately, the argument was unused. --- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c | 2 -- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 6 ++---- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h | 1 - src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 3 --- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index 3877bb730..ea8f33766 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -335,7 +335,6 @@ commit_changes (NMSettingsConnection *connection, NMSettingsConnectionCommitFunc callback, gpointer user_data) { - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) connection); GError *error = NULL; NMConnection *reread; gboolean same = FALSE, success = FALSE; @@ -369,7 +368,6 @@ commit_changes (NMSettingsConnection *connection, success = writer_update_connection (NM_CONNECTION (connection), IFCFG_DIR, filename, - priv->keyfile, &error); } else { success = writer_new_connection (NM_CONNECTION (connection), diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index f098f1295..d456f1a2a 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -2700,7 +2700,6 @@ static gboolean write_connection (NMConnection *connection, const char *ifcfg_dir, const char *filename, - const char *keyfile, char **out_filename, GError **error) { @@ -2884,14 +2883,13 @@ writer_new_connection (NMConnection *connection, char **out_filename, GError **error) { - return write_connection (connection, ifcfg_dir, NULL, NULL, out_filename, error); + return write_connection (connection, ifcfg_dir, NULL, out_filename, error); } gboolean writer_update_connection (NMConnection *connection, const char *ifcfg_dir, const char *filename, - const char *keyfile, GError **error) { if (utils_has_complex_routes (filename)) { @@ -2900,6 +2898,6 @@ writer_update_connection (NMConnection *connection, return FALSE; } - return write_connection (connection, ifcfg_dir, filename, keyfile, NULL, error); + return write_connection (connection, ifcfg_dir, filename, NULL, error); } diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h index 97a9f2525..2662f79b0 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h @@ -34,7 +34,6 @@ gboolean writer_new_connection (NMConnection *connection, gboolean writer_update_connection (NMConnection *connection, const char *ifcfg_dir, const char *filename, - const char *keyfile, GError **error); #endif /* _WRITER_H_ */ diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 0e7140e62..e5a0e9d99 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -1780,7 +1780,6 @@ test_clear_master (void) success = writer_update_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", testfile, - NULL, &error); nmtst_assert_success (success, error); keyfile = utils_get_keys_path (testfile); @@ -6244,7 +6243,6 @@ test_write_wifi_wpa_then_open (void) success = writer_update_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", testfile, - keyfile, &error); g_assert_no_error (error); g_assert (success); @@ -6392,7 +6390,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) success = writer_update_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", testfile, - keyfile, &error); g_assert_no_error (error); g_assert (success); From ecda08e1d13154c991bd54ae9159254584afc4a5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Nov 2016 14:00:51 +0100 Subject: [PATCH 37/39] ifcfg-rh/tests: some refactoring of tests When introducing the macro _svGetValue_check() we replace the call to svGetValueString() with svGetValue(). That makes a difference only when asserting against a %NULL value. It's fair to assume that in such case we actually want to assert that the value is unset, and not possibly empty. --- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 1327 +++++------------ 1 file changed, 353 insertions(+), 974 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index e5a0e9d99..c5e5456af 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -61,6 +61,41 @@ /*****************************************************************************/ +#define _svOpenFile(testfile) \ + ({ \ + shvarFile *_f; \ + GError *_error = NULL; \ + const char *_testfile = (testfile); \ + \ + g_assert (_testfile); \ + _f = svOpenFile (_testfile, &_error); \ + nmtst_assert_success (_f, _error); \ + _f; \ + }) + +#define _svGetValue_check(sv, key, expected_value) \ + G_STMT_START { \ + gs_free char *_to_free = NULL; \ + \ + g_assert_cmpstr (svGetValue (sv, key, &_to_free), ==, expected_value); \ + } G_STMT_END + +#define _writer_update_connection(connection, ifcfg_dir, filename) \ + G_STMT_START { \ + NMConnection *_connection = (connection); \ + const char *_ifcfg_dir = (ifcfg_dir); \ + const char *_filename = (filename); \ + GError *_error = NULL; \ + gboolean _success; \ + \ + g_assert (NM_IS_CONNECTION (connection)); \ + g_assert (_ifcfg_dir && _ifcfg_dir[0]); \ + g_assert (_filename && _filename[0]); \ + \ + _success = writer_update_connection (_connection, _ifcfg_dir, _filename, &_error); \ + nmtst_assert_success (_success, _error); \ + } G_STMT_END + static NMConnection * _connection_from_file (const char *filename, const char *network_file, @@ -1497,7 +1532,7 @@ test_read_wired_8021x_tls_secret_flags (gconstpointer test_data) static void test_read_write_802_1X_subj_matches (void) { - nmtst_auto_unlinkfile char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSetting8021x *s_8021x; @@ -1526,11 +1561,11 @@ test_read_write_802_1X_subj_matches (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*missing IEEE_8021X_CA_CERT*peap*"); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -1746,10 +1781,7 @@ test_clear_master (void) gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; char *unmanaged = NULL; - GError *error = NULL; - gboolean success; shvarFile *f; - char *val; /* 1. load the bridge slave connection from disk */ connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-component", @@ -1777,21 +1809,15 @@ test_clear_master (void) g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NULL); /* 4. update the connection on disk */ - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - &error); - nmtst_assert_success (success, error); + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); keyfile = utils_get_keys_path (testfile); g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); /* 5. check that BRIDGE variable has been removed */ - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - val = svGetValueString (f, "BRIDGE"); - g_assert (!val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "BRIDGE", NULL); svCloseFile (f); } @@ -1807,7 +1833,6 @@ test_write_dns_options (void) NMSettingIPConfig *s_ip6; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; NMIPAddress *addr; NMIPAddress *addr6; GError *error = NULL; @@ -1818,14 +1843,12 @@ test_write_dns_options (void) s_con = (NMSettingConnection *) 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 DNS options", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -2402,16 +2425,10 @@ test_read_wifi_leap_secret_flags (gconstpointer test_data) static void test_ifcfg_no_trailing_newline (void) { - gs_free_error GError *error = NULL; shvarFile *sv; - gs_free char *value = NULL; - - sv = svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk", &error); - nmtst_assert_success (sv, error); - - value = svGetValueString (sv, "LAST_ENTRY"); - g_assert_cmpstr (value, ==, "no-newline"); + sv = _svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk"); + _svGetValue_check (sv, "LAST_ENTRY", "no-newline"); svCloseFile (sv); } @@ -2983,11 +3000,11 @@ test_read_wifi_hidden (void) static void test_write_wifi_hidden (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -2998,13 +3015,11 @@ test_write_wifi_hidden (void) s_con = (NMSettingConnection *) 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 WiFi Hidden", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -3026,33 +3041,21 @@ test_write_wifi_hidden (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "SSID_HIDDEN"); - g_assert (val); - g_assert_cmpstr (val, ==, "yes"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "SSID_HIDDEN", "yes"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_wifi_mac_random (gconstpointer user_data) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_free char *path = NULL; NMSettingWireless *s_wifi; - char *path; const char *name; gpointer value_p; NMSettingMacRandomization value; @@ -3062,23 +3065,21 @@ test_read_wifi_mac_random (gconstpointer user_data) path = g_strdup_printf (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-mac-random-%s", name); connection = _connection_from_file (path, NULL, TYPE_WIRELESS, NULL); - g_free (path); s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); g_assert_cmpint (nm_setting_wireless_get_mac_address_randomization (s_wifi), ==, value); - - g_object_unref (connection); } static void test_write_wifi_mac_random (gconstpointer user_data) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; + char *val; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -3097,14 +3098,12 @@ test_write_wifi_mac_random (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); val = g_strdup_printf ("Test Write WiFi MAC %s", name); g_object_set (s_con, NM_SETTING_CONNECTION_ID, val, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); g_free (val); /* Wifi setting */ @@ -3125,35 +3124,25 @@ test_write_wifi_mac_random (gconstpointer user_data) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "MAC_ADDRESS_RANDOMIZATION"); - g_assert_cmpstr (val, ==, write_expected); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "MAC_ADDRESS_RANDOMIZATION", write_expected); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_wake_on_lan (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingWiredWakeOnLan wol; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; + char *val; shvarFile *f; connection = nm_simple_connection_new (); @@ -3162,13 +3151,11 @@ test_write_wired_wake_on_lan (void) s_con = (NMSettingConnection *) 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 Wired Wake-on-LAN", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3189,11 +3176,7 @@ test_write_wired_wake_on_lan (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that the key was written. */ + f = _svOpenFile (testfile); val = svGetValueString (f, "ETHTOOL_OPTS"); g_assert (val); g_assert (strstr (val, "wol")); @@ -3202,13 +3185,8 @@ test_write_wired_wake_on_lan (void) svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -3235,11 +3213,11 @@ test_read_wifi_band_a (void) static void test_write_wifi_band_a (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -3250,13 +3228,11 @@ test_write_wifi_band_a (void) s_con = (NMSettingConnection *) 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 WiFi Band A", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -3278,25 +3254,13 @@ test_write_wifi_band_a (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "BAND"); - g_assert (val); - g_assert_cmpstr (val, ==, "a"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "BAND", "a"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -3537,19 +3501,18 @@ test_read_wifi_wep_agent_keys (void) static void test_write_wired_static (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4, *reread_s_ip4; NMSettingIPConfig *s_ip6, *reread_s_ip6; - char *uuid; NMIPAddress *addr; NMIPAddress *addr6; NMIPRoute *route6; GError *error = NULL; - char *testfile = NULL; - char *route6file = NULL; connection = nm_simple_connection_new (); @@ -3557,15 +3520,13 @@ test_write_wired_static (void) s_con = (NMSettingConnection *) 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 Wired Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, 1, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3655,9 +3616,9 @@ test_write_wired_static (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", &testfile); + route6file = utils_get_route6_path (testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); /* FIXME: currently DNS domains from IPv6 setting are stored in 'DOMAIN' key in ifcfg-file * However after re-reading they are dropped into IPv4 setting. @@ -3676,27 +3637,18 @@ test_write_wired_static (void) nm_connection_add_setting (connection, nm_setting_proxy_new ()); nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); - - route6file = utils_get_route6_path (testfile); - unlink (route6file); - - g_free (testfile); - g_free (route6file); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -3704,14 +3656,12 @@ test_write_wired_dhcp (void) s_con = (NMSettingConnection *) 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 Wired DHCP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3745,46 +3695,38 @@ test_write_wired_dhcp (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_dhcp_plus_ip (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_read_write_wired_dhcp_send_hostname (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; const char * dhcp_hostname = "kamil-patka"; - char *written = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-send-hostname", NULL, TYPE_ETHERNET, NULL); @@ -3805,11 +3747,9 @@ test_read_write_wired_dhcp_send_hostname (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -3821,24 +3761,20 @@ test_read_write_wired_dhcp_send_hostname (void) g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == FALSE); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_static_ip6_only (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -3846,14 +3782,12 @@ test_write_wired_static_ip6_only (void) s_con = (NMSettingConnection *) 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 Wired Static IP6 Only", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3893,13 +3827,8 @@ test_write_wired_static_ip6_only (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } /* Test writing an IPv6 config with varying gateway address. @@ -3913,19 +3842,19 @@ test_write_wired_static_ip6_only (void) static void test_write_wired_static_ip6_only_gw (gconstpointer user_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; char *id = NULL; - char *written_ifcfg_gateway; + gs_free char *written_ifcfg_gateway = NULL; const char *gateway6 = user_data; + shvarFile *ifcfg; connection = nm_simple_connection_new (); @@ -3933,15 +3862,13 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); g_free (id); /* Wired setting */ @@ -3986,17 +3913,9 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - { - /* re-read the file to check that what key was written. */ - shvarFile *ifcfg = svOpenFile (testfile, &error); - - g_assert_no_error (error); - g_assert (ifcfg); - written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); - svCloseFile (ifcfg); - } - - unlink (testfile); + ifcfg = _svOpenFile (testfile); + written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); + svCloseFile (ifcfg); /* access the gateway from the loaded connection. */ s_ip6 = nm_connection_get_setting_ip6_config (reread); @@ -4013,23 +3932,19 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, gateway6); g_assert_cmpstr (written_ifcfg_gateway, ==, gateway6); } - - g_free (testfile); - g_free (written_ifcfg_gateway); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_write_static_routes_legacy (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_free char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *testfile = NULL; - char *routefile = NULL; - char *route6file = NULL; const char *tmp; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-static-routes-legacy", @@ -4069,36 +3984,27 @@ test_read_write_static_routes_legacy (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); routefile = utils_get_route_path (testfile); - unlink (routefile); route6file = utils_get_route6_path (testfile); - unlink (route6file); + g_assert (!g_file_test (route6file, G_FILE_TEST_EXISTS)); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (routefile); - g_free (route6file); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_static_routes (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr; NMIPRoute *route; GError *error = NULL; - char *testfile = NULL; - char *routefile = NULL; connection = nm_simple_connection_new (); @@ -4106,14 +4012,12 @@ test_write_wired_static_routes (void) s_con = (NMSettingConnection *) 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 Wired Static Routes", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4176,17 +4080,10 @@ test_write_wired_static_routes (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); routefile = utils_get_route_path (testfile); - unlink (routefile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (routefile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -4201,7 +4098,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; - char *uuid; gboolean success; GError *error = NULL; @@ -4211,14 +4107,12 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) s_con = (NMSettingConnection *) 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 Wired DHCP 802.1x PEAP MSCHAPv2", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4269,26 +4163,25 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - keyfile = utils_get_keys_path (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); + + keyfile = utils_get_keys_path (testfile); } static void test_write_wired_8021x_tls (gconstpointer test_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *pw; char *tmp; @@ -4301,36 +4194,29 @@ test_write_wired_8021x_tls (gconstpointer test_data) flags = GPOINTER_TO_INT (flags_p); connection = nm_simple_connection_new (); - g_assert (connection != NULL); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Wired 802.1x TLS Blobs", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, @@ -4339,7 +4225,6 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* 802.1x setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - g_assert (s_8021x); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); @@ -4388,9 +4273,9 @@ test_write_wired_8021x_tls (gconstpointer test_data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); + keyfile = utils_get_keys_path (testfile); - unlink (keyfile); + nmtst_file_unlink_if_exists (keyfile); /* Ensure the reread connection's certificates and private key are paths; no * matter what scheme was used in the original connection they will be read @@ -4434,21 +4319,16 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* Clean up created certs and keys */ tmp = utils_cert_path (testfile, "ca-cert.der"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); tmp = utils_cert_path (testfile, "client-cert.der"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); tmp = utils_cert_path (testfile, "private-key.pem"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } #define TEST_SCRATCH_ALIAS_BASE TEST_SCRATCH_DIR "/network-scripts/ifcfg-alias0" @@ -4456,45 +4336,43 @@ test_write_wired_8021x_tls (gconstpointer test_data) static void test_write_wired_aliases (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid; int num_addresses = 4; const char *ip[] = { "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" }; const char *label[] = { NULL, "alias0:2", NULL, "alias0:3" }; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; shvarFile *ifcfg; int i, j; + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":5"); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "alias0", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -4539,9 +4417,8 @@ test_write_wired_aliases (void) g_assert (!g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - unlink (TEST_SCRATCH_ALIAS_BASE ":2"); - unlink (TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink (TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink (TEST_SCRATCH_ALIAS_BASE ":3"); /* nm_connection_compare() is not guaranteed to succeed, because the * aliases get read back in essentially random order. So just @@ -4578,20 +4455,17 @@ test_write_wired_aliases (void) /* Gateway */ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1"); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_gateway (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL, *val; GError *error = NULL; shvarFile *f; NMIPAddress *addr; @@ -4602,13 +4476,11 @@ test_write_gateway (void) s_con = (NMSettingConnection *) 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 Static Addresses Gateway", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4640,77 +4512,37 @@ test_write_gateway (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ - val = svGetValueString (f, "IPADDR"); - g_assert (val); - g_assert_cmpstr (val, ==, "1.1.1.3"); - g_free (val); - - val = svGetValueString (f, "IPADDR1"); - g_assert (val); - g_assert_cmpstr (val, ==, "2.2.2.5"); - g_free (val); - - val = svGetValueString (f, "IPADDR0"); - g_assert (val == NULL); - - val = svGetValueString (f, "PREFIX"); - g_assert (val); - g_assert_cmpstr (val, ==, "24"); - g_free (val); - - val = svGetValueString (f, "PREFIX1"); - g_assert (val); - g_assert_cmpstr (val, ==, "24"); - g_free (val); - - val = svGetValueString (f, "PREFIX0"); - g_assert (val == NULL); - - val = svGetValueString (f, "GATEWAY"); - g_assert (val); - g_assert_cmpstr (val, ==, "1.1.1.254"); - g_free (val); - - val = svGetValueString (f, "GATEWAY0"); - g_assert (val == NULL); - - val = svGetValueString (f, "GATEWAY1"); - g_assert (val == NULL); - + f = _svOpenFile (testfile); + _svGetValue_check (f, "IPADDR", "1.1.1.3"); + _svGetValue_check (f, "IPADDR1", "2.2.2.5"); + _svGetValue_check (f, "IPADDR0", NULL); + _svGetValue_check (f, "PREFIX", "24"); + _svGetValue_check (f, "PREFIX1", "24"); + _svGetValue_check (f, "PREFIX0", NULL); + _svGetValue_check (f, "GATEWAY", "1.1.1.254"); + _svGetValue_check (f, "GATEWAY0", NULL); + _svGetValue_check (f, "GATEWAY1", NULL); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_open (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - GError *error = NULL; - char *testfile = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); @@ -4718,14 +4550,12 @@ test_write_wifi_open (void) s_con = (NMSettingConnection *) 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 Wifi Open", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4768,37 +4598,23 @@ test_write_wifi_open (void) reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - /* Now make sure that the ESSID item isn't double-quoted (rh #606518) */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg != NULL); - - tmp = svGetValueString (ifcfg, "ESSID"); - g_assert_cmpstr (tmp, ==, "Test SSID"); - - g_free (tmp); + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "ESSID", "Test SSID"); svCloseFile (ifcfg); - unlink (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_open_hex_ssid (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }; @@ -4808,14 +4624,12 @@ test_write_wifi_open_hex_ssid (void) s_con = (NMSettingConnection *) 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 Wifi Open Hex SSID", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4852,28 +4666,22 @@ test_write_wifi_open_hex_ssid (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -4884,14 +4692,12 @@ test_write_wifi_wep (void) s_con = (NMSettingConnection *) 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 Wifi WEP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4942,36 +4748,28 @@ test_write_wifi_wep (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_adhoc (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -4983,14 +4781,12 @@ test_write_wifi_wep_adhoc (void) s_con = (NMSettingConnection *) 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 Wifi WEP AdHoc", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5045,35 +4841,27 @@ test_write_wifi_wep_adhoc (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_passphrase (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -5084,14 +4872,12 @@ test_write_wifi_wep_passphrase (void) s_con = (NMSettingConnection *) 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 Wifi WEP Passphrase", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5140,35 +4926,27 @@ test_write_wifi_wep_passphrase (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_40_ascii (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah40"; struct stat statbuf; @@ -5179,14 +4957,12 @@ test_write_wifi_wep_40_ascii (void) s_con = (NMSettingConnection *) 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 Wifi WEP 40 ASCII", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5237,35 +5013,27 @@ test_write_wifi_wep_40_ascii (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_104_ascii (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah104"; struct stat statbuf; @@ -5276,14 +5044,12 @@ test_write_wifi_wep_104_ascii (void) s_con = (NMSettingConnection *) 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 Wifi WEP 104 ASCII", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5334,36 +5100,27 @@ test_write_wifi_wep_104_ascii (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_leap (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -5374,14 +5131,12 @@ test_write_wifi_leap (void) s_con = (NMSettingConnection *) 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 Wifi LEAP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5429,35 +5184,27 @@ test_write_wifi_leap (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_leap_secret_flags (gconstpointer data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; NMSettingSecretFlags flags = GPOINTER_TO_UINT (data); @@ -5467,20 +5214,16 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Wifi LEAP Secret Flags", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -5492,7 +5235,6 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -5505,13 +5247,11 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -5526,7 +5266,6 @@ test_write_wifi_leap_secret_flags (gconstpointer data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); /* No key should be written out since the secret is not system owned */ keyfile = utils_get_keys_path (testfile); @@ -5537,26 +5276,20 @@ test_write_wifi_leap_secret_flags (gconstpointer data) */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, NULL, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_psk (gconstpointer test_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct { @@ -5574,14 +5307,12 @@ test_write_wifi_wpa_psk (gconstpointer test_data) s_con = (NMSettingConnection *) 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, args.name, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5642,33 +5373,25 @@ test_write_wifi_wpa_psk (gconstpointer test_data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_psk_adhoc (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; NMIPAddress *addr; @@ -5679,14 +5402,12 @@ test_write_wifi_wpa_psk_adhoc (void) s_con = (NMSettingConnection *) 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 Wifi WPA PSK", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5748,35 +5469,27 @@ test_write_wifi_wpa_psk_adhoc (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_tls (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -5786,14 +5499,12 @@ test_write_wifi_wpa_eap_tls (void) s_con = (NMSettingConnection *) 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 Wifi WPA EAP-TLS", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5869,35 +5580,27 @@ test_write_wifi_wpa_eap_tls (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_ttls_tls (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -5907,14 +5610,12 @@ test_write_wifi_wpa_eap_ttls_tls (void) s_con = (NMSettingConnection *) 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 Wifi WPA EAP-TTLS (TLS)", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -6006,35 +5707,27 @@ test_write_wifi_wpa_eap_ttls_tls (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_ttls_mschapv2 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -6044,14 +5737,12 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) s_con = (NMSettingConnection *) 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 Wifi WPA EAP-TTLS (MSCHAPv2)", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -6120,34 +5811,24 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); - - keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); + keyfile = utils_get_keys_path (testfile); } static void test_write_wifi_wpa_then_open (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - gboolean success; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -6156,25 +5837,20 @@ test_write_wifi_wpa_then_open (void) */ connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6188,7 +5864,6 @@ test_write_wifi_wpa_then_open (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6206,16 +5881,12 @@ test_write_wifi_wpa_then_open (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); - g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, @@ -6239,50 +5910,30 @@ test_write_wifi_wpa_then_open (void) nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Write it back out */ + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - &error); - g_assert_no_error (error); - g_assert (success); - - unlink (keyfile); - g_free (keyfile); - keyfile = NULL; + g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); - - /* No keyfile since it's an open connection this time */ - keyfile = utils_get_keys_path (testfile); - g_assert (g_file_test (keyfile, G_FILE_TEST_EXISTS) == FALSE); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - unlink (testfile); - g_free (testfile); - g_free (keyfile); - g_object_unref (reread); - - g_object_unref (connection); } static void test_write_wifi_wpa_then_wep_with_perms (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; char **perms; const char *ssid_data = "SomeSSID"; @@ -6296,25 +5947,21 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); perms = g_strsplit ("user:superman:", ",", -1); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection 2", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_PERMISSIONS, perms, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); g_strfreev (perms); g_assert_cmpint (nm_setting_connection_get_num_permissions (s_con), ==, 1); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6328,7 +5975,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6346,14 +5992,12 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6377,7 +6021,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Now change the connection to WEP and recheck */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6386,16 +6029,9 @@ test_write_wifi_wpa_then_wep_with_perms (void) nm_setting_wireless_security_set_wep_key (s_wsec, 0, "abraka dabra"); /* Write it back out */ - keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - &error); - g_assert_no_error (error); - g_assert (success); - - g_free (keyfile); - keyfile = NULL; + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6406,55 +6042,38 @@ test_write_wifi_wpa_then_wep_with_perms (void) g_assert (success); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); - unlink (testfile); - g_free (keyfile); - - g_free (testfile); - g_object_unref (reread); - - g_object_unref (connection); } static void test_write_wifi_dynamic_wep_leap (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Wifi Dynamic WEP LEAP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6468,14 +6087,12 @@ test_write_wifi_dynamic_wep_leap (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); /* Wireless security setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - g_assert (s_8021x); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); nm_setting_802_1x_add_eap_method (s_8021x, "leap"); @@ -6487,13 +6104,11 @@ test_write_wifi_dynamic_wep_leap (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6510,7 +6125,6 @@ test_write_wifi_dynamic_wep_leap (void) reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -6518,38 +6132,23 @@ test_write_wifi_dynamic_wep_leap (void) * did not get written. Check first that the auth alg is not set to "LEAP" * and next that the only IEEE 802.1x EAP method is "LEAP". */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg); - tmp = svGetValueString (ifcfg, "SECURITYMODE"); - g_assert_cmpstr (tmp, ==, NULL); - g_free (tmp); - - tmp = svGetValueString (ifcfg, "IEEE_8021X_EAP_METHODS"); - g_assert_cmpstr (tmp, ==, "LEAP"); - g_free (tmp); - + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "SECURITYMODE", NULL); + _svGetValue_check (ifcfg, "IEEE_8021X_EAP_METHODS", "LEAP"); svCloseFile (ifcfg); - unlink (testfile); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_qeth_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; char **subchans; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -6557,14 +6156,12 @@ test_write_wired_qeth_dhcp (void) s_con = (NMSettingConnection *) 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 Wired qeth Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -6606,50 +6203,37 @@ test_write_wired_qeth_dhcp (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_ctc_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; char **subchans; - GError *error = NULL; - char *testfile = NULL; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Wired ctc Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); subchans = g_strsplit ("0.0.600,0.0.601", ",", -1); @@ -6662,13 +6246,11 @@ test_write_wired_ctc_dhcp (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6683,43 +6265,30 @@ test_write_wired_ctc_dhcp (void) &testfile); /* Ensure the CTCPROT item gets written out as it's own option */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg); + ifcfg = _svOpenFile (testfile); - tmp = svGetValueString (ifcfg, "CTCPROT"); - g_assert (tmp); - g_assert_cmpstr (tmp, ==, "0"); - g_free (tmp); + _svGetValue_check (ifcfg, "CTCPROT", "0"); /* And that it's not in the generic OPTIONS string */ - tmp = svGetValueString (ifcfg, "OPTIONS"); - g_assert (tmp == NULL); - g_free (tmp); + _svGetValue_check (ifcfg, "OPTIONS", NULL); svCloseFile (ifcfg); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_permissions (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -6727,14 +6296,12 @@ test_write_permissions (void) s_con = (NMSettingConnection *) 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 Permissions", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); nm_setting_connection_add_permission (s_con, "user", "blahblah", NULL); nm_setting_connection_add_permission (s_con, "user", "foobar", NULL); @@ -6768,55 +6335,44 @@ test_write_permissions (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_agent_keys (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; const char *str_ssid = "foobarbaz"; GBytes *ssid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection != NULL); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Wifi WEP Agent Owned", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6826,7 +6382,6 @@ test_write_wifi_wep_agent_keys (void) /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (str_ssid, strlen (str_ssid)); @@ -6838,7 +6393,6 @@ test_write_wifi_wep_agent_keys (void) /* Wifi security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6855,7 +6409,6 @@ test_write_wifi_wep_agent_keys (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); /* Remove the WEP key from the original, because it should not have been * written out to disk as it was agent-owned. The new connection should @@ -6868,10 +6421,6 @@ test_write_wifi_wep_agent_keys (void) NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -6883,7 +6432,6 @@ test_write_wired_pppoe (void) NMSettingIPConfig *s_ip4; NMSettingPppoe *s_pppoe; NMSettingPpp *s_ppp; - char *uuid; GError *error = NULL; connection = nm_simple_connection_new (); @@ -6892,14 +6440,12 @@ test_write_wired_pppoe (void) s_con = (NMSettingConnection *) 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 Wired PPPoE", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -6944,7 +6490,6 @@ test_write_vpn (void) NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; NMSettingVpn *s_vpn; - char *uuid; GError *error = NULL; connection = nm_simple_connection_new (); @@ -6953,14 +6498,12 @@ test_write_vpn (void) s_con = (NMSettingConnection *) 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 VPN", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VPN_SETTING_NAME, NULL); - g_free (uuid); /* VPN setting */ s_vpn = (NMSettingVpn *) nm_setting_vpn_new (); @@ -7002,7 +6545,6 @@ test_write_mobile_broadband (gconstpointer data) NMSettingCdma *s_cdma; NMSettingPpp *s_ppp; NMSettingSerial *s_serial; - char *uuid; GError *error = NULL; gboolean gsm = GPOINTER_TO_UINT (data); @@ -7012,14 +6554,12 @@ test_write_mobile_broadband (gconstpointer data) s_con = (NMSettingConnection *) 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, gsm ? "Test Write GSM" : "Test Write CDMA", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, gsm ? NM_SETTING_GSM_SETTING_NAME : NM_SETTING_CDMA_SETTING_NAME, NULL); - g_free (uuid); if (gsm) { /* GSM setting */ @@ -7104,39 +6644,34 @@ test_read_bridge_main (void) static void test_write_bridge_main (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBridge *s_bridge; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr; static const char *mac = "31:33:33:37:be:cd"; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Bridge Main", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, "br0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); - g_free (uuid); /* bridge setting */ s_bridge = (NMSettingBridge *) nm_setting_bridge_new (); - g_assert (s_bridge); nm_connection_add_setting (connection, NM_SETTING (s_bridge)); g_object_set (s_bridge, @@ -7145,7 +6680,6 @@ test_write_bridge_main (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -7161,7 +6695,6 @@ test_write_bridge_main (void) /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -7177,13 +6710,8 @@ test_write_bridge_main (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BRIDGE, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7213,38 +6741,33 @@ test_read_bridge_component (void) static void test_write_bridge_component (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSetting *s_port; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Bridge Component", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "br0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); g_object_set (s_wired, @@ -7267,13 +6790,8 @@ test_write_bridge_component (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7506,78 +7024,64 @@ test_read_vlan_flags_2 (void) static void test_write_vlan (void) { - NMConnection *connection; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; connection = _connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); - - unlink (written); - g_free (written); - - g_object_unref (connection); + &testfile); } static void test_write_vlan_flags (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-flags-2", NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_vlan_only_vlanid (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_vlan_reorder_hdr (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingVlan *s_vlan; NMSettingWired *s_wired; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7585,14 +7089,12 @@ test_write_vlan_reorder_hdr (void) s_con = (NMSettingConnection *) 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 VLAN reorder_hdr", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7613,51 +7115,40 @@ test_write_vlan_reorder_hdr (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void test_write_ethernet_missing_ipv6 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); 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 Ethernet Without IPv6 Setting", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -7679,13 +7170,8 @@ test_write_ethernet_missing_ipv6 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7722,17 +7208,16 @@ test_read_bond_main (void) static void test_write_bond_main (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBond *s_bond; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSettingWired *s_wired; - char *uuid; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7740,15 +7225,13 @@ test_write_bond_main (void) s_con = (NMSettingConnection *) 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 Bond Main", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, "bond0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7790,13 +7273,8 @@ test_write_bond_main (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BOND, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7822,14 +7300,13 @@ test_read_bond_slave (void) static void test_write_bond_slave (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7837,16 +7314,14 @@ test_write_bond_slave (void) s_con = (NMSettingConnection *) 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 Bond Slave", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "bond0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7864,13 +7339,8 @@ test_write_bond_slave (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7908,18 +7378,17 @@ test_read_infiniband (void) static void test_write_infiniband (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; guint32 mtu = 65520; - char *uuid; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7927,14 +7396,12 @@ test_write_infiniband (void) s_con = (NMSettingConnection *) 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 InfiniBand", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NULL); - g_free (uuid); /* InfiniBand setting */ s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -7976,19 +7443,14 @@ test_write_infiniband (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_INFINIBAND, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_bond_slave_ib (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-slave-ib", @@ -7998,22 +7460,18 @@ test_read_bond_slave_ib (void) g_assert (s_con); g_assert_cmpstr (nm_setting_connection_get_master (s_con), ==, "bond0"); - g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NM_SETTING_BOND_SETTING_NAME); - - g_object_unref (connection); } static void test_write_bond_slave_ib (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; static const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -8021,16 +7479,14 @@ test_write_bond_slave_ib (void) s_con = (NMSettingConnection *) 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 Bond Slave InfiniBand", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "bond0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* InfiniBand setting */ s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -8049,13 +7505,8 @@ test_write_bond_slave_ib (void) &testfile); reread = _connection_from_file (testfile, NULL, NULL, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8145,14 +7596,15 @@ test_read_dcb_basic (void) static void test_write_dcb_basic (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; guint i; - char *uuid, *testfile; const guint group_ids[8] = { 4, 0xF, 6, 0xF, 1, 7, 3, 0xF }; const guint group_bandwidths[8] = { 10, 20, 15, 10, 2, 3, 35, 5 }; const guint bandwidths[8] = { 10, 20, 30, 40, 50, 10, 0, 25 }; @@ -8164,14 +7616,12 @@ test_write_dcb_basic (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, "dcb-test", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, "eth0", NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -8217,19 +7667,14 @@ test_write_dcb_basic (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void test_read_dcb_default_app_priorities (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingDcb *s_dcb; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-default-app-priorities", @@ -8246,8 +7691,6 @@ test_read_dcb_default_app_priorities (void) g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpint (nm_setting_dcb_get_app_fip_priority (s_dcb), ==, -1); - - g_object_unref (connection); } static void @@ -8358,49 +7801,45 @@ test_read_dcb_pgpct_not_100 (void) static void test_read_fcoe_mode (gconstpointer user_data) { + gs_unref_object NMConnection *connection = NULL; + gs_free char *file = NULL; const char *expected_mode = user_data; - NMConnection *connection; NMSettingDcb *s_dcb; - char *file; file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file (file, NULL, TYPE_ETHERNET, NULL); - g_free (file); s_dcb = nm_connection_get_setting_dcb (connection); g_assert (s_dcb); g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpstr (nm_setting_dcb_get_app_fcoe_mode (s_dcb), ==, expected_mode); - - g_object_unref (connection); } static void test_write_fcoe_mode (gconstpointer user_data) { + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; const char *expected_mode = user_data; - NMConnection *connection, *reread; - GError *error = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid, *testfile; + shvarFile *ifcfg; connection = nm_simple_connection_new (); s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, "fcoe-test", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, "eth0", NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -8430,26 +7869,13 @@ test_write_fcoe_mode (gconstpointer user_data) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - { - shvarFile *ifcfg = svOpenFile (testfile, &error); - char *written_mode; - - g_assert_no_error (error); - g_assert (ifcfg); - written_mode = svGetValueString (ifcfg, "DCB_APP_FCOE_MODE"); - svCloseFile (ifcfg); - g_assert_cmpstr (written_mode, ==, expected_mode); - g_free (written_mode); - } + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "DCB_APP_FCOE_MODE", expected_mode); + svCloseFile (ifcfg); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void @@ -8504,14 +7930,14 @@ test_read_team_master_invalid (gconstpointer user_data) static void test_write_team_master (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingTeam *s_team; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; const char *expected_config = "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"; shvarFile *f; @@ -8521,14 +7947,12 @@ test_write_team_master (void) s_con = (NMSettingConnection *) 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 Team Master", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_INTERFACE_NAME, "team0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (uuid); /* Team setting */ s_team = (NMSettingTeam *) nm_setting_team_new (); @@ -8544,7 +7968,6 @@ test_write_team_master (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -8553,7 +7976,6 @@ test_write_team_master (void) /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -8568,30 +7990,14 @@ test_write_team_master (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "DEVICETYPE"); - g_assert (val); - g_assert_cmpstr (val, ==, "Team"); - g_free (val); - val = svGetValueString (f, "TEAM_CONFIG"); - g_assert (val); - g_assert_cmpstr (val, ==, expected_config); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "DEVICETYPE", "Team"); + _svGetValue_check (f, "TEAM_CONFIG", expected_config); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8626,8 +8032,6 @@ test_write_team_port (void) NMSettingConnection *s_con; NMSettingTeamPort *s_team_port; NMSettingWired *s_wired; - char *uuid, *val; - GError *error = NULL; const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; shvarFile *f; @@ -8637,15 +8041,13 @@ test_write_team_port (void) s_con = (NMSettingConnection *) 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 Team Port", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "team0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (uuid); /* Team setting */ s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new (); @@ -8662,23 +8064,11 @@ test_write_team_port (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "TYPE"); - g_assert (!val); - val = svGetValueString (f, "DEVICETYPE"); - g_assert (val); - g_assert_cmpstr (val, ==, "TeamPort"); - g_free (val); - val = svGetValueString (f, "TEAM_PORT_CONFIG"); - g_assert_cmpstr (val, ==, expected_config); - g_free (val); - val = svGetValueString (f, "TEAM_MASTER"); - g_assert_cmpstr (val, ==, "team0"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "TYPE", NULL); + _svGetValue_check (f, "DEVICETYPE", "TeamPort"); + _svGetValue_check (f, "TEAM_PORT_CONFIG", expected_config); + _svGetValue_check (f, "TEAM_MASTER", "team0"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, @@ -9025,34 +8415,23 @@ test_write_unknown (gconstpointer test_data) gs_free char *file_contents_exp = NULL; gs_free char *tmp = NULL; - sv = svOpenFile (testfile, &error); - nmtst_assert_success (sv, error); + sv = _svOpenFile (testfile); svFileSetName (sv, filename_tmp_1); svFileSetModified (sv); if (g_str_has_suffix (testfile, "ifcfg-test-write-unknown-4")) { - g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "l4x"); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, NULL); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "name3-value"); - nm_clear_g_free (&tmp); + _svGetValue_check (sv, "NAME", "l4x"); + _svGetValue_check (sv, "NAME2", NULL); + _svGetValue_check (sv, "NAME3", "name3-value"); svSetValue (sv, "NAME", "set-by-test1"); svSetValue (sv, "NAME2", "set-by-test2"); svSetValue (sv, "NAME3", "set-by-test3"); - g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "set-by-test1"); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, "set-by-test2"); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "set-by-test3"); - nm_clear_g_free (&tmp); + _svGetValue_check (sv, "NAME", "set-by-test1"); + _svGetValue_check (sv, "NAME2", "set-by-test2"); + _svGetValue_check (sv, "NAME3", "set-by-test3"); } success = svWriteFile (sv, 0644, &error); From c5ac66d392e7543c1fef77cd76c8ba4dbaeaf790 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Nov 2016 17:53:22 +0100 Subject: [PATCH 38/39] ifcfg-rh: restore previous behavior for svUnescape() stripping backslash from double-quoting Now we could parse simple shell variable assignment properly, but old versions of svEscape() wrote invalid double-quoted strings. Add a hack to restore the broken behavior for that case only. --- src/settings/plugins/ifcfg-rh/shvar.c | 44 ++++++++++++++++++- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 19 +++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index ff294c7f4..b8dcfb718 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -245,6 +245,28 @@ svEscape (const char *s, char **to_free) return new; } +static gboolean +_looks_like_old_svescaped (const char *value) +{ + gsize k; + + if (value[0] != '"') + return FALSE; + + for (k = 1; ; k++) { + if (value[k] == '\0') + return FALSE; + if (value[k] == '"') + return (value[k + 1] == '\0'); + if (value[k] == '\\') { + k++; + if (!_char_in_strset (value[k], "\"'\\$~`")) + return FALSE; + } else if (_char_in_strset (value[k], "'\\$~`")) + return FALSE; + } +} + static gboolean _ch_octal_is (char ch) { @@ -302,6 +324,7 @@ svUnescape (const char *value, char **to_free) { gsize i, j; nm_auto_free_gstring GString *str = NULL; + int looks_like_old_svescaped = -1; /* we handle bash syntax here (note that ifup has #!/bin/bash. * Thus, see https://www.gnu.org/software/bash/manual/html_node/Quoting.html#Quoting */ @@ -404,7 +427,26 @@ svUnescape (const char *value, char **to_free) /* we don't support line continuation */ goto out_error; } - if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) + if (NM_IN_SET (value[i], '$', '`', '"', '\\')) { + /* Drop the backslash. */ + } else if (NM_IN_SET (value[i], '\'', '~')) { + /* '\'' and '~' in double qoutes are not handled special by shell. + * However, old versions of svEscape() would wrongly use double-quoting + * with backslash escaping for these characters (expecting svUnescape() + * to remove the backslash). + * + * In order to preserve previous behavior, we continue to read such + * strings different then shell does. */ + + /* Actually, we can relax this. Old svEscape() escaped the entire value + * in a particular way with double quotes. + * If the value doesn't exactly look like something as created by svEscape(), + * don't do the compat hack and preserve the backslash. */ + if (looks_like_old_svescaped < 0) + looks_like_old_svescaped = _looks_like_old_svescaped (value); + if (!looks_like_old_svescaped) + g_string_append_c (str, '\\'); + } else g_string_append_c (str, '\\'); } g_string_append_c (str, value[i]); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index c5e5456af..3ee8589c1 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8233,8 +8233,6 @@ test_svUnescape (void) V1 ("\"\\\\\"", "\\"), V1 ("\"\\a\"", "\\a"), V1 ("\"\\b\"", "\\b"), - V1 ("\"\\'\"", "\\'"), - V1 ("\"\\~\"", "\\~"), V1 ("\"\\\t\"", "\\\t"), V0 ("ab\r", "ab"), V0 ("a'b'\r ", "ab"), @@ -8262,6 +8260,23 @@ test_svUnescape (void) V1 ("\"aa\\\"\"", "aa\""), V1 ("\"aa\\\"b\"c", "aa\"bc"), V1 ("\"aa\\\"\"b", "aa\"b"), + + /* the following is not shell behavior, but kept for backward compatibility + * with old svEscape(). */ + V0 ("\"\\'\"", "'"), + V0 ("\"\\~\"", "~"), + V0 ("\"b\\~b\"", "b~b"), + V0 ("\"\\~\\~\"", "~~"), + V0 ("\"\\~\\'\"", "~'"), + + /* the following is shell-behavior, because it doesn't look like written + * by old svEscape(). */ + V1 ("\"\\~~\"", "\\~~"), + V1 ("\"\\a\\'\"", "\\a\\'"), + V1 ("x\"\\~\"", "x\\~"), + V1 ("\"\\'\"''", "\\'"), + V0 ("\"b\\~b\" ", "b\\~b"), + V1 ("\"b\\~b\"x", "b\\~bx"), }; const UnescapeTestData data_ansi[] = { /* strings inside $''. They cannot be compared directly, but must From 92712d3b31b5e63e8c3c09b8cbcd05764a7a924e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Nov 2016 11:05:31 +0100 Subject: [PATCH 39/39] ifcfg-rh: optimize checking character types during svEscape() I don't think that the compiler is able to optimize strchr($SET_AS_STR, $CHAR) Use NM_IN_SET() which expands to something that should be easy for the compiler to optimize. --- src/settings/plugins/ifcfg-rh/shvar.c | 29 ++++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index b8dcfb718..b4b3c0c3f 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -191,27 +191,26 @@ _escape_ansic (const char *source) /*****************************************************************************/ -#define _char_in_strset(ch, str) (!!strchr (""str"", (ch))) - -#define ESC_ESCAPEES "\"\\$`" /* must be escaped */ -#define ESC_SPACES " '\t~|&;()<>" /* only require "" */ +#define _char_req_escape(ch) NM_IN_SET (ch, '\"', '\\', '$', '`') +#define _char_req_escape_old(ch) NM_IN_SET (ch, '\"', '\\', '\'', '$', '`', '~') +#define _char_req_quotes(ch) NM_IN_SET (ch, ' ', '\'', '~', '\t', '|', '&', ';', '(', ')', '<', '>') const char * svEscape (const char *s, char **to_free) { char *new; gsize mangle = 0; - gboolean has_space = FALSE; + gboolean requires_quotes = FALSE; int newlen; size_t i, j, slen; slen = strlen (s); for (i = 0; i < slen; i++) { - if (_char_in_strset (s[i], ESC_ESCAPEES)) + if (_char_req_escape (s[i])) mangle++; - else if (_char_in_strset (s[i], ESC_SPACES)) - has_space = TRUE; + else if (_char_req_quotes (s[i])) + requires_quotes = TRUE; else if (s[i] < ' ') { /* if the string contains newline we can only express it using ANSI C quotation * (as we don't support line continuation). @@ -220,7 +219,7 @@ svEscape (const char *s, char **to_free) return (*to_free = _escape_ansic (s)); } } - if (!mangle && !has_space) { + if (!mangle && !requires_quotes) { *to_free = NULL; return s; } @@ -231,9 +230,8 @@ svEscape (const char *s, char **to_free) j = 0; new[j++] = '"'; for (i = 0; i < slen; i++) { - if (_char_in_strset (s[i], ESC_ESCAPEES)) { + if (_char_req_escape (s[i])) new[j++] = '\\'; - } new[j++] = s[i]; } new[j++] = '"'; @@ -256,13 +254,16 @@ _looks_like_old_svescaped (const char *value) for (k = 1; ; k++) { if (value[k] == '\0') return FALSE; + if (!_char_req_escape_old (value[k])) + continue; + if (value[k] == '"') return (value[k + 1] == '\0'); - if (value[k] == '\\') { + else if (value[k] == '\\') { k++; - if (!_char_in_strset (value[k], "\"'\\$~`")) + if (!_char_req_escape_old (value[k])) return FALSE; - } else if (_char_in_strset (value[k], "'\\$~`")) + } else return FALSE; } }