Commit Graph

782 Commits

Author SHA1 Message Date
Thomas Haller
efccc2a53c shared: add nm_json_aux_gstr_append_*() helper 2019-05-23 18:09:49 +02:00
Thomas Haller
50dbcda015 shared: add nm_jansson_json_as_*() helpers to "shared/nm-glib-aux/nm-jansson.h" 2019-05-23 18:09:49 +02:00
Thomas Haller
f84e623732 shared: add "shared/nm-glib-aux/nm-json-aux.h"
This will be a set of JSON related utilities, that are independent of
libjansson.
2019-05-23 18:09:49 +02:00
Thomas Haller
f5482013ac shared: add NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY() macro as part of NM_GOBJECT_PROPERTIES_DEFINE()
This will be needed independently from NM_GOBJECT_PROPERTIES_DEFINE().
2019-05-23 18:09:49 +02:00
Thomas Haller
dadd38c484 shared: add nm_utils_strv_make_deep_copied_n() helper 2019-05-23 18:09:49 +02:00
Thomas Haller
79ef1abcca shared: add nm_strcmp0()
g_strcmp0() is not inlineable, so we first need to call to glib, only to
call to libc.
2019-05-23 18:09:49 +02:00
Thomas Haller
9e544d527a shared: fix invalid assertion in nm_utils_team_link_watcher_from_string()
Fixes: a473ab431a ('cli: refactor team-link-watcher to/from strings')
2019-05-23 18:09:49 +02:00
Thomas Haller
2946d07085 shared: implement _nm_utils_monotonic_timestamp_initialized() in "nm-logging-stub.c" 2019-05-22 20:04:08 +02:00
Thomas Haller
fbddd27e73 shared: fix type shenanigans for data pointer of nm_memdup_maybe_a()
The type of the "data" pointer may not be compatible with the type of
the "to_free" / output pointer. This is due to constness, and that we
are unable in C to remove constness from a type.

For example,

    {
        const char *const *data = ...;
        gs_free const char **cpy_to_free = NULL;
        const char **cpy;

        cpy = nm_memdup_maybe_a (300, data, NM_PTRARRAY_LEN (data) + 1, &cpy_to_free);
    }

is prefectly valid , but would not have compiled.

It shows that "data" is not of type "*(&cpy_to_free)", but rather
it might be a non-const pointer of the same type.

Fixes: d0e1d0e626 ('shared: propagate types in nm_malloc_maybe_a(), nm_malloc0_maybe_a(), nm_memdup_maybe_a()')
2019-05-16 11:42:16 +02:00
Thomas Haller
d0e1d0e626 shared: propagate types in nm_malloc_maybe_a(), nm_malloc0_maybe_a(), nm_memdup_maybe_a()
The "to_free" pointer should have the suitable type that we are
requesting. Use "typeof()" to preserve and propagate the pointer
type in the macro.
2019-05-16 08:06:46 +02:00
Thomas Haller
8fcadf5328 shared: embed scheme_type in NMSetting8021xSchemeVtable
Since we can easily lookup the vtable for a NMSetting8021xSchemeType,
it is convenient to also easily get the scheme_type for a given
NMSetting8021xSchemeVtable.

On my x86_64, this change is basically for free as it does not increase
the size of NMSetting8021xSchemeVtable, because the scheme_type fits in a
previously unused part of the NMSetting8021xSchemeVtable struct.
2019-05-15 09:49:42 +02:00
Thomas Haller
37faab73a8 systemd: merge branch systemd into master 2019-05-14 16:09:39 +02:00
Thomas Haller
f61a12ee20 systemd: update code from upstream (2019-05-14)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=b6ec9afd44934a599a761e8c741077a7512e0c82

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files -z :/src/systemd/src/ \
                :/shared/systemd/src/ \
                :/shared/nm-utils/unaligned.h | \
  xargs -0 rm -f

nm_copy_sd_shared() {
    mkdir -p "./shared/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./shared/systemd/$1"
}

