Commit Graph

342 Commits

Author SHA1 Message Date
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
a67c1ec4b5 libnm-core: fix return value in nm_utils_enum_to_str()
Fixes: 8be9814793
2015-07-24 15:48:29 +02:00
Beniamino Galvani
8be9814793 libnm-core: add enum conversion utilities
Add functions nm_utils_enum_to_str() and nm_utils_enum_from_str()
which can be used to perform conversions between enum values and
strings, passing the GType automatically generated for every enum by
glib-mkenums.
2015-07-24 14:02:59 +02:00
Thomas Haller
2b55de8560 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
2015-07-22 13:49:17 +02:00
Dan Williams
4e47d36d73 libnm-core: fix GOI annotations after 019943bb
Fixes: 019943bb
2015-07-17 17:31:17 -05:00
David Shea
568b4ad31f 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
2015-07-16 14:22:03 +02:00
Thomas Haller
904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller
ed632207cd libnm: add @deep_copy argument to _nm_utils_strv_to_slist() and _nm_utils_slist_to_strv() 2015-07-02 15:50:04 +02:00
Thomas Haller
885d187d23 libnm: add _nm_utils_strv_cleanup() function 2015-07-02 15:50:03 +02:00
Thomas Haller
650fec81e2 libnm: add _nm_utils_ptrarray_find_binary_search() helper 2015-07-01 16:02:09 +02:00
Thomas Haller
3377cd7e18 libnm: add _nm_utils_ptrarray_find_first() utility function 2015-06-17 11:41:43 +02:00
Thomas Haller
ef4e017cfa libnm/utils: add _nm_utils_strv_find_first() function 2015-06-11 19:58:51 +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
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
019943bb5d libnm-core: add dns-options property to NMSettingIPConfig 2015-05-13 17:15:34 +02:00
Dan Winship
4bac5afa2b libnm-core: trivial error message fixes 2015-04-17 14:55:42 -04:00
Thomas Haller
1eaddced10 make use of NM_MORE_ASSERTS, nm_assert() and NM_MORE_LOGGING 2015-04-10 18:09:32 +02:00
Thomas Haller
628f47285d libnm: accept unknown WEP key type in nm_utils_wep_key_valid()
libnm-core treated the UNKNOWN WEP key type as KEY. Relax that
and try to guess the correct type based on the key.

This is for example important if you have a valid connection with
  wep-key-type=0 (unknown)
If you request passwords for such a connection, the user cannot
enter them in password format -- but there is no UI indication
that the password must be KEY.
2015-03-20 13:02:04 +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
66be46309a libnm: fix memleak in nm_utils_ip_addresses_from_variant() 2015-02-09 11:51:05 +01:00
Thomas Haller
c4e197d064 libnm: fix memleak in nm_utils_hwaddr_canonical() 2015-01-29 14:59:42 +01:00
Dan Winship
6da3b3a5a5 libnm: fix versioning on new APIs, bump soname
The newly added bond mode APIs in nm-utils will be new in 1.2, so mark
them as such in the headers and docs, move them to a new section in
libnm.ver.

Since we're adding the new section to libnm.ver, this also seems like
a good time to bump the soname.
2015-01-21 12:54:36 -05:00
Jiří Klimeš
d787f0391b utils: add functions for converting string <-> numeric bonding modes 2015-01-13 09:35:49 +01:00
Thomas Haller
fc5a66b14b libnm: fix documentation for nm_utils_file_search_in_paths() 2015-01-08 13:08:56 +01:00
Dan Winship
2d29c0527e docs: misc small fixes
Cleans up all of the warnings that aren't overly annoying to clean up.
2014-12-18 13:47:03 -05:00
Thomas Haller
924f7b2064 build: embed git-commit-id as string inside libnm binary
In the 'configure.ac' script we already detect the git commit id
for the current source version. When creating a tarball, it is also
included inside the generated 'configure' script.

Add the commit id as a  static string to nm-utils.c. That way, having
a build of libnm.so or NetworkManager, you can quickly find the
corresponding git commit:

    strings src/NetworkManager | grep NM_GIT_SHA

Note that this only works after a new `autogen.sh` run. Only rebuilding
is not enough. Hence, you must rebuild all to ensure that the correct
commit id is embedded.

