Commit graph

25630 commits

Author SHA1 Message Date
Thomas Haller
0b2ecf5e35
shared: add NM_G_PARAM_SPEC_GET_DEFAULT_*() helper macros 2020-05-08 08:02:48 +02:00
Thomas Haller
a0b2955907
shared: add NM_ENSURE_NOT_NULL() macro 2020-05-08 08:00:41 +02:00
Thomas Haller
6e9967939b
acd: fix char buffer argument to _acd_event_to_string_buf() 2020-05-08 07:43:27 +02:00
Thomas Haller
bdac27eb28
config: merge branch 'th/config-fix-subtract-plugins'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/491
2020-05-07 14:15:28 +02:00
Thomas Haller
85fa23a6b5
config: minor cleanup in _sort_groups_cmp() and _intern_config_write_sort_fcn() 2020-05-07 14:08:34 +02:00
Thomas Haller
9ea7bf0da7
config: use nm_streq() and NM_STR_HAS_PREFIX() in "nm-config.c"
- nm_streq() is easier to read.

- NM_STR_HAS_PREFIX() works only with string literals, and gets
  inlined up to one strncmp() call. There is no need to call glib,
  to determine strlen(prefix) (that we already know), and then to
  call strncmp().
2020-05-07 14:08:34 +02:00
Thomas Haller
ff321e250e
config: use NM_STR_HAS_PREFIX_WITH_MORE() instead of duplicate implementation 2020-05-07 14:08:33 +02:00
Thomas Haller
3201b06925
config: use cleanup attribute in read_config() 2020-05-07 14:08:33 +02:00
Thomas Haller
f588dabb4f
settings: ensure that "plugins-=ifcfg-rh" works with the default plugins
On Fedora/RHEL, the default for main.plugins is "ifcfg-rh". You would
expect that a single configuration file

  [main]
  plugins-=ifcfg-rh

would result in an empty list of plugins (which subsequently gets
completed with "keyfile").

That didn't happen due to a bug. Fix it.
2020-05-07 14:08:33 +02:00
Thomas Haller
5cdb636301
keyfile: use nm_g_error_matches() in g_error_matches()
nm_g_error_matches() can be inlined and first checks whether the error
argument is not NULL. At least from the keyfile accessor functions, use
this macro, as they are called many times.
2020-05-07 14:08:32 +02:00
Thomas Haller
e08bb66b34
keyfile,config: use nm_keyfile_error_is_not_found() helper 2020-05-07 14:08:32 +02:00
Thomas Haller
df27164d5e
shared: add nm_keyfile_error_is_not_found() helper 2020-05-07 14:08:32 +02:00
Thomas Haller
e31b31e5e5
shared: add nm_g_error_matches() helper 2020-05-07 14:08:31 +02:00
Thomas Haller
a617177070
shared: add NM_STR_HAS_PREFIX_WITH_MORE() helper 2020-05-07 14:08:31 +02:00
Thomas Haller
5a09292f1f
shared: fix accessing "str" argument to NM_STR_HAS_PREFIX() macro twice
Macros preferably behave function-like, for example in that they evaluate
arguments exactly ones. Sometimes, we want to evaluate arguments
lazily, like in NM_IN_SET() or nm_g_set_error_take_lazy(). But it
is almost always undesirable to evaluate an argument more than once.

Fix NM_STR_HAS_PREFIX() for that.

