Commit Graph

722 Commits

Author SHA1 Message Date
Beniamino Galvani
61b666902b cli: enable secret-agent only after activation
Change the activation procedure for connections that require secrets
in the following way:

 - nmcli creates a secret-agent and leaves it disabled so that
   incoming requests are queued
 - nmcli calls ActivateConnection()
 - when the method returns success, the secret-agent gets enabled and
   all queued requests are processed

When the user activates a connection which is already auto-activating,
NM will deactivate the current active-connection and will call
CancelGetSecrets() for it before the new ActivateConnection()
returns. In this way, when the secret-agent is enabled by nmcli, we
have the guarantee that there aren't any queued requests for
the deactivating connections.

https://bugzilla.redhat.com/show_bug.cgi?id=1438476
2017-11-02 15:25:59 +01:00
Lubomir Rintel
aec8d36b3e clients: add support for ovs-bridge setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel
6f73b4608a clients: add support for ovs-port setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel
6dcd54b0de clients: add support for ovs-interface setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel
e7ab81098a clients: add support for ovs-patch setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel
fb8ea059e6 cli: ignore PAGER when escalating privileges
nmcli typically doesn't run setuid, nor uses file capabilities or is labelled
for a SELinux domain trainsition upon execution.

But in case anyone has any reason to do that, we should follow good
security practices and not exec whatever is set in the environment.
2017-10-30 15:27:05 +01:00
Thomas Haller
f3146de41b libnm: avoid unnecessary copies accessing NMIPRoute's attributes
We want to support large number of routes. Reduce the number
of copies, by adding internal accessor functions.

Also, work around a complaint from coverity:

  46. NetworkManager-1.9.2/libnm-core/nm-utils.c:1987:
  dereference: Dereferencing a null pointer "names".
2017-10-30 14:12:41 +01:00
Thomas Haller
31facf6fad cli: fix leak in _output_selection_parse()
Reported by coverity.

Fixes: fdd40b6a68
2017-10-30 11:18:25 +01:00
Thomas Haller
53aa340476 nmcli: fix wrongly adding a generic setting when constructing connection
nmc_read_connection_properties() iterates over the input arguments, and
completes the connection.

Initially, the type is not yet known, in that case, we should not wrongly
assume that this is a generic connection. Later, when the type is specified,
con_settings() will return the correct settings.

Previously, this would wrongly add a [generic] section:

  $ nmcli connection add type ethernet ifname eth1 con-name ethie autoconnect no ipv4.method auto ethernet.cloned-mac-address random

With the fix, it still works to specify the type later:

  $ nmcli connection add ifname eth1 con-name ethie autoconnect no ipv4.method auto type ethernet

but it doesn't work, to specify the type after type-specific options:

  $ nmcli connection add ifname eth1 con-name ethie autoconnect no ipv4.method auto ethernet.cloned-mac-address random type ethernet
  Error: invalid or not allowed setting 'ethernet': 'ethernet' not among [connection, ipv4, ipv6, proxy].

The patch doesn't change the latter limitation.

Fixes: c5324ed285
2017-10-26 19:07:24 +02:00
Thomas Haller
3434261811 core,clients: use our own string hashing function nm_str_hash()
Replace the usage of g_str_hash() with our own nm_str_hash().

GLib's g_str_hash() uses djb2 hashing function, just like we
do at the moment. The only difference is, that we use a diffrent
seed value.

Note, that we initialize the hash seed with random data (by calling
getrandom() or reading /dev/urandom). That is a change compared to
before.

This change of the hashing function and accessing the random pool
might be undesired for libnm/libnm-core. Hence, the change is not
done there as it possibly changes behavior for public API. Maybe
we should do that later though.

