Commit Graph

913 Commits

Author SHA1 Message Date
Thomas Haller
3c82db710f cli: reset default value of properties via set_fcn()
The property implementation must itself decide how to reset a value.
We must not rely on properties being plain GObject properties.

Let set_fcn() accept %NULL value to indicate resetting the default.
2019-03-25 09:12:32 +01:00
Thomas Haller
649968632e cli: merge remove-property, reset-property and set-property
It's fundamentally wrong to have separate "remove_fcn" and "set_fcn"
implementations. Set, reset, add, and remove are all similar, and should
be implemented in a similar manner.

Merge the implementations all in set-property, which now can:

 - reset the value (value == NULL && modifier == '\0')
 - set a value     (value != NULL && modifier == '\0')
 - add a value     (value != NULL && modifier == '+')
 - remove a value  (value != NULL && modifier == '-')

The real problem is that remove_fcn() behaves fundamentally different
from set_fcn(). You can do "+setting.property value1,value2" but you
cannot remove them the same way. That is because most remove_fcn()
implementations don't expect a list of values. But it's also because of
the unnatural split between set_fcn() and remove_fcn().

The next commit will merge set_fcn(), remove_fcn() and reset property.
This commit just merges them all in nmc_setting_set_property().
2019-03-25 09:12:32 +01:00
Thomas Haller
de93bc0712 cli: don't use nmc_property_get_gvalue() in ipv4_method_changed_cb()
ipv4_method_changed_cb() and ipv6_method_changed_cb() are horrible hacks, as they
use a static variable to cache the previous value.

Anyway, don't fix that now.

We are going to drop nmc_property_get_gvalue()/nmc_property_set_gvalue()
because that works only with GObject based properties -- and having this
API around wrongly suggests it works in general. Use the native types
directly.
2019-03-25 09:12:32 +01:00
Thomas Haller
f24ada398a cli: drop nmc_property_set_default_value()
It's wrong to pretend that all properties are GObject based. Drop
nmc_property_set_default_value() and use nmc_setting_reset_property()
instead.
2019-03-25 09:12:32 +01:00
Thomas Haller
7b5d514aef cli: implement nmc_setting_reset_property() based on nmc_setting_set_property()
"reset" is just a special case of "set". We can keep nmc_setting_reset_property() as a convenience
function, but it must be implemented based on nmc_setting_set_property().

Also, reset only used nmc_property_set_default_value(), which only works
with GObject based properties. It's wrong to assume that all properties
are GObject based. By implementing it based via nmc_setting_set_property()
we can fix this (later).
2019-03-25 09:12:32 +01:00
Thomas Haller
cb5a81399a cli: don't interpret value as index too early for nmc_setting_remove_property_option()
Not all implementations support having the value being an index.
For example, the implementations that are done via DEFINE_REMOVER_OPTION() macro.

The meaning of the "value" string must not be determined by
nmc_setting_remove_property_option(). It's up to the implementation
to decide whether to allow an index and how to interpret it.
2019-03-25 09:12:32 +01:00
Thomas Haller
a6ee43d1c1 cli/wireguard: add import functionality for WireGuard
Support importing ".conf" files as `wg-quick up` supports it.

`wg-quick` parses several options under "[Interface]" and
passes the remainder to `wg setconf`.

The PreUp/PreDown/PostUp/PostDown options are of course not supported.

"Table" for the moment behaves different.

(cherry picked from commit a3a8583c31)
2019-03-07 22:22:39 +01:00
Thomas Haller
4a137f919b cli: fix completion for nmcli connection import
If we already specified "type" or "file", don't offer it for
completion again.

  $ nmcli connection import type openvpn <TAB>
  file  type

(cherry picked from commit fea0f4a5ea)
2019-03-07 22:22:39 +01:00
Thomas Haller
c5a247c4c0 cli: add nmc_complete_strv() which takes a string array for completion that may contain NULL
This will allow for a convenient calling pattern when some elements
should be printed optionally.

(cherry picked from commit 62b939de4e)
2019-03-07 22:22:39 +01:00
Thomas Haller
b521f426ab libnm,cli: add NMSettingWireGuard
For now only add the core settings, no peers' data.

