Commit graph

24 commits

Author SHA1 Message Date
Thomas Haller
90f5d9114f
libnm: use nm_auto_unref_tc_action cleanup macro in nm_utils_tc_action_from_str() 2021-05-11 13:56:45 +02:00
Thomas Haller
3cd56e92d4
libnm: fix leak in nm_utils_tc_tfilter_from_str()
Found by Coverity:

  Error: RESOURCE_LEAK (CWE-772):
  NetworkManager-1.31.3/src/libnm-core-impl/nm-utils.c:2772: alloc_fn: Storage is returned from allocation function "nm_utils_tc_action_from_str".
  NetworkManager-1.31.3/src/libnm-core-impl/nm-utils.c:2772: var_assign: Assigning: "action" = storage returned from "nm_utils_tc_action_from_str(extra_opts, error)".
  NetworkManager-1.31.3/src/libnm-core-impl/nm-utils.c:2785: leaked_storage: Variable "action" going out of scope leaks the storage it points to.
  # 2783|       tfilter = nm_tc_tfilter_new(kind, parent, error);
  # 2784|       if (!tfilter)
  # 2785|->         return NULL;
  # 2786|
  # 2787|       nm_tc_tfilter_set_handle(tfilter, handle);

Fixes: de41c45e61 ('libnm-core: add functionality for dealing with tc-style traffic filter specifiers')
2021-05-11 13:56:45 +02:00
Thomas Haller
5bd03fd9a3
libnm: use nm_uuid_is_valid_nmlegacy() to implement nm_utils_is_uuid() 2021-05-04 15:51:57 +02:00
Thomas Haller
2fcabf5699
all: only include "libnm-glib-aux/nm-uuid.h" where needed
Don't let "nm-core-internal.h" (which is a very popular header itself)
drag in "nm-uuid.h".
2021-05-04 15:51:51 +02:00
Thomas Haller
78297db721
libnm,glib-aux: move nm_utils_uuid_*() API to libnm-glib-aux 2021-05-04 15:51:47 +02:00
Thomas Haller
73cfc4097a
libnm,glib-aux: add and use nm_uuid_generate_random_str*() helpers 2021-05-04 15:51:45 +02:00
Thomas Haller
dd1a618745
libnm,glib-aux: move nm_utils_uuid_is_null() to "nm-uuid.h" 2021-05-04 15:51:45 +02:00
Thomas Haller
73b9883c6f
build: don't link libnm/libnm-core against libuuid
We use util-linux's libuuid for handling UUIDs. But UUIDs are
really a trivial thing, at least the portion that we use.

Reimplement the parse/unparse/generate_random() methods and drop
the dependency. Note that no other libraries from our dependency chain
was dragging in libuuid, so thereby we really get rid of the dependency.

We still require libuuid for building, because it is used by an example
program. Maybe that should be changed, to avoid the build dependency.
But that can be done at a later time.
2021-05-04 15:51:44 +02:00
Thomas Haller
7a15144f75
glib-aux: use nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
42d67415b4
glib-aux: use nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
596bf4b91b
glib-aux: use nm_uuid_unparse() 2021-05-04 15:51:42 +02:00
Thomas Haller
21321ac736
clang-format: reformat code with clang 12
The format depends on the version of the tool. Now that Fedora 34 is
released, update to clang 12 (clang-tools-extra-12.0.0-0.3.rc1.fc34.x86_64).
2021-05-04 13:56:26 +02:00
Thomas Haller
80e30f4562
all: use nm_g_variant_new_au() helper 2021-04-16 11:44:20 +02:00
Thomas Haller
f34841e196
all: use nm_g_variant_new_ay() helper 2021-04-16 11:44:19 +02:00
Thomas Haller
15fe784180
libnm-core: use _nm_connection_serialize_non_secret() in _nm_utils_hwaddr_cloned_data_synth() 2021-04-01 17:44:57 +02:00
Andrew Zaborowski
34285fec76
libnm: Refactor NM_CONNECTION_SERIALIZE_* flags
nm-settings-connection.c has code similar to this in two places:

    /* FIXME: improve NMConnection API so we can avoid the overhead of cloning the connection,
     *   in particular if there are no secrets to begin with. */

    connection_cloned = nm_simple_connection_new_clone(new);

    /* Clear out unwanted secrets */
    _nm_connection_clear_secrets_by_secret_flags(connection_cloned,
                                                 NM_SETTING_SECRET_FLAG_NOT_SAVED
                                                     | NM_SETTING_SECRET_FLAG_AGENT_OWNED);

    secrets = nm_g_variant_ref_sink(
        nm_connection_to_dbus(connection_cloned, NM_CONNECTION_SERIALIZE_ONLY_SECRETS));

