Commit graph

107 commits

Author SHA1 Message Date
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
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
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
41d0902dc9 libnm: add keyfile utility functions
(cherry picked from commit 71323122c6)
2015-07-03 09:24:03 +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
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
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
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
Jiří Klimeš
e585c4d4f3 all: fix additional compiler warningis about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments

(cherry picked from commit 2dc27a99d7)
2015-06-22 09:56:05 +02:00
Thomas Haller
fb0443def9 glib-compat: add g_ptr_array_insert()
(cherry picked from commit 2f4301bd26)
2015-06-21 15:32:11 +02:00
Thomas Haller
5daac57a23 utils: add nm_utils_is_power_of_two() macro
(cherry picked from commit 0a3c1f5774)
2015-06-21 15:30:47 +02:00
Jiří Klimeš
60080377a2 all: fix a compiler warning about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments

(cherry picked from commit 94a393e9ed)
2015-06-19 12:40:54 +02:00
Jiří Klimeš
408b631673 libnm: add autoconnect-slaves property to NMSettingConnection
The property is used for controlling whether slaves should be brought up with
a master connection. If 0, activating the master will not activate slaves.
But if set to 1, activating the master will bring up slaves as well.
The property can have the third state (-1), meaning that the value is default.
That is either a value set in the configuration file for the property, or 0.

(cherry picked from commit 6caafab258)
2015-06-19 12:18:51 +02:00
Lubomir Rintel
0f95b5c345 builds: only enable TAP driver for glib >= 2.37.6
No TAP support for previous versions and --tap argument is silently ignored,
confusing the TAP driver.

(cherry picked from commit c47c06470a)
2015-06-19 11:52:50 +02:00
Lubomir Rintel
fe3e32c034 tests: use the TAP formatter
The test results in standard format are easily integrated into CI systems.

(cherry picked from commit 6463ce5dd9)
2015-06-19 11:52:50 +02:00
Lubomir Rintel
62172a9a9e tests: move all asserts into tests
Otherwise the TAP formatter would produce a plan-less output.

(cherry picked from commit f627d6db8e)
2015-06-19 11:52:49 +02:00
Thomas Haller
ba285e319e libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/
(cherry picked from commit c5d23737fd)
2015-06-17 13:30:39 +02:00
Lubomir Rintel
411fa7d002 test: initialize auto-destructed pointers
Otherwise the compiler complains that they could be left uninitialized in case
the function returns too early.