To support peers and the allowed-ips of the peers is more complicated
and will be done later. It's more complicated because these are nested
lists (allowed-ips) inside a list (peers). That is quite unusual and to
conveniently support that in D-Bus API, in keyfile format, in libnm,
and nmcli, is a effort.
Also, it's further complicated by the fact that each peer has a secret (the
preshared-key). Thus we probably need secret flags for each peer, which
is a novelty as well (until now we require a fixed set of secrets per
profile that is well known).
2019-02-22 11:00:10 +01:00
Jonathan Kang
243af16c5b Add polkit action for Wi-Fi scans
Previously, Wi-Fi scans uses polkit action
"org.freedesktop.NetworkManager.network-control". This is introduced
in commit 5e3e19d0. But in a system with restrict polkit rules, for
example "org.freedesktop.NetworkManager.network-control" was set as
auth_admin. When you open the network panel of GNOME Control Center, a
polkit dialog will keep showing up asking for admin password, as GNOME
Control Center scans the Wi-Fi list every 15 seconds.

Fix that by adding a new polkit action
"org.freedesktop.NetworkManager.wifi.scan" so that distributions can
add specific rule to allow Wi-Fi scans.

[thaller@redhat.com: fix macro in "shared/nm-common-macros.h"]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/68
2019-02-21 13:49:17 +01:00
Thomas Haller
55ce9d9de9 clients/secret-agent: allow suppressing prompting the entry-id when requesting secrets
When asking for the preshared-key for WireGuard peers, the secret request
will be very verbose with redundant information. Allow suppressing the entry
id from the prompt.
2019-02-14 08:00:29 +01:00
Thomas Haller
9beed4f661 all: replace strerror() calls with nm_strerror_native() 2019-02-12 08:50:28 +01:00
Thomas Haller
047998f80a all: cache errno in local variable before using it 2019-02-12 08:50:28 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Thomas Haller
65884733ec all: minor coding style fixes (space before parentheses) 2019-02-11 15:22:57 +01:00
Thomas Haller
2510f60e92 cli: avoid "-Wduplicate-decl-specifier" warning in nmcli's resolve_color_alias()
[1/2] Compiling C object 'clients/cli/2641089@@nmcli@exe/nmcli.c.o'.
    ../clients/cli/nmcli.c: In function ‘resolve_color_alias’:
    ../clients/cli/nmcli.c:507:4: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      } const aliases[] = {
        ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
e357d15023 Revert "cli: verify connections before sending them over to daemon"
Just calling nm_connection_verify() is not correct. We need
nm_connection_normalize() because otherwise we miss out on places
where we have common normalization steps implemented to fix a
connection. This is also what server-side is done.

Revert the patch, as it breaks CI tests.

I wonder also whether this is the right place. There are already
several places in "clients/cli/connections.c" that call verify()
and normalize(). These places should be unified so that there is
one place where we complete the connection. And it probably should be
done as a separate step before the add_new_connection()/update_connection()
calls.

This reverts commit ca58bcca0c.
2019-02-06 11:51:38 +01:00
Lubomir Rintel
ca58bcca0c cli: verify connections before sending them over to daemon
This way we generate the error messages on the client side and therefore
can localize them.
2019-02-05 10:20:30 +01:00
Lubomir Rintel
fab1116494 clients/cli: if the AP supports SAE, claim WPA3 support
RSN with SAE is what's called WPA3-Personal.
Also, if there's neither PSK nor 802.1x, it's not WPA2.
2019-02-05 10:20:30 +01:00
Lubomir Rintel
245c9c93d1 clients/cli: don't translate abbreviations 2019-02-05 10:20:27 +01:00
Lubomir Rintel
2344e958cf client/cli: send a PSK when using SAE 2019-02-05 10:20:27 +01:00
Lubomir Rintel
998ebe731e client/cli: add support for SAE key management flag 2019-02-05 10:20:27 +01:00
Lubomir Rintel
ab0d348792 client/devices: get rid of useless g_strdup()s
And, while at that, add a hint to the developer adding new items. It's
helps avoid a mistake that I believe is common (because I just made it
twice...).
2019-02-05 10:20:27 +01:00
Thomas Haller
93c848ca03 clients: don't tread secret agent as NMSecretAgentOld
Most of the times we actually need a NMSecretAgentSimple typed pointer.
This way, need need to cast less.

But even if we would need to cast more, it's better to have pointers
point to the actual type, not merely to avoid shortcomings of C.
2019-02-05 08:27:42 +01:00
Thomas Haller
2626eb6d8c cli: clear fields in nmc_cleanup()
Don't leave dangling pointers.
2019-02-05 08:22:01 +01:00
Thomas Haller
09090f2669 wifi-p2p: rename Wi-Fi P2P
After renaming the files, also rename all the content
to follow the "Wi-Fi P2P" naming scheme.
2019-02-01 17:02:57 +01:00
Benjamin Berg
42e60e327f core: Add basic P2P Wi-Fi Settings
The support is rather basic and only allows connecting to a specific
peer. However, this is actually already enough for many usecases.
2019-01-27 23:45:11 +01:00
Rafael Fontenelle
d81e10942f all: fix misspellings
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/64
2019-01-24 17:19:44 +01:00
Lubomir Rintel
96782b94e1 merge: branch 'master' of https://github.com/balrog-kun/NetworkManager
https://github.com/NetworkManager/NetworkManager/pull/137
2019-01-04 18:26:41 +01:00
Iñigo Martínez
35171b3c3f build: meson: Add trailing commas
Add missing trailing commas that avoids getting noise when another
file/parameter is added and eases reviewing changes[0].

[0] https://gitlab.gnome.org/GNOME/dconf/merge_requests/11#note_291585
2018-12-20 13:50:34 +01:00
Thomas Haller
0c17d34a7d cli: drop gettext() wrappers for no_l10n to-string functions
In most cases, we don't want the translated string (only marked
for translation, and then programatically the caller deciedes
whether to translate or not).

