Commit Graph

330 Commits

Author SHA1 Message Date
Beniamino Galvani
b28b2ba8a9 clients: add define for NMSecretAgentSimple signal name 2016-09-14 23:32:52 +02:00
Beniamino Galvani
79a357b07a cli: connections: fail the activation if the ac deactivates
Since commit ac888de151 ("cli/connections: fail the activation when
the active connection disappears") we rely only on the disappearing of
the active-connection to determine the failure of an activation.

libnm can collapse a 'added' and a 'removed' signal if they are
received closer enough and thus we may miss the removal of the active
connection. Restore the detection of failure based on
active-connection state.
2016-09-09 16:40:53 +02:00
Lubomir Rintel
afab2b8112 cli: only connect handlers for property changes in interactive edit
Fixes: c5324ed285
(cherry picked from commit 79c81bbb8c)
2016-08-24 17:27:55 +02:00
Lubomir Rintel
2f45665559 cli: default to method=manual when adding an address
This restores accidentally changed behavior for
"nmcli c add ... ip[46] <address>"

Fixes: c5324ed285
(cherry picked from commit 195ad4ec97)
2016-08-24 17:27:55 +02:00
Beniamino Galvani
e9f96024ae cli: return sane error message for D-Bus policy permission errors
The error returned to users when a load_connection(s)/set_logging call
fails due to D-Bus policy denial is a bit obscure:

  $ nmcli general logging level debug
  Error: failed to set logging: Rejected send message, 4 matched rules;
  type="method_call", sender=":1.233" (uid=1001 pid=27225 comm="nmcli
  general logging level debug ")
  interface="org.freedesktop.NetworkManager" member="SetLogging" error
  name="(unset)" requested_reply="0" destination=":1.207" (uid=0
  pid=25793 comm="/usr/sbin/NetworkManager --no-daemon ")

Convert it to a more comprehensible:

  $ nmcli general logging level debug
  Error: failed to set logging: access denied

https://bugzilla.redhat.com/show_bug.cgi?id=1362542
(cherry picked from commit 805925f9ef)
2016-08-20 10:45:55 +02:00
Beniamino Galvani
482e506674 cli: fix error reporting for connection delete
get_connection() shifts to the next argument, so we need to cache the
old one.

Fixes: 717db4fe01
2016-08-02 17:21:12 +02:00
Beniamino Galvani
ec6a118f29 cli: fix connection delete/monitor
The two commands should apply to all available connections matching
the given name.

Fixes: 717db4fe01
2016-08-02 16:49:37 +02:00
Francesco Giudici
2adb5fc00f nmcli: fix connection clone/modify
remove extra "next_arg"s (get_connection already shifts argv).

Fixes: 717db4fe01
2016-08-02 15:44:47 +02:00
Lubomir Rintel
8cc6ce7e44 cli: add -f argument completion 2016-08-01 15:51:29 +02:00
Lubomir Rintel
8e7c94ed07 cli/connections: there's nothing to complete for reload 2016-08-01 13:52:36 +02:00
Lubomir Rintel
9e8a227813 cli/connections: add completion to show subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
a410e40655 cli/connections: add completion to down subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
af5c235f14 cli/connections: add completion to import subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
345291d6f1 cli/connections: add completion to load subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
680b53c96a cli/connections: add completion to up subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
c561fa34d2 cli/connections: add completion to export subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
075e705bc7 cli/connections: add completion to monitor subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
9d076a7a1a cli/connections: add completion to delete subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
18352340b6 cli/connections: add completion to clone subcommand 2016-08-01 13:52:36 +02:00
Lubomir Rintel
2895261c91 cli/connections: do connection completion in get_connection()
Start completing by the id if the filter type is not specified
2016-08-01 13:52:36 +02:00
Lubomir Rintel
717db4fe01 cli/connections: split connection name parsing
Reduces redundant code paths; will make it easier to implement
completion in a common one.
2016-08-01 13:52:36 +02:00
Lubomir Rintel
023791edb0 cli/connections: use nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
0e298456ed cli/connections: add active connection completion
Start completing by the id if the filter type is not specified
2016-08-01 13:52:36 +02:00
Lubomir Rintel
ba45b5ac6f cli: take a reference to the device when activating
It can go away before the activation finishes:

  (process:378): GLib-GObject-WARNING **: instance with invalid (NULL) class pointer

  Thread 1 "lt-nmcli" received signal SIGTRAP, Trace/breakpoint trap.
  0x00007ffff4fa919b in g_logv () from /lib64/libglib-2.0.so.0
  (gdb) bt
  #0  0x00007ffff4fa919b in g_logv () at /lib64/libglib-2.0.so.0
  #1  0x00007ffff4fa930f in g_log () at /lib64/libglib-2.0.so.0
  #2  0x00007ffff529b3ea in g_type_check_instance () at /lib64/libgobject-2.0.so.0
  #3  0x00007ffff528fa94 in g_signal_handlers_disconnect_matched () at /lib64/libgobject-2.0.so.0
  #4  0x000000000041ae4e in activate_connection_info_finish (info=0x7b5490) at connections.c:2197
  #5  0x00007ffff5279470 in g_cclosure_marshal_VOID__OBJECTv () at /lib64/libgobject-2.0.so.0
  #6  0x00007ffff5276617 in _g_closure_invoke_va () at /lib64/libgobject-2.0.so.0
  #7  0x00007ffff5290ea9 in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
  #8  0x00007ffff52914ff in g_signal_emit () at /lib64/libgobject-2.0.so.0
  #9  0x00007ffff52763e8 in g_closure_invoke () at /lib64/libgobject-2.0.so.0
  #10 0x00007ffff52884a2 in signal_emit_unlocked_R () at /lib64/libgobject-2.0.so.0
  #11 0x00007ffff529112d in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
  #12 0x00007ffff52919ab in g_signal_emit_by_name () at /lib64/libgobject-2.0.so.0
  #13 0x00007ffff78fc9b1 in deferred_notify_cb (data=<optimized out>) at nm-object.c:243
  #14 0x00007ffff4fa2703 in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
  #15 0x00007ffff4fa2ab0 in g_main_context_iterate.isra () at /lib64/libglib-2.0.so.0
  #16 0x00007ffff4fa2dd2 in g_main_loop_run () at /lib64/libglib-2.0.so.0
  #17 0x00000000004146e3 in main (argc=<optimized out>, argv=<optimized out>) at nmcli.c:618
  (gdb) print info->device
2016-07-28 11:22:31 +02:00
Beniamino Galvani
1fbdd4d008 cli: fix crash on connection delete/down timeout
connection_op_timeout_cb() passed a wrong object type to timeout_cb();
fix this.

Fixes: ac888de151

https://bugzilla.redhat.com/show_bug.cgi?id=1355740
2016-07-23 08:54:32 +02:00
Francesco Giudici
65771b80a6 cli: improve devices vs connection compatibility check
report error message on device compatibility failures
2016-07-22 19:36:23 +02:00
Lubomir Rintel
65c6eb5ce5 cli/connections: split out ac_state_to_color()
Going to be useful outside nmcli c.
2016-07-19 14:29:05 +02:00
Jiří Klimeš
2544f78858 nmcli: add missing commands to 'nmcli connection help' usage description 2016-07-15 12:26:24 +02:00
Lubomir Rintel
ac888de151 cli/connections: fail the activation when the active connection disappears
Relying solemnly on device or active connection state is unreliable.
2016-07-07 11:56:05 +02:00
Lubomir Rintel
a0bb8cd6cb cli/connection: export read_connection_properties()
It makes sense to modify the applied connection from the device object.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
a30224f6af cli: use should_wait consistently
It's a semaphore, not a boolean.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
ef8d696252 cli: move the final completion check after the main loop exit
For "nmcli d modify" we'll need to do the completion from async
handlers. This seems to be the most reasonable place to ignore the
errors.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
86ffc08775 cli/connections: only do completion for the last argument
Completing the property when we stop parsing due to error is not the
right thing to do.
2016-06-29 20:28:42 +02:00
Francesco Giudici
aed19ff12a nmcli: fix ambiguous properties check for autocompletion
Re-enable the check on ambiguos properties but this time manage perfect
matches (i.e., the full property name has been typed) that are prefix
of other properties.

Test case:
nmcli --complete-args connection add type wifi wifi.

Here "wifi" is a property alias that is also prefix of the property
alias "wifi-sec".
2016-06-23 17:37:37 +02:00
Francesco Giudici
93e1e65467 nmcli: manage "--ask connection add" with no args
When parsing arguments of "connection add" we first read the available
property-value pairs and then check if the --ask option was passed in
order to aid in the fill process of a new connection.
Anyway, if there are no property-value tuples at all, we don't even
check the --ask option, returning with error.
Fix this just checking if any arg is there (argc) before invoking
read_connection_properties().
2016-06-22 12:34:01 +02:00
Lubomir Rintel
0172c1ed2d cli: don't free the completion string when a setting name is unambiguous
If we found that setting name prefix is in fact unambiguous and return
the completion string for that setting we were freeing the string upon
the return. That looks like a typo.

Fixes "nmcli --complete-args add type wifi wifi."
                                           ^^^^ not ambiguous
2016-06-22 09:29:03 +02:00
Lubomir Rintel
c3422e917d man: update the nmcli manual for new connection add syntax
It allows us to clean up the nmcli "c add" section considerably.

We list the old-fashioned aliases in a separate section that applies to both
"nmcli c add" and "nmcli c modify".

The section is now nicely cross-linked with nm-settings in HTML
rendering.
2016-06-21 18:40:22 +02:00
Lubomir Rintel
c5324ed285 nmcli: streamline connection addition
This is a huge refactoring in attempt to 1.) reduce the horrible redundancy in
the connection addition path and 2.) reduce confusion between various sources
of property value (command line, properties, interactive mode).

