Commit graph

6200 commits

Author SHA1 Message Date
Thomas Haller
e896817d80 core: add nm_match_spec_join() function
We have a special implemenation nm_match_spec_split() to split
a string. We also need the reverse operation to be able to convert
a list of specs to string without loss.

(cherry picked from commit bd57d76af8)
2015-07-03 09:24:05 +02:00
Thomas Haller
045841b66c config/trivial: add code comment
(cherry picked from commit 0c6a011e34)
2015-07-03 09:24:05 +02:00
Thomas Haller
1b66696f6a config: add NMConfigGetValueFlags argument to nm_config_data_get_value()
In some cases we want the returned value to be stripped. In some cases,
we want to read the raw value instead of the string parsed by GKeyFile.
Add an flags argument to nm_config_data_get_value(). It is up to the caller
to determine the exact meaning (and whether to strip).

By adding the flags argument, the caller can get the desired behavior easier
without having to workaround it afterwards. But more importantly, it becomes
apparent that there are different ways to retrieve the value and the caller
should decide on the details.

(cherry picked from commit d3e2193783)
2015-07-03 09:24:04 +02:00
Thomas Haller
93ff88fff1 config: strip white space from configuration values
https://bugzilla.gnome.org/show_bug.cgi?id=750659
https://bugzilla.redhat.com/show_bug.cgi?id=1229861
(cherry picked from commit 076ffda6f3)
2015-07-03 09:24:04 +02:00
Thomas Haller
fb71d7c2fd utils: strip whitespace for device spec in nm_match_spec_split()
Via escape sequences, the user still can specify trailing and leading
white spaces: such as "\s \s" will result in 3 spaces.

(cherry picked from commit 7498b670a8)
2015-07-03 09:24:04 +02:00
Thomas Haller
109f6756b8 config: add config utility accessors
(cherry picked from commit 11c0e107b9)
2015-07-03 09:24:04 +02:00
Thomas Haller
e713fb5e99 config: ensure nm_config_get_plugins() to return stripped values
(cherry picked from commit 7e94785f28)
2015-07-03 09:24:04 +02:00
Thomas Haller
df1cd73128 config: fix usage of g_key_file_get_value() vs. g_key_file_get_string()
g_key_file_get_value() returns the raw value as stored in the file.
When accessing a string value, in most cases it is correct to use
g_key_file_get_string() instead.

When working with internals, such as comparing two keyfiles for
equality, g_key_file_get_value() is correct.

When parsing booleans, we parse it based on the raw value.

Fix the usages. This is a change in behavior if the config file
contained unusual strings.

(cherry picked from commit 0abb502ff3)
2015-07-03 09:24:04 +02:00
Thomas Haller
bd83daf408 config: log configuration at startup and on reload
(cherry picked from commit b506c29fe1)
2015-07-03 09:24:04 +02:00
Thomas Haller
cbace6fe06 config: add defines for keyfile groups to "nm-config.h"
Some plugins had their local defines for the name of the sections and
keys in NMConfig. Move those defines to "nm-config.h".

Usually plugins make use of code in core, but not the other
way round. Defining the names inside "nm-config.h" is no violation of
that because the config section names are anyway not local to the
plugin, but global in the shared name-space with other settings.
For example, another plugins shouldn't reuse the section "ifnet".
For that reason, it is correct and consistent to move these defines
to "nm-config.h".
We don't use those names in core, we merely signal their existance.

(cherry picked from commit 6d6ab20be0)
2015-07-03 09:24:04 +02:00
Thomas Haller
c4b1156b04 config: use nm_config_data_get_value_boolean()
This removes duplicate parsing, but also makes all places use the
same str-to-boolean convention.

(cherry picked from commit 1b0ab2129c)
2015-07-03 09:24:04 +02:00
Thomas Haller
76ca6d86ec config: add nm_config_data_get_value_boolean()
(cherry picked from commit a0e92799af)
2015-07-03 09:24:04 +02:00
Thomas Haller
5eeaf4df91 config: add nm_config_parse_boolean() function
Add function to parse as boolean according our NMConfig convention.
Split this out from nm_config_keyfile_get_boolean() so that we can use
it independently. Also, change the return type to gint, so that one might
pass -1 to indicate an invalid/missing boolean value.

