Commit graph

1084 commits

Author SHA1 Message Date
Matt Bernstein
82b2251d2d
cli: make clients able to configure VXLAN without "remote"
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/658
2020-10-22 13:32:29 +02:00
Thomas Haller
4eb3b5b9dd
cli: fix showing active state for nmcli con show with fields
With "connection.multi-connect", a profile can be activated multiple
times on a device with `nmcli connection show`. Also, a profile may be
in the process of deactivating on one device, while activating on
another one. So, in general it's possible that `nmcli connection show`
lists the same profile on multiple lines (reflecting their multiple
activation states).

If the user requests no fields that are part of the activation state,
then the active connections are ignored. For example with `nmcli
-f UUID,NAME connection show`. In that case, each profile is listed only
once.

On the other hand, with `nmcli -g UUID,NAME,DEVICE connection show` the
user again requested also to see the activation state, and a profile can
appear multiple times.

To handle that, we need to consider which fields were requested.

There was a bug where the "ACTIVE" field was not treated as part of the
activation state. That results in `nmcli -f UUID,NAME,ACTIVE connection
show` always returning "no". Fix that.

Fixes: a1b25a47b0 ('cli: rework printing of `nmcli connection` for multiple active connections')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/547

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/642
2020-10-09 10:23:23 +02:00
Thomas Haller
4e966a7f36
cli: introduce NmcColorPalette struct instead of plain array
We do have types in C. Use them.
2020-10-09 09:52:10 +02:00
Thomas Haller
b7da3da7ac
cli: refactor resolve_color_alias() to use binary search 2020-10-08 17:01:27 +02:00
Thomas Haller
7d4f46425c
cli: move string to NMMetaColor conversion to separate function
And use NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(), which does a binary search.
2020-10-08 17:01:27 +02:00
Thomas Haller
f1830ab0de
cli: honor and prefer color schemes with ".scheme" extension
According to `man terminal-colors.d`, the extension should be ".scheme"
and not ".schem". Prefer that, but keep honoring ".schem" file, if it
exists.

https://bugzilla.redhat.com/show_bug.cgi?id=1886336
2020-10-08 17:01:27 +02:00
Thomas Haller
88071abb43
all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
20ebacbea2
libnm: cleanup handling of "connection.permissions" and improve validation
Previously, both nm_setting_connection_add_permission() and the GObject
property setter would merely assert that the provided values are valid
(and otherwise don't do anything). That is bad for handling errors.

For example, we use the property setter to initialize the setting from
keyfile and GVariant (D-Bus). That means, if a user provides an invalid
permissions value, we would emit a g_critical() assertion failure, but
otherwise ignore the configuration. What we instead need to do is to
accept the value, and afterwards fail verification. That way, a proper error
message can be generated.

  $ mcli connection add type ethernet autoconnect no ifname bogus con-name x connection.permissions 'bogus:'

  (process:429514): libnm-CRITICAL **: 12:12:00.359: permission_new: assertion 'strchr (uname, ':') == NULL' failed

  (process:429514): libnm-CRITICAL **: 12:12:00.359: nm_setting_connection_add_permission: assertion 'p != NULL' failed
  Connection 'x' (2802d117-f84e-44d9-925b-bfe26fd85da1) successfully added.
  $ $  nmcli -f connection.permissions connection show x
  connection.permissions:                 --

While at it, also don't track the permissions in a GSList. Tracking one
permission in a GSList requires 3 allocations (one for the user string,
one for the Permission struct, and one for the GSList struct). Instead,
use a GArray. That is still not great, because GArray cannot be embedded
inside NMSettingConnectionPrivate, so tracking one permission also
requires 3 allocations (which is really a fault of GArray). So, GArray
is not better in the common case where there is only one permissions. But even
in the worst case (only one entry), GArray is no worse than GSList.

Also change the API of nm_setting_connection_add_permission().
Previously, the function would assert that the arguments are in
a certain form (strcmp (ptype, "user") == 0), but still document
the such behaviors like regular operation ("[returns] %FALSE if @ptype
or @pitem was invalid"). Don't assert against the function arguments.
Also, if you first set the user to "fo:o", then
nm_setting_connection_add_permission() would accept it -- only at
a later phase, the property setter would assert against such values.
Also, the function would return %FALSE both if the input value was
invalid (an error) and if the value already existed. I think the
function should not treat a duplicate entry like a badly formatted
input.
Now the function does much less asserting of the arguments, but will
return %FALSE only if the values are invalid. And it will silently ignore
duplicate entries.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/636
2020-09-29 11:56:32 +02:00
Thomas Haller
8841d529e1
format: manually replace remaining tabs with spaces and reformat 2020-09-29 09:12:27 +02:00
Thomas Haller
740b092fda
format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e
all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Antonio Cardace
b4d8e69cd4
cli: use C comment to not break clang-formatting
clang-format will re-format this in multiple lines, use C comment
to not break compilation after applying code-style with clang-format.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:01:23 +02:00
Thomas Haller
b8811d97a4
all: require a semicolon after NM_CACHED_QUARK_FCN() 2020-09-23 10:55:17 +02:00
Thomas Haller
426a4c9d50
all: replace cleanup macro "gs_unref_keyfile" by "nm_auto_unref_keyfile" 2020-09-02 17:46:43 +02:00
Thomas Haller
c25f4d947a
shared: enforce compatible C-type argument for nm_utils_strv_dup()
Use a macro that uses NM_CAST_STRV_CC() to cast the strv argument. Note that
NM_CAST_STRV_CC() uses C11's _Generic() to check whether the argument is
of a valid type.
2020-08-25 08:54:36 +02:00
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