Commit Graph

405 Commits

Author SHA1 Message Date
Jiří Klimeš
3c9b8671fa cli: add 'passwd-file' option for 'nmcli connection up' to provide passwords
It is useful for running nmcli without --ask option, i.e. non-interactively.

Example contents of the file:
wifi.psk: s e c r e t 12345
802-1x.password:kili manjaro
802-1x.pin:987654321
2014-11-07 09:32:32 +01:00
Jiří Klimeš
de7f85bdec cli: use secret agent for getting passwords from user
--ask option has to be used, so that nmcli can be interactive.
2014-11-07 09:32:32 +01:00
Jiří Klimeš
098d655ef1 cli: fix an error path in second level 'set' command of nmcli editor
Test case:
nmcli> goto ipv4.addresses
nmcli ipv4.addresses> set 1.1.1.1
Do you also want to set 'ipv4.method' to 'manual'? [yes]: no
nmcli ipv4.addresses> set 3.3.3.3/99
Error: failed to set 'addresses' property: invalid prefix '99'; <1-32> allowed
Do you also want to set 'ipv4.method' to 'manual'? [yes]:

The second question (after failed 'set') should not be asked.
2014-11-06 16:44:41 +01:00
Jiří Klimeš
32600a9035 cli: fix a regression in monitoring addresses vs. method changes
while editing an existing commention.
It was broken by commit 45590f809a that called
nm_connection_replace_settings_from_connection() which replaces settings with
connected signal handlers.
2014-11-06 12:47:17 +01:00
Lubomir Rintel
0276945fd3 cli: Activating an already activated connection fails
The new ActiveConnection starts in UNKNOWN state and we immediately assume
it failed. We should wait for DEACTIVATED or ACTIVATED instead.

https://bugzilla.gnome.org/show_bug.cgi?id=739339
2014-11-03 15:40:52 +01:00
Lubomir Rintel
1f275a980a Merge branch 'lr/ap'
https://bugzilla.gnome.org/show_bug.cgi?id=738439
2014-10-31 15:35:20 +01:00
Jiří Klimeš
45590f809a cli: allow showing secrets in the editor 2014-10-30 09:18:01 +01:00
Jiří Klimeš
b4e013abed cli: display '<hidden>' string for secret properties
unless the user explicitly say to show them.
2014-10-30 09:18:01 +01:00
Jiří Klimeš
1a64683802 cli: add '--show-secrets' option for 'nmcli connection show'
It can be used to display connection secrets (passwords).  When used, it will
get secrets for the connection profile and merge it into the connection's
settings before displaying it.

Example:
nmcli con show -s hotel-wifi
2014-10-30 09:11:43 +01:00
Jiří Klimeš
f558c8a51e cli: add 'verify fix' command for nmcli connection editor
Some connection verification errors are normalizable by NetworkManager. So we
can allow users to normalize the connection using one command.
2014-10-30 08:31:54 +01:00
Jiří Klimeš
d31c456033 cli: check IP configuration when setting connection.master in editor
If IPv4 and/or IPv6 are present on setting connection.master, offer their
removal.
2014-10-30 08:30:48 +01:00
Jiří Klimeš
afde052445 trivial: fix a typo in comments 2014-10-30 08:25:11 +01:00
Dan Winship
6ae4224850 libnm: change GSList to GPtrArray in libnm methods
libnm mostly used GPtrArrays in its APIs, except that arrays of
connections were usually GSLists. Fix this and make them GPtrArrays
too (and rename nm_client_list_connections() to
nm_client_get_connections() to match everything else).
2014-10-28 17:17:17 -04:00
Lubomir Rintel
1c9b16b2f2 cli: Add mode option for wifi connecitons
Only default (infrastructure) mode connections can be created and as it's not
possible to write mode=ap connections with ifcfg-rh plugins, they can't be
switched to mode=ap.
2014-10-23 18:34:39 +02:00
Dan Winship
2ff4a7d4b0 libnm: strip GDBus gunk from GErrors
Call g_dbus_error_strip_remote_error() on all errors returned from
gdbus calls. (Blah!)
2014-10-22 08:29:10 -04:00
Jiří Klimeš
e130415f2b cli: show active connection even if the connection profile is not visible
$ nmcli con show
2014-10-20 09:11:57 +02:00
Jiří Klimeš
b03518b817 cli: show details for active connection even if the profile is not visible
$ nmcli con show other_user_con
2014-10-20 09:11:57 +02:00
Jiří Klimeš
278ec17448 cli: fix errors and crash for invisible connections
* two users are logged in: user_a and user_b
* user_b creates a connection visible only to him 'user_b_private'
  (permissions: user:user_b)
