Commit graph

307 commits

Author SHA1 Message Date
Dan Winship
2b78a1d53b libnm-core: add _nm_dbus_error_has_name()
Add a method for checking the D-Bus error name of an error.

(cherry picked from commit ec6f350f44)
2015-08-19 12:59:39 +02:00
Thomas Haller
6d2a1edc38 macros: use short-circuit evaluation in NM_IN_SET()
All current users of NM_IN_SET() would rather use short-circuit evalation
(or don't care). It seems that doing it by default seems favorable.

The only downside is, that this might have somewhat unexpected behavior
to a user who expects a regular function (which would evaluate always
all arguments).

Fixes: 7860ef959a
(cherry picked from commit 96cacc07e8)
2015-08-12 16:07:22 +02:00
Thomas Haller
69b276d6d1 macros: rework NM_IN_SET() macro to expand to a plain logical expression
Let the preprocessor do more work, but generate a simple expression that
the compiler can optimize (presumably) better.

(cherry picked from commit 7860ef959a)
2015-08-12 16:07:02 +02:00
Lubomir Rintel
6f616d4c4b libnm-core,libnm-util: drag in glib.h for nm-version.h
G_UNAVAILABLE defines need it.

Fix building of the Qt example.
2015-07-23 10:06:41 +02:00
Thomas Haller
9cfdbf6a06 libnm-core: don't assert against non-NULL @ip argument to canonicalize_ip()
Remove an assertion in canonicalize_ip() to assert that either a
non-NULL @ip is given, or @null_any is TRUE.

The condition of the assert is not easy to understand without context.
Instead the caller should already handle %NULL properly.

All callers that pass @null_any=FALSE to canonicalize_ip(), already assert
that the argument is not %NULL. With the exception of nm_ip_route_new()
which however checks for a valid @dest early on.

(cherry picked from commit 7f129b976c)
2015-07-22 14:50:51 +02:00
Lubomir Rintel
2958b3d1af libnm-core: 0.0.0.0 is a valid gateway too
It makes sense for point-to point links.

https://bugzilla.redhat.com/show_bug.cgi?id=1244483
(cherry picked from commit f14fd048ff)
2015-07-22 14:50:51 +02:00
Thomas Haller
89b630ff32 libnm-core: fix nm-setting-ip-config.c:valid_ip() to handle %NULL argument
We call valid_ip() from nm_ip_route_new() to check whether an untrusted string
is a valid ip address. Properly handle %NULL argument.

Fixes: 21c8a6b20e
(cherry picked from commit 9342568694)
2015-07-22 14:50:51 +02:00
Thomas Haller
fa2b8fdbdf libnm-core: properly handle %NULL @ip in nm_utils_ipaddr_valid()
A is_valid() function should just accept NULL as input and
return "invalid". It certainly should not crash.

Fixes: 21c8a6b20e
(cherry picked from commit 2b55de8560)
2015-07-22 14:50:51 +02:00
Beniamino Galvani
975afac6a4 ifcfg-rh: add support for CONNECTION_METERED
(cherry picked from commit 7e5e624daf)
2015-07-22 13:52:46 +02:00
Beniamino Galvani
4eb05767ee libnm-core: add 'metered' property to NMSettingConnection
Add a 'metered' enum property to NMSettingConnection with possible
values: unknown,yes,no. The value indicates the presence of limitations
in the amount of traffic flowing through the connection.

(cherry picked from commit 6f647fe689)
2015-07-22 13:52:45 +02:00
Beniamino Galvani
77a7e913a2 core,libnm: add 'metered' property to NMDevice
(cherry picked from commit bbbf522941)
2015-07-22 13:52:45 +02:00
Beniamino Galvani
1fa10e9766 build: add NM_AVAILABLE_IN_1_0_6 define 2015-07-22 13:49:31 +02:00
Jiří Klimeš
3af6be7aa6 docs: fix a copy/paste error in description of VLAN flags
(cherry picked from commit 2af10ef444)
2015-07-17 11:50:42 +02:00
David Shea
bfb6c78430 libnm: handle illegal characters in nm_utils_ssid_to_utf8() (rh #1243078)
g_convert_with_fallback() will fail if the SSID contains characters that
are not legal in the source encoding, which, if $LANG is not set, will
be ASCII. If this happens, replace all non-ASCII and non-printable
characters with '?'. It is possible that nm_utils_ssid_to_utf8() will
now return an empty string (e.g., the source string is actually
big-endian UTF-16 and g_strcanon() stops on the first byte), but it will
not return NULL.

https://bugzilla.redhat.com/show_bug.cgi?id=1243078

(cherry picked from commit 568b4ad31f)
2015-07-16 14:24:47 +02:00
Thomas Haller
a51a95b7b3 build/trivial: move declaration of NM_AVAILABLE_IN_0_9_10 macro
Move the declaration of the macro to make it more similar to the
version file on master.
2015-07-15 10:41:27 +02:00
Thomas Haller
c27385b401 build: add NM_VERSION_1_0_6 macro and bump NM_VERSION_CUR_STABLE 2015-07-15 10:36:45 +02:00
Jiří Klimeš
c73eeb39f5 supplicant: allow with_system_ca_path to be a file name (rh #1236548)
NetworkManager uses wpa_supplicant, which in turn calls OpenSSL for verifying
certificates. wpa_supplicant calls
SSL_CTX_load_verify_locations(ctx, CAfile, CApath)
using its ca_cert and ca_path options as CAfile and CApath parameters.

We have a configure time option with_system_ca_path to override ca_path.
However, it doesn't work when a system (like Fedora) only uses bundled PEM
certificates instead of a directory with hashed certificates ([1], [2]).

So this commit allows setting --with_system_ca_path to a file name (the
trusted certificate bundle). Then the name is used to populate wpa_supplicant's
ca_cert instead of ca_path.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1053882
[2] https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/

https://bugzilla.redhat.com/show_bug.cgi?id=1236548

(cherry picked from commit 640eb8f284)
2015-07-08 17:12:19 +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
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
5cf8d6fd19 libnm: add _nm_utils_strv_cleanup() function
(cherry picked from commit 885d187d23)
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
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
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
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
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
976726f221 libnm: add _nm_utils_ptrarray_find_binary_search() helper
(cherry picked from commit 650fec81e2)
2015-07-01 16:10:50 +02:00
Beniamino Galvani
5fc247347f device: restart ping process when it exits with an error
When ping is launched to check the connectivity to the gateway it may
return earlier than the given timeout in case of error. When this
happens we need to respawn it until the timeout is reached.

While at it, increase maximum timeout value to 600 seconds.

https://bugzilla.redhat.com/show_bug.cgi?id=1128581
(cherry picked from commit e86f8354a7)
2015-07-01 13:51:06 +02:00
Thomas Haller
b30e7c9c61 version: add missing NM_AVAILABLE_IN_1_0_4 2015-06-26 16:43:01 +02:00
Thomas Haller
d407727f61 libnm: fix backported autoconnect-slaves symbols in libnm.ver
On master, we added new symbols
  nm_setting_connection_autoconnect_slaves_get_type()
  nm_setting_connection_get_autoconnect_slaves()
in the libnm_1_2_0 section.

It is wrong to extend the linker section of a stable
release. When backporting the patch we must create a
new linker section.

Move the symbols to the libnm_1_0_4 section. Note that
master (1.1) also defines the symbol there, so that the
upgrade path works.

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

Fixes: 408b631673
2015-06-26 16:33:34 +02:00
Thomas Haller
56317613bd build: add NM_AVAILABLE_IN_1_0_4 define 2015-06-26 16:33:34 +02:00
Thomas Haller
e4a9698fa3 build: update NM_VERSION_CUR_STABLE and NM_VERSION_NEXT_STABLE 2015-06-26 16:33:34 +02:00
Thomas Haller
58991bea61 build: add NM_VERSION_1_0_2 and NM_VERSION_1_0_4 version defines 2015-06-26 16:33:34 +02:00