Commit Graph

1106 Commits

Author SHA1 Message Date
Antonio Cardace
15a8595575 nmcli: remove interface length check in nmcli
nmcli should not perform checks on the interface name length,
this kind of operations should only be performed by the NetworkManager
daemon and not be duplicated inside cli applications.
2020-02-17 15:27:35 +01:00
Iñigo Martínez
648155e4a1 license: Add license using SPDX identifiers to meson build files
License is missing in meson build files. This has been added using
SPDX identifiers and licensed under LGPL-2.1+.
2020-02-17 13:16:57 +01:00
Thomas Haller
cd31437024 shared: drop _STATIC variant of macros that define functions
Several macros are used to define function. They had a "_STATIC" variant,
to define the function as static.

I think those macros should not try to abstract entirely what they do.
They should not accept the function scope as argument (or have two
variants per scope). This also because it might make sense to add
additional __attribute__(()) to the function. That only works, if
the macro does not pretend to *not* define a plain function.

Instead, embrace what the function does and let the users place the
function scope as they see fit.

This also follows what is already done with

    static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
2020-02-13 17:17:07 +01:00
Thomas Haller
c69d703017 all: use g_ascii_strcasecmp() instead of the locale dependent strcasecmp()
In all the cases, we don't want to perform locale dependent comparison.

  $ sed -i 's/\<strcasecmp\>/g_ascii_\0/g' $(git grep -w -l strcasecmp -- ':(exclude)shared/systemd/' )
2020-02-11 15:23:06 +01:00
Beniamino Galvani
f4ced16791 libnm-core,cli: add VRF setting
Add new VRF setting and connection types to libnm-core and support
them in nmcli.
2020-01-14 09:49:01 +01:00
Thomas Haller
cccfeb3891 cli: don't use GIOChannel to watch plain file descriptor for nmc_readline_helper() 2020-01-13 15:46:04 +01:00
Antonio Cardace
df1d214b2e clients: polkit-agent: implement polkit agent without using libpolkit 2019-12-24 10:13:51 +01:00
Antonio Cardace
730adf2afd clients,libnm-core: zero-out memory used to store plain-text secrets 2019-12-18 16:15:06 +01:00
Antonio Cardace
725cc68710 common: readline: fix memory leak of plain text secret
After a user entered a secret it would get stored in the readline
history data structure (in plain text) and eventually get leaked.

This commit instructs readline to not store any secret in its
history and fixes a non-related memory leak.
2019-12-18 16:14:48 +01:00
Thomas Haller
4a3ca7115a all: fix wrong "gs_free GError *" declarations
This is a bug and leads either to a leak or a crash.
2019-12-16 17:42:23 +01:00
Thomas Haller
bd9b253540 all: rename time related function to spell out nsec/usec/msec/sec
The abbreviations "ns" and "ms" seem not very clear to me. Spell them
out to nsec/msec. Also, in parts we already used the longer abbreviations,
so it wasn't consistent.
2019-12-13 16:54:40 +01:00
Beniamino Galvani
622eef4882 cli: expose device D-Bus path
https://bugzilla.redhat.com/show_bug.cgi?id=1745574
2019-12-10 17:57:10 +01:00
Thomas Haller
030e1472f4 cli: don't fetch permissions for NMClient in nmcli unless required
This avoids unnecessarily fetching permissions, which are not needed
most of the time.

During `nmcli general permissions` we require to fetch the permissions. This is
now solved better, because previously the code waited for any permissions to be
not UNKNOWN. That was a hack, because there are cases where all permissions would
be UNKNOWN (hidepid mount option) and nmcli would hang.

There is a downside too: for `nmcli general permissions` we now first
need to wait for NMClient to initialize, before starting to fetch
permissions. Previously, we would call GetPermissions() in parallel
with initializing NMClient. It now takes longer.
That should be fixed be refactoring the code in nmcli to not wait for
NMClient to be fully initialized, before requesting the permissions.
2019-12-10 09:17:17 +01:00
Thomas Haller
3035837aa8 cli: use nmc_client_new_async() instead of nm_client_new_async()
This will allow us to set construct parameters to the instance, like
NM_CLIENT_INSTANCE_FLAGS.
2019-12-10 09:17:17 +01:00
Thomas Haller
89d55ad6e1 cli: sort permission in output of nmcli general permissions 2019-12-10 07:53:25 +01:00
Thomas Haller
bfdd352a61 libnm,cli: cleanup mapping between NMClientPermission and strings 2019-12-10 07:53:25 +01:00
Thomas Haller
50a12ce2d5 core: also return unknown permission check result
For example with

  mount -o remount,rw,hidepid=1 /proc/

