Commit Graph

66 Commits

Author SHA1 Message Date
Beniamino Galvani
42304b34fd clients: fix GVariantBuilder memory leak
Fixes: acf86f68b3
(cherry picked from commit 22c87f0df8)
2019-03-05 09:45:02 +01:00
Beniamino Galvani
f1628ea6f1 clients: fix i/o stream memory leaks
Fixes: 5a0d67f739
(cherry picked from commit 91a644d4a5)
2019-03-05 09:44:59 +01:00
Beniamino Galvani
efce1e34f2 clients: fix keyfile string memory leak
The return value of g_key_file_get_string() was leaked.

Fixes: 5a0d67f739
(cherry picked from commit 082ae508a0)
2019-03-05 09:44:57 +01:00
Beniamino Galvani
72f40fc421 clients: fix double free
@secrets is unreferenced at the end of request_secrets_from_ui() and
so try_spawn_vpn_auth_helper() must take a reference to it.

Fixes: 1a0fc8d437
(cherry picked from commit b57a3a4cc6)
2019-03-05 09:44:56 +01:00
Thomas Haller
e148ec07d5 libnm: add NMWireGuardPeer and libnm support for peers 2019-02-22 11:00:10 +01:00
Thomas Haller
b521f426ab libnm,cli: add NMSettingWireGuard
For now only add the core settings, no peers' data.

To support peers and the allowed-ips of the peers is more complicated
and will be done later. It's more complicated because these are nested
lists (allowed-ips) inside a list (peers). That is quite unusual and to
conveniently support that in D-Bus API, in keyfile format, in libnm,
and nmcli, is a effort.
Also, it's further complicated by the fact that each peer has a secret (the
preshared-key). Thus we probably need secret flags for each peer, which
is a novelty as well (until now we require a fixed set of secrets per
profile that is well known).
2019-02-22 11:00:10 +01:00
Thomas Haller
ead7c00348 clients/secret-agent: split creation of secret-request data 2019-02-14 08:00:29 +01:00
Thomas Haller
a4f0bda6d4 clients/secret-agent: fail request_secrets_from_ui() if there are no secrets to be requested
From looking at the code above, this likely shouldn't actually happen.
2019-02-14 08:00:29 +01:00
Thomas Haller
6ef825d501 clients/secret-agent: keep setting-name in request-data
It's not really used, but we shouldn't just forget about it.

Currently, we fill requests only based on the connection-type, ignoring
the setting-name. I guess, the concept of requesting secrets for a setting
is utterly broken. But equally broken it is to just look at the connection
(type). At least, don't just throw parts of the request away but keep
it.
2019-02-14 08:00:29 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Lubomir Rintel
fa2fe3688d clients/secret-agent: respond to SAE password requests 2019-02-05 10:20:27 +01:00
Thomas Haller
472f89da6b wifi,clients/secret-agent: use defines for property names in secret hints 2019-02-05 08:34:23 +01:00
Thomas Haller
787f5f7a46 clients/secret-agent: refactor code in request_secrets_from_ui() to return early 2019-02-05 08:34:23 +01:00
Thomas Haller
1a0fc8d437 clients/secret-agent: fix leaks in request_secrets_from_ui()
Fixes: 3bda3fb60c
2019-02-05 08:34:23 +01:00
Thomas Haller
883978ec99 clients/secret-agent: use g_hash_table_get_keys_as_array() in nm_secret_agent_simple_enable() 2019-02-05 08:34:23 +01:00
Thomas Haller
72f90a8fbc clients/secret-agent: fix cancel_get_secrets() implementation
The callback must be invoked, as also documented.

Otherwise, the tracked info gets leaked.

Let NMSecretAgentOld (the caller) be a bit resilient against
bugs in the client, and avoid a crash by prematurely remove
the request-info from the pending list. That does not fully
workaround the bug (it leads to a leak), but at least it does
not cause other "severe" issues.

The leak was present earlier as well.
2019-02-05 08:34:23 +01:00
Thomas Haller
99497a7674 clients/secret-agent: sink reference for variant passed to callback
NMSecretAgentOld's get_secrets_cb() gets this right and takes
a floating reference. So this was correct.

However, make this a bit more robust, and don't pass on
floating references. This was, we don't require the callee
to consume the reference.
2019-02-05 08:31:44 +01:00
Thomas Haller
c9ca1186c2 clients/secret-agent: add complete function for invoking secret callback
The completion of the request and the deletion usually goes hand in
hand. Add a function to unify them.
2019-02-05 08:27:43 +01:00
Thomas Haller
93c848ca03 clients: don't tread secret agent as NMSecretAgentOld
Most of the times we actually need a NMSecretAgentSimple typed pointer.
This way, need need to cast less.