nm_copy_sd_core() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_nmutils() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd_core "src/libsystemd-network/arp-util.c"
nm_copy_sd_core "src/libsystemd-network/arp-util.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd_core "src/libsystemd-network/lldp-internal.h"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd_core "src/libsystemd-network/lldp-network.c"
nm_copy_sd_core "src/libsystemd-network/lldp-network.h"
nm_copy_sd_core "src/libsystemd-network/network-internal.c"
nm_copy_sd_core "src/libsystemd-network/network-internal.h"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd_core "src/libsystemd-network/sd-lldp.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-source.h"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.h"
nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd_core "src/shared/dns-domain.c"
nm_copy_sd_core "src/shared/dns-domain.h"
nm_copy_sd_core "src/systemd/_sd-common.h"
nm_copy_sd_core "src/systemd/sd-dhcp-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd_core "src/systemd/sd-event.h"
nm_copy_sd_core "src/systemd/sd-id128.h"
nm_copy_sd_core "src/systemd/sd-ipv4acd.h"
nm_copy_sd_core "src/systemd/sd-ipv4ll.h"
nm_copy_sd_core "src/systemd/sd-lldp.h"
nm_copy_sd_core "src/systemd/sd-ndisc.h"
nm_copy_sd_nmutils "src/basic/unaligned.h"
nm_copy_sd_shared "src/basic/alloc-util.c"
nm_copy_sd_shared "src/basic/alloc-util.h"
nm_copy_sd_shared "src/basic/async.h"
nm_copy_sd_shared "src/basic/env-file.c"
nm_copy_sd_shared "src/basic/env-file.h"
nm_copy_sd_shared "src/basic/env-util.c"
nm_copy_sd_shared "src/basic/env-util.h"
nm_copy_sd_shared "src/basic/errno-util.h"
nm_copy_sd_shared "src/basic/escape.c"
nm_copy_sd_shared "src/basic/escape.h"
nm_copy_sd_shared "src/basic/ether-addr-util.c"
nm_copy_sd_shared "src/basic/ether-addr-util.h"
nm_copy_sd_shared "src/basic/extract-word.c"
nm_copy_sd_shared "src/basic/extract-word.h"
nm_copy_sd_shared "src/basic/fd-util.c"
nm_copy_sd_shared "src/basic/fd-util.h"
nm_copy_sd_shared "src/basic/fileio.c"
nm_copy_sd_shared "src/basic/fileio.h"
nm_copy_sd_shared "src/basic/fs-util.c"
nm_copy_sd_shared "src/basic/fs-util.h"
nm_copy_sd_shared "src/basic/hash-funcs.c"
nm_copy_sd_shared "src/basic/hash-funcs.h"
nm_copy_sd_shared "src/basic/hashmap.c"
nm_copy_sd_shared "src/basic/hashmap.h"
nm_copy_sd_shared "src/basic/hexdecoct.c"
nm_copy_sd_shared "src/basic/hexdecoct.h"
nm_copy_sd_shared "src/basic/hostname-util.c"
nm_copy_sd_shared "src/basic/hostname-util.h"
nm_copy_sd_shared "src/basic/in-addr-util.c"
nm_copy_sd_shared "src/basic/in-addr-util.h"
nm_copy_sd_shared "src/basic/io-util.c"
nm_copy_sd_shared "src/basic/io-util.h"
nm_copy_sd_shared "src/basic/list.h"
nm_copy_sd_shared "src/basic/log.h"
nm_copy_sd_shared "src/basic/macro.h"
nm_copy_sd_shared "src/basic/memory-util.c"
nm_copy_sd_shared "src/basic/memory-util.h"
nm_copy_sd_shared "src/basic/mempool.c"
nm_copy_sd_shared "src/basic/mempool.h"
nm_copy_sd_shared "src/basic/missing_fcntl.h"
nm_copy_sd_shared "src/basic/missing_socket.h"
nm_copy_sd_shared "src/basic/missing_stat.h"
nm_copy_sd_shared "src/basic/missing_type.h"
nm_copy_sd_shared "src/basic/parse-util.c"
nm_copy_sd_shared "src/basic/parse-util.h"
nm_copy_sd_shared "src/basic/path-util.c"
nm_copy_sd_shared "src/basic/path-util.h"
nm_copy_sd_shared "src/basic/prioq.c"
nm_copy_sd_shared "src/basic/prioq.h"
nm_copy_sd_shared "src/basic/process-util.c"
nm_copy_sd_shared "src/basic/process-util.h"
nm_copy_sd_shared "src/basic/random-util.c"
nm_copy_sd_shared "src/basic/random-util.h"
nm_copy_sd_shared "src/basic/set.h"
nm_copy_sd_shared "src/basic/signal-util.h"
nm_copy_sd_shared "src/basic/siphash24.h"
nm_copy_sd_shared "src/basic/socket-util.c"
nm_copy_sd_shared "src/basic/socket-util.h"
nm_copy_sd_shared "src/basic/sort-util.h"
nm_copy_sd_shared "src/basic/sparse-endian.h"
nm_copy_sd_shared "src/basic/stat-util.c"
nm_copy_sd_shared "src/basic/stat-util.h"
nm_copy_sd_shared "src/basic/stdio-util.h"
nm_copy_sd_shared "src/basic/string-table.c"
nm_copy_sd_shared "src/basic/string-table.h"
nm_copy_sd_shared "src/basic/string-util.c"
nm_copy_sd_shared "src/basic/string-util.h"
nm_copy_sd_shared "src/basic/strv.c"
nm_copy_sd_shared "src/basic/strv.h"
nm_copy_sd_shared "src/basic/time-util.c"
nm_copy_sd_shared "src/basic/time-util.h"
nm_copy_sd_shared "src/basic/tmpfile-util.c"
nm_copy_sd_shared "src/basic/tmpfile-util.h"
nm_copy_sd_shared "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/utf8.c"
nm_copy_sd_shared "src/basic/utf8.h"
nm_copy_sd_shared "src/basic/util.c"
nm_copy_sd_shared "src/basic/util.h"
2019-05-14 15:26:04 +02:00
Thomas Haller
3712e7a89f shared: use union instead of _nm_alignas() for static hash-seed
We want the the hash-seed array is alined so it can be used both as
guint, guint32, and guint64 directly. Don't use _nm_alignas() but
instead just add the fields to the union so we get proper alignment.

