Commit Graph

157 Commits

Author SHA1 Message Date
Jiří Klimeš
6caafab258 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.
2015-06-19 09:32:58 +02:00
Thomas Haller
2f4301bd26 glib-compat: add g_ptr_array_insert() 2015-06-17 11:41:43 +02:00
Thomas Haller
0a3c1f5774 utils: add nm_utils_is_power_of_two() macro 2015-06-17 11:41:43 +02:00
Jiří Klimeš
94a393e9ed 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
2015-06-10 10:01:49 +02:00
Beniamino Galvani
6f647fe689 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.
2015-06-09 18:11:25 +02:00
Thomas Haller
d5e948e482 libnm/test: test compare_property() to handle default values
Add a test case to check whether compare/diff works correctly.
2015-06-05 12:26:48 +02:00
Thomas Haller
b8b1a01d96 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.
2015-06-01 14:47:08 +02:00
Lubomir Rintel
c47c06470a 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.
2015-05-28 12:51:24 +02:00
Lubomir Rintel
6463ce5dd9 tests: use the TAP formatter
The test results in standard format are easily integrated into CI systems.
2015-05-26 13:51:45 +02:00
Lubomir Rintel
f627d6db8e tests: move all asserts into tests
Otherwise the TAP formatter would produce a plan-less output.
2015-05-26 13:51:44 +02:00
Thomas Haller
89c6abc7ab libnm/test: include "nm-keyfile-internal.h" in test-general.c
This enables special code in "nm-test-utils.h" that is useful
for tests.
2015-05-20 18:39:04 +02:00
Thomas Haller
670ca44721 libnm: rename DNSOptionDesc and @dns_option_descs to have an "nm"-prefix
Declarations in header files should always have an "nm" related
prefix.

Fixes: 019943bb5d
2015-05-20 12:42:19 +02:00
Beniamino Galvani
8d9776997b libnm-core/trivial: rename 'i' function argument to 'idx' 2015-05-13 17:15:34 +02:00
Beniamino Galvani
262c27935d libnm-core/test: add tests for DNS option utilities 2015-05-13 17:15:34 +02:00
Beniamino Galvani
019943bb5d libnm-core: add dns-options property to NMSettingIPConfig 2015-05-13 17:15:34 +02:00
Thomas Haller
81119c69d8 keyfile/test: refactor and cleanup _keyfile_convert()
_keyfile_convert() should really test for successful round-trip
conversion of keyfile-connection and vice versa.
2015-03-20 13:19:20 +01:00
Thomas Haller
997fc07ca5 test: add nmtst_create_connection_from_keyfile() 2015-03-12 18:16:58 +01:00
Thomas Haller
c9a8764ad2 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.
2015-03-12 18:16:58 +01:00
Thomas Haller
a49680dacd libnm: add define for cert scheme prefix file:// for NMSetting8021x 2015-03-12 18:12:27 +01:00
Thomas Haller
e82293ebf6 libnm: move _nm_utils_uuid_generate_from_strings() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
c5d23737fd libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
ad4e6f7fad build/trivial: cleanup Makefile.am by sorting EXTRA_DIST entries 2015-03-12 18:12:25 +01:00
Lubomir Rintel
2981839bde test: initialize auto-destructed pointers
Otherwise the compiler complains that they could be left uninitialized in case
the function returns too early.

Fixes: 76745817c3
2015-02-09 15:19:30 +01:00
Thomas Haller
c50f30e79c tests: enable valgrind tests for tests 2015-02-09 11:51:07 +01:00
Thomas Haller
ae73320b8c libnm/tests: fix memleaks in tests for valgrind 2015-02-09 11:51:07 +01:00
Dan Winship
76d9fc9167 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.)
2015-01-15 14:46:30 -05:00
Thomas Haller
1bef194302 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.
2014-12-19 13:53:26 +01:00
Thomas Haller
7990add493 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
2014-12-19 13:53:26 +01:00
Jiří Klimeš
6603e7ffde 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).
...
2014-12-15 14:11:03 +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