all permission checks will fail with an error. Internally, we map the
failure to NM_AUTH_CALL_RESULT_UNKNOWN.

    <trace> [1575645672.5958] auth: call[1069]: CheckAuthorization(org.freedesktop.NetworkManager.enable-disable-connectivity-check), subject=unix-process[pid=468316, uid=1000, start=1912881]
    <trace> [1575645672.6295] auth: call[1069]: completed: failed: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dfile_2derror_2dquark.Code4: Failed to open file “/proc/468316/status”: No such file or directory
    <debug> [1575645672.6296] manager: unknown auth chain result 0

First of all, we should not log a debug message about that (we already log the
result of permission checks separately).

Also, we should include the unknown result in the response. The permission was
checked, and omitting it from GetPermissions() result seems wrong (even if we
failed to get the result).

Note that "unknown" is now a new possible return value on D-Bus. But
see how nm_permission_result_to_client() would map such a value to
"unknown" as well. So, it's probably a fine extension of the D-Bus API.

Note that NMClient API is currently quite limited. The user won't know
whether permissions were received (and if they were received, they
could not distinguish between UNKNOWN and absent). Hence, returning
all permissions as unknown (or not at all) causes `nmcli general permissions`
to hang. The solution here is to improve NMClient API to allow the user
to know when the permissions are received. But this patch doesn't
fix the hanging of nmcli nor the limitation of NMClient's API.
2019-12-10 07:53:25 +01:00
David Bauer
977c0c2387 client/cli: add support for OWE key management flag 2019-12-05 14:00:10 +01:00
Beniamino Galvani
2b7def052f all: add device carrier flag
Add a new 'carrier' flag to the InterfaceFlags property of devices to
indicate the current carrier state.

The new flag is equivalent to the 'lower-up' flag for all devices
except the ones that use a non-standard carrier detection mechanism
like NMDeviceAdsl.
2019-11-22 10:18:27 +01:00
Beniamino Galvani
62c811b2bd cli: print interface flags 2019-11-22 10:18:26 +01:00
Thomas Haller
6a9ed0adfb cli: unsubscribe permission signal from NMClient on exit
During the libnm rework, we might still emit permissions changed
signal while destructing the instance. That triggers an assertion.