* user_b activates the connection user_b_private
* user_a does not see the connection profile, but he does see the active
  connection

* user_a calls
  nmcli con
  nmcli con show user_b_private
2014-10-20 09:11:57 +02:00
Jiří Klimeš
88efa1c437 cli: fix 'nmcli connection up bond0' being stuck
It can happen on activating a master without slaves. Active connection will
not move past activating state.
2014-10-19 09:26:34 -04:00
Thomas Haller
cf26bb2dea cli: support connection.autoconnect-priority property
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 20:13:18 +02:00
Dan Winship
677314c540 libnm: fix NMActiveConnection object-path-valued properties
NMActiveConnection:connection was an object path rather than an
NMRemoteConnection because in the past the NMObject property system
wasn't capable of handling NMRemoteConnection-valued properties.
NMActiveConnection:master was an object path rather than an NMDevice
entirely by accident. Fix both.

NMActiveConnection:specific-object can't currently be converted to an
object, because we don't know ahead of time what object type it is,
and NMObject can't deal with that. Instead, we rename it to
:specific-object-path (and likewise for its get function), both to
emphasize that it doesn't behave like other properties, and to leave
the old name open for an actual object-valued property later on.
2014-10-10 13:10:19 -04:00
Dan Winship
6f3d1f9526 libnm: merge NMRemoteSettings into NMClient
Make NMRemoteSettings internal and have NMClient wrap all of its APIs,
just like it does with NMManager.
2014-10-10 12:40:19 -04:00
Dan Winship
c1f1e96181 cli: (trivial) rename NmCli.system_connections to connections
Rename NmCli.system_connections to connections, since the "user
connections" have been gone forever.
2014-10-10 12:40:15 -04:00
Thomas Haller
b662fbf450 cli: support new bond option 'lacp_rate'
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-02 16:36:11 +02:00
Jiří Klimeš
8919a8572a cli: strip errors from D-Bus before presenting to a user 2014-10-01 11:53:07 +02:00
Dan Winship
1b74e77f9f cli: use g_print/g_printerr rather than printf/fprintf
Use g_print() and g_printerr(), which wrap printf() and
fprintf(stderr,...), but handle conversion from UTF-8 if the locale is
using a different character set.
2014-09-27 11:45:53 -04:00
Dan Winship
2237ea3ddb libnm: make sync/async APIs more GLib-like
Make synchronous APIs take GCancellables, and make asynchronous APIs
use GAsyncReadyCallbacks and have names ending in "_async", with
"_finish" functions to retrieve the results.