At this point, there isn't much of a change. This patch becomes
interesting, if we decide to use a different hashing algorithm.
2017-10-18 13:05:00 +02:00
Beniamino Galvani
1824cc9e3f clients: move get_effective_activation_state() to nm-clients-utils.c 2017-10-16 17:26:49 +02:00
Beniamino Galvani
aa964ae969 build: move nm-client-utils.c to libnmc-base.a
In a later commit we'll add a new generic client function used by
nmcli and nmtui. nm-client-utils.c seems the right place for it, so
move the file to the base library that is used by both clients.

While at it, also put in that file some functions that will be needed
by nmtui.
2017-10-16 17:25:35 +02:00
Beniamino Galvani
aec559cea5 cli: split evaluation of activation state
The code used to determine the activation state is useful for other
clients as well, let's split it into a dedicated function that can be
shared.
2017-10-16 17:25:30 +02:00
Thomas Haller
a22b017830 cli: show additional route attributes in IP4_CONFIG output 2017-09-26 19:36:51 +02:00
Thomas Haller
ccb83e34a3 cli: refactor printing IP6 device info 2017-09-26 19:36:51 +02:00
Thomas Haller
889ecc98a1 cli: use cleanup attribute in editor_menu_main() 2017-09-26 15:11:58 +02:00
Thomas Haller
54490be96d cli: fix crash in interactive mode for "describe ."
https://bugzilla.gnome.org/show_bug.cgi?id=788104
2017-09-26 15:11:58 +02:00
Beniamino Galvani
7af471919a cli: wifi: connect with PSK when the AP supports WPA-PSK and WPA-EAP
'nmcli device wifi connect' only supports WEP and WPA-PSK at the
moment, but not WPA-EAP. If the AP supports both WPA-PSK and WPA-EAP,
nmcli doesn't add the PSK to the connection, causing a connection
failure. Fix this.

https://bugzilla.redhat.com/show_bug.cgi?id=1492064
2017-09-20 09:23:54 +02:00
Thomas Haller
24a732c8e7 cli: show new enable-disable-connectivity-check permission 2017-08-17 23:09:07 +02:00
Thomas Haller
f42b4960f8 cli: warn when adding connection with a name that already exists
As far as NetworkManager is concerned, the "connection.id" (also called
"con-name" in nmcli) is a pretty name and does not need to be unique.

UI components usually show the "connection.id" instead of the
"connection.uuid" identifier. It is hence likely, that the user
would not intentionally re-use the same name for multiple connection
profiles.

Print a warning to stderr when the user adds such a connection.

This only affects `nmcli connection add` and `nmcli connection import`,
but not `nmcli connection clone` and not interactive edit mode.

https://bugzilla.redhat.com/show_bug.cgi?id=1460796
2017-07-17 14:49:31 +02:00
Beniamino Galvani
f395a0c29b cli: don't track device state for VPN connections
Currently nmcli considers the state of the device associated to a
connection to determine the success of an activation; for VPNs the
device is the parent interface on which the VPN is established.

This means that VPNs on bond/bridge/team interfaces are reported as
connected immediately because of the special handling of master
devices state in check_activated().

The parent device state is not meaningful for VPNs, so don't track it.
2017-07-09 16:10:54 +02:00
Thomas Haller
343c967e66 clients: make meta data subtypes of NMObjBaseInst
Yes, this wastes 4 times an unused GType instance
in the class structure.
2017-07-05 14:22:10 +02:00
Thomas Haller
c4ef6f2d2f cli: fix assertion in tab completion for gen_property_names()
$ nmcli connection edit type ethernet
  nmcli> describe x.y<TAB>
  (process:29799): libnmc-CRITICAL **: nm_meta_setting_info_editor_find_by_name: assertion 'setting_name' failed