Backtrace, with a different libnm:

  #0  _g_log_abort (breakpoint=1) at ../glib/gmessages.c:554
  #1  0x00007ffff77d09b6 in g_logv (log_domain=0x7ffff7f511cd "libnm", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffcb80) at ../glib/gmessages.c:1373
  #2  0x00007ffff77d0b83 in g_log
      (log_domain=log_domain@entry=0x7ffff7f511cd "libnm", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff78215df "%s: assertion '%s' failed")
      at ../glib/gmessages.c:1415
  #3  0x00007ffff77d137d in g_return_if_fail_warning
      (log_domain=log_domain@entry=0x7ffff7f511cd "libnm", pretty_function=pretty_function@entry=0x7ffff7f58aa0 <__func__.40223> "nm_client_get_permission_result", expression=expression@entry=0x7ffff7f54830 "NM_IS_CLIENT (client)") at ../glib/gmessages.c:2771
  #4  0x00007ffff7e9de9a in nm_client_get_permission_result (client=0x0, permission=permission@entry=NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK) at libnm/nm-client.c:3816
  #5  0x0000555555593ba3 in got_permissions (nmc=nmc@entry=0x55555562ec20 <nm_cli>) at clients/cli/general.c:587
  #6  0x0000555555593bcb in permission_changed (client=<optimized out>, permission=<optimized out>, result=<optimized out>, nmc=0x55555562ec20 <nm_cli>) at clients/cli/general.c:600
  #7  0x00007ffff73b1aa8 in ffi_call_unix64 () at ../src/x86/unix64.S:76
  #8  0x00007ffff73b12a4 in ffi_call (cif=cif@entry=0x7fffffffced0, fn=fn@entry=0x555555593bbf <permission_changed>, rvalue=<optimized out>, avalue=avalue@entry=0x7fffffffcde0)
      at ../src/x86/ffi64.c:525
  #9  0x00007ffff78b4746 in g_cclosure_marshal_generic_va
      (closure=<optimized out>, return_value=<optimized out>, instance=<optimized out>, args_list=<optimized out>, marshal_data=<optimized out>, n_params=<optimized out>, param_types=<optimized out>) at ../gobject/gclosure.c:1614
  #10 0x00007ffff78b3996 in _g_closure_invoke_va (closure=0x5555556f4330, return_value=0x0, instance=0x55555565a020, args=0x7fffffffd180, n_params=2, param_types=0x555555656f00)
      at ../gobject/gclosure.c:873
  #11 0x00007ffff78d0228 in g_signal_emit_valist (instance=0x55555565a020, signal_id=<optimized out>, detail=0, var_args=var_args@entry=0x7fffffffd180) at ../gobject/gsignal.c:3306
  #12 0x00007ffff78d09d3 in g_signal_emit (instance=instance@entry=0x55555565a020, signal_id=<optimized out>, detail=detail@entry=0) at ../gobject/gsignal.c:3453
  #13 0x00007ffff7e8989a in _emit_permissions_changed (self=self@entry=0x55555565a020, permissions=permissions@entry=0x555555690e40 = {...}, force_unknown=force_unknown@entry=1)
      at libnm/nm-client.c:2874
  #14 0x00007ffff7e9a0c9 in _init_release_all (self=self@entry=0x55555565a020) at libnm/nm-client.c:6092
  #15 0x00007ffff7e9bcde in dispose (object=0x55555565a020 [NMClient]) at libnm/nm-client.c:6838
  #16 0x00007ffff78b8c28 in g_object_unref (_object=<optimized out>) at ../gobject/gobject.c:3344
  #17 g_object_unref (_object=0x55555565a020) at ../gobject/gobject.c:3274
  #18 0x00005555555badcf in nmc_cleanup (nmc=0x55555562ec20 <nm_cli>) at clients/cli/nmcli.c:924
  #19 0x00005555555bbea7 in main (argc=<optimized out>, argv=0x7fffffffd498) at clients/cli/nmcli.c:987
2019-11-07 11:34:36 +01:00
Antonio Cardace
303fc17450 nmcli: show IP interface name when doing 'nmcli connection show <PROFILE>'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/218

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/322
2019-11-06 21:08:23 +01:00
Lubomir Rintel
e63b2afe7c clients/cli: give some hints to the translators 2019-10-30 17:15:14 +01:00
Lubomir Rintel
9c5ea0917d devices: reuse the hotspot connection if we find appropriate one
Otherwise repeated "nmcli d wifi hotspot" commands create multiple
Hostpot connections, which is just sad. We do already reuse existing
connections with "nmcli d wifi connect" -- let's just do a similar thing
here.
2019-10-30 14:29:38 +01:00
Lubomir Rintel
9f5711bec4 cli: split off the update or add-and-activate logic 2019-10-30 14:08:57 +01:00
Lubomir Rintel
7061341a41 cli: add "nmcli d wifi show"
A quick overview of the currently connected Wi-Fi network, including
credentials. Comes handy if someone wants to connect more devices to
their Hotspot or the same network as they are connected to.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
976eebae73 cli/devices: keep the AddAndActivateInfo alive until the activation ends
In a future commit it will be useful to know whether the activation
details when the activation succeeds.

This also makes the state tracking of the ongoing activation more
elegant, since we got our device and AC neatly packed together and we
can treat their respective state changes consistently.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
8766d05ea9 cli/devices: on connecting a device, don't uselessly look it up from the ac
For quite some time we already pass the AddAndActivateInfo for device
connect too, and that one remembers the device.
2019-10-18 17:38:57 +02:00
Thomas Haller
ba2e1d52ad libnm,client: use nm_g_task_new() to set source-tag and check it
Public API should validate input arguments with g_return_*().
Tag the task with the source function (using nm_g_task_new())
and check it in the corresponding _finish() function.
2019-10-16 08:56:00 +02:00
Thomas Haller
597e4b2d1e cli: honor NO_COLOR environment variable to prevent automatic ASCII colors
See-also: https://no-color.org/
2019-10-08 12:18:20 +02:00
Beniamino Galvani
d0db41c1d4 cli: fix crash in 'nmcli connection add'
The connection type can be NULL.