While at at, also let the seed argument to c_siphash_init() be aligned
to 64 integers. c_siphash_init() does not require that, but it tries to
read the seed as (unaligned) LE 64 bit integers. So, it doesn't hurt.
2019-05-13 09:25:05 +02:00
Thomas Haller
78999f9b61 shared: add NM_HASH_OBFUSCATE_PTR() macro
We want to log pointer values to indicate the related parties of a
log message. But we should not, because plain pointer values can be
used to defeat ASLR.

Instead, we have nm_hash_obfuscate_ptr() to managle a pointer and give
a distinct (albeit not 100% unique) 64 bit integer for logging.

But for the logging messages to be meaning-full, all related parties
must use the same static-seed.

Add a macro NM_HASH_OBFUSCATE_PTR() that uses a particular seed.
2019-05-13 09:25:05 +02:00
Thomas Haller
654faa4d38 shared: add nm_dbus_connection_call_start_service_by_name() helper 2019-05-12 09:56:36 +02:00
Thomas Haller
f7fff62067 shared: add nm_clear_g_dbus_connection_signal() helper 2019-05-12 09:56:36 +02:00
Thomas Haller
8ffa75685e shared: add nm_dbus_connection_signal_subscribe_name_owner_changed() helper
... and nm_dbus_connection_call_get_name_owner().

We are going to use GDBusConnection more instead of GDBusProxy. Hence,
these two functions are the standard repertoire and used over and over.

Their arguments are complicated enough to warrant a small helper.
2019-05-12 09:56:36 +02:00
Thomas Haller
655e6bb1e3 shared: add "shared/nm-glib-aux/nm-dbus-aux.h" 2019-05-12 09:56:36 +02:00
Beniamino Galvani
4735d6764a all: fix typos (milli seconds -> milliseconds) 2019-05-08 13:35:59 +02:00
Thomas Haller
9d2623cceb shared: use nm_str_skip_leading_spaces() in _nm_utils_ascii_str_to_int64() 2019-05-07 20:58:17 +02:00
Thomas Haller
b0693863c1 shared: add NMKeyFileDB API
It will be used for "/var/lib/NetworkManager/seen-bssids" and
"/var/lib/NetworkManager/timestamps" which currently is implemented
in NMSettingConnection.
2019-05-07 16:41:21 +02:00
Thomas Haller
8c2fda7ca0 shared: add "shared/nm-glib-aux/nm-keyfile-aux.h" 2019-05-07 16:41:21 +02:00
Thomas Haller
8decdf2225 shared: add nm_log_level_from_syslog() helper to convert from syslog levels 2019-05-07 16:41:21 +02:00
Thomas Haller
945620624a shared: add nm_malloc_maybe_a(), nm_malloc0_maybe_a() and nm_memdup_maybe_a() utils 2019-05-07 09:38:44 +02:00
Thomas Haller
4853be52af shared: add nm_g_variant_take_ref() util 2019-05-01 13:46:32 +02:00
Lubomir Rintel
35a428f168 dispatcher: look for the scripts in /usr/lib as well
This makes it possible for packages that ship dispatcher scripts to use
the correct location.
2019-04-29 16:57:07 +02:00
Thomas Haller
2f9e55ee52 shared,libnm-core: use nm_utils_named_value_list_sort() 2019-04-25 08:53:51 +02:00
Thomas Haller
6d472dacb4 shared: add nm_utils_named_value_list_*() utils
nm_utils_named_value_list_find(), nm_utils_named_value_list_sort(),
and nm_utils_named_value_list_is_sorted().
2019-04-25 08:53:51 +02:00
Thomas Haller
a473ab431a cli: refactor team-link-watcher to/from strings
Stricter parsing of the string:

- reject attributes that don't make sense depending on the type.

- reject duplicate attributes.
2019-04-25 07:50:47 +02:00
Thomas Haller
2800574221 shared: fix to/from string of vlanid and missed-max values for NMTeamLinkWatcher
The vlanid and missed-max values have non-zero default values.
That is what nm_utils_team_link_watcher_from_string() honors.

Note that nm_utils_team_link_watcher_to_string() must omit printing
the value only if it's the default value too.

Otherwise, these values are not preserved during a to string conversion
and back.

Maybe a better fix would be to always print the values, regardless of
the default value. But arguably, that is quite ugly because in most
cases we don't want to cluter the string output with values that are
left at the default.
2019-04-25 07:49:56 +02:00
Thomas Haller
7a25f67af7 shared/tests: add tests for libnm-core-aux
These tests cannot (easily) be under "shared/nm-libnm-core-aux/tests"
because libnm/libnm-core requires code under shared while
"nm-libnm-core-aux" requires libnm/libnm-core. With autotools that is
not problem, but with meson we include sub directories in a particular
order and there is no way to foward declare stuff (AFAIK). To avoid
the circular dependency, add the tests to "clients/common/tests", which
is always built last.
2019-04-25 07:47:37 +02:00
Thomas Haller
911f2dfe56 shared: fix missing space printing "send-always" flag of NMTeamLinkWatcher 2019-04-25 07:47:09 +02:00
Thomas Haller
db9fbcee6c cli,shared: move NMTeamLinkWatcher to/from string function to "nm-libnm-core-aux.h"
to/from string functions are useful. We should be able to reuse them.
Move them to their own location.

Also, it moves independent code out of "clients/common/nm-meta-setting-desc.c"
which is already one of the largest source files we have.

Also, it makes the code unit-testable, which is obviously required
as the code has bugs.
2019-04-25 07:46:17 +02:00
Thomas Haller
14b94e6adf shared: add "nm-libnm-core-aux/nm-libnm-core-aux.h" 2019-04-25 07:45:31 +02:00
Thomas Haller
af07ed01c0 shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-core
"libnm-core" implements common functionality for "NetworkManager" and
"libnm".

Note that clients like "nmcli" cannot access the internal API provided
by "libnm-core". So, if nmcli wants to do something that is also done by
"libnm-core", , "libnm", or "NetworkManager", the code would have to be
duplicated.

Instead, such code can be in "libnm-libnm-core-{intern|aux}.la".
Note that:

  0) "libnm-libnm-core-intern.la" is used by libnm-core itsself.
     On the other hand, "libnm-libnm-core-aux.la" is not used by
     libnm-core, but provides utilities on top of it.

  1) they both extend "libnm-core" with utlities that are not public
     API of libnm itself. Maybe part of the code should one day become
     public API of libnm. On the other hand, this is code for which
     we may not want to commit to a stable interface or which we
     don't want to provide as part of the API.

  2) "libnm-libnm-core-intern.la" is statically linked by "libnm-core"
     and thus directly available to "libnm" and "NetworkManager".
     On the other hand, "libnm-libnm-core-aux.la" may be used by "libnm"
     and "NetworkManager".
     Both libraries may be statically linked by libnm clients (like
     nmcli).

  3) it must only use glib, libnm-glib-aux.la, and the public API
     of libnm-core.
     This is important: it must not use "libnm-core/nm-core-internal.h"
     nor "libnm-core/nm-utils-private.h" so the static library is usable
     by nmcli which couldn't access these.

Note that "shared/nm-meta-setting.c" is an entirely different case,
because it behaves differently depending on whether linking against
"libnm-core" or the client programs. As such, this file must be compiled
twice.
2019-04-18 18:59:09 +02:00
Thomas Haller
8183335878 shared: move "nm-dbus-compat.h" header to "nm-std-aux/nm-dbus-compat.h" 2019-04-18 18:59:09 +02:00
Thomas Haller
80db06f768 shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"
From the files under "shared/nm-utils" we build an internal library
that provides glib-based helper utilities.

