Commit graph

1420 commits

Author SHA1 Message Date
Ikey Doherty
5c5a553ca6 settings: ensure the keyfile storage directory actually exists
When first trying to write out the connections we need to ensure that the
keyfile directory exists, as the /etc/ tree may be either stateless or
reset initially.

Creating the directory on demand ensures that we have a chance for our
writes to actually work.

[lkundrak@v3.sk: dropped a comment for what seems obvious, minor style
fixes]
2017-08-31 18:29:48 +02:00
Thomas Haller
75dc0fdd27 platform,libnm: cleanup handling of TOS for routes
- kernel ignores rtm_tos for IPv6 routes. While iproute2 accepts it,
  let libnm reject TOS attribute for routes as well.

- move the tos field from NMPlatformIPRoute to NMPlatformIP4Route.

- the tos field is part of the weak-id of an IPv4 route. Meaning,
  `ip route add` can add routes that only differ by their TOS.
2017-08-03 18:51:57 +02:00
Thomas Haller
f5c800885b ifcfg-rh: fix writing/reading TOS for routes in hexadecimal
iproute2 expects TOS in hex.

This is a change in behavior.
2017-08-03 18:51:57 +02:00
Beniamino Galvani
17ec3aef2f bridge: introduce a bridge.group-forward-mask connection property
https://bugzilla.redhat.com/show_bug.cgi?id=1358615
2017-07-27 09:35:11 +02:00
Mike Gorse
6405d17730 Move CONF_DHCP definition to nm-hostname-manager.c
It is only referenced from there. Fixes the build if HOSTNAME_PERSIST_SUSE
is defined.

Fixes: 5bfb7c3c89

https://bugzilla.gnome.org/show_bug.cgi?id=784225
2017-06-27 09:05:42 +02:00
Thomas Haller
2656ba8d1d core: log changes to NMSettingsConnection's flags 2017-06-16 13:47:08 +02:00
Tom Gundersen
6c8fe5754c ifcfg-rh: refactor dbus policy
This drops some redundant rules and orderes the remaining ones by
precedence.

The 'root' rules take precedence over the 'default' rules, so order
the file accordingly.

It is not necessary to repeat send_destination rules, as the default
rules already allows everyone to send to the interface.

Moreover, it is not necessary to restrict the ownership of the name
in the default context, as this is already done by the system-wide
default rule.

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2017-06-15 13:20:55 +02:00
Thomas Haller
238efbbb12 settings: refactor nm_settings_connection_read_and_fill_timestamp()
Coverity complains about not checking the return value:

  src/settings/nm-settings-connection.c:2329: check_return: Calling "g_key_file_load_from_file" without checking return value (as is done elsewhere 6 out of 7 times).

While at it, refactor the code and check whether the timestamp
is valid.
2017-06-02 20:17:30 +02:00
Thomas Haller
c7c47575ce tests: work around coverity false-positives 2017-06-02 20:00:56 +02:00
Lubomir Rintel
0d71c0569f ifcfg: drop an unused variable 2017-05-31 19:50:58 +02:00
Thomas Haller
84f2d226b5 ifcfg-rh: fix build failure in write_wired_setting()
Fixes: f80d0eb29e
2017-05-30 18:27:37 +02:00
Thomas Haller
f80d0eb29e ifcfg-rh: use svSetValueInt64_cond() to write MTU value 2017-05-30 16:37:28 +02:00
Thomas Haller
80c0a37b47 ifcfg-rh: add svSetValueInt64_cond()
There are a lot of places where we want to either write a number,
or conditionally clear it. Like:

    mtu = nm_setting_wireless_get_mtu (s_wireless);
    if (mtu)
        svSetValueInt64 (ifcfg, "MTU", mtu);
    else
        svUnsetValue (ifcfg, "MTU");
2017-05-30 16:35:13 +02:00
Thomas Haller
263c5b9207 ifcfg-rh: cleanup writer by using numbered_tag() helper 2017-05-30 13:40:34 +02:00
Thomas Haller
afc76d78ed ifcfg-rh: move numbered_tag() util to "nms-ifcfg-rh-utils.h" header 2017-05-30 13:40:34 +02:00
Thomas Haller
844bf3d1a2 ifcfg-rh: fix preserving NETMASK key in write_ip4_setting()
To support legacy scripts, we want to write out the NETMASK
key whenever the ifcfg file has a NETMASK key previously.
Note, that we anyway always write the relevant PREFIX key.
The NETMASK is redundant, only there to help legacy scripts.

That was broken, because we would svUnsetValue("NETMASK") before
checking whether the NETMASK key is present.

