After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 740135 - [review] lr/nm-1-0-fixes: Fixes for issues identified in master testing
[review] lr/nm-1-0-fixes: Fixes for issues identified in master testing
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-11-14 17:49 UTC by Lubomir Rintel
Modified: 2014-11-20 16:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] cli: Only construct an agent for a connection if there is a connection (3.91 KB, text/plain)
2014-11-16 15:26 UTC, Lubomir Rintel
Details

Description Lubomir Rintel 2014-11-14 17:49:49 UTC
A couple of mostly trivial fixes, VPN and CLI related (sorry for the mixup):

http://cgit.freedesktop.org/NetworkManager/NetworkManager/log/?h=lr/nm-1-0-fixes
Comment 1 Dan Williams 2014-11-14 19:35:50 UTC
They all look good to me.
Comment 2 Dan Winship 2014-11-14 22:47:22 UTC
All look good except:

> cli: Only construct an agent for a connection if there is a connection

The point of the code is that we only want to answer secret requests if they're for the connection that we're activating.

But that gets complicated here, because we won't know the connection path until the AddAndActivate() call returns, but if we wait until that point to register the secret agent, then the daemon might get the registration too late... So I guess, we need to add nm_secret_agent_simple_set_connection_path() so we can first create the agent without a path, and then set the path later once we know it. (Although, we also need to make it so it doesn't respond to any requests in between... I guess you could just pass a dummy path rather than no path when creating it.)
Comment 3 Lubomir Rintel 2014-11-16 15:26:42 UTC
Created attachment 290799 [details]
[PATCH] cli: Only construct an agent for a connection if there is a connection

(In reply to comment #2)
> All look good except:
> 
> > cli: Only construct an agent for a connection if there is a connection
> 
> The point of the code is that we only want to answer secret requests if they're
> for the connection that we're activating.
> 
> But that gets complicated here, because we won't know the connection path until
> the AddAndActivate() call returns, but if we wait until that point to register
> the secret agent, then the daemon might get the registration too late... So I
> guess, we need to add nm_secret_agent_simple_set_connection_path() so we can
> first create the agent without a path, and then set the path later once we know
> it. (Although, we also need to make it so it doesn't respond to any requests in
> between... I guess you could just pass a dummy path rather than no path when
> creating it.)

You mean, like this? I think (not tested yet) it's still racy, as the secret might be requested before we set the path?

I'm wondering if we shouldn't use the path of the device instead?
Comment 4 Dan Winship 2014-11-16 22:32:41 UTC
(In reply to comment #3)
> You mean, like this? I think (not tested yet) it's still racy, as the secret
> might be requested before we set the path?

Hm, yes, I was thinking it was safe because we know you'll get the AddAndActivateConnection reply before you could get a secrets request, but we don't know for sure that all of the async NMObject property loading stuff will finish in time.

> I'm wondering if we shouldn't use the path of the device instead?

The secret agent doesn't know the device (and can't necessarily figure it out from the connection yet, because of the same race condition).

Oh... but we can just use the connection UUID rather than the path. That should work.
Comment 5 Lubomir Rintel 2014-11-19 19:54:19 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > You mean, like this? I think (not tested yet) it's still racy, as the secret
> > might be requested before we set the path?
> 
> Hm, yes, I was thinking it was safe because we know you'll get the
> AddAndActivateConnection reply before you could get a secrets request, but we
> don't know for sure that all of the async NMObject property loading stuff will
> finish in time.
> 
> > I'm wondering if we shouldn't use the path of the device instead?
> 
> The secret agent doesn't know the device (and can't necessarily figure it out
> from the connection yet, because of the same race condition).
> 
> Oh... but we can just use the connection UUID rather than the path. That should
> work.

Consulted with Jirka -- turned out that we need to deal with the "activate an existing connection, but let server negotiate it" case, so generating uuid in client is not a viable option.

I've updated the branch. I'm now deferring the secret request processing to until we learn the actual path.