The few places that always call gettext() can do it explicitly.

Now, that our functions are all "no_l10n" by default, rename them.
2018-12-11 09:23:47 +01:00
Thomas Haller
3b515f54cf cli: don't translate connectivity state in terse output
Fixes: de7a159e69
2018-12-11 09:23:47 +01:00
Lubomir Rintel
f13da72b3c cli/devices: remove redundant Device/AC state evaluation
The state handling in add_and_activate_cb() and connect_device_cb() is
redundant to connected_state_cb() and in fact executed only if the
activation is really really really quick (which it never is).

Also, the return_text those implementations provide is different from
what connected_state_cb(), potentially confusing the users and adding
extra work for translators.

Not to mention extra lines of code, reading whose wastes our precious
time on the planet we could spend doing heroin instead.
2018-12-04 14:46:37 +01:00
Andrew Zaborowski
3593237527 cli: reuse connections in nmcli dev wifi con
Try to locate an existing connection before creating a new one when
handling "nmcli device wifi connect".  This allows WPA-Enterprise
networks to be activated this way, consistent with the comment that this
command is equivalent to clicking on an SSID in a GUI client.
2018-12-04 14:46:37 +01:00
Andrew Zaborowski
0c70a9ef6d cli: match both ssid and bssid when connecting to wifi
Instead of matching candidate APs by either SSID or BSSID (bssid1_arr)
make sure both match if a bssid2_arr was given.
2018-12-04 14:46:23 +01:00
Beniamino Galvani
cf1126f60b cli: avoid crash on device disconnect
When nm_device_disconnect_async() returns, the device could be still
in DEACTIVATING state, and so we also register to device-state signal
notifications to know when the device state goes to DISCONNECTED.

Sometimes it happens that the device state goes to DISCONNECTED before
nm_device_disconnect_async() returns. In this case the signal handler
exits the main loop and then the callback for disconnect_async() is
executed anyway because it was already dispatched, leading to an
invalid memory access.

To avoid this we should cancel nm_device_disconnect_async() when we
are quitting the main loop.

Reproducer:
  nmcli connection add type team ifname t1 con-name t1
  nmcli connection up t1
  nmcli device disconnect t1 & nmcli device delete t1

Crash example:
 ==14955==ERROR: AddressSanitizer: SEGV on unknown address 0xffffffff0000000b (pc 0x7f128c8ba3dd bp 0x0000004be080 sp 0x7ffcda7dc6e0 T0)
 ==14955==The signal is caused by a READ memory access.
    0 0x7f128c8ba3dc in g_string_truncate (/lib64/libglib-2.0.so.0+0x713dc)
    1 0x7f128c8bb4bb in g_string_printf (/lib64/libglib-2.0.so.0+0x724bb)
    2 0x45bdfa in disconnect_device_cb clients/cli/devices.c:2321
    3 0x7f128ca3d1a9 in g_simple_async_result_complete /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gsimpleasyncresult.c:802
    4 0x7f128cf85d0e in device_disconnect_cb libnm/nm-device.c:2354
    5 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    6 0x7f128ca508d5 in g_task_return /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1206
    7 0x7f128ca8ecfc in reply_cb /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gdbusproxy.c:2586
    8 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    9 0x7f128ca508d5 in g_task_return /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1206
    10 0x7f128ca83440 in g_dbus_connection_call_done /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gdbusconnection.c:5713
    11 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    12 0x7f128ca4ffac in complete_in_idle_cb /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1162
    13 0x7f128c893b7a in g_idle_dispatch gmain.c:5620
    14 0x7f128c89726c in g_main_dispatch gmain.c:3182
    15 0x7f128c897637 in g_main_context_iterate gmain.c:3920
    16 0x7f128c897961 in g_main_loop_run (/lib64/libglib-2.0.so.0+0x4e961)
    17 0x473afb in main clients/cli/nmcli.c:1067
    18 0x7f128c6a1412 in __libc_start_main (/lib64/libc.so.6+0x24412)
    19 0x416c39 in _start (/usr/bin/nmcli+0x416c39)