* The conversions from the strings was done all over the place:
  settings.c already does for all sensible properties.
  The rest is removed.

* The validations are done randomly and redundantly:
  server does some validation, and per-property client validations
  useful for interactive mode are done in settings.c
  The rest is removed.

* The information about defaults and required options was redundantly
  scattered in per-type completion functions and interactive mode
  questionnaries. This is now driven by the option_info[] table.

In general, we do our best to just map the command line options to
properties and allow mixing them. For the rest there's the
check_and_set() callbacks (basically to keep compatibility with previous
nmcli versions). This this is now all possible:

$ nmcli c add type ethernet ifname '*'
  This always worked

$ nmcli c add type bond-slave save no -- connection.autoconnect no
  The "save" and "--" still work

$ nmcli c add connection.type ethernet ifname eth0
  Properties can now be used

$ nmcli c add type ethernet ip4 1.2.3.4 mac 80:86:66:77:88:99 con-name whatever
  There's no implementation mandated order of the properties (the type
  still must be known to determine which properties make sense)

$ nmcli --ask c add type ethernet ip4 1.2.3.4 mac 80:86:66:77:88:99 con-name whatever
  The interactive mode asks only for properties that weren't specified
  on command line
2016-06-21 18:40:13 +02:00
Francesco Giudici
00b362bcf2 nmcli: add support to shortnames for connection properties autocompletion 2016-06-21 16:28:48 +02:00
Lubomir Rintel
3aff650e22 nmcli: improve connection autocompletion (2/2)
Complete the property as we parse the list of properties. This makes it
possible to actually complete an unfinished property.  E.g:

  $ nmcli --complete c modify enp0s25 +ipv6.addr
  +ipv6.addresses +ipv6.addr-gen-mode