Thereby also don't log a warning in nm_config_keyfile_get_boolean()
We don't want to log a warning every time we access a keyfile value.
If we want to warn about invalid values, we should do it once after
the configuration is loaded. And then we should not only do it
for booleans, but for other types as well.

(cherry picked from commit 35d2981546)
2015-07-03 09:24:04 +02:00
Thomas Haller
a771e2ffcf config: add macros NM_CONFIG_GET_DATA and NM_CONFIG_GET_DATA_ORIG
(cherry picked from commit 2c46003e99)
2015-07-03 09:24:04 +02:00
Thomas Haller
4ba8dd09ac config: get rid of @error argument to nm_config_data_get_value()
We don't use this argument. A failure to retrieve a key is (for
every practical purpose) the same as no such key.

(cherry picked from commit a5f7abb842)
2015-07-03 09:24:03 +02:00
Thomas Haller
b1246efc60 libnm: consider ordering for _nm_keyfile_equals()
GKeyFile considers the order of the files, so add a possibility
to check whether to keyfiles are equal -- also with respect to
the order of the elements.

(cherry picked from commit 7fbfaf567d)
2015-07-03 09:24:03 +02:00
Thomas Haller
41d0902dc9 libnm: add keyfile utility functions
(cherry picked from commit 71323122c6)
2015-07-03 09:24:03 +02:00
Thomas Haller
bee9b7e327 config: reload also no-auto-default state
The content of the no-auto-default state file is part of NMConfig.
During a reload, also reload that.

This way, a user could edit the no-auto-default file and it would
be properly reloaded.

(cherry picked from commit 4a8a0b0918)
2015-07-03 09:24:03 +02:00
Thomas Haller
4adecd466e config: fix evaluation of no-auto-default setting
We used to merge the spec list for no-auto-default from keyfile with the
content of the state file. Since the addition of the "except:" spec this
is wrong.
For example, if the user configured:

  no-auto-default=except:mac:11:11:11:11:11

and statefile contained "11:11:11:11:11" and "22:22:22:22:22", we would
wrongly not match "11:11:11:11:11". The two lists must be kept separate,
so that devices that are blocked by internal decision always match.

This separation is also clearer. Now the spec list is devided into a
part that comes from user configuration, and a part that comes from
internal decision.

(cherry picked from commit 3e4458659b)
2015-07-03 09:24:03 +02:00
Thomas Haller
a325abc425 config: refactor processing of 'option+' and 'option-' config settings
We have a hack to extend GKeyFile to support specifying an 'option+'
key. Also add support for 'option-'.

Options that make use of these modifiers can only be string lists.
So do the concatenation not based on plain strings, but by treating
the values as string lists. Also, don't add duplicates.

(cherry picked from commit fab5c6a372)
2015-07-03 09:24:03 +02:00
Thomas Haller
4c45642b8b config: add nm_config_keyfile_set_string_list() utils function
(cherry picked from commit bb4ae800a1)
2015-07-03 09:24:03 +02:00
Thomas Haller
bd2df64bac config: add NM_CONFIG_KEYFILE_LIST_SEPARATOR define
(cherry picked from commit a05e80913e)
2015-07-03 09:24:03 +02:00
Thomas Haller
68a1c54fa2 config/trivial: rename defines for default settings
Make them match to the variable names that we assign them to.

(cherry picked from commit 3c8abc2d5b)
2015-07-03 09:24:03 +02:00
Thomas Haller
0a2325ded0 config: change examples for command line arguments to system default
(cherry picked from commit 27bd7dc938)
2015-07-03 09:24:03 +02:00
Thomas Haller
14202e10b7 config: fix order of processing [connection] sections in NMConfig
We support the "NetworkManager.conf" sections '[connection]' and
'[connection.\+]' (with arbitrary suffix).

Fix the order of how we evaluate these section.

Note that the literal '[connection]' section is always evaluated lastly
after any other '[connection.\+]' section.

Within one file, we want to evaluate the sections in top-to-bottom
order. But accross multiple files, we want to order them
later-files-first. That gives a reasonable behavior if the user
looks at one file, and also if he wants to overwrite configuration
via configuration snippets like "conf.d/99-last.conf".

