Commit graph

41 commits

Author SHA1 Message Date
Thomas Haller
6cd264b0d5 keyfile: ignore GFileMonitor change flags in dir_changed()
When writing a file (for example with `sed -i`) a temporary file
might be created and removed quickly. This causes spurious events
in dir_changed().

(cherry picked from commit 8ba8a55cfa)
2015-03-11 17:07:55 +01:00
Thomas Haller
8c97626918 keyfile: reuse duplicate check from update_connection() in add_connection()
Also during add_connection() we must take special care of not "adding" a
connection with a conflicting UUID. In that case we want to fallback to
"update".

update_connection() already does all the checks, so call
update_connection() from add_connection().

(cherry picked from commit db5c4ce64f)
2015-03-11 17:07:55 +01:00
Thomas Haller
84353078c1 keyfile: cleanup logging
Log lines with a "keyfile:" prefix and show more information about
the loaded connection. Especially printing the UUID is interesting.

(cherry picked from commit 5c2fa92099)
2015-03-11 17:07:55 +01:00
Thomas Haller
1b0fd9fae0 keyfile: read_connections() must skip duplicate connections
If there are keyfiles with duplicate UUIDs, read_connections()
would iterate over the files, loading them as they appear and
overwriting duplicate connections that were just loaded.

For example, have keyfiles 'A' and 'B' with the same UUID.
On start, NM might first load 'A', then 'B'. 'B' would replace the
content of 'A' which was just loaded.
On reload, NM would first overwrite 'B' with 'A', and then again
overwriting 'A' with 'B'.

Fix that by accept the first found connection and don't overwrite
it during the same read_connections() run.

Also sort the files by file modification timestamp so that we
get a reproducible and sensible behavior.

(cherry picked from commit 8a4e64c6aa)
2015-03-11 17:07:55 +01:00
Thomas Haller
b21d0b68fe keyfile: merge update_connection() and new_connection()
new_connection() and update_connection() are very similar as both
must anticipate collisions of UUIDs.

When reloading a connection (update_connection(), previously), the loaded
connection for a certain path might actually replace another existing
connection. In this case, the old connection must be removed, and
the existing one updated instead.
If reloading a connection changes the UUID to a new value, the old
connection must be removed likewise and a new connection added.

Merge both functions into update_connection().

(cherry picked from commit c2fcb680f8)
2015-03-11 17:07:55 +01:00
Thomas Haller
09e88d1d45 keyfile/trival: move code
(cherry picked from commit f41586f00c)
2015-03-11 17:07:55 +01:00
Thomas Haller
2e0293cc81 settings: log connection diffs in replace_settings only where appropriate
Only log connection diffs when we update a connection that we actually
care about.

Note that most plugin specific connections use
nm_settings_connection_replace_settings() in their constructor
to initialize themselves. These occurrences are not interesting
and spam the logfile.

