summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-11-09 12:21:18 +0100
committerThomas Haller <thaller@redhat.com>2016-11-09 12:21:18 +0100
commite3928c8c5ee83a09d73bf67820f51a7204e1cf50 (patch)
tree99af8c7d9e8496a41a981b665d7ccb303468d393
parente028edd1c5015caac4605dfc4460aa3f0c887fe7 (diff)
parent92712d3b31b5e63e8c3c09b8cbcd05764a7a924e (diff)
downloadNetworkManager-e3928c8c5ee83a09d73bf67820f51a7204e1cf50.tar.gz
ifcfg-rh: merge branch 'th/ifcfg-rh-shell-parsing-rh1369380'
https://bugzilla.redhat.com/show_bug.cgi?id=1369380
-rw-r--r--Makefile.am10
-rw-r--r--libnm-core/crypto.c27
-rw-r--r--libnm-core/nm-core-internal.h8
-rw-r--r--libnm-core/nm-utils.c26
-rw-r--r--shared/nm-utils/nm-macros-internal.h46
-rw-r--r--shared/nm-utils/nm-test-utils.h56
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c2
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c462
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c81
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h4
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c590
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h1
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c830
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.h17
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk2
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-18
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected12
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-23
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected4
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-33
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected5
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-432
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected27
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-22
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c1856
25 files changed, 2153 insertions, 1961 deletions
diff --git a/Makefile.am b/Makefile.am
index 6741cb495c..643a7ff118 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1926,7 +1926,15 @@ 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 \
+ 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/libnm-core/crypto.c b/libnm-core/crypto.c
index e734f40d89..c4e48475ff 100644
--- a/libnm-core/crypto.c
+++ b/libnm-core/crypto.c
@@ -771,13 +771,12 @@ 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;
- 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);
@@ -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)
@@ -804,14 +798,19 @@ 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++];
- 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);
}
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index 8fba357167..1b4c469420 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 4be430af6b..41b6304c82 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -2147,24 +2147,34 @@ next:
/*****************************************************************************/
/**
- * nm_utils_uuid_generate:
+ * nm_utils_uuid_generate_buf_:
+ * @buf: input buffer, must contain at least 37 bytes
*
- * Returns: a newly allocated UUID suitable for use as the #NMSettingConnection
- * object's #NMSettingConnection:id: property. Should be freed with g_free()
+ * Returns: generates a new random UUID, writes it to @buf and returns @buf.
**/
char *
-nm_utils_uuid_generate (void)
+nm_utils_uuid_generate_buf_ (char *buf)
{
uuid_t uuid;
- char *buf;
- buf = g_malloc0 (37);
uuid_generate_random (uuid);
- uuid_unparse_lower (uuid, &buf[0]);
+ uuid_unparse_lower (uuid, buf);
return buf;
}
/**
+ * nm_utils_uuid_generate:
+ *
+ * Returns: a newly allocated UUID suitable for use as the #NMSettingConnection
+ * object's #NMSettingConnection:id: property. Should be freed with g_free()
+ **/
+char *
+nm_utils_uuid_generate (void)
+{
+ return nm_utils_uuid_generate_buf_ (g_malloc (37));
+}
+
+/**
* nm_utils_uuid_generate_from_string:
* @s: a string to use as the seed for the UUID
* @slen: if negative, treat @s as zero terminated C string.
@@ -2212,7 +2222,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;
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 658b3b92a4..fdb45f9291 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)
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index 75d01bb632..7e712dcd79 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -1144,6 +1144,62 @@ 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_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)
{
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 3877bb7305..ea8f337661 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-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
index 0d59063b0e..142c2251a5 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 = 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", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "USERS");
if (value) {
char **items, **iter;
@@ -208,7 +208,7 @@ make_connection_setting (const char *file,
}
- zone = svGetValue(ifcfg, "ZONE", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ value = svGetValueString (ifcfg, metric_tag);
if (value) {
metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1);
if (metric < 0) {
@@ -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;
@@ -910,7 +910,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error)
char *value = NULL;
NMSettingProxyMethod method;
- value = svGetValue (ifcfg, "PROXY_METHOD", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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);
@@ -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;
@@ -993,9 +994,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 = svGetValueString (ifcfg, "DEVICE");
+ gatewaydev = svGetValueString (network_ifcfg, "GATEWAYDEV");
+ 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.
@@ -1008,7 +1009,7 @@ make_ip4_setting (shvarFile *ifcfg,
svCloseFile (network_ifcfg);
}
- value = svGetValue (ifcfg, "BOOTPROTO", FALSE);
+ value = svGetValueString (ifcfg, "BOOTPROTO");
if (!value || !*value || !g_ascii_strcasecmp (value, "none")) {
if (is_any_ip4_address_defined (ifcfg, NULL))
@@ -1070,12 +1071,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 = 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", FALSE);
+ value = svGetValueString (ifcfg, "DHCP_FQDN");
if (value && *value) {
g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NULL,
@@ -1089,7 +1090,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 = 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 +1153,7 @@ make_ip4_setting (shvarFile *ifcfg,
char *tag;
tag = g_strdup_printf ("DNS%u", i);
- value = svGetValue (ifcfg, tag, FALSE);
+ 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 +1174,7 @@ make_ip4_setting (shvarFile *ifcfg,
}
/* DNS searches */
- value = svGetValue (ifcfg, "DOMAIN", FALSE);
+ value = svGetValueString (ifcfg, "DOMAIN");
if (value) {
char **searches = NULL;
@@ -1192,12 +1193,9 @@ make_ip4_setting (shvarFile *ifcfg,
}
/* DNS options */
- value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE);
- 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);
@@ -1240,7 +1238,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 = svGetValueString (ifcfg, "SEARCH");
if (value) {
char **searches = NULL;
@@ -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;
@@ -1328,7 +1325,7 @@ read_aliases (NMSettingIPConfig *s_ip4, const char *filename)
continue;
}
- device = svGetValue (parsed, "DEVICE", FALSE);
+ device = svGetValueString (parsed, "DEVICE");
if (!device) {
PARSE_WARNING ("alias file '%s' has no DEVICE", full_path);
svCloseFile (parsed);
@@ -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;
@@ -1415,10 +1413,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 = 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_free);
if (ipv6_defaultgw) {
default_dev = strchr (ipv6_defaultgw, '%');
@@ -1442,7 +1440,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 = svGetValueString (ifcfg, "IPV6INIT");
ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE);
if (!str_value) {
network_ifcfg = svOpenFile (network_file, NULL);
@@ -1466,9 +1464,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 = svGetValueString (ifcfg, "IPV6ADDR");
if (!str_value)
- str_value = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE);
+ str_value = svGetValueString (ifcfg, "IPV6ADDR_SECONDARIES");
if (!str_value)
method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL;
@@ -1478,7 +1476,7 @@ make_ip6_setting (shvarFile *ifcfg,
/* TODO - handle other methods */
/* Read IPv6 Privacy Extensions configuration */
- tmp = svGetValue (ifcfg, "IPV6_PRIVACY", FALSE);
+ tmp = svGetValueString (ifcfg, "IPV6_PRIVACY");
if (tmp) {
ip6_privacy = svGetValueBoolean (ifcfg, "IPV6_PRIVACY", FALSE);
if (!ip6_privacy)
@@ -1511,7 +1509,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 = 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 +1520,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 = svGetValueString (ifcfg, "IPV6ADDR");
+ ipv6addr_secondaries = svGetValueString (ifcfg, "IPV6ADDR_SECONDARIES");
value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL,
ipv6addr ? ipv6addr : "",
@@ -1550,12 +1548,12 @@ make_ip6_setting (shvarFile *ifcfg,
/* Gateway */
if (nm_setting_ip_config_get_num_addresses (s_ip6)) {
- value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE);
+ 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", FALSE);
+ value = svGetValueString (network_ifcfg, "IPV6_DEFAULTGW");
svCloseFile (network_ifcfg);
}
}
@@ -1576,7 +1574,7 @@ make_ip6_setting (shvarFile *ifcfg,
}
/* IPv6 addressing mode configuration */
- tmp = svGetValue (ifcfg, "IPV6_ADDR_GEN_MODE", FALSE);
+ 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 +1590,7 @@ make_ip6_setting (shvarFile *ifcfg,
}
/* IPv6 tokenized interface identifier */
- tmp = svGetValue (ifcfg, "IPV6_TOKEN", FALSE);
+ tmp = svGetValueString (ifcfg, "IPV6_TOKEN");
if (tmp) {
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, tmp, NULL);
g_free (tmp);
@@ -1605,7 +1603,7 @@ make_ip6_setting (shvarFile *ifcfg,
char *tag;
tag = g_strdup_printf ("DNS%u", i);
- value = svGetValue (ifcfg, tag, FALSE);
+ value = svGetValueString (ifcfg, tag);
if (!value) {
g_free (tag);
break; /* all done */
@@ -1639,11 +1637,9 @@ make_ip6_setting (shvarFile *ifcfg,
}
/* DNS options */
- value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE);
- 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;
@@ -1667,7 +1662,7 @@ check_if_bond_slave (shvarFile *ifcfg,
{
char *value;
- value = svGetValue (ifcfg, "MASTER", FALSE);
+ value = svGetValueString (ifcfg, "MASTER");
if (value) {
g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL);
g_object_set (s_con,
@@ -1687,7 +1682,7 @@ check_if_team_slave (shvarFile *ifcfg,
{
gs_free char *value = NULL;
- value = svGetValue (ifcfg, "TEAM_MASTER", FALSE);
+ value = svGetValueString (ifcfg, "TEAM_MASTER");
if (!value)
return FALSE;
g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL);
@@ -1762,7 +1757,7 @@ read_dcb_app (shvarFile *ifcfg,
/* Priority */
tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app);
- val = svGetValue (ifcfg, tmp, FALSE);
+ val = svGetValueString (ifcfg, tmp);
if (val) {
priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1);
if (priority < 0) {
@@ -1803,7 +1798,7 @@ read_dcb_bool_array (shvarFile *ifcfg,
gboolean success = FALSE;
guint i;
- val = svGetValue (ifcfg, prop, FALSE);
+ val = svGetValueString (ifcfg, prop);
if (!val)
return TRUE;
@@ -1854,7 +1849,7 @@ read_dcb_uint_array (shvarFile *ifcfg,
gboolean success = FALSE;
guint i;
- val = svGetValue (ifcfg, prop, FALSE);
+ val = svGetValueString (ifcfg, prop);
if (!val)
return TRUE;
@@ -1908,7 +1903,7 @@ read_dcb_percent_array (shvarFile *ifcfg,
char **split = NULL, **iter;
guint i, sum = 0;
- val = svGetValue (ifcfg, prop, FALSE);
+ val = svGetValueString (ifcfg, prop);
if (!val)
return TRUE;
@@ -1986,7 +1981,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 = 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 +2118,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 = svGetValueString (ifcfg, shvar_key);
if (!value || !strlen (value)) {
g_free (value);
return TRUE;
@@ -2230,7 +2225,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 = svGetValueString (ifcfg, flags_key);
if (val) {
if (strstr (val, SECRET_FLAG_AGENT))
flags |= NM_SETTING_SECRET_FLAG_AGENT_OWNED;
@@ -2259,7 +2254,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 = 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 +2290,7 @@ make_wep_setting (shvarFile *ifcfg,
}
}
- value = svGetValue (ifcfg, "SECURITYMODE", FALSE);
+ value = svGetValueString (ifcfg, "SECURITYMODE");
if (value) {
char *lcase;
@@ -2358,16 +2353,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 = svGetValueString (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE");
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
@@ -2422,9 +2411,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
@@ -2435,64 +2423,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 = svGetValueString (keys_ifcfg, "WPA_PSK");
svCloseFile (keys_ifcfg);
}
/* Fall back to the original ifcfg */
if (!psk)
- psk = svGetValue (ifcfg, "WPA_PSK", TRUE);
+ psk = svGetValueString (ifcfg, "WPA_PSK");
if (!psk)
return NULL;
- p = psk;
- plen = strlen (p);
-
- 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;
+ plen = strlen (psk);
- 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
@@ -2506,7 +2466,7 @@ eap_simple_reader (const char *eap_method,
NMSettingSecretFlags flags;
char *value;
- value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE);
+ 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'.",
@@ -2521,10 +2481,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 = svGetValueString (ifcfg, "IEEE_8021X_PASSWORD");
if (!value && keys) {
/* Try the lookaside keys file */
- value = svGetValue (keys, "IEEE_8021X_PASSWORD", FALSE);
+ value = svGetValueString (keys, "IEEE_8021X_PASSWORD");
}
if (!value) {
@@ -2587,7 +2547,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 = 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'.",
@@ -2597,7 +2557,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 = svGetValueString (ifcfg, ca_cert_key);
if (ca_cert) {
real_path = get_full_file_path (svFileGetName (ifcfg), ca_cert);
if (phase2) {
@@ -2629,10 +2589,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 = svGetValueString (ifcfg, pk_pw_key);
if (!privkey_password && keys) {
/* Try the lookaside keys file */
- privkey_password = svGetValue (keys, pk_pw_key, FALSE);
+ privkey_password = svGetValueString (keys, pk_pw_key);
}
if (!privkey_password) {
@@ -2645,7 +2605,7 @@ eap_tls_reader (const char *eap_method,
}
/* The private key itself */
- privkey = svGetValue (ifcfg, pk_key, FALSE);
+ 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'.",
@@ -2682,7 +2642,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 = 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'.",
@@ -2739,7 +2699,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 = 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,
@@ -2753,7 +2713,7 @@ eap_peap_reader (const char *eap_method,
eap_method);
}
- peapver = svGetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", FALSE);
+ 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);
@@ -2770,11 +2730,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 = 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", FALSE);
+ 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.");
@@ -2843,7 +2803,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 = 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,
@@ -2857,11 +2817,11 @@ eap_ttls_reader (const char *eap_method,
eap_method);
}
- anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE);
+ 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", FALSE);
+ 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.");
@@ -2934,13 +2894,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 = 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", FALSE);
+ 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++) {
@@ -2968,11 +2928,11 @@ eap_fast_reader (const char *eap_method,
goto done;
}
- anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE);
+ 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", FALSE);
+ 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.");
@@ -3059,7 +3019,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 = svGetValueString (ifcfg, ifcfg_var_name);
if (!value)
return;
@@ -3082,7 +3042,7 @@ fill_8021x (shvarFile *ifcfg,
char *value;
char **list = NULL, **iter;
- value = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE);
+ 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'",
@@ -3143,11 +3103,11 @@ fill_8021x (shvarFile *ifcfg,
goto error;
}
- value = svGetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH", FALSE);
+ 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", FALSE);
+ 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);
@@ -3156,10 +3116,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 = 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", FALSE);
+ 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);
@@ -3192,7 +3152,7 @@ make_wpa_setting (shvarFile *ifcfg,
wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
- value = svGetValue (ifcfg, "KEY_MGMT", FALSE);
+ value = svGetValueString (ifcfg, "KEY_MGMT");
wpa_psk = !g_strcmp0 (value, "WPA-PSK");
wpa_eap = !g_strcmp0 (value, "WPA-EAP");
ieee8021x = !g_strcmp0 (value, "IEEE8021X");
@@ -3212,8 +3172,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 = 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");
@@ -3267,7 +3227,7 @@ make_wpa_setting (shvarFile *ifcfg,
g_free (value);
- value = svGetValue (ifcfg, "SECURITYMODE", FALSE);
+ value = svGetValueString (ifcfg, "SECURITYMODE");
if (NM_IN_STRSET (value, NULL, "open"))
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, value, NULL);
@@ -3293,12 +3253,12 @@ make_leap_setting (shvarFile *ifcfg,
wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
- value = svGetValue (ifcfg, "KEY_MGMT", FALSE);
+ value = svGetValueString (ifcfg, "KEY_MGMT");
if (!value || strcmp (value, "IEEE8021X"))
goto error; /* Not LEAP */
g_free (value);
- value = svGetValue (ifcfg, "SECURITYMODE", FALSE);
+ value = svGetValueString (ifcfg, "SECURITYMODE");
if (!value || strcasecmp (value, "leap"))
goto error; /* Not LEAP */
@@ -3309,12 +3269,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 = 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", FALSE);
+ value = svGetValueString (keys_ifcfg, "IEEE_8021X_PASSWORD");
svCloseFile (keys_ifcfg);
}
}
@@ -3323,7 +3283,7 @@ make_leap_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE);
+ 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");
@@ -3408,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;
@@ -3415,25 +3376,25 @@ make_wireless_setting (shvarFile *ifcfg,
s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ());
- value = svGetValue (ifcfg, "HWADDR", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "HWADDR_BLACKLIST");
if (value) {
char **strv;
@@ -3443,39 +3404,19 @@ make_wireless_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "ESSID", TRUE);
+ value = svGetValueString (ifcfg, "ESSID");
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);
@@ -3484,17 +3425,15 @@ 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);
}
- value = svGetValue (ifcfg, "MODE", FALSE);
+ value = svGetValueString (ifcfg, "MODE");
if (value) {
char *lcase;
const char *mode = NULL;
@@ -3520,14 +3459,14 @@ make_wireless_setting (shvarFile *ifcfg,
g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, mode, NULL);
}
- value = svGetValue (ifcfg, "BSSID", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "CHANNEL");
if (value) {
errno = 0;
chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0);
@@ -3541,7 +3480,7 @@ make_wireless_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "BAND", FALSE);
+ value = svGetValueString (ifcfg, "BAND");
if (value) {
if (!strcmp (value, "a")) {
if (chan && chan <= 14) {
@@ -3572,7 +3511,7 @@ make_wireless_setting (shvarFile *ifcfg,
g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "bg", NULL);
}
- value = svGetValue (ifcfg, "MTU", FALSE);
+ value = svGetValueString (ifcfg, "MTU");
if (value) {
int mtu;
@@ -3592,19 +3531,19 @@ make_wireless_setting (shvarFile *ifcfg,
svGetValueBoolean (ifcfg, "SSID_HIDDEN", FALSE),
NULL);
- value = svGetValueFull (ifcfg, "POWERSAVE", FALSE);
- 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;
}
@@ -3616,17 +3555,17 @@ make_wireless_setting (shvarFile *ifcfg,
powersave,
NULL);
- value = svGetValueFull (ifcfg, "MAC_ADDRESS_RANDOMIZATION", FALSE);
- 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;
}
@@ -3849,7 +3788,7 @@ make_wired_setting (shvarFile *ifcfg,
s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
- value = svGetValue (ifcfg, "MTU", FALSE);
+ value = svGetValueString (ifcfg, "MTU");
if (value) {
int mtu;
@@ -3861,14 +3800,14 @@ make_wired_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "HWADDR", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "SUBCHANNELS");
if (value) {
const char *p = value;
gboolean success = TRUE;
@@ -3899,18 +3838,18 @@ make_wired_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "PORTNAME", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ 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);
@@ -3919,7 +3858,7 @@ make_wired_setting (shvarFile *ifcfg,
}
g_free (nettype);
- value = svGetValue (ifcfg, "OPTIONS", FALSE);
+ value = svGetValueString (ifcfg, "OPTIONS");
if (value && strlen (value)) {
char **options, **iter;
@@ -3940,18 +3879,18 @@ make_wired_setting (shvarFile *ifcfg,
}
g_free (value);
- value = svGetValue (ifcfg, "MACADDR", FALSE);
+ 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", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "HWADDR_BLACKLIST");
if (value) {
char **strv;
@@ -3961,7 +3900,7 @@ make_wired_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "KEY_MGMT", FALSE);
+ value = svGetValueString (ifcfg, "KEY_MGMT");
if (value) {
if (!strcmp (value, "IEEE8021X")) {
*s_8021x = fill_8021x (ifcfg, file, value, FALSE, error);
@@ -3975,8 +3914,8 @@ make_wired_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValueFull (ifcfg, "ETHTOOL_OPTS", FALSE);
- 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;
@@ -4036,19 +3975,19 @@ parse_infiniband_p_key (shvarFile *ifcfg,
int id;
gboolean ret = FALSE;
- device = svGetValue (ifcfg, "DEVICE", FALSE);
+ device = svGetValueString (ifcfg, "DEVICE");
if (!device) {
PARSE_WARNING ("InfiniBand connection specified PKEY but not DEVICE");
goto done;
}
- physdev = svGetValue (ifcfg, "PHYSDEV", FALSE);
+ physdev = svGetValueString (ifcfg, "PHYSDEV");
if (!physdev) {
PARSE_WARNING ("InfiniBand connection specified PKEY but not PHYSDEV");
goto done;
}
- pkey_id = svGetValue (ifcfg, "PKEY_ID", FALSE);
+ pkey_id = svGetValueString (ifcfg, "PKEY_ID");
if (!pkey_id) {
PARSE_WARNING ("InfiniBand connection specified PKEY but not PKEY_ID");
goto done;
@@ -4096,7 +4035,7 @@ make_infiniband_setting (shvarFile *ifcfg,
s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ());
- value = svGetValue (ifcfg, "MTU", FALSE);
+ value = svGetValueString (ifcfg, "MTU");
if (value) {
int mtu;
@@ -4108,7 +4047,7 @@ make_infiniband_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "HWADDR", FALSE);
+ value = svGetValueString (ifcfg, "HWADDR");
if (value) {
value = g_strstrip (value);
g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, value, NULL);
@@ -4208,7 +4147,7 @@ make_bond_setting (shvarFile *ifcfg,
s_bond = NM_SETTING_BOND (nm_setting_bond_new ());
- value = svGetValue (ifcfg, "DEVICE", FALSE);
+ value = svGetValueString (ifcfg, "DEVICE");
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"mandatory DEVICE keyword missing");
@@ -4216,7 +4155,7 @@ make_bond_setting (shvarFile *ifcfg,
}
g_free (value);
- value = svGetValue (ifcfg, "BONDING_OPTS", FALSE);
+ value = svGetValueString (ifcfg, "BONDING_OPTS");
if (value) {
char **items, **iter;
@@ -4297,33 +4236,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 = svGetValueString (ifcfg, key);
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 *
@@ -4337,7 +4269,7 @@ make_team_setting (shvarFile *ifcfg,
s_team = NM_SETTING_TEAM (nm_setting_team_new ());
- value = svGetValue (ifcfg, "DEVICE", FALSE);
+ value = svGetValueString (ifcfg, "DEVICE");
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"mandatory DEVICE keyword missing");
@@ -4494,7 +4426,7 @@ make_bridge_setting (shvarFile *ifcfg,
s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ());
- value = svGetValue (ifcfg, "DEVICE", FALSE);
+ value = svGetValueString (ifcfg, "DEVICE");
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"mandatory DEVICE keyword missing");
@@ -4502,14 +4434,14 @@ make_bridge_setting (shvarFile *ifcfg,
}
g_free (value);
- value = svGetValue (ifcfg, "MACADDR", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "STP");
if (value) {
if (!strcasecmp (value, "on") || !strcasecmp (value, "yes")) {
g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, TRUE, NULL);
@@ -4528,7 +4460,7 @@ make_bridge_setting (shvarFile *ifcfg,
g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL);
}
- value = svGetValue (ifcfg, "DELAY", FALSE);
+ value = svGetValueString (ifcfg, "DELAY");
if (value) {
if (stp) {
if (get_uint (value, &u))
@@ -4540,7 +4472,7 @@ make_bridge_setting (shvarFile *ifcfg,
g_free (value);
}
- value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE);
+ value = svGetValueString (ifcfg, "BRIDGING_OPTS");
if (value) {
handle_bridging_opts (NM_SETTING (s_bridge), stp, value, handle_bridge_option);
g_free (value);
@@ -4623,12 +4555,12 @@ make_bridge_port_setting (shvarFile *ifcfg)
g_return_val_if_fail (ifcfg != NULL, FALSE);
- value = svGetValue (ifcfg, "BRIDGE", FALSE);
+ value = svGetValueString (ifcfg, "BRIDGE");
if (value) {
g_free (value);
s_port = nm_setting_bridge_port_new ();
- value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE);
+ value = svGetValueString (ifcfg, "BRIDGING_OPTS");
if (value)
handle_bridging_opts (s_port, FALSE, value, handle_bridge_port_option);
g_free (value);
@@ -4705,7 +4637,7 @@ parse_prio_map_list (NMSettingVlan *s_vlan,
char *value;
gchar **list = NULL, **iter;
- value = svGetValue (ifcfg, key, FALSE);
+ value = svGetValueString (ifcfg, key);
if (!value)
return;
@@ -4736,7 +4668,7 @@ make_vlan_setting (shvarFile *ifcfg,
guint32 vlan_flags = 0;
gint gvrp, reorder_hdr;
- value = svGetValue (ifcfg, "VLAN_ID", FALSE);
+ value = svGetValueString (ifcfg, "VLAN_ID");
if (value) {
vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1);
if (vlan_id == -1) {
@@ -4749,7 +4681,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 = 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.");
@@ -4759,7 +4691,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 = svGetValueString (ifcfg, "PHYSDEV");
if (iface_name) {
p = strchr (iface_name, '.');
@@ -4815,7 +4747,7 @@ make_vlan_setting (shvarFile *ifcfg,
if (gvrp > 0)
vlan_flags |= NM_VLAN_FLAG_GVRP;
- value = svGetValue (ifcfg, "VLAN_FLAGS", FALSE);
+ value = svGetValueString (ifcfg, "VLAN_FLAGS");
if (value) {
gs_strfreev char **strv = NULL;
char **ptr;
@@ -4926,7 +4858,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 = svGetValueString (ifcfg, "HWADDR");
if (value) {
char *lower = g_ascii_strdown (value, -1);
*out_spec = g_strdup_printf ("%s:mac:%s", type, lower);
@@ -4935,14 +4867,14 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg,
return connection;
}
- value = svGetValue (ifcfg, "SUBCHANNELS", FALSE);
+ 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", FALSE);
+ value = svGetValueString (ifcfg, "DEVICE");
if (value) {
*out_spec = g_strdup_printf ("%s:interface-name:%s", type, value);
g_free (value);
@@ -4971,7 +4903,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 = 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);
@@ -4992,7 +4924,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 = svGetValueString (ifcfg, "DOMAIN");
if (value) {
char **searches = g_strsplit (value, " ", 0);
if (searches) {
@@ -5052,7 +4984,7 @@ connection_from_file_full (const char *filename,
}
/* iBFT is handled by the iBFT settings plugin */
- bootproto = svGetValue (parsed, "BOOTPROTO", FALSE);
+ bootproto = svGetValueString (parsed, "BOOTPROTO");
if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) {
if (out_ignore_error)
*out_ignore_error = TRUE;
@@ -5063,7 +4995,7 @@ connection_from_file_full (const char *filename,
}
g_free (bootproto);
- devtype = svGetValue (parsed, "DEVICETYPE", FALSE);
+ devtype = svGetValueString (parsed, "DEVICETYPE");
if (devtype) {
if (!strcasecmp (devtype, TYPE_TEAM))
type = g_strdup (TYPE_TEAM);
@@ -5077,19 +5009,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 = svGetValueString (parsed, "TEAM_CONFIG");
if (t)
type = g_strdup (TYPE_TEAM);
}
if (!type)
- type = svGetValue (parsed, "TYPE", FALSE);
+ type = svGetValueString (parsed, "TYPE");
if (!type) {
gs_free char *tmp = NULL;
char *device;
- if ((tmp = svGetValue (parsed, "IPV6TUNNELIPV4", FALSE))) {
+ 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,
@@ -5097,7 +5029,7 @@ connection_from_file_full (const char *filename,
goto done;
}
- device = svGetValue (parsed, "DEVICE", FALSE);
+ 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);
@@ -5311,7 +5243,7 @@ devtimeout_from_file (const char *filename)
if (!ifcfg)
return 0;
- devtimeout_str = svGetValue (ifcfg, "DEVTIMEOUT", FALSE);
+ 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-utils.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
index 9cb44b19c6..d1c0097649 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
@@ -31,87 +31,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 c105487ac5..af0469e66f 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);
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 0b6ed52cdc..d456f1a2a6 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);
+ svSetValueString (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);
+ svSetValueString (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);
+ svSetValueString (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);
+ svSetValueString (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);
+ svSetValueString (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 */
@@ -382,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, FALSE);
+ 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))
@@ -421,7 +418,7 @@ write_8021x_setting (NMConnection *connection,
/* If wired, write KEY_MGMT */
if (wired)
- svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X", FALSE);
+ svSetValueString (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);
+ svSetValueString (ifcfg, "IEEE_8021X_EAP_METHODS", tmp);
g_free (tmp);
- svSetValue (ifcfg, "IEEE_8021X_IDENTITY",
- nm_setting_802_1x_get_identity (s_8021x),
- FALSE);
+ 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),
- FALSE);
+ svSetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY",
+ 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);
+ 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", FALSE);
+ 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, FALSE);
+ 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", FALSE);
+ svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth");
else if (strcmp (value, "2") == 0)
- svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth", FALSE);
+ svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth");
else if (strcmp (value, "3") == 0)
- svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth", FALSE);
+ svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth");
}
/* Phase2 auth methods */
@@ -498,19 +492,16 @@ write_8021x_setting (NMConnection *connection,
g_free (tmp);
}
- svSetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS",
- phase2_auth->len ? phase2_auth->str : NULL,
- FALSE);
+ 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),
- FALSE);
+ 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),
- FALSE);
+ 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);
@@ -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);
+ svSetValueString (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);
+ 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),
- FALSE);
- svSetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH",
- nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x),
- FALSE);
+ 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) {
@@ -562,7 +551,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;
@@ -587,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);
+ svSetValueString (ifcfg, "KEY_MGMT", "WPA-PSK");
wpa = TRUE;
*no_8021x = TRUE;
} else if (!strcmp (key_mgmt, "ieee8021x")) {
- svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X", FALSE);
+ svSetValueString (ifcfg, "KEY_MGMT", "IEEE8021X");
dynamic_wep = TRUE;
} else if (!strcmp (key_mgmt, "wpa-eap")) {
- svSetValue (ifcfg, "KEY_MGMT", "WPA-EAP", FALSE);
+ svSetValueString (ifcfg, "KEY_MGMT", "WPA-EAP");
wpa = TRUE;
}
svUnsetValue (ifcfg, "SECURITYMODE");
if (auth_alg) {
if (!strcmp (auth_alg, "shared"))
- svSetValue (ifcfg, "SECURITYMODE", "restricted", FALSE);
+ svSetValueString (ifcfg, "SECURITYMODE", "restricted");
else if (!strcmp (auth_alg, "open"))
- svSetValue (ifcfg, "SECURITYMODE", "open", FALSE);
+ svSetValueString (ifcfg, "SECURITYMODE", "open");
else if (!strcmp (auth_alg, "leap")) {
- svSetValue (ifcfg, "SECURITYMODE", "leap", FALSE);
- svSetValue (ifcfg, "IEEE_8021X_IDENTITY",
- nm_setting_wireless_security_get_leap_username (s_wsec),
- FALSE);
+ 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),
"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;
}
}
@@ -622,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);
}
@@ -639,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);
+ svSetValueString (ifcfg, "DEFAULTKEY", tmp);
g_free (tmp);
for (i = 0; i < 4; i++) {
@@ -680,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);
@@ -696,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);
+ svSetValueString (ifcfg, "WPA_ALLOW_WPA", "yes");
else if (proto && !strcmp (proto, "rsn"))
- svSetValue (ifcfg, "WPA_ALLOW_WPA2", "yes", FALSE);
+ svSetValueString (ifcfg, "WPA_ALLOW_WPA2", "yes");
}
/* WPA Pairwise ciphers */
@@ -720,7 +707,7 @@ write_wireless_security_setting (NMConnection *connection,
}
}
if (strlen (str->str) && (dynamic_wep == FALSE))
- svSetValue (ifcfg, "CIPHER_PAIRWISE", str->str, FALSE);
+ svSetValueString (ifcfg, "CIPHER_PAIRWISE", str->str);
g_string_free (str, TRUE);
/* WPA Group ciphers */
@@ -736,33 +723,17 @@ write_wireless_security_setting (NMConnection *connection,
g_free (tmp);
}
if (strlen (str->str) && (dynamic_wep == FALSE))
- svSetValue (ifcfg, "CIPHER_GROUP", str->str, FALSE);
+ svSetValueString (ifcfg, "CIPHER_GROUP", str->str);
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);
return TRUE;
}
@@ -774,13 +745,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;
@@ -793,14 +763,13 @@ write_wireless_setting (NMConnection *connection,
}
device_mac = nm_setting_wireless_get_mac_address (s_wireless);
- svSetValue (ifcfg, "HWADDR", device_mac, FALSE);
+ svSetValueString (ifcfg, "HWADDR", device_mac);
cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless);
- svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE);
+ svSetValueString (ifcfg, "MACADDR", cloned_mac);
- svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK",
- nm_setting_wireless_get_generate_mac_address_mask (s_wireless),
- FALSE);
+ 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);
@@ -808,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);
+ svSetValueString (ifcfg, "HWADDR_BLACKLIST", blacklist_str);
g_free (blacklist_str);
}
@@ -816,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);
+ svSetValueString (ifcfg, "MTU", tmp);
g_free (tmp);
}
@@ -836,10 +805,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,36 +833,25 @@ 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);
+ svSetValueString (ifcfg, "ESSID", str->str);
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';
+ svSetValueString (ifcfg, "ESSID", buf);
}
mode = nm_setting_wireless_get_mode (s_wireless);
if (!mode || !strcmp (mode, "infrastructure")) {
- svSetValue (ifcfg, "MODE", "Managed", FALSE);
+ svSetValueString (ifcfg, "MODE", "Managed");
} else if (!strcmp (mode, "adhoc")) {
- svSetValue (ifcfg, "MODE", "Ad-Hoc", FALSE);
+ svSetValueString (ifcfg, "MODE", "Ad-Hoc");
adhoc = TRUE;
} else if (!strcmp (mode, "ap")) {
- svSetValue (ifcfg, "MODE", "Ap", FALSE);
+ svSetValueString (ifcfg, "MODE", "Ap");
} else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
"Invalid mode '%s' in '%s' setting",
@@ -893,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);
+ 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), FALSE);
+ svSetValueString (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless));
}
bssid = nm_setting_wireless_get_bssid (s_wireless);
- svSetValue (ifcfg, "BSSID", bssid, FALSE);
+ 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
@@ -919,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);
}
@@ -939,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));
@@ -947,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, TRUE);
+ 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", TRUE);
+ svSetValueString (ifcfg, "POWERSAVE", "ignore");
break;
case NM_SETTING_WIRELESS_POWERSAVE_DISABLE:
- svSetValue (ifcfg, "POWERSAVE", "disable", TRUE);
+ svSetValueString (ifcfg, "POWERSAVE", "disable");
break;
case NM_SETTING_WIRELESS_POWERSAVE_ENABLE:
- svSetValue (ifcfg, "POWERSAVE", "enable", TRUE);
+ svSetValueString (ifcfg, "POWERSAVE", "enable");
break;
default:
case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT:
@@ -968,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", TRUE);
+ svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default");
break;
case NM_SETTING_MAC_RANDOMIZATION_ALWAYS:
- svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always", TRUE);
+ svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always");
break;
default:
case NM_SETTING_MAC_RANDOMIZATION_NEVER:
- svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never", TRUE);
+ svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never");
break;
}
- svSetValue (ifcfg, "TYPE", TYPE_WIRELESS, FALSE);
+ svSetValueString (ifcfg, "TYPE", TYPE_WIRELESS);
return TRUE;
}
@@ -1001,34 +972,32 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e
}
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
- svSetValue (ifcfg, "HWADDR", mac, FALSE);
+ 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, FALSE);
+ svSetValueString (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);
+ svSetValueBoolean (ifcfg, "CONNECTED_MODE", nm_streq (transport_mode, "connected"));
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
if (p_key != -1) {
- svSetValue (ifcfg, "PKEY", "yes", FALSE);
+ svSetValueString (ifcfg, "PKEY", "yes");
tmp = g_strdup_printf ("%u", p_key);
- svSetValue (ifcfg, "PKEY_ID", tmp, FALSE);
+ svSetValueString (ifcfg, "PKEY_ID", tmp);
g_free (tmp);
parent = nm_setting_infiniband_get_parent (s_infiniband);
if (parent)
- svSetValue (ifcfg, "PHYSDEV", parent, FALSE);
+ svSetValueString (ifcfg, "PHYSDEV", parent);
}
- svSetValue (ifcfg, "TYPE", TYPE_INFINIBAND, FALSE);
+ svSetValueString (ifcfg, "TYPE", TYPE_INFINIBAND);
return TRUE;
}
@@ -1055,14 +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, FALSE);
+ svSetValueString (ifcfg, "HWADDR", device_mac);
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE);
+ svSetValueString (ifcfg, "MACADDR", cloned_mac);
- svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK",
- nm_setting_wired_get_generate_mac_address_mask (s_wired),
- FALSE);
+ 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);
@@ -1070,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, FALSE);
+ svSetValueString (ifcfg, "HWADDR_BLACKLIST", blacklist_str);
g_free (blacklist_str);
}
@@ -1078,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, FALSE);
+ svSetValueString (ifcfg, "MTU", tmp);
g_free (tmp);
}
@@ -1094,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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "CTCPROT", ctcprot);
svUnsetValue (ifcfg, "OPTIONS");
num_opts = nm_setting_wired_get_num_s390_options (s_wired);
@@ -1129,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, FALSE);
+ 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", "", FALSE);
+ svSetValue (ifcfg, "ETHTOOL_OPTS", "");
else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT)
svUnsetValue (ifcfg, "ETHTOOL_OPTS");
else {
@@ -1162,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, FALSE);
+ svSetValueString (ifcfg, "ETHTOOL_OPTS", str->str);
g_string_free (str, TRUE);
}
- svSetValue (ifcfg, "TYPE", TYPE_ETHERNET, FALSE);
+ svSetValueString (ifcfg, "TYPE", TYPE_ETHERNET);
return TRUE;
}
@@ -1208,19 +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, FALSE);
+ svSetValueString (ifcfg, "HWADDR", device_mac);
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE);
+ svSetValueString (ifcfg, "MACADDR", cloned_mac);
- svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK",
- nm_setting_wired_get_generate_mac_address_mask (s_wired),
- FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "MTU", tmp);
g_free (tmp);
} else
svUnsetValue (ifcfg, "MTU");
@@ -1252,22 +1219,18 @@ 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);
+ 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, FALSE);
+ svSetValueString (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);
- else
- svSetValue (ifcfg, "REORDER_HDR", "no", FALSE);
-
- svSetValue (ifcfg, "GVRP", vlan_flags & NM_VLAN_FLAG_GVRP ? "yes" : "no", FALSE);
+ 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);
@@ -1276,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, FALSE);
+ svSetValueString (ifcfg, "VLAN_FLAGS", s_buf);
- svSetValue (ifcfg, "MVRP", vlan_flags & NM_VLAN_FLAG_MVRP ? "yes" : "no", FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp);
g_free (tmp);
svUnsetValue (ifcfg, "HWADDR");
@@ -1318,7 +1281,7 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir
return FALSE;
}
- svSetValue (ifcfg, "DEVICE", iface, FALSE);
+ svSetValueString (ifcfg, "DEVICE", iface);
svUnsetValue (ifcfg, "BONDING_OPTS");
num_opts = nm_setting_bond_get_num_options (s_bond);
@@ -1338,13 +1301,13 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir
}
if (str->len)
- svSetValue (ifcfg, "BONDING_OPTS", str->str, FALSE);
+ svSetValueString (ifcfg, "BONDING_OPTS", str->str);
g_string_free (str, TRUE);
}
- svSetValue (ifcfg, "TYPE", TYPE_BOND, FALSE);
- svSetValue (ifcfg, "BONDING_MASTER", "yes", FALSE);
+ svSetValueString (ifcfg, "TYPE", TYPE_BOND);
+ svSetValueString (ifcfg, "BONDING_MASTER", "yes");
*wired = write_wired_for_virtual (connection, ifcfg);
@@ -1372,9 +1335,9 @@ write_team_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired,
return FALSE;
}
- svSetValue (ifcfg, "DEVICE", iface, FALSE);
+ svSetValueString (ifcfg, "DEVICE", iface);
config = nm_setting_team_get_config (s_team);
- svSetValue (ifcfg, "TEAM_CONFIG", config, FALSE);
+ svSetValueString (ifcfg, "TEAM_CONFIG", config);
*wired = write_wired_for_virtual (connection, ifcfg);
@@ -1440,24 +1403,24 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error
return FALSE;
}
- svSetValue (ifcfg, "DEVICE", iface, FALSE);
+ svSetValueString (ifcfg, "DEVICE", iface);
svUnsetValue (ifcfg, "BRIDGING_OPTS");
- svSetValue (ifcfg, "STP", "no", FALSE);
+ svSetValueBoolean (ifcfg, "STP", FALSE);
svUnsetValue (ifcfg, "DELAY");
mac = nm_setting_bridge_get_mac_address (s_bridge);
- svSetValue (ifcfg, "MACADDR", mac, FALSE);
+ svSetValueString (ifcfg, "MACADDR", mac);
/* Bridge options */
opts = g_string_sized_new (32);
if (nm_setting_bridge_get_stp (s_bridge)) {
- svSetValue (ifcfg, "STP", "yes", FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "DELAY", s);
g_free (s);
}
@@ -1493,10 +1456,10 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error
}
if (opts->len)
- svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE);
+ svSetValueString (ifcfg, "BRIDGING_OPTS", opts->str);
g_string_free (opts, TRUE);
- svSetValue (ifcfg, "TYPE", TYPE_BRIDGE, FALSE);
+ svSetValueString (ifcfg, "TYPE", TYPE_BRIDGE);
return TRUE;
}
@@ -1535,7 +1498,7 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **
}
if (opts->len)
- svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE);
+ svSetValueString (ifcfg, "BRIDGING_OPTS", opts->str);
g_string_free (opts, TRUE);
return TRUE;
@@ -1552,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, FALSE);
+ svSetValueString (ifcfg, "TEAM_PORT_CONFIG", config);
return TRUE;
}
@@ -1563,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, FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL);
}
static void
@@ -1609,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, FALSE);
+ svSetValueString (ifcfg, key, str);
}
typedef guint (*DcbGetUintFunc) (NMSettingDcb *, guint);
@@ -1639,7 +1602,7 @@ write_dcb_uint_array (shvarFile *ifcfg,
else
g_assert_not_reached ();
}
- svSetValue (ifcfg, key, str, FALSE);
+ svSetValueString (ifcfg, key, str);
}
static void
@@ -1663,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, FALSE);
+ svSetValueString (ifcfg, key, str->str);
g_string_free (str, TRUE);
}
@@ -1707,13 +1670,13 @@ write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
return TRUE;
}
- svSetValue (ifcfg, "DCB", "yes", FALSE);
+ 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), FALSE);
+ svSetValueString (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb));
else
svUnsetValue (ifcfg, KEY_DCB_APP_FCOE_MODE);
@@ -1753,38 +1716,35 @@ 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, "ONBOOT",
- nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no",
- FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "AUTOCONNECT_RETRIES", tmp);
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)
|| !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,
- FALSE);
- }
+ 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");
switch (nm_setting_connection_get_lldp (s_con)) {
case NM_SETTING_CONNECTION_LLDP_ENABLE_RX:
@@ -1796,7 +1756,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
default:
tmp = NULL;
}
- svSetValue (ifcfg, "LLDP", tmp, FALSE);
+ svSetValueString (ifcfg, "LLDP", tmp);
/* Permissions */
svUnsetValue (ifcfg, "USERS");
@@ -1816,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, FALSE);
+ svSetValueString (ifcfg, "USERS", str->str);
g_string_free (str, TRUE);
}
- svSetValue (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con), FALSE);
+ svSetValueString (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con));
master = nm_setting_connection_get_master (s_con);
if (master) {
@@ -1835,15 +1795,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);
+ 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, FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT);
else
svUnsetValue (ifcfg, "DEVICETYPE");
@@ -1865,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, FALSE);
+ 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, FALSE);
+ 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", FALSE);
+ svSetValueString (ifcfg, "CONNECTION_METERED", "yes");
break;
case NM_METERED_NO:
- svSetValue (ifcfg, "CONNECTION_METERED", "no", FALSE);
+ svSetValueString (ifcfg, "CONNECTION_METERED", "no");
break;
default:
svUnsetValue (ifcfg, "CONNECTION_METERED");
@@ -1949,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)
@@ -1962,27 +1921,23 @@ 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);
+ svSetValueString (ifcfg, "PROXY_METHOD", "auto");
pac_url = nm_setting_proxy_get_pac_url (s_proxy);
if (pac_url)
- svSetValue (ifcfg, "PAC_URL", pac_url, FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "PAC_SCRIPT", pac_script);
break;
case NM_SETTING_PROXY_METHOD_NONE:
- svSetValue (ifcfg, "PROXY_METHOD", "none", FALSE);
+ svSetValueString (ifcfg, "PROXY_METHOD", "none");
break;
}
- browser_only = nm_setting_proxy_get_browser_only (s_proxy);
- if (browser_only)
- svSetValue (ifcfg, "BROWSER_ONLY", "yes", FALSE);
- else
- svSetValue (ifcfg, "BROWSER_ONLY", "no", FALSE);
+ svSetValueBoolean (ifcfg, "BROWSER_ONLY", nm_setting_proxy_get_browser_only (s_proxy));
return TRUE;
}
@@ -2064,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", FALSE);
+ svSetValueString (ifcfg, "BOOTPROTO", "dhcp");
else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
- svSetValue (ifcfg, "BOOTPROTO", "none", FALSE);
+ svSetValueString (ifcfg, "BOOTPROTO", "none");
else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
- svSetValue (ifcfg, "BOOTPROTO", "autoip", FALSE);
+ svSetValueString (ifcfg, "BOOTPROTO", "autoip");
else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
- svSetValue (ifcfg, "BOOTPROTO", "shared", FALSE);
+ svSetValueString (ifcfg, "BOOTPROTO", "shared");
/* Clear out un-numbered IP address fields */
svUnsetValue (ifcfg, "IPADDR");
@@ -2117,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), FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, prefix_key, tmp);
g_free (tmp);
svUnsetValue (ifcfg, netmask_key);
@@ -2151,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), FALSE);
+ 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++) {
@@ -2163,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, FALSE);
+ svSetValueString (ifcfg, addr_key, dns);
}
g_free (addr_key);
}
@@ -2176,60 +2131,50 @@ 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);
+ svSetValueString (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);
+ 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",
- FALSE);
-
- svSetValue (ifcfg, "PEERROUTES",
- nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes",
- FALSE);
+ 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)
- svSetValue (ifcfg, "DHCP_HOSTNAME", value, FALSE);
+ 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, FALSE);
+ 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",
- FALSE);
+ 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, FALSE);
+ 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, FALSE);
+ svSetValueString (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);
+ 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;
- svSetValue (ifcfg, "IPV4_ROUTE_METRIC", tmp, FALSE);
+ svSetValueString (ifcfg, "IPV4_ROUTE_METRIC", tmp);
g_free (tmp);
/* Static routes - route-<name> file */
@@ -2272,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), FALSE);
+ 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], FALSE);
+ svSetValueString (routefile, netmask_key, &buf[0]);
- svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route), FALSE);
+ svSetValueString (routefile, gw_key, nm_ip_route_get_next_hop (route));
memset (buf, 0, sizeof (buf));
metric = nm_ip_route_get_metric (route);
@@ -2287,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, FALSE);
+ svSetValueString (routefile, metric_key, tmp);
g_free (tmp);
}
}
@@ -2313,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", FALSE);
+ svSetValueString (ifcfg, "ARPING_WAIT", "0");
else {
/* Round the value up to next integer */
svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1);
@@ -2400,13 +2345,13 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
ifcfg = svCreateFile (path);
g_free (path);
- svSetValue (ifcfg, "DEVICE", label, FALSE);
+ svSetValueString (ifcfg, "DEVICE", label);
addr = nm_setting_ip_config_get_address (s_ip4, i);
- svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr), FALSE);
+ svSetValueString (ifcfg, "IPADDR", nm_ip_address_get_address (addr));
tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr));
- svSetValue (ifcfg, "PREFIX", tmp, FALSE);
+ svSetValueString (ifcfg, "PREFIX", tmp);
g_free (tmp);
svWriteFile (ifcfg, 0644, NULL);
@@ -2507,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", FALSE);
+ svSetValueString (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);
+ 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", FALSE);
- svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE);
- svSetValue (ifcfg, "DHCPV6C", "yes", FALSE);
+ 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, FALSE);
+ svSetValueString (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);
+ 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", FALSE);
- svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE);
+ 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", FALSE);
+ svSetValueString (ifcfg, "IPV6INIT", "yes");
svUnsetValue (ifcfg, "DHCPV6C");
/* TODO */
}
@@ -2554,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, FALSE);
- svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str, FALSE);
- svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6), FALSE);
+ 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);
@@ -2571,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, FALSE);
+ svSetValueString (ifcfg, addr_key, dns);
}
g_free (addr_key);
}
@@ -2580,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", FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "DOMAIN", searches->str);
g_string_free (searches, TRUE);
g_free (ip4_domains);
}
@@ -2595,29 +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", FALSE);
+ svSetValueString (ifcfg, "IPV6_DEFROUTE", "no");
else
- svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE);
+ 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",
- FALSE);
+ 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",
- FALSE);
+ 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",
- FALSE);
+ 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, FALSE);
+ svSetValueString (ifcfg, "IPV6_ROUTE_METRIC", tmp);
g_free (tmp);
/* IPv6 Privacy Extensions */
@@ -2625,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", FALSE);
+ svSetValueString (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);
+ 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", FALSE);
+ svSetValueString (ifcfg, "IPV6_PRIVACY", "rfc3041");
break;
default:
break;
@@ -2643,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, FALSE);
+ svSetValueString (ifcfg, "IPV6_ADDR_GEN_MODE", tmp);
g_free (tmp);
} else {
svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE");
@@ -2651,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, FALSE);
+ svSetValueString (ifcfg, "IPV6_TOKEN", value);
priority = nm_setting_ip_config_get_dns_priority (s_ip6);
if (priority)
@@ -2728,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, FALSE);
+ svSetValue (ifcfg, "RES_OPTIONS", value->str);
g_string_free (value, TRUE);
} else
svUnsetValue (ifcfg, "RES_OPTIONS");
@@ -2758,7 +2700,6 @@ static gboolean
write_connection (NMConnection *connection,
const char *ifcfg_dir,
const char *filename,
- const char *keyfile,
char **out_filename,
GError **error)
{
@@ -2942,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)) {
@@ -2958,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 97a9f25252..2662f79b06 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/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index cc0eefeba2..b4b3c0c3f0 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 */
};
@@ -85,114 +84,514 @@ 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 */
+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 == '_');
+}
+
+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*.
+ *
+ * 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 _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;
- int i, j, mangle = 0, space = 0, newline = 0;
- int newlen, slen;
+ gsize mangle = 0;
+ gboolean requires_quotes = FALSE;
+ int newlen;
+ size_t i, j, slen;
slen = strlen (s);
for (i = 0; i < slen; i++) {
- if (strchr (escapees, s[i]))
+ if (_char_req_escape (s[i]))
mangle++;
- if (strchr (spaces, s[i]))
- space++;
- if (strchr (newlines, s[i]))
- newline++;
+ 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).
+ * 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 && !requires_quotes) {
*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 (newlines, s[i]))
- continue;
- if (strchr (escapees, s[i])) {
+ if (_char_req_escape (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 + 3);
*to_free = new;
return new;
}
-/* remove escaped characters in place */
-void
-svUnescape (char *s)
+static gboolean
+_looks_like_old_svescaped (const char *value)
{
- size_t len, idx_rd = 0, idx_wr = 0;
- char c;
+ gsize k;
- len = strlen (s);
- if (len < 2) {
- if (s[0] == '\\')
- s[0] = '\0';
- return;
+ if (value[0] != '"')
+ return FALSE;
+
+ 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');
+ else if (value[k] == '\\') {
+ k++;
+ if (!_char_req_escape_old (value[k]))
+ return FALSE;
+ } else
+ return FALSE;
}
+}
+
+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);
+ }
+}
- if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) {
- if (len == 2) {
- s[0] = '\0';
- return;
+const char *
+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 */
+
+ /* @value shall start with the first character after "FOO=" */
+
+ nm_assert (value);
+ nm_assert (to_free);
+
+ /* 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'));
+
+ 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 (len == 3) {
- if (s[1] == '\\') {
- s[0] = '\0';
- } else {
- s[0] = s[1];
- s[1] = '\0';
+
+ 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;
}
- return;
+ g_string_append_c (str, value[i]);
+ i++;
+ goto loop1_next;
}
- s[--len] = '\0';
- idx_rd = 1;
- } else {
- /* seek for the first escape... */
- char *p = strchr (s, '\\');
-
- if (!p)
- return;
- if (p[1] == '\0') {
- p[0] = '\0';
- return;
+
+ 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;
}
- idx_wr = idx_rd = (p - s);
- }
- /* 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;
+ 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], '$', '`', '"', '\\')) {
+ /* 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]);
+ i++;
}
- s[idx_wr++] = s[idx_rd++];
- continue;
+ 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;
}
- s[idx_wr++] = c;
+
+ 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: ;
+ }
+
+ 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 {
+ *to_free = NULL;
+ return value;
}
- s[idx_wr] = '\0';
+
+out_error:
+ *to_free = NULL;
+ return NULL;
}
/*****************************************************************************/
@@ -205,6 +604,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 <name>, returning a shvarFile on success and NULL on failure.
@@ -260,8 +672,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_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
@@ -307,43 +722,114 @@ 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;
- len = strlen (key);
+ nm_assert (_shell_is_name (key));
- for (s->current = s->lineList; s->current; s->current = s->current->next) {
- line = s->current->data;
- if (!strncmp (key, line, len) && line[len] == '=')
- return line + len + 1;
+ if (current) {
+ len = strlen (key);
+ do {
+ const char *line = current->data;
+
+ /* skip over leading spaces */
+ while (g_ascii_isspace (line[0]))
+ line++;
+
+ 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;
}
-/* 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. */
-char *
-svGetValueFull (shvarFile *s, const char *key, gboolean verbatim)
+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 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)
+{
+ 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));
+}
+
+/*****************************************************************************/
+
+static const char *
+_svGetValue (shvarFile *s, const char *key, char **to_free)
{
+ const GList *current;
const char *line_val;
- char *value;
+ const char *last_val = NULL;
- 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))) {
+ last_val = line_val;
+ current = current->next;
+ }
- line_val = find_line (s, key);
- if (!line_val)
+ if (!last_val) {
+ *to_free = NULL;
return NULL;
+ }
- value = g_strchomp (g_strdup (line_val));
- if (!verbatim)
- svUnescape (value);
- return value;
+ return svUnescape (last_val, to_free);
+}
+
+const char *
+svGetValue (shvarFile *s, const char *key, 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);
+
+ return _svGetValue (s, key, to_free);
}
/* Get the value associated with the key, and leave the current pointer
@@ -351,16 +837,21 @@ svGetValueFull (shvarFile *s, const char *key, gboolean verbatim)
* be freed by the caller.
*/
char *
-svGetValue (shvarFile *s, const char *key, gboolean verbatim)
+svGetValueString (shvarFile *s, const char *key)
{
- char *value;
+ char *to_free;
+ const char *value;
- value = svGetValueFull (s, key, verbatim);
- 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:
@@ -375,10 +866,11 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim)
gint
svGetValueBoolean (shvarFile *s, const char *key, gint fallback)
{
- gs_free char *tmp = NULL;
+ gs_free char *to_free = NULL;
+ const char *value;
- tmp = svGetValue (s, key, FALSE);
- return svParseBoolean (tmp, fallback);
+ value = _svGetValue (s, key, &to_free);
+ return svParseBoolean (value, fallback);
}
/* svGetValueInt64:
@@ -394,78 +886,80 @@ 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 = svGetValueFull (s, key, FALSE);
- if (!tmp) {
- errno = 0;
+ value = _svGetValue (s, key, &to_free);
+ if (!value) {
+ nm_assert (!to_free);
+ /* indicate that the key does not exist (or has a syntax error
+ * and svUnescape() failed). */
+ errno = ENOKEY;
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;
}
/*****************************************************************************/
-/* 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, gboolean verbatim)
+svSetValue (shvarFile *s, const char *key, const char *value)
{
- gs_free char *newval_free = NULL;
- gs_free char *oldval = NULL;
- const char *newval;
- char *keyValue;
+ gs_free char *oldval_free = NULL;
+ const char *oldval, *oldval_tmp;
+ GList *current, *last;
+ gboolean has_multiple = FALSE;
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) {
- /* 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);
+
+ nm_assert (_shell_is_name (key));
+
+ if (!value) {
+ if (shlist_delete_all (&s->lineList, key, TRUE))
s->modified = TRUE;
- }
return;
}
- oldval = svGetValueFull (s, key, FALSE);
+ current = (GList *) shlist_find (s->lineList, key, &oldval);
- keyValue = g_strdup_printf ("%s=%s", key, newval);
- 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, newval) != 0) {
- /* change line */
- if (s->current) {
- g_free (s->current->data);
- s->current->data = keyValue;
- } else
- s->lineList = g_list_append (s->lineList, keyValue);
+ 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_streq0 (oldval, value)) {
+ g_free (current->data);
+ current->data = line_construct (key, value);
s->modified = TRUE;
- } else
- g_free (keyValue);
+ }
+
+ if (has_multiple) {
+ if (shlist_delete_all (&s->lineList, key, FALSE))
+ s->modified = TRUE;
+ }
}
/* Set the variable <key> equal to the value <value>.
@@ -474,9 +968,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)
+svSetValueString (shvarFile *s, const char *key, const char *value)
{
- svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim);
+ svSetValue (s, key, value && value[0] ? value : NULL);
}
void
@@ -484,15 +978,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),
- TRUE);
+ svSetValue (s, key, nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value));
+}
+
+void
+svSetValueBoolean (shvarFile *s, const char *key, gboolean value)
+{
+ svSetValue (s, key, value ? "yes" : "no");
}
void
svUnsetValue (shvarFile *s, const char *key)
{
- svSetValueFull (s, key, NULL, FALSE);
+ svSetValue (s, key, NULL);
}
/*****************************************************************************/
@@ -508,6 +1006,7 @@ svWriteFile (shvarFile *s, int mode, GError **error)
{
FILE *f;
int tmpfd;
+ const GList *current;
if (s->modified) {
if (s->fd == -1)
@@ -540,8 +1039,31 @@ 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;
+ 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);
@@ -561,6 +1083,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);
}
diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h
index 14b2c5e8b4..a6498fcea2 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 <name>, return a shvarFile (never fails) */
shvarFile *svCreateFile (const char *name);
@@ -45,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.
*/
-char *svGetValue (shvarFile *s, const char *key, gboolean verbatim);
-char *svGetValueFull (shvarFile *s, const char *key, gboolean verbatim);
+const char *svGetValue (shvarFile *s, const char *key, char **to_free);
+char *svGetValueString (shvarFile *s, const char *key);
gint svParseBoolean (const char *value, gint def);
@@ -63,8 +66,9 @@ 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 svSetValueString (shvarFile *s, const char *key, const char *value);
+void svSetValue (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);
@@ -80,10 +84,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/network-scripts/ifcfg-test-wifi-wpa-psk b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk
index 2119ba8e6b..a78051aad4 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/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 0000000000..c927389e65
--- /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 0000000000..568b2efcd8
--- /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 0000000000..850149b21e
--- /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 0000000000..6ec53c17e9
--- /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 0000000000..3d198e005b
--- /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 0000000000..d2b27eb338
--- /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/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 0000000000..2a0198d30b
--- /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 0000000000..7f9a2d0616
--- /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/network-scripts/keys-test-wifi-wpa-psk-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2
index 6a63e817f8..995721ddb8 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 df332b2407..3ee8589c17 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -57,8 +57,45 @@
#include "nm-test-utils-core.h"
+#define TEST_SCRATCH_DIR_TMP TEST_SCRATCH_DIR"/network-scripts/tmp"
+
/*****************************************************************************/
+#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,
@@ -365,8 +402,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 +488,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);
@@ -1495,9 +1532,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 *testfile = 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*");
@@ -1523,14 +1561,12 @@ 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 ();
- unlink (written);
- g_free (written);
nmtst_assert_connection_equals (connection, TRUE, reread, FALSE);
@@ -1549,9 +1585,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,14 +1776,12 @@ 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;
- char *val;
/* 1. load the bridge slave connection from disk */
connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-component",
@@ -1778,47 +1809,33 @@ test_clear_master (void)
g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NULL);
/* 4. update the connection on disk */
+ _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,
- keyfile,
- &error);
- g_assert_no_error (error);
- g_assert (success);
- unlink (keyfile);
- g_free (keyfile);
+ 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 = svGetValue (f, "BRIDGE", FALSE);
- g_assert (!val);
+ f = _svOpenFile (testfile);
+ _svGetValue_check (f, "BRIDGE", NULL);
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;
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;
- char *testfile = NULL;
connection = nm_simple_connection_new ();
@@ -1826,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 ();
@@ -1884,7 +1899,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 +1910,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
@@ -2025,6 +2035,30 @@ test_read_wifi_open_ssid_hex (void)
}
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)
{
_connection_from_file_fail ((const char *) data, NULL, TYPE_WIRELESS, NULL);
@@ -2389,6 +2423,16 @@ test_read_wifi_leap_secret_flags (gconstpointer test_data)
}
static void
+test_ifcfg_no_trailing_newline (void)
+{
+ shvarFile *sv;
+
+ sv = _svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk");
+ _svGetValue_check (sv, "LAST_ENTRY", "no-newline");
+ svCloseFile (sv);
+}
+
+static void
test_read_wifi_wpa_psk (void)
{
NMConnection *connection;
@@ -2537,7 +2581,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);
}
@@ -2576,12 +2620,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
@@ -2958,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 };
@@ -2973,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 ();
@@ -3001,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 = svGetValue (f, "SSID_HIDDEN", FALSE);
- 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;
@@ -3037,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 };
@@ -3072,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 */
@@ -3100,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 = svGetValue (f, "MAC_ADDRESS_RANDOMIZATION", FALSE);
- 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 ();
@@ -3137,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 ();
@@ -3164,12 +3176,8 @@ 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. */
- val = svGetValue (f, "ETHTOOL_OPTS", FALSE);
+ f = _svOpenFile (testfile);
+ val = svGetValueString (f, "ETHTOOL_OPTS");
g_assert (val);
g_assert (strstr (val, "wol"));
g_assert (strstr (val, "sopass 00:00:00:11:22:33"));
@@ -3177,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
@@ -3210,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 };
@@ -3225,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 ();
@@ -3253,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 = svGetValue (f, "BAND", FALSE);
- 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
@@ -3512,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 ();
@@ -3532,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 ();
@@ -3630,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.
@@ -3651,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 ();
@@ -3679,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 ();
@@ -3720,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);
@@ -3780,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);
@@ -3796,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 ();
@@ -3821,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 ();
@@ -3868,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.
@@ -3888,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 ();
@@ -3908,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 */
@@ -3961,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 = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE);
- 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);
@@ -3988,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",
@@ -4040,40 +3980,31 @@ 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);
- 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 ();
@@ -4081,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 ();
@@ -4151,34 +4080,26 @@ 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
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;
NMSettingIPConfig *s_ip6;
NMSetting8021x *s_8021x;
- char *uuid;
gboolean success;
GError *error = NULL;
- char *testfile = NULL;
- char *keyfile = NULL;
connection = nm_simple_connection_new ();
@@ -4186,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 ();
@@ -4243,34 +4162,26 @@ 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);
+ 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;
@@ -4283,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,
@@ -4321,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);
@@ -4370,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
@@ -4416,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"
@@ -4438,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,
@@ -4498,15 +4394,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);
+ 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", FALSE);
- svSetValue (ifcfg, "IPADDR", "192.168.1.5", FALSE);
+ 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));
@@ -4521,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
@@ -4560,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;
@@ -4584,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 ();
@@ -4622,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 = svGetValue (f, "IPADDR", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, "1.1.1.3");
- g_free (val);
-
- val = svGetValue (f, "IPADDR1", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, "2.2.2.5");
- g_free (val);
-
- val = svGetValue (f, "IPADDR0", FALSE);
- g_assert (val == NULL);
-
- val = svGetValue (f, "PREFIX", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, "24");
- g_free (val);
-
- val = svGetValue (f, "PREFIX1", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, "24");
- g_free (val);
-
- val = svGetValue (f, "PREFIX0", FALSE);
- g_assert (val == NULL);
-
- val = svGetValue (f, "GATEWAY", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, "1.1.1.254");
- g_free (val);
-
- val = svGetValue (f, "GATEWAY0", FALSE);
- g_assert (val == NULL);
-
- val = svGetValue (f, "GATEWAY1", FALSE);
- 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 ();
@@ -4700,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 ();
@@ -4750,39 +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 = svGetValue (ifcfg, "ESSID", TRUE);
- g_assert (tmp);
-
- g_assert (strncmp (tmp, "\"\"", 2) != 0);
-
- 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 };
@@ -4792,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 ();
@@ -4836,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;
@@ -4868,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 ();
@@ -4926,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;
@@ -4967,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 ();
@@ -5029,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;
@@ -5068,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 ();
@@ -5124,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;
@@ -5163,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 ();
@@ -5221,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;
@@ -5260,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 ();
@@ -5318,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;
@@ -5358,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 ();
@@ -5413,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);
@@ -5451,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));
@@ -5476,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,
@@ -5489,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,
@@ -5510,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);
@@ -5521,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 {
@@ -5558,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 ();
@@ -5626,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;
@@ -5663,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 ();
@@ -5732,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";
@@ -5770,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 ();
@@ -5853,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";
@@ -5891,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 ();
@@ -5990,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";
@@ -6028,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 ();
@@ -6104,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";
@@ -6140,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));
@@ -6172,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,
@@ -6190,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,
@@ -6223,51 +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,
- keyfile,
- &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";
@@ -6281,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));
@@ -6313,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,
@@ -6331,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,
@@ -6362,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,
@@ -6371,17 +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,
- keyfile,
- &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);
@@ -6392,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));
@@ -6454,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");
@@ -6473,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,
@@ -6496,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);
@@ -6504,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 = svGetValue (ifcfg, "SECURITYMODE", FALSE);
- g_assert_cmpstr (tmp, ==, NULL);
- g_free (tmp);
-
- tmp = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE);
- 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 ();
@@ -6543,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 ();
@@ -6592,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);
@@ -6648,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,
@@ -6669,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 = svGetValue (ifcfg, "CTCPROT", TRUE);
- 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 = svGetValue (ifcfg, "OPTIONS", TRUE);
- 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 ();
@@ -6713,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);
@@ -6754,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,
@@ -6812,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));
@@ -6824,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,
@@ -6841,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
@@ -6854,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
@@ -6869,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 ();
@@ -6878,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 ();
@@ -6930,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 ();
@@ -6939,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 ();
@@ -6988,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);
@@ -6998,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 */
@@ -7090,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,
@@ -7131,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,
@@ -7147,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,
@@ -7163,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
@@ -7199,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,
@@ -7253,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
@@ -7492,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);
-
- reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL);
+ &testfile);
- 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 ();
@@ -7571,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 ();
@@ -7599,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,
@@ -7665,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
@@ -7708,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 ();
@@ -7726,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 ();
@@ -7776,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
@@ -7808,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 ();
@@ -7823,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 ();
@@ -7850,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
@@ -7894,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 ();
@@ -7913,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 ();
@@ -7962,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",
@@ -7984,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 ();
@@ -8007,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 ();
@@ -8035,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
@@ -8131,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 };
@@ -8150,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 ();
@@ -8203,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",
@@ -8232,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
@@ -8344,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 ();
@@ -8416,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 = svGetValue (ifcfg, "DCB_APP_FCOE_MODE", FALSE);
- 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
@@ -8490,16 +7930,15 @@ 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\" } }";
- const char *escaped_expected_config = "\"{ \\\"device\\\": \\\"team0\\\", \\\"link_watch\\\": { \\\"name\\\": \\\"ethtool\\\" } }\"";
shvarFile *f;
connection = nm_simple_connection_new ();
@@ -8508,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 ();
@@ -8531,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,
@@ -8540,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,
@@ -8555,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 = svGetValue (f, "DEVICETYPE", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, "Team");
- g_free (val);
- val = svGetValue (f, "TEAM_CONFIG", TRUE);
- g_assert (val);
- g_assert_cmpstr (val, ==, escaped_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
@@ -8607,14 +8026,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;
- 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 ();
@@ -8623,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 ();
@@ -8648,36 +8064,17 @@ 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 = svGetValue (f, "TYPE", FALSE);
- g_assert (!val);
- val = svGetValue (f, "DEVICETYPE", FALSE);
- 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);
- g_free (val);
- val = svGetValue (f, "TEAM_MASTER", TRUE);
- g_assert (val);
- 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,
NULL);
- unlink (testfile);
nmtst_assert_connection_equals (connection, TRUE, reread, FALSE);
-
- g_free (testfile);
- g_object_unref (connection);
- g_object_unref (reread);
}
static void
@@ -8703,108 +8100,368 @@ 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 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)
{
- char *s1 = g_strdup (str);
- char *s2 = g_strdup (str);
+ gs_free char *to_free = NULL;
+ const char *s;
+
+ s = _svUnescape (str, &to_free);
+ g_assert_cmpstr (s, ==, expected);
- svUnescape (s1);
- svUnescape_On2 (s2);
+ /* 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;
- g_assert_cmpstr (s1, ==, s2);
+ s1 = svEscape (expected, &s1_free);
+ g_assert (s1);
- g_free (s1);
- g_free (s2);
+ s2 = _svUnescape (s1, &s2_free);
+ g_assert (s2);
+
+ g_assert_cmpstr (s2, ==, 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 ();
-
- g_rand_set_seed (r, seed);
-
- 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\" } }");
-
- for (len = 1; len < 25; len++) {
- char *s = g_new0 (char, len+1);
-
- 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;
- }
+#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", ""),
+ 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 ("\"\\\t\"", "\\\t"),
+ 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"),
+
+ /* 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
+ * 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"),
+
+ /* 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);
+
+ do_svUnescape_assert ( "' '' '", " ");
+
+ for (i = 0; i < G_N_ELEMENTS (data_full); i++)
+ do_svUnescape_assert (data_full[i].val, data_full[i].exp);
+
+ 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;
}
- /*g_message (">>%s<<", s);*/
- test_svUnescape_assert (s);
+ 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--;
}
- g_free (s);
+ 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);
+ }
+}
+
+/*****************************************************************************/
+
+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;
+ gs_free char *tmp = NULL;
+
+ sv = _svOpenFile (testfile);
+
+ svFileSetName (sv, filename_tmp_1);
+ svFileSetModified (sv);
+
+ if (g_str_has_suffix (testfile, "ifcfg-test-write-unknown-4")) {
+ _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");
+
+ _svGetValue_check (sv, "NAME", "set-by-test1");
+ _svGetValue_check (sv, "NAME2", "set-by-test2");
+ _svGetValue_check (sv, "NAME3", "set-by-test3");
}
- g_rand_free (r);
+ 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);
}
+/*****************************************************************************/
+
static void
test_read_vlan_trailing_spaces (void)
{
@@ -8970,7 +8627,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"
@@ -8982,10 +8638,16 @@ 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_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);
g_test_add_func (TPATH "unmanaged", test_read_unmanaged);
@@ -9047,7 +8709,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);
@@ -9218,6 +8880,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);