2017-06-29 09:46:21 +02:00
Beniamino Galvani
65a0208ba0 core,cli: replace wrong pattern for clearing GError
Use gs_free_error instead of gs_free.
2017-06-27 09:42:28 +02:00
Lubomir Rintel
d473b34745 cli: prioritize devices with default routes and addresses
This makes "nmcli" and "nmcli d" output slightly more useful.
2017-06-26 15:17:49 +02:00
Beniamino Galvani
f545ed486e cli: ask NMSettingConnection properties first in questionnaire mode
Since properties are asked only when the connection has the related
setting, ensure that the connection type is set early so that the base
type gets added to the connection before evaluating other settings.

After NMSettingConnection properties, ask properties for the base
setting and then all other settings.
2017-06-22 15:01:15 +02:00
Beniamino Galvani
cd3a561251 cli: fix failed assertion in readline helper
The INT signal can arrive after a new line has been processed in
nmc_readline_helper(). In such case, the handler gets uninstalled by
readline_cb() and nmc_seen_sigint() returns TRUE. However it's an
error to call rl_callback_read_char() without handler, don't do it.

Fixes the following:
 "readline: readline_callback_read_char() called with no handler!"
 #0 __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1 __GI_abort () at abort.c:90
 #2 rl_callback_read_char () at ../callback.c:116
 #3 nmc_readline_helper (prompt=prompt@entry=0x2aa0d229080 "nmcli> ") at clients/cli/common.c:1387
 #4 nmc_readline (prompt_fmt=prompt_fmt@entry=0x2aa0036ac9e "%s") at clients/cli/common.c:1448
 #5 do_connection_edit (connection=0x2aa0d215440, nmc=0x2aa00391298 <nm_cli>) at clients/cli/connections.c:7072

Fixes: 995229181c

https://bugzilla.redhat.com/show_bug.cgi?id=1458311
2017-06-15 10:03:58 +02:00
Beniamino Galvani
d2b4332b36 cli: remove spurious device names from output
When running one of:

 nmcli device wifi list ifname wlan0
 nmcli device wifi connect ... ifname wlan0

nmcli wrongly adds the device name to the output.

Do the completion only when requested.

Fixes: 8679793f6b
Fixes: 1a0dfd31c4
2017-06-11 22:31:43 +02:00
Thomas Haller
ee5fdcbfb5 cli: minor refactoring of if-condition in device_overview
Note that nm_device_get_ip_iface() never returns an emptry string "".
2017-06-09 15:34:31 +02:00
Thomas Haller
126b0874f1 cli: fix output of iface in overview output
Fixes: f14845cc20

https://bugzilla.redhat.com/show_bug.cgi?id=1460219
2017-06-09 15:34:31 +02:00
Beniamino Galvani
ea909e38dc cli: disable pager in editor mode
nmcli closes its stdout when spawning the pager and thus, in editor
mode, nothing is printed once the pager terminates. For an interactive
mode like the editor, the pager seems not suitable, disable it.

Fixes: 24c079e4b2
2017-06-07 11:37:23 +02:00
Lubomir Rintel
aedeb3cbf4 clients: add support for Bluetooth NAP type 2017-05-31 20:17:42 +02:00
Thomas Haller
cd6449f162 cli: change check_activated() to ensure we don't miss a deactivation
In the previous code it is not clear to me that there won't be
a situation where we don't react on a state change, waiting for a
device-state-change that never comes.

Now, only wait for a better device-state reason if:

 - we have a device
 - and the ac-reason is unspecific (NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED)
 - and the device still references the current active connection
 - and the device state is not yet FAILED or DISCONNECTED.

The most important change is that we only wait longer, if the device's
active-connection is still the same as our current active connection.

I don't think this commit is really necessary, but I cannot understand
the previous logic.

See-also: 57a26fd2aa
2017-05-25 10:59:15 +02:00
Thomas Haller
4f69c1e85e cli: prettify check_activated() to by using switch() statement
No change in behavior.
2017-05-24 22:00:05 +02:00
Lubomir Rintel
7c24a2cb39 cli: allow the GNU option format
$ nmcli --fields=all c
  Error: Option '-fields=all' is unknown, try 'nmcli -help'.