Fixes: 76745817c3
(cherry picked from commit 2981839bde)
2015-03-13 11:50:50 +01:00
Thomas Haller
b9a8f3c059 tests: enable valgrind tests for tests
(cherry picked from commit c50f30e79c)
2015-03-13 11:50:04 +01:00
Thomas Haller
2eb71b6229 libnm/tests: fix memleaks in tests for valgrind
(cherry picked from commit ae73320b8c)
2015-03-13 11:50:04 +01:00
Dan Winship
f40a69f624 libnm-core: validate property types from D-Bus (rh #1182567)
In _nm_setting_new_from_dbus(), verify that the properties have the
right types, and return an error if not. (In particular, don't crash
if someone tries to assign a GBytes-valued property a non-'ay' value.)

(cherry picked from commit 76d9fc9167)
2015-01-16 09:11:14 -05:00
Thomas Haller
35f95de60e libnm/tests: make tested IPv4 addresses non-palindromic
For IPv4 addresses, the binary representation is in network-order,
contrary to host-order. It's better to choose addresses for testing
that are differently on big and little endian systems.

(cherry picked from commit 1bef194302)
2014-12-19 14:06:05 +01:00
Thomas Haller
648e1c7277 libnm/tests: fix build failure on big-endian machines
`make check` fails:

  make  check-TESTS
  make[4]: Entering directory `/builddir/build/BUILD/NetworkManager-1.1.0/libnm-core/tests'
  ...
  /core/general/test_setting_802_1x_changed_signal: OK
  /core/general/test_setting_ip4_gateway: **
  ERROR:test-general.c:3652:test_setting_ip4_gateway: assertion failed (nm_setting_ip_config_get_gateway (s_ip4) == "192.168.1.1"): ("1.1.168.192" == "192.168.1.1")
  /bin/sh: line 5: 44957 Aborted                 (core dumped) ${dir}$tst

(cherry picked from commit 7990add493)
2014-12-19 14:06:05 +01:00
Jiří Klimeš
7ee93a0029 tests: mute coverity for CHECKED_RETURN (CWE-252) in tests
Error: CHECKED_RETURN (CWE-252): [#def12]
NetworkManager-0.9.11.0/libnm-core/tests/test-general.c:348: check_return: Calling "nm_setting_verify" without checking return value (as is done elsewhere 37 out of 45 times).
...

(cherry picked from commit 6603e7ffde)
2014-12-16 21:47:01 +01:00
Thomas Haller
cd025f05f7 libnm: normalize connections in nm_simple_connection_new_from_dbus()
Before we would just call verify() and only return valid connections
without attempting to fix them.

It is better to use normalize(), because that function is especially there to
accept and repair deprecated configurations that would no longer verify().

This changes behavior in the way that the function now accepts connections
that would have been rejected before.

Since commit b88715e05b normalize() also
adds a missing UUID. Hence this also affects the DBUS method 'AddConnection'
in that it now accepts connections without UUID. Previously, clients were
required to set a UUID for the new connection, now NM core can create a random
one if no UUID is set.

https://bugzilla.gnome.org/show_bug.cgi?id=740813
2014-12-05 11:04:20 +01:00
Thomas Haller
924fd189b8 libnm: allow empty strings for nm_utils_uuid_generate_from_string()
Since commit ef3de46c43
crypto_md5_hash() allows empty password. Also support
empty strings for nm_utils_uuid_generate_from_string().
2014-12-04 17:02:22 +01:00
Thomas Haller
b88715e05b libnm: normalize missing connection UUID
Extend nm_connection_normalize() to add a connection UUID
in case it is unset.
2014-12-04 17:02:22 +01:00
Thomas Haller
e7661c9b52 libnm: implement variant3 UUIDs according to rfc4122
Compare the results:
  perl -e 'use UUID::Tiny ":std"; print(uuid_to_string(create_uuid(UUID_V3, UUID_NS_DNS, "test"))."\n");'
  python -c 'from uuid import *; print(uuid3(UUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), "test"))'
2014-12-04 17:02:22 +01:00
Thomas Haller
1e313e000d libnm: add a type argument to nm_utils_uuid_generate_from_string()
There are different types (variants) of UUIDs defined.
Especially variants 3 and 5 are name based variants (rfc4122).

The way we create our UUIDs in nm_utils_uuid_generate_from_string()
however does not create them according to RFC and does not set
the flags to indicate the variant.

Modify the signature of nm_utils_uuid_generate_from_string() to accept
a "uuid_type" argument, so that we later can add other algorithms without
breaking API.
2014-12-04 17:02:22 +01:00
Thomas Haller
21eb6b5d0d libnm: accept additional length argument in nm_utils_uuid_generate_from_string()
This makes the function also useful for non C-strings,
non UTF-8-strings, and generic blobs.
2014-12-04 17:02:22 +01:00
Thomas Haller
e67425347a libnm/test: add test for nm_utils_uuid_generate_from_string() 2014-12-04 17:02:22 +01:00
Thomas Haller
ea14a0136f crypto/test: test crypto_md5_hash() for empty passwords
Empty passwords are allowed since commit
ef3de46c43 .
2014-12-04 17:00:55 +01:00
Dan Winship
d91bcc4960 libnm-core: drop nm_utils_rsa_key_encrypt(), _encrypt_aes()
In general, we shouldn't end up with an unencrypted copy of a
certificate key anyway, so this function ought to be unnecessary (or
at least, not broadly useful enough to be in the public API).
nm-applet's GConf migration tool needs it, but that will eventually go
away, and until then it can just use libnm-util.
2014-12-04 08:39:54 -05:00
Thomas Haller
ef3de46c43 libnm-core: relax restrictions on input arguments for crypto_md5_hash()
crypto_md5_hash() only has two users:
 (a) crypto_make_des_aes_key()
 (b) nm_utils_uuid_generate_from_string()

For (b) it is just a complicated way to compute the MD5 hash. The
restrictions on salt and password don't matter. Actually they
are harmful because we cannot compute the MD5 hash of the empty
word.
For (a), the caller should make sure to pass whatever restrictions
he wants to enforce on the data.

For example, it is counterintuitive, that crypto_md5_hash() would
require @salt_len, enforce it to be at least 8 bytes, and then just
use the first 8 bytes. If the caller (a) wants that behavior, he
should make sure that he passes in 8 bytes.
Likewise for the empty word. If the caller does not want to compute
the hash of empty passwords, he must not hash them.

Indeed, all of this was enforced by assertions, any caller already
did the right thing.
2014-12-04 08:39:54 -05:00
Dan Winship
3b86cc047e libnm: remove nm_utils_init() from the public API
Remove nm_utils_init() from the public API, and just do it as a
constructor instead.
2014-12-04 08:39:54 -05:00
Dan Winship
bddc0de51e libnm-core: call crypto_init() on the fly
Rather than requiring crypto_init() to have been called beforehand,
just have every method that depends on it call it itself.

This required adding a GError argument to crypto_is_pkcs12_data(),
which in turn required a few other changes elsewhere.
2014-12-04 08:39:54 -05:00
Dan Winship
48ff21b5bc libnm-core: reimplement crypto_md5_hash() using GChecksum
Reimplement crypto_md5_hash() using GChecksum. Remove the gboolean
return value and GError argument, since it cannot fail now.
2014-12-04 08:39:54 -05:00
Dan Winship
34519eee13 tests: add a test of libnm-core's crypto_md5_hash() 2014-12-04 08:39:54 -05:00
Dan Winship
926f4e1473 libnm: drop nm_utils_deinit()
It was a no-op anyway.
2014-12-04 08:39:54 -05:00
Dan Winship
cb025dba5b libnm-core: fix the rule for parsing 'gateway' out of 'addresses' (rh #1170199)
We were always using the gateway field of the first address in
ipv4.addresses / ipv6.addresses to set the gateway, but to be
compatible with old behavior, we should actually be using the first
non-0 gateway field (if the first one is 0).
2014-12-03 16:31:50 -05:00
Dan Winship
1c4f41c610 libnm-core: add nm_utils_file_is_certificate() and _file_is_private_key()
Add nm-utils methods to check if a file is a certificate or private
key file.

nm-applet currently has its own internal versions of these, but they
ended up having to duplicate a bunch of logic that we already have in
crypto.c.
2014-11-21 08:46:07 -05:00
Dan Winship
7c74e71e91 libnm-core: tweak crypto.c APIs
Update crypto_verify_private_key() and
crypto_verify_private_key_data() to indicate whether the key was
encrypted or not.

Rename crypto_decrypt_private_key() and
crypto_decrypt_private_key_data() to
crypto_decrypt_openssl_private_key*, since that's the only private key
format they deal with, and the old names made them sound more generic
than they were. Also, update the openssl private key parsing code to
recognize unencrypted private keys as well. (Previously we accepted
unencrypted PKCS#8 keys, but not unencrypted openssl-style keys.)
2014-11-21 08:46:07 -05:00
Dan Winship
1313658829 libnm-core, libnm-util: move test cert files to libnm-core/
Move the certificate files used by the libnm-util and libnm-core tests
from libnm-util/tests/certs/ to libnm-core/tests/certs/.
2014-11-21 08:40:09 -05:00
Dan Winship
98da2ae72c libnm-core: port test-crypto to g_assert* macros
And in particular, add some g_assert_error() checks
2014-11-21 08:40:09 -05:00
Lubomir Rintel
c30379e0fd libnm-core: Add missing type cast
Fixes testing on 32-bit arches:

/core/general/test_setting_compare_timestamp:
(./test-general:29331): GLib-GObject-WARNING **: g_object_set_valist: object class `NMSettingConnection' has no property named `$?\xff\xff\x89t$0\x89|$4\xe8\u001c\x98\xff\xff\x85\xc0tM\x83\xf8\xfft3\x8dT$(\xc7D$\u0008'
/bin/sh: line 5: 29331 Trace/breakpoint trap   ${dir}$tst
FAIL: test-general

Fixes: 093a3c88d0
2014-11-19 16:04:41 +01:00