Also, make nm_client_activate_connection_finish(),
nm_client_add_and_activate_finish(), and
nm_remote_settings_add_connection_finish() be (transfer full) rather
than (transfer none), because the refcounting semantics become
slightly confusing in some edge cases otherwise.
2014-09-25 09:29:20 -04:00
Dan Winship
6ca10677d6 libnm: merge saved and unsaved connection methods
Merge nm_remote_settings_add_connection() and
nm_remote_settings_add_connection_unsaved(), and likewise
nm_remote_connection_commit_changes() and
nm_remote_connection_commit_changes_unsaved(), by adding a boolean
flag to each saying whether to save to disk.
2014-09-25 09:29:20 -04:00
Jiří Klimeš
dc1c17fd30 cli: get NMClient early and remove duplicated code 2014-09-22 12:53:46 +02:00
Jiří Klimeš
f27a259ee6 cli: when NM is not running, give this error in 'nmcli connection'
Check whether NM is running before comparing nmcli and NM versions. Returning
NMC_RESULT_ERROR_NM_NOT_RUNNING is in accordance with other nmcli commands.
2014-09-22 12:53:46 +02:00
Dan Winship
acf86f68b3 libnm-core: change connection hash tables to variants in API
In preparation for porting to GDBus, make nm_connection_to_dbus(),
etc, represent connections as GVariants of type 'a{sa{sv}}' rather
than as GHashTables-of-GHashTables-of-GValues.

This means we're constantly converting back and forth internally, but
this is just a stepping stone on the way to the full GDBus port, and
all of that code will go away again later.
2014-09-18 11:51:09 -04:00
Dan Winship
ad8b13091b libnm-core: fix up connection deserialize/copy/replace semantics
libnm-util's connection deserializing/copying/replacing functions have
odd semantics where sometimes they both modify a connection AND return
an error. libnm-core tried to improve things by guaranteeing that the
connection would not be modified if the new settings were invalid, but
this ended up breaking a bunch of places that needed to be able to
work with invalid connections. So re-fix the functions by reverting
back to the old semantics, but having return values that clearly
distinguish whether the connection was modified or not.

For comparison:

  - nm_connection_new_from_hash() / nm_simple_connection_new_from_dbus():

      - libnm-util: returns a valid connection or NULL.

      - OLD libnm-core: returned a valid connection or NULL.

      - NEW libnm-core: returns a valid connection or NULL.

  - nm_connection_duplicate() / nm_simple_connection_new_clone():

      - libnm-util: always succeeds, whether or not the connection is
        valid.

      - OLD libnm-core: returned a valid connection or NULL

      - NEW libnm-core: always succeeds, whether or not the connection
        is valid.

    - nm_connection_replace_settings_from_connection():

      - libnm-util: always replaces the settings, but returns FALSE if
        the connection is now invalid.

      - OLD libnm-core: either replaced the settings and returned TRUE
        (if the settings were valid), or else left the connection
        unchanged and returned FALSE (if not).

      - NEW libnm-core: always replaces the settings, and has no
        return value. (The modified connection is valid if and only if
        the replaced-from connection was valid; just like with the
        libnm-util version.)

    - nm_connection_replace_settings():

      - libnm-util: returns TRUE if the new settings are valid, or
        FALSE if either (a) the new settings could not be deserialized
        and the connection is unchanged, or (b) the new settings were
        deserialized, and the connection was updated, but is now not
        valid.

      - OLD libnm-core: either replaced the settings and returned TRUE
        (if the settings were valid), or else left the connection
        unchanged and returned FALSE (if not).

      - NEW libnm-core: returns TRUE if the connection was updated
        (whether or not it is valid), or FALSE if the new settings
        could not be deserialized and the connection is unchanged.