But even if we would need to cast more, it's better to have pointers
point to the actual type, not merely to avoid shortcomings of C.
2019-02-05 08:27:42 +01:00
Thomas Haller
82472c557c clients/secret-agent: use nm-utils error reason for callback while disposing NMSecretAgentSimple
No caller cared about the NM_SECRET_AGENT_ERROR_AGENT_CANCELED reason.
In particular, because previously the requests would keep the secret-agent
instance alive, and this never happend.

Also, NM_SECRET_AGENT_ERROR_AGENT_CANCELED precicley exists for
NMSecretAgentOld:cancel_get_secrets() (as documented). During finalize
we are not cancelled -- at least not the same way as
cancel_get_secrets(). Setting NM_SECRET_AGENT_ERROR_AGENT_CANCELED
is wrong.

Anyway, we have a default error for such cases already.
2019-02-05 08:27:42 +01:00
Thomas Haller
d68bdce206 clients/secret-agent: minor cleanup of child-watch-id for secret-agent
The code was correct. But it's hard to follow when and whether
the child-watch-id was destroyed at the right time.

Instead, always let _auth_dialog_data_free() clear the signal handlers.
2019-02-05 08:27:42 +01:00
Thomas Haller
8b951afac9 clients/secret-agent: don't let request keep secret-agent alive
Don't let RequestData keep the parent NMSecretAgentSimple instance
alive. Previously, the code in finalize() was never actually reached.

Also, move the final callback from finalize() to dispose(). It feels
wrong to invoke callbacks from finalize().
2019-02-05 08:27:42 +01:00
Thomas Haller
16e0f38c3e clients/secret-agent: cancel pending operations
We must actually cancel the GCancellable. Otherwise, the pending async
operations are not cancelled. _auth_dialog_write_done() doesn't care
about that, but _auth_dialog_read_done() does. It must not touch the
destroyed data, after the operation is cancelled.
2019-02-05 08:27:42 +01:00
Thomas Haller
f2973fd72e clients/secret-agent: remove request in finalize loop early
It's ugly to keep the request in the list. Just remove it
right away.
2019-02-05 08:27:42 +01:00
Thomas Haller
4157092a8a clients/secret-agent: rework tracking of requests in secret-agent-simple
Note that previously the @requests hash took the request-id as key and
the RequestData as value. Likewise, the destroy functions of the head
would destroy the key and the value.

However, RequestData also had a field "request_id". But that pointer was
not owned (nor freed) by the RequestData structure. Instead, it was
relied that the hash kept the request-id alive long enough.

That is confusing. Let RequestData own the request-id.

Also, we don't need to track a separate key. Just move the request-id
as first filed in RequestData, and use compare/hash functions that
handle that correctly (nm_pstr_*()).
2019-02-05 08:27:12 +01:00
Thomas Haller
5572c8f81c clients/secret-agent: only pass char buffer to _auth_dialog_write_done()
We don't need the entire GString. It's only to keep the buffer alive
for long enough.
2019-02-05 08:22:01 +01:00
Thomas Haller
73f423c5e5 clients/secret-agent: various cleanups in secret-agent-simple 2019-02-05 08:22:01 +01:00
Thomas Haller
378a4a8e1a clients/secret-agent: drop strv_has() implementation 2019-02-05 08:22:01 +01:00
Thomas Haller
aaaa8902fd clients/secret-agent/trival: rename internal types, functions and variables
Code that is internal to a source file should not have a "nm" prefix.
That is what differenciates it from declarations in header files. It
makes it clearer that these names are only defined in the current file.

Also, our implementations of virtual functions shall have the same
name as the function pointer of the VTable (or at least, it shouldn't
have a "nm" prefix).
2019-02-05 08:22:01 +01:00
Thomas Haller
9d1becb0dd clients/secret-agent: embed private data in NMSecretAgentSimple class 2019-02-05 08:22:01 +01:00
Thomas Haller
a6600f5ae6 clients/secret-agent: reorder code in nm-secret-agent-simple.c 2019-02-05 08:22:01 +01:00
Lubomir Rintel
5a0d67f739 clients/secret-agent-simple: support auth helpers
This makes it possible to utilize agents in the "external UI" mode
instead of hardcoded handling of VPN secrets requests.

Ideally this would be turned into a library so that nm-applet can share
the code, but figuring out the right API might be a non-trivial
undertaking.
2018-10-22 18:15:25 +02:00
Thomas Haller
6bfab6796f cli: fix reading "vpn.secrets.*" from passwd-file
Due to a bug, we required VPN secrets to be prefixed with
"vpn.secret." instead of "vpn.secrets.". This was a change
in behavior with 1.12.0 release.

Fix it, to restore the old behavior. For backward compatibility
to the broken behavior, adjust parse_passwords() to treat accept
that as well.

https://bugzilla.redhat.com/show_bug.cgi?id=1628833
https://github.com/NetworkManager/NetworkManager/pull/201

Fixes: 0601b5d725
(cherry picked from commit 5815ae8c60)
2018-09-14 15:17:53 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
b32c03c879 clients: fix using hints for 802-1x secret request
https://github.com/NetworkManager/NetworkManager/pull/139

