Re: Retrieving 'secret' setting




On 07 September 2017 at 16:37 Dan Williams <dcbw redhat com> wrote:

On Thu, 2017-09-07 at 09:31 +0100, Colin Helliwell wrote:

On 06 September 2017 at 17:18 Dan Williams <dcbw redhat com> wrote:

On Wed, 2017-09-06 at 12:51 +0100, Colin Helliwell wrote:

On 06 September 2017 at 11:14 Thomas Haller <thaller redhat com >
wrote:

On Wed, 2017-09-06 at 10:20 +0100, colin.helliwell@ln-systems.c
om
wrote:

I'm python-scripting to get a connection's gsm properties,
and
want
to get
the password - which "c.for_each_setting_value(print_values,
None)"
seems to
not report (just "None").
What would be the technique to get it?
Thanks

Hi,

on D-Bus, secrets are exposed separately from regular
properties of
the
connection.

GetSettings() vs GetSecrets() in
https://developer.gnome.org/NetworkManager/stable/gdbus-org.fre
edes
ktop.NetworkManager.Settings.Connection.html

Anyway, from libnm (and python gi) you would call

secrets = remote_connection.get_secrets('ethernet')

Great, got that. Now, don't suppose you could help me get to
grips
with parsing the Glib.Variant....? ;)

You can get around the need for touching GVariant by passing what
you
get from get_secrets() to NMConnection's replace_settings() call
too.
Then you get a nice NMConnection object, with only the secrets
filled
in. For example, pass a connection UUID as the argument to this:

#!/usr/bin/env python
import gi
gi.require_version('NM', '1.0')
from
gi.repository import GLib, NM
import sys

client = NM.Client.new(None)
c = client.get_connection_by_uuid(sys.argv[1])
wifi_secrets =
c.get_secrets(NM.SETTING_WIRELESS_SECURITY_SETTING_NAME)
wifi_secrets_con = NM.SimpleConnection.new()
wifi_secrets_con.replace_settings(wifi_secrets)
wsec = wifi_secrets_con.get_setting_wireless_security()
print "%s" % wsec.get_psk()

Thanks Dan, that gets it.
Now I'm struggling to *modify* the password.... :S I see that I can
do a
 settings.set_property(NM.SETTING_GSM_PASSWORD, "NewPw")
but unsure how to complete the updating. I found
NM.Connection.replace_settings(), and update_secrets(), but both of
those put me back into GVariant territory.
What would be the route to get the new password fed back through
(presumably prior to finishing with a
NM.RemoteConnection.save()/commit()?)

You're correct. Here's what I'd do:

client = NM.Client.new(None)
c =
client.get_connection_by_uuid(sys.argv[1])
secrets =
c.get_secrets(NM.SETTING_WIRELESS_SECURITY_SETTING_NAME)

# this merges
the secrets into the existing connection
c.update_secrets(NM.SETTING_WIR
ELESS_SECURITY_SETTING_NAME, secrets)



# write the full connection back to NM
c.save()

Thanks, I'll work through that in due course, but just to step back a bit to something perhaps simpler (which 
may help my understanding in general!) I've just been trying to modify some other gsm settings. All is good 
until trying to write the changes to the connection file (/etc/NetworkManager/system-connections/):
c.save() does write to the file (I see the timestamp is changed), but the setting itself is unchanged, whereas
c.commit_changes(True,None) *does* alter the setting in there.

Just wondering therefore what save() is intended for, and/or whether it needs to be used in a different way?
No problem to use commit_changes() instead, but save() doesn't seem to be doing what the docs imply: "Saves 
the connection to disk if the connection has changes that have not yet been written to disk, or if the 
connection has never been saved"

AND, just to get my next question in while I'm at it :)   - What are the calls to do a down/reload/up on the 
connection? (i.e. I'll have changed the gsm settings from incorrect apn etc to correct, and want pppd to be 
kicked into a re-connect)

Thanks!


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]