2014-09-17 08:21:21 -04:00
Jiří Klimeš
c6a932a2ce cli: fix ssid parameter processing in 'nmcli con add'
(broken by commit c43f88907b)
2014-09-09 16:54:32 +02:00
Dan Winship
730d096fe1 cli: fix MAC address validation (bgo #736275)
nm_utils_hwaddr_valid() accepts length while check_mac() mistakenly passes
type.

(broken by 3a54d05098)

https://bugzilla.gnome.org/show_bug.cgi?id=736275
2014-09-09 11:13:00 +02:00
Dan Winship
3e5b3833aa libnm: change empty-GPtrArray-return semantics
libnm functions that return GPtrArrays of objects had a rule that if
the array was empty, they would return NULL rather than a 0-length
array. As it turns out, this is just a nuisance to clients, since in
most places the code for the non-empty case would end up doing the
right thing for the empty case as well (and where it doesn't, we can
check "array->len == 0" just as easily as "array == NULL"). So just
return the 0-length array instead.
2014-09-04 09:21:05 -04:00
Dan Winship
3a54d05098 libnm-core: change all mac-address properties to G_TYPE_STRING
Make all mac-address properties (including NMSettingBluetooth:bdaddr,
NMSettingOlpcMesh:dhcp-anycast-addr, and NMSettingWireless:bssid) be
strings, using _nm_setting_class_transform_property() to handle
translating to/from binary form when dealing with D-Bus.

Update everything accordingly for the change, and also add a test for
transformed setting properties to test-general.
2014-09-04 09:20:10 -04:00
Dan Winship
ee3467e531 libnm-core: add nm_connection_is_virtual()
Add a method to determine if a connection applies to a virtual device.

Perhaps eventually the logic should be spread across the NMSetting
classes, but for now it's better off having it in NMConnection than
once in NMManager and once in nmcli.
2014-09-04 09:18:43 -04:00
Dan Winship
ab26964c56 all: stop using virtual interface-name properties
The virtual :interface-name properties (eg,
NMDeviceBond:interface-name) are deprecated in favor of
NMSettingConnection:interface-name, and nm_connection_verify() ensures
that their values are kept in sync. So (a) there is no need to set
those properties when we can just set
NMSettingConnection:interface-name instead, and (b) we can replace any
calls to the setting-specific get_interface_name() methods with
nm_connection_get_interface_name() or
nm_setting_connection_get_interface_name().
2014-09-04 09:18:43 -04:00
Dan Winship
7314256b77 libnm-core: drop nm_{setting,connection}_get_virtual_iface_name()
Since we enforce the fact that bond, bridge, team, and vlan
interface-name properties match NMSettingConnection:interface-name,
nm_connection_get_virtual_iface_name() can be replaced with
nm_connection_get_interface_name() basically everywhere.

The one place this doesn't work is with InfiniBand partitions (where
get_virtual_iface_name() was actually computing the name), but for the
most part we only need to care about the interface names of InfiniBand
partitions in places where we also already need to do some other
InfiniBand-specific handling as well, so we can use an
InfiniBand-specific method
(nm_setting_infiniband_get_virtual_interface_name()) to get it.

(Also, while updating nm_device_get_virtual_device_description(), fix
it to handle InfiniBand partitions too.)
2014-09-04 09:18:43 -04:00
Dan Winship
773d3f0ab6 libnm-core: rename NMConnection to/from_hash methods
Rename nm_connection_to_hash() to nm_connection_to_dbus(), and
nm_connection_new_from_hash() to nm_connection_new_from_dbus(). In
addition to clarifying that this is specifically the D-Bus
serialization format, these names will also work better in the
GDBus-based future where the serialization format is GVariant, not
GHashTable.

Also, move NMSettingHashFlags to nm-connection.h, and rename it
NMConnectionSerializationFlags.
2014-09-04 09:17:36 -04:00
Dan Winship
1838db9e71 all: remove a bunch of unnecessary dbus/dbus-glib includes 2014-09-03 10:45:24 -04:00
Jiří Klimeš
a1907ec257 cli: simplify do_connections() now that we don't wait for "connection-read"
nm_remote_settings_list_connections() ensures the connections are loaded first.
We check "help" commands before getting connections, because it is time
intensive action.
2014-08-22 23:33:04 +02:00
Jiří Klimeš
3cf1131e89 cli: fix 'nmcli connection' so that it returns correct exit code
It was broken by commit 57e802f3aa, which made
nmcli always return success.