Also, rename the local variable to not use the name "_str",
which may be a common name that the caller would like to use.
2020-05-07 14:08:31 +02:00
Thomas Haller
6325297367
all: merge branch 'th/lgtm-com-fixes-1'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/494
2020-05-07 14:01:14 +02:00
Thomas Haller
64331d6085
examples: remove unused code from "examples/python/dbus/vpn.py"
lgtm.com says "The value assigned to local variable all_connections is never used".
Just drop the entire statement. It's not right there.
2020-05-07 13:58:16 +02:00
Thomas Haller
8ad448444a
examples: avoid "x == None" checks in python examples
lgmt.com says "Testing for None should use the is operator".
2020-05-07 13:58:15 +02:00
Thomas Haller
c7d0a86050
examples: avoid "except" for BaseException in examples
lgtm.com flags this as "Except block directly handles BaseException".
2020-05-07 13:58:14 +02:00
Thomas Haller
5c08981356
examples: avoid non-thread-safe localtime() function example
Just to silence the warning on lgtm.com.
2020-05-07 13:58:13 +02:00
Thomas Haller
41a7a26259
examples: remove unused imports from python examples 2020-05-07 13:58:13 +02:00
Thomas Haller
a5614dc469
examples: remove unused assignment in "examples/python/gi/wifi-p2p.py"
lgtm.com warns about this.
2020-05-07 13:58:12 +02:00
Thomas Haller
cc1c2c9fc9
libnm: remove unused import from "generate-setting-docs.py" 2020-05-07 13:58:11 +02:00
Thomas Haller
0258616bd8
libnm: fix redundant line constructing dbus_type_name_map in "generate-setting-docs.py" 2020-05-07 13:58:10 +02:00
Thomas Haller
9e6d6191d1
tests: add include guard to "nm-test-libnm-utils.h" header
It causes a warning on lgtm.com.
2020-05-07 13:58:10 +02:00
Thomas Haller
9acf32a7a8
config: avoid lgtm.com warning about int bitfield for NMConfigDeviceStateData.nm_owned
lgtm.com warns:

  int nm_owned:3;
  >> Bit field nm_owned of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type.

So make it a NMTernary instead. It's nicer anyway.
2020-05-07 13:58:09 +02:00
Thomas Haller
3a1273f777
cli: avoid empty if block without a comment
lgtm.com flags this as "Empty block without comment".
Avoid it.

This code is of course ugly. Much work was already done to
port such occurrences, and more is needed. I won't add a FIXME
comment, because lgtm.com flags those too. :)
2020-05-07 13:58:09 +02:00
Thomas Haller
b93e12cb43
cli: avoid redundant "if" check that is always TRUE in nmcli_editor_tab_completion() 2020-05-07 13:58:09 +02:00
Thomas Haller
6f0dadabd7
cli: avoid non-thread-safe localtime() function in nmcli
Static analysis tools flag the use of localtime() because it is not
thread safe. Of course, that was no problem here, but avoiding the
warning is simple.

Also, if we allocate 128 bytes, let strftime use it.
2020-05-07 13:58:08 +02:00
Thomas Haller
53b2297701
ndisc: avoid static analysis complaining about overflow check in receive_ra()
lgtm.com flags this. The check was there to be better safe than sorry.
Also, it seems better to have code that shows what happens instead
of a verbose code comment (or no comment at all). Anyway, avoid the
false positive.
2020-05-07 13:58:08 +02:00
Thomas Haller
b447c80ad8
acd: avoid alloca() inside an unbounded loop 2020-05-07 13:58:08 +02:00
Thomas Haller
d170f8b7f2
device: fix compilation error "--without-more-asserts"
Defining the name "dispose" breaks

   object_class->dispose = dispose;

below.

Fixes: fdba9200c0 ('device: avoid coverity warning about unused variable')
2020-05-07 11:15:22 +02:00
Beniamino Galvani
be3549abbd merge: branch 'bg/coverity'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/495
2020-05-07 10:37:56 +02:00
Beniamino Galvani
a29b13c7f1 libnm: remove early return statement in test_nm_auth_permissions()
Reported by coverity:

>>> CID 210230: Control flow issues (UNREACHABLE)
>>> This code cannot be reached: "i = 0;".

Fixes: 09e17888f7 ('libnm: add mapping functions between string and NMClientPermission enum')
2020-05-07 10:01:59 +02:00
Beniamino Galvani
581aa981c2 ifcfg-rh: check return value of fdopen()
Reported by coverity:

>>> CID 210222: Null pointer dereferences (NULL_RETURNS)
>>> Dereferencing a pointer that might be "NULL" "f" when calling
    "fseek".

Fixes: ac5206aa9c ('2007-11-21')
2020-05-07 10:01:57 +02:00
Beniamino Galvani
272f19108b libnm: fix assertion in NML_IS_DBUS_OBJECT()
Reported by coverity:

>>> CID 210228: Null pointer dereferences (REVERSE_INULL)
>>> Null-checking "dbobj" suggests that it may be null, but it has
    already been dereferenced on all paths leading to the check.

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2020-05-07 10:01:56 +02:00
Beniamino Galvani
966e3341a6 libnm-core: replace malloc() with g_malloc()
For consistency with the rest of the code, prefer g_malloc() over
malloc().
2020-05-07 10:01:54 +02:00
Beniamino Galvani
8cb58ef1eb cli/polkit: add missing variable initialization in retrieve_session_id_cb()
Reported by coverity:

>>> CID 210213 Uninitialized pointer read (UNINIT)
>>> Using uninitialized value iter when calling
    _nm_auto_free_variant_iter

Fixes: df1d214b2e ('clients: polkit-agent: implement polkit agent without using libpolkit')
2020-05-07 10:01:52 +02:00
Beniamino Galvani
fbccd24db6 cli/polkit: add missing variable initialization in dbus_method_call_cb()
Reported by coverity:

>>> CID 210217: (UNINIT)
>>> Using uninitialized value "identities_gvariant" when calling
    "gs_local_variant_unref".

Fixes: df1d214b2e ('clients: polkit-agent: implement polkit agent without using libpolkit')
2020-05-07 10:01:50 +02:00
Thomas Haller
20f5d8877b
all: merge branch 'af/settings-add-matches'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/431
2020-05-07 00:07:15 +02:00
Thomas Haller
5beb42b942
device: style fixes 2020-05-06 17:10:31 +02:00
Thomas Haller
bdd0e89b9a
device: handle match.driver also with unknown device driver
If the driver is unknown, that doesn't necessarily mean that the match
passes. Instead, the match passes if there is no positive match that
asks for the driver name.
2020-05-06 16:20:11 +02:00
Thomas Haller
623cf7c9a3
core: accept %NULL argument to nm_wildcard_match_check()
%NULL means that the string is unknown. The pattern should still match
if there are no positive matches that want to match against the string.

For example, the nm_device_get_driver() might return NULL. If we have
a match.driver setting, we still need to handle that somehow that it
makes sense.
2020-05-06 16:14:16 +02:00
Thomas Haller
ace437338d
ifcfg-rh: minor cleanup of make_match_setting() 2020-05-06 16:01:13 +02:00
Thomas Haller
cf546ee789
ifcfg-rh: refactor write_match_setting()
- write_match_setting() never fails. Don't let it return a boolean
  error result.

- drop "if (!name || !name[0])" checks. It's not possibly to configure
  a name %NULL in NMSettingMatch (without triggering assertions). Also,
  an empty name "" is not valid, so we wouldn't expect it. There is one
  problem with the way how we concatenate the string list: it uses
  spaces as separator, while stripping spaces. That means, in the
  currenty format, an empty token "" cannot be expressed. On the other
  hand, serializing it would lead to duplicate spaces, that get dropped
  during re-read. So the empty name wasn't valid from the start, but it
  also cannot be encoded.

- use nm_gstring_add_space_delimiter() and nm_gstring_prepare().
2020-05-06 15:58:43 +02:00
Thomas Haller
8bb172ee2b
cli: use default implementation of getter for NMSettingMatch properties
The default implementation should be good enough. Use it.
2020-05-06 15:44:29 +02:00
Thomas Haller
0ba444a084
libnm: allocate device and kernel_command_line arrays in NMSettingMatch lazy 2020-05-06 15:39:14 +02:00
Thomas Haller
7939c8e770
libnm: allocate interface_name array in NMSettingMatch lazy
Also track the interface_name in a GArray so that
nm_setting_match_get_interface_names() returns a NULL
terminated strv array.
2020-05-06 15:39:08 +02:00
Thomas Haller
5056e0d3c8
shared: add nm_strvarray_*() helper API
GPtrArray does not support NULL terminating the pointer array. That
makes it cumbersome to use it for tracking a strv array. Add a few
helper functions nm_strvarray_*() that help using a GArray instead.
2020-05-06 15:19:27 +02:00
Thomas Haller
8dd74fe364
shared: add nm_indirect_g_free() helper 2020-05-06 15:19:25 +02:00