2016-06-21 16:28:48 +02:00
Lubomir Rintel
5aec1a3928 nmcli: improve connection autocompletion (1/2)
Make property autocompletion take a prefix and modifier flags.

This will make it easier to complete an unfinished property name
(possibly accompanied by a modifier) without shell trickery.
2016-06-21 16:28:48 +02:00
Lubomir Rintel
7046e806d1 cli: streamline complete_connection_by_type() arguments
Will be useful to pass around the complete flag.
2016-06-21 16:28:48 +02:00
Francesco Giudici
cd4395a261 nmcli: enable connection autocompletion for 802.1x properties
nmcli bash autocompletion leveraged on "nmcli connection edit", "print"
to retrieve the specific properties of a connection. Anyway, the
interactive editor is smart and just prints the used components, so in a
connection where 802.1x is not enabled we had no autocompletion.
Solved adding an "hidden" command "nmcli --complete connection modify"
as suggested in bgo #724860 in order to retrieve ALL the available
properties for use in autocompletion.
Here patch from L.Rintel has been merged to make che --complete option
global to nmcli (first version was local to "connection modify").

https://bugzilla.gnome.org/show_bug.cgi?id=724860
https://bugzilla.redhat.com/show_bug.cgi?id=1301226
2016-06-21 16:28:48 +02:00
Thomas Haller
4cb57964d9 cli: fix handling of VPN names in nmcli by using libnm functions
At various places, nmcli requires to specify a VPN type by name, for example

  $ nmcli connection add type vpn ifname '*' vpn-type $VPN_TYPE

