Commit Graph

252 Commits

Author SHA1 Message Date
Thomas Haller
986ca94a36 libnm: assert in nm_utils_is_uuid() for valid argument
nm_utils_is_uuid() is public API. Commonly we check input arguments for such
functions with g_return_*() assertions.
2018-09-06 07:41:22 +02:00
Thomas Haller
a9406ca4a7 libnm-core: expose _nm_utils_str2bin_full() as internal API
We only exposed wrappers around this function, but all of them have
different behavior, and none exposes all possible features. For example,
nm_utils_hexstr2bin() strips leading "0x", but it does not clear
the data on failure (nm_explicit_bzero()). Instead of adding more
wrappers, expose the underlying implementation, so that callers may
use the function the way they want it.
2018-09-04 07:38:30 +02:00
Thomas Haller
f961dcb806 libnm/crypto: move and mark nm_utils_rsa_key_encrypt() as test code
nm_utils_rsa_key_encrypt() is internal API which is only uesd for testing.
Move it to nm-crypto.h (where it fits better) and rename it to make the
testing-aspect obvious.
2018-09-04 07:38:30 +02:00
Thomas Haller
896a47da53 libnm/crypto: refactor nm_crypto_load_and_verify_certificate() and return GBytes
The GBytes has a suitable cleanup function, which zeros the certificate
from memory.

Also, all callers that require the certificate, actually later converted
it into a GBytes anyway. This way, they can re-used the same instance
(avoiding an additionaly copying of the data), and they will properly
clear the memory when freed.
2018-09-04 07:38:30 +02:00
Thomas Haller
c172675c13 libnm/crypto: rename libnm crypto API to have consistent NM prefix
Follow our convention, that items in headers are all named with
an "NM" prefix.

Also, "nm-crypto-impl.h" contains internal functions that are to be implemented
by the corresponding crypto backends. Distinguish their names as well.
2018-09-04 07:38:30 +02:00
Thomas Haller
4106f2968d libnm/crypto: rename libnm's crypto files
"crypto.h" did not follow our common NM style naming. Rename
the files.
2018-09-04 07:38:30 +02:00
Thomas Haller
9ca12145a3 libnm/crypto: adjust argument types for crypto_md5_hash()
There should be a clear distinction between whether an array
is a NUL terminated string or binary with a length.

crypto_md5_hash() is already complicated enough. Adjust it's
API to only support binary arguments, and thus have "guint8 *" type.
2018-09-04 07:38:30 +02:00
Thomas Haller
b8a57fb272 libnm-core: remove unused utlity functions for GSList
I think GSList is not a great data type. Most of the time when we used
it, we better had choosen another data type.

These utility functions were unused, and I think we should use GSList
less.

Drop them.
2018-08-30 11:17:09 +02:00
Thomas Haller
5cd4e6f3e6 wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable.

Also, since at other places we use GBytes, having
different types is combersome and requires needless
conversions.

Also:

- avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string().
  We use nm_utils_escape_ssid() when we want to log the SSID. However, it
  does not escape newlines, which is bad.

- also no longer use nm_utils_same_ssid(). Since it no longer
  treated trailing NUL special, it is not different from
  g_bytes_equal().

- also, don't use nm_utils_ssid_to_utf8() for logging anymore.
  For logging, _nm_utils_ssid_escape_utf8safe() is better because
  it is loss-less escaping which can be unambigously reverted.
2018-08-22 10:49:34 +02:00
Thomas Haller
dba19ebd7d all: avoid useless cast of g_free() to GDestroyNotify 2018-08-22 10:49:34 +02:00
Thomas Haller
e730f7429d libnm: replace _nm_utils_bytes_to_dbus() with nm_utils_gbytes_get_variant_ay() 2018-08-22 10:49:34 +02:00
Beniamino Galvani
6a51d393b2 shared: add @allow_escaping argument to @nm_utils_strsplit_set 2018-08-11 09:41:07 +02:00
Thomas Haller
a587d32467 shared: move nm_utils_ptrarray_find_binary_search() to shared utils 2018-08-10 10:38:19 +02:00
Thomas Haller
d32da2daaa shared: move nm_utils_array_find_binary_search() to shared utils 2018-08-10 10:38:19 +02:00
Thomas Haller
4444db6b6f libnm: avoid deadlock during g_module_open() in _nm_utils_init()
_nm_utils_init() is a __attribute__((constructor)) function,
that is, it runs during dlopen().

On the other head, g_module_open() itself calls dlopen().

It is prone to deadlock. Don't do it.