https://github.com/NetworkManager/NetworkManager/pull/254
https://bugzilla.redhat.com/show_bug.cgi?id=1546061
2018-11-30 14:15:27 +01:00
Lubomir Rintel
64e51241e6 cli: fix a couple of typos 2018-11-29 17:53:35 +01:00
Lubomir Rintel
b385ad0159 all: say Wi-Fi instead of "wifi" or "WiFi"
Correct the spelling across the *entire* tree, including translations,
comments, etc. It's easier that way.

Even the places where it's not exposed to the user, such as tests, so
that we learn how is it spelled correctly.
2018-11-29 17:53:35 +01:00
Lubomir Rintel
def03fd7cf cli/connections: improve sort by active connections
When sorting the active connections, use the same policy as "nmcli" and
"nmcli d", not just the connection state. It looks better that way.
2018-11-21 11:46:22 +01:00
Lubomir Rintel
13d2d332dd cli: deduplicate active connections sort
Both connections and devices need to sort active connections. Make the
more sensible policy default.
2018-11-21 11:46:22 +01:00
Lubomir Rintel
522fd14251 cli/connections: export nmc_active_connection_cmp()
To be able to sensibly sort devices we want to be able to sort their
active connections. Currently it's implemented redundantly.
2018-11-21 11:46:21 +01:00
Lubomir Rintel
2a7e60d724 cli/devices: sort hotspots above in nmcli output
In general we want to keep the connections that the user is most likely
to want to see topmost. Default connections should be close to the top,
but the connections that are likely to have been brought up manually
shall be above them. It applies to VPN connections and should apply to
Hotspots too.
2018-11-21 11:46:21 +01:00
Beniamino Galvani
a370faeb59 cli: wait for changed signal after updating a connection
In editor_menu_main(), after saving a connection we wait that the
Update2() D-Bus call returns and then we copy the NMRemoteConnection
instance over to @connection.

This assumes that when Update2() returns the remote connection
instance is already updated with new settings. Indeed, on server side
the NMSettingsConnection first emits the "Updated" signal and then
returns to Update2(). However, the Updated signal doesn't include the
new setting values and so libnm has to fire an asynchronous
nmdbus_settings_connection_call_get_setting() to fetch the new
settings, which terminates after the Update2().

So, to be sure that the remote connection got updated we have also to
listen to the connection-changed signal, which is always emitted after
an update.

https://bugzilla.redhat.com/show_bug.cgi?id=1546805
2018-11-20 15:16:53 +01:00
Beniamino Galvani
096eef61d4 cli: editor: reload secrets after updating connection
Connection secrets are lost after calling
nm_connection_replace_settings_from_connection() because @con_tmp
doesn't contain secrets; refetch them like we do when starting the
editor.
2018-11-20 15:15:58 +01:00
Beniamino Galvani
c7edb34eb9 cli: add --rescan option to help output 2018-11-05 09:32:20 +01:00
Beniamino Galvani
e107d3b593 cli: display double-dash long options in help
We support all of these:

 nmcli -v
 nmcli -version
 nmcli --version

Change the help output to display the first and last versions for
options, since they are the most common ones for command line tools.
2018-11-05 09:32:20 +01:00
Beniamino Galvani
d76ac490f5 cli: sort options in man page and program help
Options are displayed in a random order, sort them.
2018-11-05 09:32:20 +01:00
Beniamino Galvani
a985efaf93 cli: fix memory leaks 2018-11-02 14:56:40 +01:00
Beniamino Galvani
c0138cdb35 cli: wait for all wifi scans to finish before displaying the result
Otherwise devices are displayed in a inconsistent order.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/39
2018-11-02 14:56:40 +01:00