Also, when saving a connection to ifcfg-rh file that was created
by other tools, we might mix up the numbering. E.g. we never
write out IPADDR0. Hence, turn on legacy mode whenever the ifcfg-rh
file has any key starting with "NETMASK".
2017-05-30 13:39:15 +02:00
Thomas Haller
ba05819c89 ifcfg-rh/tests: add test for reading NETMASK property 2017-05-30 11:10:19 +02:00
Thomas Haller
e9d960740a ifcfg-rh: add svFindFirstKeyWithPrefix() function 2017-05-30 11:10:19 +02:00
Thomas Haller
bdd7d858f3 ifcfg-rh: return from svSetValue*() functions whether anything changed 2017-05-30 11:10:19 +02:00
Thomas Haller
efd462d946 ifcfg-rh: fix writing NETMASK in write_ip4_setting() 2017-05-30 11:10:19 +02:00
Beniamino Galvani
af8aac9b54 ifcfg-rh: omit empty next hop for routes in legacy format
Don't add "via (null)" if the next hop is missing.

https://bugzilla.redhat.com/show_bug.cgi?id=1452648
2017-05-19 17:44:09 +02:00
Lubomir Rintel
99c112a493 ifcfg-rh: save/restore WPS properties 2017-05-15 12:59:55 +02:00
Lubomir Rintel
f87912326c settings-connection: all method to internally supply new secrets
It's sort of a very very lightweight version of get_secrets_done_cb()
that allows as to add secrets to the connection that didn't come from
the agent manager.
2017-05-15 12:59:55 +02:00
Lubomir Rintel
63836f3945 ifcfg-rh: don't skip 802-11-security if there's no WPA-PSK 2017-05-15 12:59:55 +02:00
Thomas Haller
54f5407abf hostname: cache hostname-manager's hostname property
A property preferably only emits a notify-changed signal when
the value actually changes and it caches the value (so that
between property-changed signals the value is guaranteed not to change).

NMSettings and NMManager both already cache the hostname, because
NMHostnameManager didn't guarantee this basic concept.

Implement it and rely on it from NMSettings and NMPolicy.
And remove the copy of the property from NMManager.

Move the call for nm_dispatcher_call_hostname() from NMHostnameManager
to NMManager. Note that NMPolicy also has a call to the dispatcher
when set-transient-hostname returns. This should be cleaned up later.
2017-05-12 17:29:33 +02:00
Thomas Haller
5bfb7c3c89 hostname: split out hostname management from NMSettings
Hostname management is complicated. At least, how it is implemented currently.
For example, NMPolicy also sets the hostname (NMPolicy calls
nm_settings_set_transient_hostname() to have hostnamed set the hostname,
but then falls back to sethostname() in settings_set_hostname_cb()).
Also, NMManager tracks the hostname in NM_MANAGER_HOSTNAME too, and
NMPolicy listens to changes from there -- instead of changes from
NMSettings.

Eventually, NMHostnameManager should contain the hostname parts from NMSettings
and NMPolicy.
2017-05-12 17:29:33 +02:00
Thomas Haller
e827925646 agent-manager: use CList to track requests 2017-05-11 18:26:10 +02:00
Thomas Haller
a844b98259 agent-manager/trivial: move code 2017-05-11 18:26:10 +02:00
Thomas Haller
04dfff7db8 secret-agent: use CList to track requests 2017-05-11 18:26:10 +02:00
Thomas Haller
c12dd0d970 ifcfg-rh: refactor shvar.c to use CList instead of GList 2017-05-11 18:26:10 +02:00
Thomas Haller
79be44d990 ifcfg: add read/write support for user-data
The user data values are encoded in shell variables named
prefix "NM_USER_". The variable name is an encoded form of the
data key, consisting only of upper-case letters, digits, and underscore.

The alternative would be something like

  NM_USER_1_KEY=my.keys.1
  NM_USER_1_VAL='some value'
  NM_USER_2_KEY=my.other.KEY.42
  NM_USER_2_VAL='other value'

contary to

  NM_USER_MY__KEYS__1='some value'
  NM_USER_MY__OTHER___K_E_Y__42='other value'

The advantage of the former, numbered scheme is that it may be easier to
find the key of a user-data entry. With the current implementation, the
shell script would have to decode the key, like the ifcfg-rh plugin
does.

However, user data keys are opaque identifers for values. Usually, you
are not concerned with a certain name of the key, you already know it.
Hence, you don't need to write a shell script to decode the key name,
instead, you can use it directly:

  if [ -z ${NM_USER_MY__OTHER___K_E_Y__42+x} ]; then
      do_something_with_key "$NM_USER_MY__OTHER___K_E_Y__42"
  fi

Otherwise, you'd first have to search write a shell script to search
for the interesting key -- in this example "$NM_USER_2_KEY", before being
able to access the value "$NM_USER_2_VAL".
2017-05-06 14:12:19 +02:00
Thomas Haller
6ef59b5b77 libnm: make NMSettingWirelessSecurity's PMF property signed
The PMF property is an GEnum, not GFlags. We only have the GObject
property NM_SETTING_WIRELESS_SECURITY_PMF as plain integer type
to allow for future extensions.