What a shame. Let's fix this.
2017-05-15 19:19:49 +02:00
Lubomir Rintel
24c079e4b2 cli: spawn a pager when running on a terminal
This makes it a lot more convenient to deal with long outputs (such as
"nmcli c show id ...").

The implementation is essentially jacked from systemd. The bugs are
mine.
2017-05-15 17:23:51 +02:00
Lubomir Rintel
6fde475b27 cli: shorten setting names to aliases in "nmcli c show" connection list
This basically uses "wifi" in place of "802-11-wireless" and analogously
for other setting types that have aliases unless a --terse option was
specified.

Apart from looking nicer it makes the default output less wide,
hopefully avoiding line breaks on 80 column terminals in basic use
cases.
2017-05-15 14:46:05 +02:00
Thomas Haller
a6c84e2ea0 cli: fix redundant "const const" declaration in nmcli.h
Fixes: bfb9fd0d2f
2017-05-12 14:06:49 +02:00
Thomas Haller
83a6f36207 cli: don't mark field names for translation
Before refactoring nmcli recently, field names were marked for translation.
Note that for the property names, marking them had no effect as only
plain strings can be marked with N_().

Note how --fields are also an input argument. The input should be
independent of the locale and not translated. Likewise, when printing
the header names, they should not be translated to match the --fields
option.

    $ LANG=de_DE.utf8 nmcli --fields GENERAL.DEVICE device show enp0s25
    GENERAL.GERÄT:                          enp0s25

Drop the translation marks.
2017-04-23 23:45:02 +02:00
Beniamino Galvani
ed824102ff cli: fix completion of connection types
Return only main settings and the special slave types.
2017-04-20 14:34:20 +02:00
Beniamino Galvani
07cba18036 cli: accept special slave connection types in editor 2017-04-20 14:34:20 +02:00
Beniamino Galvani
032a3b4712 cli: only return main setting names as connection types
Also, return the special slave types.
2017-04-20 14:34:20 +02:00
Beniamino Galvani
243061edb6 cli: normalize function name 2017-04-20 14:34:20 +02:00
Francesco Giudici
4bdb6b026a nmcli: show secrets when the --show-secrets option is put after the connection id
'nmcli connection show <con_id1> --show-secrets'
secrets were not shown.
'nmcli connection show <con_id1> --show-secrets <con_id2>'
secrets were shown only for connection ids following the
"--show-secrets" option (so only for 'con_id2').

Fix these behaviors showing secrets for all connections also
if the "--show-secrets" option is put after the connection ids.
2017-04-20 12:41:08 +02:00
Thomas Haller
6dfb3e9ffb cli/trivial: remove whitespace between N_ macro and parenthesis
For _() and N_() we don't have a space before the parenthesis.
Be consistent about that.
2017-04-19 18:27:19 +02:00
Beniamino Galvani
f13fd4524c all: detect SR-IOV device support 2017-04-18 22:48:34 +02:00
Beniamino Galvani
67d144dd1e cli: check for deactivation failures
If the D-Bus call to DeactivateConnection() fails, don't wait for the
connection to change state because this is not going to
happen. Instead, notify the user of the error and, if necessary, wait
for remaining connections to be deactivated.

https://bugzilla.redhat.com/show_bug.cgi?id=1422786
2017-04-13 17:18:34 +02:00
Thomas Haller
275ab5fb8f cli: make properties list a list of pointers
That allows for the property list to contain derived
property types. Also, the list can be directly passed
off as a "const NMMetaAbstractInfo *const*" list.
2017-04-13 10:10:12 +02:00
Thomas Haller
f2b5a42c7c cli: let NMMetaNestedPropertyInfo derive NMMetaPropertyInfo 2017-04-13 10:10:12 +02:00
Thomas Haller
886dad49d4 cli: move parsing of meta data fields 2017-04-13 10:10:12 +02:00