Commit Graph

28470 Commits

Author SHA1 Message Date
Thomas Haller
840dd8cbcd settings: in assertion to check valid UUID use nm_uuid_is_valid_full()
In the past, the UUID was only loosely validate and would accept
forms that are not valid. This was fixed by commit 207cf3d5d4 ('libnm:
normalize "connection.uuid"'). Now the UUID is always strictly valid
and lower case.

Thus, don't use the fuzzy nm_utils_is_uuid() from libnm but the exact
check nm_uuid_is_valid_full().

Note that this is only used for assertions in the header file. We thus
don't want to drag in "libnm-glib-aux/nm-uuid.h". Instead, we forward
declare the function.

lgtm.com warns about declarations are block scope, so fix that too by
moving the declaration at file scope.
2021-05-27 09:24:00 +02:00
Thomas Haller
ce1dd0c0de glib-aux: add nm_uuid_is_valid_full() to have a non-static, non-inline variant 2021-05-27 09:22:14 +02:00
Thomas Haller
f18c6e7bd1 core: forward declare nm_settings_plugin_get_type() at file scope in "nm-settings-storage.h"
lgtm.com warns about function declarations inside blocks.
*sigh*. I think it's well understood what this code means, and it is not
done by accident. Still, let's make the tool happy in this case.
2021-05-27 09:17:29 +02:00
Thomas Haller
fdc0285e68 examples: explicitly catch "Exception" in "ovs-external-ids.py"
lgtm.com warns about unqualified "except". This catches any "BaseException",
when we really only should handle "Exception" here.
2021-05-27 09:13:26 +02:00
Thomas Haller
d5e8d1382b all/trivial: add code comment about using alloca() inside a loop
lgtm.com warns about these uses. They are correct though. Maybe the code should
not use alloca() simply to suppress the warning. Instead, add a comment pointing
out that this is in fact correct.
2021-05-27 09:09:29 +02:00
Thomas Haller
f903d3b7b8 platform: drop unnecessary check in _vlan_xgress_qos_mappings_cpy()
For one, "src_n_map" must always be greater than zero at this point.
lgtm.com warns about that, and the point of this patch is to avoid
that warning.

Still, the check really isn't needed, also because nm_memdup() explicitly
handles buffers sizes of zero.
2021-05-27 09:04:59 +02:00
Thomas Haller
90818b5391 core: minor cleanup of integer multiplication in _sleep_duration_convert_ms_to_us()
Cast to unsigned int64. Also add parenthesis, even if not strictly
necessary.
2021-05-27 09:02:45 +02:00
Thomas Haller
07193dabd1 examples: fix printing applied connection in "ovs-external-ids.py"
lgtm.com also complained about "connection_after" being unused. This
hopefully works around that warning.
2021-05-27 08:56:20 +02:00
Thomas Haller
6c919dc897 examples: drop unused variable in "examples/python/gi/ovs-external-ids.py" 2021-05-27 08:53:35 +02:00
Thomas Haller
26f0fb0604 python: remove unused imports
They are flagged by lgtm.com. Avoid the warning by dropping unused
includes.
2021-05-27 08:52:30 +02:00
Thomas Haller
f1a1921edc examples: drop confusing UID handling in "vpn.py" example
First of all, the "os.setuid()" call is never reached. lgtm.com warns about
that, and warnings are annoying because they require investigation.

This code is only in the example, so that the user would understand that
they should edit the source and set the desired UID. But you can only
call setuid() if you have CAP_SETUID, so commonly this anyway doesn't
work -- unless you are root already, and then you actually don't need
it either.

Let's drop this code from the example.

Maybe this example really should be dropped. Does the "dbus" python
module even still work? Doesn't for me...
2021-05-27 00:02:19 +02:00
Thomas Haller
6365d8c67a contrib/scripts: drop unnecessary line in "find-backports" script 2021-05-26 23:38:58 +02:00
Thomas Haller
fb64935597 gitlab-ci: fix error evaluating "distro.always" in ci.template
...
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1361, in generate
    yield self.environment.handle_exception()
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File ".gitlab-ci/ci.template", line 178, in top-level template code
    {% if not version in distro.always and (distro.name != pages_build.name or version != pages_build.version) %}
  jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'always'
2021-05-26 22:39:33 +02:00
Thomas Haller
7e581a0303 Revert "contrib: no longer install libuuid as build dependency"
Ups, we actually still require libuuid. Actually, we only need to
to build the example script `examples/C/glib/add-connection-gdbus.c`.
The proper solution would be to make this an optional dependency.

So far this was not yet done. Also, libuuid is really an ubiquitous
dependency on Linux, so it's not really a problem to have this build
dependency, even if it's just to build the examples.

This reverts commit c0a3947ff9.
2021-05-26 22:16:35 +02:00
Thomas Haller
4e7040d46d gitlab-ci: belatedly regenerate .gitlab-ci.yml 2021-05-26 21:45:51 +02:00
Thomas Haller
2e68ceba75 lgtm.com: add configuration file for building on lgtm.com
lgtm.com has some interesting scripts that try to automatically
build an autotools project and detect dependencies.

It currently doesn't work, because gobject-introspection is detected,
but pgobject is not installed. That causes a configure failure

  configure: error: "--enable-introspection aims to build the settings documentation. This requires GObject introspection for python (pygobject)

I guess we could make the configure script smarter, to ignore
introspection by default if pygobject is not workable.

On the other hand, let's simply help the project to build NetworkManager by
adding a .lgtm.yml configuration.
2021-05-26 19:25:42 +02:00
Thomas Haller
c0a3947ff9 contrib: no longer install libuuid as build dependency
We no longer need it. Only for build.sh script we require `uuidgen`
from util-linux package.
2021-05-26 19:25:41 +02:00
Thomas Haller
e1d40d89f0 examples: fix usage of input() with Python2
input() in Python2 evaluated the string and was thus unsafe. On
Python2, the right choice is raw_input. In Python3, input does
what raw_input did.

Work around this.

The main "problem" is that lgtm.com flags this as error. The fix
in the example is not important, but getting a low number of warnings
is.
2021-05-26 18:03:13 +02:00
Thomas Haller
ebbf740c64 wifi/iwd: merge branch 'balrog-kun:iwd-config-writing'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/866
2021-05-26 17:08:08 +02:00
Andrew Zaborowski
b86d83860e iwd: Add default "auto" value for [main].iwd-config-path
Since the [main].iwd-config-path functionality, where NM watches for
NMSettingsConnection changes and update IWD network config files with
new settings, has proven to work without issues so far, enable it by
default.  Instead of hardcoding /var/lib/iwd as the value, and since the
value can't be probed at NM compile time, query it from IWD's recently-
added D-Bus interface for settings when [main].iwd-config-path is either
missing or set to the new value "auto".
2021-05-26 16:47:04 +02:00
Andrew Zaborowski
62dc214033 iwd: Fix conversion of user certificate path in EAP settings
Fix a copy-paste error when converting NMSettingsConnection profiles to
IWD network config format.

Fixes: 9d22ae7981 ('wifi: Add utilities for writing IWD connection profiles')
2021-05-26 16:47:04 +02:00
Thomas Haller
07b23749aa all: merge branch 'th/libnm-read-vpn-details'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/867
2021-05-26 15:47:50 +02:00
Thomas Haller
8fcbbdd7a4 all: reimplement g_strstrip() macro to avoid Coverity warning
Coverity has issues with functions that handle ownership like
g_strstrip(). Thus the scan is full of false positives like:

  Error: RESOURCE_LEAK (CWE-772): [#def45] [important]
  NetworkManager-1.31.5/src/core/devices/wwan/nm-service-providers.c:134: alloc_fn: Storage is returned from allocation function "g_strdup".
  NetworkManager-1.31.5/src/core/devices/wwan/nm-service-providers.c:134: noescape: Resource "g_strdup(attribute_values[i])" is not freed or pointed-to in "g_strchug".
  NetworkManager-1.31.5/src/core/devices/wwan/nm-service-providers.c:134: leaked_storage: Failing to save or free storage allocated by "g_strdup(attribute_values[i])" leaks it.
  #  132|               if (strcmp(attribute_names[i], "value") == 0) {
  #  133|                   parse_context->state = PARSER_METHOD_GSM_APN;
  #  134|->                 parse_context->apn   = g_strstrip(g_strdup(attribute_values[i]));
  #  135|                   break;
  #  136|               }

Add a workaround for that.

There are other functions that have the same problem, but the usage
g_strstrip(g_strdup(...)) is common to warrant a special workaround.
2021-05-26 15:46:01 +02:00
Thomas Haller
9154f0128a glib-aux: avoid coverity warning in nm_str_buf_append_printf()
It's a false positive. Still avoid it.

  Error: FORWARD_NULL (CWE-476): [#def479]
  NetworkManager-1.31.5/src/libnm-glib-aux/nm-shared-utils.c:5558: var_compare_op: Comparing "strbuf->_priv_str" to null implies that "strbuf->_priv_str" might be null.
  NetworkManager-1.31.5/src/libnm-glib-aux/nm-shared-utils.c:5575: var_deref_model: Passing "strbuf" to "nm_str_buf_maybe_expand", which dereferences null "strbuf->_priv_str".
  # 5573|           l2 = ((gsize) l) + 1u;
  # 5574|
  # 5575|->         nm_str_buf_maybe_expand(strbuf, l2, FALSE);
  # 5576|
  # 5577|           va_start(args, format);

  Error: FORWARD_NULL (CWE-476): [#def480]
  NetworkManager-1.31.5/src/libnm-glib-aux/nm-shared-utils.c:5558: var_compare_op: Comparing "strbuf->_priv_str" to null implies that "strbuf->_priv_str" might be null.
  NetworkManager-1.31.5/src/libnm-glib-aux/nm-shared-utils.c:5575: no_write_call: Although "nm_str_buf_maybe_expand" does overwrite "strbuf->_priv_str" on some paths, it also contains at least one feasible path which does not overwrite it.
  NetworkManager-1.31.5/src/libnm-glib-aux/nm-shared-utils.c:5578: var_deref_op: Dereferencing null pointer "strbuf->_priv_str".
  # 5576|
  # 5577|           va_start(args, format);
  # 5578|->         l = g_vsnprintf(&strbuf->_priv_str[strbuf->_priv_len], l2, format, args);
  # 5579|           va_end(args);
  # 5580|
2021-05-26 15:46:01 +02:00
Thomas Haller
a559950d41 libnm/tests: avoid Coverity warning in test code _do_test_utils_str_utf8safe_unescape()
Error: FORWARD_NULL (CWE-476): [#def435]
    NetworkManager-1.31.5/src/libnm-core-impl/tests/test-general.c:9084: var_compare_op: Comparing "str" to null implies that "str" might be null.
    NetworkManager-1.31.5/src/libnm-core-impl/tests/test-general.c:9105: var_deref_model: Passing null pointer "str" to "strchr", which dereferences it.
    # 9103|           s = nm_utils_str_utf8safe_unescape(str, NM_UTILS_STR_UTF8_SAFE_FLAG_NONE, &str_free_1);
    # 9104|           g_assert_cmpstr(s, ==, expected);
    # 9105|->         if (strchr(str, '\\')) {
    # 9106|               g_assert(str_free_1 != str);
    # 9107|               g_assert(s == str_free_1);
2021-05-26 15:46:00 +02:00
Thomas Haller
6646ee6546 libnm/tests: avoid potential crash in test code test_nm_utils_escaped_tokens()
It causes a Coverity warning, so let's work around it.
2021-05-26 15:46:00 +02:00
Thomas Haller
bbe39ed095 libnm: use cleanup attribute in NMVpnPluginOld's _connect_generic() 2021-05-26 15:45:59 +02:00
Thomas Haller
e56f126071 libnm: fix error handling in NMVpnPluginOld's _connect_generic()
Also Coverity found that something is wrong here:

   Error: FORWARD_NULL (CWE-476): [#def361]
   NetworkManager-1.31.5/src/libnm-client-impl/nm-vpn-plugin-old.c:441: var_compare_op: Comparing "connection" to null implies that "connection" might be null.
   NetworkManager-1.31.5/src/libnm-client-impl/nm-vpn-plugin-old.c:489: var_deref_model: Passing null pointer "connection" to "g_object_unref", which dereferences it.
   #  487|       }
   #  488|
   #  489|->     g_object_unref(connection);
   #  490|   }
   #  491|

Fixes: 6793a32a8c ('libnm: port to GDBus')
2021-05-26 15:45:59 +02:00
Thomas Haller
8db23d47e4 ifcfg-rh: minor cleanup in svEscape() 2021-05-26 15:45:59 +02:00
Thomas Haller
370316fc3e ifcfg-rh: allocate exact buffer in _escape_ansic()
Previously, we would allocate a buffer of the worst case, that is,
4 times the number of bytes, in case all of them require octal escaping.

Coverity doesn't like _escape_ansic() for another reason:

   Error: NULL_RETURNS (CWE-476): [#def298]
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: returned_null: "g_malloc" returns "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: alias: Assigning: "q" = "dest = g_malloc(strlen(source) * 4UL + 1UL + 3UL)". Both pointers are now "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:163: dereference: Incrementing a pointer which might be null: "q".
   #  161|       q = dest = g_malloc(strlen(source) * 4 + 1 + 3);
   #  162|
   #  163|->     *q++ = '$';
   #  164|       *q++ = '\'';
   #  165|

It doesn't recognize that g_malloc() shouldn't return NULL (because
we never request zero bytes).

I am not sure how to avoid that, but let's rework the code to first count
how many characters we exactly need. It think that should also help with
the coverity warning.

Doing exact allocation requires first to count the number of required
bytes. It still might be worth it, because we might keep the allocated
strings a bit longer around.
2021-05-26 15:45:59 +02:00
Thomas Haller
f305a411cf libnm: abort read in nm_vpn_service_plugin_read_vpn_details() on '\0'
We expect to read NUL terminated strings. Upon NUL, we should do
something. Assume this is EOF.
2021-05-26 15:45:58 +02:00
Thomas Haller
6bf7908d05 libnm: abort huge read in nm_vpn_service_plugin_read_vpn_details()
There is no need to accept such a huge read. Abort.
2021-05-26 15:45:58 +02:00
Thomas Haller
4a9fcb0fc3 libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()
It seems very ugly to read one byte at a time. Use a naive buffered
reader, so that we can read multiple bytes at a time, and return them
one by one.

Also, this now keeps state of any error/EOF. Once we reach EOF, we won't
read again. The previous code did that too, but I think this code is
easier to read.
2021-05-26 15:45:58 +02:00
Thomas Haller
1338a2ef96 libnm: avoid sleep in nm_vpn_service_plugin_read_vpn_details()
Polling with sleep() is really ugly. Use poll() instead.
2021-05-26 15:45:58 +02:00
Thomas Haller
ddf1942bfb libnm: avoid g_warning() in nm_vpn_service_plugin_read_vpn_details()
g_warning() and printing to stdout/stderr are not suitable actions
for a library. If there is something important, find a way to report the
condition to the caller. If it's not important, stay quiet.
2021-05-26 15:45:58 +02:00
Thomas Haller
f0dc95e517 libnm: avoid strcmp in nm_vpn_service_plugin_read_vpn_details() 2021-05-26 15:45:57 +02:00
Thomas Haller
62c1944e7d libnm: fix logic and double free in nm_vpn_service_plugin_read_vpn_details()
"val" and "key" are now marked as nm_auto. They are freed at the end,
and we should not free them before breaking the loop (at least not,
without also clearing the variables).

Fixes: 02dbba49d6 ('libnm: fix leak in nm_vpn_service_plugin_read_vpn_details()')
2021-05-26 15:45:57 +02:00
Thomas Haller
8da91cd85f glib-aux: add nm_clear_g_string() helper
Since g_string_free() takes an additional argument,
it's not direclty usable with nm_clear_pointer(ptr, g_string_free);

As workaround, add nm_clear_g_string() helper.
2021-05-26 15:45:57 +02:00
Thomas Haller
c3d3429916 tools: drop spurious whitespace in "src/libnm-client-impl/nm-property-infos-*.xml"
<nm-setting-docs>
  -  <setting name="6lowpan">
  +<setting name="6lowpan">
   </setting>
2021-05-26 15:33:29 +02:00
Wen Liang
18839361ac bond: support tlb_dynamic_lb in balance-alb mode
In kernel, `tlb_dynamic_lb` is supported to configure in bonding mode
`balance-alb`. Therefore, add the support in NetworkManager to avoid
undesirable limitation.

Kernel previously had such limitation and it was removed in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e79c1055749e3183a2beee04a24da378623329c5.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1959934

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/868
2021-05-26 14:57:21 +02:00
Thomas Haller
8ba66f8ec9 trivial: improve code comments 2021-05-26 12:07:11 +02:00
Thomas Haller
174f7bd27b core: rework string handling in enslave_slave()
Coverity doesn't like the previous code:

  Error: RESOURCE_LEAK (CWE-772): [#def34] [important]
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: alloc_fn: Storage is returned from allocation function "g_strdup".
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: noescape: Resource "g_strdup(config)" is not freed or pointed-to in "g_strdelimit".
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: leaked_storage: Failing to save or free storage allocated by "g_strdup(config)" leaks it.
  #  833|                       char *sanitized_config;
  #  834|
  #  835|->                     sanitized_config = g_strdelimit(g_strdup(config), "\r\n", ' ');
  #  836|                       err = teamdctl_port_config_update_raw(priv->tdc, slave_iface, sanitized_config);
  #  837|                       g_free(sanitized_config);

Maybe this works better.
2021-05-25 13:56:42 +02:00
Thomas Haller
ff9f2d27ec bluetooth: ensure function-like behavior of _LOG_bzobj() macro
We want that macros behave like functions, in that they evaluate all
their arguments exactly once.
2021-05-25 13:27:26 +02:00
Thomas Haller
95085acec3 update references from "freenode" to "Libera.Chat" 2021-05-25 11:09:37 +02:00
Thomas Haller
0448d3b931 contrib/rpm: merge branch 'th/contrib-rpm-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/865
2021-05-21 17:14:27 +02:00
Thomas Haller
847d6b31d4 contrib/rpm: remove "Obsoletes: NetworkManager-{atm,bt}"
These subpackages existed before commit 886366d0fd ('contrib/rpm:
update spec file after renaming NM plugins') (2014, before 0.9.9.95).

rpm warns about unversioned obsoletes like:

  It's not recommended to have unversioned Obsoletes: Obsoletes: NetworkManager-atm
  It's not recommended to have unversioned Obsoletes: Obsoletes: NetworkManager-bt

These packages are so long gone by now, let's just drop the Obsoletes.
2021-05-21 09:58:16 +02:00
Thomas Haller
871faa3ba7 contrib/rpm: remove "Obsoletes: dhcdbd"
"dhcdbd" is gone since 2007. Drop it. Also, rpm doesn't really like
unversioned obsoletes and warns:

    It's not recommended to have unversioned Obsoletes: Obsoletes: dhcdbd
2021-05-21 09:34:47 +02:00
Thomas Haller
f215c9a7fa contrib/rpm: don't have build dependency for iptables
We really only require "iptables" as build dependency to autodetect the
path where iptables is installed. On Fedora/RHEL, this is always /usr/sbin,
so we can just as well hard code this.

Alternatively, if the autodetection is really necessary, we would also require
a build dependency on /usr/sbin/nft. That seems a waste.
2021-05-21 09:34:46 +02:00
Thomas Haller
199807b2ec contrib/rpm: add rhel-8 specific libndp dependeny 2021-05-21 09:34:46 +02:00
Thomas Haller
8c7da8afc6 build: merge branch 'liangwen12year:wl/xml_rework3'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/863
2021-05-20 10:48:11 +02:00