This $VPN_TYPE used to be a hard-coded list of known VPN plugin names.
But actually, it should be a VPN service-type. A service-type used to be
the D-Bus name of the VPN plugin. Now, with multiple VPN support that
is no longer the case, but it still has the form of a D-Bus bus name.
Alternativley, it could be an alias, which is just a way for plugins
to support multiple service-types.

Fix that, to support fully qualified service-types in the form
of D-Bus bus names. Also, support lookup by name, in which case
the present plugin-info instances are searched.
Finally, support a list of hard-code short-names.

All the logic how to translate a short-name to a fully qualified
service-type is now inside libnm, so that various user agree on
those names and don't have to hard-code them each.
2016-06-15 10:32:32 +02:00
Thomas Haller
971a8181f6 nmcli: fix VPN export to find plugin by service-type 2016-06-15 10:32:32 +02:00
Thomas Haller
466bf2f633 build: avoid compiler warnings about non-constant format strings (-Wformat-nonliteral) 2016-06-05 12:22:01 +02:00
Thomas Haller
77e7a9c075 cli: re-merge branch 'th/cli-vpn-import-fixes-rh1337300'
(fix wrong merge. I already cherry-picked 3d25b2e to nm-1-2)

https://bugzilla.redhat.com/show_bug.cgi?id=1337300
2016-05-19 17:21:44 +02:00
Beniamino Galvani
73221a809d cli: remove wrong assertion in check_valid_name()
As explained in the function comment, a NULL value for @val is
acceptable. Otherwise:

$ nmcli connection edit
 (process:2276): nmcli-CRITICAL **: check_valid_name: assertion 'val' failed

Fixes: fb8fe1d8cb
2016-05-19 17:09:06 +02:00
Thomas Haller
41976e3069 clients,cli: for connection-add consider VPNs as loaded from the plugin
Instead of using (only) a hard-coded list of VPN types,
prefer lookup the VPN settings from the .name files.

Still, fallback to a hard-coded list if the plugin cannot
be found, because for connection-add we currently don't
actually need the plugin installed.
2016-05-19 12:52:59 +02:00
Thomas Haller
0225c4567b clients: lookup VPN plugins either by "name" or "service"
... not constructing a "service" by prepending a D-Bus prefix to "name" (urgh).
2016-05-19 12:52:59 +02:00