Commit Graph

1069 Commits

Author SHA1 Message Date
Thomas Haller
ba42189bb9 all: add trailing semicolon to NM_UTILS_LOOKUP_DEFINE()/NM_GOBJECT_PROPERTIES_DEFINE*() 2020-07-19 12:12:58 +02:00
Thomas Haller
b17e3cf707 all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Thomas Haller
5deb71625d cli: fix leak in do_device_modify() and minor cleanup 2020-07-13 17:16:28 +02:00
Thomas Haller
09c94bc24f cli: fix accessing argv with zero elements in nmc_process_connection_properties()
Without this, `nmcli device modify "$DEVICE"` leads to a crash. At least
since commit c5d45848dd ('cli: mark argv argument for command line
parsing as const'), when this happens.

That is, because it passes a NULL strv array with argc being set to
zero. nmc_process_connection_properties() is not supposed to access
the array, if there are no elements there.

Fixes: c5d45848dd ('cli: mark argv argument for command line parsing as const')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/492
2020-07-13 17:15:56 +02:00
Thomas Haller
b55578bf6e cli: fix alternating miimon/arp_interval settings for bond options in nmcli
Before 1.24, nm_setting_bond_add_option() would clear
miimon/arp_interval settings when the respective other was set.

That was no longer done, with the effect that enabling (for example)
miimon on a bond profile that has arp_interval enabled, sets both
conflicting options.

That is not a severe problem, because the profile still validates.
However, at runtime only one of the settings can be actually configured.

Fix that, by restoring the previous behavior for the client. But note
that this time it's implemented in the client, and not in libnm's
nm_setting_bond_add_option().
2020-07-11 11:18:54 +02:00
Yuri Chornoivan
4e33f8cd89 all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33:46 +02:00
Thomas Haller
2a1e621704 cli: suppress "(unknown)" output in terse mode for device properties HWADDR and DRIVER
$ nmcli -f GENERAL.HWADDR device show ovsport0
  GENERAL.HWADDR: (unknown)

but:

  $ nmcli -f GENERAL.HWADDR --terse device show ovsport0
  GENERAL.HWADDR:

This is an API change of nmcli.
2020-07-03 11:40:11 +02:00
Thomas Haller
05a84be550 cli: add nmc_meta_generic_get_str_i18n_null() helper 2020-07-03 11:37:45 +02:00
Sayed Shah
7337ab8959 all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +02:00
Beniamino Galvani
3ecfd13ded cli: fix reference count handling in hotspot error path
The connection is automatically unreferenced when the function
returns.

Fixes: 9c5ea0917d ('devices: reuse the hotspot connection if we find appropriate one'):
2020-06-18 14:25:58 +02:00
Beniamino Galvani
d13ca45ca2 all: add device.path property
Add a device property to expose its path as reported in the ID_PATH
udev property.
2020-06-12 16:04:06 +02:00
Thomas Haller
125cbf5737 docs: show aliases for settings in man nm-settings-nmcli 2020-06-12 14:01:26 +02:00
Thomas Haller
efe0ccf04a docs: use describe_doc for "generate-docs-nm-settings-nmcli.c"
In practice, this is exactly the same, because also the describe_doc
is generated. However, in the future they might diverge.
2020-06-12 12:29:37 +02:00
Thomas Haller
10020a9466 docs: generate nm-settings-docs-nmcli.xml based on nmcli meta data
We have the correct meta-data of supported properties for nmcli. It is
in clients/common. Use that for generating the manual page instead of
the properties that are part of libnm (some properties may be in libnm
but not supported by nmcli, or some properties may not be GObject
properties, and not detected as by GObject introspection).
2020-06-11 10:53:50 +02:00
Thomas Haller
ec332e3a25 cli: show differnt text for state of externally connected devices 2020-06-10 19:45:47 +02:00
Thomas Haller
a3528b1fe8 cli: show external connection in different color 2020-06-10 19:45:46 +02:00
David Bauer
45ab623c12 nm-supplicant-interface: fix removal of OWE flag from non-transition mode BSSIDs
Commit 37e7fa38c2 ("nm-supplicant-interface: enable OWE security
when transition mode is available") adds the OWE security flag in
case a valid OWE transtition mode IE is present on the beacon.

It also removes the OWE security flag in case the Iinformation elements
of a beacon are updated and a OWE transition mode IE can't be found.

When a pure OWE AP updates it's Information Elements (e.g. BSS Load
Element), the OWE security flag is falsely removed.

Introduce a new NM_802_11_AP_SEC_KEY_MGMT_OWE_TM security flag and use
it exclusively for OWE transition mode. Don't use the
M_802_11_AP_SEC_KEY_MGMT_OWE security flag on transition-mode APs.

Signed-off-by: David Bauer <mail@david-bauer.net>
2020-06-09 16:07:04 +02:00
Thomas Haller
446a145db5 cli: use nm_strdup_int() in "clients/cli/devices.c" 2020-05-14 12:03:24 +02:00
Thomas Haller
a1e12c01df cli: fix leak in show_device_lldp_list() for nmc_parse_lldp_capabilities() 2020-05-14 12:03:23 +02:00
Thomas Haller
589d51ca9d cli: fix leak in show_device_lldp_list() 2020-05-14 11:53:48 +02:00
Thomas Haller
18b903943d cli: fix memcpy() with %NULL pointers in nmc_get_devices_sorted()
UBSan correctly flags this:

  clients/cli/devices.c:966:2: runtime error: null pointer passed as argument 2, which is declared to never be null
2020-05-14 11:06:09 +02:00
Thomas Haller
801c895aa6 cli: cleanup internal functions in "clients/cli/connections.c"
There should be no change in behavior. Use cleanup attribute.
2020-05-13 10:31:11 +02:00
Thomas Haller
67283b4932 cli: use cleanup attribute in save_history_cmds() 2020-05-13 10:29:39 +02:00
Thomas Haller
360f0fae11 cli: move nmc_utils_read_passwd_file() to "common/nm-client-utils.c" 2020-05-13 10:28:04 +02:00
Thomas Haller
1086a47cda cli: refactor error handling in parse_passwords() 2020-05-13 10:28:04 +02:00
Thomas Haller
2285dd38ea cli: support backslash escaping in passwd-file
Rework parsing of nmcli's passwd-file.

1) support backslash escaping of secrets.

  - only the secret can be backslash escaped, the property and setting
    name cannot.

  This is a change in behavior for passwd-files with secrets that contain
  a backslash.