It seems the secrets filtering can be done by nm_connection_to_dbus() if
the NM_CONNECTION_SERIALIZE_* flags are extended.  The current set of
flags contains flags that start with NO, ONLY and WITH prefixes, which
makes it useless for combining the flags because most combinations of
more than one flag don't have a clear interpretation.  So they're mostly
useful when used alone, i.e. you'd need to add a new enum value for
each new subset of settings to be serialized.

To get the most flexibility from a small set of flags they should
either all be of the WITH_* type or NO_* type.  In the former case they
could be combined to extend the subset of properties serialized, in the
latter case each flag would reduce the subset.  After trying both
options I found it's easier to adapt the current set of flags to the
WITH_* schema while keeping binary and source compatibility.  This
commit changes the set of flags in the following way:

NM_CONNECTION_SERIALIZE_ALL is kept for compatibility but is equivalent
to a combination of other flags.

NM_CONNECTION_SERIALIZE_WITH_NON_SECRET is added with the same value as
NM_CONNECTION_SERIALIZE_NO_SECRETS, it implies that non-secret
properties are included but doesn't prevent including other properties.
Since it couldn't be meaningfully combined with any other flag this
change shouldn't break compatibility.

Similarly NM_CONNECTION_SERIALIZE_WITH_SECRETS is added with the same
value as existing NM_CONNECTION_SERIALIZE_ONLY_SECRETS with the same
consideration about compatibility.

NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED and the new
NM_CONNECTION_SERIALIZE_WITH_SECRETS_SYSTEM_OWNED and
NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_SAVED add only subsets of
secrets and can be combined.  For backwards compatibility
NM_CONNECTION_SERIALIZE_ONLY_SECRETS is basically ignored when either of
these three is present, so that the value:
..ONLY_SECRETS | ..AGENT_OWNED works as previously.
2021-04-01 17:19:15 +02:00
Thomas Haller
cd00b04099
libnm: expose NM_IW_ESSID_MAX_SIZE define 2021-03-18 11:30:56 +01:00
Thomas Haller
6e4cdae256
all: split "range" variant of nm_utils_ptrarray_find_binary_search()
nm_utils_ptrarray_find_binary_search() had two additional output
arguments: the first and last index -- in case the sorted list contains
duplicates.

That's nice, and was used in the past. But now, those output arguments
are no longer used.

So drop them from nm_utils_ptrarray_find_binary_search().

Actually, we could now also drop the previous variant
nm_utils_ptrarray_find_binary_search_range(), as it's only used by unit
tests. However, although not rocket science, getting this right is not
entirely trivial, so lets keep the code in case we need it again.
2021-03-16 09:55:49 +01:00
Thomas Haller
af0cfc559b
glib-aux: move nm_utils_ptrarray_find_first() helper to libnm-glib-aux 2021-03-05 11:09:15 +01:00
Thomas Haller
ec22551ce9
glib-aux: move NMUtilsIPv6IfaceId struct to libnm-glib-aux 2021-03-05 11:09:14 +01:00
Thomas Haller
5c790db8b6
glib-aux: move ssid utils from "libnm-core-impl" to "libnm-glib-aux"
The purpose is of course to be able to use it outside of the internal
API from libnm-core-intern.
2021-03-05 11:09:12 +01:00
Thomas Haller
9dc84b32b0
build: move "shared/nm-{glib-aux,log-null,log-core}" to "src/libnm-{glib-aux,log-null,log-core}" 2021-02-24 12:48:20 +01:00
Thomas Haller
39225258d6
build: move "shared/systemd" to "src/libnm-systemd-shared" 2021-02-24 12:48:16 +01:00
Thomas Haller
fdf9614ba7
build: move "libnm-core/" to "src/" and split it
"libnm-core/" is rather complicated. It provides a static library that
is linked into libnm.so and NetworkManager. It also contains public
headers (like "nm-setting.h") which are part of public libnm API.

Then we have helper libraries ("libnm-core/nm-libnm-core-*/") which
only rely on public API of libnm-core, but are themself static
libraries that can be used by anybody who uses libnm-core. And
"libnm-core/nm-libnm-core-intern" is used by libnm-core itself.

Move "libnm-core/" to "src/". But also split it in different
directories so that they have a clearer purpose.

The goal is to have a flat directory hierarchy. The "src/libnm-core*/"
directories correspond to the different modules (static libraries and set
of headers that we have). We have different kinds of such modules because
of how we combine various code together. The directory layout now reflects
this.
2021-02-18 19:46:51 +01:00
Renamed from libnm-core/nm-utils.c (Browse further)