Move the files of that basic library to a new subdirectory
"shared/nm-glib-aux" and rename the helper library "libnm-core-base.la"
to "libnm-glib-aux.la".

Reasons:

 - the name "utils" is overused in our code-base. Everything's an
   "utils". Give this thing a more distinct name.

 - there were additional files under "shared/nm-utils", which are not
   part of this internal library "libnm-utils-base.la". All the files
   that are part of this library should be together in the same
   directory, but files that are not, should not be there.

 - the new name should better convey what this library is and what is isn't:
   it's a set of utilities and helper functions that extend glib with
   funcitonality that we commonly need.

There are still some files left under "shared/nm-utils". They have less
a unifying propose to be in their own directory, so I leave them there
for now. But at least they are separate from "shared/nm-glib-aux",
which has a very clear purpose.
2019-04-18 18:59:09 +02:00
Thomas Haller
2973d68253 shared: move udev helper to separate directory "shared/nm-udev-aux"
We built (among others) two libraries from the sources in "shared/nm-utils":
"libnm-utils-base.la" and "libnm-utils-udev.la".

It's confusing. Instead use directories so there is a direct
correspondence between these internal libraries and the source files.
2019-04-18 18:58:28 +02:00
Thomas Haller
b434b9ec07 shared: split C-only helper "shared/nm-std-aux" utils out of "shared/nm-utils"
"shared/nm-utils" contains general purpose utility functions that only
depend on glib (and extend glib with some helper functions).

We will also add code that does not use glib, hence it would be good
if the part of "shared/nm-utils" that does not depend on glib, could be
used by these future projects.

Also, we use the term "utils" everywhere. While that covers the purpose
and content well, having everything called "nm-something-utils" is not
great. Instead, call this "nm-std-aux", inspired by "c-util/c-stdaux".
2019-04-18 18:57:24 +02:00
Thomas Haller
304eab8703 shared: remove unused _nm_utils_escape_plain()/_nm_utils_escape_spaces() API
... and the "unescape" variants.

This is replaced by nm_utils_escaped_tokens_split()
and nm_utils_escaped_tokens_escape*() API.
2019-04-18 17:53:09 +02:00
Thomas Haller
832adf323e shared: add nm_utils_escaped_tokens_escape_gstr_assert() 2019-04-17 11:26:30 +02:00
Thomas Haller
ced7dbe8bf shared: remove unused nm_utils_str_simpletokens_extract_next()
This can be replaced by nm_utils_escaped_tokens_split().

Note that nm_utils_escaped_tokens_split() does not behave exactly
the same. For example, nm_utils_str_simpletokens_extract_next() would
remove all backslashes and leave only the following character.
nm_utils_escaped_tokens_split() instead only strips backslashes
that preceed a delimiter, whitespace or another backslash.

But we should have one preferred way of tokenizing, and I find this
preferable, because it allows for most backslashes to appear verbatim.
2019-04-17 11:11:21 +02:00
Thomas Haller
e206e3d4d8 shared: add nm_utils_escaped_tokens_escape()
This escapes strings so that they can be concatenated with a delimiter
and without loss tokenized with nm_utils_escaped_tokens_split().

Note that this is similar to _nm_utils_escape_plain() and
_nm_utils_escape_spaces(). The difference is that
nm_utils_escaped_tokens_escape() also escapes the last trailing
whitespace. That means, if delimiters contains all NM_ASCII_SPACES, then
it is identical to _nm_utils_escape_spaces(). Otherwise, the trailing
space is treated specially. That is, because
nm_utils_escaped_tokens_split() uses NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP,
to strip leading and trailing whitespace. To still express a trailing
whitespace, the last whitespace must be escaped. Note that
NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP also honors escaping any whitespace
(not only at the last position), but when escaping we don't need to
escape them, because unescaped (non-trailing) whitespace are taken just
fine.

The pair nm_utils_escaped_tokens_split() and
nm_utils_escaped_tokens_escape() are proposed as default way of
tokenizing a list of items. For example, with

  $ nmcli connection modify "$PROFILE" +ipv4.routing-rules 'priority 5 from 192.168.7.5/32 table 5, priority 6 iif a\, from 192.168.7.5/32 table 6'