https://bugzilla.gnome.org/show_bug.cgi?id=741651
2014-12-18 17:36:57 +01:00
Jiří Klimeš
afb0e2c53c libnm-core: mute coverity for RESOURCE_LEAK (CWE-772) in g_return_val_if_fail()
Error: RESOURCE_LEAK (CWE-772): [#def10]
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:225: alloc_fn: Storage is returned from allocation function "priority_map_new_from_str".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:154:4: alloc_fn: Storage is returned from allocation function "g_malloc0".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:154:4: var_assign: Assigning: "p" = "g_malloc0(8UL)".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:164:2: return_alloc: Returning allocated memory "p".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:225: var_assign: Assigning: "item" = storage returned from "priority_map_new_from_str(map, str)".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:226: leaked_storage: Variable "item" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK (CWE-772): [#def11]
NetworkManager-0.9.11.0/libnm-core/nm-utils.c:2056: alloc_fn: Storage is returned from allocation function "crypto_make_des_aes_key".
NetworkManager-0.9.11.0/libnm-core/crypto.c:405:2: alloc_fn: Storage is returned from allocation function "g_malloc0".
NetworkManager-0.9.11.0/libnm-core/crypto.c:405:2: var_assign: Assigning: "key" = "g_malloc0(digest_len + 1U)".
NetworkManager-0.9.11.0/libnm-core/crypto.c:407:2: noescape: Resource "key" is not freed or pointed-to in function "crypto_md5_hash".
NetworkManager-0.9.11.0/libnm-core/crypto.c:769:24: noescape: "crypto_md5_hash(char const *, gssize, char const *, gssize, char *, gsize)" does not free or save its pointer parameter "buffer".
NetworkManager-0.9.11.0/libnm-core/crypto.c:415:2: return_alloc: Returning allocated memory "key".
NetworkManager-0.9.11.0/libnm-core/nm-utils.c:2056: var_assign: Assigning: "key" = storage returned from "crypto_make_des_aes_key("DES-EDE3-CBC", &salt[0], salt_len, in_password, &key_len, NULL)".
NetworkManager-0.9.11.0/libnm-core/nm-utils.c:2057: leaked_storage: Variable "key" going out of scope leaks the storage it points to.
2014-12-15 14:10:55 +01:00
Thomas Haller
937a5639fc libnm: return 0 for empty address in hwaddr_binary_len()
Motivated by avoiding compiler warning with -O2 -Wstrict-overflow (gcc-4.8.3):

    make[4]: Entering directory `./NetworkManager/libnm-core'
      CC       nm-utils.lo
    ../libnm-core/nm-utils.c: In function 'nm_utils_hwaddr_valid':
    ../libnm-core/nm-utils.c:2725:14: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
       if (length == 0 || length > NM_UTILS_HWADDR_LEN_MAX)
                  ^
    ../libnm-core/nm-utils.c: In function 'nm_utils_hwaddr_canonical':
    ../libnm-core/nm-utils.c:2755:14: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
       if (length == 0 || length > NM_UTILS_HWADDR_LEN_MAX)
                  ^

https://bugzilla.gnome.org/show_bug.cgi?id=741168
2014-12-08 19:02:55 +01:00
Thomas Haller
820e41645f libnm: fix wrong g_return_if_fail() in nm_utils_file_search_in_paths()
Fixes: 6399170ff3
https://bugzilla.gnome.org/show_bug.cgi?id=740783
2014-12-05 15:01:01 +01:00
Thomas Haller
005b83de47 libnm: fix gtkdoc annotations for nm_utils_file_search_in_paths()
Fixes: 6399170ff3
2014-12-05 11:53:29 +01:00
Thomas Haller
6399170ff3 libnm: add function nm_utils_file_search_in_paths()
We now also use a similar function in VPN plugins. It makes
sense to provide a generic implementation in libnm.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=740783
2014-12-05 11:07:42 +01:00
Thomas Haller
69860e5d3a libnm: don't allocate temporary buffer in nm_utils_uuid_generate_from_strings()
crypto_md5_sum() already accepts two separate strings: salt and password.
No need to allocate a temporary buffer. Just pass @ns_uuid and @s
separately.
2014-12-04 17:44:11 +01:00
Thomas Haller
440b9d85b4 libnm: fix leak in nm_utils_uuid_generate_from_strings()
Did not free the GString instance @str. Thereby,
also don't use GString. Just malloc() the temporary
buffer.

Fixes: e7661c9b52
2014-12-04 17:22:40 +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
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
50d1de13cb libnm: don't heap allocate uuid temporary variable 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
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
4460386800 libnm-core: combine duplicate crypto_make_des_aes_key() function 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
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
Lubomir Rintel
abcb3184b3 libnm-core: Add a missing initializer
/libnm/crypto/PKCS#8: OK
/libnm/crypto/cert/pem: ==16241== Conditional jump or move depends on uninitialised value(s)
==16241==    at 0x121967: crypto_load_and_verify_certificate (crypto.c:605)
==16241==    by 0x12512E: nm_utils_file_is_certificate (nm-utils.c:2279)
==16241==    by 0x1201F1: test_cert (test-crypto.c:113)
2014-11-21 16:00:19 +01: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
c785a7dfcd libnm-core: change how new and legacy properties are serialized
Although libnm filters out properties received from the daemon that it
doesn't understand, there may be other clients that do not. In
particular, a client might call GetSettings() on a connection, update
the ipv4.addresses property in the returned dictionary, and then pass
the dictionary to Update(). In that case, the updated dictionary would
contain ipv4.address-data, but it would not reflect the changes the
client intended to make.

Fix this by changing the daemon side to prefer the legacy properties
to the new ones if both are set, and changing the client side to not
send the legacy properties (since we don't support new clients talking
to old servers anyway).
2014-11-15 09:52:29 -05:00