Commit Graph

692 Commits

Author SHA1 Message Date
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
8b39090597 cli: use --complete-args for connection add completion
And make it incredibly slow at the same time.
2016-06-21 18:40:22 +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
Francesco Giudici
fbaaf51f52 nmcli autocompletion cleanups
* no need to check HELP_ONLY_AS_FIRST var as when --help option is passed
  _nmcli_compl_OPTIONS will return 0, falling in the general case that
  will trigger end of autocompletion

* clanup local var declaration in _nmcli func:
  - remove dupliated OPTIONS_MANDATORY declaration
  - init HELP_ONLY_AS_FIRST on declaration
  - order vars for common prefix
2016-06-21 16:28:39 +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
348e505b3a macros: add macro _nm_printf() for function attribute 2016-06-05 12:22:01 +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
8e54cfdb27 all: move NM_AUTH_PERMISSION_* defines to "nm-common-macros.h" header 2016-06-01 19:06:35 +02:00
Thomas Haller
1d0e0eeffd manager: add Reload() D-Bus command
Add new Reload D-Bus command to reload NetworkManager configuration.

For now, this is like sending SIGHUP to the process. There are several
advantages here:

  - it is guarded via PolicyKit authentication while signals
    can only be sent by root.

  - the user can wait for the reload to be complete instead of sending
    an asynchronous signal. For now, we operation completes after
    nm_config_reload() returns, but later we could delay the response
    further until specific parts are fully reloaded.

  - SIGHUP reloads everything including re-reading configuration from
    disk while SIGUSR1 reloads just certain parts such as writing out DNS
    configuration anew.
    Now, the Reload command has a flags argument which is more granular
    in selecting parts which are to be reloaded. For example, via
    signals the user can:

      1) send SIGUSR1: this writes out the DNS configuration to
         resolv.conf and possibly reloads other parts without
         re-reading configuration and without restarting the DNS plugin.
      2) send SIGHUP: this reloads configuration from disk,
         writes out resolv.conf and restarts the DNS plugin.

    There is no way, to only restart the DNS plugin without also reloading
    everything else.
2016-06-01 19:06:34 +02:00
Thomas Haller
8913585397 libnm: implement missing NM_AUTH_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS 2016-06-01 19:06:34 +02:00
Lubomir Rintel
0bd51b41c3 cli: add ipv6.token support 2016-05-30 16:32:07 +02:00
Beniamino Galvani
3c649e6429 team: expose current device configuration through D-Bus and nmcli
Add a new "Config" property to the D-Bus interface for team devices
and show its value through "nmcli device show". The property contains
the full JSON configuration from teamd for the device.

https://bugzilla.redhat.com/show_bug.cgi?id=1310435
2016-05-26 09:16:46 +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
Thomas Haller
09a015b23b nmcli-completion: complete filename for VPN import and passwd-file
Also hard-code the VPN types strongswan and fortisslvpn.

https://bugzilla.redhat.com/show_bug.cgi?id=1337300
2016-05-19 12:52:59 +02:00
Beniamino Galvani
dbd0634c84 cli: append newline to failure message
Fixes: a06487a6ae
2016-05-16 17:55:21 +02:00
Beniamino Galvani
c094ee5f90 cli: also hide phase2 private key unless --show-secrets is passed
Fixes: ca6f1e7f25
2016-05-13 13:48:43 +02:00
Beniamino Galvani
ca6f1e7f25 cli: hide secret certificate blobs unless --show-secrets is passed
Client certificate and private key blobs should be considered private
as other secrets and not shown unless the --show-secrets option is
passed.

https://bugzilla.redhat.com/show_bug.cgi?id=1184530
2016-05-13 11:49:58 +02:00
Beniamino Galvani
d5855ed807 cli: add support for DNS priority 2016-05-12 17:13:50 +02:00
Thomas Haller
7752f390c2 cli: declare external variable nm_cli in <nmcli.h> header 2016-05-03 11:53:15 +02:00
Thomas Haller
a9908c012c cli: remove unused functions 2016-05-03 11:53:15 +02:00
Thomas Haller
d742ea7817 cli: don't allow multiple <ifname> arguments to device-reapply
Just like `nmcli device connect` only allows one argument, don't allow
multiple device arguments for reapply.

Allowing multiple device names makes it more complicated to add
additional options to the command. For example, it would be useful
to have a

    nmcli device reapply eth0 connection id other-connection

but when allowing multiple device names, it gets more complicated in
documentation, command line parsing and bash completion.

Note that the user can achieve a very similar outcome by using the
shell:

    for DEV in eth0 eth1 eth2; do
        nmcli device reapply $DEV &
    done
    wait

argubaly, this doesn't report the exit status properly. To properly
handle that would require more effort. Also, it is somewhat less
efficient, but well.