But commonly, enums are signed int, while flags are unsigned. Change
the property to be signed for consistency.
2017-04-28 17:20:02 +02:00
Thomas Haller
2c46b65923 ifcfg-rh: use cleanup attribute for error handling in reader
Drop some uses of "goto error". Instead, have the memory owned
by an auto variable and automatically release it via the cleanup
attribute.
2017-04-28 12:42:18 +02:00
Thomas Haller
f16ec61a01 ifcfg-rh: use svGetValueEnum() in reader 2017-04-28 12:31:45 +02:00
Thomas Haller
606497a4e9 ifcfg-rh: use svSetValueEnum() in writer 2017-04-28 12:21:17 +02:00
Thomas Haller
7298798a64 ifcfg-rh: add svGetValueEnum() 2017-04-28 12:21:17 +02:00
Thomas Haller
e81bdf19fa ifcfg-rh: add svSetValueEnum() 2017-04-28 12:21:10 +02:00
Beniamino Galvani
53f3113389 ifcfg-rh: support the wifi.pmf property 2017-04-28 09:46:06 +02:00
Thomas Haller
43c3501f97 ifcfg-rh/tests: fix test_write_unknown() after change svGetValue() for invalid values
Fixes: daaa741a3d
2017-04-27 17:52:25 +02:00
Lubomir Rintel
9e668595fe ifcfg-rh: preserve the archaic NETMASK key
py-kickstart writes this out and there apparently are users using this.
Let them have one less problem.

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-27 17:24:23 +02:00
Lubomir Rintel
38fbcdf0e5 ifcfg-rh: preserve the archaic BOOTPROTO=static form
py-kickstart writes this out. Okay -- we don't care on read and it makes
sense when there actually are addresses.

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-27 17:24:23 +02:00
Lubomir Rintel
67fab76bf3 ifcfg: use svSetValueInt64() wherever appropriate
With a little help from coccinelle:

  @@
  identifier string;
  expression value, ifcfg, key;
  @@
  (
  - string = g_strdup_printf ("%u", value);
  |
  - string = g_strdup_printf ("%d", value);
  )
  - svSetValueStr (ifcfg, key, string);
  - g_free (string);
  + svSetValueInt64 (ifcfg, key, value);

Applied with:

  spatch --sp-file nm_platform_get.cocci --in-place --smpl-spacing --dir src

Manually fixed up style issues & dropped unused variables.
2017-04-27 17:24:23 +02:00
Thomas Haller
daaa741a3d ifcfg-rh: treat a wrongly quoted value like empty string
For example, if you want to test whether a value is present and
reset it to a different value (only if it is present), it would
be reasonable to do

    if (svGetValue (s, key, &tmp)) {
        svSetValue (s, key, "new-value");
        g_free (tmp);
    }

Without this patch, you could not be sure that key is not
set to some inparsable value, which svWriteFile() would then
write out as empty string.

Have invalid values returned by svGetValue() as empty string.
That is how svWriteFile() treats them.
2017-04-27 17:24:23 +02:00
Lubomir Rintel
39594852ba ifcfg: remove dead code
Unused since 0c6349c62.
2017-04-27 17:24:19 +02:00
Thomas Haller
5fc4bfc0e3 ifcfg-rh/tests: fix out-of-tree build for cexpected file
Fixes: f04bf45e84
2017-04-27 16:25:20 +02:00
Thomas Haller
f04bf45e84 ifcfg-rh/tests: compare the written files to a expected result
We have unit tests for writing and re-reading ifcfg file. Those
tests compare whether a file can be successfully read and is
semantically identical.

However, there were no tests that a certain output is written in
a stable format. We aim not to change the output of what we write.
For that, add tests to not only check the semantic of the written
ifcfg file, but their bits and bytes.

Some future changes may well intentionally change the current
output. That will require to update the expected result files
and can be done via

  NMTST_IFCFG_RH_UPDATE_EXPECTED=yes src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh

Note that alias, route, and key files are not checked.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-26 12:30:02 +02:00
Thomas Haller
e1e5d0d867 ifcfg-rh/tests: remove unused macro _writer_update_connection_FIXME()
Fixes: 670e088efe
2017-04-25 20:14:34 +02:00
Lubomir Rintel
d4d6272fec ifcfg: don't complain if 8021x secrets are empty
The connection is still valid; and it's easily possible to create it. It would
be a shame if it couldn't be read back.
2017-04-10 10:33:24 +02:00
Lubomir Rintel
0812413c9d ifcfg-rh: fix loading the PKCS#11 client certificate
Contrary to the comment above, the reader would skip the client certificate
even if the key is on PKCS#11 token, not just in a PKCS#12 archive.
2017-04-10 10:33:22 +02:00
Lubomir Rintel
2839da06db settings/secret-agent: add initializers
To make coverity a bit happier.
2017-04-03 13:28:26 +02:00