It works for me, I'm not particularly happy about the abuse of "/" literal for "we'll learn the real connection path later"; ideas about how to make it nicer are welcome.
Comment 6 Dan Winship 2014-11-19 22:19:35 UTC
(In reply to comment #5)
> It works for me, I'm not particularly happy about the abuse of "/" literal for
> "we'll learn the real connection path later"; ideas about how to make it nicer
> are welcome.

Hm, yeah.

You could separate out the path-setting and stop/go into separate properties. So instead of adding a "path" arg to nm_secret_agent_simple_new(), add a "running" arg. Then, in the "nmcli agent" case, you'd do:

  agent = nm_secret_agent_simple_new ("nmcli", TRUE);

And in the activate case:

  agent = nm_secret_agent_simple_new ("nmcli", TRUE);
  nm_secret_agent_simple_set_path (agent, connection_path);

And in the add-and-activate case:

  agent = nm_secret_agent_simple_new ("nmcli", FALSE);

  /* time passes */

  nm_secret_agent_simple_set_path (agent, connection_path);
  nm_secret_agent_simple_set_running (agent, TRUE);


>+	if (!g_str_has_prefix (request->request_id, priv->path)) {
>+		request_secrets_from_ui (request);

The "!" shouldn't be there should it?
Comment 7 Jiri Klimes 2014-11-20 10:49:58 UTC
>>+	if (!g_str_has_prefix (request->request_id, priv->path)) {
>>+		request_secrets_from_ui (request);

> The "!" shouldn't be there should it?

Right, we should handle matching path.

> »·······»·······»·······error = g_error_new (NM_SECRET_AGENT_ERROR,  NM_SECRET_AGENT_ERROR_FAILED,
> »·······»·······»·······»·······»·······     "Request for %s secrets doesn't match path %s",
> »·······»·······»·······»·······»·······     request->request_id, priv->path);

indentation (two extra tabs)
Comment 8 Jiri Klimes 2014-11-20 11:49:41 UTC
I have published a branch jk/nmcli-dev-connect-secrets that adds secret agent support for 'nmcli device connect' too (on top of Lubomir stuff).
Comment 9 Lubomir Rintel 2014-11-20 12:10:57 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > It works for me, I'm not particularly happy about the abuse of "/" literal for
> > "we'll learn the real connection path later"; ideas about how to make it nicer
> > are welcome.
> 
> Hm, yeah.
> 
> You could separate out the path-setting and stop/go into separate properties.
> So instead of adding a "path" arg to nm_secret_agent_simple_new(), add a
> "running" arg. Then, in the "nmcli agent" case, you'd do:
> 
>   agent = nm_secret_agent_simple_new ("nmcli", TRUE);
> 
> And in the activate case:
> 
>   agent = nm_secret_agent_simple_new ("nmcli", TRUE);
>   nm_secret_agent_simple_set_path (agent, connection_path);
> 
> And in the add-and-activate case:
> 
>   agent = nm_secret_agent_simple_new ("nmcli", FALSE);
> 
>   /* time passes */
> 
>   nm_secret_agent_simple_set_path (agent, connection_path);
>   nm_secret_agent_simple_set_running (agent, TRUE);

Done.

I'm doing nm_secret_agent_simple_enable_running() which unconditionally sets
running to true instead of nm_secret_agent_simple_set_running() as it does not
really make sense to disable the agent once it's running and it would make the
implementation more difficult (we'd need to keep track of requests that were
presented to the user already).

(In reply to comment #7)
> >>+	if (!g_str_has_prefix (request->request_id, priv->path)) {
> >>+		request_secrets_from_ui (request);
> 
> > The "!" shouldn't be there should it?
> 
> Right, we should handle matching path.

Fixed.

> > »·······»·······»·······error = g_error_new (NM_SECRET_AGENT_ERROR,  NM_SECRET_AGENT_ERROR_FAILED,
> > »·······»·······»·······»·······»·······     "Request for %s secrets doesn't match path %s",
> > »·······»·······»·······»·······»·······     request->request_id, priv->path);
> 
> indentation (two extra tabs)

Fixed.
Comment 10 Dan Winship 2014-11-20 14:27:38 UTC
>+	nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect", FALSE);
>+	if (nmc->secret_agent) {
> 		g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc);
>+		if (connection) {
>+			nm_secret_agent_simple_set_connection_path (nmc->secret_agent,
>+			                                            nm_object_get_path (NM_OBJECT (connection)));
>+			nm_secret_agent_simple_enable_running (nmc->secret_agent);

There's no need to pass FALSE initially and then set enable_running; there's no way a request could be received in between creating it and setting the path, so you can just pass TRUE. (Likewise in the nmtui patch.)

>+nm_secret_agent_simple_enable_running (NMSecretAgent *agent)

"enable_running" sounds weird. "_enable()", "_run()", "_start()", "_set_running()"

> 	agent = g_initable_new (NM_TYPE_SECRET_AGENT_SIMPLE, NULL, NULL,
> 	                        NM_SECRET_AGENT_IDENTIFIER, name,
> 	                        NULL);
>-	NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (agent)->path = g_strdup (path);
>+	NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (agent)->running = running;

This is already broken in master but I'm just noticing it now; g_initable_new() will return NULL here if NM isn't running (or some other error occurs while trying to register the agent), so you need to check that agent is non-NULL before setting path/running.

(Unless you disagree with any of this stuff I don't think another round of review is needed. Just fix it up and commit.)
Comment 11 Jiri Klimes 2014-11-20 15:41:47 UTC
I added a fix and support for secrets in 'nmcli device connect'

jk/nmcli-dev-connect-secrets rebased on master.
Comment 12 Jiri Klimes 2014-11-20 16:22:24 UTC
Commits in master:
224acba cli,vpn: merge branch 'lr/nm-1-0-fixes'
991df80 cli: Process secret agent request for a connection only if we know its path
d4240ad cli: Abort when given name of a non-existent connection for nmcli up
75f767c libnm: Don't expect VPN connections to attach to the device
282d9b0 vpn: Propagate daemon exec error correctly
5197419 cli: Only escape VPN banner if it's present

4b799db cli: add support for secret agent to 'nmcli dev connect' too
a1f16d2 clients: fix processing a secret agent request