Note that if a later file extends/overwrites a section defined in an
earlier file, the section is still considered with lower priority
This is intentional, because the user ~extends~ a lower priority
section. If he wants to add a higher priority section, he should
choose a new suffix.

Fixes: dc0193ac02
(cherry picked from commit f8c9863d55)
2015-07-03 09:24:02 +02:00
Thomas Haller
53dcdf8516 config: backport refactoring to no_auto_default_merge_from_file()
The original backport was different then what was done on master.
Make 'nm-config.c' more similar to what we have on master.

Fixes: d510f0a039

(cherry picked from commit 643f042b9b)
2015-07-03 09:24:02 +02:00
Lubomir Rintel
b2a6022de8 config: add configure and quit command line option
Useful for using the feature without having to hardcode it in configuration
(container set up scripts, development).

https://bugzilla.gnome.org/show_bug.cgi?id=744241
(cherry picked from commit bf6073b647)
2015-07-03 09:24:02 +02:00
Thomas Haller
6d1ca9d614 core: replace g_test_initialized() by nm_utils_get_testing()
(cherry picked from commit 9ac4d88ff7)
2015-07-03 09:24:02 +02:00
Thomas Haller
79af56e0b8 keyfile: readd owner check of files (bgo #701112)
Commit 5dc4be54e6 dropped the
owner check for keyfiles to allow running `make check` as root.
Re-add it, but disable the check for tests.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
(cherry picked from commit d4dd9ba3cf)
2015-07-03 09:24:02 +02:00
Thomas Haller
3a46d1ba6e core/tests: add nm_utils_get_testing() function
Code that is testable often needs special hooks to work
both for unit-tests and production.

Add a function nm_utils_get_testing() that returns whether
the code is run as part of a unit-test.

For non-testing mode, nm_utils_get_testing() will return
zero (NM_UTILS_TEST_NONE). For unit tests, the test should call
_nm_utils_set_testing() to configure tested functions.
By specifing the @flags attribute, the test can enable/disable
specific behaviors.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
(cherry picked from commit b9d8dc050a)
2015-07-03 09:24:02 +02:00
Lubomir Rintel
89733404aa build: use compat version of g_clear_pointer()
Ubuntu 12.04 has an ancient version of glib, which we nevertheless support.

(cherry picked from commit eb2b8c2798)
2015-07-03 09:24:01 +02:00
Thomas Haller
a1abe76aec keyfile: support writing certificates as blob inside the keyfile
keyfile should become our main import/export format. It is desirable,
that a keyfile can contain every aspect of a connection.

For blob certificates, the writer in core daemon would always write
them to a file and convert the scheme to path.
This behavior is not great for a (hyptetical) `nmcli connection export`
command because it would have to export them somehow outside of keyfile,
e.g. by writing them to temporary files.

Instead, if the write handler does not handle a certificate, use a
default implementation in nm_keyfile_write() which adds the blob inside
the keyfile.

Interestingly, keyfile reader already supported reading certificate
blobs. But this legacy format accepts the blob as arbitrary
binary without marking the format and without scheme prefix.
Instead of writing the binary data directly, write it with a new
uri scheme "data:;base64," and encode it in base64.

Also go through some lengths to make sure that whatever path
keyfile plugin writes, can be read back again. That is, because
keyfile writer preferably writes relative paths without prefix.
Add nm_keyfile_detect_unqualified_path_scheme() to encapsulate
the detection of pathnames without file:// prefix and use it to
check whether the path name must be fully qualified.

(cherry picked from commit c9a8764ad2)
2015-07-03 09:24:01 +02:00
Thomas Haller
a18e6c81af keyfile: refactor to use reading and writing of keyfile from libnm-core
(cherry picked from commit 57a432fa8a)
2015-07-03 09:24:01 +02:00
Thomas Haller
7617637086 libnm: move _nm_utils_uuid_generate_from_strings() from src/ to libnm-core/
(cherry picked from commit e82293ebf6)
2015-07-03 09:24:00 +02:00
Thomas Haller
e0777a33b6 trivial: rename nm_utils_uuid_generate_from_strings() to _nm_utils_uuid_generate_from_strings()
(cherry picked from commit 67510e323a)
2015-07-03 09:24:00 +02:00
Thomas Haller
0bc93e62f7 keyfile: remove unused struct member ObjectType.privkey_pw_prop in writer.c
(cherry picked from commit b66deb67fa)
2015-07-03 09:24:00 +02:00
Thomas Haller
57c2c844f1 keyfile: handle invalid integer list in keyfile reader get_bytes()
nm_keyfile_plugin_kf_get_integer_list() should always set
@length to zero when returning no integer list. So, this
is probably correct. Still, just to be explicit, anticipate
and handle a missing @tmp_list.

(cherry picked from commit f430774ca0)
2015-07-03 09:24:00 +02:00
Thomas Haller
d655b80dbe keyfile: make reader more strict in handle_as_path()
When interpreting a blob as filename, ensure that it contains
no NUL character (except the last char).

(cherry picked from commit 7b6759b764)
2015-07-03 09:24:00 +02:00
Thomas Haller
36f5c1b278 keyfile: add code comment to cert_writer() and downgrade assertion to g_critical()
(cherry picked from commit 1e4612e476)
2015-07-03 09:23:59 +02:00
Pavel Šimerda
0fe52b9cd7 keyfile: ignore all dot files (bgo#735824)
https://bugzilla.gnome.org/show_bug.cgi?id=735824
(cherry picked from commit 091732e13b)
2015-07-03 09:23:59 +02:00
Thomas Haller
7d065b018b keyfile: add nm_keyfile_plugin_utils_escape_filename() function
We have nm_keyfile_plugin_utils_should_ignore_file() to ignore certain
files based on patterns. We also need a matching escape function to
avoid saving connections with a name we would ignore later.

https://bugzilla.gnome.org/show_bug.cgi?id=735824
(cherry picked from commit a823217b1f)
2015-07-03 09:23:59 +02:00
Thomas Haller
5a63d42de4 keyfile: use locale independent g_ascii_strcasecmp()
https://bugzilla.gnome.org/show_bug.cgi?id=735824
(cherry picked from commit 904677dc88)
2015-07-03 09:23:59 +02:00
Thomas Haller
9293ab5d66 keyfile: retry harder finding a suitable filename in writer()
Try harder to find a suitable filename by appending a counter
to the name.

https://bugzilla.gnome.org/show_bug.cgi?id=740738
(cherry picked from commit 3b1c5ee0fd)
2015-07-03 09:23:59 +02:00
Dan Winship
570582b316 keyfile: fix an uninitialized variable
read_field() was supposed to set *error to NULL if there was no error,
but it missed one case. (If **current was '\0'.)

(cherry picked from commit d746103d75)
2015-07-03 09:23:59 +02:00
Lubomir Rintel
c7a1627ea1 platform: avoid assuming a permanent address is an ethernet address
This gets called for all links via link_get_permanent_address(). This could
easily be an infiniband address and we don't want to assert it's not.

(cherry picked from commit 31c8bd6b69)
2015-07-02 23:04:40 +02:00
Lubomir Rintel
fd06f0498f infiniband: don't crash if the parent interface is not yet there
Just bail politely just like vlans do.

(cherry picked from commit 1a5fec681b)
2015-07-02 23:04:39 +02:00
Thomas Haller
ce0893e532 platform: fix wrong removal of generated enums
Fixes: a130f72d74
(cherry picked from commit 17216ed453)
2015-07-02 16:59:21 +02:00
Thomas Haller
809ddb89f9 platform: mark internal enums to be skipped by glib-mkenums
No need to generate glib type information for these internal
enums.

(cherry picked from commit a130f72d74)
2015-07-02 16:26:54 +02:00
Lubomir Rintel
9dc446cd3f ifcfg-rh: correct the error handling for NM_CONTROLLED=no connections
We ought to set an error if we're returning NULL from
connection_from_file_full(). Also, printing out a warning ourselves makes no
sense -- the caller communicates this if we signal an error by returning NULL.

(cherry picked from commit e27aa5b4d7)
2015-07-02 15:19:47 +02:00
Lubomir Rintel
13cd646b9d ifcfg-rh: don't signal removal of the connection we didn't register
Removal of a NM_CONTROLLED=no connection and subsequent 'nmcli c reload' would
cause a crash.

(cherry picked from commit 3b853de2e9)
2015-07-02 15:19:46 +02:00