Re: Problem to add a broadband connection on NetworkManagerUserSettings



On Tuesday 19 January 2010 16:45:23 Jirka Klimes wrote:
> On Wednesday 13 January 2010 16:33:27 Maxwell Chiareli Xandeco wrote:
> > I'm using Ubuntu 9.10, with your code I don't get errors but a
> > connection is not added, nothing happens when I call AddConnection
> > method.
> 
> I've investigated it a bit and found out that AddConnection is not
>  supported via D-Bus due to security reasons.
> (src/gconf-helpers/nma-gconf-settings.c:add_connection() function)
> 

Actually, there is an error causing critical error (g_error_new (0, ...))

g_error_new (0, ...
(nm-applet:27425): GLib-CRITICAL **: g_error_new: assertion `domain != 0' 
failed
(nm-applet:27425): GLib-CRITICAL **: g_error_free: assertion `error != NULL' 
failed

The attached patch fixes that. D-Bus then returns an error message on 
AddConnection.
Please find also attached test program in python.

Jirka
diff --git a/src/gconf-helpers/nma-gconf-settings.c b/src/gconf-helpers/nma-gconf-settings.c
index 986d947..57300c1 100644
--- a/src/gconf-helpers/nma-gconf-settings.c
+++ b/src/gconf-helpers/nma-gconf-settings.c
@@ -191,7 +191,10 @@ add_connection (NMSettingsService *settings,
 	if (context) {
 		GError *error;
 
-		error = g_error_new (0, 0, "%s: adding connections via D-Bus is not (yet) supported", __func__);
+		/* Beware: error domain is actually checked in D-Bus via _dbus_validate_interface() function. 
+		 * That's why use an interface name.
+		 */
+		error = g_error_new (g_quark_from_string("org.freedesktop.NetworkManagerSettings.AddFailed"), 0, "%s: adding connections via D-Bus is not (yet) supported", __func__);
 		callback (NM_SETTINGS_INTERFACE (settings), error, user_data);
 		g_error_free (error);
 		return;
#!/usr/bin/python

import dbus                                                                                                                                                                                                    
import glib  
import posix
import os

settings = dbus.Dictionary({dbus.String(u'connection'):
dbus.Dictionary({dbus.String(u'timestamp'): dbus.UInt64(1263301788L,
variant_level=1), dbus.String(u'autoconnect'):     dbus.Boolean(False,
variant_level=1), dbus.String(u'type'): dbus.String(u'gsm',
variant_level=1), dbus.String(u'uuid'):
dbus.String(u'8a0e02d9-9b1a-463b-a089-7a68140bf4c3', variant_level=1),
dbus.String(u'id'): dbus.String(u'Vivo Default', variant_level=1)},
signature=dbus.Signature('sv')), dbus.String(u'ppp'):
dbus.Dictionary({}, signature=dbus.Signature('sv')),
dbus.String(u'gsm'): dbus.Dictionary({dbus.String(u'username'):
dbus.String(u'vivo', variant_level=1), dbus.String(u'band'):
dbus.Int32(0, variant_level=1), dbus.String(u'apn'):
dbus.String(u'zap.vivo.com.br', variant_level=1),
dbus.String(u'number'): dbus.String(u'*99#', variant_level=1)},
signature=dbus.Signature('sv')), dbus.String(u'serial'):
dbus.Dictionary({dbus.String(u'baud'): dbus.UInt32(115200L,
variant_level=1)}, signature=dbus.Signature('sv')), dbus.String(u'ipv4'):
dbus.Dictionary({dbus.String(u'method'): dbus.String(u'auto',
variant_level=1)}, signature=dbus.Signature('sv'))},
signature=dbus.Signature('sa{sv}'))


uuid = "cabfaf9e-4043-4afb-8506-0e6f4a225636"
s_con = { 'id':          'NovaGSM',
          'uuid':        uuid,
          'type':        'gsm',
          'autoconnect': False,
          'name':        'connection' }


s_gsm = { 'username':     'vivo',
          'band':     0, 
          'apn': 'zap.vivo.com.br',
          'number':     '*99#', 
          'name':     'gsm' }


s_ip4 = { 'method': 'auto',
          'name':   'ipv4' }

s_ppp = { 'name': 'ppp' }

s_serial = { 'baud': 115200,
             'name': 'serial' }



con = { 'connection': s_con,
        'gsm': s_gsm,
        'ppp': s_ppp,
        'serial': s_serial,
        'ipv4': s_ip4 }



sys_bus = dbus.SystemBus()
ses_bus = dbus.SessionBus()
proxy = sys_bus.get_object("org.freedesktop.NetworkManagerUserSettings", "/org/freedesktop/NetworkManagerSettings")
iface = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings")

try:
    iface.AddConnection(con)
except Exception, e:
    print e



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