Here we implement a to/from string function to handle one item
(nm_ip_routing_rule_{from,to}_string()). When such elements are combined with ',',
then we need to support an additional layer of escaping on top of that.
The advantage is that the indvidual to/from string functions are agnostic
to this second layer of escaping/tokenizing that nmcli employs to handle
a list of these items.
The disadvantage is that we possibly get multiple layers of backslash
escapings. That is only mitigated by the fact that nm_utils_escaped_tokens_*()
supports a syntax for which *most* characters don't need any special escaping.
Only delimiters, backslash, and the trailing space needs escaping, and
these are cases are expected to be few.
2019-04-17 11:11:21 +02:00
Thomas Haller
9522aaf226 shared: add NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED to nm_utils_strsplit_set_full()
Add a new flag that will remove escape characters after splitting
the string.

This implements a special kind of backslash escaping. It's not C escape
sequences (like '\n' or '\020'), but simply to take the special character
following the backslash verbatim. Note that the backslash is only
considered special, if it's followed by a delimiter, another backslash,
or a whitespace (in combination with %NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP).

The main purpose of this form of escaping is nmcli's list options, like

  $ nmcli connection modify "$PROFILE" +ipv4.routing-rules 'priority 5 from 192.168.7.5/32 table 5, priority 6 iif a\, from 192.168.7.5/32 table 6'

It's a contrieved example, but the list options are a list of IP
addresses, rules, etc. They implement their own syntax for one element,
and are concatenated by ','. To support that one element may have
arbitrary characters (including the delimiter and whitespaces), nmcli
employs a tokenization with this special kind of escaping.
2019-04-17 11:11:21 +02:00
Thomas Haller
5b2b0dcadf shared: add NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP to nm_utils_strsplit_set_full()
This will essentially call g_strstrip() on each token.

There are some specialties:

 - if the resulting word is empty after stripping, then according to
   %NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, the empty token will be
   removed. If that results in an empty string array, %NULL will be
   returned.

 - if %NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING is set, then
   whitespace that is backslash escaped is not removed.

Since this is a post-operation that happens after tokeninzing, it
could be done as a separate function. And we already have this function:
_nm_utils_unescape_plain() and _nm_utils_unescape_spaces().
However, that is ugly for several reasons:

 - the stripping should be part of the tokenizing, you shouldn't need
   several steps.

 - nm_utils_strsplit_set_full() returns a "const char **" which
   indicates the strings must not be freed. However, it is perfectly
   valid to modify the string inplace. Hence, the post-op function
   would need to cast the strings to "char *", which seems ugly
   (although we do that on many places, and it's guaranteed to work).

 - _nm_utils_unescape_plain()/_nm_utils_unescape_spaces() is indeed
   already used together with nm_utils_strsplit_set_full(). However,
   it requires to initialize the cb_lookup buffer twice. I would expect
   that initializing the cb_lookup buffer is a large portion of what
   the function does already (for short strings).
   This issue will be solved in the next commit by adding yet another flag
   which allows to unescape.
2019-04-17 11:10:11 +02:00
Lubomir Rintel
5801f89f4d all: goodbye libnm-glib
This removes libnm-glib, libnm-glib-vpn, and libnm-util for good.
The it has been replaced with libnm since NetworkManager 1.0, disabled
by default since 1.12 and no up-to-date distributions ship it for years
now.

Removing the libraries allows us to:

* Remove the horrible hacks that were in place to deal with accidental use
  of both the new and old library in a single process.
* Relief the translators of maintenance burden of similar yet different
  strings.
* Get rid of known bad code without chances of ever getting fixed
  (libnm-glib/nm-object.c and libnm-glib/nm-object-cache.c)
* Generally lower the footprint of the releases and our workspace

If there are some really really legacy users; they can just build
libnm-glib and friends from the NetworkManager-1.16 distribution. The
D-Bus API is stable and old libnm-glib will keep working forever.

https://github.com/NetworkManager/NetworkManager/pull/308
2019-04-16 15:52:27 +02:00
Thomas Haller
5974c6ae7f shared/n-acd: reimport
git subtree pull --prefix shared/n-acd git@github.com:nettools/n-acd.git master --squash
2019-04-14 17:23:50 +02:00
Thomas Haller
6d513f4bf2 shared/c-siphash: reimport
git subtree pull --prefix shared/c-siphash git@github.com:c-util/c-siphash.git master --squash
2019-04-14 17:23:25 +02:00
Thomas Haller
72de3d45cc shared/c-rbtree: reimport
git subtree pull --prefix shared/c-rbtree git@github.com:c-util/c-rbtree.git master --squash
2019-04-14 17:23:01 +02:00