From 964ae8cc391520440cf5aa13e2b9cc34850ea6c2 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Tue, 26 Feb 2019 19:01:41 +0100 Subject: New upstream version 1.14.6 --- src/settings/nm-settings-connection.c | 22 +++++++++++++- .../plugins/ibft/tests/iscsiadm-test-bad-dns1 | 21 +++++++++++++ .../plugins/ibft/tests/iscsiadm-test-bad-dns2 | 21 +++++++++++++ .../plugins/ibft/tests/iscsiadm-test-bad-entry | 20 +++++++++++++ .../plugins/ibft/tests/iscsiadm-test-bad-gateway | 21 +++++++++++++ .../plugins/ibft/tests/iscsiadm-test-bad-ipaddr | 21 +++++++++++++ .../plugins/ibft/tests/iscsiadm-test-bad-record | 18 +++++++++++ src/settings/plugins/ibft/tests/iscsiadm-test-dhcp | 33 ++++++++++++++++++++ .../plugins/ibft/tests/iscsiadm-test-static | 35 ++++++++++++++++++++++ src/settings/plugins/ibft/tests/iscsiadm-test-vlan | 19 ++++++++++++ .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 31 ++++++++++++------- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 9 +++--- .../plugins/ifupdown/nms-ifupdown-plugin.c | 6 ++-- 13 files changed, 258 insertions(+), 19 deletions(-) create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-record create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-dhcp create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-static create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-vlan (limited to 'src/settings') diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 4c25d0e9..6f47e14d 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -640,7 +640,9 @@ nm_settings_connection_update (NMSettingsConnection *self, gboolean replaced = FALSE; gs_free char *logmsg_change = NULL; GError *local = NULL; + gs_unref_object NMConnection *simple = NULL; gs_unref_variant GVariant *con_agent_secrets = NULL; + gs_unref_variant GVariant *new_agent_secrets = NULL; g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); @@ -681,6 +683,16 @@ nm_settings_connection_update (NMSettingsConnection *self, replace_connection = reread_connection ?: new_connection; + /* Save agent-owned secrets from the new connection for later use */ + if (new_connection) { + simple = nm_simple_connection_new_clone (new_connection); + nm_connection_clear_secrets_with_flags (simple, + secrets_filter_cb, + GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED)); + new_agent_secrets = nm_connection_to_dbus (simple, NM_CONNECTION_SERIALIZE_ONLY_SECRETS); + g_clear_object (&simple); + } + /* Disconnect the changed signal to ensure we don't set Unsaved when * it's not required. */ @@ -691,7 +703,6 @@ nm_settings_connection_update (NMSettingsConnection *self, && !nm_connection_compare (nm_settings_connection_get_connection (self), replace_connection, NM_SETTING_COMPARE_FLAG_EXACT)) { - gs_unref_object NMConnection *simple = NULL; if (log_diff_name) { nm_utils_log_connection_diff (replace_connection, nm_settings_connection_get_connection (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ", @@ -738,6 +749,15 @@ nm_settings_connection_update (NMSettingsConnection *self, (void) nm_connection_update_secrets (nm_settings_connection_get_connection (self), NULL, con_agent_secrets, NULL); } + /* Apply agent-owned secrets from the new connection so that + * they can be sent to agents */ + if (new_agent_secrets) { + (void) nm_connection_update_secrets (nm_settings_connection_get_connection (self), + NULL, + new_agent_secrets, + NULL); + } + nm_settings_connection_recheck_visibility (self); if ( replaced diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 new file mode 100755 index 00000000..54f02da6 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10000.500.250.1 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 new file mode 100755 index 00000000..ebd7a9ca --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = blah.foo.bar.baz +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry new file mode 100755 index 00000000..4e326048 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry @@ -0,0 +1,20 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway new file mode 100755 index 00000000..5390a6c3 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = bb.cc.dd.ee +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr new file mode 100755 index 00000000..b41cd1f1 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = aa.bb.cc.dd +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record new file mode 100755 index 00000000..22b34e6f --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record @@ -0,0 +1,18 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp b/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp new file mode 100755 index 00000000..556b0586 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp @@ -0,0 +1,33 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f1 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth1 +node.name = iqn.1.2008-11.com.blahblah:iscsi1 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-static b/src/settings/plugins/ibft/tests/iscsiadm-test-static new file mode 100755 index 00000000..51711480 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-static @@ -0,0 +1,35 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f1 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth1 +node.name = iqn.1.2008-11.com.blahblah:iscsi1 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-vlan b/src/settings/plugins/ibft/tests/iscsiadm-test-vlan new file mode 100755 index 00000000..59b80bd0 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-vlan @@ -0,0 +1,19 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD 6.2.0.873-21 +iface.initiatorname = iqn.2010-04.org.ipxe:d05faa97-c4be-44f6-a723-efde9aa399a0 +iface.transport_name = tcp +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.6.200 +iface.subnet_mask = 255.255.255.0 +iface.vlan_id = 123 +iface.net_ifacename = eth0 +node.name = iqn.2003-01.org.x:disk1 +node.conn[0].address = 192.168.6.32 +node.conn[0].port = 3260 +node.boot_lun = 01000000 +# END RECORD +EOF + 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 09a37991..261dfea2 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -189,7 +189,7 @@ _secret_password_raw_to_bytes (const char *ifcfg_key, password_raw += 2; secret = nm_secret_buf_new (strlen (password_raw) / 2 + 3); - if (!_nm_utils_str2bin_full (password_raw, FALSE, ":", secret->bin, secret->len, &len)) { + if (!_nm_utils_hexstr2bin_full (password_raw, FALSE, FALSE, ":", 0, secret->bin, secret->len, &len)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid hex password in %s", ifcfg_key); @@ -2226,20 +2226,19 @@ make_sriov_setting (shvarFile *ifcfg) { gs_unref_hashtable GHashTable *keys = NULL; gs_unref_ptrarray GPtrArray *vfs = NULL; - NMTernary autoprobe_drivers; + int autoprobe_drivers; NMSettingSriov *s_sriov; - int total_vfs; + gint64 total_vfs; - total_vfs = svGetValueInt64 (ifcfg, "SRIOV_TOTAL_VFS", 10, 0, G_MAXINT32, 0); - if (!total_vfs) - return NULL; + + total_vfs = svGetValueInt64 (ifcfg, "SRIOV_TOTAL_VFS", 10, 0, G_MAXUINT32, -1); autoprobe_drivers = svGetValueInt64 (ifcfg, "SRIOV_AUTOPROBE_DRIVERS", 10, - NM_TERNARY_FALSE, + NM_TERNARY_DEFAULT, NM_TERNARY_TRUE, - NM_TERNARY_DEFAULT); + -2); keys = svGetKeys (ifcfg, SV_KEY_TYPE_SRIOV_VF); if (keys) { @@ -2261,7 +2260,7 @@ make_sriov_setting (shvarFile *ifcfg) key += NM_STRLEN ("SRIOV_VF"); - vf = _nm_utils_sriov_vf_from_strparts (key, value, &error); + vf = _nm_utils_sriov_vf_from_strparts (key, value, TRUE, &error); if (!vf) { PARSE_WARNING ("ignoring invalid SR-IOV VF '%s %s': %s", key, value, error->message); @@ -2273,11 +2272,21 @@ make_sriov_setting (shvarFile *ifcfg) } } + /* Create the setting when at least one key is set */ + if ( total_vfs < 0 + && !vfs + && autoprobe_drivers < NM_TERNARY_DEFAULT) + return NULL; + s_sriov = (NMSettingSriov *) nm_setting_sriov_new (); + + autoprobe_drivers = NM_MAX (autoprobe_drivers, NM_TERNARY_DEFAULT); + total_vfs = NM_MAX (total_vfs, 0); + g_object_set (s_sriov, - NM_SETTING_SRIOV_TOTAL_VFS, total_vfs, + NM_SETTING_SRIOV_TOTAL_VFS, (guint) total_vfs, NM_SETTING_SRIOV_VFS, vfs, - NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, (int) autoprobe_drivers, + NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, autoprobe_drivers, NULL); return (NMSetting *) s_sriov; 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 b70690cc..f5be7520 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -2223,16 +2223,15 @@ write_sriov_setting (NMConnection *connection, shvarFile *ifcfg) svUnsetAll (ifcfg, SV_KEY_TYPE_SRIOV_VF); - s_sriov = NM_SETTING_SRIOV (nm_connection_get_setting (connection, NM_TYPE_SETTING_SRIOV)); - if (s_sriov) - num = nm_setting_sriov_get_total_vfs (s_sriov); - if (num == 0) { + s_sriov = NM_SETTING_SRIOV (nm_connection_get_setting (connection, + NM_TYPE_SETTING_SRIOV)); + if (!s_sriov) { svUnsetValue (ifcfg, "SRIOV_TOTAL_VFS"); svUnsetValue (ifcfg, "SRIOV_AUTOPROBE_DRIVERS"); return; } - svSetValueInt64 (ifcfg, "SRIOV_TOTAL_VFS", num); + svSetValueInt64 (ifcfg, "SRIOV_TOTAL_VFS", nm_setting_sriov_get_total_vfs (s_sriov)); b = nm_setting_sriov_get_autoprobe_drivers (s_sriov); if (b != NM_TERNARY_DEFAULT) diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index b66eedc7..f0e64d1d 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -282,8 +282,10 @@ initialize (NMSettingsPlugin *plugin) g_hash_table_iter_init (&iter, priv->eni_ifaces); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) conn)) { - _nm_settings_plugin_emit_signal_connection_added (NM_SETTINGS_PLUGIN (self), - NM_SETTINGS_CONNECTION (conn)); + if (conn) { + _nm_settings_plugin_emit_signal_connection_added (NM_SETTINGS_PLUGIN (self), + NM_SETTINGS_CONNECTION (conn)); + } } } } -- cgit 1.3.0-6-gf8a5 From 9a6dcbf895f9da01768e64b73cec88c16157d91e Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Tue, 26 Mar 2019 23:25:23 +0100 Subject: New upstream version 1.16.0 --- src/settings/nm-agent-manager.c | 47 +-- src/settings/nm-settings-connection.c | 208 ++----------- src/settings/nm-settings.c | 43 ++- src/settings/nm-settings.h | 2 +- src/settings/plugins/ibft/meson.build | 6 +- src/settings/plugins/ibft/nms-ibft-connection.c | 1 - src/settings/plugins/ibft/nms-ibft-plugin.c | 2 - src/settings/plugins/ibft/nms-ibft-reader.c | 2 - src/settings/plugins/ibft/tests/meson.build | 4 +- src/settings/plugins/ibft/tests/test-ibft.c | 1 - src/settings/plugins/ifcfg-rh/meson.build | 12 +- src/settings/plugins/ifcfg-rh/nm-inotify-helper.c | 8 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-connection.c | 1 - .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 11 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 67 ++--- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 1 - .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 6 +- src/settings/plugins/ifcfg-rh/shvar.c | 32 +- src/settings/plugins/ifcfg-rh/tests/meson.build | 4 +- .../ifcfg-Test_Write_WiFi_Band_A.cexpected | 2 +- .../ifcfg-Test_Write_WiFi_Hidden.cexpected | 2 +- .../ifcfg-Test_Write_WiFi_MAC_always.cexpected | 2 +- .../ifcfg-Test_Write_WiFi_MAC_default.cexpected | 2 +- .../ifcfg-Test_Write_WiFi_MAC_missing.cexpected | 2 +- .../ifcfg-Test_Write_WiFi_MAC_never.cexpected | 2 +- .../tests/network-scripts/ifcfg-test-wifi-sae | 5 + .../network-scripts/ifcfg-test-write-unknown-4 | 2 +- .../ifcfg-test-write-unknown-4.expected | 2 +- .../tests/network-scripts/keys-test-wifi-sae | 1 + .../network-test-wired-never-default | 2 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 63 +++- src/settings/plugins/ifupdown/meson.build | 10 +- .../plugins/ifupdown/nms-ifupdown-connection.c | 1 - .../ifupdown/nms-ifupdown-interface-parser.c | 1 - .../plugins/ifupdown/nms-ifupdown-parser.c | 6 +- .../plugins/ifupdown/nms-ifupdown-plugin.c | 1 - src/settings/plugins/ifupdown/tests/meson.build | 4 +- .../plugins/ifupdown/tests/test-ifupdown.c | 2 - .../plugins/keyfile/nms-keyfile-connection.c | 1 - src/settings/plugins/keyfile/nms-keyfile-plugin.c | 71 +---- src/settings/plugins/keyfile/nms-keyfile-reader.c | 10 +- src/settings/plugins/keyfile/nms-keyfile-utils.c | 328 +++++++++++++-------- src/settings/plugins/keyfile/nms-keyfile-utils.h | 43 ++- src/settings/plugins/keyfile/nms-keyfile-writer.c | 77 ++--- src/settings/plugins/keyfile/tests/meson.build | 3 +- src/settings/plugins/keyfile/tests/test-keyfile.c | 131 +++++++- 46 files changed, 619 insertions(+), 615 deletions(-) create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae (limited to 'src/settings') diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 953d3ce4..8924c39f 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -22,7 +22,6 @@ #include "nm-agent-manager.h" -#include #include #include "nm-common-macros.h" @@ -1058,49 +1057,6 @@ _con_get_request_start_validated (NMAuthChain *chain, nm_auth_chain_destroy (chain); } -static void -has_system_secrets_check (NMSetting *setting, - const char *key, - const GValue *value, - GParamFlags flags, - gpointer user_data) -{ - NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - gboolean *has_system = user_data; - - if (!(flags & NM_SETTING_PARAM_SECRET)) - return; - - /* Clear out system-owned or always-ask secrets */ - if (NM_IS_SETTING_VPN (setting) && !strcmp (key, NM_SETTING_VPN_SECRETS)) { - GHashTableIter iter; - const char *secret_name = NULL; - - /* VPNs are special; need to handle each secret separately */ - g_hash_table_iter_init (&iter, (GHashTable *) g_value_get_boxed (value)); - while (g_hash_table_iter_next (&iter, (gpointer *) &secret_name, NULL)) { - secret_flags = NM_SETTING_SECRET_FLAG_NONE; - nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL); - if (secret_flags == NM_SETTING_SECRET_FLAG_NONE) - *has_system = TRUE; - } - } else { - if (!nm_setting_get_secret_flags (setting, key, &secret_flags, NULL)) - g_return_if_reached (); - if (secret_flags == NM_SETTING_SECRET_FLAG_NONE) - *has_system = TRUE; - } -} - -static gboolean -has_system_secrets (NMConnection *connection) -{ - gboolean has_system = FALSE; - - nm_connection_for_each_setting_value (connection, has_system_secrets_check, &has_system); - return has_system; -} - static void _con_get_request_start (Request *req) { @@ -1121,7 +1077,8 @@ _con_get_request_start (Request *req) * unprivileged users. */ if ( (req->con.get.flags != NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE) - && (req->con.get.existing_secrets || has_system_secrets (req->con.connection))) { + && ( req->con.get.existing_secrets + || _nm_connection_aggregate (req->con.connection, NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS, NULL))) { _LOGD (NULL, "("LOG_REQ_FMT") request has system secrets; checking agent %s for MODIFY", LOG_REQ_ARG (req), agent_dbus_owner); diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 6f47e14d..8d1f9583 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -23,8 +23,6 @@ #include "nm-settings-connection.h" -#include - #include "c-list/src/c-list.h" #include "nm-common-macros.h" @@ -208,141 +206,6 @@ nm_settings_connection_get_last_secret_agent_version_id (NMSettingsConnection *s /*****************************************************************************/ -/* Return TRUE to keep, FALSE to drop */ -typedef gboolean (*ForEachSecretFunc) (NMSettingSecretFlags flags, - gpointer user_data); - -/* Returns always a non-NULL, non-floating variant that must - * be unrefed by the caller. */ -static GVariant * -for_each_secret (NMConnection *self, - GVariant *secrets, - gboolean remove_non_secrets, - ForEachSecretFunc callback, - gpointer callback_data) -{ - GVariantBuilder secrets_builder, setting_builder; - GVariantIter secrets_iter, *setting_iter; - const char *setting_name; - - /* This function, given a dict of dicts representing new secrets of - * an NMConnection, walks through each toplevel dict (which represents a - * NMSetting), and for each setting, walks through that setting dict's - * properties. For each property that's a secret, it will check that - * secret's flags in the backing NMConnection object, and call a supplied - * callback. - * - * The one complexity is that the VPN setting's 'secrets' property is - * *also* a dict (since the key/value pairs are arbitrary and known - * only to the VPN plugin itself). That means we have three levels of - * dicts that we potentially have to traverse here. When we hit the - * VPN setting's 'secrets' property, we special-case that and iterate over - * each item in that 'secrets' dict, calling the supplied callback - * each time. - */ - - g_return_val_if_fail (callback, NULL); - - g_variant_iter_init (&secrets_iter, secrets); - g_variant_builder_init (&secrets_builder, NM_VARIANT_TYPE_CONNECTION); - while (g_variant_iter_next (&secrets_iter, "{&sa{sv}}", &setting_name, &setting_iter)) { - NMSetting *setting; - const char *secret_name; - GVariant *val; - - setting = nm_connection_get_setting_by_name (self, setting_name); - if (setting == NULL) { - g_variant_iter_free (setting_iter); - continue; - } - - g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); - while (g_variant_iter_next (setting_iter, "{&sv}", &secret_name, &val)) { - NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - - /* VPN secrets need slightly different treatment here since the - * "secrets" property is actually a hash table of secrets. - */ - if (NM_IS_SETTING_VPN (setting) && !g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS)) { - GVariantBuilder vpn_secrets_builder; - GVariantIter vpn_secrets_iter; - const char *vpn_secret_name, *secret; - - /* Iterate through each secret from the VPN dict in the overall secrets dict */ - g_variant_builder_init (&vpn_secrets_builder, G_VARIANT_TYPE ("a{ss}")); - g_variant_iter_init (&vpn_secrets_iter, val); - while (g_variant_iter_next (&vpn_secrets_iter, "{&s&s}", &vpn_secret_name, &secret)) { - if (!nm_setting_get_secret_flags (setting, vpn_secret_name, &secret_flags, NULL)) { - if (!remove_non_secrets) - g_variant_builder_add (&vpn_secrets_builder, "{ss}", vpn_secret_name, secret); - continue; - } - - if (callback (secret_flags, callback_data)) - g_variant_builder_add (&vpn_secrets_builder, "{ss}", vpn_secret_name, secret); - } - - g_variant_builder_add (&setting_builder, "{sv}", - secret_name, g_variant_builder_end (&vpn_secrets_builder)); - } else { - if (!nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL)) { - if (!remove_non_secrets) - g_variant_builder_add (&setting_builder, "{sv}", secret_name, val); - continue; - } - if (callback (secret_flags, callback_data)) - g_variant_builder_add (&setting_builder, "{sv}", secret_name, val); - } - g_variant_unref (val); - } - - g_variant_iter_free (setting_iter); - g_variant_builder_add (&secrets_builder, "{sa{sv}}", setting_name, &setting_builder); - } - - return g_variant_ref_sink (g_variant_builder_end (&secrets_builder)); -} - -typedef gboolean (*FindSecretFunc) (NMSettingSecretFlags flags, - gpointer user_data); - -typedef struct { - FindSecretFunc find_func; - gpointer find_func_data; - gboolean found; -} FindSecretData; - -static gboolean -find_secret_for_each_func (NMSettingSecretFlags flags, - gpointer user_data) -{ - FindSecretData *data = user_data; - - if (!data->found) - data->found = data->find_func (flags, data->find_func_data); - return FALSE; -} - -static gboolean -find_secret (NMConnection *self, - GVariant *secrets, - FindSecretFunc callback, - gpointer callback_data) -{ - FindSecretData data; - GVariant *dummy; - - data.find_func = callback; - data.find_func_data = callback_data; - data.found = FALSE; - - dummy = for_each_secret (self, secrets, FALSE, find_secret_for_each_func, &data); - g_variant_unref (dummy); - return data.found; -} - -/*****************************************************************************/ - static void set_visible (NMSettingsConnection *self, gboolean new_visible) { @@ -790,7 +653,7 @@ out: else if (new_connection) _LOGI ("write: successfully updated (%s)", logmsg_change); else - _LOGI ("write: successfully commited (%s)", logmsg_change); + _LOGI ("write: successfully committed (%s)", logmsg_change); } return TRUE; } @@ -938,8 +801,8 @@ typedef struct { } ForEachSecretFlags; static gboolean -validate_secret_flags (NMSettingSecretFlags flags, - gpointer user_data) +validate_secret_flags_cb (NMSettingSecretFlags flags, + gpointer user_data) { ForEachSecretFlags *cmp_flags = user_data; @@ -950,6 +813,18 @@ validate_secret_flags (NMSettingSecretFlags flags, return TRUE; } +static GVariant * +validate_secret_flags (NMConnection *connection, + GVariant *secrets, + ForEachSecretFlags *cmp_flags) +{ + return g_variant_ref_sink (_nm_connection_for_each_secret (connection, + secrets, + TRUE, + validate_secret_flags_cb, + cmp_flags)); +} + static gboolean secret_is_system_owned (NMSettingSecretFlags flags, gpointer user_data) @@ -992,7 +867,7 @@ get_cmp_flags (NMSettingsConnection *self, /* only needed for logging */ * save those system-owned secrets. If not, discard them and use the * existing secrets, or fail the connection. */ - *agent_had_system = find_secret (connection, secrets, secret_is_system_owned, NULL); + *agent_had_system = _nm_connection_find_secret (connection, secrets, secret_is_system_owned, NULL); if (*agent_had_system) { if (flags == NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE) { /* No user interaction was allowed when requesting secrets; the @@ -1151,14 +1026,14 @@ get_secrets_done_cb (NMAgentManager *manager, /* Update the connection with our existing secrets from backing storage */ nm_connection_clear_secrets (nm_settings_connection_get_connection (self)); if (!dict || nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, dict, &local)) { - GVariant *filtered_secrets; + gs_unref_variant GVariant *filtered_secrets = NULL; /* Update the connection with the agent's secrets; by this point if any * system-owned secrets exist in 'secrets' the agent that provided them * will have been authenticated, so those secrets can replace the existing * system secrets. */ - filtered_secrets = for_each_secret (nm_settings_connection_get_connection (self), secrets, TRUE, validate_secret_flags, &cmp_flags); + filtered_secrets = validate_secret_flags (nm_settings_connection_get_connection (self), secrets, &cmp_flags); if (nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, filtered_secrets, &local)) { /* Now that all secrets are updated, copy and cache new secrets, * then save them to backing storage. @@ -1194,7 +1069,6 @@ get_secrets_done_cb (NMAgentManager *manager, call_id, local->message); } - g_variant_unref (filtered_secrets); } else { _LOGD ("(%s:%p) failed to update with existing secrets: %s", setting_name, @@ -1218,11 +1092,10 @@ get_secrets_done_cb (NMAgentManager *manager, nm_connection_clear_secrets (applied_connection); if (!dict || nm_connection_update_secrets (applied_connection, setting_name, dict, NULL)) { - GVariant *filtered_secrets; + gs_unref_variant GVariant *filtered_secrets = NULL; - filtered_secrets = for_each_secret (applied_connection, secrets, TRUE, validate_secret_flags, &cmp_flags); + filtered_secrets = validate_secret_flags (applied_connection, secrets, &cmp_flags); nm_connection_update_secrets (applied_connection, setting_name, filtered_secrets, NULL); - g_variant_unref (filtered_secrets); } } @@ -1338,7 +1211,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, /* we remember the current version-id of the secret-agents. The version-id is strictly increasing, * as new agents register the number. We know hence, that this request was made against a certain * set of secret-agents. - * If after making this request a new secret-agent registeres, the version-id increases. + * If after making this request a new secret-agent registers, the version-id increases. * Then we know that the this request probably did not yet include the latest secret-agent. */ priv->last_secret_agent_version_id = nm_agent_manager_get_agent_version_id (priv->agent_mgr); @@ -1659,38 +1532,6 @@ typedef struct { bool is_update2:1; } UpdateInfo; -static void -has_some_secrets_cb (NMSetting *setting, - const char *key, - const GValue *value, - GParamFlags flags, - gpointer user_data) -{ - GParamSpec *pspec; - - if (NM_IS_SETTING_VPN (setting)) { - if (nm_setting_vpn_get_num_secrets (NM_SETTING_VPN(setting))) - *((gboolean *) user_data) = TRUE; - return; - } - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), key); - if (pspec) { - if ( (flags & NM_SETTING_PARAM_SECRET) - && !g_param_value_defaults (pspec, (GValue *)value)) - *((gboolean *) user_data) = TRUE; - } -} - -static gboolean -any_secrets_present (NMConnection *self) -{ - gboolean has_secrets = FALSE; - - nm_connection_for_each_setting_value (self, has_some_secrets_cb, &has_secrets); - return has_secrets; -} - static void cached_secrets_to_connection (NMSettingsConnection *self, NMConnection *connection) { @@ -1758,7 +1599,7 @@ update_auth_cb (NMSettingsConnection *self, } if (info->new_settings) { - if (!any_secrets_present (info->new_settings)) { + if (!_nm_connection_aggregate (info->new_settings, NM_CONNECTION_AGGREGATE_ANY_SECRETS, NULL)) { /* If the new connection has no secrets, we do not want to remove all * secrets, rather we keep all the existing ones. Do that by merging * them in to the new connection. @@ -1910,6 +1751,9 @@ settings_connection_update (NMSettingsConnection *self, &error); if (!tmp) goto error; + + if (!nm_connection_verify_secrets (tmp, &error)) + goto error; } } @@ -2809,7 +2653,7 @@ _autoconnect_retries_set (NMSettingsConnection *self, /* NOTE: the blocked time must be identical for all connections, otherwise * the tracking of resetting the retry count in NMPolicy needs adjustment * in _connection_autoconnect_retries_set() (as it would need to re-evaluate - * the next-timeout everytime a connection gets blocked). */ + * the next-timeout every time a connection gets blocked). */ priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_s () + AUTOCONNECT_RESET_RETRIES_TIMER; } } diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 2253d56a..fd1d316a 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -29,8 +29,6 @@ #include #include -#include -#include #include #include @@ -129,6 +127,8 @@ typedef struct { NMHostnameManager *hostname_manager; + NMSettingsConnection *startup_complete_blocked_by; + guint connections_len; bool started:1; @@ -182,19 +182,23 @@ static void check_startup_complete (NMSettings *self) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); - NMSettingsConnection *conn; + NMSettingsConnection *sett_conn; if (priv->startup_complete) return; - c_list_for_each_entry (conn, &priv->connections_lst_head, _connections_lst) { - if (!nm_settings_connection_get_ready (conn)) + c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) { + if (!nm_settings_connection_get_ready (sett_conn)) { + nm_g_object_ref_set (&priv->startup_complete_blocked_by, sett_conn); return; + } } + g_clear_object (&priv->startup_complete_blocked_by); + /* the connection_ready_changed signal handler is no longer needed. */ - c_list_for_each_entry (conn, &priv->connections_lst_head, _connections_lst) - g_signal_handlers_disconnect_by_func (conn, G_CALLBACK (connection_ready_changed), self); + c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) + g_signal_handlers_disconnect_by_func (sett_conn, G_CALLBACK (connection_ready_changed), self); priv->startup_complete = TRUE; _notify (self, PROP_STARTUP_COMPLETE); @@ -369,10 +373,10 @@ _clear_connections_cached_list (NMSettingsPrivate *priv) /** * nm_settings_get_connections: * @self: the #NMSettings - * @out_len: (out): (allow-none): returns the number of returned + * @out_len: (out) (allow-none): returns the number of returned * connections. * - * Returns: (transfer-none): a list of NMSettingsConnections. The list is + * Returns: (transfer none): a list of NMSettingsConnections. The list is * unsorted and NULL terminated. The result is never %NULL, in case of no * connections, it returns an empty list. * The returned list is cached internally, only valid until the next @@ -632,7 +636,7 @@ add_plugin_load_file (NMSettings *self, const char *pname, GError **error) if (stat (path, &st) != 0) { errsv = errno; - _LOGW ("could not load plugin '%s' from file '%s': %s", pname, path, strerror (errsv)); + _LOGW ("could not load plugin '%s' from file '%s': %s", pname, path, nm_strerror_native (errsv)); return TRUE; } if (!S_ISREG (st.st_mode)) { @@ -840,10 +844,10 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data) if (priv->connections_loaded) g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connection); - g_object_unref (connection); - check_startup_complete (self); + g_object_unref (connection); + g_object_unref (self); /* Balanced by a ref in claim_connection() */ } @@ -1754,12 +1758,17 @@ nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quittin /*****************************************************************************/ -gboolean -nm_settings_get_startup_complete (NMSettings *self) +const char * +nm_settings_get_startup_complete_blocked_reason (NMSettings *self) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); + const char *uuid = NULL; - return priv->startup_complete; + if (priv->startup_complete) + return NULL; + if (priv->startup_complete_blocked_by) + uuid = nm_settings_connection_get_uuid (priv->startup_complete_blocked_by); + return uuid ?: "unknown"; } /*****************************************************************************/ @@ -1845,7 +1854,7 @@ get_property (GObject *object, guint prop_id, g_value_set_boxed (value, NULL); break; case PROP_STARTUP_COMPLETE: - g_value_set_boolean (value, nm_settings_get_startup_complete (self)); + g_value_set_boolean (value, !nm_settings_get_startup_complete_blocked_reason (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1878,6 +1887,8 @@ dispose (GObject *object) NMSettings *self = NM_SETTINGS (object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); + g_clear_object (&priv->startup_complete_blocked_by); + g_slist_free_full (priv->auths, (GDestroyNotify) nm_auth_chain_destroy); priv->auths = NULL; diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index 38d8ad4e..eb74c09c 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -112,6 +112,6 @@ void nm_settings_device_added (NMSettings *self, NMDevice *device); void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quitting); -gboolean nm_settings_get_startup_complete (NMSettings *self); +const char *nm_settings_get_startup_complete_blocked_reason (NMSettings *self); #endif /* __NM_SETTINGS_H__ */ diff --git a/src/settings/plugins/ibft/meson.build b/src/settings/plugins/ibft/meson.build index c7dbe459..c33b24cc 100644 --- a/src/settings/plugins/ibft/meson.build +++ b/src/settings/plugins/ibft/meson.build @@ -8,7 +8,7 @@ libnms_ibft_core = static_library( sources = files( 'nms-ibft-connection.c', - 'nms-ibft-plugin.c' + 'nms-ibft-plugin.c', ) libnm_settings_plugin_ibft = shared_module( @@ -19,7 +19,7 @@ libnm_settings_plugin_ibft = shared_module( link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, install: true, - install_dir: nm_plugindir + install_dir: nm_plugindir, ) core_plugins += libnm_settings_plugin_ibft @@ -29,7 +29,7 @@ core_plugins += libnm_settings_plugin_ibft run_target( 'check-local-symbols-settings-ibft', command: [check_so_symbols, libnm_settings_plugin_ibft.full_path()], - depends: libnm_settings_plugin_ibft + depends: libnm_settings_plugin_ibft, ) check-local-symbols-settings-ibft: src/settings/plugins/ibft/libnm-settings-plugin-ibft.la diff --git a/src/settings/plugins/ibft/nms-ibft-connection.c b/src/settings/plugins/ibft/nms-ibft-connection.c index fb7f18f8..a36d8a31 100644 --- a/src/settings/plugins/ibft/nms-ibft-connection.c +++ b/src/settings/plugins/ibft/nms-ibft-connection.c @@ -22,7 +22,6 @@ #include "nms-ibft-connection.h" -#include #include #include #include diff --git a/src/settings/plugins/ibft/nms-ibft-plugin.c b/src/settings/plugins/ibft/nms-ibft-plugin.c index 69dd3733..00b25068 100644 --- a/src/settings/plugins/ibft/nms-ibft-plugin.c +++ b/src/settings/plugins/ibft/nms-ibft-plugin.c @@ -22,9 +22,7 @@ #include "nms-ibft-plugin.h" -#include #include -#include #include #include "nm-setting-connection.h" diff --git a/src/settings/plugins/ibft/nms-ibft-reader.c b/src/settings/plugins/ibft/nms-ibft-reader.c index ac5824a1..c6c14376 100644 --- a/src/settings/plugins/ibft/nms-ibft-reader.c +++ b/src/settings/plugins/ibft/nms-ibft-reader.c @@ -23,13 +23,11 @@ #include "nms-ibft-reader.h" #include -#include #include #include #include #include #include -#include #include #include diff --git a/src/settings/plugins/ibft/tests/meson.build b/src/settings/plugins/ibft/tests/meson.build index 8b5e143a..e2f9ca7e 100644 --- a/src/settings/plugins/ibft/tests/meson.build +++ b/src/settings/plugins/ibft/tests/meson.build @@ -6,11 +6,11 @@ exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - link_with: libnms_ibft_core + link_with: libnms_ibft_core, ) test( 'ibft/' + test_unit, test_script, - args: test_args + [exe.full_path()] + args: test_args + [exe.full_path()], ) diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c index 5e46be2e..4c45f574 100644 --- a/src/settings/plugins/ibft/tests/test-ibft.c +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/src/settings/plugins/ifcfg-rh/meson.build b/src/settings/plugins/ifcfg-rh/meson.build index e84ae80c..9024782a 100644 --- a/src/settings/plugins/ifcfg-rh/meson.build +++ b/src/settings/plugins/ifcfg-rh/meson.build @@ -1,6 +1,6 @@ install_data( 'nm-ifcfg-rh.conf', - install_dir: dbus_conf_dir + install_dir: dbus_conf_dir, ) name = 'nmdbus-ifcfg-rh' @@ -9,7 +9,7 @@ dbus_sources = gnome.gdbus_codegen( name, 'nm-ifcfg-rh.xml', interface_prefix: 'com.redhat', - namespace: 'NMDBus' + namespace: 'NMDBus', ) libnmdbus_ifcfg_rh = static_library( @@ -23,11 +23,11 @@ core_sources = files( 'nms-ifcfg-rh-reader.c', 'nms-ifcfg-rh-utils.c', 'nms-ifcfg-rh-writer.c', - 'shvar.c' + 'shvar.c', ) deps = [ - nm_dep + nm_dep, ] libnms_ifcfg_rh_core = static_library( @@ -46,7 +46,7 @@ libnm_settings_plugin_ifcfg_rh = shared_module( link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, install: true, - install_dir: nm_plugindir + install_dir: nm_plugindir, ) core_plugins += libnm_settings_plugin_ifcfg_rh @@ -56,7 +56,7 @@ core_plugins += libnm_settings_plugin_ifcfg_rh run_target( 'check-local-symbols-settings-ifcfg-rh', command: [check_so_symbols, libnm_settings_plugin_ifcfg_rh.full_path()], - depends: libnm_settings_plugin_ifcfg_rh + depends: libnm_settings_plugin_ifcfg_rh, ) check-local-symbols-settings-ifcfg-rh: src/settings/plugins/ifcfg-rh/libnm-settings-plugin-ifcfg-rh.la diff --git a/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c b/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c index e7a74a1a..04cbb5bc 100644 --- a/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c +++ b/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c @@ -23,9 +23,7 @@ #include "nm-inotify-helper.h" #include -#include #include -#include #include "NetworkManagerUtils.h" @@ -143,12 +141,12 @@ init_inotify (NMInotifyHelper *self) { NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self); GIOChannel *channel; + int errsv; priv->ifd = inotify_init1 (IN_CLOEXEC); if (priv->ifd == -1) { - int errsv = errno; - - nm_log_warn (LOGD_SETTINGS, "couldn't initialize inotify: %s (%d)", strerror (errsv), errsv); + errsv = errno; + nm_log_warn (LOGD_SETTINGS, "couldn't initialize inotify: %s (%d)", nm_strerror_native (errsv), errsv); return FALSE; } 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 ca319ddc..4f769c5f 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -22,7 +22,6 @@ #include "nms-ifcfg-rh-connection.h" -#include #include #include diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index 6cac8cb6..89272edb 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -25,9 +25,7 @@ #include "nms-ifcfg-rh-plugin.h" -#include #include -#include #include #include #include @@ -539,7 +537,7 @@ read_connections (SettingsPluginIfcfg *plugin) * iterating over the files. * * To have sensible, reproducible behavior, sort the paths by last modification - * time prefering older files. + * time preferring older files. */ paths = _paths_from_connections (priv->connections); g_ptr_array_sort_with_data (filenames, (GCompareDataFunc) _sort_paths, paths); @@ -602,12 +600,9 @@ load_connection (NMSettingsPlugin *config, { SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); NMIfcfgConnection *connection; - int dir_len = strlen (IFCFG_DIR); char *ifcfg_path; - if ( strncmp (filename, IFCFG_DIR, dir_len) != 0 - || filename[dir_len] != '/' - || strchr (filename + dir_len + 1, '/') != NULL) + if (!nm_utils_file_is_in_path (filename, IFCFG_DIR)) return FALSE; /* get the real ifcfg-path. This allows us to properly @@ -987,7 +982,7 @@ config_changed_cb (NMConfig *config, * won't be offered. * * On SIGHUP and SIGUSR1 try to re-connect to D-Bus. So in the unlikely - * event that the D-Bus conneciton is broken, that allows for recovery + * event that the D-Bus connection is broken, that allows for recovery * without need for restarting NetworkManager. */ if (!NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP | NM_CONFIG_CHANGE_CAUSE_SIGUSR1)) 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 261dfea2..7c1db225 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -23,13 +23,11 @@ #include "nms-ifcfg-rh-reader.h" #include -#include #include #include #include #include #include -#include #include #include @@ -189,7 +187,7 @@ _secret_password_raw_to_bytes (const char *ifcfg_key, password_raw += 2; secret = nm_secret_buf_new (strlen (password_raw) / 2 + 3); - if (!_nm_utils_hexstr2bin_full (password_raw, FALSE, FALSE, ":", 0, secret->bin, secret->len, &len)) { + if (!nm_utils_hexstr2bin_full (password_raw, FALSE, FALSE, ":", 0, secret->bin, secret->len, &len)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid hex password in %s", ifcfg_key); @@ -670,7 +668,7 @@ read_full_ip4_address (shvarFile *ifcfg, &has_key, &a, error)) return FALSE; if (has_key) - *out_gateway = g_strdup (nm_utils_inet4_ntop (a, inet_buf)); + *out_gateway = nm_utils_inet4_ntop_dup (a); } /* Prefix */ @@ -801,7 +799,7 @@ enum { * @options_route: (in-out): when line is from the OPTIONS setting, this is a pre-created * route object that is completed with the settings from options. Otherwise, * it shall point to %NULL and a new route is created and returned. - * @out_route: (out): (transfer-full): (allow-none): the parsed %NMIPRoute instance. + * @out_route: (out) (transfer-full) (allow-none): the parsed %NMIPRoute instance. * In case a @options_route is passed in, it returns the input route that was modified * in-place. But the caller must unref the returned route in either case. * @error: the failure description. @@ -810,7 +808,7 @@ enum { * setting, and one for initscript's handle_ip_file(), which takes the lines * and passes them to `ip route add`. The modes are similar, but certain properties * are not allowed for OPTIONS. - * The mode is differenciated by having an @options_route argument. + * The mode is differentiated by having an @options_route argument. * * Returns: returns a negative errno on failure. On success, it returns 0 * and @out_route. @@ -873,7 +871,7 @@ parse_route_line (const char *line, }; nm_assert (line); - nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); + nm_assert_addr_family (addr_family); nm_assert (!options_route || nm_ip_route_get_family (options_route) == addr_family); /* initscripts read the legacy route file line-by-line and @@ -1018,6 +1016,7 @@ parse_line_type_addr_with_prefix: if (info->type == PARSE_LINE_TYPE_ADDR) { if (!nm_utils_parse_inaddr_bin (addr_family, s, + NULL, &info->v.addr.addr)) { if ( info == &infos[PARSE_LINE_ATTR_ROUTE_VIA] && nm_streq (s, "(null)")) { @@ -1045,6 +1044,7 @@ parse_line_type_addr_with_prefix: prefix = 0; } else if (!nm_utils_parse_inaddr_prefix_bin (addr_family, s, + NULL, &info->v.addr.addr, &prefix)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -1150,7 +1150,7 @@ next: : "")); break; case PARSE_LINE_TYPE_FLAG: - /* NOTE: the flag (for "onlink") only allows to explictly set "TRUE". + /* NOTE: the flag (for "onlink") only allows to explicitly set "TRUE". * There is no way to express an explicit "FALSE" setting * of this attribute, hence, the file format cannot encode * that configuration. */ @@ -1425,8 +1425,8 @@ make_user_setting (shvarFile *ifcfg) has_user_data = TRUE; } - return has_user_data - ? g_steal_pointer (&s_user) + return has_user_data + ? NM_SETTING (g_steal_pointer (&s_user)) : NULL; } @@ -1527,7 +1527,6 @@ make_ip4_setting (shvarFile *ifcfg, gboolean never_default; gint64 timeout; int priority; - char inet_buf[NM_UTILS_INET_ADDRSTRLEN]; const char *const *item; guint32 route_table; @@ -1612,7 +1611,7 @@ make_ip4_setting (shvarFile *ifcfg, NULL); if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) - return g_steal_pointer (&s_ip4); + return NM_SETTING (g_steal_pointer (&s_ip4)); /* Handle DHCP settings */ nm_clear_g_free (&value); @@ -1679,7 +1678,7 @@ make_ip4_setting (shvarFile *ifcfg, PARSE_WARNING ("ignoring GATEWAY (/etc/sysconfig/network) for %s " "because the connection has no static addresses", f); } else - gateway = g_strdup (nm_utils_inet4_ntop (a, inet_buf)); + gateway = nm_utils_inet4_ntop_dup (a); } } } @@ -1803,7 +1802,7 @@ make_ip4_setting (shvarFile *ifcfg, } g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DAD_TIMEOUT, (int) timeout, NULL); - return g_steal_pointer (&s_ip4); + return NM_SETTING (g_steal_pointer (&s_ip4)); } static void @@ -2945,7 +2944,7 @@ make_wep_setting (shvarFile *ifcfg, return NULL; } - return g_steal_pointer (&s_wsec); + return NM_SETTING (g_steal_pointer (&s_wsec)); } static gboolean @@ -3160,7 +3159,7 @@ eap_tls_reader (const char *eap_method, /* FIXME: writer does not actually write IEEE_8021X_CLIENT_CERT_PASSWORD and other * certificate related passwords. It should, because otherwise persisting such profiles * to ifcfg looses information. As this currently only matters for PKCS11 URIs, it seems - * a seldomly used feature so that it is not fixed yet. */ + * a seldom used feature so that it is not fixed yet. */ _secret_set_from_ifcfg (s_8021x, ifcfg, keys_ifcfg, @@ -3535,7 +3534,7 @@ fill_8021x (shvarFile *ifcfg, goto next; /* Some EAP methods don't provide keying material, thus they - * cannot be used with WiFi unless they are an inner method + * cannot be used with Wi-Fi unless they are an inner method * used with TTLS or PEAP or whatever. */ if (wifi && eap->wifi_phase2_only) { @@ -3611,7 +3610,7 @@ make_wpa_setting (shvarFile *ifcfg, gs_unref_object NMSettingWirelessSecurity *wsec = NULL; gs_free char *value = NULL; const char *v; - gboolean wpa_psk = FALSE, wpa_eap = FALSE, ieee8021x = FALSE; + gboolean wpa_psk = FALSE, wpa_sae = FALSE, wpa_eap = FALSE, ieee8021x = FALSE; int i_val; GError *local = NULL; @@ -3619,9 +3618,10 @@ make_wpa_setting (shvarFile *ifcfg, v = svGetValueStr (ifcfg, "KEY_MGMT", &value); wpa_psk = nm_streq0 (v, "WPA-PSK"); + wpa_sae = nm_streq0 (v, "SAE"); wpa_eap = nm_streq0 (v, "WPA-EAP"); ieee8021x = nm_streq0 (v, "IEEE8021X"); - if (!wpa_psk && !wpa_eap && !ieee8021x) + if (!wpa_psk && !wpa_sae && !wpa_eap && !ieee8021x) return NULL; /* Not WPA or Dynamic WEP */ /* WPS */ @@ -3635,7 +3635,7 @@ make_wpa_setting (shvarFile *ifcfg, NULL); /* Pairwise and Group ciphers (only relevant for WPA/RSN) */ - if (wpa_psk || wpa_eap) { + if (wpa_psk || wpa_sae || wpa_eap) { fill_wpa_ciphers (ifcfg, wsec, FALSE, adhoc); fill_wpa_ciphers (ifcfg, wsec, TRUE, adhoc); } @@ -3658,7 +3658,7 @@ make_wpa_setting (shvarFile *ifcfg, nm_setting_wireless_security_add_proto (wsec, "rsn"); } - if (wpa_psk) { + if (wpa_psk || wpa_sae) { NMSettingSecretFlags psk_flags; psk_flags = _secret_read_ifcfg_flags (ifcfg, "WPA_PSK_FLAGS"); @@ -3679,8 +3679,12 @@ make_wpa_setting (shvarFile *ifcfg, if (adhoc) g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL); - else + else if (wpa_psk) g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL); + else if (wpa_sae) + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "sae", NULL); + else + g_assert_not_reached (); } else if (wpa_eap || ieee8021x) { /* Adhoc mode is mutually exclusive with any 802.1x-based authentication */ if (adhoc) { @@ -3945,9 +3949,8 @@ make_wireless_setting (shvarFile *ifcfg, value = svGetValueStr_cp (ifcfg, "CHANNEL"); if (value) { - errno = 0; chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0); - if (errno || (chan == 0)) { + if (chan == 0) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid wireless channel '%s'", value); g_free (value); @@ -4991,7 +4994,7 @@ handle_bridge_option (NMSetting *setting, } else { v = _nm_utils_ascii_str_to_int64 (value, 10, 0, 1, -1); if (v == -1) { - error_message = g_strerror (errno); + error_message = nm_strerror_native (errno); goto warn; } } @@ -5003,7 +5006,7 @@ handle_bridge_option (NMSetting *setting, case G_TYPE_UINT: v = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT, -1); if (v == -1) { - error_message = g_strerror (errno); + error_message = nm_strerror_native (errno); goto warn; } if (!nm_g_object_set_property_uint (G_OBJECT (setting), m[i].property_name, v, NULL)) { @@ -5228,16 +5231,14 @@ is_vlan_device (const char *name, shvarFile *parsed) static gboolean is_wifi_device (const char *name, shvarFile *parsed) { - int ifindex; + const NMPlatformLink *pllink; g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (parsed != NULL, FALSE); - ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, name); - if (ifindex == 0) - return FALSE; - - return nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) == NM_LINK_TYPE_WIFI; + pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, name); + return pllink + && pllink->type == NM_LINK_TYPE_WIFI; } static void @@ -5383,7 +5384,7 @@ make_vlan_setting (shvarFile *ifcfg, parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP); parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP); - return g_steal_pointer (&s_vlan); + return NM_SETTING (g_steal_pointer (&s_vlan)); } static NMConnection * 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 49096d26..22c9061b 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -23,7 +23,6 @@ #include "nms-ifcfg-rh-utils.h" #include -#include #include "nm-core-internal.h" #include "NetworkManagerUtils.h" 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 f5be7520..ee7fd161 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -22,11 +22,9 @@ #include "nms-ifcfg-rh-writer.h" -#include #include #include #include -#include #include #include #include @@ -603,6 +601,10 @@ write_wireless_security_setting (NMConnection *connection, svSetValueStr (ifcfg, "KEY_MGMT", "WPA-PSK"); wpa = TRUE; *no_8021x = TRUE; + } else if (!strcmp (key_mgmt, "sae")) { + svSetValueStr (ifcfg, "KEY_MGMT", "SAE"); + wpa = TRUE; + *no_8021x = TRUE; } else if (!strcmp (key_mgmt, "ieee8021x")) { svSetValueStr (ifcfg, "KEY_MGMT", "IEEE8021X"); dynamic_wep = TRUE; diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index fe82fbdd..f3d58e26 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -27,11 +27,9 @@ #include "shvar.h" -#include #include #include #include -#include #include #include #include @@ -215,9 +213,9 @@ _escape_ansic (const char *source) /*****************************************************************************/ -#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', '|', '&', ';', '(', ')', '<', '>') +#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) @@ -330,7 +328,7 @@ _gstr_init (GString **str, const char *value, gsize i) * 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 + * However, due to $'\Ux' escapes, the maximum 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. @@ -453,7 +451,7 @@ svUnescape (const char *value, char **to_free) 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. + /* '\'' and '~' in double quotes 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). @@ -649,7 +647,7 @@ void _nmtst_svFileSetName (shvarFile *s, const char *fileName) { /* changing the file name is not supported for regular - * operation. Only allowed to use in tests, othewise, + * operation. Only allowed to use in tests, otherwise, * the filename is immutable. */ g_free (s->fileName); s->fileName = g_strdup (fileName); @@ -815,7 +813,7 @@ svOpenFileInternal (const char *name, gboolean create, GError **error) g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), "Could not read file '%s': %s", - name, strerror (errsv)); + name, nm_strerror_native (errsv)); return NULL; } @@ -1317,34 +1315,32 @@ svWriteFile (shvarFile *s, int mode, GError **error) FILE *f; int tmpfd; CList *current; + int errsv; if (s->modified) { if (s->fd == -1) s->fd = open (s->fileName, O_WRONLY | O_CREAT | O_CLOEXEC, mode); if (s->fd == -1) { - int errsv = errno; - + errsv = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), "Could not open file '%s' for writing: %s", - s->fileName, strerror (errsv)); + s->fileName, nm_strerror_native (errsv)); return FALSE; } if (ftruncate (s->fd, 0) < 0) { - int errsv = errno; - + errsv = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), "Could not overwrite file '%s': %s", - s->fileName, strerror (errsv)); + s->fileName, nm_strerror_native (errsv)); return FALSE; } tmpfd = fcntl (s->fd, F_DUPFD_CLOEXEC, 0); if (tmpfd == -1) { - int errsv = errno; - + errsv = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), "Internal error writing file '%s': %s", - s->fileName, strerror (errsv)); + s->fileName, nm_strerror_native (errsv)); return FALSE; } f = fdopen (tmpfd, "w"); diff --git a/src/settings/plugins/ifcfg-rh/tests/meson.build b/src/settings/plugins/ifcfg-rh/tests/meson.build index 29bc9699..f65494bb 100644 --- a/src/settings/plugins/ifcfg-rh/tests/meson.build +++ b/src/settings/plugins/ifcfg-rh/tests/meson.build @@ -6,12 +6,12 @@ exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - link_with: libnms_ifcfg_rh_core + link_with: libnms_ifcfg_rh_core, ) test( 'ifcfg-rh/' + test_unit, test_script, timeout: 90, - args: test_args + [exe.full_path()] + args: test_args + [exe.full_path()], ) diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected index a95a58db..ddbd986f 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected @@ -13,6 +13,6 @@ IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy -NAME="Test Write WiFi Band A" +NAME="Test Write Wi-Fi Band A" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected index cf325f35..495a24d3 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected @@ -12,6 +12,6 @@ IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy -NAME="Test Write WiFi Hidden" +NAME="Test Write Wi-Fi Hidden" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected index f3704f10..aec6918a 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected @@ -13,6 +13,6 @@ IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy -NAME="Test Write WiFi MAC always" +NAME="Test Write Wi-Fi MAC always" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected index 005c6179..9d47163f 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected @@ -12,6 +12,6 @@ IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy -NAME="Test Write WiFi MAC default" +NAME="Test Write Wi-Fi MAC default" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected index dff17ef2..43c07ddb 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected @@ -13,6 +13,6 @@ IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy -NAME="Test Write WiFi MAC missing" +NAME="Test Write Wi-Fi MAC missing" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected index 94274cf9..21f2e2de 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected @@ -13,6 +13,6 @@ IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy -NAME="Test Write WiFi MAC never" +NAME="Test Write Wi-Fi MAC never" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae new file mode 100644 index 00000000..68afbe97 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae @@ -0,0 +1,5 @@ +TYPE=Wireless +DEVICE=wlan1 +ESSID=blahblah +MODE=Managed +KEY_MGMT=SAE 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 index a7156e33..2c1b7fb4 100644 --- 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 @@ -6,7 +6,7 @@ # expected. # # Also note that setting NAME will replace the last -# occurance, and delete all previous once. +# occurrence, and delete all previous once. #L1 NAME=l2 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 index 674df840..cf3f45bd 100644 --- 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 @@ -6,7 +6,7 @@ # expected. # # Also note that setting NAME will replace the last -# occurance, and delete all previous once. +# occurrence, and delete all previous once. #L1 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae new file mode 100644 index 00000000..5a9569ed --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae @@ -0,0 +1 @@ +WPA_PSK="The king is dead." diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default b/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default index 9a292679..4347405e 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default @@ -1,4 +1,4 @@ GATEWAYDEV=eth0 -# when devices in IPV6_DEFAULTDEV and IPV6_DEFAULTGW don't match the one in IPV6_DEFAULTGW is prefered +# when devices in IPV6_DEFAULTDEV and IPV6_DEFAULTGW don't match the one in IPV6_DEFAULTGW is preferred IPV6_DEFAULTDEV=eth4 IPV6_DEFAULTGW=2001::1234%eth0 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 472bb8a6..b352fbfc 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -123,7 +122,7 @@ _assert_reread_same_FIXME (NMConnection *connection, NMConnection *reread) /* dummy path for an "expected" file, meaning: don't check for expected * written ifcfg file. */ -static const char const NO_EXPECTED[1]; +static const char NO_EXPECTED[1]; static void _assert_expected_content (NMConnection *connection, const char *filename, const char *expected) @@ -2374,7 +2373,7 @@ test_read_wifi_open (void) g_assert_cmpstr (nm_setting_wireless_get_mode (s_wireless), ==, "infrastructure"); g_assert_cmpint (nm_setting_wireless_get_channel (s_wireless), ==, 1); - /* ===== WiFi SECURITY SETTING ===== */ + /* ===== Wi-Fi SECURITY SETTING ===== */ s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec == NULL); @@ -2966,6 +2965,45 @@ test_read_wifi_wpa_psk (void) g_object_unref (connection); } +static void +test_read_wifi_sae (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + NMSettingWirelessSecurity *s_wsec; + GBytes *ssid; + const char *expected_ssid = "blahblah"; + + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-sae", + 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 blahblah (test-wifi-sae)"); + + g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); + g_assert (nm_setting_connection_get_autoconnect (s_con)); + + s_wireless = nm_connection_get_setting_wireless (connection); + g_assert (s_wireless); + + g_assert_cmpint (nm_setting_wireless_get_mtu (s_wireless), ==, 0); + + 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)); + + g_assert (!nm_setting_wireless_get_bssid (s_wireless)); + g_assert_cmpstr (nm_setting_wireless_get_mode (s_wireless), ==, "infrastructure"); + + s_wsec = nm_connection_get_setting_wireless_security (connection); + g_assert (s_wsec); + g_assert_cmpstr (nm_setting_wireless_security_get_key_mgmt (s_wsec), ==, "sae"); + g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "The king is dead."); + g_assert (!nm_setting_wireless_security_get_auth_alg (s_wsec)); +} + static void test_read_wifi_wpa_psk_2 (void) { @@ -3275,7 +3313,7 @@ test_read_wifi_dynamic_wep_leap (void) s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); - /* ===== WiFi SECURITY SETTING ===== */ + /* ===== Wi-Fi SECURITY SETTING ===== */ s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); @@ -3501,7 +3539,7 @@ test_write_wifi_hidden (void) nm_connection_add_setting (connection, NM_SETTING (s_con)); g_object_set (s_con, - NM_SETTING_CONNECTION_ID, "Test Write WiFi Hidden", + NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Hidden", NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -3584,7 +3622,7 @@ test_write_wifi_mac_random (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - val = g_strdup_printf ("Test Write WiFi MAC %s", name); + val = g_strdup_printf ("Test Write Wi-Fi MAC %s", name); g_object_set (s_con, NM_SETTING_CONNECTION_ID, val, NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), @@ -3803,7 +3841,7 @@ test_write_wifi_band_a (void) nm_connection_add_setting (connection, NM_SETTING (s_con)); g_object_set (s_con, - NM_SETTING_CONNECTION_ID, "Test Write WiFi Band A", + NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Band A", NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -7402,8 +7440,6 @@ test_write_mobile_broadband (gconstpointer data) /* GSM setting */ s_gsm = (NMSettingGsm *) nm_setting_gsm_new (); nm_connection_add_setting (connection, NM_SETTING (s_gsm)); - - g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, "*99#", NULL); } else { /* CDMA setting */ s_cdma = (NMSettingCdma *) nm_setting_cdma_new (); @@ -9983,10 +10019,14 @@ NMTST_DEFINE (); int main (int argc, char **argv) { + int errsv; + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - 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)); + if (g_mkdir_with_parents (TEST_SCRATCH_DIR_TMP, 0755) != 0) { + errsv = errno; + g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR_TMP, nm_strerror_native (errsv)); + } g_test_add_func (TPATH "svUnescape", test_svUnescape); @@ -10083,6 +10123,7 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wifi/read/wpa-psk/unquoted2", test_read_wifi_wpa_psk_unquoted2); g_test_add_func (TPATH "wifi/read/wpa-psk/adhoc", test_read_wifi_wpa_psk_adhoc); g_test_add_func (TPATH "wifi/read/wpa-psk/hex", test_read_wifi_wpa_psk_hex); + g_test_add_func (TPATH "wifi/read/sae", test_read_wifi_sae); g_test_add_func (TPATH "wifi/read/dynamic-wep/leap", test_read_wifi_dynamic_wep_leap); g_test_add_func (TPATH "wifi/read/wpa/eap/tls", test_read_wifi_wpa_eap_tls); g_test_add_func (TPATH "wifi/read/wpa/eap/ttls/tls", test_read_wifi_wpa_eap_ttls_tls); diff --git a/src/settings/plugins/ifupdown/meson.build b/src/settings/plugins/ifupdown/meson.build index 826c7458..42edd438 100644 --- a/src/settings/plugins/ifupdown/meson.build +++ b/src/settings/plugins/ifupdown/meson.build @@ -1,11 +1,11 @@ sources = files( 'nms-ifupdown-interface-parser.c', - 'nms-ifupdown-parser.c' + 'nms-ifupdown-parser.c', ) deps = [ libudev_dep, - nm_dep + nm_dep, ] libnms_ifupdown_core = static_library( @@ -16,7 +16,7 @@ libnms_ifupdown_core = static_library( sources = files( 'nms-ifupdown-connection.c', - 'nms-ifupdown-plugin.c' + 'nms-ifupdown-plugin.c', ) libnm_settings_plugin_ifupdown = shared_module( @@ -27,7 +27,7 @@ libnm_settings_plugin_ifupdown = shared_module( link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, install: true, - install_dir: nm_plugindir + install_dir: nm_plugindir, ) core_plugins += libnm_settings_plugin_ifupdown @@ -37,7 +37,7 @@ core_plugins += libnm_settings_plugin_ifupdown run_target( 'check-local-symbols-settings-ifupdown', command: [check_so_symbols, libnm_settings_plugin_ifupdown.full_path()], - depends: libnm_settings_plugin_ifupdown + depends: libnm_settings_plugin_ifupdown, ) check-local-symbols-settings-ifupdown: src/settings/plugins/ifupdown/libnm-settings-plugin-ifupdown.la diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-connection.c b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c index 1b817044..d06078a9 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-connection.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c @@ -24,7 +24,6 @@ #include "nms-ifupdown-connection.h" -#include #include #include "nm-dbus-interface.h" diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c index 73ecc2f9..6587fc84 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c @@ -26,7 +26,6 @@ #include #include -#include #include #include diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c index 369fa70d..fd5561ae 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -25,10 +25,8 @@ #include "nms-ifupdown-parser.h" -#include #include #include -#include #include #include "nm-core-internal.h" @@ -63,7 +61,7 @@ _ifupdownplugin_guess_connection_type (if_block *block) { const char *ret_type = NULL; - if(nm_streq0 (ifparser_getkey (block, "inet"), "ppp")) + if (nm_streq0 (ifparser_getkey (block, "inet"), "ppp")) ret_type = NM_SETTING_PPP_SETTING_NAME; else { if_data *ifb; @@ -75,7 +73,7 @@ _ifupdownplugin_guess_connection_type (if_block *block) break; } } - if(!ret_type) + if (!ret_type) ret_type = NM_SETTING_WIRED_SETTING_NAME; } diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index f0e64d1d..99a59477 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -26,7 +26,6 @@ #include "nms-ifupdown-plugin.h" -#include #include #include diff --git a/src/settings/plugins/ifupdown/tests/meson.build b/src/settings/plugins/ifupdown/tests/meson.build index 5a2383d9..9b844c75 100644 --- a/src/settings/plugins/ifupdown/tests/meson.build +++ b/src/settings/plugins/ifupdown/tests/meson.build @@ -4,11 +4,11 @@ exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - link_with: libnms_ifupdown_core + link_with: libnms_ifupdown_core, ) test( 'ifupdown/' + test_unit, test_script, - args: test_args + [exe.full_path()] + args: test_args + [exe.full_path()], ) diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index 82ee1c4a..674cb19c 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -20,8 +20,6 @@ #include "nm-default.h" -#include - #include "nm-core-internal.h" #include "settings/plugins/ifupdown/nms-ifupdown-interface-parser.h" diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c index 7511f206..3b362978 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -23,7 +23,6 @@ #include "nms-keyfile-connection.h" -#include #include #include "nm-dbus-interface.h" diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index 346b78c0..c13cc1ff 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -26,8 +26,6 @@ #include #include #include -#include - #include #include "nm-connection.h" @@ -36,6 +34,7 @@ #include "nm-utils.h" #include "nm-config.h" #include "nm-core-internal.h" +#include "nm-keyfile-internal.h" #include "settings/nm-settings-plugin.h" @@ -171,7 +170,6 @@ update_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection_by_uuid; GError *local = NULL; const char *uuid; - int dir_len; g_return_val_if_fail (!source || NM_IS_CONNECTION (source), NULL); g_return_val_if_fail (full_path || source, NULL); @@ -179,17 +177,8 @@ update_connection (NMSKeyfilePlugin *self, if (full_path) _LOGD ("loading from file \"%s\"...", full_path); - if (g_str_has_prefix (full_path, nms_keyfile_utils_get_path ())) { - dir_len = strlen (nms_keyfile_utils_get_path ()); - } else if (g_str_has_prefix (full_path, NM_CONFIG_KEYFILE_PATH_IN_MEMORY)) { - dir_len = NM_STRLEN (NM_CONFIG_KEYFILE_PATH_IN_MEMORY); - } else { - /* Just make sure the file name is not going go pass the following check. */ - dir_len = strlen (full_path); - } - - if ( full_path[dir_len] != '/' - || strchr (full_path + dir_len + 1, '/') != NULL) { + if ( !nm_utils_file_is_in_path (full_path, nms_keyfile_utils_get_path ()) + && !nm_utils_file_is_in_path (full_path, NM_KEYFILE_PATH_NAME_RUN)) { g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "File not in recognized system-connections directory"); return FALSE; @@ -322,7 +311,7 @@ dir_changed (GFileMonitor *monitor, gboolean exists; full_path = g_file_get_path (file); - if (nms_keyfile_utils_should_ignore_file (full_path, FALSE)) { + if (nm_keyfile_utils_ignore_filename (full_path, FALSE)) { g_free (full_path); return; } @@ -444,7 +433,7 @@ _read_dir (GPtrArray *filenames, } while ((item = g_dir_read_name (dir))) { - if (nms_keyfile_utils_should_ignore_file (item, require_extension)) + if (nm_keyfile_utils_ignore_filename (item, require_extension)) continue; g_ptr_array_add (filenames, g_build_filename (path, item, NULL)); } @@ -467,7 +456,7 @@ read_connections (NMSettingsPlugin *config) filenames = g_ptr_array_new_with_free_func (g_free); - _read_dir (filenames, NM_CONFIG_KEYFILE_PATH_IN_MEMORY, TRUE); + _read_dir (filenames, NM_KEYFILE_PATH_NAME_RUN, TRUE); _read_dir (filenames, nms_keyfile_utils_get_path (), FALSE); alive_connections = g_hash_table_new (nm_direct_hash, NULL); @@ -476,7 +465,7 @@ read_connections (NMSettingsPlugin *config) * iterating over the files. * * To have sensible, reproducible behavior, sort the paths by last modification - * time prefering older files. + * time preferring older files. */ paths = _paths_from_connections (priv->connections); g_ptr_array_sort_with_data (filenames, (GCompareDataFunc) _sort_paths, paths); @@ -522,35 +511,6 @@ get_connections (NMSettingsPlugin *config) return _nm_utils_hash_values_to_slist (priv->connections); } -static gboolean -_file_is_in_path (const char *abs_filename, - const char *abs_path) -{ - gsize l; - - /* FIXME: ensure that both paths are at least normalized (coalescing ".", - * duplicate '/', and trailing '/'). */ - - nm_assert (abs_filename && abs_filename[0] == '/'); - nm_assert (abs_path && abs_path[0] == '/'); - - l = strlen (abs_path); - if (strncmp (abs_filename, abs_path, l) != 0) - return FALSE; - - abs_filename += l; - while (abs_filename[0] == '/') - abs_filename++; - - if (!abs_filename[0]) - return FALSE; - - if (strchr (abs_filename, '/')) - return FALSE; - - return TRUE; -} - static gboolean load_connection (NMSettingsPlugin *config, const char *filename) @@ -559,25 +519,14 @@ load_connection (NMSettingsPlugin *config, NMSKeyfileConnection *connection; gboolean require_extension; - /* the test whether to require a file extension tries to figure out whether - * the provided filename is inside /etc or /run. - * - * However, on Posix a filename just resolves to an Inode, and there can - * be any kind of paths that point to the same Inode. It's not generally possible - * to check for that (unless, we would stat all files in the target directory - * and see whether their inode matches). - * - * So, when loading the file do something simpler: require that the path - * starts with the well-known prefix. This rejects symlinks or hard links - * which would actually also point to the same file. */ - if (_file_is_in_path (filename, nms_keyfile_utils_get_path ())) + if (nm_utils_file_is_in_path (filename, nms_keyfile_utils_get_path ())) require_extension = FALSE; - else if (_file_is_in_path (filename, NM_CONFIG_KEYFILE_PATH_IN_MEMORY)) + else if (nm_utils_file_is_in_path (filename, NM_KEYFILE_PATH_NAME_RUN)) require_extension = TRUE; else return FALSE; - if (nms_keyfile_utils_should_ignore_file (filename, require_extension)) + if (nm_keyfile_utils_ignore_filename (filename, require_extension)) return FALSE; connection = update_connection (self, NULL, filename, find_by_path (self, filename), TRUE, NULL, NULL); diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c index 580a857a..5778f13c 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -23,7 +23,6 @@ #include "nms-keyfile-reader.h" #include -#include #include "nm-keyfile-internal.h" @@ -142,11 +141,11 @@ nms_keyfile_reader_from_keyfile (GKeyFile *key_file, if (!connection) return NULL; - if (g_str_has_suffix (filename, NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION)) { + if (g_str_has_suffix (filename, NM_KEYFILE_PATH_SUFFIX_NMCONNECTION)) { gsize l = strlen (filename); - if (l > NM_STRLEN (NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION)) - filename_id = g_strndup (filename, l - NM_STRLEN (NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION)); + if (l > NM_STRLEN (NM_KEYFILE_PATH_SUFFIX_NMCONNECTION)) + filename_id = g_strndup (filename, l - NM_STRLEN (NM_KEYFILE_PATH_SUFFIX_NMCONNECTION)); } nm_keyfile_read_ensure_id (connection, filename_id ?: filename); @@ -172,7 +171,8 @@ nms_keyfile_reader_from_file (const char *full_filename, nm_assert (full_filename && full_filename[0] == '/'); nm_assert (!profile_dir || profile_dir[0] == '/'); - if (!nms_keyfile_utils_check_file_permissions (full_filename, + if (!nms_keyfile_utils_check_file_permissions (NMS_KEYFILE_FILETYPE_KEYFILE, + full_filename, NULL, error)) return NULL; diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c index c3bfcdee..3c4b0288 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -23,111 +23,223 @@ #include "nms-keyfile-utils.h" #include -#include #include +#include "nm-keyfile-internal.h" +#include "nm-utils.h" #include "nm-setting-wired.h" #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" #include "nm-config.h" -#define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections" - /*****************************************************************************/ -static const char temp_letters[] = -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - -/* - * Check '.[a-zA-Z0-9]{6}' file suffix used for temporary files by g_file_set_contents() (mkstemp()). - */ -static gboolean -check_mkstemp_suffix (const char *path) +char * +nms_keyfile_loaded_uuid_filename (const char *dirname, + const char *uuid, + gboolean temporary) { - const char *ptr; - - g_return_val_if_fail (path != NULL, FALSE); + char filename[250]; + + nm_assert (dirname && dirname[0] == '/'); + nm_assert (uuid && nm_utils_is_uuid (uuid) && !strchr (uuid, '/')); + + if (g_snprintf (filename, + sizeof (filename), + "%s%s%s%s", + NM_KEYFILE_PATH_PREFIX_NMLOADED, + uuid, + NM_KEYFILE_PATH_SUFFIX_NMCONNECTION, + temporary ? "~" : "") >= sizeof (filename)) { + /* valid uuids are limited in length. The buffer should always be large + * enough. */ + nm_assert_not_reached (); + return NULL; + } - /* Matches *.[a-zA-Z0-9]{6} suffix of mkstemp()'s temporary files */ - ptr = strrchr (path, '.'); - if (ptr && (strspn (ptr + 1, temp_letters) == 6) && (! ptr[7])) - return TRUE; - return FALSE; + return g_build_filename (dirname, filename, NULL); } -static gboolean -check_prefix_dot (const char *base) +gboolean +nms_keyfile_loaded_uuid_read (const char *dirname, + const char *filename, + char **out_full_filename, + char **out_uuid, + char **out_loaded_path) { - nm_assert (base && base[0]); + const char *uuid; + const char *tmp; + gsize len; + gs_free char *full_filename = NULL; + gs_free char *ln = NULL; + + nm_assert (dirname && dirname[0] == '/'); + nm_assert (filename && filename[0] && !strchr (filename, '/')); + + if (filename[0] != '.') { + /* the hidden-uuid filename must start with '.'. That is, + * so that it does not conflict with regular keyfiles according + * to nm_keyfile_utils_ignore_filename(). */ + return FALSE; + } + + len = strlen (filename); + if ( len <= NM_STRLEN (NM_KEYFILE_PATH_PREFIX_NMLOADED) + || memcmp (filename, NM_KEYFILE_PATH_PREFIX_NMLOADED, NM_STRLEN (NM_KEYFILE_PATH_PREFIX_NMLOADED)) != 0) { + /* the filename does not have the right prefix. */ + return FALSE; + } + + tmp = &filename[NM_STRLEN (NM_KEYFILE_PATH_PREFIX_NMLOADED)]; + len -= NM_STRLEN (NM_KEYFILE_PATH_PREFIX_NMLOADED); + + if ( len <= NM_STRLEN (NM_KEYFILE_PATH_SUFFIX_NMCONNECTION) + || memcmp (&tmp[len - NM_STRLEN (NM_KEYFILE_PATH_SUFFIX_NMCONNECTION)], + NM_KEYFILE_PATH_SUFFIX_NMCONNECTION, + NM_STRLEN (NM_KEYFILE_PATH_SUFFIX_NMCONNECTION)) != 0) { + /* the file does not have the right suffix. */ + return FALSE; + } + len -= NM_STRLEN (NM_KEYFILE_PATH_SUFFIX_NMCONNECTION); + + if (!NM_IN_SET (len, 36, 40)) { + /* the remaining part of the filename has not the right length to + * contain a UUID (according to nm_utils_is_uuid()). */ + return FALSE; + } + + uuid = nm_strndup_a (100, tmp, len, NULL); + if (!nm_utils_is_uuid (uuid)) + return FALSE; - return base[0] == '.'; + full_filename = g_build_filename (dirname, filename, NULL); + + if (!nms_keyfile_utils_check_file_permissions (NMS_KEYFILE_FILETYPE_NMLOADED, + full_filename, + NULL, + NULL)) + return FALSE; + + ln = nm_utils_read_link_absolute (full_filename, NULL); + if (!ln) + return FALSE; + + NM_SET_OUT (out_uuid, g_strdup (uuid)); + NM_SET_OUT (out_full_filename, g_steal_pointer (&full_filename)); + NM_SET_OUT (out_loaded_path, g_steal_pointer (&ln)); + return TRUE; } -static gboolean -check_suffix (const char *base, const char *tag) +gboolean +nms_keyfile_loaded_uuid_read_from_file (const char *full_filename, + char **out_dirname, + char **out_filename, + char **out_uuid, + char **out_loaded_path) { - int len, tag_len; + gs_free char *dirname = NULL; + gs_free char *filename = NULL; - g_return_val_if_fail (base != NULL, TRUE); - g_return_val_if_fail (tag != NULL, TRUE); + nm_assert (full_filename && full_filename[0] == '/'); - len = strlen (base); - tag_len = strlen (tag); - if ((len > tag_len) && !g_ascii_strcasecmp (base + len - tag_len, tag)) - return TRUE; - return FALSE; -} + filename = g_path_get_basename (full_filename); + dirname = g_path_get_dirname (full_filename); -#define SWP_TAG ".swp" -#define SWPX_TAG ".swpx" -#define PEM_TAG ".pem" -#define DER_TAG ".der" + if (!nms_keyfile_loaded_uuid_read (dirname, + filename, + NULL, + out_uuid, + out_loaded_path)) + return FALSE; + + NM_SET_OUT (out_dirname, g_steal_pointer (&dirname)); + NM_SET_OUT (out_filename, g_steal_pointer (&filename)); + return TRUE; +} gboolean -nms_keyfile_utils_should_ignore_file (const char *filename, gboolean require_extension) +nms_keyfile_loaded_uuid_write (const char *dirname, + const char *uuid, + const char *loaded_path, + gboolean allow_relative, + char **out_full_filename) { - gs_free char *base = NULL; - - g_return_val_if_fail (filename != NULL, TRUE); - - base = g_path_get_basename (filename); - g_return_val_if_fail (base != NULL, TRUE); - - /* Ignore hidden and backup files */ - /* should_ignore_file() must mirror escape_filename() */ - if (check_prefix_dot (base) || check_suffix (base, "~")) - return TRUE; - /* Ignore temporary files */ - if (check_mkstemp_suffix (base)) - return TRUE; - /* Ignore 802.1x certificates and keys */ - if (check_suffix (base, PEM_TAG) || check_suffix (base, DER_TAG)) - return TRUE; - - if (require_extension) { - gsize l = strlen (base); - - if ( l <= NM_STRLEN (NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION) - || !g_str_has_suffix (base, NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION)) - return TRUE; + gs_free char *full_filename_tmp = NULL; + gs_free char *full_filename = NULL; + + nm_assert (dirname && dirname[0] == '/'); + nm_assert (uuid && nm_utils_is_uuid (uuid) && !strchr (uuid, '/')); + nm_assert (!loaded_path || loaded_path[0] == '/'); + + full_filename_tmp = nms_keyfile_loaded_uuid_filename (dirname, uuid, TRUE); + + nm_assert (g_str_has_suffix (full_filename_tmp, "~")); + nm_assert (nm_utils_file_is_in_path (full_filename_tmp, dirname)); + + (void) unlink (full_filename_tmp); + + if (!loaded_path) { + gboolean success = TRUE; + + full_filename_tmp[strlen (full_filename_tmp) - 1] = '\0'; + if (unlink (full_filename_tmp) != 0) + success = NM_IN_SET (errno, ENOENT); + NM_SET_OUT (out_full_filename, g_steal_pointer (&full_filename_tmp)); + return success; + } + + if (allow_relative) { + const char *f; + + f = nm_utils_file_is_in_path (loaded_path, dirname); + if (f) { + /* @loaded_path points to a file directly in @dirname. + * Don't use absolute paths. */ + loaded_path = f; + } + } + + if (symlink (loaded_path, full_filename_tmp) != 0) { + full_filename_tmp[strlen (full_filename_tmp) - 1] = '\0'; + NM_SET_OUT (out_full_filename, g_steal_pointer (&full_filename_tmp)); + return FALSE; } - return FALSE; + full_filename = g_strdup (full_filename_tmp); + full_filename[strlen (full_filename) - 1] = '\0'; + if (rename (full_filename_tmp, full_filename) != 0) { + (void) unlink (full_filename_tmp); + NM_SET_OUT (out_full_filename, g_steal_pointer (&full_filename)); + return FALSE; + } + + NM_SET_OUT (out_full_filename, g_steal_pointer (&full_filename)); + return TRUE; } /*****************************************************************************/ gboolean -nms_keyfile_utils_check_file_permissions_stat (const struct stat *st, +nms_keyfile_utils_check_file_permissions_stat (NMSKeyfileFiletype filetype, + const struct stat *st, GError **error) { g_return_val_if_fail (st, FALSE); - if (!S_ISREG (st->st_mode)) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "file is not a regular file"); - return FALSE; - } + if (filetype == NMS_KEYFILE_FILETYPE_KEYFILE) { + if (!S_ISREG (st->st_mode)) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "file is not a regular file"); + return FALSE; + } + } else if (filetype == NMS_KEYFILE_FILETYPE_NMLOADED) { + if (!S_ISLNK (st->st_mode)) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "file is not a slink"); + return FALSE; + } + } else + g_return_val_if_reached (FALSE); if (!NM_FLAGS_HAS (nm_utils_get_testing (), NM_UTILS_TEST_NO_KEYFILE_OWNER_CHECK)) { if (st->st_uid != 0) { @@ -137,7 +249,8 @@ nms_keyfile_utils_check_file_permissions_stat (const struct stat *st, return FALSE; } - if (st->st_mode & 0077) { + if ( filetype == NMS_KEYFILE_FILETYPE_KEYFILE + && (st->st_mode & 0077)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "File permissions (%03o) are insecure", st->st_mode); @@ -149,7 +262,8 @@ nms_keyfile_utils_check_file_permissions_stat (const struct stat *st, } gboolean -nms_keyfile_utils_check_file_permissions (const char *filename, +nms_keyfile_utils_check_file_permissions (NMSKeyfileFiletype filetype, + const char *filename, struct stat *out_st, GError **error) { @@ -158,14 +272,24 @@ nms_keyfile_utils_check_file_permissions (const char *filename, g_return_val_if_fail (filename && filename[0] == '/', FALSE); - if (stat (filename, &st) != 0) { - errsv = errno; - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "cannot access file: %s", g_strerror (errsv)); - return FALSE; - } + if (filetype == NMS_KEYFILE_FILETYPE_KEYFILE) { + if (stat (filename, &st) != 0) { + errsv = errno; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "cannot access file: %s", nm_strerror_native (errsv)); + return FALSE; + } + } else if (filetype == NMS_KEYFILE_FILETYPE_NMLOADED) { + if (lstat (filename, &st) != 0) { + errsv = errno; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "cannot access file: %s", nm_strerror_native (errsv)); + return FALSE; + } + } else + g_return_val_if_reached (FALSE); - if (!nms_keyfile_utils_check_file_permissions_stat (&st, error)) + if (!nms_keyfile_utils_check_file_permissions_stat (filetype, &st, error)) return FALSE; NM_SET_OUT (out_st, st); @@ -174,50 +298,6 @@ nms_keyfile_utils_check_file_permissions (const char *filename, /*****************************************************************************/ -char * -nms_keyfile_utils_escape_filename (const char *filename, - gboolean with_extension) -{ - GString *str; - const char *f = filename; - /* keyfile used to escape with '*', do not change that behavior. - * - * But for newly added escapings, use '_' instead. - * Also, @with_extension is new-style. */ - const char ESCAPE_CHAR = with_extension ? '_' : '*'; - const char ESCAPE_CHAR2 = '_'; - - g_return_val_if_fail (filename && filename[0], NULL); - - str = g_string_sized_new (60); - - /* Convert '/' to ESCAPE_CHAR */ - for (f = filename; f[0]; f++) { - if (f[0] == '/') - g_string_append_c (str, ESCAPE_CHAR); - else - g_string_append_c (str, f[0]); - } - - /* escape_filename() must avoid anything that should_ignore_file() would reject. - * We can escape here more aggressivly then what we would read back. */ - if (check_prefix_dot (str->str)) - str->str[0] = ESCAPE_CHAR2; - if (check_suffix (str->str, "~")) - str->str[str->len - 1] = ESCAPE_CHAR2; - if ( check_mkstemp_suffix (str->str) - || check_suffix (str->str, PEM_TAG) - || check_suffix (str->str, DER_TAG)) - g_string_append_c (str, ESCAPE_CHAR2); - - if (with_extension) - g_string_append (str, NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION); - - return g_string_free (str, FALSE);; -} - -/*****************************************************************************/ - const char * nms_keyfile_utils_get_path (void) { @@ -229,7 +309,7 @@ nms_keyfile_utils_get_path (void) NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH, NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY); if (!path) - path = g_strdup (""NM_CONFIG_KEYFILE_PATH_DEFAULT""); + path = g_strdup (""NM_KEYFILE_PATH_NAME_ETC_DEFAULT""); } return path; } diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h index 297dd4ea..bc601dad 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.h +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h @@ -23,27 +23,52 @@ #include "NetworkManagerUtils.h" -#define NM_CONFIG_KEYFILE_PATH_IN_MEMORY NMRUNDIR "/system-connections" - -#define NMS_KEYFILE_PATH_SUFFIX_NMCONNECTION ".nmconnection" - #define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") #define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")" #define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)) #define NMS_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" #define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)), (con) -gboolean nms_keyfile_utils_should_ignore_file (const char *filename, gboolean require_extension); - -char *nms_keyfile_utils_escape_filename (const char *filename, gboolean with_extension); +typedef enum { + NMS_KEYFILE_FILETYPE_KEYFILE, + NMS_KEYFILE_FILETYPE_NMLOADED, +} NMSKeyfileFiletype; const char *nms_keyfile_utils_get_path (void); +/*****************************************************************************/ + +char *nms_keyfile_loaded_uuid_filename (const char *dirname, + const char *uuid, + gboolean temporary); + +gboolean nms_keyfile_loaded_uuid_read (const char *dirname, + const char *filename, + char **out_full_filename, + char **out_uuid, + char **out_loaded_path); + +gboolean nms_keyfile_loaded_uuid_read_from_file (const char *full_filename, + char **out_dirname, + char **out_filename, + char **out_uuid, + char **out_loaded_path); + +gboolean nms_keyfile_loaded_uuid_write (const char *dirname, + const char *uuid, + const char *loaded_path, + gboolean allow_relative, + char **out_full_filename); + +/*****************************************************************************/ + struct stat; -gboolean nms_keyfile_utils_check_file_permissions_stat (const struct stat *st, +gboolean nms_keyfile_utils_check_file_permissions_stat (NMSKeyfileFiletype filetype, + const struct stat *st, GError **error); -gboolean nms_keyfile_utils_check_file_permissions (const char *filename, +gboolean nms_keyfile_utils_check_file_permissions (NMSKeyfileFiletype filetype, + const char *filename, struct stat *out_st, GError **error); diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index df26ea60..8c75d8c7 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include "nm-keyfile-internal.h" @@ -177,27 +175,30 @@ _internal_write_connection (NMConnection *connection, uid_t owner_uid, pid_t owner_grp, const char *existing_path, + gboolean existing_path_read_only, gboolean force_rename, char **out_path, NMConnection **out_reread, gboolean *out_reread_same, GError **error) { - gs_unref_keyfile GKeyFile *key_file = NULL; - gs_free char *data = NULL; - gsize len; + gs_unref_keyfile GKeyFile *kf_file = NULL; + gs_free char *kf_content_buf = NULL; + gsize kf_content_len; gs_free char *path = NULL; const char *id; WriteInfo info = { 0 }; GError *local_err = NULL; int errsv; - gboolean rename = force_rename; + gboolean rename; g_return_val_if_fail (!out_path || !*out_path, FALSE); g_return_val_if_fail (keyfile_dir && keyfile_dir[0] == '/', FALSE); - if (existing_path && !g_str_has_prefix (existing_path, keyfile_dir)) - rename = TRUE; + rename = force_rename + || existing_path_read_only + || ( existing_path + && !nm_utils_file_is_in_path (existing_path, keyfile_dir)); switch (_nm_connection_verify (connection, error)) { case NM_SETTING_VERIFY_NORMALIZABLE: @@ -214,11 +215,11 @@ _internal_write_connection (NMConnection *connection, info.keyfile_dir = keyfile_dir; - key_file = nm_keyfile_write (connection, _handler_write, &info, error); - if (!key_file) + kf_file = nm_keyfile_write (connection, _handler_write, &info, error); + if (!kf_file) return FALSE; - data = g_key_file_to_data (key_file, &len, error); - if (!data) + kf_content_buf = g_key_file_to_data (kf_file, &kf_content_len, error); + if (!kf_content_buf) return FALSE; if (!g_file_test (keyfile_dir, G_FILE_TEST_IS_DIR)) @@ -227,13 +228,14 @@ _internal_write_connection (NMConnection *connection, /* If we have existing file path, use it. Else generate one from * connection's ID. */ - if (existing_path != NULL && !rename) { + if ( existing_path + && !rename) path = g_strdup (existing_path); - } else { - char *filename_escaped = nms_keyfile_utils_escape_filename (id, with_extension); + else { + gs_free char *filename_escaped = NULL; + filename_escaped = nm_keyfile_utils_create_filename (id, with_extension); path = g_build_filename (keyfile_dir, filename_escaped, NULL); - g_free (filename_escaped); } /* If a file with this path already exists (but isn't the existing path @@ -243,32 +245,34 @@ _internal_write_connection (NMConnection *connection, * there's a race here, but there's not a lot we can do about it, and * we shouldn't get more than one connection with the same UUID either. */ - if (g_strcmp0 (path, existing_path) != 0 && g_file_test (path, G_FILE_TEST_EXISTS)) { + if ( !nm_streq0 (path, existing_path) + && g_file_test (path, G_FILE_TEST_EXISTS)) { guint i; gboolean name_found = FALSE; /* A keyfile with this connection's ID already exists. Pick another name. */ for (i = 0; i < 100; i++) { - char *filename, *filename_escaped; + gs_free char *filename_escaped = NULL; + gs_free char *filename = NULL; if (i == 0) filename = g_strdup_printf ("%s-%s", id, nm_connection_get_uuid (connection)); else filename = g_strdup_printf ("%s-%s-%u", id, nm_connection_get_uuid (connection), i); - filename_escaped = nms_keyfile_utils_escape_filename (filename, with_extension); + filename_escaped = nm_keyfile_utils_create_filename (filename, with_extension); g_free (path); path = g_strdup_printf ("%s/%s", keyfile_dir, filename_escaped); - g_free (filename); - g_free (filename_escaped); - if (g_strcmp0 (path, existing_path) == 0 || !g_file_test (path, G_FILE_TEST_EXISTS)) { + + if ( nm_streq0 (path, existing_path) + || !g_file_test (path, G_FILE_TEST_EXISTS)) { name_found = TRUE; break; } } if (!name_found) { - if (existing_path == NULL) { + if (existing_path_read_only || !existing_path) { /* this really should not happen, we tried hard to find an unused name... bail out. */ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "could not find suitable keyfile file name (%s already used)", path); @@ -281,13 +285,7 @@ _internal_write_connection (NMConnection *connection, } } - /* In case of updating the connection and changing the file path, - * we need to remove the old one, not to end up with two connections. - */ - if (existing_path != NULL && strcmp (path, existing_path) != 0) - unlink (existing_path); - - nm_utils_file_set_contents (path, data, len, 0600, &local_err); + nm_utils_file_set_contents (path, kf_content_buf, kf_content_len, 0600, &local_err); if (local_err) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "error writing to file '%s': %s", @@ -300,17 +298,24 @@ _internal_write_connection (NMConnection *connection, errsv = errno; g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "error chowning '%s': %s (%d)", - path, g_strerror (errsv), errsv); + path, nm_strerror_native (errsv), errsv); unlink (path); return FALSE; } - if (out_reread || out_reread_same) - { + /* In case of updating the connection and changing the file path, + * we need to remove the old one, not to end up with two connections. + */ + if ( existing_path + && !existing_path_read_only + && !nm_streq (path, existing_path)) + unlink (existing_path); + + if (out_reread || out_reread_same) { gs_unref_object NMConnection *reread = NULL; gboolean reread_same = FALSE; - reread = nms_keyfile_reader_from_keyfile (key_file, path, NULL, profile_dir, FALSE, NULL); + reread = nms_keyfile_reader_from_keyfile (kf_file, path, NULL, profile_dir, FALSE, NULL); nm_assert (NM_IS_CONNECTION (reread)); @@ -356,7 +361,7 @@ nms_keyfile_writer_connection (NMConnection *connection, if (save_to_disk) keyfile_dir = nms_keyfile_utils_get_path (); else - keyfile_dir = NM_CONFIG_KEYFILE_PATH_IN_MEMORY; + keyfile_dir = NM_KEYFILE_PATH_NAME_RUN; return _internal_write_connection (connection, keyfile_dir, @@ -365,6 +370,7 @@ nms_keyfile_writer_connection (NMConnection *connection, 0, 0, existing_path, + FALSE, force_rename, out_path, out_reread, @@ -390,6 +396,7 @@ nms_keyfile_writer_test_connection (NMConnection *connection, owner_grp, NULL, FALSE, + FALSE, out_path, out_reread, out_reread_same, diff --git a/src/settings/plugins/keyfile/tests/meson.build b/src/settings/plugins/keyfile/tests/meson.build index 8b94b256..752b6d7b 100644 --- a/src/settings/plugins/keyfile/tests/meson.build +++ b/src/settings/plugins/keyfile/tests/meson.build @@ -11,5 +11,6 @@ exe = executable( test( 'keyfile/' + test_unit, test_script, - args: test_args + [exe.full_path()] + args: test_args + [exe.full_path()], + timeout: default_test_timeout, ) diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index 4a0e01b3..baecac13 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -1177,7 +1176,6 @@ test_write_bt_dun_connection (void) NM_SETTING_GSM_APN, "internet2.voicestream.com", NM_SETTING_GSM_USERNAME, "george.clinton", NM_SETTING_GSM_PASSWORD, "parliament", - NM_SETTING_GSM_NUMBER, "*99#", NULL); write_test_connection_and_reread (connection, TRUE); @@ -1259,7 +1257,6 @@ test_write_gsm_connection (void) NM_SETTING_GSM_APN, "internet2.voicestream.com", NM_SETTING_GSM_USERNAME, "george.clinton.again", NM_SETTING_GSM_PASSWORD, "parliament2", - NM_SETTING_GSM_NUMBER, "*99#", NM_SETTING_GSM_PIN, "123456", NM_SETTING_GSM_NETWORK_ID, "254098", NM_SETTING_GSM_HOME_ONLY, TRUE, @@ -2073,7 +2070,7 @@ test_write_new_wireless_group_names (void) NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* WiFi setting */ + /* Wi-Fi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); @@ -2084,7 +2081,7 @@ test_write_new_wireless_group_names (void) NULL); g_bytes_unref (ssid); - /* WiFi security setting */ + /* Wi-Fi security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -2333,7 +2330,6 @@ test_write_flags_property (void) s_gsm = nm_setting_gsm_new (); nm_connection_add_setting (connection, s_gsm); g_object_set (s_gsm, - NM_SETTING_GSM_NUMBER, "#99*", NM_SETTING_GSM_APN, "myapn", NM_SETTING_GSM_USERNAME, "adfasdfasdf", NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED, @@ -2466,18 +2462,18 @@ _escape_filename (gboolean with_extension, const char *filename, gboolean would_ g_assert (filename && filename[0]); - if (!!would_be_ignored != !!nms_keyfile_utils_should_ignore_file (filename, with_extension)) { + if (!!would_be_ignored != !!nm_keyfile_utils_ignore_filename (filename, with_extension)) { if (would_be_ignored) g_error ("We expect filename \"%s\" to be ignored, but it isn't", filename); else g_error ("We expect filename \"%s\" not to be ignored, but it is", filename); } - esc = nms_keyfile_utils_escape_filename (filename, with_extension); + esc = nm_keyfile_utils_create_filename (filename, with_extension); g_assert (esc && esc[0]); g_assert (!strchr (esc, '/')); - if (nms_keyfile_utils_should_ignore_file (esc, with_extension)) + if (nm_keyfile_utils_ignore_filename (esc, with_extension)) g_error ("Escaping filename \"%s\" yielded \"%s\", but this is ignored", filename, esc); } @@ -2503,21 +2499,131 @@ test_nm_keyfile_plugin_utils_escape_filename (void) _escape_filename (FALSE, ".#emacs-locking", TRUE); _escape_filename (FALSE, "file-with-tilde~", TRUE); _escape_filename (FALSE, ".file-with-dot", TRUE); + _escape_filename (FALSE, "/some/path/with/trailing/slash/", TRUE); + _escape_filename (FALSE, "/some/path/without/trailing/slash", FALSE); _escape_filename (TRUE, "lala", TRUE); } /*****************************************************************************/ +static void +_assert_keyfile_loaded_uuid (const char *dirname, + const char *uuid, + const char *loaded_path, + gboolean allow_relative, + const char *exp_full_filename, + const char *exp_uuid, + const char *exp_symlink_target, + const char *exp_loaded_path) +{ + gs_free char *full_filename = NULL; + gs_free char *symlink_target = NULL; + gs_free char *uuid2 = NULL; + gs_free char *loaded_path2 = NULL; + gs_free char *dirname3 = NULL; + gs_free char *filename3 = NULL; + gs_free char *uuid3 = NULL; + gs_free char *loaded_path3 = NULL; + gboolean success; + gs_free char *filename = NULL; + + g_assert (dirname && dirname[0] == '/'); + g_assert (exp_full_filename && exp_full_filename[0]); + g_assert (!exp_loaded_path || exp_loaded_path[0] == '/'); + + filename = g_path_get_basename (exp_full_filename); + + full_filename = nms_keyfile_loaded_uuid_filename (dirname, uuid, FALSE); + g_assert_cmpstr (full_filename, ==, full_filename); + nm_clear_g_free (&full_filename); + + + g_assert (nms_keyfile_loaded_uuid_write (dirname, uuid, loaded_path, allow_relative, &full_filename)); + g_assert_cmpstr (full_filename, ==, exp_full_filename); + nm_clear_g_free (&full_filename); + + if (exp_symlink_target) + g_assert (g_file_test (exp_full_filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK)); + else + g_assert (!g_file_test (exp_full_filename, G_FILE_TEST_EXISTS)); + symlink_target = g_file_read_link (exp_full_filename, NULL); + g_assert_cmpstr (symlink_target, ==, exp_symlink_target); + + + success = nms_keyfile_loaded_uuid_read (dirname, filename, &full_filename, &uuid2, &loaded_path2); + g_assert_cmpint (!!exp_uuid, ==, success); + if (success) + g_assert_cmpstr (full_filename, ==, exp_full_filename); + else + g_assert_cmpstr (full_filename, ==, NULL); + nm_clear_g_free (&full_filename); + g_assert_cmpstr (uuid2, ==, exp_uuid); + g_assert_cmpstr (loaded_path2, ==, exp_loaded_path); + + + success = nms_keyfile_loaded_uuid_read_from_file (exp_full_filename, &dirname3, &filename3, &uuid3, &loaded_path3); + g_assert_cmpint (!!exp_uuid, ==, success); + if (success) { + g_assert_cmpstr (dirname3, ==, dirname); + g_assert_cmpstr (filename3, ==, filename); + } else { + g_assert_cmpstr (dirname3, ==, NULL); + g_assert_cmpstr (filename3, ==, NULL); + } + g_assert_cmpstr (uuid3, ==, exp_uuid); + g_assert_cmpstr (loaded_path3, ==, exp_loaded_path); +} + +static void +test_loaded_uuid (void) +{ + const char *uuid = "3c03fd17-ddc3-4100-a954-88b6fafff959"; + gs_free char *filename = g_strdup_printf ("%s%s%s", + NM_KEYFILE_PATH_PREFIX_NMLOADED, + uuid, + NM_KEYFILE_PATH_SUFFIX_NMCONNECTION); + gs_free char *full_filename = g_strdup_printf ("%s/%s", + TEST_SCRATCH_DIR, + filename); + const char *loaded_path0 = NM_KEYFILE_PATH_NMLOADED_NULL; + const char *loaded_path1 = "/some/where/but/not/scratch/dir"; + const char *filename2 = "foo1"; + gs_free char *loaded_path2 = g_strdup_printf ("%s/%s", + TEST_SCRATCH_DIR, + filename2); + + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, NULL, FALSE, full_filename, NULL, NULL, NULL); + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, NULL, TRUE, full_filename, NULL, NULL, NULL); + + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, loaded_path0, FALSE, full_filename, uuid, loaded_path0, loaded_path0); + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, loaded_path0, TRUE, full_filename, uuid, loaded_path0, loaded_path0); + + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, loaded_path1, FALSE, full_filename, uuid, loaded_path1, loaded_path1); + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, loaded_path1, TRUE, full_filename, uuid, loaded_path1, loaded_path1); + + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, loaded_path2, FALSE, full_filename, uuid, loaded_path2, loaded_path2); + _assert_keyfile_loaded_uuid (TEST_SCRATCH_DIR, uuid, loaded_path2, TRUE, full_filename, uuid, filename2, loaded_path2); + + (void) unlink (full_filename); +} + +/*****************************************************************************/ + NMTST_DEFINE (); int main (int argc, char **argv) { + int errsv; + _nm_utils_set_testing (NM_UTILS_TEST_NO_KEYFILE_OWNER_CHECK); + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - if (g_mkdir_with_parents (TEST_SCRATCH_DIR, 0755) != 0) - g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR, g_strerror (errno)); + if (g_mkdir_with_parents (TEST_SCRATCH_DIR, 0755) != 0) { + errsv = errno; + g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR, nm_strerror_native (errsv)); + } /* The tests */ g_test_add_func ("/keyfile/test_read_valid_wired_connection", test_read_valid_wired_connection); @@ -2591,6 +2697,7 @@ int main (int argc, char **argv) g_test_add_func ("/keyfile/test_nm_keyfile_plugin_utils_escape_filename", test_nm_keyfile_plugin_utils_escape_filename); + g_test_add_func ("/keyfile/test_loaded_uuid", test_loaded_uuid); + return g_test_run (); } - -- cgit 1.3.0-6-gf8a5 From 85563b7fc7ec2cd21e38debb9b28db342e2e8e7c Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Sun, 21 Apr 2019 21:09:51 +0200 Subject: New upstream version 1.18.0 --- src/settings/nm-agent-manager.c | 2 +- src/settings/nm-settings-connection.c | 2 +- src/settings/nm-settings.c | 12 +- src/settings/plugins/README | 33 -- src/settings/plugins/ibft/nms-ibft-plugin.c | 23 +- src/settings/plugins/ibft/nms-ibft-reader.c | 66 ++-- src/settings/plugins/ibft/nms-ibft-reader.h | 8 + src/settings/plugins/ibft/tests/test-ibft.c | 17 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 2 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 401 +++++++++++++-------- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 2 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 164 ++++++++- src/settings/plugins/ifcfg-rh/shvar.c | 79 +++- src/settings/plugins/ifcfg-rh/shvar.h | 8 + .../ifcfg-Test_Write_Bridge_Component.cexpected | 1 + .../ifcfg-Test_Write_Routing_Rules.cexpected | 19 + .../tests/network-scripts/ifcfg-test-bridge-main | 2 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 130 ++++++- .../plugins/ifupdown/nms-ifupdown-parser.c | 32 +- .../plugins/ifupdown/nms-ifupdown-plugin.c | 12 +- src/settings/plugins/keyfile/nms-keyfile-writer.c | 2 +- 21 files changed, 710 insertions(+), 307 deletions(-) delete mode 100644 src/settings/plugins/README create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected (limited to 'src/settings') diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 8924c39f..814dee85 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -24,7 +24,7 @@ #include -#include "nm-common-macros.h" +#include "nm-libnm-core-intern/nm-common-macros.h" #include "nm-dbus-interface.h" #include "nm-secret-agent.h" #include "nm-auth-utils.h" diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 8d1f9583..3fdaa598 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -25,7 +25,7 @@ #include "c-list/src/c-list.h" -#include "nm-common-macros.h" +#include "nm-libnm-core-intern/nm-common-macros.h" #include "nm-config.h" #include "nm-config-data.h" #include "nm-dbus-interface.h" diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index fd1d316a..8e18a33e 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -36,7 +36,7 @@ #include #endif -#include "nm-common-macros.h" +#include "nm-libnm-core-intern/nm-common-macros.h" #include "nm-dbus-interface.h" #include "nm-connection.h" #include "nm-setting-8021x.h" @@ -60,7 +60,7 @@ #include "nm-utils.h" #include "nm-core-internal.h" -#include "nm-utils/nm-c-list.h" +#include "nm-glib-aux/nm-c-list.h" #include "nm-dbus-object.h" #include "devices/nm-device-ethernet.h" #include "nm-settings-connection.h" @@ -1138,7 +1138,7 @@ pk_add_cb (NMAuthChain *chain, NMAuthCallResult result; GError *error = NULL; NMConnection *connection = NULL; - NMSettingsConnection *added = NULL; + gs_unref_object NMSettingsConnection *added = NULL; NMSettingsAddCallback callback; gpointer callback_data; NMAuthSubject *subject; @@ -1169,6 +1169,12 @@ pk_add_cb (NMAuthChain *chain, save_to_disk = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "save-to-disk")); added = nm_settings_add_connection (self, connection, save_to_disk, &error); + + /* The callback may remove the connection from the settings manager (e.g. + * because it's found to be incompatible with the device on AddAndActivate). + * But we need to keep it alive for a bit longer, precisely to check wehther + * it's still known to the setting manager. */ + g_object_ref (added); } callback = nm_auth_chain_get_data (chain, "callback"); diff --git a/src/settings/plugins/README b/src/settings/plugins/README deleted file mode 100644 index 307d0bb1..00000000 --- a/src/settings/plugins/README +++ /dev/null @@ -1,33 +0,0 @@ -Plugins generally have three components: - -1) plugin object: manages the individual "connections", which are - just objects wrapped around on-disk config data. The plugin handles requests - to add new connections via the NM D-Bus API, and also watches config - directories for changes to configuration data. Plugins implement the - NMSettingsPlugin interface. See plugin.c. - -2) "connections": subclasses of NMSettingsConnection. They handle updates to - configuration data, deletion, etc. See NMKeyfileConnection. - -3) reader/writer code: typically a separate static library that gets linked - into the main plugin shared object, so they can be unit tested separately - from the plugin. This code should read config data from disk and create - an NMConnection from it, and be capable of taking an NMConnection and writing - out appropriate configuration data to disk. - -NM will first call the "factory" function that every module must provide, which -is nm_settings_plugin_factory(). That function creates and returns a singleton -instance of the plugin's main object, which implements NMSettingsPlugin. -That interface is implemented via the object definition in G_DEFINE_TYPE_EXTENDED -in plugin.c, which registers the interface setup function -settings_plugin_interface_init(), which when called actually sets up the vtables -for the functions defined by NMSettingsPluginInterface. Thus there are two -entry points into the plugin: nm_settings_plugin_factory() and -the NMSettingsPluginInterface methods. - -The plugin also emits various signals (defined by NMSettingsPluginInterface) -which NetworkManager listens for. These include notifications of new -connections if they were created via changes to the on-disk files. The -"connection" objects can also emit signals (defined by the NMSettingsConnection -and NMConnection superclasses) when the connections' backing storage gets -changed or deleted. diff --git a/src/settings/plugins/ibft/nms-ibft-plugin.c b/src/settings/plugins/ibft/nms-ibft-plugin.c index 00b25068..47051995 100644 --- a/src/settings/plugins/ibft/nms-ibft-plugin.c +++ b/src/settings/plugins/ibft/nms-ibft-plugin.c @@ -64,31 +64,30 @@ static void read_connections (NMSIbftPlugin *self) { NMSIbftPluginPrivate *priv = NMS_IBFT_PLUGIN_GET_PRIVATE (self); - GSList *blocks = NULL, *iter; - GError *error = NULL; + nm_auto_free_ibft_blocks GSList *blocks = NULL; + GSList *iter; + gs_free_error GError *error = NULL; NMSIbftConnection *connection; if (!nms_ibft_reader_load_blocks ("/sbin/iscsiadm", &blocks, &error)) { nm_log_dbg (LOGD_SETTINGS, "ibft: failed to read iscsiadm records: %s", error->message); - g_error_free (error); return; } for (iter = blocks; iter; iter = iter->next) { connection = nms_ibft_connection_new (iter->data, &error); - if (connection) { - nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'", - nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (connection))); - g_hash_table_insert (priv->connections, - g_strdup (nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection))), - connection); - } else { + if (!connection) { nm_log_warn (LOGD_SETTINGS, "ibft: failed to read iscsiadm record: %s", error->message); g_clear_error (&error); + continue; } - } - g_slist_free_full (blocks, (GDestroyNotify) g_ptr_array_unref); + nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'", + nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (connection))); + g_hash_table_insert (priv->connections, + g_strdup (nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection))), + connection); + } } static GSList * diff --git a/src/settings/plugins/ibft/nms-ibft-reader.c b/src/settings/plugins/ibft/nms-ibft-reader.c index c6c14376..fde30383 100644 --- a/src/settings/plugins/ibft/nms-ibft-reader.c +++ b/src/settings/plugins/ibft/nms-ibft-reader.c @@ -46,8 +46,7 @@ remove_most_whitespace (const char *src) char *s_new, *s2; const char *svalue; - while (*src && g_ascii_isspace (*src)) - src++; + src = nm_str_skip_leading_spaces (src); svalue = strchr (src, '='); if (!svalue || svalue == src) @@ -94,24 +93,25 @@ nms_ibft_reader_load_blocks (const char *iscsiadm_path, { const char *argv[4] = { iscsiadm_path, "-m", "fw", NULL }; const char *envp[1] = { NULL }; - GSList *blocks = NULL; - char *out = NULL, *err = NULL; - int status = 0; - char **lines = NULL, **iter; + nm_auto_free_ibft_blocks GSList *blocks = NULL; + gs_free char *out = NULL; + gs_free char *err = NULL; + gs_free const char **lines = NULL; GPtrArray *block_lines = NULL; - gboolean success = FALSE; + gsize i; + int status = 0; g_return_val_if_fail (iscsiadm_path != NULL, FALSE); g_return_val_if_fail (out_blocks != NULL && *out_blocks == NULL, FALSE); if (!g_spawn_sync ("/", (char **) argv, (char **) envp, 0, NULL, NULL, &out, &err, &status, error)) - goto done; + return FALSE; if (!WIFEXITED (status)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "iBFT: %s exited abnormally.", iscsiadm_path); - goto done; + return FALSE; } if (WEXITSTATUS (status) != 0) { @@ -127,59 +127,47 @@ nms_ibft_reader_load_blocks (const char *iscsiadm_path, g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "iBFT: %s exited with error %d. Message: '%s'", iscsiadm_path, WEXITSTATUS (status), err ?: "(none)"); - goto done; + return FALSE; } nm_log_dbg (LOGD_SETTINGS, "iBFT records:\n%s", out); - lines = g_strsplit_set (out, "\n\r", -1); - for (iter = lines; iter && *iter; iter++) { - if (!*iter[0]) - continue; + lines = nm_utils_strsplit_set (out, "\n\r"); + for (i = 0; lines && lines[i]; i++) { + const char *ss = lines[i]; - if (!g_ascii_strncasecmp (*iter, TAG_BEGIN, NM_STRLEN (TAG_BEGIN))) { + if (!g_ascii_strncasecmp (ss, TAG_BEGIN, NM_STRLEN (TAG_BEGIN))) { if (block_lines) { PARSE_WARNING ("malformed iscsiadm record: missing END RECORD."); - g_ptr_array_unref (block_lines); + nm_clear_pointer (&block_lines, g_ptr_array_unref); } /* Start new record */ block_lines = g_ptr_array_new_full (15, g_free); - } else if (!g_ascii_strncasecmp (*iter, TAG_END, NM_STRLEN (TAG_END))) { + } else if (!g_ascii_strncasecmp (ss, TAG_END, NM_STRLEN (TAG_END))) { if (block_lines) { if (block_lines->len) - blocks = g_slist_prepend (blocks, block_lines); + blocks = g_slist_prepend (blocks, g_steal_pointer (&block_lines)); else - g_ptr_array_unref (block_lines); - block_lines = NULL; + g_ptr_array_unref (g_steal_pointer (&block_lines)); } } else if (block_lines) { - char *s = remove_most_whitespace (*iter); + char *s = remove_most_whitespace (ss); - if (s) + if (!s) { + PARSE_WARNING ("malformed iscsiadm record: no = in '%s'.", ss); + nm_clear_pointer (&block_lines, g_ptr_array_unref); + } else g_ptr_array_add (block_lines, s); - else { - PARSE_WARNING ("malformed iscsiadm record: no = in '%s'.", *iter); - g_clear_pointer (&block_lines, g_ptr_array_unref); - } } } if (block_lines) { PARSE_WARNING ("malformed iscsiadm record: missing # END RECORD."); - g_clear_pointer (&block_lines, g_ptr_array_unref); + nm_clear_pointer (&block_lines, g_ptr_array_unref); } - success = TRUE; - -done: - if (lines) - g_strfreev (lines); - g_free (out); - g_free (err); - if (success) - *out_blocks = blocks; - else - g_slist_free_full (blocks, (GDestroyNotify) g_ptr_array_unref); - return success; + + *out_blocks = g_steal_pointer (&blocks); + return TRUE; } #define ISCSI_HWADDR_TAG "iface.hwaddress" diff --git a/src/settings/plugins/ibft/nms-ibft-reader.h b/src/settings/plugins/ibft/nms-ibft-reader.h index 27500cc5..baa81e99 100644 --- a/src/settings/plugins/ibft/nms-ibft-reader.h +++ b/src/settings/plugins/ibft/nms-ibft-reader.h @@ -23,6 +23,14 @@ #include "nm-connection.h" +static inline void +_nm_auto_free_ibft_blocks (GSList **p_blocks) +{ + if (*p_blocks) + g_slist_free_full (*p_blocks, (GDestroyNotify) g_ptr_array_unref); +} +#define nm_auto_free_ibft_blocks nm_auto (_nm_auto_free_ibft_blocks) + gboolean nms_ibft_reader_load_blocks (const char *iscsiadm_path, GSList **out_blocks, GError **error); diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c index 4c45f574..f5b584a1 100644 --- a/src/settings/plugins/ibft/tests/test-ibft.c +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -40,16 +40,16 @@ static GPtrArray * read_block (const char *iscsiadm_path, const char *expected_mac) { - GSList *blocks = NULL, *iter; + nm_auto_free_ibft_blocks GSList *blocks = NULL; + GSList *iter; GPtrArray *block = NULL; GError *error = NULL; gboolean success; success = nms_ibft_reader_load_blocks (iscsiadm_path, &blocks, &error); - g_assert_no_error (error); - g_assert (success); - g_assert (blocks); + nmtst_assert_success (success, error); + g_assert (blocks); for (iter = blocks; iter; iter = iter->next) { const char *s_hwaddr = NULL; @@ -63,7 +63,6 @@ read_block (const char *iscsiadm_path, const char *expected_mac) } g_assert (block); - g_slist_free_full (blocks, (GDestroyNotify) g_ptr_array_unref); return block; } @@ -176,7 +175,7 @@ static void test_read_ibft_malformed (gconstpointer user_data) { const char *iscsiadm_path = user_data; - GSList *blocks = NULL; + nm_auto_free_ibft_blocks GSList *blocks = NULL; GError *error = NULL; gboolean success; @@ -185,9 +184,9 @@ test_read_ibft_malformed (gconstpointer user_data) NMTST_EXPECT_NM_WARN ("*malformed iscsiadm record*"); success = nms_ibft_reader_load_blocks (iscsiadm_path, &blocks, &error); - g_assert_no_error (error); - g_assert (success); - g_assert (blocks == NULL); + nmtst_assert_success (success, error); + + g_assert (!blocks); g_test_assert_expected_messages (); } diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index 89272edb..5160dbf0 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -30,7 +30,7 @@ #include #include -#include "nm-dbus-compat.h" +#include "nm-std-aux/nm-dbus-compat.h" #include "nm-setting-connection.h" #include "settings/nm-settings-plugin.h" #include "nm-config.h" 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 7c1db225..e5423b18 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -31,7 +31,7 @@ #include #include -#include "nm-utils/nm-secret-utils.h" +#include "nm-glib-aux/nm-secret-utils.h" #include "nm-connection.h" #include "nm-dbus-interface.h" #include "nm-setting-connection.h" @@ -53,7 +53,7 @@ #include "nm-setting-generic.h" #include "nm-core-internal.h" #include "nm-utils.h" -#include "nm-ethtool-utils.h" +#include "nm-libnm-core-intern/nm-ethtool-utils.h" #include "platform/nm-platform.h" #include "NetworkManagerUtils.h" @@ -82,7 +82,8 @@ static char * get_full_file_path (const char *ifcfg_path, const char *file_path) { const char *base = file_path; - char *p, *ret, *dirname; + gs_free char *dirname = NULL; + char *p; g_return_val_if_fail (ifcfg_path != NULL, NULL); g_return_val_if_fail (file_path != NULL, NULL); @@ -95,9 +96,7 @@ get_full_file_path (const char *ifcfg_path, const char *file_path) base = p + 1; dirname = g_path_get_dirname (ifcfg_path); - ret = g_build_path ("/", dirname, base, NULL); - g_free (dirname); - return ret; + return g_build_path ("/", dirname, base, NULL); } /*****************************************************************************/ @@ -207,7 +206,7 @@ _cert_get_cert_bytes (const char *ifcfg_path, { gs_free char *path = NULL; - if (g_str_has_prefix (value, "pkcs11:")) + if (NM_STR_HAS_PREFIX (value, "pkcs11:")) return _nm_setting_802_1x_cert_value_to_bytes (NM_SETTING_802_1X_CK_SCHEME_PKCS11, (guint8 *) value, -1, error); path = get_full_file_path (ifcfg_path, value); @@ -379,7 +378,7 @@ make_connection_setting (const char *file, NMSettingConnection *s_con; NMSettingConnectionLldp lldp; const char *ifcfg_name = NULL; - char *new_id; + gs_free char *new_id = NULL; const char *uuid; gs_free char *uuid_free = NULL; gs_free char *value = NULL; @@ -396,7 +395,6 @@ make_connection_setting (const char *file, new_id = make_connection_name (ifcfg, ifcfg_name, suggested, prefix); g_object_set (s_con, NM_SETTING_CONNECTION_ID, new_id, NULL); - g_free (new_id); /* Try for a UUID key before falling back to hashing the file name */ uuid = svGetValueStr (ifcfg, "UUID", &uuid_free); @@ -457,7 +455,7 @@ make_connection_setting (const char *file, if (v) { gs_free const char **items = NULL; - items = nm_utils_strsplit_set (v, " ", FALSE); + items = nm_utils_strsplit_set (v, " "); for (iter = items; iter && *iter; iter++) { if (!nm_setting_connection_add_permission (s_con, "user", *iter, NULL)) PARSE_WARNING ("invalid USERS item '%s'", *iter); @@ -473,7 +471,7 @@ make_connection_setting (const char *file, if (v) { gs_free const char **items = NULL; - items = nm_utils_strsplit_set (v, " \t", FALSE); + items = nm_utils_strsplit_set (v, " \t"); for (iter = items; iter && *iter; iter++) { if (!nm_setting_connection_add_secondary (s_con, *iter)) PARSE_WARNING ("secondary connection UUID '%s' already added", *iter); @@ -562,7 +560,6 @@ make_connection_setting (const char *file, return NM_SETTING (s_con); } -/* Returns TRUE on missing address or valid address */ static gboolean read_ip4_address (shvarFile *ifcfg, const char *tag, @@ -572,7 +569,7 @@ read_ip4_address (shvarFile *ifcfg, { gs_free char *value_to_free = NULL; const char *value; - guint32 a; + in_addr_t a; nm_assert (ifcfg); nm_assert (tag); @@ -820,7 +817,7 @@ parse_route_line (const char *line, NMIPRoute **out_route, GError **error) { - nm_auto_ip_route_unref NMIPRoute *route = NULL; + nm_auto_unref_ip_route NMIPRoute *route = NULL; gs_free const char **words_free = NULL; const char *const*words; const char *s; @@ -889,7 +886,7 @@ parse_route_line (const char *line, * Maybe later we want to support some form of quotation here. * Which of course, would be incompatible with initscripts. */ - words_free = nm_utils_strsplit_set (line, " \t\n", FALSE); + words_free = nm_utils_strsplit_set (line, " \t\n"); words = words_free ?: NM_PTRARRAY_EMPTY (const char *); @@ -1284,7 +1281,7 @@ read_route_file (int addr_family, for (line = strtok_r (contents, "\n", &contents_rest); line; line = strtok_r (NULL, "\n", &contents_rest)) { - nm_auto_ip_route_unref NMIPRoute *route = NULL; + nm_auto_unref_ip_route NMIPRoute *route = NULL; gs_free_error GError *local = NULL; int e; @@ -1327,7 +1324,7 @@ parse_dns_options (NMSettingIPConfig *ip_config, const char *value) if (!nm_setting_ip_config_has_dns_options (ip_config)) nm_setting_ip_config_clear_dns_options (ip_config, TRUE); - options = nm_utils_strsplit_set (value, " ", FALSE); + options = nm_utils_strsplit_set (value, " "); if (options) { for (item = options; *item; item++) { if (!nm_setting_ip_config_add_dns_option (ip_config, *item)) @@ -1343,46 +1340,33 @@ parse_full_ip6_address (shvarFile *ifcfg, NMIPAddress **out_address, GError **error) { - char **list; - char *ip_val, *prefix_val; + NMIPAddress *addr; + NMIPAddr addr_bin; int prefix; - gboolean success = FALSE; - g_return_val_if_fail (addr_str != NULL, FALSE); - g_return_val_if_fail (out_address != NULL, FALSE); - g_return_val_if_fail (*out_address == NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); + nm_assert (addr_str); + nm_assert (out_address && !*out_address); + nm_assert (!error || !*error); - /* Split the address and prefix */ - list = g_strsplit_set (addr_str, "/", 2); - if (g_strv_length (list) < 1) { + if (!nm_utils_parse_inaddr_prefix_bin (AF_INET6, + addr_str, + NULL, + &addr_bin, + &prefix)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 address '%s'", addr_str); - goto error; + return FALSE; } - ip_val = list[0]; - - prefix_val = list[1]; - if (prefix_val) { - prefix = _nm_utils_ascii_str_to_int64 (prefix_val, 10, 0, 128, -1); - if (prefix < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 prefix '%s'", prefix_val); - goto error; - } - } else { - /* Missing prefix is treated as prefix of 64 */ + if (prefix < 0) prefix = 64; - } - *out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error); - if (*out_address) - success = TRUE; + addr = nm_ip_address_new_binary (AF_INET6, &addr_bin, prefix, error); + if (!addr) + return FALSE; -error: - g_strfreev (list); - return success; + *out_address = addr; + return TRUE; } static NMSetting * @@ -1443,13 +1427,12 @@ make_match_setting (shvarFile *ifcfg) if (!v) return NULL; - strv = nm_utils_strsplit_set (v, " \t", TRUE); + strv = nm_utils_escaped_tokens_split (v, NM_ASCII_SPACES); if (strv) { for (i = 0; strv[i]; i++) { if (!s_match) s_match = (NMSettingMatch *) nm_setting_match_new (); - nm_setting_match_add_interface_name (s_match, - _nm_utils_unescape_spaces ((char *) strv[i])); + nm_setting_match_add_interface_name (s_match, strv[i]); } } @@ -1722,7 +1705,7 @@ make_ip4_setting (shvarFile *ifcfg, if (v) { gs_free const char **searches = NULL; - searches = nm_utils_strsplit_set (v, " ", FALSE); + searches = nm_utils_strsplit_set (v, " "); if (searches) { for (item = searches; *item; item++) { if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) @@ -1783,7 +1766,7 @@ make_ip4_setting (shvarFile *ifcfg, if (v) { gs_free const char **searches = NULL; - searches = nm_utils_strsplit_set (v, " ", FALSE); + searches = nm_utils_strsplit_set (v, " "); if (searches) { for (item = searches; *item; item++) { if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) @@ -1809,7 +1792,8 @@ static void read_aliases (NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *filename) { GDir *dir; - char *dirname, *base; + gs_free char *dirname = NULL; + gs_free char *base = NULL; NMIPAddress *base_addr = NULL; GError *err = NULL; @@ -1820,9 +1804,9 @@ read_aliases (NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *file base_addr = nm_setting_ip_config_get_address (s_ip4, 0); dirname = g_path_get_dirname (filename); - g_return_if_fail (dirname != NULL); + nm_assert (dirname != NULL); base = g_path_get_basename (filename); - g_return_if_fail (base != NULL); + nm_assert (base != NULL); dir = g_dir_open (dirname, 0, &err); if (dir) { @@ -1911,9 +1895,6 @@ read_aliases (NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *file PARSE_WARNING ("can not read directory '%s': %s", dirname, err->message); g_error_free (err); } - - g_free (base); - g_free (dirname); } static NMSetting * @@ -1922,10 +1903,9 @@ make_ip6_setting (shvarFile *ifcfg, gboolean routes_read, GError **error) { - NMSettingIPConfig *s_ip6 = NULL; + gs_unref_object NMSettingIPConfig *s_ip6 = NULL; const char *v; gs_free char *value = NULL; - char *route6_path = NULL; gboolean ipv6init, ipv6forwarding, dhcp6 = FALSE; char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; const char *ipv6addr, *ipv6addr_secondaries; @@ -2060,7 +2040,7 @@ make_ip6_setting (shvarFile *ifcfg, /* Don't bother to read IP, DNS and routes when IPv6 is disabled */ if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) - return NM_SETTING (s_ip6); + return NM_SETTING (g_steal_pointer (&s_ip6)); nm_clear_g_free (&value); v = svGetValueStr (ifcfg, "DHCPV6_DUID", &value); @@ -2083,7 +2063,7 @@ make_ip6_setting (shvarFile *ifcfg, g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, v, NULL); g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, - svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL); + svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL); /* Read static IP addresses. * Read them even for AUTO and DHCP methods - in this case the addresses are @@ -2099,12 +2079,12 @@ make_ip6_setting (shvarFile *ifcfg, ipv6addr_secondaries ?: "", NULL); - list = nm_utils_strsplit_set (value, " ", FALSE); + list = nm_utils_strsplit_set (value, " "); for (iter = list, i = 0; iter && *iter; iter++, i++) { NMIPAddress *addr = NULL; if (!parse_full_ip6_address (ifcfg, *iter, i, &addr, error)) - goto error; + return NULL; if (!nm_setting_ip_config_add_address (s_ip6, addr)) PARSE_WARNING ("duplicate IP6 address"); @@ -2129,7 +2109,7 @@ make_ip6_setting (shvarFile *ifcfg, if (!nm_utils_ipaddr_valid (AF_INET6, v)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 address '%s'", v); - goto error; + return NULL; } g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, v, NULL); @@ -2172,18 +2152,19 @@ make_ip6_setting (shvarFile *ifcfg, /* Ignore IPv4 addresses */ } else { PARSE_WARNING ("invalid DNS server address %s", v); - goto error; + return NULL; } } if (!routes_read) { /* NOP */ } else { + gs_free char *route6_path = NULL; + /* Read static routes from route6- file */ route6_path = utils_get_route6_path (svFileGetName (ifcfg)); if (!read_route_file (AF_INET6, route6_path, s_ip6, error)) - goto error; - g_free (route6_path); + return NULL; } /* DNS searches */ @@ -2192,7 +2173,7 @@ make_ip6_setting (shvarFile *ifcfg, if (v) { gs_free const char **searches = NULL; - searches = nm_utils_strsplit_set (v, " ", FALSE); + searches = nm_utils_strsplit_set (v, " "); if (searches) { for (iter = searches; *iter; iter++) { if (!nm_setting_ip_config_add_dns_search (s_ip6, *iter)) @@ -2212,12 +2193,7 @@ make_ip6_setting (shvarFile *ifcfg, priority, NULL); - return NM_SETTING (s_ip6); - -error: - g_free (route6_path); - g_object_unref (s_ip6); - return NULL; + return NM_SETTING (g_steal_pointer (&s_ip6)); } static NMSetting * @@ -2551,7 +2527,7 @@ read_dcb_percent_array (shvarFile *ifcfg, return TRUE; } - split = nm_utils_strsplit_set (val, ",", FALSE); + split = nm_utils_strsplit_set (val, ","); if (NM_PTRARRAY_LEN (split) != 8) { PARSE_WARNING ("invalid %s percentage list value '%s'", prop, val); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -2588,10 +2564,9 @@ make_dcb_setting (shvarFile *ifcfg, NMSetting **out_setting, GError **error) { - NMSettingDcb *s_dcb = NULL; + gs_unref_object NMSettingDcb *s_dcb = NULL; gboolean dcb_on; NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - char *val; g_return_val_if_fail (out_setting != NULL, FALSE); @@ -2600,31 +2575,28 @@ make_dcb_setting (shvarFile *ifcfg, return TRUE; s_dcb = (NMSettingDcb *) nm_setting_dcb_new (); - g_assert (s_dcb); /* FCOE */ if (!read_dcb_app (ifcfg, s_dcb, "FCOE", &dcb_flags_props[DCB_APP_FCOE_FLAGS], NM_SETTING_DCB_APP_FCOE_PRIORITY, error)) { - g_object_unref (s_dcb); return FALSE; } if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) { + gs_free char *val = NULL; + val = svGetValueStr_cp (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) + if (NM_IN_STRSET (val, NM_SETTING_DCB_FCOE_MODE_FABRIC, + NM_SETTING_DCB_FCOE_MODE_VN2VN)) g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, val, NULL); else { PARSE_WARNING ("invalid FCoE mode '%s'", val); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "invalid FCoE mode"); - g_free (val); - g_object_unref (s_dcb); return FALSE; } - g_free (val); } } @@ -2633,7 +2605,6 @@ make_dcb_setting (shvarFile *ifcfg, &dcb_flags_props[DCB_APP_ISCSI_FLAGS], NM_SETTING_DCB_APP_ISCSI_PRIORITY, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2642,7 +2613,6 @@ make_dcb_setting (shvarFile *ifcfg, &dcb_flags_props[DCB_APP_FIP_FLAGS], NM_SETTING_DCB_APP_FIP_PRIORITY, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2657,7 +2627,6 @@ make_dcb_setting (shvarFile *ifcfg, "PFC", nm_setting_dcb_set_priority_flow_control, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2673,7 +2642,6 @@ make_dcb_setting (shvarFile *ifcfg, TRUE, nm_setting_dcb_set_priority_group_id, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2686,7 +2654,6 @@ make_dcb_setting (shvarFile *ifcfg, TRUE, nm_setting_dcb_set_priority_group_bandwidth, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2699,7 +2666,6 @@ make_dcb_setting (shvarFile *ifcfg, FALSE, nm_setting_dcb_set_priority_bandwidth, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2711,7 +2677,6 @@ make_dcb_setting (shvarFile *ifcfg, "STRICT", nm_setting_dcb_set_priority_strict_bandwidth, error)) { - g_object_unref (s_dcb); return FALSE; } @@ -2723,11 +2688,10 @@ make_dcb_setting (shvarFile *ifcfg, FALSE, nm_setting_dcb_set_priority_traffic_class, error)) { - g_object_unref (s_dcb); return FALSE; } - *out_setting = NM_SETTING (s_dcb); + *out_setting = NM_SETTING (g_steal_pointer (&s_dcb)); return TRUE; } @@ -2834,7 +2798,7 @@ make_wep_setting (shvarFile *ifcfg, GError **error) { gs_unref_object NMSettingWirelessSecurity *s_wsec = NULL; - char *value; + gs_free char *value = NULL; shvarFile *keys_ifcfg = NULL; int default_key_idx = 0; gboolean has_default_key = FALSE; @@ -2849,13 +2813,12 @@ make_wep_setting (shvarFile *ifcfg, if (default_key_idx == 0) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid default WEP key '%s'", value); - g_free (value); return NULL; } has_default_key = TRUE; default_key_idx--; /* convert to [0...3] */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, (guint) default_key_idx, NULL); - g_free (value); + nm_clear_g_free (&value); } /* Read WEP key flags */ @@ -2902,23 +2865,21 @@ make_wep_setting (shvarFile *ifcfg, value = svGetValueStr_cp (ifcfg, "SECURITYMODE"); if (value) { - char *lcase; + gs_free char *lcase = NULL; lcase = g_ascii_strdown (value, -1); - g_free (value); + nm_clear_g_free (&value); - if (!strcmp (lcase, "open")) { + if (nm_streq (lcase, "open")) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); - } else if (!strcmp (lcase, "restricted")) { + } else if (nm_streq (lcase, "restricted")) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL); } else { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WEP authentication algorithm '%s'", lcase); - g_free (lcase); return NULL; } - g_free (lcase); } /* If no WEP keys were given, and the keys are not agent-owned, and no @@ -2963,7 +2924,7 @@ fill_wpa_ciphers (shvarFile *ifcfg, if (!p) return TRUE; - list = nm_utils_strsplit_set (p, " ", FALSE); + list = nm_utils_strsplit_set (p, " "); for (iter = list; iter && *iter; iter++, i++) { /* Ad-Hoc configurations cannot have pairwise ciphers, and can only * have one group cipher. Ignore any additional group ciphers and @@ -3233,7 +3194,7 @@ eap_peap_reader (const char *eap_method, } /* Handle options for the inner auth method */ - list = nm_utils_strsplit_set (v, " ", FALSE); + list = nm_utils_strsplit_set (v, " "); iter = list; if (iter) { if (NM_IN_STRSET (*iter, "MSCHAPV2", @@ -3311,7 +3272,7 @@ eap_ttls_reader (const char *eap_method, inner_auth = g_ascii_strdown (v, -1); /* Handle options for the inner auth method */ - list = nm_utils_strsplit_set (inner_auth, " ", FALSE); + list = nm_utils_strsplit_set (inner_auth, " "); iter = list; if (iter) { if (NM_IN_STRSET (*iter, "mschapv2", @@ -3372,7 +3333,7 @@ eap_fast_reader (const char *eap_method, if (fast_provisioning) { gs_free const char **list1 = NULL; - list1 = nm_utils_strsplit_set (fast_provisioning, " \t", FALSE); + list1 = nm_utils_strsplit_set (fast_provisioning, " \t"); for (iter = list1; iter && *iter; iter++) { if (strcmp (*iter, "allow-unauth") == 0) allow_unauth = TRUE; @@ -3406,7 +3367,7 @@ eap_fast_reader (const char *eap_method, } /* Handle options for the inner auth method */ - list = nm_utils_strsplit_set (inner_auth, " ", FALSE); + list = nm_utils_strsplit_set (inner_auth, " "); iter = list; if (iter) { if ( !strcmp (*iter, "MSCHAPV2") @@ -3486,7 +3447,7 @@ read_8021x_list_value (shvarFile *ifcfg, if (!v) return; - strv = nm_utils_strsplit_set (v, " \t", FALSE); + strv = nm_utils_strsplit_set (v, " \t"); if (strv) g_object_set (setting, prop_name, strv, NULL); } @@ -3515,7 +3476,7 @@ fill_8021x (shvarFile *ifcfg, return NULL; } - list = nm_utils_strsplit_set (v, " ", FALSE); + list = nm_utils_strsplit_set (v, " "); s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); @@ -3829,7 +3790,7 @@ transform_hwaddr_blacklist (const char *blacklist) const char **strv; gsize i, j; - strv = nm_utils_strsplit_set (blacklist, " \t", FALSE); + strv = nm_utils_strsplit_set (blacklist, " \t"); if (!strv) return NULL; for (i = 0, j = 0; strv[j]; j++) { @@ -4147,7 +4108,7 @@ parse_ethtool_option (const char *value, gs_free const char **words = NULL; guint i; - words = nm_utils_strsplit_set (value, NULL, FALSE); + words = nm_utils_strsplit_set (value, " \t\n"); if (!words) return; @@ -4316,6 +4277,84 @@ parse_ethtool_option (const char *value, } } +static GPtrArray * +read_routing_rules_parse (shvarFile *ifcfg, + gboolean routes_read) +{ + gs_unref_ptrarray GPtrArray *arr = NULL; + gs_free const char **keys = NULL; + guint i, len; + + keys = svGetKeysSorted (ifcfg, SV_KEY_TYPE_ROUTING_RULE4 | SV_KEY_TYPE_ROUTING_RULE6, &len); + if (len == 0) + return NULL; + + if (!routes_read) { + PARSE_WARNING ("'rule-' or 'rule6-' files are present; Policy routing rules (ROUTING_RULE*) settings are ignored"); + return NULL; + } + + arr = g_ptr_array_new_full (len, (GDestroyNotify) nm_ip_routing_rule_unref); + for (i = 0; i < len; i++) { + const char *key = keys[i]; + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; + gs_free_error GError *local = NULL; + gs_free char *value_to_free = NULL; + const char *value; + gboolean key_is_ipv4; + + key_is_ipv4 = (key[NM_STRLEN ("ROUTING_RULE")] == '_'); + nm_assert ( key_is_ipv4 == NM_STR_HAS_PREFIX (key, "ROUTING_RULE_")); + nm_assert ((!key_is_ipv4) == NM_STR_HAS_PREFIX (key, "ROUTING_RULE6_")); + + value = svGetValueStr (ifcfg, key, &value_to_free); + if (!value) + continue; + + rule = nm_ip_routing_rule_from_string (value, + NM_IP_ROUTING_RULE_AS_STRING_FLAGS_VALIDATE + | (key_is_ipv4 + ? NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET + : NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET6), + NULL, + &local); + if (!rule) { + PARSE_WARNING ("invalid routing rule %s=\"%s\": %s", key, value, local->message); + continue; + } + + g_ptr_array_add (arr, g_steal_pointer (&rule)); + } + + if (arr->len == 0) + return NULL; + + return g_steal_pointer (&arr); +} + +static void +read_routing_rules (shvarFile *ifcfg, + gboolean routes_read, + NMSettingIPConfig *s_ip4, + NMSettingIPConfig *s_ip6) +{ + gs_unref_ptrarray GPtrArray *routing_rules = NULL; + guint i; + + routing_rules = read_routing_rules_parse (ifcfg, routes_read); + if (!routing_rules) + return; + + for (i = 0; i < routing_rules->len; i++) { + NMIPRoutingRule *rule = routing_rules->pdata[i]; + + nm_setting_ip_config_add_routing_rule ( (nm_ip_routing_rule_get_addr_family (rule) == AF_INET) + ? s_ip4 + : s_ip6, + rule); + } +} + static void parse_ethtool_options (shvarFile *ifcfg, NMConnection *connection) { @@ -4340,7 +4379,7 @@ parse_ethtool_options (shvarFile *ifcfg, NMConnection *connection) gs_free const char **opts = NULL; const char *const *iter; - opts = nm_utils_strsplit_set (ethtool_opts, ";", FALSE); + opts = nm_utils_strsplit_set (ethtool_opts, ";"); for (iter = opts; iter && iter[0]; iter++) { /* in case of repeated wol_passwords, parse_ethtool_option() * will do the right thing and clear wol_password before resetting. */ @@ -4436,7 +4475,7 @@ make_wired_setting (shvarFile *ifcfg, gs_free const char **chans = NULL; guint32 num_chans; - chans = nm_utils_strsplit_set (value, ",", FALSE); + chans = nm_utils_strsplit_set (value, ","); num_chans = NM_PTRARRAY_LEN (chans); if (num_chans < 2 || num_chans > 3) { PARSE_WARNING ("invalid SUBCHANNELS '%s' (%u channels, 2 or 3 expected)", @@ -4470,22 +4509,23 @@ make_wired_setting (shvarFile *ifcfg, value = svGetValueStr_cp (ifcfg, "OPTIONS"); if (value) { - char **options, **iter; + gs_free const char **options = NULL; + gsize i; - iter = options = g_strsplit_set (value, " ", 0); - while (iter && *iter) { - char *equals = strchr (*iter, '='); + options = nm_utils_strsplit_set_with_empty (value, " "); + for (i = 0; options && options[i]; i++) { + const char *line = options[i]; + const char *equals; gboolean valid = FALSE; + equals = strchr (line, '='); if (equals) { - *equals = '\0'; - valid = nm_setting_wired_add_s390_option (s_wired, *iter, equals + 1); + ((char *) equals)[0] = '\0'; + valid = nm_setting_wired_add_s390_option (s_wired, line, equals + 1); } if (!valid) - PARSE_WARNING ("invalid s390 OPTION '%s'", *iter); - iter++; + PARSE_WARNING ("invalid s390 OPTION '%s'", line); } - g_strfreev (options); nm_clear_g_free (&value); } @@ -4759,18 +4799,18 @@ make_bond_setting (shvarFile *ifcfg, gs_free const char **items = NULL; const char *const *iter; - items = nm_utils_strsplit_set (v, " ", FALSE); + items = nm_utils_strsplit_set (v, " "); for (iter = items; iter && *iter; iter++) { - gs_strfreev char **keys = NULL; - const char *key, *val; - - keys = g_strsplit_set (*iter, "=", 2); - if (keys && *keys) { - key = *keys; - val = *(keys + 1); - if (val && key[0] && val[0]) - handle_bond_option (s_bond, key, val); - } + gs_free char *key = NULL; + const char *val; + + val = strchr (*iter, '='); + if (!val) + continue; + key = g_strndup (*iter, val - *iter); + val++; + if (key[0] && val[0]) + handle_bond_option (s_bond, key, val); } } @@ -4958,6 +4998,8 @@ handle_bridge_option (NMSetting *setting, { "max_age", NM_SETTING_BRIDGE_MAX_AGE, BRIDGE_OPT_TYPE_OPTION, .only_with_stp = TRUE }, { "ageing_time", NM_SETTING_BRIDGE_AGEING_TIME, BRIDGE_OPT_TYPE_OPTION }, { "multicast_snooping", NM_SETTING_BRIDGE_MULTICAST_SNOOPING, BRIDGE_OPT_TYPE_OPTION }, + { "vlan_filtering", NM_SETTING_BRIDGE_VLAN_FILTERING, BRIDGE_OPT_TYPE_OPTION }, + { "default_pvid", NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, BRIDGE_OPT_TYPE_OPTION }, { "group_fwd_mask", NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, BRIDGE_OPT_TYPE_OPTION }, { "priority", NM_SETTING_BRIDGE_PORT_PRIORITY, BRIDGE_OPT_TYPE_PORT_OPTION }, { "path_cost", NM_SETTING_BRIDGE_PORT_PATH_COST, BRIDGE_OPT_TYPE_PORT_OPTION }, @@ -5037,19 +5079,56 @@ handle_bridging_opts (NMSetting *setting, gs_free const char **items = NULL; const char *const *iter; - items = nm_utils_strsplit_set (value, " ", FALSE); + items = nm_utils_strsplit_set (value, " "); for (iter = items; iter && *iter; iter++) { - gs_strfreev char **keys = NULL; - const char *key, *val; - - keys = g_strsplit_set (*iter, "=", 2); - if (keys && *keys) { - key = *keys; - val = *(keys + 1); - if (val && key[0] && val[0]) - func (setting, stp, key, val, opt_type); + gs_free char *key = NULL; + const char *val; + + val = strchr (*iter, '='); + if (!val) + continue; + key = g_strndup (*iter, val - *iter); + val++; + if (key[0] && val[0]) + func (setting, stp, key, val, opt_type); + } +} + +static void +read_bridge_vlans (shvarFile *ifcfg, + const char *key, + NMSetting *setting, + const char *property) +{ + gs_unref_ptrarray GPtrArray *array = NULL; + gs_free char *value_to_free = NULL; + const char *value; + + value = svGetValueStr (ifcfg, key, &value_to_free); + if (value) { + gs_free const char **strv = NULL; + const char *const *iter; + GError *local = NULL; + NMBridgeVlan *vlan; + + array = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_bridge_vlan_unref); + + strv = nm_utils_escaped_tokens_split (value, ","); + if (strv) { + for (iter = strv; *iter; iter++) { + vlan = nm_bridge_vlan_from_str (*iter, &local); + if (!vlan) { + PARSE_WARNING ("invalid bridge VLAN: %s", local->message); + g_clear_error (&local); + continue; + } + g_ptr_array_add (array, vlan); + } } + nm_clear_g_free (&value_to_free); } + + g_object_set (setting, property, array, NULL); } static NMSetting * @@ -5110,6 +5189,11 @@ make_bridge_setting (shvarFile *ifcfg, nm_clear_g_free (&value_to_free); } + read_bridge_vlans (ifcfg, + "BRIDGE_VLANS", + NM_SETTING (s_bridge), + NM_SETTING_BRIDGE_VLANS); + return (NMSetting *) g_steal_pointer (&s_bridge); } @@ -5179,6 +5263,11 @@ make_bridge_port_setting (shvarFile *ifcfg) handle_bridging_opts (s_port, FALSE, value, handle_bridge_option, BRIDGE_OPT_TYPE_PORT_OPTION); nm_clear_g_free (&value_to_free); } + + read_bridge_vlans (ifcfg, + "BRIDGE_PORT_VLANS", + s_port, + NM_SETTING_BRIDGE_PORT_VLANS); } return s_port; @@ -5255,7 +5344,7 @@ parse_prio_map_list (NMSettingVlan *s_vlan, v = svGetValueStr (ifcfg, key, &value); if (!v) return; - list = nm_utils_strsplit_set (v, ",", FALSE); + list = nm_utils_strsplit_set (v, ","); for (iter = list; iter && *iter; iter++) { if (!strchr (*iter, ':')) @@ -5360,7 +5449,7 @@ make_vlan_setting (shvarFile *ifcfg, gs_free const char **strv = NULL; const char *const *ptr; - strv = nm_utils_strsplit_set (v, ", ", FALSE); + strv = nm_utils_strsplit_set (v, ", "); for (ptr = strv; ptr && *ptr; ptr++) { if (nm_streq (*ptr, "GVRP") && gvrp == -1) vlan_flags |= NM_VLAN_FLAG_GVRP; @@ -5502,7 +5591,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) gs_free const char **searches = NULL; const char *const *item; - searches = nm_utils_strsplit_set (v, " ", FALSE); + searches = nm_utils_strsplit_set (v, " "); if (searches) { for (item = searches; *item; item++) { if (!nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (s_ip6), *item)) @@ -5768,8 +5857,7 @@ connection_from_file_full (const char *filename, error); if (!s_ip6) return NULL; - else - nm_connection_add_setting (connection, s_ip6); + nm_connection_add_setting (connection, s_ip6); s_ip4 = make_ip4_setting (main_ifcfg, network_ifcfg, @@ -5778,12 +5866,15 @@ connection_from_file_full (const char *filename, error); if (!s_ip4) return NULL; - else { - read_aliases (NM_SETTING_IP_CONFIG (s_ip4), - !has_ip4_defroute && !nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (s_ip4)), - filename); - nm_connection_add_setting (connection, s_ip4); - } + read_aliases (NM_SETTING_IP_CONFIG (s_ip4), + !has_ip4_defroute && !nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (s_ip4)), + filename); + nm_connection_add_setting (connection, s_ip4); + + read_routing_rules (main_ifcfg, + !has_complex_routes_v4 && !has_complex_routes_v6, + NM_SETTING_IP_CONFIG (s_ip4), + NM_SETTING_IP_CONFIG (s_ip6)); s_sriov = make_sriov_setting (main_ifcfg); if (s_sriov) 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 84c22094..c7729df5 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -22,7 +22,7 @@ #define _UTILS_H_ #include "nm-connection.h" -#include "nm-ethtool-utils.h" +#include "nm-libnm-core-intern/nm-ethtool-utils.h" #include "shvar.h" 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 ee7fd161..80b1bffe 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -30,8 +30,8 @@ #include #include -#include "nm-utils/nm-enum-utils.h" -#include "nm-utils/nm-io-utils.h" +#include "nm-glib-aux/nm-enum-utils.h" +#include "nm-glib-aux/nm-io-utils.h" #include "nm-manager.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" @@ -50,7 +50,7 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" #include "nm-meta-setting.h" -#include "nm-ethtool-utils.h" +#include "nm-libnm-core-intern/nm-ethtool-utils.h" #include "nms-ifcfg-rh-common.h" #include "nms-ifcfg-rh-reader.h" @@ -1463,6 +1463,43 @@ get_setting_default_boolean (NMSetting *setting, const char *prop) return ret; } +static gboolean +write_bridge_vlans (NMSetting *setting, + const char *property_name, + shvarFile *ifcfg, + const char *key, + GError **error) +{ + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan *vlan; + GString *string; + guint i; + + g_object_get (setting, property_name, &vlans, NULL); + + if (!vlans || !vlans->len) { + svUnsetValue (ifcfg, key); + return TRUE; + } + + string = g_string_new (""); + for (i = 0; i < vlans->len; i++) { + gs_free char *vlan_str = NULL; + + vlan = vlans->pdata[i]; + vlan_str = nm_bridge_vlan_to_str (vlan, error); + if (!vlan_str) + return FALSE; + if (string->len > 0) + g_string_append (string, ","); + nm_utils_escaped_tokens_escape_gstr_assert (vlan_str, ",", string); + } + + svSetValueStr (ifcfg, key, string->str); + g_string_free (string, TRUE); + return TRUE; +} + static gboolean write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) { @@ -1534,10 +1571,31 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wire g_string_append_printf (opts, "multicast_snooping=%u", (guint32) b); } + b = nm_setting_bridge_get_vlan_filtering (s_bridge); + if (b != get_setting_default_boolean (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_VLAN_FILTERING)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "vlan_filtering=%u", (guint32) b); + } + + i = nm_setting_bridge_get_vlan_default_pvid (s_bridge); + if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "default_pvid=%u", i); + } + if (opts->len) svSetValueStr (ifcfg, "BRIDGING_OPTS", opts->str); g_string_free (opts, TRUE); + if (!write_bridge_vlans ((NMSetting *) s_bridge, + NM_SETTING_BRIDGE_VLANS, + ifcfg, + "BRIDGE_VLANS", + error)) + return FALSE; + svSetValueStr (ifcfg, "TYPE", TYPE_BRIDGE); *wired = write_wired_for_virtual (connection, ifcfg); @@ -1550,7 +1608,7 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError ** { NMSettingBridgePort *s_port; guint32 i; - GString *opts; + GString *string; s_port = nm_connection_get_setting_bridge_port (connection); if (!s_port) @@ -1559,28 +1617,35 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError ** svUnsetValue (ifcfg, "BRIDGING_OPTS"); /* Bridge options */ - opts = g_string_sized_new (32); + string = g_string_sized_new (32); i = nm_setting_bridge_port_get_priority (s_port); if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY)) - g_string_append_printf (opts, "priority=%u", i); + g_string_append_printf (string, "priority=%u", i); i = nm_setting_bridge_port_get_path_cost (s_port); if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "path_cost=%u", i); + if (string->len) + g_string_append_c (string, ' '); + g_string_append_printf (string, "path_cost=%u", i); } if (nm_setting_bridge_port_get_hairpin_mode (s_port)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "hairpin_mode=1"); + if (string->len) + g_string_append_c (string, ' '); + g_string_append_printf (string, "hairpin_mode=1"); } - if (opts->len) - svSetValueStr (ifcfg, "BRIDGING_OPTS", opts->str); - g_string_free (opts, TRUE); + if (string->len) + svSetValueStr (ifcfg, "BRIDGING_OPTS", string->str); + g_string_free (string, TRUE); + + if (!write_bridge_vlans ((NMSetting *) s_port, + NM_SETTING_BRIDGE_PORT_VLANS, + ifcfg, + "BRIDGE_PORT_VLANS", + error)) + return FALSE; return TRUE; } @@ -2310,15 +2375,17 @@ write_match_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) num = nm_setting_match_get_num_interface_names (s_match); for (i = 0; i < num; i++) { - gs_free char *to_free = NULL; const char *name; - if (i == 0) + name = nm_setting_match_get_interface_name (s_match, i); + if (!name || !name[0]) + continue; + + if (!str) str = g_string_new (""); else g_string_append_c (str, ' '); - name = nm_setting_match_get_interface_name (s_match, i); - g_string_append (str, _nm_utils_escape_spaces (name, &to_free)); + nm_utils_escaped_tokens_escape_gstr (name, NM_ASCII_SPACES, str); } if (str) @@ -2889,6 +2956,52 @@ write_ip6_setting (NMConnection *connection, return TRUE; } +static void +write_ip_routing_rules (NMConnection *connection, + shvarFile *ifcfg, + gboolean route_ignore) +{ + gsize idx; + int is_ipv4; + + svUnsetAll (ifcfg, SV_KEY_TYPE_ROUTING_RULE4 | SV_KEY_TYPE_ROUTING_RULE6); + + if (route_ignore) + return; + + idx = 0; + + for (is_ipv4 = 1; is_ipv4 >= 0; is_ipv4--) { + const int addr_family = is_ipv4 ? AF_INET : AF_INET6; + NMSettingIPConfig *s_ip; + guint i, num; + + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); + if (!s_ip) + continue; + + num = nm_setting_ip_config_get_num_routing_rules (s_ip); + for (i = 0; i < num; i++) { + NMIPRoutingRule *rule = nm_setting_ip_config_get_routing_rule (s_ip, i); + gs_free const char *s = NULL; + char key[64]; + + s = nm_ip_routing_rule_to_string (rule, + NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE, + NULL, + NULL); + if (!s) + continue; + + if (is_ipv4) + numbered_tag (key, "ROUTING_RULE_", ++idx); + else + numbered_tag (key, "ROUTING_RULE6_", ++idx); + svSetValueStr (ifcfg, key, s); + } + } +} + static char * escape_id (const char *id) { @@ -3111,6 +3224,15 @@ do_write_construct (NMConnection *connection, has_complex_routes_v4 ? "" : "6"); return FALSE; } + if ( ( s_ip4 + && nm_setting_ip_config_get_num_routing_rules (s_ip4) > 0) + || ( s_ip6 + && nm_setting_ip_config_get_num_routing_rules (s_ip6) > 0)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Cannot configure routing rules on a connection that has an associated 'rule%s-' file", + has_complex_routes_v4 ? "" : "6"); + return FALSE; + } route_ignore = TRUE; } else route_ignore = FALSE; @@ -3128,6 +3250,10 @@ do_write_construct (NMConnection *connection, error)) return FALSE; + write_ip_routing_rules (connection, + ifcfg, + route_ignore); + write_connection_setting (s_con, ifcfg); NM_SET_OUT (out_ifcfg, g_steal_pointer (&ifcfg)); diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index f3d58e26..b399a17f 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -36,8 +36,8 @@ #include "nm-core-internal.h" #include "nm-core-utils.h" -#include "nm-utils/nm-enum-utils.h" -#include "nm-utils/nm-io-utils.h" +#include "nm-glib-aux/nm-enum-utils.h" +#include "nm-glib-aux/nm-io-utils.h" #include "c-list/src/c-list.h" /*****************************************************************************/ @@ -878,11 +878,26 @@ _is_all_digits (const char *str) } #define IS_NUMBERED_TAG(key, tab_name) \ + ({ \ + const char *_key2 = (key); \ + \ + ( (strncmp (_key2, tab_name, NM_STRLEN (tab_name)) == 0) \ + && _is_all_digits (&_key2[NM_STRLEN (tab_name)])); \ + }) + +#define IS_NUMBERED_TAG_PARSE(key, tab_name, out_idx) \ ({ \ const char *_key = (key); \ + gint64 _idx; \ + gboolean _good = FALSE; \ + gint64 *_out_idx = (out_idx); \ \ - ( (strncmp (_key, tab_name, NM_STRLEN (tab_name)) == 0) \ - && _is_all_digits (&_key[NM_STRLEN (tab_name)])); \ + if ( IS_NUMBERED_TAG (_key, ""tab_name"") \ + && (_idx = _nm_utils_ascii_str_to_int64 (&_key[NM_STRLEN (tab_name)], 10, 0, G_MAXINT64, -1)) != -1) { \ + NM_SET_OUT (_out_idx, _idx); \ + _good = TRUE; \ + } \ + _good; \ }) static gboolean @@ -919,10 +934,30 @@ _svKeyMatchesType (const char *key, SvKeyType match_key_type) if (IS_NUMBERED_TAG (key, "SRIOV_VF")) return TRUE; } + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_ROUTING_RULE4)) { + if (IS_NUMBERED_TAG_PARSE (key, "ROUTING_RULE_", NULL)) + return TRUE; + } + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_ROUTING_RULE6)) { + if (IS_NUMBERED_TAG_PARSE (key, "ROUTING_RULE6_", NULL)) + return TRUE; + } return FALSE; } +gint64 +svNumberedParseKey (const char *key) +{ + gint64 idx; + + if (IS_NUMBERED_TAG_PARSE (key, "ROUTING_RULE_", &idx)) + return idx; + if (IS_NUMBERED_TAG_PARSE (key, "ROUTING_RULE6_", &idx)) + return idx; + return -1; +} + GHashTable * svGetKeys (shvarFile *s, SvKeyType match_key_type) { @@ -947,6 +982,42 @@ svGetKeys (shvarFile *s, SvKeyType match_key_type) return keys; } +static int +_get_keys_sorted_cmp (gconstpointer a, + gconstpointer b, + gpointer user_data) +{ + const char *k_a = *((const char *const*) a); + const char *k_b = *((const char *const*) b); + gint64 n_a; + gint64 n_b; + + n_a = svNumberedParseKey (k_a); + n_b = svNumberedParseKey (k_b); + NM_CMP_DIRECT (n_a, n_b); + NM_CMP_RETURN (strcmp (k_a, k_b)); + nm_assert_not_reached (); + return 0; +} + +const char ** +svGetKeysSorted (shvarFile *s, + SvKeyType match_key_type, + guint *out_len) +{ + gs_unref_hashtable GHashTable *keys_hash = NULL; + + keys_hash = svGetKeys (s, match_key_type); + if (!keys_hash) { + NM_SET_OUT (out_len, 0); + return NULL; + } + return (const char **) nm_utils_hash_keys_to_array (keys_hash, + _get_keys_sorted_cmp, + NULL, + out_len); +} + /*****************************************************************************/ const char * diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 622bb474..b38a8557 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -40,6 +40,8 @@ typedef enum { SV_KEY_TYPE_TC = (1LL << 3), SV_KEY_TYPE_USER = (1LL << 4), SV_KEY_TYPE_SRIOV_VF = (1LL << 5), + SV_KEY_TYPE_ROUTING_RULE4 = (1LL << 6), + SV_KEY_TYPE_ROUTING_RULE6 = (1LL << 7), } SvKeyType; const char *svFileGetName (const shvarFile *s); @@ -67,8 +69,14 @@ char *svGetValueStr_cp (shvarFile *s, const char *key); int svParseBoolean (const char *value, int def); +gint64 svNumberedParseKey (const char *key); + GHashTable *svGetKeys (shvarFile *s, SvKeyType match_key_type); +const char **svGetKeysSorted (shvarFile *s, + SvKeyType match_key_type, + guint *out_len); + /* return TRUE if resolves to any truth value (e.g. "yes", "y", "true") * return FALSE if resolves to any non-truth value (e.g. "no", "n", "false") * return otherwise diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected index c478db38..a8ff8df3 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected @@ -2,6 +2,7 @@ HWADDR=31:33:33:37:BE:CD MTU=1492 TYPE=Ethernet BRIDGING_OPTS="priority=50 path_cost=33" +BRIDGE_PORT_VLANS="1 untagged,2 pvid,4-4094 untagged" NAME="Test Write Bridge Component" UUID=${UUID} ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected new file mode 100644 index 00000000..0c2fa035 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected @@ -0,0 +1,19 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +ROUTING_RULE_1="priority 10 from 0.0.0.0/0 table 1" +ROUTING_RULE_2="priority 10 to 192.167.8.0/24 table 2" +ROUTING_RULE6_3="priority 10 from ::/0 table 10" +ROUTING_RULE6_4="priority 10 to 1:2:3::5/24 table 22" +ROUTING_RULE6_5="priority 10 to 1:3:3::5 table 55" +NAME="Test Write Routing Rules" +UUID=${UUID} +ONBOOT=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main index 2bc987c2..1788efe2 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main @@ -4,5 +4,5 @@ TYPE=Bridge BOOTPROTO=dhcp STP=on DELAY=2 -BRIDGING_OPTS="priority=32744 hello_time=7 max_age=39 ageing_time=235352 multicast_snooping=0 group_fwd_mask=24" +BRIDGING_OPTS="priority=32744 hello_time=7 max_age=39 ageing_time=235352 multicast_snooping=0 group_fwd_mask=24 vlan_filtering=1 default_pvid=99" MACADDR=00:16:41:11:22:33 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 b352fbfc..49ab04d4 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -49,7 +49,7 @@ #include "nm-setting-vlan.h" #include "nm-setting-dcb.h" #include "nm-core-internal.h" -#include "nm-ethtool-utils.h" +#include "nm-libnm-core-intern/nm-ethtool-utils.h" #include "NetworkManagerUtils.h" @@ -4465,6 +4465,101 @@ test_write_wired_dhcp (void) nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); } +static NMIPRoutingRule * +_ip_routing_rule_new (int addr_family, + const char *str) +{ + NMIPRoutingRuleAsStringFlags flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE; + gs_free_error GError *local = NULL; + NMIPRoutingRule *rule; + + if (addr_family != AF_UNSPEC) { + if (addr_family == AF_INET) + flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET; + else { + g_assert (addr_family == AF_INET6); + flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET6; + } + } + + rule = nm_ip_routing_rule_from_string (str, + NM_IP_ROUTING_RULE_AS_STRING_FLAGS_VALIDATE + | flags, + NULL, + nmtst_get_rand_bool () ? &local : NULL); + nmtst_assert_success (rule, local); + + if (addr_family != AF_UNSPEC) + g_assert_cmpint (nm_ip_routing_rule_get_addr_family (rule), ==, addr_family); + return rule; +} + +static void +_ip_routing_rule_add_to_setting (NMSettingIPConfig *s_ip, + const char *str) +{ + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; + + rule = _ip_routing_rule_new (nm_setting_ip_config_get_addr_family (s_ip), str); + nm_setting_ip_config_add_routing_rule (s_ip, rule); +} + +static void +test_write_routing_rules (void) +{ + 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; + + connection = nm_simple_connection_new (); + + s_con = (NMSettingConnection *) nm_setting_connection_new (); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "Test Write Routing Rules", + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), + NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, + NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, + NULL); + + s_wired = (NMSettingWired *) nm_setting_wired_new (); + nm_connection_add_setting (connection, NM_SETTING (s_wired)); + + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + 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); + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); + nm_connection_add_setting (connection, NM_SETTING (s_ip6)); + + g_object_set (s_ip6, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + + _ip_routing_rule_add_to_setting (s_ip4, "pref 10 from 0.0.0.0/0 table 1"); + _ip_routing_rule_add_to_setting (s_ip4, "priority 10 to 192.167.8.0/24 table 2"); + _ip_routing_rule_add_to_setting (s_ip6, "pref 10 from ::/0 table 10"); + _ip_routing_rule_add_to_setting (s_ip6, "pref 10 from ::/0 to 1:2:3::5/24 table 22"); + _ip_routing_rule_add_to_setting (s_ip6, "pref 10 from ::/0 to 1:3:3::5/128 table 55"); + + nmtst_assert_connection_verifies (connection); + + _writer_new_connec_exp (connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Routing_Rules.cexpected", + &testfile); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); +} + static void test_write_wired_match (void) { @@ -7507,6 +7602,8 @@ test_read_bridge_main (void) g_assert_cmpuint (nm_setting_bridge_get_ageing_time (s_bridge), ==, 235352); g_assert_cmpuint (nm_setting_bridge_get_group_forward_mask (s_bridge), ==, 24); g_assert (!nm_setting_bridge_get_multicast_snooping (s_bridge)); + g_assert_cmpint (nm_setting_bridge_get_vlan_filtering (s_bridge), ==, TRUE); + g_assert_cmpint (nm_setting_bridge_get_vlan_default_pvid (s_bridge), ==, 99); /* MAC address */ s_wired = nm_connection_get_setting_wired (connection); @@ -7531,6 +7628,8 @@ test_write_bridge_main (void) NMIPAddress *addr; static const char *mac = "31:33:33:37:be:cd"; GError *error = NULL; + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan *vlan; connection = nm_simple_connection_new (); g_assert (connection); @@ -7551,9 +7650,23 @@ test_write_bridge_main (void) s_bridge = (NMSettingBridge *) nm_setting_bridge_new (); nm_connection_add_setting (connection, NM_SETTING (s_bridge)); + vlans = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_bridge_vlan_unref); + vlan = nm_bridge_vlan_new (10, 16); + nm_bridge_vlan_set_untagged (vlan, TRUE); + g_ptr_array_add (vlans, vlan); + vlan = nm_bridge_vlan_new (22, 22); + nm_bridge_vlan_set_pvid (vlan, TRUE); + nm_bridge_vlan_set_untagged (vlan, TRUE); + g_ptr_array_add (vlans, vlan); + vlan = nm_bridge_vlan_new (44, 0); + g_ptr_array_add (vlans, vlan); + g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, mac, NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, 19008, + NM_SETTING_BRIDGE_VLAN_FILTERING, TRUE, + NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, 4000, + NM_SETTING_BRIDGE_VLANS, vlans, NULL); /* IP4 setting */ @@ -7631,6 +7744,8 @@ test_write_bridge_component (void) NMSetting *s_port; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan *vlan; connection = nm_simple_connection_new (); g_assert (connection); @@ -7658,11 +7773,23 @@ test_write_bridge_component (void) NULL); /* Bridge port */ + vlans = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_bridge_vlan_unref); + vlan = nm_bridge_vlan_new (1, 0); + nm_bridge_vlan_set_untagged (vlan, TRUE); + g_ptr_array_add (vlans, vlan); + vlan = nm_bridge_vlan_new (4, 4094); + nm_bridge_vlan_set_untagged (vlan, TRUE); + g_ptr_array_add (vlans, vlan); + vlan = nm_bridge_vlan_new (2, 2); + nm_bridge_vlan_set_pvid (vlan, TRUE); + g_ptr_array_add (vlans, vlan); + s_port = nm_setting_bridge_port_new (); nm_connection_add_setting (connection, s_port); g_object_set (s_port, NM_SETTING_BRIDGE_PORT_PRIORITY, 50, NM_SETTING_BRIDGE_PORT_PATH_COST, 33, + NM_SETTING_BRIDGE_PORT_VLANS, vlans, NULL); nmtst_assert_connection_verifies (connection); @@ -10168,6 +10295,7 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wired/write-dhcp-plus-ip", test_write_wired_dhcp_plus_ip); g_test_add_func (TPATH "wired/write/dhcp-8021x-peap-mschapv2", test_write_wired_dhcp_8021x_peap_mschapv2); g_test_add_func (TPATH "wired/write/match", test_write_wired_match); + g_test_add_func (TPATH "wired/write/routing-rules", test_write_routing_rules); #define _add_test_write_wired_8021x_tls(testpath, scheme, flags) \ nmtst_add_test_func (testpath, test_write_wired_8021x_tls, GINT_TO_POINTER (scheme), GINT_TO_POINTER (flags)) diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c index fd5561ae..239f6415 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -419,17 +419,15 @@ update_wired_setting_from_if_block (NMConnection *connection, static void ifupdown_ip4_add_dns (NMSettingIPConfig *s_ip4, const char *dns) { + gs_free const char **list = NULL; + const char **iter; guint32 addr; - gs_strfreev char **list = NULL; - char **iter; if (dns == NULL) return; - list = g_strsplit_set (dns, " \t", -1); + list = nm_utils_strsplit_set (dns, " \t"); for (iter = list; iter && *iter; iter++) { - if ((*iter)[0] == '\0') - continue; if (!inet_pton (AF_INET, *iter, &addr)) { _LOGW (" ignoring invalid nameserver '%s'", *iter); continue; @@ -524,13 +522,11 @@ update_ip4_setting_from_if_block (NMConnection *connection, /* DNS searches */ search_v = ifparser_getkey (block, "dns-search"); if (search_v) { - gs_strfreev char **list = NULL; - char **iter; + gs_free const char **list = NULL; + const char **iter; - list = g_strsplit_set (search_v, " \t", -1); + list = nm_utils_strsplit_set (search_v, " \t"); for (iter = list; iter && *iter; iter++) { - if ((*iter)[0] == '\0') - continue; if (!nm_setting_ip_config_add_dns_search (s_ip4, *iter)) _LOGW (" duplicate DNS domain '%s'", *iter); } @@ -546,17 +542,15 @@ update_ip4_setting_from_if_block (NMConnection *connection, static void ifupdown_ip6_add_dns (NMSettingIPConfig *s_ip6, const char *dns) { + gs_free const char **list = NULL; + const char **iter; struct in6_addr addr; - gs_strfreev char **list = NULL; - char **iter; if (dns == NULL) return; - list = g_strsplit_set (dns, " \t", -1); + list = nm_utils_strsplit_set (dns, " \t"); for (iter = list; iter && *iter; iter++) { - if ((*iter)[0] == '\0') - continue; if (!inet_pton (AF_INET6, *iter, &addr)) { _LOGW (" ignoring invalid nameserver '%s'", *iter); continue; @@ -640,13 +634,11 @@ update_ip6_setting_from_if_block (NMConnection *connection, /* DNS searches */ search_v = ifparser_getkey (block, "dns-search"); if (search_v) { - gs_strfreev char **list = NULL; - char **iter; + gs_free const char **list = NULL; + const char **iter; - list = g_strsplit_set (search_v, " \t", -1); + list = nm_utils_strsplit_set (search_v, " \t"); for (iter = list; iter && *iter; iter++) { - if ((*iter)[0] == '\0') - continue; if (!nm_setting_ip_config_add_dns_search (s_ip6, *iter)) _LOGW (" duplicate DNS domain '%s'", *iter); } diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index 99a59477..04281f00 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -175,14 +175,14 @@ initialize (NMSettingsPlugin *plugin) const char *ports = ifparser_getkey (block, "bridge-ports"); if (ports) { - guint i; int state = 0; - gs_strfreev char **port_ifaces = NULL; + gs_free const char **port_ifaces = NULL; + gsize i; _LOGD ("parse: found bridge ports %s for %s", ports, block->name); - port_ifaces = g_strsplit_set (ports, " \t", -1); - for (i = 0; port_ifaces[i]; i++) { + port_ifaces = nm_utils_strsplit_set (ports, " \t"); + for (i = 0; port_ifaces && port_ifaces[i]; i++) { const char *token = port_ifaces[i]; /* Skip crazy stuff like regex or all */ @@ -200,7 +200,7 @@ initialize (NMSettingsPlugin *plugin) } if (nm_streq (token, "none")) continue; - if (state == 0 && strlen (token) > 0) { + if (state == 0) { conn = g_hash_table_lookup (priv->eni_ifaces, block->name); if (!conn) { _LOGD ("parse: adding bridge port \"%s\"", token); @@ -280,7 +280,7 @@ initialize (NMSettingsPlugin *plugin) GHashTableIter iter; g_hash_table_iter_init (&iter, priv->eni_ifaces); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) conn)) { + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &conn)) { if (conn) { _nm_settings_plugin_emit_signal_connection_added (NM_SETTINGS_PLUGIN (self), NM_SETTINGS_CONNECTION (conn)); diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index 8c75d8c7..2e06aeb9 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -32,7 +32,7 @@ #include "nms-keyfile-utils.h" #include "nms-keyfile-reader.h" -#include "nm-utils/nm-io-utils.h" +#include "nm-glib-aux/nm-io-utils.h" /*****************************************************************************/ -- cgit 1.3.0-6-gf8a5