The check is only an aggressive assertion to crash the application
if it wrongly loads libnm and libnm-util/libnm-glib at the same time.
If that happens, all is lost already. We can just as well call the
assertion later. It's not supposed to fail anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=796804
2018-08-01 16:06:11 +02:00
Beniamino Galvani
a9b4532fa7 libnm-core: add SR-IOV setting
Add a setting containing SR-IOV parameters.
2018-07-11 16:16:22 +02:00
Beniamino Galvani
d7382fbe93 nm-utils: add _nm_utils_format_variant_attributes_full() 2018-07-11 16:16:22 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
9d3f01a27c libnm: add code comment about thread-safty of _nm_utils_init() and use atomic
Although we don't really need protect for thread safety in _nm_utils_init(),
avoid using static variables without lock/atomic operations. libnm is not
thread-safe, but we still should try to avoid potential issues whenever it is
easy.
2018-07-01 18:17:31 +02:00
Lubomir Rintel
0132da1ddb libnm: add nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Thomas Haller
92b8161578 libnm: avoid allocating GBytes in _nm_utils_dhcp_duid_valid()
In a lot of cases, we don't require the GBytes out-argument. This
is the case when called from NMSettingIP6Config's verify().
Avoid allocating the GBytes instance and also don't heap allocate
the temporary buffer in that case.

Also, being called from NMSettingIP6Config's verify(), at which
point the string value contains untrusted data. Of course, we
do very badly in general protecting against the user creating
huge settings, which could trick NetworkManage to allocate
large amounts of memory (and being killed by glib's out of memory
handling). We should handle such cases better in general, but
just avoid it here.

Since we know that the buffer must hold at most 128+2 bytes,
we can stack allocate it. Later, in case we really need to
return the value, we can create a GBytes instance of the right
size.
2018-06-12 14:45:40 +02:00
Francesco Giudici
7a0b6b17bb libnm-core: add ipv6.dhcp-duid property
allow to specify the DUID to be used int the DHCPv6 client identifier
option: the dhcp-duid property accepts either a hex string or the
special values "lease", "llt", "ll", "stable-llt", "stable-ll" and
"stable-uuid".

"lease": give priority to the DUID available in the lease file if any,
         otherwise fallback to a global default dependant on the dhcp
         client used. This is the default and reflects how the DUID
         was managed previously.
"ll": enforce generation and use of LL type DUID based on the current
      hardware address.
"llt": enforce generation and use of LLT type DUID based on the current
       hardware address and a stable time field.
"stable-ll": enforce generation and use of LL type DUID based on a
             link layer address derived from the stable id.
"stable-llt": enforce generation and use of LLT type DUID based on
              a link layer address and a timestamp both derived from the
              stable id.
"stable-uuid": enforce generation and use of a UUID type DUID based on a
               uuid generated from the stable id.
2018-06-08 18:23:31 +02:00
Thomas Haller
e5d1a71396 build: unifiy specifying locale directory define 2018-05-31 15:59:38 +02:00
Thomas Haller
5f5f75ce0e libnm: expose _bin2str() helper function as internal API 2018-05-28 14:58:24 +02:00
Thomas Haller
4e463df100 libnm: allow nm_utils_hwaddr_valid() of length zero
nm_utils_hwaddr_valid() is used for validating strings. It should
not assert against calling it with an empty string "". That is just
an invalid hwaddr.
2018-05-28 14:58:24 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Beniamino Galvani
aca671fff0 all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
Beniamino Galvani
919f6b6d75 shared: use value infos in _nm_utils_enum_to_str_full 2018-04-13 17:02:55 +02:00
Corentin Noël
468a019333 gobject-introspection: made several fixes to the annotations
https://bugzilla.gnome.org/show_bug.cgi?id=794658
2018-03-26 12:45:49 +02:00
Lubomir Rintel
8a46b25cfa all: require glib 2.40
RHEL 7.1 and Ubuntu 14.04 LTS both have this.

https://bugzilla.gnome.org/show_bug.cgi?id=792323
2018-01-18 11:45:36 +01:00
Thomas Haller
e5f3c0fc8a libnm: only include "nm-jansson.h" from "nm-json.h"
"nm-utils/nm-jansson.h" and thus <jansson.h> must be included only
after "nm-json.h". Enforce that by never including them directly,
except from "nm-json.h" itself.
2018-01-16 14:47:24 +01:00
Thomas Haller
b6b6baa773 libnm: rename "libnm-core/nm-jansson.h" to "libnm-core/nm-json.h"
We already have "shared/nm-utils/nm-jansson.h". Avoid reusing the same file name.
2018-01-16 14:47:24 +01:00
Francesco Giudici
c6448f724b cli: get team defaults from setting header files
this allows centralizing default values definition and allows quicker
and safer update of default values.
2018-01-15 18:27:10 +01:00
Lubomir Rintel
cd476e4dc9 core: load jansson on demand
Avoid using it if the symbols clash is detected.
2018-01-08 10:15:29 +01:00
Lubomir Rintel
9e4de97967 libnm-core: move detection of UTF-8 capable terminals to clients/
Having it in libnm doesn't make any sense and prevents using it for more
internal functionality.