Fixes: 1a6e53808d
(cherry picked from commit 55598d8104)
2018-06-24 14:16:13 +02:00
Andrew Zaborowski
d1163e9499 cli: use the hints from 802.1x secrets requests if given
If the hints parameter to the agent request wasn't empty, ask
specifically for the 802-1x keys listed in the hints and skip the
guessing.  I didn't add human readable names for all of the 802-1x
settings, it could be useful to do for at least the three 802-1x
properties that add_8021x_secrets already knows about because
those may have translations.

(cherry picked from commit 1a6e53808d)
2018-06-22 16:46:05 +02:00
Thomas Haller
52baa8c52b clients: drop redundant #include "NetworkManager.h"
This header is already included by "nm-default.h".
2018-01-08 12:38:54 +01:00
Lubomir Rintel
6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Thomas Haller
0601b5d725 clients: some cleanup of requesting VPN secrets 2017-11-23 14:44:25 +01:00
Thomas Haller
3ee8de20c4 all: include "nm-utils/nm-hash-utils.h" by default
Next we will use siphash24() instead of the glib version g_direct_hash() or
g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very
fundamental and will be needed basically everywhere.

Instead of requiring the users to include them, let it be included via
"nm-default.h" header.
2017-11-16 11:49:51 +01:00
Beniamino Galvani
a25db64f7c clients: implement CancelGetSecrets() secret-agent API 2017-11-02 15:25:59 +01: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
Thomas Haller
abdf9a3673 all: change handling of connection.type for bluetooth NAP and in general
Branch f9b1bc16e9 added bluetooth NAP
support. A NAP connection is of connection.type "bluetooth", but it
also has a "bridge" setting. Also, it is primarily handled by NMDeviceBridge
and NMBridgeDeviceFactory (with help from NMBluezManager).

However, don't let nm_connection_get_connection_type() and
nm_connnection_is_type() lie about what the connection.type is.
The type is "bluetooth" for most purposes -- at least, as far as
the client is concerned (and the public API of libnm). This restores
previous API behavior, where nm_connection_get_connection_type()
and nm_connection_is_type() would be simple accessors to the
"connection.type" property.

Only a few places care about the bridge aspect, and those places need special
treatment. For example NMDeviceBridge needs to be fully aware that it can
handle bluetooth NAP connection. That is nothing new: if you handle a
connection of any type, you must know which fields matter and what they
mean. It's not enough that nm_connection_get_connection_type() for bluetooth
NAP connectins is claiming to be a bridge.

Counter examples, where the original behavior is right:

src/nm-manager.c-        g_set_error (error,
src/nm-manager.c-                     NM_MANAGER_ERROR,
src/nm-manager.c-                     NM_MANAGER_ERROR_FAILED,
src/nm-manager.c-                     "NetworkManager plugin for '%s' unavailable",
src/nm-manager.c:                     nm_connection_get_connection_type (connection));

the correct message is: "no bluetooth plugin available", not "bridge".

src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:   if (   (   nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:           && !nm_connection_get_setting_pppoe (connection))
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c-        return TRUE;

the correct behavior is for ifcfg-rh plugin to reject bluetooth NAP
connections, not proceed and store it.
2017-06-07 09:07:17 +02:00
Lubomir Rintel
1d35fd0103 clients: respond to the secret requests that we can't service
Otherwise the daemon would hang waiting for us while we respond with awkward
silence. That is not a healthy kind of communication.
2017-06-02 20:52:16 +02:00
Thomas Haller
29dbc21c30 cli: fix leak in add_vpn_secrets()
No need to copy @tmp variable, it was leaked.
2017-04-05 14:18:55 +02:00
Beniamino Galvani
d197c0626a cli: macsec support 2017-01-16 17:47:10 +01:00
Beniamino Galvani
2a391348b6 clients: fix check on secret request path
priv->path is NULL when the agent handles all requests (for example
when executing "nmcli agent").

Fixes: f3099db28e
2016-09-15 09:40:03 +02:00
Beniamino Galvani
f666efed0d clients: fix matching of connection path
Since we use g_str_has_prefix() to match a request_id with the
connection path, there can be wrong matches. For example:

 request_id: /org/freedesktop/NetworkManager/Settings/10/802-1x
 connection: /org/freedesktop/NetworkManager/Settings/1

would match. Add a trailing slash to the connection path stored in the
agent to prevent this.
2016-09-14 23:34:25 +02:00
Beniamino Galvani
f3099db28e clients: handle secret requests only for current connection
The path was checked only when serving the enqueued requests but not
for new ones. Fix this by moving the check to
request_secrets_from_ui().

Fixes: 991df80408

https://bugzilla.redhat.com/show_bug.cgi?id=1351272
2016-09-14 23:34:25 +02:00
Beniamino Galvani
2c1adaae5e clients: add secrets request message for wired and DSL connections 2016-09-14 23:32:52 +02:00