This is an API change, however it is very new API that probably nobody
is using much. Also, the documentation (man nmcli) didn't mention the
possibility to pass multiple device names.
2016-05-03 11:52:57 +02:00
Thomas Haller
b217b68b80 cli: refactor cleanup in do_device_reapply() 2016-05-03 11:52:40 +02:00
Beniamino Galvani
a06487a6ae cli: handle device failure when activating
We might receive the update of the device state to FAILED when the
active connection is still in ACTIVATING. Handle this case properly.
2016-04-29 11:16:30 +02:00
Francesco Giudici
3c67a1ec5e cli: remove version check against NM
When performing NM package upgrade the new version of nmcli will be immediately
available while NM daemon will not, as it would not restart in order to avoid
to disrupt connectivity. This could create issues with tools leveraging
on nmcli output (till reboot). As apart from this case it is very unlikely
that a user can have this nmcli / NM daemon version mismatch situation,
the check could cause more harm than benefit in real user case
scenarios.

https://bugzilla.redhat.com/show_bug.cgi?id=1291785
2016-04-28 09:35:20 +02:00
Thomas Haller
9152dec99f build: disable deprecation checks for internal compilation
For internal compilation we want to be able to use deprecated
API without warnings.

Define the version min/max macros to effectively disable deprecation
warnings.

However, don't do it via CFLAGS option in the makefiles, instead hack it
to "nm-default.h". After all, *every* source file that is for internal
compilation needs to include this header as first.
2016-04-05 22:22:58 +02:00
Thomas Haller
03fd18cde0 cli: fix setting 'slave-type' for nmcli connection add type *-slave
$ nmcli connection add type bond-slave ifname eth1 con-name bond0.0 master nm-bond
  Error: Failed to add 'bond0.0' connection: connection.slave-type: Cannot set 'master' without 'slave-type'

Fixes: 8ad218e71c
2016-03-30 18:36:07 +02:00
Thomas Haller
6fa521b384 cli/trivial: fix indention and whitespace 2016-03-30 18:15:03 +02:00
Beniamino Galvani
a9241773d7 cli: allow setting multiple IPs in bond 'arp_ip_target' option
The bond 'arp_ip_target' option contains a list of comma-separated IP
addresses; but comma is also used to separate options and so at the
moment it is not possible to specify multiple IPs as the command

 $ nmcli c m b1 bond.options \
   mode=0,arp_interval=1,arp_ip_target=1.1.1.1,2.2.2.2

interprets 2.2.2.2 as the next option.

Allows spaces to be used as separators for the IPs of the
'arp_ip_target':

 $ nmcli c m b1 bond.options \
   "mode=0,arp_interval=1,arp_ip_target=1.1.1.1 2.2.2.2"
2016-03-29 18:10:05 +02:00
Thomas Haller
31669329bb cli/trivial: fix TABs for indention 2016-03-29 14:59:01 +02:00
Lubomir Rintel
8ad218e71c nmcli: fix slave_type setting 2016-03-29 14:53:45 +02:00
Lubomir Rintel
e691f01e01 cli: make the *-slave type option parsing out of the common path
We actually don't want to understand these options unless the legacy
*-slave types are used. The properties should be used directly instead.

https://bugzilla.gnome.org/show_bug.cgi?id=748302

This basically undoes most of what has been done in  commit 00e0fffea2.
2016-03-29 14:20:09 +02:00
Beniamino Galvani
945c459f20 cli: add support for NMSetting8021x domain-suffix-match properties 2016-03-16 17:32:17 +01:00
Beniamino Galvani
ff97494e78 cli: fix memory leak in connection listing 2016-03-14 22:18:17 +01:00
Beniamino Galvani
f0c6a0315d cli: prefer 'modify' over 'monitor' when the command is abbreviated
In previous releases 'nmcli connection m' was interpreted as 'modify',
but recently the monitor command was introduced with a higher
priority, changing the behavior when the abbreviated form is
used.

Restore the old behavior.

https://bugzilla.redhat.com/show_bug.cgi?id=1316120
2016-03-10 11:12:02 +01:00
Francesco Giudici
fb8fe1d8cb nmcli: fix check on allowed parameters for slave connections
When editing a connection, check its slave-type parameter. If not null,
we will not have ip properties but possibly others, slave-type specific.
2016-03-04 19:14:26 +01:00
Dan Winship
6265398b6e all: use g_error_matches()
Use g_error_matches() where we're testing error codes. In particular,
use it rather than looking at only ->code and not also ->domain, which
is just wrong.

[thaller@redhat.com: rebase and modify original patch]
2016-03-03 18:54:20 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Beniamino Galvani
4ded98dd0f cli: fix use-after-free when adding ADSL connections
check_adsl_protocol() can free and assign a new string to
@protocol_ask, leaving @protocol dangling. Fix this.

Fixes: 290c1626b9
2016-02-29 13:47:47 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00