Commit graph

12188 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
0cbcf21e80 libnm: add @deep_copy argument to _nm_utils_strv_to_slist() and _nm_utils_slist_to_strv()
(cherry picked from commit ed632207cd)
2015-07-03 09:24:05 +02:00
Thomas Haller
1dec33e2af libnm: expose strv utils function in internal header nm-core-internal.h
(cherry picked from commit 93e4a8d102)
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
016d46265f libnm-keyfile/test: fix missing assertion in test
(cherry picked from commit e1b0195c67)
2015-07-03 09:24:03 +02:00
Thomas Haller
582ef15d3e libnm/keyfile: fix compile warning about uninitialized variable
Fixes: 71323122c6
(cherry picked from commit 47551df352)
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
0b10fb15a0 test: add nmtst_assert_success() util
(cherry picked from commit f5177dbf7a)
2015-07-03 09:24:02 +02:00
Thomas Haller
fa0f53b07b macros: add nm_strstrip() util
(cherry picked from commit d6a331bd8c)
2015-07-03 09:24:02 +02:00
Thomas Haller
5cf8d6fd19 libnm: add _nm_utils_strv_cleanup() function
(cherry picked from commit 885d187d23)
2015-07-03 09:24:02 +02:00
Thomas Haller
53223b4842 glib-compat: backport g_key_file_save_to_file()
(cherry picked from commit 69f2d22bfe)
2015-07-03 09:24:02 +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
519ea3f0d4 libnm-keyfile: ensure g_key_file_get_groups() sets the length argument
Under certain cases, if g_key_file_get_groups() fails, it might not set the
out argument @length. Play it safe and initialize it.

(cherry picked from commit aa7a53bc67)
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
92ce214567 core: merge branch 'th/keyfile-owner-check-bgo701112'
Renable checking owner of keyfile files but disable that
behavior for tests.

For that, add a nm_utils_get_testing() function to core to detect
whether the code is running as part of a test.

https://bugzilla.gnome.org/show_bug.cgi?id=701112

(cherry picked from commit 046115b588)
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
06395568e7 keyfile/test: refactor and cleanup _keyfile_convert()
_keyfile_convert() should really test for successful round-trip
conversion of keyfile-connection and vice versa.

(cherry picked from commit 81119c69d8)
2015-07-03 09:24:01 +02:00
Yuri Chornoivan
7eeb6ec593 fix typo and do not translate an empty string
https://bugzilla.gnome.org/show_bug.cgi?id=748906
(cherry picked from commit f851a741a6)
2015-07-03 09:24:01 +02:00
Thomas Haller
c91ca73c9b libnm/keyfile: fix format string for unsigned integer
Fixes: 04df4edf48
(cherry picked from commit d05bedbc0d)
2015-07-03 09:24:01 +02:00
Thomas Haller
518a5781ee keyfile: merge branch 'th/libnm-keyfile-bgo744699'
Move basic keyfile functionality from settings plugin to libnm-core.
This is a first step to have a semi-standard way to stringify
connections back and forth, which is also available to libnm users.

Still the new functions are internal API (nm-keyfile-internal.h).
Let's decide later how the public API should really look like.

https://bugzilla.gnome.org/show_bug.cgi?id=744699

(cherry picked from commit 59eb5312a5)
2015-07-03 09:24:01 +02:00
Thomas Haller
e977e55e94 test: add nmtst_create_connection_from_keyfile()
(cherry picked from commit 997fc07ca5)
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
46ebed64f4 libnm: add define for cert scheme prefix file:// for NMSetting8021x
(cherry picked from commit a49680dacd)
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
176e4a3f54 libnm: merge nm-keyfile-reader.h and nm-keyfile-writer.h to internal header
These headers are not entirely private to libnm-core as they are also
used by keyfile plugin. Merge them to a new header file
nm-keyfile-internal.h so that the name makes the internal nature of the
header more apparent.

(cherry picked from commit 5e5afcffce)
2015-07-03 09:24:01 +02:00