2) strip the white space around the secret. This is a change in behavior
  for secrets that had leading or trailing spaces. Note that you can
  backslash escape spaces in secrets.

3) strip white space around the setting.property key. This is also a
  change in behavior, but such keys would never have been valid
  previously (or the caller would have performed the same kind of
  stripping).

4) accept '=' as alternative delimiter beside ':'. The ':' feels really
  odd and unexpected. Also accept '='. This is a change in behavior if
  keys would contain '=', which they really shouldn't.

5) reject non-UTF-8 secrets and keys. For keys, that is not an issue,
  because such keys were never valid. For secrets, it probably didn't
  work anyway to specify non-UTF-8 secrets, because most (if not all)
  secrets are transmitted via D-Bus as strings where arbitrary binary
  is not allowed.

6) ignore empty lines and lines starting with '#'.

7) ensure we don't leak any secrets in memory.

1) to 4) are changes in behavior. 3) and 4) seem less severe, as they
only concern unusual setting.property keys, which really shouldn't be
used (although, VPN secrets can have almost arbitrary names *sigh*).
1) and 2) is more dangerous, as it changes behavior for secrets that
contain backslashes or leading/trailing white space.
2020-05-13 10:28:04 +02:00
Beniamino Galvani
211c6fa795 cli: unref main loop after destroying NMClient instance
Callbacks might reference the main loop when destroying the NMClient
instance. Unref the main loop later.

  # G_DEBUG=fatal-warnings valgrind --num-callers=100 nmcli device wifi connect home
  ^C
  Error: nmcli terminated by signal Interrupt (2)
  Error: Connection activation failed: (0) No reason given.
  ==11050== Invalid read of size 4
  ==11050==    at 0x4C90D3D: g_main_loop_quit (in /usr/lib64/libglib-2.0.so.0.6200.6)
  ==11050==    by 0x431435: quit (devices.c:934)
  ==11050==    by 0x43272C: connected_state_cb (devices.c:1919)
  ==11050==    by 0x4BF6741: g_closure_invoke (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x4C0A603: ??? (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x4C133AD: g_signal_emit_valist (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x4C139D2: g_signal_emit (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x4BFB1C3: ??? (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x4BFAAEC: ??? (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x4BFD86A: g_object_thaw_notify (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x48BA040: _nm_client_notify_event_emit (nm-client.c:937)
  ==11050==    by 0x48CA01F: _dbus_handle_changes_commit (nm-client.c:2850)
  ==11050==    by 0x48CC221: _dbus_handle_changes (nm-client.c:2864)
  ==11050==    by 0x48CC833: _init_release_all (nm-client.c:6969)
  ==11050==    by 0x48D2818: dispose (nm-client.c:7826)
  ==11050==    by 0x4BFBC27: g_object_unref (in /usr/lib64/libgobject-2.0.so.0.6200.6)
  ==11050==    by 0x43FF93: nmc_cleanup (nmcli.c:941)
  ==11050==    by 0x4410AD: main (nmcli.c:1005)
  ==11050==  Address 0x54738fc is 12 bytes inside a block of size 16 free'd
  ==11050==    at 0x4839A0C: free (vg_replace_malloc.c:540)
  ==11050==    by 0x4C9649C: g_free (in /usr/lib64/libglib-2.0.so.0.6200.6)
  ==11050==    by 0x4410A3: main (nmcli.c:1004)
  ==11050==  Block was alloc'd at
  ==11050==    at 0x483AB1A: calloc (vg_replace_malloc.c:762)
  ==11050==    by 0x4C96400: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6200.6)
  ==11050==    by 0x4C90A45: g_main_loop_new (in /usr/lib64/libglib-2.0.so.0.6200.6)
  ==11050==    by 0x441020: main (nmcli.c:987)

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/501
2020-05-12 23:00:01 +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
27e2d51abc cli: repeatedly trigger Wi-Fi scans while waiting for scan result
NetworkManager will reject scan requests, if it is currently scanning.
That is very wrong. Even if NetworkManager wants to ratelimit scan
requests or not scan at critical moments, it should never reject a
request, but remember and start scanning as soon as it can.
That should be fixed.

But regardless, also nmcli can do better.

If you issue

  $ nmcli device wifi list --rescan yes

once, it works as expected.

If you issue it again right after, the scan request of nmcli will be
rejected. But nmcli cannot just merely complete and print the result.
Instead, it will wait in the hope that a scan result will be present
soon. But if the request was simply rejected, then the result will
never come, and nmcli hangs for the 15 seconds timeout.

Instead, repeatedly re-trigger scan requests, in the hope that as soon
as possible we will be ready.
2020-04-24 13:58:46 +02:00
Thomas Haller
69eca25391 cli: let _print_fill() hide option if NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE is set
Regardless, whether the option is also currently the default.
2020-04-16 10:52:45 +02:00
Thomas Haller
0dbb9c279e cli/polkit: rename NM_POLKIT_LISTENER_SIGNAL_REQUEST signal to "request-sync"
The response is blocking, which generally is rather ugly. Let's not fix
that now, but at least rename the signal so that it clearly points this
out.
2020-04-10 10:44:52 +02:00
Thomas Haller
aede8fa554 cli: remove redundant return value from NMCCommand funcs
Many func implementations are asynchronous, that means, they
cannot return right away. Instead, they record the return value
in nmc->result_value.

The return value from the command functions was thus redundant.
In the best case, the return value agrees with the cached result
in nmc->result_value, in which it was unnecessary. In the worst case,
they disagree, and overwrite each other.

nmc->result_value is state. Tracking state is hard, and there should
be fewer places where the state gets mutated. Also, the rules how that
happened should be clearer. Drop the redundant, conflicting mechanism.
2020-04-10 10:44:37 +02:00
Thomas Haller
c5d45848dd cli: mark argv argument for command line parsing as const
It's bad style to pass the argv argument around and mutate it.
We shouldn't mutate it, and not assume that it stays around after
the function returns to the caller (meaning, we should clone the
array if we intend to use it later).

Add const specifier.
2020-04-10 10:27:27 +02:00
Thomas Haller
3a451141bd cli: merge implementations for do_networking_on_off() 2020-04-10 10:27:27 +02:00
Thomas Haller
d39f5c264b cli: pass cmd to NMCCommand.func()
It is useful from inside a function to know the command that it belongs to.
Currently we have do_networking_on() and do_networking_off() as separate
functions. However, these are basically the same with a minor difference.
If the func callback could know the "cmd" that it was called for, these
function can be combined.

Of course, without passing the NMCCommand instance, you still can
achieve the same results, especially as the NMCCommand instances are
static and known at compile time: just have separate func
implementations. But by passing the command to the function, they
*can* be combined, which is a useful thing to do.
2020-04-10 10:27:27 +02:00
Thomas Haller
e05f35f9f1 cli: cleanup NMCCommand and declarations of func implementations
- move the main func declarations to nmcli.h and give them a common
prefix "nmc_command_func_" prefix.

- remove some of the header files that are now empty. In fact, these
headers did not really declare some well separated module. While we
probably should structure the code in nmcli better with better layering,
it was not and still is not. Having these dummy headers don't mean that
the code is well structured and they serve little purpose.

- move the static NMCommand lists variables into the function scope
where they are used.
2020-04-10 10:27:27 +02:00
Thomas Haller
038d53a745 cli: hide nm_cli global variable from public headers 2020-04-04 19:28:41 +02:00
Thomas Haller
30b8bb476a cli: avoid using nm_cli global variable in print_data() 2020-04-04 19:28:41 +02:00
Thomas Haller
dbf697c759 cli: avoid passing full NmCli global variable to nm_cli_spawn_pager()
We should not use global variables, and we should minimize the state
that we pass around. Instead of requiring the full NmCli struct in
nm_cli_spawn_pager(), pass only the necessary data.

This reduces our use of global variables.
2020-04-04 19:28:41 +02:00
Thomas Haller
7627173c0e cli: make nmc_meta_environment_arg const pointer
Of course, we later pass the point on, where we need to cast the constness away
again. This is more a reminder that we aren't suppost to change the variable.
2020-04-04 19:28:41 +02:00
Thomas Haller
873f4795b2 cli: add and use nm_cli_global_readline global variable
We should try to avoid access to global variables. For libreadline
callbacks we still need a global variable.

Introduce a global variable nm_cli_global_readline, specially for this
use. It makes the places clear where we use it, and discourages
the use at other places, where we better avoid global variables.
2020-04-04 19:28:41 +02:00
Thomas Haller
93a6bcc8a2 cli: fix nmcli device wifi list --rescan=yes to wait
Fixes: db396cea9d ('cli: rework do_device_wifi_list() to scan and print Wi-Fi list')
2020-04-03 11:26:49 +02:00
Thomas Haller
46dd4d0fbf meson: merge branch 'inigomartinez/meson-license'
Add SPDX license headers for meson files.

As far as I can tell, according to RELICENSE.md file, almost everybody
who contributed to the meson files agreed to the LGPL-2.1+ licensing.
This entails the vast majority of code in question.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/397
2020-03-28 12:45:19 +01:00
Beniamino Galvani
2334a27692 cli: support setting removal 2020-03-23 11:42:57 +01:00
Thomas Haller
52dbab7d07 all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like

   GPtrArray *ptr_arr = ...

   g_clear_pointer (&ptr_arr, g_array_unref);

Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.

[1] f9a9902aac

We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.

Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.

Replace:

   sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:22:38 +01:00
Thomas Haller
42edeb62a3 cli: use async method D-Bus for nmcli radio wifi on|off
Showcase nm_client_dbus_set_property().

Thereby, also print error messages and return an error if
the command fails.

Also, enable PolicyKit authentication (although, I think there are
some bugs with this still).
2020-03-23 09:38:23 +01:00
Thomas Haller
c6c15c2c25 cli: use async method D-Bus for nmcli networking on|off
Previously, we would call the synchronous nm_client_networking_set_enabled()
method. There were 3 problems:

1) nmcli ignored the return value, that means, if the request failed with
  access denied it would just silently pretend that it succeeded.

2) nmcli first called nmc_start_polkit_agent_start_try(), but when
  invoking the synchronous method, the main context is busy and a
  polkit request cannot possibly be handled.

3) nm_client_networking_set_enabled() is deprecated.

Fix all of these, by calling the D-Bus method directly.

Policykit authentication requests are only handled partly. There
seems to be an unrelated race/bug. Now it works sometimes.
2020-03-23 09:37:53 +01:00
Thomas Haller
d99d1dc265 cli: replace deprecated and synchronous nm_client_set_logging()
This is more a showcase for using nm_client_dbus_call(), than a
real use.

In this case, nmcli was mostly fine to just invoke the synchronous API
and not care about the problems that it had.

Still, replace it, and show the suggested alternative.
2020-03-23 09:33:52 +01:00