(cherry picked from commit e14ea6818a)
2015-03-11 17:07:55 +01:00
Thomas Haller
d0283bc9e6 settings: fix wrong assertions for calling nm_settings_connection_replace_settings()
(cherry picked from commit c2dc5d3b0f)
2015-03-11 17:07:55 +01:00
Dan Winship
3572160f55 settings: add NMSettingsConnection:filename
Add a "filename" property to NMSettingsConnection, and set it from
keyfile and ifcfg-rh (replacing the existing priv->path variables in
those connection types). (The other plugins either don't use files, or
don't use per-connection files.)

(cherry picked from commits 24a464a7da
and c9002c041d)
2015-01-14 11:35:17 -05:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Thomas Haller
e478d1fb71 all: use _nm_utils_hash_values_to_slist()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Dan Williams
76ac21b26d keyfile: allow "," as unmanaged-devices separator
Only using ";" (the GKeyFile default) often confuses people.
2014-08-15 14:40:02 -05:00
Dan Winship
357efd26e4 libnm-core: include ETH_ALEN/INFINIBAND_ALEN defines in nm-utils.h
Include <linux/if_ether.h> and <linux/if_infiniband.h> from
nm-utils.h, to get ETH_ALEN and INFINIBAND_ALEN, and remove those
includes (as well as <net/ethernet.h> and <netinet/ether.h>, and
various headers that had been included to get the ARPHRD_* constants)
from other files where they're not needed now.
2014-08-07 14:04:14 -04:00
Dan Winship
35f36ba4c3 libnm-core, etc: drop type-based hwaddr funcs, port to length-based ones
Drop the arptype-based nm_utils_hwaddr funcs, and rename the
length-based ones to no longer have _len in their names. This also
switches nm_utils_hwaddr_atoba() to using a length rather than an
arptype, and adds a length argument to nm_utils_hwaddr_valid() (making
nm_utils_hwaddr_valid() now a replacement for nm_utils_hwaddr_aton()
in some places, where we were only using aton() to do validity
checking).
2014-08-07 12:08:16 -04:00
Dan Williams
95e4b6fc1e keyfile: clean up logging connection verify errors
Prevents:

Connection failed to verify: (unknown)
   invalid or missing connection property 'blah blah/foo bar'

Simply removing the warning in reader.c is fine, because callers that
care already log the warning themselves.  Also make the warning in
update_connection() the same as the warning in new_connection().
2014-06-13 15:18:47 -05:00
Dan Williams
3aedc94fa6 keyfile: fix use-after-free and refcounting of invalid changed connections
If a valid connection was updated and still valid, and then was
updated and become invalid, the connection would not be properly
removed from the keyfile plugin's priv->connections hash, and thus
would never be disposed.

This was due to using the direct pointer to the connection's UUID
as the key for the hash table.  When a connection is updated and
its settings are replaced, the old UUID is freed and replaced with
a new pointer.  But the keyfile plugin hash table still uses the
old (now freed) UUID pointer as the key.  Thus when the connection
is updated and becomes invalid, looking up the UUID in the hash
table fails to find the connection, and the connection is not
removed from the hash.

This bug could cause a crash in some cases, if two keys of the
GHashTable hashed to the same value, in which case GLib would
call g_str_equal() on the freed pointer.

Since code other than in the keyfile plugin replaces settings,
we cannot be guaranteed that the pointer won't change.  Avoid all
that and just strdup() the UUID when using it as a key.

(also collapses _internal_new_connection() into its only caller)
2014-06-13 15:18:47 -05:00
Dan Winship
8537db959c settings: use nm_log_info/warning() in settings plugins
Remove the PLUGIN_PRINT() and PLUGIN_WARN() macros and use the
standard NM logging functions instead.

Also changed PLUGIN_PRINT("error: ...") to nm_log_warn("...") in
places.
2014-04-23 10:19:17 -04:00
Dan Winship
51c6269d46 core: add o.fd.NM.Settings.LoadConnections
Add a D-Bus method to reload connection files specified by
filename, and implement it in the ifcfg-rh and keyfile backends.

https://bugzilla.gnome.org/show_bug.cgi?id=709830
2013-11-15 13:30:13 -05:00
Jiří Klimeš
07bf4eb802 keyfile: don't crash when in-memory-only connections don't have paths
If the connection has never been saved to disk, it won't have a path yet,
but that doesn't mean we should crash.  Next, when reloading connections,
only try to do connection matching on connections that have paths, otherwise
all in-memory-only connections would be removed at the end of
read_connections().
2013-11-12 15:04:15 +01:00
Jiří Klimeš
fc9eae55b3 keyfile: replace g_str_equal() with g_strcmp0()
It fixes crash when nm_keyfile_connection_get_path() returns NULL.
2013-11-01 12:38:25 +01:00
Thomas Haller
94bcecdb14 keyfile: always chain-up parent constructor in keyfile dispose method
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-22 19:22:59 +02:00
Dan Williams
b5170903c0 settings: correctly handle connection deletion after unsaved and monitor-connection-files
Plugins that could save connections to disk previously depended on inotify
events from the kernel to know when to signal connection removal; that is
in response to a 'delete' request they would unlink the backing filesystem
resources, get the inotify signal, and cause NM_SETTINGS_CONNECTION_REMOVED
to be emitted.

Unsaved connections don't have any backing resources, so they would never
get the signal emitted, and NMSettings would never forget about them.

Also, when monitor-connection-files=false in the configuration, obviously
the inotify signals will never come in because they aren't set up.

Given that we can no longer rely on inotify, it's best to just explicitly
send out the NM_SETTINGS_CONNECTION_REMOVED signal whenever a connection
is deleted via the D-Bus interface or internally.
2013-08-09 00:54:58 -05:00
Dan Winship
1f81851017 core: add monitor-connection-files=false and ReloadConnections
Add a "monitor-connection-files" config option, which can be set to
"false" to disable automatic reloading of connections on file change.

To go with this, add a new ReloadConnections method on
o.fd.NM.Settings that can be used to manually reload connections, and
add an nm-cli command to call it.
2013-06-14 12:57:47 -03:00
Dan Winship
d575381c28 settings: fix unmanaging of InfiniBand devices
ifcfg-rh didn't let you unmanage an InfiniBand device by hardware
address because it was recording the hardware address with uppercase
letters, while nm_match_spec_hwaddr() required lowercase. Fix this by
making nm_match_spec_hwaddr() match case-insensitively (and remove the
manual lowercasing that several other places were doing to work around
this.)

keyfile didn't let you unmanage an InfiniBand device by hardware
address because it only accepted ARPHRD_ETHER hardware addresses. Fix
that by using nm_utils_hwaddr_valid() instead.
2013-06-13 15:52:51 -03:00
Dan Williams
8a79fb1d41 settings: implement ability to add connections without saving them to disk
We don't always want to immediately write new connections to disk, to
facilitate "runtime" or "temporary" connections where an interface's
runtime config isn't backed by on-disk config.  Also, just because
an interface's configuration is changed doesn't necessarily mean
that new configuration should be written to disk either.

Add D-Bus methods for adding new connections and for updating existing
connections that don't immediately save the connection to disk.

Also add infrastructure to indicate to plugins that the new connection
shouldn't be immediately saved if the connection was added with the
new method.
2013-05-28 12:26:56 -05:00
Dan Williams
9d94000c69 keyfile: don't require a path when creating a keyfile connection 2013-05-28 12:26:55 -05:00
Dan Williams
830f65fc58 keyfile: track connections by UUID not file path
We'll need this for later with unsaved connections.
2013-05-28 12:26:55 -05:00
Dan Winship
b3e8361f0f settings: don't pass config_path to NMSettings and settings plugins
They can just call nm_config_get() now to get the config, and
nm_config_get_path() to get its path.
2013-04-03 10:23:48 -04:00
Jiří Klimeš
df1a1bf69e keyfile: fix reading unmanaged-devices for interface name
[keyfile]
unmanaged-devices=interface-name:eth0
2013-03-14 12:03:47 +01:00
Dan Winship
c308e75b92 core: allow marking a device unmanaged by its interface name
Virtual devices often don't have stable hardware addresses. So allow
for marking a device unmanaged via its interface name instead.

https://bugzilla.gnome.org/show_bug.cgi?id=693684
2013-03-13 16:45:19 -04:00
Colin Walters
dc6f5f5dd7 keyfile: handle NetworkManager.conf not existing
Since in gnome-ostree we're trying to move towards an empty /etc.
We'll create it on demand if necessary.
2013-03-07 15:49:28 -06:00
Colin Walters
21ba714f78 keyfile: Use "goto out" style error handling
Just code cleanup: This is much less error-prone than manual nesting,
and will mesh very well with future changes to use the libgsystem
cleanup macros.
2013-03-07 15:46:15 -06:00
Dan Winship
08f04466e8 all: remove more pointless NULL checks
GObject creation cannot normally fail, except for types that implement
GInitable and take a GError in their _new() method. Some NM types
override constructor() and return NULL in some cases, but these
generally only happen in the case of programmer error (eg, failing to
set a mandatory property), and so crashing is reasonable (and most
likely inevitable anyway).

So, remove all NULL checks after calls to g_object_new() and its
myriad wrappers.

https://bugzilla.gnome.org/show_bug.cgi?id=693678
2013-02-13 13:38:36 -05:00
Jiří Klimeš
eeb19fe216 keyfile: don't rename system connection files (bgo #682570)
When updating connections, it is less confusing to reuse the existing file
instead of renaming files according to connection's ID. That reduces surprises
of moving connection files when a connection is edited.
2012-11-01 11:59:00 +01:00
Dan Williams
644e245c0b keyfile: crash less if conf_file is NULL
If for some reason we have no config file, don't segfault.
2012-01-13 16:42:58 -06:00
Colin Walters
8c6d3040dc keyfile: fix mismatched strdup/g_free
g_strdup is also NULL safe.
2012-01-13 00:34:23 -06:00
Jiří Klimeš
7b7e426b65 settings: pass config file name to settings plugins
Thus plugins will use the correct configuration file, even in case the name
is specified on command line with --config.
2011-11-16 08:56:29 +01:00
Dan Williams
9cba854fa0 settings: ensure transient secrets are ignored when rereading connections (rh #703785)
When a connection changes on-disk, the in-memory copy of it may contain
transient secrets (agent-owned or not saved) that dont' get written out
to disk.  When comparing the on-disk copy to the in-memory copy make sure
transient secrets are ignored so that we don't re-read the on-disk copy
needlessly.
2011-06-07 18:39:18 -05:00
Kjartan Maraas
b224ab8e56 trivial: let g_free and g_strdup handle NULL (bgo #644763) 2011-03-15 00:08:58 -05:00
Jiří Klimeš
c207d020f7 core: use nm_connection_get_id() and nm_connection_get_uuid() to simplify code 2011-03-08 13:41:28 +01:00
Dan Williams
5bcb0832e5 settings: move system-settings/plugins => src/settings/plugins 2011-02-15 11:55:34 -06:00
Renamed from system-settings/plugins/keyfile/plugin.c (Browse further)