Commit graph

12163 commits

Author SHA1 Message Date
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
Thomas Haller
45aba0fe73 libnm: add keyfile support to libnm-core
https://bugzilla.gnome.org/show_bug.cgi?id=744699
(cherry picked from commit 04df4edf48)
2015-07-03 09:24:01 +02:00
Thomas Haller
d086b5e928 keyfile: copy read/writer files to libnm-core
This is the first step to move keyfile to libnm. For now, only
copy the files to make later changes nicer in git-history.

  /bin/cp src/settings/plugins/keyfile/reader.c libnm-core/nm-keyfile-reader.c
  /bin/cp src/settings/plugins/keyfile/reader.h libnm-core/nm-keyfile-reader.h
  /bin/cp src/settings/plugins/keyfile/utils.c  libnm-core/nm-keyfile-utils.c
  /bin/cp src/settings/plugins/keyfile/utils.h  libnm-core/nm-keyfile-utils.h
  /bin/cp src/settings/plugins/keyfile/writer.c libnm-core/nm-keyfile-writer.c
  /bin/cp src/settings/plugins/keyfile/writer.h libnm-core/nm-keyfile-writer.h

(cherry picked from commit 1fc9bc401e)
2015-07-03 09:24:00 +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
21849d73ee libnm: add function nm_setting_802_1x_check_cert_scheme()
When setting the certificate glib properties directly,
we raise a g_warning() when the binary data is invalid.
But since the caller has no access to the validation function,
he cannot easily check whether his action will result
in a warning. Add nm_setting_802_1x_check_cert_scheme() for
that.

While backporting, hide public API from 1.2.

(cherry picked from commit 15926e9eb3)
2015-07-03 09:24:00 +02:00
Thomas Haller
7c6da95f14 trivial: add FIXME code comment about potential race
(cherry picked from commit 0f1fe69422)
2015-07-03 09:24:00 +02:00
Thomas Haller
40b640f9bc libnm: only call strlen() once in NMSetting8021x:path_to_scheme_value()
Also assert that path is not empty.

(cherry picked from commit 11371b5470)
2015-07-03 09:24:00 +02:00
Thomas Haller
ef3cd489e1 libnm: fix clearing memory in file_to_secure_bytes()
If we go through the lengths of clearing the allocated
memory, we must not forget @contents.

(cherry picked from commit 88a79625a6)
2015-07-03 09:24:00 +02:00
Thomas Haller
fa5a6caf2b libnm: ensure valid blob for nm_setting_802_1x_set_*_cert()
A valid blob cannot start with "file://", otherwise it would
break the implementation of the certificate properties in
NMSetting8021x. Simply reject every blob in nm_setting_802_1x_set_ca_cert()
et al. that is not valid according to get_cert_scheme().

(cherry picked from commit cda7b158e2)
2015-07-03 09:24:00 +02:00
Thomas Haller
7642a6c771 libnm: combine get_cert_scheme() and verify_cert() and ensure valid paths for NMSetting8021x
get_cert_scheme() would return PATH scheme for binary data that
later will be rejected by verify_cert(). Even worse, get_cert_scheme()
would not check whether the path is NUL terminated, hence the following
can crash for an invalid connection:

  if (nm_setting_802_1x_get_ca_cert_scheme (s_8021x) == NM_SETTING_802_1X_CK_SCHEME_PATH)
      g_print ("path: %s", nm_setting_802_1x_get_ca_cert_path (s_8021x))

Combine the two functions so that already get_cert_scheme() does
the same validation as verify_cert().

Also change behavior and be more strict about invalid paths:

 - Now, the value is considered a PATH candidate if it starts with "file://",
   (sans NUL character).
   A change is that before, the "file://" (without NUL) would have
   been treated as BLOB, now it is an invalid PATH (UNKNOWN).

 - If the binary starts with "file://" it is considered as PATH but it
   is only valid, if all the fllowing is true:
   (a) the last character must be NUL.
   (b) there is no other intermediate NUL character.
       Before, an intermediate NUL character would have been accepted
       and the remainder would be ignored.
   (c) there is at least one non-NUL character after "file://".
   (d) the string must be fully valid utf8.

   The conditions (b) and (c) are new and some invalid(?) paths
   might no longer validate.
   Checking (d) moved from verify_cert() to get_cert_scheme().
   As set_cert_prop_helper() already called verify_cert(), this
   causes no additional change beyond (b).

(cherry picked from commit e59e68c528)
2015-07-03 09:24:00 +02:00
Thomas Haller
d2b76543bf keyfile: merge branch 'th/keyfile-escape-file-bgo735824'
This changes behavior, in that we now ignore keyfiles that
start with a dot ('.'). This means, that connection with ids
starting with a dot, will be ignored.

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

(cherry picked from commit 6ccb888831)
2015-07-03 09:23:59 +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
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
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
db2fa9455d test: add nmtst_assert_resolve_relative_path_equals() function
(cherry picked from commit cbfa00219e)
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
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
f2b397acf2 build/trivial: cleanup Makefile.am by sorting EXTRA_DIST entries
(cherry picked from commit ad4e6f7fad)
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
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