Too bad nm_utils_wifi_strength_bars() is already a public API.
No problem -- replace it with a compatible yet dumber equivalent.
2017-12-18 14:47:37 +01:00
Lubomir Rintel
6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Thomas Haller
cb06a36a18 libnm: avoid deep cloning list of address attribute names for nm_utils_ip_addresses_to_variant()
It's only a temporary list. No need for cloning the names
as well.
2017-12-18 12:14:50 +01:00
Thomas Haller
f299a79d5b libnm: sort attribute names in nm_tc_action_get_attribute_names()
The order in which the attribute names are returns should
be defined and stable. Sort them and re-use the helper functions.
2017-12-18 12:14:49 +01:00
Thomas Haller
d83eee5d57 utils: extend binary-search to return the first/last index
binary-search can find an index of a matching entry in a sorted
list. However, if the list contains multiple entries that compare
equal, it can be interesting to find the first/last entry. For example,
if you want to append new items after the last.

Extend binary search to optionally continue the binary search
to determine the range that compares equal.
2017-12-15 11:36:07 +01:00
Thomas Haller
f44f21c87e core: avoid leaks parsing team link-watcher
Found by coverity.
2017-12-12 11:15:38 +01:00
Lubomir Rintel
de41c45e61 libnm-core: add functionality for dealing with tc-style traffic filter specifiers
Tailored to fit both nmcli and keyfile needs.
2017-12-11 11:02:04 +01:00
Lubomir Rintel
733464ada3 libnm-core: add functionality for dealing with tc-style action specifiers
Tailored to fit both nmcli and keyfile needs.
2017-12-11 11:02:04 +01:00
Lubomir Rintel
92f8f30d47 clients: add tc qdisc support
What works:

  nmcli c add con-name dum0 ifname dum0 type dummy \
      tc.qdiscs 'ingress, root pfifo_fast'
  nmcli c modify dum0 -tc.qdiscs 'root pfifo_fast'
  nmcli c modify dum0 +tc.qdiscs 'root handle 666: fq_codel'
2017-12-11 10:52:23 +01:00
Lubomir Rintel
7c1de05f41 libnm-core: add functionality for dealing with tc-style qdisc specifiers
Tailored to fit both nmcli and keyfile needs.
2017-12-11 10:52:22 +01:00
Lubomir Rintel
18dd937b81 libnm-core/utils: allow use of bytestring with attributes 2017-12-11 10:30:26 +01:00
Lubomir Rintel
47b1dc3828 libnm-core/utils: add some special properties for the attributes
"no_value" indicates that the the attribute is a single word, not a
key=value pair. If the type is BOOLEAN then the attribute is considered
true, if it's a STRING then the key is used instead of a value.

"consumes_rest" indicates that the particular key takes the unparseable
tail of the string for a value.

This allows parsing tc-style strings. Consider this filter:

              ,------ regular key/value pair
       ,-----'----.
  root handle 1234: matchall action simple foo bar baz
    |                  |     `-----------.-----------'
    |                  |                 `- "", STRING, consumes_rest
    |                  `------------------- "kind", STRING, no_value
    `-------------------------------------- "root', BOOLEAN, no_value
2017-12-11 10:30:26 +01:00
Lubomir Rintel
48a619e62b libnm-core/utils: allow using the same character for key/value and attribute separators
Allows doing a nm_utils_parse_variant_attributes(..., ' ', ' ').
2017-12-11 10:30:26 +01:00
Lubomir Rintel
9a00750c06 libnm-core/utils: (trivial) use g_set_error_literal() where appropriate 2017-12-11 10:30:25 +01:00
Thomas Haller
b11eac1a0d libnm: use nm_utils_named_values_from_str_dict()
Make use of NMUtilsNamedValue in nm_utils_format_variant_attributes().
This avoids creating a GList and sorting it.

Also, reuse nm_utils_named_values_from_str_dict() in
nm_setting_bond_get_option().
2017-12-08 18:48:36 +01:00