Fixes: e1ec22f74b ('cli: cleanup setting default interface-name')
2019-10-07 13:35:02 +02:00
Thomas Haller
10e8f7fdb4 cli: translate overview output of nmcli
Note the "to" in the output:

  $ LANG=de_DE.UTF-8 nmcli
  eth0: verbunden to Wired Connection 1
        "Intel Ethernet"
  ...

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/246
2019-10-02 18:17:21 +02:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
Marco Trevisan (Treviño)
b68bb97971 cli: Assert we don't require multiple commands during client initalization
If a new command was requested while a client was in the process of being
created we were just requesting a new client.

This was causing leak, so let's strongly ensure this is not the case.
2019-10-02 09:11:28 +02:00
Thomas Haller
c4c8889256 cli: fix leaking error variable in command_done() 2019-10-02 09:11:28 +02:00
Marco Trevisan (Treviño)
479c269766 cli: Use GTask to perform async requests 2019-10-02 09:11:28 +02:00
Iñigo Martínez
8a5a38f74a meson: Improve nmcli build
The dependencies used in the build of `nmcli` has been reviewed and
removed the unnecessary ones. The used compiler flags has also been
moved to one line.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
096748a196 meson: Rename cflags variable
The variable holding the compiler flags, `cflags`, has been renamed
to `c_flags` to be consistent with the rest of build files.

Different objects used in the `test-dispatcher-envp` target
have been grouped together.

The dependency over the `libnm` library has been removed as it is
unnecessary.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
70a34c54fe meson: Use dependency for nm-default header
The `nm-default.h` header is used widely in the code by many
targets. This header includes different headers and needs different
libraries depending the compilation flags.

A new set of `*nm_default_dep` dependencies have been created to
ease the inclusion of different directorires and libraries.

This allows cleaner build files and avoiding linking unnecessary
libraries so this has been applied allowing the removal of some
dependencies involving the linking of unnecessary libraries.
2019-10-01 09:49:33 +02:00
Thomas Haller
abff46cacf all: manually drop code comments with file description 2019-10-01 07:50:52 +02:00
Lubomir Rintel
25fadf8f92 cli: add kill switch indication to "nmcli" output
There is some guess work done on the client side. Perhaps the
o.fd.NM.Device could be extended to indicate which kill switch is the
device disabled by. This could be good enough for now though.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/271/commits
2019-09-20 12:49:21 +02:00
Beniamino Galvani
5afcf9c045 cli: add 'general reload' command
Add 'nmcli general reload [flags]' command to reload NM configuration
and perform other updates.
2019-09-17 09:31:34 +02:00
Beniamino Galvani
fd8d5a0c7a cli: don't create a NMClient for the 'connection reload' command
It is a waste of resources instantiating a NMClient, filling the
object cache and then throwing everything away without using it. This
can take seconds on slow systems with many objects. Since the
ReloadConnections doesn't need anything from the cache, just execute
the D-Bus method call directly.
2019-09-17 09:31:34 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Lubomir Rintel
b76da15dbf clients: avoid clearing a structure pointer when we're still using it
We're dereferencing the info pointer in the argument list in the call to
nm_client_activate_connection_async(). Stealing it at that point causes
a crash.

This reverts a chunk of commit b298f2e605 ('cli: use cleanup macro for
freeing AddAndActivateInfo').
2019-09-02 14:58:43 +02:00
Beniamino Galvani
73b3806228 wifi: expose IBSS_RSN capability
The new capability indicates whether the device supports WPA2/RSN in
an IBSS (ad-hoc) network.

https://bugzilla.gnome.org/show_bug.cgi?id=757823
2019-08-26 10:25:00 +02:00
Maciek Borzecki
378099c60e cli: include BSSID to NMC_FIELDS_DEV_WIFI_LIST_COMMON
When using WiFi in an environment with multiple APs of the same SSID (eg.
conference venue, hotels), it is often useful to be able to identify particular
APs by their BSSID.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/235
2019-08-22 11:36:06 +02:00
Francesco Giudici
40647bd887 cli: prefer nm_assert() to g_assert*() 2019-08-22 11:35:53 +02:00
Francesco Giudici
1a91ef2dc6 cli: fix bad indentation 2019-08-22 11:35:38 +02:00
Thomas Haller
0e1748afe1 cli: cleanup unique_master_iface_ifname()
- use appropriate types for integer variables

- rework the confusing loop which would reset the loop-counter
  to start again.
2019-08-20 15:31:08 +02:00