For example:
$ nmcli con add type blabla
2014-08-22 23:33:04 +02:00
Thomas Haller
00af27f0ba cli: succeed in master bring-up when device state reaches IP_CONFIG (bgo #733641)
When connecting a master connection, no slave devices will be activated
automatically. The user is supposed to activate them individually.

Hence nmcli should not wait for the connection to be fully activated
because that is not going to happen (unless the user connects a slave
connection from another terminal).

Instead, for master connections behave differently and signal success
once the master device reaches IP_CONFIG state.

This revises behavior introduced by commit
47710f8211.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
2014-08-19 13:42:31 +02:00
Dan Winship
e1ba13a426 libnm-core, libnm, core: make NMConnection an interface
The fact that NMRemoteConnection has to be an NMConnection and
therefore can't be an NMObject means that it needs to reimplement bits
of NMObject functionality (and likewise NMObject needs some special
magic to deal with it). Likewise, we will need a daemon-side
equivalent of NMObject as part of the gdbus port, and we would want
NMSettingsConnection to be able to inherit from this as well.

Solve this problem by making NMConnection into an interface, and
having NMRemoteConnection and NMSettingsConnection implement it. (We
use some hacks to keep the GHashTable of NMSettings objects inside
nm-connection.c rather than having to be implemented by the
implementations.)

Since NMConnection is no longer an instantiable type, this adds
NMSimpleConnection to replace the various non-D-Bus-based uses of
NMConnection throughout the code. nm_connection_new() becomes
nm_simple_connection_new(), nm_connection_new_from_hash() becomes
nm_simple_connection_new_from_hash(), and nm_connection_duplicate()
becomes nm_simple_connection_new_clone().
2014-08-16 10:17:53 -04:00
Dan Winship
57e802f3aa libnm: port NMRemoteSettings to NMObject
NMRemoteSettings duplicates a bunch of NMObject's functionality that
it doesn't need to. In libnm-glib, it wouldn't have been possible to
port NMRemoteSettings to NMObject without breaking ABI, but now in
libnm we can do that.

As a side effect of this, NMRemoteSettings gains a "connections"
property, and "connection-added" and "connection-removed" signals
(with the former replacing the old "new-connection" signal). This also
removes the "connections-loaded" signal, since the connections will
now always be loaded (via the initialization of the "connections"
property) during init()/init_async().

Also, this removes NMRemoteConnection's "removed" signal, since it's
redundant with the new NMRemoteSettings::connection-removed (and
having the signal on NMRemoteSettings instead is more consistent with
other objects).
2014-08-07 15:43:43 -04:00
Dan Winship
8ce06b814c libnm: synchronize NMClient and NMRemoteSettings "is NM running" properties
Rename NMClient:manager-running and NMRemoteSettings:service-running
to both be :nm-running.
2014-08-07 15:43:43 -04:00
Dan Winship
35f36ba4c3 libnm-core, etc: drop type-based hwaddr funcs, port to length-based ones
Drop the arptype-based nm_utils_hwaddr funcs, and rename the
length-based ones to no longer have _len in their names. This also
switches nm_utils_hwaddr_atoba() to using a length rather than an
arptype, and adds a length argument to nm_utils_hwaddr_valid() (making
nm_utils_hwaddr_valid() now a replacement for nm_utils_hwaddr_aton()
in some places, where we were only using aton() to do validity
checking).
2014-08-07 12:08:16 -04:00
Dan Winship
d0b05b34d5 libnm: add NetworkManager.h, disallow including individual headers
Add NetworkManager.h, which includes all of the other NM header, and
require all external users of libnm to use that rather than the
individual headers.

(An exception is made for nm-dbus-interface.h,
nm-vpn-dbus-interface.h, and nm-version.h, which can be included
separately.)
2014-08-01 14:34:40 -04:00
Dan Winship
258e74eb0c libnm: make the the use of GInitable mandatory
Remove _nm_object_ensure_inited(), etc; objects that implement
GInitable are now mandatory-to-init().

Remove constructor() implementations that sometimes return NULL; do
all the relevant checking in init() instead.

Make nm_client_new() and nm_remote_settings_new() take a GCancellable
and a GError**.
2014-08-01 14:34:40 -04:00