all: merge branch 'danw/gdbus-bgo622927'

Port the remaining parts of src/ to gdbus.

(Note that most of the individual commits on this branch do not
compile; they are split up for ease of comprehension, but all depend
on each other.)

https://bugzilla.gnome.org/show_bug.cgi?id=622927
This commit is contained in:
Dan Winship 2015-08-10 09:44:13 -04:00
commit 3cf736b9e0
113 changed files with 2434 additions and 2713 deletions

4
.gitignore vendored
View file

@ -31,7 +31,6 @@ cscope.*out
valgrind-*.log valgrind-*.log
test-*.log test-*.log
test-*.trs test-*.trs
*-glue.h
/ABOUT-NLS /ABOUT-NLS
/COPYING /COPYING
@ -156,6 +155,8 @@ test-*.trs
/libnm-core/tests/test-setting-8021x /libnm-core/tests/test-setting-8021x
/libnm-core/tests/test-setting-dcb /libnm-core/tests/test-setting-dcb
/libnm-glib/nm-secret-agent-glue.h
/libnm-glib/nm-vpn-plugin-glue.h
/libnm-glib/libnm-glib-test /libnm-glib/libnm-glib-test
/libnm-glib/tests/test-nm-client /libnm-glib/tests/test-nm-client
/libnm-glib/tests/test-remote-settings-client /libnm-glib/tests/test-remote-settings-client
@ -246,6 +247,7 @@ test-*.trs
/src/rdisc/tests/test-rdisc-fake /src/rdisc/tests/test-rdisc-fake
/src/rdisc/tests/test-rdisc-linux /src/rdisc/tests/test-rdisc-linux
/src/settings/plugins/ibft/tests/test-ibft /src/settings/plugins/ibft/tests/test-ibft
/src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.[ch]
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh /src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils /src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils
/src/settings/plugins/ifnet/tests/test-ifnet /src/settings/plugins/ifnet/tests/test-ifnet

View file

@ -6,8 +6,6 @@ SUBDIRS = \
introspection \ introspection \
libnm-core \ libnm-core \
libnm \ libnm \
libnm-util \
libnm-glib \
src \ src \
callouts \ callouts \
clients \ clients \
@ -15,9 +13,17 @@ SUBDIRS = \
policy \ policy \
data \ data \
po \ po \
docs \
man \ man \
examples \ examples
if WITH_LEGACY_LIBRARIES
SUBDIRS += \
libnm-util \
libnm-glib
endif
SUBDIRS += \
docs \
vapi vapi
@GNOME_CODE_COVERAGE_RULES@ @GNOME_CODE_COVERAGE_RULES@

View file

@ -5,7 +5,6 @@ AM_CPPFLAGS = \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DNETWORKMANAGER_COMPILATION \ -DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
-DNMCONFDIR=\"$(nmconfdir)\" \ -DNMCONFDIR=\"$(nmconfdir)\" \

View file

@ -9,8 +9,7 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \ -DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
-DSRCDIR=\"$(abs_srcdir)\" \ -DSRCDIR=\"$(abs_srcdir)\" \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS)
$(DBUS_CFLAGS)
noinst_PROGRAMS = \ noinst_PROGRAMS = \
test-dispatcher-envp test-dispatcher-envp
@ -23,8 +22,7 @@ test_dispatcher_envp_SOURCES = \
test_dispatcher_envp_LDADD = \ test_dispatcher_envp_LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(top_builddir)/callouts/libtest-dispatcher-envp.la \ $(top_builddir)/callouts/libtest-dispatcher-envp.la \
$(GLIB_LIBS) \ $(GLIB_LIBS)
$(DBUS_LIBS)
########################################### ###########################################

View file

@ -268,25 +268,6 @@ dnl
AC_CHECK_LIB([dl], [dladdr], LIBDL="-ldl", LIBDL="") AC_CHECK_LIB([dl], [dladdr], LIBDL="-ldl", LIBDL="")
AC_SUBST(LIBDL) AC_SUBST(LIBDL)
dnl
dnl Checks for dbus-glib
dnl
PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1 dbus-glib-1 >= 0.94)
AC_CHECK_LIB([dbus-glib-1], [dbus_g_method_invocation_get_g_connection], ac_have_gmi_get_con="1", ac_have_gmi_get_con="0")
AC_DEFINE_UNQUOTED(HAVE_DBUS_GLIB_GMI_GET_CONNECTION, $ac_have_gmi_get_con, [Define if you have a dbus-glib with dbus_g_method_invocation_get_g_connection()])
dnl
dnl Only dbus-glib >= 0.100 can use private dbus connections
dnl
PKG_CHECK_MODULES(DBUS_GLIB_100, [dbus-glib-1 >= 0.100], [have_dbus_glib_100=yes],[have_dbus_glib_100=no])
if (test "${have_dbus_glib_100}" = "yes"); then
AC_DEFINE(HAVE_DBUS_GLIB_100, 1, [Define if you have dbus-glib >= 0.100])
else
AC_DEFINE(HAVE_DBUS_GLIB_100, 0, [Define if you have dbus-glib >= 0.100])
fi
AM_CONDITIONAL(HAVE_DBUS_GLIB_100, test "${have_dbus_glib_100}" = "yes")
PKG_CHECK_MODULES(GLIB, [gio-unix-2.0 >= 2.37.6 gmodule-2.0], PKG_CHECK_MODULES(GLIB, [gio-unix-2.0 >= 2.37.6 gmodule-2.0],
[AC_SUBST(LOG_DRIVER, '$(top_srcdir)/build-aux/tap-driver.sh'), [AC_SUBST(LOG_DRIVER, '$(top_srcdir)/build-aux/tap-driver.sh'),
AC_SUBST(AM_TESTS_FD_REDIRECT, '--tap')], AC_SUBST(AM_TESTS_FD_REDIRECT, '--tap')],
@ -302,6 +283,16 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 -DGLIB_V
AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS) AC_SUBST(GLIB_LIBS)
AC_ARG_WITH(libnm-glib, AS_HELP_STRING([--without-libnm-glib], [don't build legacy libraries]))
if test "$with_libnm_glib" != "no"; then
PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1 dbus-glib-1 >= 0.94, :,
[AC_MSG_FAILURE([$DBUS_PKG_ERRORS
Configure with --without-libnm-glib if you do not need the legacy libraries])])
with_libnm_glib=yes
fi
AM_CONDITIONAL(WITH_LEGACY_LIBRARIES, test "$with_libnm_glib" != "no")
PKG_CHECK_MODULES(GUDEV, gudev-1.0 >= 165) PKG_CHECK_MODULES(GUDEV, gudev-1.0 >= 165)
GOBJECT_INTROSPECTION_CHECK([0.9.6]) GOBJECT_INTROSPECTION_CHECK([0.9.6])
@ -1154,6 +1145,7 @@ echo " ppp: $enable_ppp"
echo " modemmanager-1: $with_modem_manager_1" echo " modemmanager-1: $with_modem_manager_1"
echo " concheck: $enable_concheck" echo " concheck: $enable_concheck"
echo " libteamdctl: $enable_teamdctl" echo " libteamdctl: $enable_teamdctl"
echo " libnm-glib: $with_libnm_glib"
echo " nmtui: $build_nmtui" echo " nmtui: $build_nmtui"
echo echo

View file

@ -1,2 +1,7 @@
SUBDIRS = libnm-glib libnm-util libnm api SUBDIRS = libnm api
if WITH_LEGACY_LIBRARIES
SUBDIRS += \
libnm-util \
libnm-glib
endif

View file

@ -1,10 +1,8 @@
EXTRA_DIST = \ EXTRA_DIST = \
gsystem-local-alloc.h \ gsystem-local-alloc.h \
nm-dbus-compat.h \ nm-dbus-compat.h \
nm-dbus-glib-types.h \
nm-default.h \ nm-default.h \
nm-glib.h \ nm-glib.h \
nm-gvaluearray-compat.h \
nm-test-utils.h \ nm-test-utils.h \
nm-macros-internal.h nm-macros-internal.h

View file

@ -38,9 +38,6 @@
#endif #endif
#include "nm-gvaluearray-compat.h"
static inline void static inline void
__g_type_ensure (GType type) __g_type_ensure (GType type)
{ {
@ -258,4 +255,23 @@ _g_key_file_save_to_file (GKeyFile *key_file,
#endif #endif
#if GLIB_CHECK_VERSION (2, 36, 0)
#define g_credentials_get_unix_pid(creds, error) \
G_GNUC_EXTENSION ({ \
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
(g_credentials_get_unix_pid) ((creds), (error)); \
G_GNUC_END_IGNORE_DEPRECATIONS \
})
#else
#define g_credentials_get_unix_pid(creds, error) \
G_GNUC_EXTENSION ({ \
struct ucred *native_creds; \
\
native_creds = g_credentials_get_native ((creds), G_CREDENTIALS_TYPE_LINUX_UCRED); \
g_assert (native_creds); \
native_creds->pid; \
})
#endif
#endif /* __NM_GLIB_H__ */ #endif /* __NM_GLIB_H__ */

View file

@ -12,6 +12,10 @@
<tp:docstring>Flags describing the access point's capabilities according to the RSN (Robust Secure Network) protocol.</tp:docstring> <tp:docstring>Flags describing the access point's capabilities according to the RSN (Robust Secure Network) protocol.</tp:docstring>
</property> </property>
<property name="Ssid" type="ay" access="read"> <property name="Ssid" type="ay" access="read">
<!-- gdbus-codegen assumes that "ay" means "non-UTF-8 string" and
won't deal with '\0' bytes correctly.
-->
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="1"/>
<tp:docstring>The Service Set Identifier identifying the access point.</tp:docstring> <tp:docstring>The Service Set Identifier identifying the access point.</tp:docstring>
</property> </property>
<property name="Frequency" type="u" access="read"> <property name="Frequency" type="u" access="read">

View file

@ -8,8 +8,6 @@
Called by secret Agents to register their ability to provide and save Called by secret Agents to register their ability to provide and save
network secrets. network secrets.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="identifier" type="s" direction="in"> <arg name="identifier" type="s" direction="in">
<tp:docstring> <tp:docstring>
Identifies this agent; only one agent in each user session may use the Identifies this agent; only one agent in each user session may use the
@ -27,8 +25,6 @@
<tp:docstring> <tp:docstring>
Like Register() but indicates agent capabilities to NetworkManager. Like Register() but indicates agent capabilities to NetworkManager.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register_with_capabilities"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="identifier" type="s" direction="in"> <arg name="identifier" type="s" direction="in">
<tp:docstring> <tp:docstring>
See the Register() method's identifier argument. See the Register() method's identifier argument.
@ -47,8 +43,6 @@
longer handle requests for network secrets. Agents are automatically longer handle requests for network secrets. Agents are automatically
unregistered when they disconnect from D-Bus. unregistered when they disconnect from D-Bus.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_unregister"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method> </method>
</interface> </interface>

View file

@ -5,7 +5,6 @@
<annotation name="org.gtk.GDBus.C.Name" value="DeviceWifi"/> <annotation name="org.gtk.GDBus.C.Name" value="DeviceWifi"/>
<method name="GetAccessPoints"> <method name="GetAccessPoints">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_access_points"/>
<arg name="access_points" type="ao" direction="out"> <arg name="access_points" type="ao" direction="out">
<tp:docstring> <tp:docstring>
List of access point object paths. List of access point object paths.
@ -20,7 +19,6 @@
</method> </method>
<method name="GetAllAccessPoints"> <method name="GetAllAccessPoints">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_all_access_points"/>
<arg name="access_points" type="ao" direction="out"> <arg name="access_points" type="ao" direction="out">
<tp:docstring> <tp:docstring>
List of access point object paths. List of access point object paths.
@ -33,8 +31,6 @@
</method> </method>
<method name="RequestScan"> <method name="RequestScan">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_request_scan"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="options" type="a{sv}" direction="in"> <arg name="options" type="a{sv}" direction="in">
<tp:docstring> <tp:docstring>
Options of scan (currently unused argument). Options of scan (currently unused argument).

View file

@ -3,7 +3,6 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.Device.WiMax"> <interface name="org.freedesktop.NetworkManager.Device.WiMax">
<method name="GetNspList"> <method name="GetNspList">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_nsp_list"/>
<arg name="nsps" type="ao" direction="out"> <arg name="nsps" type="ao" direction="out">
<tp:docstring> <tp:docstring>
List of NSP object paths List of NSP object paths

View file

@ -153,16 +153,12 @@
</property> </property>
<method name="Disconnect"> <method name="Disconnect">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_disconnect"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Disconnects a device and prevents the device from automatically activating further connections without user intervention. Disconnects a device and prevents the device from automatically activating further connections without user intervention.
</tp:docstring> </tp:docstring>
</method> </method>
<method name="Delete"> <method name="Delete">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_delete"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Deletes a software device from NetworkManager and removes the interface from the system. Deletes a software device from NetworkManager and removes the interface from the system.
The method returns an error when called for a hardware device. The method returns an error when called for a hardware device.

View file

@ -35,6 +35,10 @@
</tp:docstring> </tp:docstring>
</property> </property>
<property name="Nameservers" type="aay" access="read"> <property name="Nameservers" type="aay" access="read">
<!-- gdbus-codegen assumes that "aay" means "array of non-UTF-8
string" and so would make this a char **.
-->
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="1"/>
<tp:docstring>The nameservers in use.</tp:docstring> <tp:docstring>The nameservers in use.</tp:docstring>
</property> </property>
<property name="Domains" type="as" access="read"> <property name="Domains" type="as" access="read">

View file

@ -8,7 +8,6 @@
<tp:docstring> <tp:docstring>
Get the list of network devices. Get the list of network devices.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_devices"/>
<arg name="devices" type="ao" direction="out"> <arg name="devices" type="ao" direction="out">
<tp:docstring> <tp:docstring>
List of object paths of network devices known to the system. List of object paths of network devices known to the system.
@ -22,7 +21,6 @@
interface name. Note that some devices (usually modems) only have an interface name. Note that some devices (usually modems) only have an
IP interface name when they are connected. IP interface name when they are connected.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_device_by_ip_iface"/>
<arg name="iface" type="s" direction="in"> <arg name="iface" type="s" direction="in">
<tp:docstring> <tp:docstring>
Interface name of the device to find. Interface name of the device to find.
@ -36,8 +34,6 @@
</method> </method>
<method name="ActivateConnection"> <method name="ActivateConnection">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Activate a connection using the supplied device. Activate a connection using the supplied device.
</tp:docstring> </tp:docstring>
@ -76,8 +72,6 @@
</method> </method>
<method name="AddAndActivateConnection"> <method name="AddAndActivateConnection">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_add_and_activate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Adds a new connection using the given details (if any) as a template Adds a new connection using the given details (if any) as a template
(automatically filling in missing settings with the capabilities of the (automatically filling in missing settings with the capabilities of the
@ -121,8 +115,6 @@
<tp:docstring> <tp:docstring>
Deactivate an active connection. Deactivate an active connection.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_deactivate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="active_connection" type="o" direction="in"> <arg name="active_connection" type="o" direction="in">
<tp:docstring> <tp:docstring>
The currently active connection to deactivate. The currently active connection to deactivate.
@ -131,8 +123,6 @@
</method> </method>
<method name="Sleep"> <method name="Sleep">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_sleep"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Control the NetworkManager daemon's sleep state. When asleep, all Control the NetworkManager daemon's sleep state. When asleep, all
interfaces that it manages are deactivated. When awake, devices are interfaces that it manages are deactivated. When awake, devices are
@ -147,8 +137,6 @@
</method> </method>
<method name="Enable"> <method name="Enable">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_enable"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Control whether overall networking is enabled or disabled. When Control whether overall networking is enabled or disabled. When
disabled, all interfaces that NM manages are deactivated. When enabled, disabled, all interfaces that NM manages are deactivated. When enabled,
@ -165,8 +153,6 @@
</method> </method>
<method name="GetPermissions"> <method name="GetPermissions">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_permissions"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Returns the permissions a caller has for various authenticated operations Returns the permissions a caller has for various authenticated operations
that NetworkManager provides, like Enable/Disable networking, changing that NetworkManager provides, like Enable/Disable networking, changing
@ -193,8 +179,6 @@
</signal> </signal>
<method name="SetLogging"> <method name="SetLogging">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_set_logging"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Set logging verbosity and which operations are logged. Set logging verbosity and which operations are logged.
</tp:docstring> </tp:docstring>
@ -223,7 +207,6 @@
</method> </method>
<method name="GetLogging"> <method name="GetLogging">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_logging"/>
<tp:docstring> <tp:docstring>
Get current logging verbosity level and operations domains. Get current logging verbosity level and operations domains.
</tp:docstring> </tp:docstring>
@ -240,8 +223,6 @@
</method> </method>
<method name="CheckConnectivity"> <method name="CheckConnectivity">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_check_connectivity"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring> <tp:docstring>
Re-check the network connectivity state. Re-check the network connectivity state.
</tp:docstring> </tp:docstring>
@ -257,7 +238,6 @@
The overall networking state as determined by the NetworkManager daemon, The overall networking state as determined by the NetworkManager daemon,
based on the state of network devices under it's management. based on the state of network devices under it's management.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_state"/>
<arg name="state" type="u" direction="out" tp:type="NM_STATE"/> <arg name="state" type="u" direction="out" tp:type="NM_STATE"/>
</method> </method>

View file

@ -5,24 +5,19 @@
<annotation name="org.gtk.GDBus.C.Name" value="PPP_Manager"/> <annotation name="org.gtk.GDBus.C.Name" value="PPP_Manager"/>
<method name="NeedSecrets"> <method name="NeedSecrets">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_need_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="username" type="s" direction="out"/> <arg name="username" type="s" direction="out"/>
<arg name="password" type="s" direction="out"/> <arg name="password" type="s" direction="out"/>
</method> </method>
<method name="SetIp4Config"> <method name="SetIp4Config">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_ip4_config"/>
<arg name="config" type="a{sv}" direction="in"/> <arg name="config" type="a{sv}" direction="in"/>
</method> </method>
<method name="SetIp6Config"> <method name="SetIp6Config">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_ip6_config"/>
<arg name="config" type="a{sv}" direction="in"/> <arg name="config" type="a{sv}" direction="in"/>
</method> </method>
<method name="SetState"> <method name="SetState">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_state"/>
<arg name="state" type="u" direction="in"/> <arg name="state" type="u" direction="in"/>
</method> </method>
</interface> </interface>

View file

@ -15,8 +15,6 @@
stored in persistent storage or sent to a Secret Agent for storage, stored in persistent storage or sent to a Secret Agent for storage,
depending on the flags associated with each secret. depending on the flags associated with each secret.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_update"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="properties" type="a{sa{sv}}" direction="in"> <arg name="properties" type="a{sa{sv}}" direction="in">
<tp:docstring> <tp:docstring>
New connection settings, properties, and (optionally) secrets. New connection settings, properties, and (optionally) secrets.
@ -37,8 +35,6 @@
reloaded from disk (either automatically on file change or reloaded from disk (either automatically on file change or
due to an explicit ReloadConnections call). due to an explicit ReloadConnections call).
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_update_unsaved"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="properties" type="a{sa{sv}}" direction="in"> <arg name="properties" type="a{sa{sv}}" direction="in">
<tp:docstring> <tp:docstring>
New connection settings, properties, and (optionally) secrets. New connection settings, properties, and (optionally) secrets.
@ -50,8 +46,6 @@
<tp:docstring> <tp:docstring>
Delete the connection. Delete the connection.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_delete"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method> </method>
<method name="GetSettings"> <method name="GetSettings">
@ -61,8 +55,6 @@
to the network, as those are often protected. Secrets must to the network, as those are often protected. Secrets must
be requested separately using the GetSecrets() call. be requested separately using the GetSecrets() call.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_get_settings"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="settings" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map"> <arg name="settings" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map">
<tp:docstring> <tp:docstring>
The nested settings maps describing this object. The nested settings maps describing this object.
@ -77,8 +69,6 @@
the requestor's session will be returned. The user will never the requestor's session will be returned. The user will never
be prompted for secrets as a result of this request. be prompted for secrets as a result of this request.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_get_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="setting_name" type="s" direction="in"> <arg name="setting_name" type="s" direction="in">
<tp:docstring> <tp:docstring>
Name of the setting to return secrets for. If empty, all Name of the setting to return secrets for. If empty, all
@ -97,8 +87,6 @@
<tp:docstring> <tp:docstring>
Clear the secrets belonging to this network connection profile. Clear the secrets belonging to this network connection profile.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_clear_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method> </method>
<method name="Save"> <method name="Save">
@ -106,8 +94,6 @@
Saves a "dirty" connection (that had previously been Saves a "dirty" connection (that had previously been
updated with UpdateUnsaved) to persistent storage. updated with UpdateUnsaved) to persistent storage.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_save"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method> </method>
<signal name="Updated"> <signal name="Updated">

View file

@ -10,7 +10,6 @@
<tp:docstring> <tp:docstring>
List the saved network connections known to NetworkManager. List the saved network connections known to NetworkManager.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_list_connections"/>
<arg name="connections" type="ao" direction="out"> <arg name="connections" type="ao" direction="out">
<tp:docstring> <tp:docstring>
List of connections. List of connections.
@ -22,8 +21,6 @@
<tp:docstring> <tp:docstring>
Retrieve the object path of a connection, given that connection's UUID. Retrieve the object path of a connection, given that connection's UUID.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_get_connection_by_uuid"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="uuid" type="s" direction="in"> <arg name="uuid" type="s" direction="in">
<tp:docstring> <tp:docstring>
The UUID to find the connection object path for. The UUID to find the connection object path for.
@ -43,8 +40,6 @@
the network described by the new connection, and (2) the connection the network described by the new connection, and (2) the connection
is allowed to be started automatically. is allowed to be started automatically.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_add_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in"> <arg name="connection" type="a{sa{sv}}" direction="in">
<tp:docstring> <tp:docstring>
Connection settings and properties. Connection settings and properties.
@ -69,8 +64,6 @@
connection is reloaded from disk (either automatically on file connection is reloaded from disk (either automatically on file
change or due to an explicit ReloadConnections call). change or due to an explicit ReloadConnections call).
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_add_connection_unsaved"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in"> <arg name="connection" type="a{sa{sv}}" direction="in">
<tp:docstring> <tp:docstring>
Connection settings and properties. Connection settings and properties.
@ -93,8 +86,6 @@
harmless.) As with AddConnection(), this operation does not harmless.) As with AddConnection(), this operation does not
necessarily start the network connection. necessarily start the network connection.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_load_connections"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="filenames" type="as" direction="in"> <arg name="filenames" type="as" direction="in">
<tp:docstring> <tp:docstring>
Array of paths to on-disk connection profiles in directories Array of paths to on-disk connection profiles in directories
@ -125,8 +116,6 @@
change, so you only need to use this command if you have set change, so you only need to use this command if you have set
"monitor-connection-files=false" in NetworkManager.conf. "monitor-connection-files=false" in NetworkManager.conf.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_reload_connections"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="status" type="b" direction="out"> <arg name="status" type="b" direction="out">
<tp:docstring> <tp:docstring>
Success or failure. Success or failure.
@ -138,8 +127,6 @@
<tp:docstring> <tp:docstring>
Save the hostname to persistent configuration. Save the hostname to persistent configuration.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_save_hostname"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="hostname" type="s" direction="in"> <arg name="hostname" type="s" direction="in">
<tp:docstring> <tp:docstring>
The hostname to save to persistent configuration. If blank, the persistent hostname is cleared. The hostname to save to persistent configuration. If blank, the persistent hostname is cleared.

View file

@ -62,9 +62,11 @@ nodist_libnm_util_include_HEADERS = \
libnm_util_la_private_headers = \ libnm_util_la_private_headers = \
crypto.h \ crypto.h \
nm-dbus-glib-types.h \
nm-gvaluearray-compat.h \
nm-param-spec-specialized.h \ nm-param-spec-specialized.h \
nm-utils-private.h \ nm-setting-private.h \
nm-setting-private.h nm-utils-private.h
libnm_util_la_csources = \ libnm_util_la_csources = \
crypto.c \ crypto.c \

View file

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "nm-default.h" #include "nm-default.h"
#include "nm-gvaluearray-compat.h"
#include "nm-param-spec-specialized.h" #include "nm-param-spec-specialized.h"
struct _NMParamSpecSpecialized { struct _NMParamSpecSpecialized {

View file

@ -30,6 +30,7 @@
#include <gmodule.h> #include <gmodule.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-gvaluearray-compat.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h" #include "nm-utils-private.h"
#include "nm-dbus-glib-types.h" #include "nm-dbus-glib-types.h"

View file

@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-gvaluearray-compat.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h" #include "nm-utils-private.h"
#include "nm-dbus-glib-types.h" #include "nm-dbus-glib-types.h"

View file

@ -30,6 +30,7 @@
#include <nm-utils.h> #include <nm-utils.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-gvaluearray-compat.h"
#include "nm-setting-private.h" #include "nm-setting-private.h"
#include "nm-setting-connection.h" #include "nm-setting-connection.h"

View file

@ -33,6 +33,7 @@ endif
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-I$(top_srcdir)/include \ -I$(top_srcdir)/include \
-I$(top_builddir)/introspection \
-I$(top_srcdir)/libnm-core \ -I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \ -I$(top_builddir)/libnm-core \
-I$(top_srcdir)/callouts \ -I$(top_srcdir)/callouts \
@ -190,7 +191,7 @@ nm_dhcp_client_headers = \
dhcp-manager/nm-dhcp-dhcpcd.h \ dhcp-manager/nm-dhcp-dhcpcd.h \
dhcp-manager/nm-dhcp-systemd.h dhcp-manager/nm-dhcp-systemd.h
nm_sources = \ libNetworkManager_la_SOURCES = \
$(nm_device_headers) \ $(nm_device_headers) \
$(nm_dhcp_client_headers) \ $(nm_dhcp_client_headers) \
devices/nm-device.c \ devices/nm-device.c \
@ -362,14 +363,14 @@ nm_sources = \
if SUSPEND_RESUME_UPOWER if SUSPEND_RESUME_UPOWER
nm_sources += nm-sleep-monitor-upower.c libNetworkManager_la_SOURCES += nm-sleep-monitor-upower.c
else else
# systemd/consolekit suspend/resume used whenever upower is not enabled # systemd/consolekit suspend/resume used whenever upower is not enabled
nm_sources += nm-sleep-monitor-systemd.c libNetworkManager_la_SOURCES += nm-sleep-monitor-systemd.c
endif endif
if WITH_WEXT if WITH_WEXT
nm_sources += \ libNetworkManager_la_SOURCES += \
platform/wifi/wifi-utils-wext.c \ platform/wifi/wifi-utils-wext.c \
platform/wifi/wifi-utils-wext.h platform/wifi/wifi-utils-wext.h
endif endif
@ -378,45 +379,11 @@ endif
GLIB_GENERATED = nm-enum-types.h nm-enum-types.c GLIB_GENERATED = nm-enum-types.h nm-enum-types.c
GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include <nm-core-enum-types.h>\n' GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include <nm-core-enum-types.h>\n'
GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
nm_enum_types_sources = $(nm_sources) nm_enum_types_sources = $(libNetworkManager_la_SOURCES)
BUILT_SOURCES = $(GLIB_GENERATED) BUILT_SOURCES = $(GLIB_GENERATED)
glue_sources = \
nm-access-point-glue.h \
nm-active-connection-glue.h \
nm-agent-manager-glue.h \
nm-device-bond-glue.h \
nm-device-bridge-glue.h \
nm-device-ethernet-glue.h \
nm-device-generic-glue.h \
nm-device-glue.h \
nm-device-gre-glue.h \
nm-device-infiniband-glue.h \
nm-device-macvlan-glue.h \
nm-device-tun-glue.h \
nm-device-veth-glue.h \
nm-device-vlan-glue.h \
nm-device-vxlan-glue.h \
nm-dhcp4-config-glue.h \
nm-dhcp6-config-glue.h \
nm-ip4-config-glue.h \
nm-ip6-config-glue.h \
nm-manager-glue.h \
nm-ppp-manager-glue.h \
nm-settings-connection-glue.h \
nm-settings-glue.h \
nm-vpn-connection-glue.h
BUILT_SOURCES += $(glue_sources)
%-glue.h: $(top_srcdir)/introspection/%.xml
$(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $<
AM_CPPFLAGS += \ AM_CPPFLAGS += \
$(DBUS_CFLAGS) \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(GUDEV_CFLAGS) \ $(GUDEV_CFLAGS) \
$(LIBNL_CFLAGS) \ $(LIBNL_CFLAGS) \
@ -450,14 +417,10 @@ AM_CPPFLAGS += \
\ \
$(NULL) $(NULL)
libNetworkManager_la_SOURCES = \
$(nm_sources) \
$(glue_sources)
libNetworkManager_la_LIBADD = \ libNetworkManager_la_LIBADD = \
$(top_builddir)/libnm-core/libnm-core.la \ $(top_builddir)/libnm-core/libnm-core.la \
$(top_builddir)/introspection/libnmdbus.la \
libsystemd-nm.la \ libsystemd-nm.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(GUDEV_LIBS) \ $(GUDEV_LIBS) \
$(LIBNL_LIBS) \ $(LIBNL_LIBS) \
@ -533,8 +496,8 @@ endif
libnm_iface_helper_la_LIBADD = \ libnm_iface_helper_la_LIBADD = \
$(top_builddir)/libnm-core/libnm-core.la \ $(top_builddir)/libnm-core/libnm-core.la \
$(top_builddir)/introspection/libnmdbus.la \
libsystemd-nm.la \ libsystemd-nm.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(GUDEV_LIBS) \ $(GUDEV_LIBS) \
$(LIBNL_LIBS) \ $(LIBNL_LIBS) \
@ -555,7 +518,6 @@ nm_iface_helper_LDADD = \
$(top_builddir)/libnm-core/libnm-core.la \ $(top_builddir)/libnm-core/libnm-core.la \
libsystemd-nm.la \ libsystemd-nm.la \
libnm-iface-helper.la \ libnm-iface-helper.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(GUDEV_LIBS) \ $(GUDEV_LIBS) \
$(SYSTEMD_JOURNAL_LIBS) \ $(SYSTEMD_JOURNAL_LIBS) \
@ -582,8 +544,4 @@ install-data-hook:
$(mkinstalldirs) -m 0755 $(DESTDIR)$(pkglibdir) $(mkinstalldirs) -m 0755 $(DESTDIR)$(pkglibdir)
CLEANFILES = \ CLEANFILES = \
$(BUILT_SOURCES) \ $(BUILT_SOURCES)
settings/*-glue.h \
devices/*-glue.h \
devices/*/*-glue.h

View file

@ -44,7 +44,6 @@
#include "nm-setting-wireless.h" #include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h" #include "nm-setting-wireless-security.h"
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-dbus-glib-types.h"
/* /*
* Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export * Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export
@ -2890,47 +2889,6 @@ nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid,
memcpy (iid, addr->s6_addr + 8, 8); memcpy (iid, addr->s6_addr + 8, 8);
} }
/**
* nm_utils_connection_hash_to_dict:
* @hash: a hashed #NMConnection
*
* Returns: a (floating) #GVariant equivalent to @hash.
*/
GVariant *
nm_utils_connection_hash_to_dict (GHashTable *hash)
{
GValue val = { 0, };
GVariant *variant;
if (!hash)
return NULL;
g_value_init (&val, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT);
g_value_set_boxed (&val, hash);
variant = dbus_g_value_build_g_variant (&val);
g_value_unset (&val);
return variant;
}
/**
* nm_utils_connection_dict_to_hash:
* @dict: a #GVariant-serialized #NMConnection
*
* Returns: a #GHashTable equivalent to @dict.
*/
GHashTable *
nm_utils_connection_dict_to_hash (GVariant *dict)
{
GValue val = { 0, };
if (!dict)
return NULL;
dbus_g_value_parse_g_variant (dict, &val);
return g_value_get_boxed (&val);
}
/** /**
* nm_utils_setpgid: * nm_utils_setpgid:
* @unused: unused * @unused: unused
@ -2963,9 +2921,9 @@ nm_utils_g_value_set_object_path (GValue *value, gpointer object)
g_return_if_fail (!object || NM_IS_EXPORTED_OBJECT (object)); g_return_if_fail (!object || NM_IS_EXPORTED_OBJECT (object));
if (object && nm_exported_object_is_exported (object)) if (object && nm_exported_object_is_exported (object))
g_value_set_boxed (value, nm_exported_object_get_path (object)); g_value_set_string (value, nm_exported_object_get_path (object));
else else
g_value_set_boxed (value, "/"); g_value_set_string (value, "/");
} }
/** /**
@ -2989,5 +2947,27 @@ nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects)
continue; continue;
g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (object))); g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (object)));
} }
g_value_take_boxed (value, paths); g_ptr_array_add (paths, NULL);
g_value_take_boxed (value, (char **) g_ptr_array_free (paths, FALSE));
}
/**
* nm_utils_g_value_set_strv:
* @value: a #GValue, initialized to store a #G_TYPE_STRV
* @strings: a #GPtrArray of strings
*
* Converts @strings to a #GStrv and stores it in @value.
*/
void
nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings)
{
char **strv;
int i;
strv = g_new (char *, strings->len + 1);
for (i = 0; i < strings->len; i++)
strv[i] = g_strdup (strings->pdata[i]);
strv[i] = NULL;
g_value_take_boxed (value, strv);
} }

View file

@ -224,9 +224,6 @@ void nm_utils_ipv6_addr_set_interface_identfier (struct in6_addr *addr,
void nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid, void nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid,
const struct in6_addr *addr); const struct in6_addr *addr);
GVariant *nm_utils_connection_hash_to_dict (GHashTable *hash);
GHashTable *nm_utils_connection_dict_to_hash (GVariant *dict);
void nm_utils_array_remove_at_indexes (GArray *array, const guint *indexes_to_delete, gsize len); void nm_utils_array_remove_at_indexes (GArray *array, const guint *indexes_to_delete, gsize len);
void nm_utils_setpgid (gpointer unused); void nm_utils_setpgid (gpointer unused);
@ -253,5 +250,6 @@ void _nm_utils_set_testing (NMUtilsTestFlags flags);
void nm_utils_g_value_set_object_path (GValue *value, gpointer object); void nm_utils_g_value_set_object_path (GValue *value, gpointer object);
void nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects); void nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects);
void nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings);
#endif /* __NETWORKMANAGER_UTILS_H__ */ #endif /* __NETWORKMANAGER_UTILS_H__ */

View file

@ -7,13 +7,13 @@ AM_CPPFLAGS = \
-I${top_builddir}/src \ -I${top_builddir}/src \
-I${top_srcdir}/src/devices \ -I${top_srcdir}/src/devices \
-I${top_srcdir}/src/platform \ -I${top_srcdir}/src/platform \
-I${top_builddir}/introspection \
-I${top_srcdir}/include \ -I${top_srcdir}/include \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \ -DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(DBUS_CFLAGS) \
$(GUDEV_CFLAGS) $(GUDEV_CFLAGS)
GLIB_GENERATED = nm-adsl-enum-types.h nm-adsl-enum-types.c GLIB_GENERATED = nm-adsl-enum-types.h nm-adsl-enum-types.c
@ -21,10 +21,7 @@ GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM
GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
nm_adsl_enum_types_sources = $(srcdir)/nm-device-adsl.h nm_adsl_enum_types_sources = $(srcdir)/nm-device-adsl.h
nm-device-adsl-glue.h: $(top_srcdir)/introspection/nm-device-adsl.xml BUILT_SOURCES = $(GLIB_GENERATED)
dbus-binding-tool --prefix=nm_device_adsl --mode=glib-server --output=$@ $<
BUILT_SOURCES = $(GLIB_GENERATED) nm-device-adsl-glue.h
pkglib_LTLIBRARIES = libnm-device-plugin-adsl.la pkglib_LTLIBRARIES = libnm-device-plugin-adsl.la
@ -43,7 +40,7 @@ libnm_device_plugin_adsl_la_LDFLAGS = \
-Wl,--version-script=$(SYMBOL_VIS_FILE) -Wl,--version-script=$(SYMBOL_VIS_FILE)
libnm_device_plugin_adsl_la_LIBADD = \ libnm_device_plugin_adsl_la_LIBADD = \
$(DBUS_LIBS) \ $(top_builddir)/introspection/libnmdbus.la \
$(GUDEV_LIBS) $(GUDEV_LIBS)
CLEANFILES = $(BUILT_SOURCES) CLEANFILES = $(BUILT_SOURCES)

View file

@ -43,7 +43,7 @@
#include "nm-setting-adsl.h" #include "nm-setting-adsl.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-device-adsl-glue.h" #include "nmdbus-device-adsl.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF (NMDeviceAdsl); _LOG_DECLARE_SELF (NMDeviceAdsl);
@ -613,5 +613,6 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass)
parent_class->deactivate = deactivate; parent_class->deactivate = deactivate;
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_adsl_object_info); NMDBUS_TYPE_DEVICE_ADSL_SKELETON,
NULL);
} }

View file

@ -9,23 +9,21 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/settings \ -I${top_srcdir}/src/settings \
-I${top_srcdir}/src/platform \ -I${top_srcdir}/src/platform \
-I${top_srcdir}/src/devices/wwan \ -I${top_srcdir}/src/devices/wwan \
-I${top_builddir}/introspection \
-I${top_srcdir}/include \ -I${top_srcdir}/include \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \ -DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(DBUS_CFLAGS) $(GLIB_CFLAGS)
GLIB_GENERATED = nm-bt-enum-types.h nm-bt-enum-types.c GLIB_GENERATED = nm-bt-enum-types.h nm-bt-enum-types.c
GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM
GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
nm_bt_enum_types_sources = $(srcdir)/nm-bt-error.h nm_bt_enum_types_sources = $(srcdir)/nm-bt-error.h
nm-device-bt-glue.h: $(top_srcdir)/introspection/nm-device-bt.xml BUILT_SOURCES = $(GLIB_GENERATED)
dbus-binding-tool --prefix=nm_device_bt --mode=glib-server --output=$@ $<
BUILT_SOURCES = $(GLIB_GENERATED) nm-device-bt-glue.h
pkglib_LTLIBRARIES = libnm-device-plugin-bluetooth.la pkglib_LTLIBRARIES = libnm-device-plugin-bluetooth.la
@ -56,8 +54,9 @@ libnm_device_plugin_bluetooth_la_LDFLAGS = \
-Wl,--version-script=$(SYMBOL_VIS_FILE) -Wl,--version-script=$(SYMBOL_VIS_FILE)
libnm_device_plugin_bluetooth_la_LIBADD = \ libnm_device_plugin_bluetooth_la_LIBADD = \
$(top_builddir)/introspection/libnmdbus.la \
$(top_builddir)/src/devices/wwan/libnm-wwan.la \ $(top_builddir)/src/devices/wwan/libnm-wwan.la \
$(DBUS_LIBS) \ $(GLIB_LIBS) \
$(GUDEV_LIBS) $(GUDEV_LIBS)
if WITH_BLUEZ5_DUN if WITH_BLUEZ5_DUN

View file

@ -37,6 +37,7 @@
#include "nm-device-bt.h" #include "nm-device-bt.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-dbus-compat.h"
typedef struct { typedef struct {
int bluez_version; int bluez_version;

View file

@ -35,13 +35,14 @@
#include "nm-setting-gsm.h" #include "nm-setting-gsm.h"
#include "nm-setting-serial.h" #include "nm-setting-serial.h"
#include "nm-setting-ppp.h" #include "nm-setting-ppp.h"
#include "nm-device-bt-glue.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-bt-enum-types.h" #include "nm-bt-enum-types.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-bt-error.h" #include "nm-bt-error.h"
#include "nm-bt-enum-types.h" #include "nm-bt-enum-types.h"
#include "nmdbus-device-bt.h"
#define MM_DBUS_SERVICE "org.freedesktop.ModemManager1" #define MM_DBUS_SERVICE "org.freedesktop.ModemManager1"
#define MM_DBUS_PATH "/org/freedesktop/ModemManager1" #define MM_DBUS_PATH "/org/freedesktop/ModemManager1"
#define MM_DBUS_INTERFACE "org.freedesktop.ModemManager1" #define MM_DBUS_INTERFACE "org.freedesktop.ModemManager1"
@ -1194,5 +1195,6 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
G_TYPE_UINT, G_TYPE_UINT); G_TYPE_UINT, G_TYPE_UINT);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_bt_object_info); NMDBUS_TYPE_DEVICE_BLUETOOTH_SKELETON,
NULL);
} }

View file

@ -28,13 +28,12 @@
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-device-private.h" #include "nm-device-private.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-dbus-glib-types.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-ip4-config.h" #include "nm-ip4-config.h"
#include "nm-device-bond-glue.h" #include "nmdbus-device-bond.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceBond); _LOG_DECLARE_SELF(NMDeviceBond);
@ -556,12 +555,13 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_SLAVES, (object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "", g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_bond_object_info); NMDBUS_TYPE_DEVICE_BOND_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -26,13 +26,12 @@
#include "nm-device-bridge.h" #include "nm-device-bridge.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-device-private.h" #include "nm-device-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-bridge-glue.h" #include "nmdbus-device-bridge.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceBridge); _LOG_DECLARE_SELF(NMDeviceBridge);
@ -501,12 +500,13 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_SLAVES, (object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "", g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_bridge_object_info); NMDBUS_TYPE_DEVICE_BRIDGE_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -50,7 +50,7 @@
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-device-ethernet-glue.h" #include "nmdbus-device-ethernet.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceEthernet); _LOG_DECLARE_SELF(NMDeviceEthernet);
@ -1712,7 +1712,8 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_ethernet_object_info); NMDBUS_TYPE_DEVICE_ETHERNET_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -26,7 +26,7 @@
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-generic-glue.h" #include "nmdbus-device-generic.h"
G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
@ -202,5 +202,6 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_generic_object_info); NMDBUS_TYPE_DEVICE_GENERIC_SKELETON,
NULL);
} }

View file

@ -31,7 +31,7 @@
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-gre-glue.h" #include "nmdbus-device-gre.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceGre); _LOG_DECLARE_SELF(NMDeviceGre);
@ -187,10 +187,10 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_PARENT, (object_class, PROP_PARENT,
g_param_spec_boxed (NM_DEVICE_GRE_PARENT, "", "", g_param_spec_string (NM_DEVICE_GRE_PARENT, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_INPUT_FLAGS, (object_class, PROP_INPUT_FLAGS,
@ -256,7 +256,8 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_gre_object_info); NMDBUS_TYPE_DEVICE_GRE_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -33,7 +33,7 @@
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-infiniband-glue.h" #include "nmdbus-device-infiniband.h"
G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE)
@ -350,7 +350,8 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_infiniband_object_info); NMDBUS_TYPE_DEVICE_INFINIBAND_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -29,7 +29,7 @@
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-device-macvlan-glue.h" #include "nmdbus-device-macvlan.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceMacvlan); _LOG_DECLARE_SELF(NMDeviceMacvlan);
@ -144,10 +144,10 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_PARENT, (object_class, PROP_PARENT,
g_param_spec_boxed (NM_DEVICE_MACVLAN_PARENT, "", "", g_param_spec_string (NM_DEVICE_MACVLAN_PARENT, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_MODE, (object_class, PROP_MODE,
@ -164,7 +164,8 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_macvlan_object_info); NMDBUS_TYPE_DEVICE_MACVLAN_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -29,7 +29,7 @@
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-device-tun-glue.h" #include "nmdbus-device-tun.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceTun); _LOG_DECLARE_SELF(NMDeviceTun);
@ -232,7 +232,8 @@ nm_device_tun_class_init (NMDeviceTunClass *klass)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_tun_object_info); NMDBUS_TYPE_DEVICE_TUN_SKELETON,
NULL);
} }

View file

@ -34,7 +34,7 @@
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-device-veth-glue.h" #include "nmdbus-device-veth.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceVeth); _LOG_DECLARE_SELF(NMDeviceVeth);
@ -160,13 +160,14 @@ nm_device_veth_class_init (NMDeviceVethClass *klass)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_PEER, (object_class, PROP_PEER,
g_param_spec_boxed (NM_DEVICE_VETH_PEER, "", "", g_param_spec_string (NM_DEVICE_VETH_PEER, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_veth_object_info); NMDBUS_TYPE_DEVICE_VETH_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -37,7 +37,7 @@
#include "nm-manager.h" #include "nm-manager.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-vlan-glue.h" #include "nmdbus-device-vlan.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceVlan); _LOG_DECLARE_SELF(NMDeviceVlan);
@ -617,10 +617,10 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_PARENT, (object_class, PROP_PARENT,
g_param_spec_boxed (NM_DEVICE_VLAN_PARENT, "", "", g_param_spec_string (NM_DEVICE_VLAN_PARENT, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_VLAN_ID, (object_class, PROP_VLAN_ID,
g_param_spec_uint (NM_DEVICE_VLAN_ID, "", "", g_param_spec_uint (NM_DEVICE_VLAN_ID, "", "",
@ -628,7 +628,8 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_vlan_object_info); NMDBUS_TYPE_DEVICE_VLAN_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -30,7 +30,7 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-device-vxlan-glue.h" #include "nmdbus-device-vxlan.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceVxlan); _LOG_DECLARE_SELF(NMDeviceVxlan);
@ -234,10 +234,10 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_PARENT, (object_class, PROP_PARENT,
g_param_spec_boxed (NM_DEVICE_VXLAN_PARENT, "", "", g_param_spec_string (NM_DEVICE_VXLAN_PARENT, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_ID, (object_class, PROP_ID,
@ -345,7 +345,8 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_vxlan_object_info); NMDBUS_TYPE_DEVICE_VXLAN_SKELETON,
NULL);
} }
/*************************************************************/ /*************************************************************/

View file

@ -21,7 +21,6 @@
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -55,7 +54,6 @@
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-connection-provider.h" #include "nm-connection-provider.h"
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-dispatcher.h" #include "nm-dispatcher.h"
#include "nm-config.h" #include "nm-config.h"
#include "nm-dns-manager.h" #include "nm-dns-manager.h"
@ -68,13 +66,11 @@
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF (NMDevice); _LOG_DECLARE_SELF (NMDevice);
static void impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context); #include "nmdbus-device.h"
static void impl_device_delete (NMDevice *self, DBusGMethodInvocation *context);
static void nm_device_update_metered (NMDevice *self); static void nm_device_update_metered (NMDevice *self);
static void ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data); static void ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data);
#include "nm-device-glue.h"
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT)
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
@ -6178,7 +6174,7 @@ delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex)
static void static void
disconnect_cb (NMDevice *self, disconnect_cb (NMDevice *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
@ -6187,7 +6183,7 @@ disconnect_cb (NMDevice *self,
GError *local = NULL; GError *local = NULL;
if (error) { if (error) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, error->message); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, error->message);
return; return;
} }
@ -6197,16 +6193,15 @@ disconnect_cb (NMDevice *self,
local = g_error_new_literal (NM_DEVICE_ERROR, local = g_error_new_literal (NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ACTIVE, NM_DEVICE_ERROR_NOT_ACTIVE,
"Device is not active"); "Device is not active");
dbus_g_method_return_error (context, local);
nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, local->message); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, local->message);
g_error_free (local); g_dbus_method_invocation_take_error (context, local);
} else { } else {
nm_device_set_autoconnect (self, FALSE); nm_device_set_autoconnect (self, FALSE);
nm_device_state_changed (self, nm_device_state_changed (self,
NM_DEVICE_STATE_DEACTIVATING, NM_DEVICE_STATE_DEACTIVATING,
NM_DEVICE_STATE_REASON_USER_REQUESTED); NM_DEVICE_STATE_REASON_USER_REQUESTED);
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, TRUE, subject, NULL); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, TRUE, subject, NULL);
} }
} }
@ -6221,7 +6216,7 @@ _clear_queued_act_request (NMDevicePrivate *priv)
} }
static void static void
impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) impl_device_disconnect (NMDevice *self, GDBusMethodInvocation *context)
{ {
NMConnection *connection; NMConnection *connection;
GError *error = NULL; GError *error = NULL;
@ -6230,8 +6225,7 @@ impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context)
error = g_error_new_literal (NM_DEVICE_ERROR, error = g_error_new_literal (NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ACTIVE, NM_DEVICE_ERROR_NOT_ACTIVE,
"This device is not active"); "This device is not active");
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
return; return;
} }
@ -6250,25 +6244,25 @@ impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context)
static void static void
delete_cb (NMDevice *self, delete_cb (NMDevice *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
if (error) { if (error) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, FALSE, subject, error->message); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, FALSE, subject, error->message);
return; return;
} }
/* Authorized */ /* Authorized */
nm_platform_link_delete (NM_PLATFORM_GET, nm_device_get_ifindex (self)); nm_platform_link_delete (NM_PLATFORM_GET, nm_device_get_ifindex (self));
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, TRUE, subject, NULL); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, TRUE, subject, NULL);
} }
static void static void
impl_device_delete (NMDevice *self, DBusGMethodInvocation *context) impl_device_delete (NMDevice *self, GDBusMethodInvocation *context)
{ {
GError *error = NULL; GError *error = NULL;
@ -6276,8 +6270,7 @@ impl_device_delete (NMDevice *self, DBusGMethodInvocation *context)
error = g_error_new_literal (NM_DEVICE_ERROR, error = g_error_new_literal (NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_SOFTWARE, NM_DEVICE_ERROR_NOT_SOFTWARE,
"This device is not a software device"); "This device is not a software device");
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
return; return;
} }
@ -9311,8 +9304,6 @@ set_property (GObject *object, guint prop_id,
} }
} }
#define DBUS_TYPE_STATE_REASON_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID))
static void static void
get_property (GObject *object, guint prop_id, get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) GValue *value, GParamSpec *pspec)
@ -9376,8 +9367,8 @@ get_property (GObject *object, guint prop_id,
g_value_set_uint (value, priv->state); g_value_set_uint (value, priv->state);
break; break;
case PROP_STATE_REASON: case PROP_STATE_REASON:
g_value_take_boxed (value, dbus_g_type_specialized_construct (DBUS_TYPE_STATE_REASON_STRUCT)); g_value_take_variant (value,
dbus_g_type_struct_set (value, 0, priv->state, 1, priv->state_reason, G_MAXUINT); g_variant_new ("(uu)", priv->state, priv->state_reason));
break; break;
case PROP_ACTIVE_CONNECTION: case PROP_ACTIVE_CONNECTION:
nm_utils_g_value_set_object_path (value, priv->act_request); nm_utils_g_value_set_object_path (value, priv->act_request);
@ -9408,7 +9399,8 @@ get_property (GObject *object, guint prop_id,
g_hash_table_iter_init (&iter, priv->available_connections); g_hash_table_iter_init (&iter, priv->available_connections);
while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL))
g_ptr_array_add (array, g_strdup (nm_connection_get_path (connection))); g_ptr_array_add (array, g_strdup (nm_connection_get_path (connection)));
g_value_take_boxed (value, array); g_ptr_array_add (array, NULL);
g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE));
break; break;
case PROP_PHYSICAL_PORT_ID: case PROP_PHYSICAL_PORT_ID:
g_value_set_string (value, priv->physical_port_id); g_value_set_string (value, priv->physical_port_id);
@ -9548,31 +9540,31 @@ nm_device_class_init (NMDeviceClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_IP4_CONFIG, (object_class, PROP_IP4_CONFIG,
g_param_spec_boxed (NM_DEVICE_IP4_CONFIG, "", "", g_param_spec_string (NM_DEVICE_IP4_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DHCP4_CONFIG, (object_class, PROP_DHCP4_CONFIG,
g_param_spec_boxed (NM_DEVICE_DHCP4_CONFIG, "", "", g_param_spec_string (NM_DEVICE_DHCP4_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_IP6_CONFIG, (object_class, PROP_IP6_CONFIG,
g_param_spec_boxed (NM_DEVICE_IP6_CONFIG, "", "", g_param_spec_string (NM_DEVICE_IP6_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DHCP6_CONFIG, (object_class, PROP_DHCP6_CONFIG,
g_param_spec_boxed (NM_DEVICE_DHCP6_CONFIG, "", "", g_param_spec_string (NM_DEVICE_DHCP6_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_STATE, (object_class, PROP_STATE,
@ -9583,17 +9575,18 @@ nm_device_class_init (NMDeviceClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_STATE_REASON, (object_class, PROP_STATE_REASON,
g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "", g_param_spec_variant (NM_DEVICE_STATE_REASON, "", "",
DBUS_TYPE_STATE_REASON_STRUCT, G_VARIANT_TYPE ("(uu)"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_ACTIVE_CONNECTION, (object_class, PROP_ACTIVE_CONNECTION,
g_param_spec_boxed (NM_DEVICE_ACTIVE_CONNECTION, "", "", g_param_spec_string (NM_DEVICE_ACTIVE_CONNECTION, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DEVICE_TYPE, (object_class, PROP_DEVICE_TYPE,
@ -9656,7 +9649,7 @@ nm_device_class_init (NMDeviceClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_AVAILABLE_CONNECTIONS, (object_class, PROP_AVAILABLE_CONNECTIONS,
g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "", g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
@ -9732,8 +9725,8 @@ nm_device_class_init (NMDeviceClass *klass)
G_OBJECT_CLASS_TYPE (object_class), G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, 0, NULL, NULL, NULL,
/* dbus-glib context, connection, permission, allow_interaction, callback, user_data */ /* context, connection, permission, allow_interaction, callback, user_data */
G_TYPE_NONE, 6, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 6, G_TYPE_DBUS_METHOD_INVOCATION, NM_TYPE_CONNECTION, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER);
signals[IP4_CONFIG_CHANGED] = signals[IP4_CONFIG_CHANGED] =
g_signal_new (NM_DEVICE_IP4_CONFIG_CHANGED, g_signal_new (NM_DEVICE_IP4_CONFIG_CHANGED,
@ -9771,7 +9764,8 @@ nm_device_class_init (NMDeviceClass *klass)
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_object_info); NMDBUS_TYPE_DEVICE_SKELETON,
"Disconnect", impl_device_disconnect,
dbus_g_error_domain_register (NM_DEVICE_ERROR, NULL, NM_TYPE_DEVICE_ERROR); "Delete", impl_device_delete,
NULL);
} }

View file

@ -22,7 +22,6 @@
#ifndef __NETWORKMANAGER_DEVICE_H__ #ifndef __NETWORKMANAGER_DEVICE_H__
#define __NETWORKMANAGER_DEVICE_H__ #define __NETWORKMANAGER_DEVICE_H__
#include <dbus/dbus-glib.h>
#include <netinet/in.h> #include <netinet/in.h>
#include "nm-exported-object.h" #include "nm-exported-object.h"
@ -310,7 +309,7 @@ typedef struct {
} NMDeviceClass; } NMDeviceClass;
typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device, typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer user_data); gpointer user_data);

View file

@ -7,13 +7,14 @@ AM_CPPFLAGS = \
-I${top_builddir}/src \ -I${top_builddir}/src \
-I${top_srcdir}/src/devices \ -I${top_srcdir}/src/devices \
-I${top_srcdir}/src/platform \ -I${top_srcdir}/src/platform \
-I${top_builddir}/introspection \
-I${top_srcdir}/include \ -I${top_srcdir}/include \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-team"\" \ -DG_LOG_DOMAIN=\""NetworkManager-team"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(DBUS_CFLAGS) $(GLIB_CFLAGS)
if WITH_TEAMDCTL if WITH_TEAMDCTL
AM_CPPFLAGS += ${LIBTEAMDCTL_CFLAGS} AM_CPPFLAGS += ${LIBTEAMDCTL_CFLAGS}
@ -24,13 +25,7 @@ GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM
GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
nm_team_enum_types_sources = $(srcdir)/nm-device-team.h nm_team_enum_types_sources = $(srcdir)/nm-device-team.h
glue_sources = \ BUILT_SOURCES = $(GLIB_GENERATED)
nm-device-team-glue.h
%-glue.h: $(top_srcdir)/introspection/%.xml
$(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $<
BUILT_SOURCES = $(GLIB_GENERATED) $(glue_sources)
pkglib_LTLIBRARIES = libnm-device-plugin-team.la pkglib_LTLIBRARIES = libnm-device-plugin-team.la
@ -49,7 +44,8 @@ libnm_device_plugin_team_la_LDFLAGS = \
-Wl,--version-script=$(SYMBOL_VIS_FILE) -Wl,--version-script=$(SYMBOL_VIS_FILE)
libnm_device_plugin_team_la_LIBADD = \ libnm_device_plugin_team_la_LIBADD = \
$(DBUS_LIBS) \ $(top_builddir)/introspection/libnmdbus.la \
$(GLIB_LIBS) \
$(GUDEV_LIBS) $(GUDEV_LIBS)
if WITH_TEAMDCTL if WITH_TEAMDCTL

View file

@ -32,12 +32,12 @@
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-device-private.h" #include "nm-device-private.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-dbus-glib-types.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-team-enum-types.h" #include "nm-team-enum-types.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-dbus-compat.h"
#include "nm-device-team-glue.h" #include "nmdbus-device-team.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceTeam); _LOG_DECLARE_SELF(NMDeviceTeam);
@ -809,11 +809,12 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_SLAVES, (object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "", g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_team_object_info); NMDBUS_TYPE_DEVICE_TEAM_SKELETON,
NULL);
} }

View file

@ -13,13 +13,14 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/settings \ -I${top_srcdir}/src/settings \
-I${top_srcdir}/src/platform \ -I${top_srcdir}/src/platform \
-I${top_srcdir}/src/supplicant-manager \ -I${top_srcdir}/src/supplicant-manager \
-I${top_builddir}/introspection \
-I${top_srcdir}/include \ -I${top_srcdir}/include \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(DBUS_CFLAGS) $(GLIB_CFLAGS)
GLIB_GENERATED = nm-wifi-enum-types.h nm-wifi-enum-types.c GLIB_GENERATED = nm-wifi-enum-types.h nm-wifi-enum-types.c
GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM
@ -29,14 +30,7 @@ nm_wifi_enum_types_sources = \
$(srcdir)/nm-wifi-ap.h \ $(srcdir)/nm-wifi-ap.h \
$(srcdir)/nm-device-olpc-mesh.h $(srcdir)/nm-device-olpc-mesh.h
glue_sources = \ BUILT_SOURCES = $(GLIB_GENERATED)
nm-device-wifi-glue.h \
nm-device-olpc-mesh-glue.h
%-glue.h: $(top_srcdir)/introspection/%.xml
$(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $<
BUILT_SOURCES = $(GLIB_GENERATED) $(glue_sources)
pkglib_LTLIBRARIES = libnm-device-plugin-wifi.la pkglib_LTLIBRARIES = libnm-device-plugin-wifi.la
@ -60,7 +54,8 @@ libnm_device_plugin_wifi_la_LDFLAGS = \
-Wl,--version-script=$(SYMBOL_VIS_FILE) -Wl,--version-script=$(SYMBOL_VIS_FILE)
libnm_device_plugin_wifi_la_LIBADD = \ libnm_device_plugin_wifi_la_LIBADD = \
$(DBUS_LIBS) \ $(top_builddir)/introspection/libnmdbus.la \
$(GLIB_LIBS) \
$(GUDEV_LIBS) $(GUDEV_LIBS)
CLEANFILES = $(BUILT_SOURCES) CLEANFILES = $(BUILT_SOURCES)

View file

@ -26,7 +26,6 @@
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -54,7 +53,7 @@
/* This is a bug; but we can't really change API now... */ /* This is a bug; but we can't really change API now... */
#include "nm-vpn-dbus-interface.h" #include "nm-vpn-dbus-interface.h"
#include "nm-device-olpc-mesh-glue.h" #include "nmdbus-device-olpc-mesh.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceOlpcMesh); _LOG_DECLARE_SELF(NMDeviceOlpcMesh);
@ -531,10 +530,10 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
/* Properties */ /* Properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_COMPANION, (object_class, PROP_COMPANION,
g_param_spec_boxed (NM_DEVICE_OLPC_MESH_COMPANION, "", "", g_param_spec_string (NM_DEVICE_OLPC_MESH_COMPANION, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_ACTIVE_CHANNEL, (object_class, PROP_ACTIVE_CHANNEL,
@ -544,6 +543,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_olpc_mesh_object_info); NMDBUS_TYPE_DEVICE_OLPC_MESH_SKELETON,
NULL);
} }

View file

@ -21,7 +21,6 @@
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -48,23 +47,10 @@
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-dbus-glib-types.h"
#include "nm-wifi-enum-types.h" #include "nm-wifi-enum-types.h"
#include "nm-connection-provider.h" #include "nm-connection-provider.h"
static gboolean impl_device_get_access_points (NMDeviceWifi *device, #include "nmdbus-device-wifi.h"
GPtrArray **aps,
GError **err);
static gboolean impl_device_get_all_access_points (NMDeviceWifi *device,
GPtrArray **aps,
GError **err);
static void impl_device_request_scan (NMDeviceWifi *device,
GHashTable *options,
DBusGMethodInvocation *context);
#include "nm-device-wifi-glue.h"
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceWifi); _LOG_DECLARE_SELF(NMDeviceWifi);
@ -1017,102 +1003,108 @@ get_sorted_ap_list (NMDeviceWifi *self)
return g_slist_sort (sorted, (GCompareFunc) ap_id_compare); return g_slist_sort (sorted, (GCompareFunc) ap_id_compare);
} }
static gboolean static void
impl_device_get_access_points (NMDeviceWifi *self, impl_device_wifi_get_access_points (NMDeviceWifi *self,
GPtrArray **aps, GDBusMethodInvocation *context)
GError **err)
{ {
GSList *sorted, *iter; GSList *sorted, *iter;
GPtrArray *paths;
*aps = g_ptr_array_new (); paths = g_ptr_array_new ();
sorted = get_sorted_ap_list (self); sorted = get_sorted_ap_list (self);
for (iter = sorted; iter; iter = iter->next) { for (iter = sorted; iter; iter = iter->next) {
NMAccessPoint *ap = NM_AP (iter->data); NMAccessPoint *ap = NM_AP (iter->data);
if (nm_ap_get_ssid (ap)) if (nm_ap_get_ssid (ap))
g_ptr_array_add (*aps, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap)))); g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap))));
} }
g_ptr_array_add (paths, NULL);
g_slist_free (sorted); g_slist_free (sorted);
return TRUE;
g_dbus_method_invocation_return_value (context, g_variant_new ("(^ao)", (char **) paths->pdata));
g_ptr_array_unref (paths);
} }
static gboolean static void
impl_device_get_all_access_points (NMDeviceWifi *self, impl_device_wifi_get_all_access_points (NMDeviceWifi *self,
GPtrArray **aps, GDBusMethodInvocation *context)
GError **err)
{ {
GSList *sorted, *iter; GSList *sorted, *iter;
GPtrArray *paths;
*aps = g_ptr_array_new (); paths = g_ptr_array_new ();
sorted = get_sorted_ap_list (self); sorted = get_sorted_ap_list (self);
for (iter = sorted; iter; iter = iter->next) for (iter = sorted; iter; iter = iter->next)
g_ptr_array_add (*aps, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data)))); g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data))));
g_ptr_array_add (paths, NULL);
g_slist_free (sorted); g_slist_free (sorted);
return TRUE;
g_dbus_method_invocation_return_value (context, g_variant_new ("(^ao)", (char **) paths->pdata));
g_ptr_array_unref (paths);
} }
static void static void
request_scan_cb (NMDevice *device, request_scan_cb (NMDevice *device,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifi *self = NM_DEVICE_WIFI (device);
GError *local = NULL;
if (error) { if (error) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
return; return;
} }
if (!check_scanning_allowed (self)) { if (!check_scanning_allowed (self)) {
local = g_error_new_literal (NM_DEVICE_ERROR, g_dbus_method_invocation_return_error_literal (context,
NM_DEVICE_ERROR_NOT_ALLOWED, NM_DEVICE_ERROR,
"Scanning not allowed at this time"); NM_DEVICE_ERROR_NOT_ALLOWED,
dbus_g_method_return_error (context, local); "Scanning not allowed at this time");
g_error_free (local);
return; return;
} }
cancel_pending_scan (self); cancel_pending_scan (self);
request_wireless_scan (self); request_wireless_scan (self);
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
} }
static void static void
impl_device_request_scan (NMDeviceWifi *self, impl_device_wifi_request_scan (NMDeviceWifi *self,
GHashTable *options, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) GVariant *options)
{ {
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
NMDevice *device = NM_DEVICE (self); NMDevice *device = NM_DEVICE (self);
gint32 last_scan; gint32 last_scan;
GError *error;
if ( !priv->enabled if ( !priv->enabled
|| !priv->sup_iface || !priv->sup_iface
|| nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED || nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED
|| nm_device_is_activating (device)) { || nm_device_is_activating (device)) {
error = g_error_new_literal (NM_DEVICE_ERROR, g_dbus_method_invocation_return_error_literal (context,
NM_DEVICE_ERROR_NOT_ALLOWED, NM_DEVICE_ERROR,
"Scanning not allowed while unavailable or activating"); NM_DEVICE_ERROR_NOT_ALLOWED,
goto error; "Scanning not allowed while unavailable or activating");
return;
} }
if (nm_supplicant_interface_get_scanning (priv->sup_iface)) { if (nm_supplicant_interface_get_scanning (priv->sup_iface)) {
error = g_error_new_literal (NM_DEVICE_ERROR, g_dbus_method_invocation_return_error_literal (context,
NM_DEVICE_ERROR_NOT_ALLOWED, NM_DEVICE_ERROR,
"Scanning not allowed while already scanning"); NM_DEVICE_ERROR_NOT_ALLOWED,
goto error; "Scanning not allowed while already scanning");
return;
} }
last_scan = nm_supplicant_interface_get_last_scan_time (priv->sup_iface); last_scan = nm_supplicant_interface_get_last_scan_time (priv->sup_iface);
if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) { if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) {
error = g_error_new_literal (NM_DEVICE_ERROR, g_dbus_method_invocation_return_error_literal (context,
NM_DEVICE_ERROR_NOT_ALLOWED, NM_DEVICE_ERROR,
"Scanning not allowed immediately following previous scan"); NM_DEVICE_ERROR_NOT_ALLOWED,
goto error; "Scanning not allowed immediately following previous scan");
return;
} }
/* Ask the manager to authenticate this request for us */ /* Ask the manager to authenticate this request for us */
@ -1124,11 +1116,6 @@ impl_device_request_scan (NMDeviceWifi *self,
TRUE, TRUE,
request_scan_cb, request_scan_cb,
NULL); NULL);
return;
error:
dbus_g_method_return_error (context, error);
g_error_free (error);
} }
static gboolean static gboolean
@ -2922,11 +2909,12 @@ get_property (GObject *object, guint prop_id,
g_value_set_uint (value, priv->capabilities); g_value_set_uint (value, priv->capabilities);
break; break;
case PROP_ACCESS_POINTS: case PROP_ACCESS_POINTS:
array = g_ptr_array_sized_new (g_hash_table_size (priv->aps)); array = g_ptr_array_sized_new (g_hash_table_size (priv->aps) + 1);
g_hash_table_iter_init (&iter, priv->aps); g_hash_table_iter_init (&iter, priv->aps);
while (g_hash_table_iter_next (&iter, (gpointer) &dbus_path, NULL)) while (g_hash_table_iter_next (&iter, (gpointer) &dbus_path, NULL))
g_ptr_array_add (array, g_strdup (dbus_path)); g_ptr_array_add (array, g_strdup (dbus_path));
g_value_take_boxed (value, array); g_ptr_array_add (array, NULL);
g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE));
break; break;
case PROP_ACTIVE_ACCESS_POINT: case PROP_ACTIVE_ACCESS_POINT:
nm_utils_g_value_set_object_path (value, priv->current_ap); nm_utils_g_value_set_object_path (value, priv->current_ap);
@ -3011,16 +2999,16 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_ACCESS_POINTS, (object_class, PROP_ACCESS_POINTS,
g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "", g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_ACTIVE_ACCESS_POINT, (object_class, PROP_ACTIVE_ACCESS_POINT,
g_param_spec_boxed (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "", g_param_spec_string (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_CAPABILITIES, (object_class, PROP_CAPABILITIES,
@ -3044,7 +3032,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
G_STRUCT_OFFSET (NMDeviceWifiClass, access_point_added), G_STRUCT_OFFSET (NMDeviceWifiClass, access_point_added),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_OBJECT); NM_TYPE_AP);
signals[ACCESS_POINT_REMOVED] = signals[ACCESS_POINT_REMOVED] =
g_signal_new ("access-point-removed", g_signal_new ("access-point-removed",
@ -3053,7 +3041,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_OBJECT); NM_TYPE_AP);
signals[SCANNING_ALLOWED] = signals[SCANNING_ALLOWED] =
g_signal_new ("scanning-allowed", g_signal_new ("scanning-allowed",
@ -3064,7 +3052,11 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
G_TYPE_BOOLEAN, 0); G_TYPE_BOOLEAN, 0);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_wifi_object_info); NMDBUS_TYPE_DEVICE_WIFI_SKELETON,
"GetAccessPoints", impl_device_wifi_get_access_points,
"GetAllAccessPoints", impl_device_wifi_get_all_access_points,
"RequestScan", impl_device_wifi_request_scan,
NULL);
} }

View file

@ -33,7 +33,7 @@
#include "nm-setting-wireless.h" #include "nm-setting-wireless.h"
#include "nm-access-point-glue.h" #include "nmdbus-access-point.h"
/* /*
* Encapsulates Access Point information * Encapsulates Access Point information
@ -46,7 +46,7 @@ typedef struct
GByteArray * ssid; GByteArray * ssid;
char * address; char * address;
NM80211Mode mode; NM80211Mode mode;
gint8 strength; guint8 strength;
guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */ guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */
guint32 max_bitrate;/* Maximum bitrate of the AP in Kbit/s (ie 54000 Kb/s == 54Mbit/s) */ guint32 max_bitrate;/* Maximum bitrate of the AP in Kbit/s (ie 54000 Kb/s == 54Mbit/s) */
@ -902,9 +902,7 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) GValue *value, GParamSpec *pspec)
{ {
NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object);
GArray * ssid; GVariant *ssid;
int len;
int i;
switch (prop_id) { switch (prop_id) {
case PROP_FLAGS: case PROP_FLAGS:
@ -917,12 +915,12 @@ get_property (GObject *object, guint prop_id,
g_value_set_uint (value, priv->rsn_flags); g_value_set_uint (value, priv->rsn_flags);
break; break;
case PROP_SSID: case PROP_SSID:
len = priv->ssid ? priv->ssid->len : 0; if (priv->ssid) {
ssid = g_array_sized_new (FALSE, TRUE, sizeof (unsigned char), len); ssid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
for (i = 0; i < len; i++) priv->ssid->data, priv->ssid->len, 1);
g_array_append_val (ssid, priv->ssid->data[i]); } else
g_value_set_boxed (value, ssid); ssid = g_variant_new_array (G_VARIANT_TYPE_BYTE, NULL, 0);
g_array_free (ssid, TRUE); g_value_take_variant (value, ssid);
break; break;
case PROP_FREQUENCY: case PROP_FREQUENCY:
g_value_set_uint (value, priv->freq); g_value_set_uint (value, priv->freq);
@ -937,7 +935,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_uint (value, priv->max_bitrate); g_value_set_uint (value, priv->max_bitrate);
break; break;
case PROP_STRENGTH: case PROP_STRENGTH:
g_value_set_schar (value, priv->strength); g_value_set_uchar (value, priv->strength);
break; break;
case PROP_LAST_SEEN: case PROP_LAST_SEEN:
g_value_set_int (value, g_value_set_int (value,
@ -1004,9 +1002,10 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_SSID, (object_class, PROP_SSID,
g_param_spec_boxed (NM_AP_SSID, "", "", g_param_spec_variant (NM_AP_SSID, "", "",
DBUS_TYPE_G_UCHAR_ARRAY, G_VARIANT_TYPE ("ay"),
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_FREQUENCY, (object_class, PROP_FREQUENCY,
@ -1034,9 +1033,9 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_STRENGTH, (object_class, PROP_STRENGTH,
g_param_spec_char (NM_AP_STRENGTH, "", "", g_param_spec_uchar (NM_AP_STRENGTH, "", "",
G_MININT8, G_MAXINT8, 0, 0, G_MAXINT8, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_LAST_SEEN, (object_class, PROP_LAST_SEEN,
@ -1045,6 +1044,7 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ap_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ap_class),
&dbus_glib_nm_access_point_object_info); NMDBUS_TYPE_ACCESS_POINT_SKELETON,
NULL);
} }

View file

@ -1,4 +1,5 @@
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-I$(top_builddir)/introspection \
-I$(top_srcdir)/include \ -I$(top_srcdir)/include \
-I$(top_srcdir)/libnm-core \ -I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \ -I$(top_builddir)/libnm-core \
@ -9,8 +10,7 @@ AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS)
$(DBUS_CFLAGS)
noinst_PROGRAMS = test-wifi-ap-utils noinst_PROGRAMS = test-wifi-ap-utils

View file

@ -24,7 +24,6 @@
#include "nm-default.h" #include "nm-default.h"
#include "nm-wifi-ap-utils.h" #include "nm-wifi-ap-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"

View file

@ -8,13 +8,14 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/devices \ -I${top_srcdir}/src/devices \
-I${top_srcdir}/src/settings \ -I${top_srcdir}/src/settings \
-I${top_srcdir}/src/platform \ -I${top_srcdir}/src/platform \
-I${top_builddir}/introspection \
-I${top_srcdir}/include \ -I${top_srcdir}/include \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \ -DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(DBUS_CFLAGS) \ $(GLIB_CFLAGS) \
$(MM_GLIB_CFLAGS) $(MM_GLIB_CFLAGS)
BUILT_SOURCES = $(null) BUILT_SOURCES = $(null)
@ -45,31 +46,29 @@ WWAN_SYMBOL_VIS_FILE=$(srcdir)/wwan-exports.ver
libnm_wwan_la_LDFLAGS = \ libnm_wwan_la_LDFLAGS = \
-avoid-version \ -avoid-version \
-Wl,--version-script=$(WWAN_SYMBOL_VIS_FILE) -Wl,--version-script=$(WWAN_SYMBOL_VIS_FILE)
libnm_wwan_la_LIBADD = $(DBUS_LIBS) $(MM_GLIB_LIBS) libnm_wwan_la_LIBADD = \
$(top_builddir)/introspection/libnmdbus.la \
$(GLIB_LIBS) \
$(MM_GLIB_LIBS)
########################################################### ###########################################################
nm-device-modem-glue.h: $(top_srcdir)/introspection/nm-device-modem.xml
dbus-binding-tool --prefix=nm_device_modem --mode=glib-server --output=$@ $<
BUILT_SOURCES += nm-device-modem-glue.h
SYMBOL_VIS_FILE=$(srcdir)/exports.ver SYMBOL_VIS_FILE=$(srcdir)/exports.ver
libnm_device_plugin_wwan_la_SOURCES = \ libnm_device_plugin_wwan_la_SOURCES = \
nm-wwan-factory.c \ nm-wwan-factory.c \
nm-wwan-factory.h \ nm-wwan-factory.h \
nm-device-modem.c \ nm-device-modem.c \
nm-device-modem.h \ nm-device-modem.h
nm-device-modem-glue.h
libnm_device_plugin_wwan_la_LDFLAGS = \ libnm_device_plugin_wwan_la_LDFLAGS = \
-module -avoid-version \ -module -avoid-version \
-Wl,--version-script=$(SYMBOL_VIS_FILE) -Wl,--version-script=$(SYMBOL_VIS_FILE)
libnm_device_plugin_wwan_la_LIBADD = \ libnm_device_plugin_wwan_la_LIBADD = \
$(top_builddir)/introspection/libnmdbus.la \
libnm-wwan.la \ libnm-wwan.la \
$(DBUS_LIBS) $(GLIB_LIBS)
########################################################### ###########################################################

View file

@ -35,12 +35,12 @@
#include "nm-device-logging.h" #include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceModem); _LOG_DECLARE_SELF(NMDeviceModem);
#include "nmdbus-device-modem.h"
G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
#define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate)) #define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate))
#include "nm-device-modem-glue.h"
typedef struct { typedef struct {
NMModem *modem; NMModem *modem;
NMDeviceModemCapabilities caps; NMDeviceModemCapabilities caps;
@ -794,5 +794,6 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (mclass), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (mclass),
&dbus_glib_nm_device_modem_object_info); NMDBUS_TYPE_DEVICE_MODEM_SKELETON,
NULL);
} }

View file

@ -28,7 +28,6 @@
#include "nm-default.h" #include "nm-default.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-device-private.h" #include "nm-device-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-modem-enum-types.h" #include "nm-modem-enum-types.h"
#include "nm-route-manager.h" #include "nm-route-manager.h"

View file

@ -12,15 +12,3 @@ nm_dhcp_helper_CPPFLAGS = \
-DNMRUNDIR=\"$(nmrundir)\" -DNMRUNDIR=\"$(nmrundir)\"
nm_dhcp_helper_LDADD = $(GLIB_LIBS) nm_dhcp_helper_LDADD = $(GLIB_LIBS)
# FIXME: remove when dbus-glib >= 0.100 or GDBus is required
dhcp_helper_conf = nm-dhcp-helper.conf
if !HAVE_DBUS_GLIB_100
dbusservicedir = $(DBUS_SYS_DIR)
dbusservice_DATA = $(dhcp_helper_conf)
endif
EXTRA_DIST = $(dhcp_helper_conf)

View file

@ -31,7 +31,6 @@
#include "nm-default.h" #include "nm-default.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-dhcp-client.h" #include "nm-dhcp-client.h"
#include "nm-dhcp-utils.h" #include "nm-dhcp-utils.h"
#include "nm-platform.h" #include "nm-platform.h"
@ -648,21 +647,25 @@ nm_dhcp_client_stop (NMDhcpClient *self, gboolean release)
/********************************************/ /********************************************/
static char * static char *
garray_to_string (GArray *array, const char *key) bytearray_variant_to_string (GVariant *value, const char *key)
{ {
const guint8 *array;
gsize length;
GString *str; GString *str;
int i; int i;
unsigned char c; unsigned char c;
char *converted = NULL; char *converted = NULL;
g_return_val_if_fail (array != NULL, NULL); g_return_val_if_fail (value != NULL, NULL);
array = g_variant_get_fixed_array (value, &length, 1);
/* Since the DHCP options come through environment variables, they should /* Since the DHCP options come through environment variables, they should
* already be UTF-8 safe, but just make sure. * already be UTF-8 safe, but just make sure.
*/ */
str = g_string_sized_new (array->len); str = g_string_sized_new (length);
for (i = 0; i < array->len; i++) { for (i = 0; i < length; i++) {
c = array->data[i]; c = array[i];
/* Convert NULLs to spaces and non-ASCII characters to ? */ /* Convert NULLs to spaces and non-ASCII characters to ? */
if (c == '\0') if (c == '\0')
@ -684,11 +687,10 @@ garray_to_string (GArray *array, const char *key)
#define NEW_TAG "new_" #define NEW_TAG "new_"
static void static void
copy_option (const char * key, maybe_add_option (GHashTable *hash,
GValue *value, const char *key,
gpointer user_data) GVariant *value)
{ {
GHashTable *hash = user_data;
char *str_value = NULL; char *str_value = NULL;
const char **p; const char **p;
static const char *ignored_keys[] = { static const char *ignored_keys[] = {
@ -699,10 +701,7 @@ copy_option (const char * key,
NULL NULL
}; };
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)) { g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_BYTESTRING));
nm_log_warn (LOGD_DHCP, "key %s value type was not DBUS_TYPE_G_UCHAR_ARRAY", key);
return;
}
if (g_str_has_prefix (key, OLD_TAG)) if (g_str_has_prefix (key, OLD_TAG))
return; return;
@ -718,7 +717,7 @@ copy_option (const char * key,
if (!key[0]) if (!key[0])
return; return;
str_value = garray_to_string ((GArray *) g_value_get_boxed (value), key); str_value = bytearray_variant_to_string (value, key);
if (str_value) if (str_value)
g_hash_table_insert (hash, g_strdup (key), str_value); g_hash_table_insert (hash, g_strdup (key), str_value);
} }
@ -727,7 +726,7 @@ gboolean
nm_dhcp_client_handle_event (gpointer unused, nm_dhcp_client_handle_event (gpointer unused,
const char *iface, const char *iface,
gint pid, gint pid,
GHashTable *options, GVariant *options,
const char *reason, const char *reason,
NMDhcpClient *self) NMDhcpClient *self)
{ {
@ -740,7 +739,7 @@ nm_dhcp_client_handle_event (gpointer unused,
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE); g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
g_return_val_if_fail (iface != NULL, FALSE); g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (pid > 0, FALSE); g_return_val_if_fail (pid > 0, FALSE);
g_return_val_if_fail (options != NULL, FALSE); g_return_val_if_fail (g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT), FALSE);
g_return_val_if_fail (reason != NULL, FALSE); g_return_val_if_fail (reason != NULL, FALSE);
priv = NM_DHCP_CLIENT_GET_PRIVATE (self); priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
@ -756,9 +755,17 @@ nm_dhcp_client_handle_event (gpointer unused,
iface, reason, state_to_string (new_state)); iface, reason, state_to_string (new_state));
if (new_state == NM_DHCP_STATE_BOUND) { if (new_state == NM_DHCP_STATE_BOUND) {
GVariantIter iter;
const char *name;
GVariant *value;
/* Copy options */ /* Copy options */
str_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); str_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
g_hash_table_foreach (options, (GHFunc) copy_option, str_options); g_variant_iter_init (&iter, options);
while (g_variant_iter_next (&iter, "{&sv}", &name, &value)) {
maybe_add_option (str_options, name, value);
g_variant_unref (value);
}
/* Create the IP config */ /* Create the IP config */
g_warn_if_fail (g_hash_table_size (str_options)); g_warn_if_fail (g_hash_table_size (str_options));

View file

@ -159,7 +159,7 @@ void nm_dhcp_client_set_state (NMDhcpClient *self,
gboolean nm_dhcp_client_handle_event (gpointer unused, gboolean nm_dhcp_client_handle_event (gpointer unused,
const char *iface, const char *iface,
gint pid, gint pid,
GHashTable *options, GVariant *options,
const char *reason, const char *reason,
NMDhcpClient *self); NMDhcpClient *self);

View file

@ -75,69 +75,6 @@ build_signal_parameters (void)
return g_variant_new ("(a{sv})", &builder); return g_variant_new ("(a{sv})", &builder);
} }
#if !HAVE_DBUS_GLIB_100
/* It doesn't matter that nm-dhcp-helper doesn't use dbus-glib itself; the
* workaround code is for if the daemon is built with old dbus-glib.
*/
static gboolean ever_acquired = FALSE;
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
GMainLoop *loop = user_data;
ever_acquired = TRUE;
g_main_loop_quit (loop);
}
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
if (ever_acquired) {
g_print ("Lost D-Bus name: exiting\n");
exit (0);
} else {
g_printerr ("Error: Could not acquire the NM DHCP client service.\n");
exit (1);
}
}
static GDBusConnection *
shared_connection_init (void)
{
GDBusConnection *connection;
GError *error = NULL;
GMainLoop *loop;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!connection) {
g_dbus_error_strip_remote_error (error);
g_printerr ("Error: could not get the system bus. Make sure "
"the message bus daemon is running! Message: %s\n",
error->message);
g_error_free (error);
return NULL;
}
loop = g_main_loop_new (NULL, FALSE);
g_bus_own_name_on_connection (connection,
"org.freedesktop.nm_dhcp_client",
0,
on_name_acquired,
on_name_lost,
loop, NULL);
g_main_loop_run (loop);
g_main_loop_unref (loop);
return connection;
}
#endif
static void static void
fatal_error (void) fatal_error (void)
{ {
@ -164,16 +101,11 @@ main (int argc, char *argv[])
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL, NULL, &error); NULL, NULL, &error);
if (!connection) { if (!connection) {
#if !HAVE_DBUS_GLIB_100 g_dbus_error_strip_remote_error (error);
connection = shared_connection_init (); g_printerr ("Error: could not connect to NetworkManager D-Bus socket: %s\n",
#endif error->message);
if (!connection) { g_error_free (error);
g_dbus_error_strip_remote_error (error); fatal_error ();
g_printerr ("Error: could not connect to NetworkManager D-Bus socket: %s\n",
error->message);
g_error_free (error);
fatal_error ();
}
} }
if (!g_dbus_connection_emit_signal (connection, if (!g_dbus_connection_emit_signal (connection,

View file

@ -1,13 +0,0 @@
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.freedesktop.nm_dhcp_client"/>
</policy>
<policy context="default">
<deny own="org.freedesktop.nm_dhcp_client"/>
<deny send_destination="org.freedesktop.nm_dhcp_client"/>
</policy>
</busconfig>

View file

@ -19,7 +19,6 @@
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h> #include <signal.h>
@ -32,7 +31,6 @@
#include "nm-dhcp-listener.h" #include "nm-dhcp-listener.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-bus-manager.h" #include "nm-bus-manager.h"
#include "nm-dbus-glib-types.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client" #define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
@ -43,8 +41,7 @@ typedef struct {
NMBusManager * dbus_mgr; NMBusManager * dbus_mgr;
guint new_conn_id; guint new_conn_id;
guint dis_conn_id; guint dis_conn_id;
GHashTable * proxies; GHashTable * signal_handlers;
DBusGProxy * proxy;
} NMDhcpListenerPrivate; } NMDhcpListenerPrivate;
#define NM_DHCP_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_LISTENER, NMDhcpListenerPrivate)) #define NM_DHCP_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_LISTENER, NMDhcpListenerPrivate))
@ -60,61 +57,44 @@ static guint signals[LAST_SIGNAL] = { 0 };
/***************************************************/ /***************************************************/
static char * static char *
garray_to_string (GArray *array, const char *key) get_option (GVariant *options, const char *key)
{ {
GString *str; GVariant *value;
int i; const guchar *bytes, *s;
unsigned char c; gsize len;
char *converted = NULL; char *converted, *d;
g_return_val_if_fail (array != NULL, NULL); if (!g_variant_lookup (options, key, "@ay", &value))
return NULL;
bytes = g_variant_get_fixed_array (value, &len, 1);
/* Since the DHCP options come through environment variables, they should /* Since the DHCP options come through environment variables, they should
* already be UTF-8 safe, but just make sure. * already be UTF-8 safe, but just make sure.
*/ */
str = g_string_sized_new (array->len); converted = g_malloc (len + 1);
for (i = 0; i < array->len; i++) { for (s = bytes, d = converted; s < bytes + len; s++, d++) {
c = array->data[i];
/* Convert NULLs to spaces and non-ASCII characters to ? */ /* Convert NULLs to spaces and non-ASCII characters to ? */
if (c == '\0') if (*s == '\0')
c = ' '; *d = ' ';
else if (c > 127) else if (*s > 127)
c = '?'; *d = '?';
str = g_string_append_c (str, c); else
*d = *s;
} }
str = g_string_append_c (str, '\0'); *d = '\0';
converted = str->str;
if (!g_utf8_validate (converted, -1, NULL))
nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key);
g_string_free (str, FALSE);
return converted; return converted;
} }
static char *
get_option (GHashTable *hash, const char *key)
{
GValue *value;
value = g_hash_table_lookup (hash, key);
if (value == NULL)
return NULL;
if (G_VALUE_TYPE (value) != DBUS_TYPE_G_UCHAR_ARRAY) {
nm_log_warn (LOGD_DHCP, "unexpected key %s value type was not "
"DBUS_TYPE_G_UCHAR_ARRAY",
(char *) key);
return NULL;
}
return garray_to_string ((GArray *) g_value_get_boxed (value), key);
}
static void static void
handle_event (DBusGProxy *proxy, handle_event (GDBusConnection *connection,
GHashTable *options, const char *sender_name,
gpointer user_data) const char *object_path,
const char *interface_name,
const char *signal_name,
GVariant *parameters,
gpointer user_data)
{ {
NMDhcpListener *self = NM_DHCP_LISTENER (user_data); NMDhcpListener *self = NM_DHCP_LISTENER (user_data);
char *iface = NULL; char *iface = NULL;
@ -122,6 +102,12 @@ handle_event (DBusGProxy *proxy,
char *reason = NULL; char *reason = NULL;
gint pid; gint pid;
gboolean handled = FALSE; gboolean handled = FALSE;
GVariant *options;
if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})")))
return;
g_variant_get (parameters, "(@a{sv})", &options);
iface = get_option (options, "interface"); iface = get_option (options, "interface");
if (iface == NULL) { if (iface == NULL) {
@ -155,39 +141,42 @@ out:
g_free (iface); g_free (iface);
g_free (pid_str); g_free (pid_str);
g_free (reason); g_free (reason);
g_variant_unref (options);
} }
#if HAVE_DBUS_GLIB_100
static void static void
new_connection_cb (NMBusManager *mgr, new_connection_cb (NMBusManager *mgr,
DBusGConnection *connection, GDBusConnection *connection,
NMDhcpListener *self) NMDhcpListener *self)
{ {
DBusGProxy *proxy; NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
guint id;
/* Create a new proxy for the client */ id = g_dbus_connection_signal_subscribe (connection,
proxy = dbus_g_proxy_new_for_peer (connection, "/", NM_DHCP_CLIENT_DBUS_IFACE); NULL,
dbus_g_proxy_add_signal (proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); NM_DHCP_CLIENT_DBUS_IFACE,
dbus_g_proxy_connect_signal (proxy, "Event", G_CALLBACK (handle_event), self, NULL); "Event",
NULL,
g_hash_table_insert (NM_DHCP_LISTENER_GET_PRIVATE (self)->proxies, connection, proxy); NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
handle_event, self, NULL);
g_hash_table_insert (priv->signal_handlers, connection, GUINT_TO_POINTER (id));
} }
static void static void
dis_connection_cb (NMBusManager *mgr, dis_connection_cb (NMBusManager *mgr,
DBusGConnection *connection, GDBusConnection *connection,
NMDhcpListener *self) NMDhcpListener *self)
{ {
NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self); NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
DBusGProxy *proxy; guint id;
proxy = g_hash_table_lookup (priv->proxies, connection); id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->signal_handlers, connection));
if (proxy) { if (id) {
dbus_g_proxy_disconnect_signal (proxy, "Event", G_CALLBACK (handle_event), self); g_dbus_connection_signal_unsubscribe (connection, id);
g_hash_table_remove (priv->proxies, connection); g_hash_table_remove (priv->signal_handlers, connection);
} }
} }
#endif
/***************************************************/ /***************************************************/
@ -197,16 +186,12 @@ static void
nm_dhcp_listener_init (NMDhcpListener *self) nm_dhcp_listener_init (NMDhcpListener *self)
{ {
NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self); NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
#if !HAVE_DBUS_GLIB_100
DBusGConnection *g_connection;
#endif
/* Maps DBusGConnection :: DBusGProxy */ /* Maps GDBusConnection :: GDBusProxy */
priv->proxies = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); priv->signal_handlers = g_hash_table_new (NULL, NULL);
priv->dbus_mgr = nm_bus_manager_get (); priv->dbus_mgr = nm_bus_manager_get ();
#if HAVE_DBUS_GLIB_100
/* Register the socket our DHCP clients will return lease info on */ /* Register the socket our DHCP clients will return lease info on */
nm_bus_manager_private_server_register (priv->dbus_mgr, PRIV_SOCK_PATH, PRIV_SOCK_TAG); nm_bus_manager_private_server_register (priv->dbus_mgr, PRIV_SOCK_PATH, PRIV_SOCK_TAG);
priv->new_conn_id = g_signal_connect (priv->dbus_mgr, priv->new_conn_id = g_signal_connect (priv->dbus_mgr,
@ -217,16 +202,6 @@ nm_dhcp_listener_init (NMDhcpListener *self)
NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG, NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG,
G_CALLBACK (dis_connection_cb), G_CALLBACK (dis_connection_cb),
self); self);
#else
g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
priv->proxy = dbus_g_proxy_new_for_name (g_connection,
"org.freedesktop.nm_dhcp_client",
"/",
NM_DHCP_CLIENT_DBUS_IFACE);
g_assert (priv->proxy);
dbus_g_proxy_add_signal (priv->proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "Event", G_CALLBACK (handle_event), self, NULL);
#endif
} }
static void static void
@ -244,11 +219,7 @@ dispose (GObject *object)
} }
priv->dbus_mgr = NULL; priv->dbus_mgr = NULL;
if (priv->proxies) { g_clear_pointer (&priv->signal_handlers, g_hash_table_destroy);
g_hash_table_destroy (priv->proxies);
priv->proxies = NULL;
}
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_dhcp_listener_parent_class)->dispose (object); G_OBJECT_CLASS (nm_dhcp_listener_parent_class)->dispose (object);
} }
@ -274,6 +245,6 @@ nm_dhcp_listener_class_init (NMDhcpListenerClass *listener_class)
4, 4,
G_TYPE_STRING, /* iface */ G_TYPE_STRING, /* iface */
G_TYPE_INT, /* pid */ G_TYPE_INT, /* pid */
G_TYPE_HASH_TABLE, /* options */ G_TYPE_VARIANT, /* options */
G_TYPE_STRING); /* reason */ G_TYPE_STRING); /* reason */
} }

View file

@ -38,7 +38,6 @@
#include "nm-dhcp-dhcpcd.h" #include "nm-dhcp-dhcpcd.h"
#include "nm-dhcp-systemd.h" #include "nm-dhcp-systemd.h"
#include "nm-config.h" #include "nm-config.h"
#include "nm-dbus-glib-types.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#define DHCP_TIMEOUT 45 /* default DHCP timeout, in seconds */ #define DHCP_TIMEOUT 45 /* default DHCP timeout, in seconds */
@ -180,7 +179,7 @@ get_client_type (const char *client, GError **error)
static void client_state_changed (NMDhcpClient *client, static void client_state_changed (NMDhcpClient *client,
NMDhcpState state, NMDhcpState state,
GObject *ip_config, GObject *ip_config,
GHashTable *options, GVariant *options,
NMDhcpManager *self); NMDhcpManager *self);
static void static void
@ -200,7 +199,7 @@ static void
client_state_changed (NMDhcpClient *client, client_state_changed (NMDhcpClient *client,
NMDhcpState state, NMDhcpState state,
GObject *ip_config, GObject *ip_config,
GHashTable *options, GVariant *options,
NMDhcpManager *self) NMDhcpManager *self)
{ {
if (state >= NM_DHCP_STATE_TIMEOUT) if (state >= NM_DHCP_STATE_TIMEOUT)

View file

@ -9,7 +9,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DTESTDIR="\"$(abs_srcdir)\"" -DTESTDIR="\"$(abs_srcdir)\""
noinst_PROGRAMS = \ noinst_PROGRAMS = \

View file

@ -21,9 +21,6 @@
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus-glib.h>
#include <getopt.h> #include <getopt.h>
#include <locale.h> #include <locale.h>
#include <errno.h> #include <errno.h>
@ -261,7 +258,6 @@ main (int argc, char *argv[])
gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE; gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE;
gboolean success = FALSE; gboolean success = FALSE;
NMManager *manager = NULL; NMManager *manager = NULL;
gs_unref_object NMSettings *settings = NULL;
NMConfig *config; NMConfig *config;
GError *error = NULL; GError *error = NULL;
gboolean wrote_pidfile = FALSE; gboolean wrote_pidfile = FALSE;
@ -402,13 +398,6 @@ main (int argc, char *argv[])
} }
g_clear_error (&error); g_clear_error (&error);
dbus_threads_init_default ();
/* Ensure that non-exported properties don't leak out, and that the
* introspection 'access' permissions are respected.
*/
dbus_glib_global_set_disable_legacy_property_access ();
nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config))); nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config)));
nm_config_data_log (nm_config_get_data (config), "CONFIG: "); nm_config_data_log (nm_config_get_data (config), "CONFIG: ");
nm_log_dbg (LOGD_CORE, "WEXT support is %s", nm_log_dbg (LOGD_CORE, "WEXT support is %s",
@ -419,13 +408,16 @@ main (int argc, char *argv[])
#endif #endif
); );
nm_auth_manager_setup (nm_config_get_auth_polkit (config));
manager = nm_manager_setup (global_opt.state_file,
net_enabled,
wifi_enabled,
wwan_enabled,
wimax_enabled);
if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) { if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) {
#if HAVE_DBUS_GLIB_100
nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available"); nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available");
#else
nm_log_err (LOGD_CORE, "Failed to connect to D-Bus, exiting...");
goto done;
#endif
} else { } else {
/* Start our DBus service */ /* Start our DBus service */
if (!nm_bus_manager_start_service (nm_bus_manager_get ())) { if (!nm_bus_manager_start_service (nm_bus_manager_get ())) {
@ -443,33 +435,14 @@ main (int argc, char *argv[])
* NMPlatform. */ * NMPlatform. */
g_object_ref (NM_PLATFORM_GET); g_object_ref (NM_PLATFORM_GET);
nm_auth_manager_setup (nm_config_get_auth_polkit (config));
nm_dispatcher_init (); nm_dispatcher_init ();
settings = nm_settings_new (&error);
if (!settings) {
nm_log_err (LOGD_CORE, "failed to initialize settings storage: %s",
error && error->message ? error->message : "(unknown)");
goto done;
}
manager = nm_manager_new (settings,
global_opt.state_file,
net_enabled,
wifi_enabled,
wwan_enabled,
wimax_enabled,
&error);
if (manager == NULL) {
nm_log_err (LOGD_CORE, "failed to initialize the network manager: %s",
error && error->message ? error->message : "(unknown)");
goto done;
}
g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config); g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config);
nm_manager_start (manager); if (!nm_manager_start (manager, &error)) {
nm_log_err (LOGD_CORE, "failed to initialize: %s", error->message);
goto done;
}
/* Make sure the loopback interface is up. If interface is down, we bring /* Make sure the loopback interface is up. If interface is down, we bring
* it up and kernel will assign it link-local IPv4 and IPv6 addresses. If * it up and kernel will assign it link-local IPv4 and IPv6 addresses. If

View file

@ -461,7 +461,7 @@ get_property (GObject *object, guint prop_id,
device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object)); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
if (!device) { if (!device) {
g_value_set_boxed (value, "/"); g_value_set_string (value, "/");
return; return;
} }

View file

@ -24,13 +24,13 @@
#include "nm-default.h" #include "nm-default.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-dbus-glib-types.h"
#include "nm-device.h" #include "nm-device.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-auth-subject.h" #include "nm-auth-subject.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-active-connection-glue.h"
#include "nmdbus-active-connection.h"
/* Base class for anything implementing the Connection.Active D-Bus interface */ /* Base class for anything implementing the Connection.Active D-Bus interface */
G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_EXPORTED_OBJECT)
@ -586,7 +586,7 @@ nm_active_connection_get_assumed (NMActiveConnection *self)
static void static void
auth_done (NMAuthChain *chain, auth_done (NMAuthChain *chain,
GError *error, GError *error,
DBusGMethodInvocation *unused, GDBusMethodInvocation *unused,
gpointer user_data) gpointer user_data)
{ {
NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data);
@ -720,10 +720,10 @@ set_property (GObject *object, guint prop_id,
nm_active_connection_set_master (NM_ACTIVE_CONNECTION (object), g_value_get_object (value)); nm_active_connection_set_master (NM_ACTIVE_CONNECTION (object), g_value_get_object (value));
break; break;
case PROP_SPECIFIC_OBJECT: case PROP_SPECIFIC_OBJECT:
tmp = g_value_get_boxed (value); tmp = g_value_get_string (value);
/* NM uses "/" to mean NULL */ /* NM uses "/" to mean NULL */
if (g_strcmp0 (tmp, "/") != 0) if (g_strcmp0 (tmp, "/") != 0)
priv->specific_object = g_value_dup_boxed (value); priv->specific_object = g_strdup (tmp);
break; break;
case PROP_DEFAULT: case PROP_DEFAULT:
priv->is_default = !!g_value_get_boolean (value); priv->is_default = !!g_value_get_boolean (value);
@ -752,7 +752,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case PROP_CONNECTION: case PROP_CONNECTION:
g_value_set_boxed (value, nm_connection_get_path (priv->connection)); g_value_set_string (value, nm_connection_get_path (priv->connection));
break; break;
case PROP_ID: case PROP_ID:
g_value_set_string (value, nm_connection_get_id (priv->connection)); g_value_set_string (value, nm_connection_get_id (priv->connection));
@ -764,13 +764,14 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, nm_connection_get_connection_type (priv->connection)); g_value_set_string (value, nm_connection_get_connection_type (priv->connection));
break; break;
case PROP_SPECIFIC_OBJECT: case PROP_SPECIFIC_OBJECT:
g_value_set_boxed (value, priv->specific_object ? priv->specific_object : "/"); g_value_set_string (value, priv->specific_object ? priv->specific_object : "/");
break; break;
case PROP_DEVICES: case PROP_DEVICES:
devices = g_ptr_array_sized_new (1); devices = g_ptr_array_sized_new (2);
if (priv->device && priv->state < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) if (priv->device && priv->state < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)
g_ptr_array_add (devices, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (priv->device)))); g_ptr_array_add (devices, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (priv->device))));
g_value_take_boxed (value, devices); g_ptr_array_add (devices, NULL);
g_value_take_boxed (value, (char **) g_ptr_array_free (devices, FALSE));
break; break;
case PROP_STATE: case PROP_STATE:
if (priv->state_set) if (priv->state_set)
@ -787,19 +788,19 @@ get_property (GObject *object, guint prop_id,
break; break;
case PROP_IP4_CONFIG: case PROP_IP4_CONFIG:
/* The IP and DHCP config properties may be overridden by a subclass */ /* The IP and DHCP config properties may be overridden by a subclass */
g_value_set_boxed (value, "/"); g_value_set_string (value, "/");
break; break;
case PROP_DHCP4_CONFIG: case PROP_DHCP4_CONFIG:
g_value_set_boxed (value, "/"); g_value_set_string (value, "/");
break; break;
case PROP_DEFAULT6: case PROP_DEFAULT6:
g_value_set_boolean (value, priv->is_default6); g_value_set_boolean (value, priv->is_default6);
break; break;
case PROP_IP6_CONFIG: case PROP_IP6_CONFIG:
g_value_set_boxed (value, "/"); g_value_set_string (value, "/");
break; break;
case PROP_DHCP6_CONFIG: case PROP_DHCP6_CONFIG:
g_value_set_boxed (value, "/"); g_value_set_string (value, "/");
break; break;
case PROP_VPN: case PROP_VPN:
g_value_set_boolean (value, priv->vpn); g_value_set_boolean (value, priv->vpn);
@ -888,10 +889,10 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
/* D-Bus exported properties */ /* D-Bus exported properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_CONNECTION, (object_class, PROP_CONNECTION,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_CONNECTION, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_ID, (object_class, PROP_ID,
@ -916,15 +917,15 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_SPECIFIC_OBJECT, (object_class, PROP_SPECIFIC_OBJECT,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DEVICES, (object_class, PROP_DEVICES,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "", g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
@ -946,17 +947,17 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_IP4_CONFIG, (object_class, PROP_IP4_CONFIG,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DHCP4_CONFIG, (object_class, PROP_DHCP4_CONFIG,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DEFAULT6, (object_class, PROP_DEFAULT6,
@ -967,17 +968,17 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_IP6_CONFIG, (object_class, PROP_IP6_CONFIG,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_DHCP6_CONFIG, (object_class, PROP_DHCP6_CONFIG,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_VPN, (object_class, PROP_VPN,
@ -988,10 +989,10 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_MASTER, (object_class, PROP_MASTER,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_MASTER, "", "", g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER, "", "",
DBUS_TYPE_G_OBJECT_PATH, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
/* Internal properties */ /* Internal properties */
g_object_class_install_property g_object_class_install_property
@ -1045,6 +1046,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
G_TYPE_NONE, 1, G_TYPE_UINT); G_TYPE_NONE, 1, G_TYPE_UINT);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ac_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ac_class),
&dbus_glib_nm_active_connection_object_info); NMDBUS_TYPE_ACTIVE_CONNECTION_SKELETON,
NULL);
} }

View file

@ -167,9 +167,9 @@ nm_auth_subject_get_unix_process_dbus_sender (NMAuthSubject *subject)
/**************************************************************/ /**************************************************************/
static NMAuthSubject * static NMAuthSubject *
_new_unix_process (DBusGMethodInvocation *context, _new_unix_process (GDBusMethodInvocation *context,
DBusConnection *connection, GDBusConnection *connection,
DBusMessage *message) GDBusMessage *message)
{ {
NMAuthSubject *self; NMAuthSubject *self;
gboolean success = FALSE; gboolean success = FALSE;
@ -221,14 +221,14 @@ _new_unix_process (DBusGMethodInvocation *context,
} }
NMAuthSubject * NMAuthSubject *
nm_auth_subject_new_unix_process_from_context (DBusGMethodInvocation *context) nm_auth_subject_new_unix_process_from_context (GDBusMethodInvocation *context)
{ {
return _new_unix_process (context, NULL, NULL); return _new_unix_process (context, NULL, NULL);
} }
NMAuthSubject * NMAuthSubject *
nm_auth_subject_new_unix_process_from_message (DBusConnection *connection, nm_auth_subject_new_unix_process_from_message (GDBusConnection *connection,
DBusMessage *message) GDBusMessage *message)
{ {
return _new_unix_process (NULL, connection, message); return _new_unix_process (NULL, connection, message);
} }

View file

@ -22,8 +22,6 @@
#define __NETWORKMANAGER_AUTH_SUBJECT_H__ #define __NETWORKMANAGER_AUTH_SUBJECT_H__
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include "nm-default.h" #include "nm-default.h"
@ -57,9 +55,9 @@ GType nm_auth_subject_get_type (void);
NMAuthSubject *nm_auth_subject_new_internal (void); NMAuthSubject *nm_auth_subject_new_internal (void);
NMAuthSubject *nm_auth_subject_new_unix_process_from_context (DBusGMethodInvocation *context); NMAuthSubject *nm_auth_subject_new_unix_process_from_context (GDBusMethodInvocation *context);
NMAuthSubject *nm_auth_subject_new_unix_process_from_message (DBusConnection *connection, DBusMessage *message); NMAuthSubject *nm_auth_subject_new_unix_process_from_message (GDBusConnection *connection, GDBusMessage *message);
NMAuthSubjectType nm_auth_subject_get_subject_type (NMAuthSubject *subject); NMAuthSubjectType nm_auth_subject_get_subject_type (NMAuthSubject *subject);

View file

@ -34,7 +34,7 @@ struct NMAuthChain {
GSList *calls; GSList *calls;
GHashTable *data; GHashTable *data;
DBusGMethodInvocation *context; GDBusMethodInvocation *context;
NMAuthSubject *subject; NMAuthSubject *subject;
GError *error; GError *error;
@ -83,7 +83,7 @@ auth_chain_finish (gpointer user_data)
/* Creates the NMAuthSubject automatically */ /* Creates the NMAuthSubject automatically */
NMAuthChain * NMAuthChain *
nm_auth_chain_new_context (DBusGMethodInvocation *context, nm_auth_chain_new_context (GDBusMethodInvocation *context,
NMAuthChainResultFunc done_func, NMAuthChainResultFunc done_func,
gpointer user_data) gpointer user_data)
{ {
@ -107,7 +107,7 @@ nm_auth_chain_new_context (DBusGMethodInvocation *context,
/* Requires an NMAuthSubject */ /* Requires an NMAuthSubject */
NMAuthChain * NMAuthChain *
nm_auth_chain_new_subject (NMAuthSubject *subject, nm_auth_chain_new_subject (NMAuthSubject *subject,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthChainResultFunc done_func, NMAuthChainResultFunc done_func,
gpointer user_data) gpointer user_data)
{ {

View file

@ -21,8 +21,6 @@
#ifndef __NETWORKMANAGER_MANAGER_AUTH_H__ #ifndef __NETWORKMANAGER_MANAGER_AUTH_H__
#define __NETWORKMANAGER_MANAGER_AUTH_H__ #define __NETWORKMANAGER_MANAGER_AUTH_H__
#include <dbus/dbus-glib.h>
#include <nm-connection.h> #include <nm-connection.h>
#include "nm-default.h" #include "nm-default.h"
@ -50,15 +48,15 @@ typedef enum {
typedef void (*NMAuthChainResultFunc) (NMAuthChain *chain, typedef void (*NMAuthChainResultFunc) (NMAuthChain *chain,
GError *error, GError *error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data); gpointer user_data);
NMAuthChain *nm_auth_chain_new_context (DBusGMethodInvocation *context, NMAuthChain *nm_auth_chain_new_context (GDBusMethodInvocation *context,
NMAuthChainResultFunc done_func, NMAuthChainResultFunc done_func,
gpointer user_data); gpointer user_data);
NMAuthChain *nm_auth_chain_new_subject (NMAuthSubject *subject, NMAuthChain *nm_auth_chain_new_subject (NMAuthSubject *subject,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthChainResultFunc done_func, NMAuthChainResultFunc done_func,
gpointer user_data); gpointer user_data);

View file

@ -29,10 +29,9 @@
#include "nm-default.h" #include "nm-default.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-bus-manager.h" #include "nm-bus-manager.h"
#include "nm-core-internal.h"
#include "nm-dbus-compat.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <string.h> #include <string.h>
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@ -41,7 +40,6 @@
enum { enum {
DBUS_CONNECTION_CHANGED = 0, DBUS_CONNECTION_CHANGED = 0,
NAME_OWNER_CHANGED,
PRIVATE_CONNECTION_NEW, PRIVATE_CONNECTION_NEW,
PRIVATE_CONNECTION_DISCONNECTED, PRIVATE_CONNECTION_DISCONNECTED,
NUMBER_OF_SIGNALS NUMBER_OF_SIGNALS
@ -58,22 +56,21 @@ G_DEFINE_TYPE(NMBusManager, nm_bus_manager, G_TYPE_OBJECT)
typedef struct _PrivateServer PrivateServer; typedef struct _PrivateServer PrivateServer;
typedef struct { typedef struct {
DBusConnection *connection; GDBusConnection *connection;
DBusGConnection *g_connection;
GHashTable *exported; GHashTable *exported;
gboolean started; gboolean started;
GSList *private_servers; GSList *private_servers;
PrivateServer *priv_server; PrivateServer *priv_server;
DBusGProxy *proxy; GDBusProxy *proxy;
guint proxy_destroy_id;
guint bus_closed_id;
guint reconnect_id; guint reconnect_id;
} NMBusManagerPrivate; } NMBusManagerPrivate;
static gboolean nm_bus_manager_init_bus (NMBusManager *self); static gboolean nm_bus_manager_init_bus (NMBusManager *self);
static void nm_bus_manager_cleanup (NMBusManager *self, gboolean dispose); static void nm_bus_manager_cleanup (NMBusManager *self);
static void start_reconnection_timeout (NMBusManager *self); static void start_reconnection_timeout (NMBusManager *self);
static void object_destroyed (NMBusManager *self, gpointer object); static void object_destroyed (NMBusManager *self, gpointer object);
@ -111,82 +108,73 @@ struct _PrivateServer {
const char *tag; const char *tag;
GQuark detail; GQuark detail;
char *address; char *address;
DBusServer *server; GDBusServer *server;
GHashTable *connections; GHashTable *connections;
NMBusManager *manager; NMBusManager *manager;
}; };
static DBusHandlerResult static void
private_server_message_filter (DBusConnection *conn, private_server_closed (GDBusConnection *conn,
DBusMessage *message, gboolean remote_peer_vanished,
void *data) GError *error,
gpointer user_data)
{ {
PrivateServer *s = data; PrivateServer *s = user_data;
int fd;
/* Clean up after the connection */ /* Clean up after the connection */
if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) { nm_log_dbg (LOGD_CORE, "(%s) closed connection %p on private socket.",
nm_log_dbg (LOGD_CORE, "(%s) closed connection %p on private socket (fd %d).", s->tag, conn);
s->tag, conn, dbus_connection_get_unix_fd (conn, &fd) ? fd : -1);
/* Emit this for the manager */ /* Emit this for the manager */
g_signal_emit (s->manager, g_signal_emit (s->manager,
signals[PRIVATE_CONNECTION_DISCONNECTED], signals[PRIVATE_CONNECTION_DISCONNECTED],
s->detail, s->detail,
dbus_connection_get_g_connection (conn)); conn);
g_hash_table_remove (s->connections, conn); g_hash_table_remove (s->connections, conn);
/* Let dbus-glib process the message too */
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} }
static dbus_bool_t static gboolean
allow_only_root (DBusConnection *connection, unsigned long uid, void *data) private_server_new_connection (GDBusServer *server,
{ GDBusConnection *conn,
return uid == 0;
}
static void
private_server_new_connection (DBusServer *server,
DBusConnection *conn,
gpointer user_data) gpointer user_data)
{ {
PrivateServer *s = user_data; PrivateServer *s = user_data;
static guint32 counter = 0; static guint32 counter = 0;
char *sender; char *sender;
int fd;
if (!dbus_connection_add_filter (conn, private_server_message_filter, s, NULL)) { g_signal_connect (conn, "closed", G_CALLBACK (private_server_closed), s);
dbus_connection_close (conn);
return;
}
dbus_connection_set_unix_user_function (conn, allow_only_root, NULL, NULL);
dbus_connection_setup_with_g_main (conn, NULL);
/* Fake a sender since private connections don't have one */ /* Fake a sender since private connections don't have one */
sender = g_strdup_printf ("x:y:%d", counter++); sender = g_strdup_printf ("x:y:%d", counter++);
g_hash_table_insert (s->connections, dbus_connection_ref (conn), sender); g_hash_table_insert (s->connections, g_object_ref (conn), sender);
nm_log_dbg (LOGD_CORE, "(%s) accepted connection %p on private socket (fd %d).", nm_log_dbg (LOGD_CORE, "(%s) accepted connection %p on private socket.",
s->tag, conn, dbus_connection_get_unix_fd (conn, &fd) ? fd : -1); s->tag, conn);
/* Emit this for the manager */ /* Emit this for the manager */
g_signal_emit (s->manager, g_signal_emit (s->manager,
signals[PRIVATE_CONNECTION_NEW], signals[PRIVATE_CONNECTION_NEW],
s->detail, s->detail,
dbus_connection_get_g_connection (conn)); conn);
return TRUE;
} }
static void static void
private_server_dbus_connection_destroy (DBusConnection *conn) private_server_dbus_connection_destroy (GDBusConnection *conn)
{ {
if (dbus_connection_get_is_connected (conn)) if (!g_dbus_connection_is_closed (conn))
dbus_connection_close (conn); g_dbus_connection_close (conn, NULL, NULL, NULL);
dbus_connection_unref (conn); g_object_unref (conn);
}
static gboolean
private_server_authorize (GDBusAuthObserver *observer,
GIOStream *stream,
GCredentials *credentials,
gpointer user_data)
{
return g_credentials_get_unix_user (credentials, NULL) == 0;
} }
static PrivateServer * static PrivateServer *
@ -195,21 +183,32 @@ private_server_new (const char *path,
NMBusManager *manager) NMBusManager *manager)
{ {
PrivateServer *s; PrivateServer *s;
DBusServer *server; GDBusAuthObserver *auth_observer;
DBusError error; GDBusServer *server;
char *address; GError *error = NULL;
char *address, *guid;
unlink (path); unlink (path);
address = g_strdup_printf ("unix:path=%s", path); address = g_strdup_printf ("unix:path=%s", path);
nm_log_dbg (LOGD_CORE, "(%s) creating private socket %s.", tag, address); nm_log_dbg (LOGD_CORE, "(%s) creating private socket %s.", tag, address);
dbus_error_init (&error); guid = g_dbus_generate_guid ();
server = dbus_server_listen (address, &error); auth_observer = g_dbus_auth_observer_new ();
g_signal_connect (auth_observer, "authorize-authenticated-peer",
G_CALLBACK (private_server_authorize), NULL);
server = g_dbus_server_new_sync (address,
G_DBUS_SERVER_FLAGS_NONE,
guid,
auth_observer,
NULL, &error);
g_free (guid);
g_object_unref (auth_observer);
if (!server) { if (!server) {
nm_log_warn (LOGD_CORE, "(%s) failed to set up private socket %s: %s", nm_log_warn (LOGD_CORE, "(%s) failed to set up private socket %s: %s",
tag, address, error.message); tag, address, error->message);
dbus_error_free (&error); g_error_free (error);
g_free (address); g_free (address);
return NULL; return NULL;
} }
@ -217,8 +216,8 @@ private_server_new (const char *path,
s = g_malloc0 (sizeof (*s)); s = g_malloc0 (sizeof (*s));
s->address = address; s->address = address;
s->server = server; s->server = server;
dbus_server_setup_with_g_main (s->server, NULL); g_signal_connect (server, "new-connection",
dbus_server_set_new_connection_function (s->server, private_server_new_connection, s, NULL); G_CALLBACK (private_server_new_connection), s);
s->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, s->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal,
(GDestroyNotify) private_server_dbus_connection_destroy, (GDestroyNotify) private_server_dbus_connection_destroy,
@ -227,6 +226,8 @@ private_server_new (const char *path,
s->detail = g_quark_from_string (tag); s->detail = g_quark_from_string (tag);
s->tag = g_quark_to_string (s->detail); s->tag = g_quark_to_string (s->detail);
g_dbus_server_start (server);
return s; return s;
} }
@ -238,8 +239,10 @@ private_server_free (gpointer ptr)
unlink (s->address); unlink (s->address);
g_free (s->address); g_free (s->address);
g_hash_table_destroy (s->connections); g_hash_table_destroy (s->connections);
dbus_server_disconnect (s->server);
dbus_server_unref (s->server); g_dbus_server_stop (s->server);
g_object_unref (s->server);
memset (s, 0, sizeof (*s)); memset (s, 0, sizeof (*s));
g_free (s); g_free (s);
} }
@ -253,10 +256,6 @@ nm_bus_manager_private_server_register (NMBusManager *self,
PrivateServer *s; PrivateServer *s;
GSList *iter; GSList *iter;
#if !HAVE_DBUS_GLIB_100
g_assert_not_reached ();
#endif
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
g_return_if_fail (path != NULL); g_return_if_fail (path != NULL);
g_return_if_fail (tag != NULL); g_return_if_fail (tag != NULL);
@ -274,12 +273,12 @@ nm_bus_manager_private_server_register (NMBusManager *self,
} }
static const char * static const char *
private_server_get_connection_owner (PrivateServer *s, DBusGConnection *connection) private_server_get_connection_owner (PrivateServer *s, GDBusConnection *connection)
{ {
g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (s != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL);
return g_hash_table_lookup (s->connections, dbus_g_connection_get_connection (connection)); return g_hash_table_lookup (s->connections, connection);
} }
/**************************************************************/ /**************************************************************/
@ -291,52 +290,74 @@ _bus_get_unix_pid (NMBusManager *self,
GError **error) GError **error)
{ {
guint32 unix_pid = G_MAXUINT32; guint32 unix_pid = G_MAXUINT32;
GVariant *ret;
if (!dbus_g_proxy_call_with_timeout (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy, ret = _nm_dbus_proxy_call_sync (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy,
"GetConnectionUnixProcessID", 2000, error, "GetConnectionUnixProcessID",
G_TYPE_STRING, sender, g_variant_new ("(s)", sender),
G_TYPE_INVALID, G_VARIANT_TYPE ("(u)"),
G_TYPE_UINT, &unix_pid, G_DBUS_CALL_FLAGS_NONE, 2000,
G_TYPE_INVALID)) { NULL, error);
if (!ret)
return FALSE; return FALSE;
}
g_variant_get (ret, "(u)", &unix_pid);
*out_pid = (gulong) unix_pid; *out_pid = (gulong) unix_pid;
return TRUE; return TRUE;
} }
static gboolean
_bus_get_unix_user (NMBusManager *self,
const char *sender,
gulong *out_user,
GError **error)
{
guint32 unix_uid = G_MAXUINT32;
GVariant *ret;
ret = _nm_dbus_proxy_call_sync (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy,
"GetConnectionUnixUser",
g_variant_new ("(s)", sender),
G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE, 2000,
NULL, error);
if (!ret)
return FALSE;
g_variant_get (ret, "(u)", &unix_uid);
*out_user = (gulong) unix_uid;
return TRUE;
}
/** /**
* _get_caller_info_from_context(): * _get_caller_info():
* *
* Given a dbus-glib method invocation, or a DBusConnection + DBusMessage, * Given a GDBus method invocation, or a GDBusConnection + GDBusMessage,
* return the sender and the UID of the sender. * return the sender and the UID of the sender.
*/ */
static gboolean static gboolean
_get_caller_info (NMBusManager *self, _get_caller_info (NMBusManager *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
DBusConnection *connection, GDBusConnection *connection,
DBusMessage *message, GDBusMessage *message,
char **out_sender, char **out_sender,
gulong *out_uid, gulong *out_uid,
gulong *out_pid) gulong *out_pid)
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
DBusGConnection *gconn; const char *sender;
char *sender;
const char *priv_sender;
DBusError error;
GSList *iter; GSList *iter;
if (context) { if (context) {
gconn = dbus_g_method_invocation_get_g_connection (context); connection = g_dbus_method_invocation_get_connection (context);
g_assert (gconn);
connection = dbus_g_connection_get_connection (gconn);
/* only bus connections will have a sender */ /* only bus connections will have a sender */
sender = dbus_g_method_get_sender (context); sender = g_dbus_method_invocation_get_sender (context);
} else { } else {
g_assert (message); g_assert (message);
sender = g_strdup (dbus_message_get_sender (message)); sender = g_dbus_message_get_sender (message);
} }
g_assert (connection); g_assert (connection);
@ -345,14 +366,25 @@ _get_caller_info (NMBusManager *self,
for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) { for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) {
PrivateServer *s = iter->data; PrivateServer *s = iter->data;
priv_sender = g_hash_table_lookup (s->connections, connection); sender = g_hash_table_lookup (s->connections, connection);
if (priv_sender) { if (sender) {
if (out_uid) if (out_uid)
*out_uid = 0; *out_uid = 0;
if (out_sender) if (out_sender)
*out_sender = g_strdup (priv_sender); *out_sender = g_strdup (sender);
if (out_pid) { if (out_pid) {
if (!dbus_connection_get_unix_process_id (connection, out_pid)) GCredentials *creds;
creds = g_dbus_connection_get_peer_credentials (connection);
if (creds) {
pid_t pid;
pid = g_credentials_get_unix_pid (creds, NULL);
if (pid == -1)
*out_pid = G_MAXULONG;
else
*out_pid = pid;
} else
*out_pid = G_MAXULONG; *out_pid = G_MAXULONG;
} }
return TRUE; return TRUE;
@ -364,12 +396,8 @@ _get_caller_info (NMBusManager *self,
/* Bus connections always have a sender */ /* Bus connections always have a sender */
g_assert (sender); g_assert (sender);
if (out_uid) { if (out_uid) {
dbus_error_init (&error); if (!_bus_get_unix_user (self, sender, out_uid, NULL)) {
*out_uid = dbus_bus_get_unix_user (connection, sender, &error);
if (dbus_error_is_set (&error)) {
dbus_error_free (&error);
*out_uid = G_MAXULONG; *out_uid = G_MAXULONG;
g_free (sender);
return FALSE; return FALSE;
} }
} }
@ -377,7 +405,6 @@ _get_caller_info (NMBusManager *self,
if (out_pid) { if (out_pid) {
if (!_bus_get_unix_pid (self, sender, out_pid, NULL)) { if (!_bus_get_unix_pid (self, sender, out_pid, NULL)) {
*out_pid = G_MAXULONG; *out_pid = G_MAXULONG;
g_free (sender);
return FALSE; return FALSE;
} }
} }
@ -385,13 +412,12 @@ _get_caller_info (NMBusManager *self,
if (out_sender) if (out_sender)
*out_sender = g_strdup (sender); *out_sender = g_strdup (sender);
g_free (sender);
return TRUE; return TRUE;
} }
gboolean gboolean
nm_bus_manager_get_caller_info (NMBusManager *self, nm_bus_manager_get_caller_info (NMBusManager *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
char **out_sender, char **out_sender,
gulong *out_uid, gulong *out_uid,
gulong *out_pid) gulong *out_pid)
@ -401,8 +427,8 @@ nm_bus_manager_get_caller_info (NMBusManager *self,
gboolean gboolean
nm_bus_manager_get_caller_info_from_message (NMBusManager *self, nm_bus_manager_get_caller_info_from_message (NMBusManager *self,
DBusConnection *connection, GDBusConnection *connection,
DBusMessage *message, GDBusMessage *message,
char **out_sender, char **out_sender,
gulong *out_uid, gulong *out_uid,
gulong *out_pid) gulong *out_pid)
@ -417,7 +443,7 @@ nm_bus_manager_get_unix_user (NMBusManager *self,
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
GSList *iter; GSList *iter;
DBusError error; GError *error = NULL;
g_return_val_if_fail (sender != NULL, FALSE); g_return_val_if_fail (sender != NULL, FALSE);
g_return_val_if_fail (out_uid != NULL, FALSE); g_return_val_if_fail (out_uid != NULL, FALSE);
@ -438,11 +464,10 @@ nm_bus_manager_get_unix_user (NMBusManager *self,
} }
/* Otherwise, a bus connection */ /* Otherwise, a bus connection */
dbus_error_init (&error); if (!_bus_get_unix_user (self, sender, out_uid, &error)) {
*out_uid = dbus_bus_get_unix_user (priv->connection, sender, &error);
if (dbus_error_is_set (&error)) {
nm_log_warn (LOGD_CORE, "Failed to get unix user for dbus sender '%s': %s", nm_log_warn (LOGD_CORE, "Failed to get unix user for dbus sender '%s': %s",
sender, error.message); sender, error->message);
g_error_free (error);
return FALSE; return FALSE;
} }
@ -451,38 +476,30 @@ nm_bus_manager_get_unix_user (NMBusManager *self,
/**************************************************************/ /**************************************************************/
#if HAVE_DBUS_GLIB_100
static void static void
private_connection_new (NMBusManager *self, DBusGConnection *connection) private_connection_new (NMBusManager *self, GDBusConnection *connection)
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
GHashTableIter iter; GHashTableIter iter;
GObject *object; GDBusInterfaceSkeleton *interface;
const char *path; const char *path;
GError *error = NULL;
/* Register all exported objects on this private connection */ /* Register all exported objects on this private connection */
g_hash_table_iter_init (&iter, priv->exported); g_hash_table_iter_init (&iter, priv->exported);
while (g_hash_table_iter_next (&iter, (gpointer) &object, (gpointer) &path)) { while (g_hash_table_iter_next (&iter, (gpointer) &interface, (gpointer) &path)) {
dbus_g_connection_register_g_object (connection, path, object); if (g_dbus_interface_skeleton_export (interface, connection, path, &error)) {
nm_log_trace (LOGD_CORE, "(%s) registered %p (%s) at '%s' on private socket.", nm_log_trace (LOGD_CORE, "(%s) registered %p (%s) at '%s' on private socket.",
PRIV_SOCK_TAG, object, G_OBJECT_TYPE_NAME (object), path); PRIV_SOCK_TAG, interface, G_OBJECT_TYPE_NAME (interface), path);
} else {
nm_log_warn (LOGD_CORE, "(%s) could not register %p (%s) at '%s' on private socket: %s.",
PRIV_SOCK_TAG, interface, G_OBJECT_TYPE_NAME (interface), path,
error->message);
g_clear_error (&error);
}
} }
} }
static void
private_connection_disconnected (NMBusManager *self, DBusGConnection *connection)
{
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
const char *owner;
owner = private_server_get_connection_owner (priv->priv_server, connection);
g_assert (owner);
/* Fake a NameOwnerChanged to let listerners know this owner has quit */
g_signal_emit (G_OBJECT (self), signals[NAME_OWNER_CHANGED],
0, owner, owner, NULL);
}
static void static void
private_server_setup (NMBusManager *self) private_server_setup (NMBusManager *self)
{ {
@ -500,18 +517,12 @@ private_server_setup (NMBusManager *self)
priv->priv_server = private_server_new (PRIV_SOCK_PATH, PRIV_SOCK_TAG, self); priv->priv_server = private_server_new (PRIV_SOCK_PATH, PRIV_SOCK_TAG, self);
if (priv->priv_server) { if (priv->priv_server) {
priv->private_servers = g_slist_append (priv->private_servers, priv->priv_server); priv->private_servers = g_slist_append (priv->private_servers, priv->priv_server);
g_signal_connect (self, g_signal_connect (self,
NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW "::" PRIV_SOCK_TAG, NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW "::" PRIV_SOCK_TAG,
(GCallback) private_connection_new, (GCallback) private_connection_new,
NULL); NULL);
g_signal_connect (self,
NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG,
(GCallback) private_connection_disconnected,
NULL);
} }
} }
#endif /* HAVE_DBUS_GLIB_100 */
static void static void
nm_bus_manager_init (NMBusManager *self) nm_bus_manager_init (NMBusManager *self)
@ -520,9 +531,7 @@ nm_bus_manager_init (NMBusManager *self)
priv->exported = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); priv->exported = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
#if HAVE_DBUS_GLIB_100
private_server_setup (self); private_server_setup (self);
#endif
} }
static void static void
@ -546,7 +555,7 @@ nm_bus_manager_dispose (GObject *object)
priv->private_servers = NULL; priv->private_servers = NULL;
priv->priv_server = NULL; priv->priv_server = NULL;
nm_bus_manager_cleanup (self, TRUE); nm_bus_manager_cleanup (self);
if (priv->reconnect_id) { if (priv->reconnect_id) {
g_source_remove (priv->reconnect_id); g_source_remove (priv->reconnect_id);
@ -573,14 +582,6 @@ nm_bus_manager_class_init (NMBusManagerClass *klass)
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_POINTER); G_TYPE_NONE, 1, G_TYPE_POINTER);
signals[NAME_OWNER_CHANGED] =
g_signal_new (NM_BUS_MANAGER_NAME_OWNER_CHANGED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NMBusManagerClass, name_owner_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
signals[PRIVATE_CONNECTION_NEW] = signals[PRIVATE_CONNECTION_NEW] =
g_signal_new (NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW, g_signal_new (NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW,
G_OBJECT_CLASS_TYPE (object_class), G_OBJECT_CLASS_TYPE (object_class),
@ -601,23 +602,16 @@ nm_bus_manager_class_init (NMBusManagerClass *klass)
/* Only cleanup a specific dbus connection, not all our private data */ /* Only cleanup a specific dbus connection, not all our private data */
static void static void
nm_bus_manager_cleanup (NMBusManager *self, gboolean dispose) nm_bus_manager_cleanup (NMBusManager *self)
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
if (priv->proxy) { g_clear_object (&priv->proxy);
if (dispose) {
g_signal_handler_disconnect (priv->proxy, priv->proxy_destroy_id);
priv->proxy_destroy_id = 0;
}
g_object_unref (priv->proxy);
priv->proxy = NULL;
}
if (priv->g_connection) { if (priv->connection) {
dbus_g_connection_unref (priv->g_connection); g_signal_handler_disconnect (priv->connection, priv->bus_closed_id);
priv->g_connection = NULL; priv->bus_closed_id = 0;
priv->connection = NULL; g_clear_object (&priv->connection);
} }
priv->started = FALSE; priv->started = FALSE;
@ -642,7 +636,7 @@ nm_bus_manager_reconnect (gpointer user_data)
} }
/* Try again */ /* Try again */
nm_bus_manager_cleanup (self, FALSE); nm_bus_manager_cleanup (self);
return TRUE; return TRUE;
} }
@ -658,81 +652,18 @@ start_reconnection_timeout (NMBusManager *self)
priv->reconnect_id = g_timeout_add_seconds (3, nm_bus_manager_reconnect, self); priv->reconnect_id = g_timeout_add_seconds (3, nm_bus_manager_reconnect, self);
} }
char *
nm_bus_manager_get_name_owner (NMBusManager *self,
const char *name,
GError **error)
{
char *owner = NULL;
g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL);
g_return_val_if_fail (name != NULL, NULL);
if (error)
g_return_val_if_fail (*error == NULL, NULL);
if (!NM_BUS_MANAGER_GET_PRIVATE (self)->proxy)
return NULL;
if (!dbus_g_proxy_call_with_timeout (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy,
"GetNameOwner", 2000, error,
G_TYPE_STRING, name,
G_TYPE_INVALID,
G_TYPE_STRING, &owner,
G_TYPE_INVALID)) {
return NULL;
}
return owner;
}
gboolean
nm_bus_manager_name_has_owner (NMBusManager *self,
const char *name)
{
gboolean has_owner = FALSE;
GError *err = NULL;
g_return_val_if_fail (NM_IS_BUS_MANAGER (self), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
if (!NM_BUS_MANAGER_GET_PRIVATE (self)->proxy)
return FALSE;
if (!dbus_g_proxy_call (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy,
"NameHasOwner", &err,
G_TYPE_STRING, name,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &has_owner,
G_TYPE_INVALID)) {
nm_log_warn (LOGD_CORE, "NameHasOwner request failed: %s",
(err && err->message) ? err->message : "(unknown)");
g_clear_error (&err);
}
return has_owner;
}
static void static void
proxy_name_owner_changed (DBusGProxy *proxy, closed_cb (GDBusConnection *connection,
const char *name, gboolean remote_peer_vanished,
const char *old_owner, GError *error,
const char *new_owner, gpointer user_data)
gpointer user_data)
{
g_signal_emit (G_OBJECT (user_data), signals[NAME_OWNER_CHANGED],
0, name, old_owner, new_owner);
}
static void
destroy_cb (DBusGProxy *proxy, gpointer user_data)
{ {
NMBusManager *self = NM_BUS_MANAGER (user_data); NMBusManager *self = NM_BUS_MANAGER (user_data);
/* Clean up existing connection */ /* Clean up existing connection */
nm_log_warn (LOGD_CORE, "disconnected by the system bus."); nm_log_warn (LOGD_CORE, "disconnected by the system bus.");
NM_BUS_MANAGER_GET_PRIVATE (self)->proxy = NULL;
nm_bus_manager_cleanup (self, FALSE); nm_bus_manager_cleanup (self);
g_signal_emit (G_OBJECT (self), signals[DBUS_CONNECTION_CHANGED], 0, NULL); g_signal_emit (G_OBJECT (self), signals[DBUS_CONNECTION_CHANGED], 0, NULL);
@ -743,43 +674,47 @@ static gboolean
nm_bus_manager_init_bus (NMBusManager *self) nm_bus_manager_init_bus (NMBusManager *self)
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
GError *error = NULL;
if (priv->connection) { if (priv->connection) {
nm_log_warn (LOGD_CORE, "DBus Manager already has a valid connection."); nm_log_warn (LOGD_CORE, "DBus Manager already has a valid connection.");
return FALSE; return FALSE;
} }
dbus_connection_set_change_sigpipe (TRUE); priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!priv->connection) {
priv->g_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
if (!priv->g_connection) {
/* Log with 'info' severity; there won't be a bus daemon in minimal /* Log with 'info' severity; there won't be a bus daemon in minimal
* environments (eg, initrd) where we only want to use the private * environments (eg, initrd) where we only want to use the private
* socket. * socket.
*/ */
nm_log_info (LOGD_CORE, "Could not connect to the system bus; only the " nm_log_info (LOGD_CORE, "Could not connect to the system bus (%s); only the "
"private D-Bus socket will be available."); "private D-Bus socket will be available.",
error->message);
g_error_free (error);
return FALSE; return FALSE;
} }
priv->connection = dbus_g_connection_get_connection (priv->g_connection); g_dbus_connection_set_exit_on_close (priv->connection, FALSE);
dbus_connection_set_exit_on_disconnect (priv->connection, FALSE); priv->bus_closed_id = g_signal_connect (priv->connection, "closed",
G_CALLBACK (closed_cb), self);
priv->proxy = dbus_g_proxy_new_for_name (priv->g_connection, priv->proxy = g_dbus_proxy_new_sync (priv->connection,
DBUS_SERVICE_DBUS, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
DBUS_PATH_DBUS, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
DBUS_INTERFACE_DBUS); NULL,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
NULL, &error);
if (!priv->proxy) {
g_clear_object (&priv->connection);
nm_log_warn (LOGD_CORE, "Could not create org.freedesktop.DBus proxy (%s); only the "
"private D-Bus socket will be available.",
error->message);
g_error_free (error);
return FALSE;
}
priv->proxy_destroy_id = g_signal_connect (priv->proxy, "destroy",
G_CALLBACK (destroy_cb), self);
dbus_g_proxy_add_signal (priv->proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
self, NULL);
return TRUE; return TRUE;
} }
@ -791,6 +726,7 @@ gboolean
nm_bus_manager_start_service (NMBusManager *self) nm_bus_manager_start_service (NMBusManager *self)
{ {
NMBusManagerPrivate *priv; NMBusManagerPrivate *priv;
GVariant *ret;
int result; int result;
GError *err = NULL; GError *err = NULL;
@ -807,19 +743,23 @@ nm_bus_manager_start_service (NMBusManager *self)
if (!priv->proxy) if (!priv->proxy)
return FALSE; return FALSE;
if (!dbus_g_proxy_call (priv->proxy, "RequestName", &err, ret = _nm_dbus_proxy_call_sync (priv->proxy,
G_TYPE_STRING, NM_DBUS_SERVICE, "RequestName",
G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, g_variant_new ("(su)",
G_TYPE_INVALID, NM_DBUS_SERVICE,
G_TYPE_UINT, &result, DBUS_NAME_FLAG_DO_NOT_QUEUE),
G_TYPE_INVALID)) { G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL, &err);
if (!ret) {
nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service.\n" nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service.\n"
" Error: '%s'", " Error: '%s'", err->message);
(err && err->message) ? err->message : "(unknown)");
g_error_free (err); g_error_free (err);
return FALSE; return FALSE;
} }
g_variant_get (ret, "(u)", &result);
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service as it is already taken."); nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service as it is already taken.");
return FALSE; return FALSE;
@ -829,20 +769,12 @@ nm_bus_manager_start_service (NMBusManager *self)
return priv->started; return priv->started;
} }
DBusConnection * GDBusConnection *
nm_bus_manager_get_dbus_connection (NMBusManager *self)
{
g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL);
return NM_BUS_MANAGER_GET_PRIVATE (self)->connection;
}
DBusGConnection *
nm_bus_manager_get_connection (NMBusManager *self) nm_bus_manager_get_connection (NMBusManager *self)
{ {
g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL); g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL);
return NM_BUS_MANAGER_GET_PRIVATE (self)->g_connection; return NM_BUS_MANAGER_GET_PRIVATE (self)->connection;
} }
static void static void
@ -858,9 +790,9 @@ nm_bus_manager_register_object (NMBusManager *self,
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
GHashTableIter iter; GHashTableIter iter;
DBusConnection *connection; GDBusConnection *connection;
g_assert (G_IS_OBJECT (object)); g_assert (G_IS_DBUS_INTERFACE_SKELETON (object));
if (g_hash_table_lookup (priv->exported, G_OBJECT (object))) if (g_hash_table_lookup (priv->exported, G_OBJECT (object)))
g_return_if_reached (); g_return_if_reached ();
@ -868,27 +800,43 @@ nm_bus_manager_register_object (NMBusManager *self,
g_hash_table_insert (priv->exported, G_OBJECT (object), g_strdup (path)); g_hash_table_insert (priv->exported, G_OBJECT (object), g_strdup (path));
g_object_weak_ref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); g_object_weak_ref (G_OBJECT (object), (GWeakNotify) object_destroyed, self);
if (priv->g_connection) if (priv->connection) {
dbus_g_connection_register_g_object (priv->g_connection, path, G_OBJECT (object)); g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (object),
priv->connection, path, NULL);
}
if (priv->priv_server) { if (priv->priv_server) {
g_hash_table_iter_init (&iter, priv->priv_server->connections); g_hash_table_iter_init (&iter, priv->priv_server->connections);
while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) { while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) {
dbus_g_connection_register_g_object (dbus_connection_get_g_connection (connection), g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (object),
path, connection, path, NULL);
G_OBJECT (object));
} }
} }
} }
gpointer
nm_bus_manager_get_registered_object (NMBusManager *self,
const char *path)
{
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
GObject *object;
const char *export_path;
g_hash_table_iter_init (&iter, priv->exported);
while (g_hash_table_iter_next (&iter, (gpointer *) &object, (gpointer *) &export_path)) {
if (!strcmp (path, export_path))
return object;
}
return NULL;
}
void void
nm_bus_manager_unregister_object (NMBusManager *self, gpointer object) nm_bus_manager_unregister_object (NMBusManager *self, gpointer object)
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
DBusConnection *connection;
g_assert (G_IS_OBJECT (object)); g_assert (G_IS_DBUS_INTERFACE_SKELETON (object));
if (!g_hash_table_lookup (priv->exported, G_OBJECT (object))) if (!g_hash_table_lookup (priv->exported, G_OBJECT (object)))
g_return_if_reached (); g_return_if_reached ();
@ -896,74 +844,69 @@ nm_bus_manager_unregister_object (NMBusManager *self, gpointer object)
g_hash_table_remove (priv->exported, G_OBJECT (object)); g_hash_table_remove (priv->exported, G_OBJECT (object));
g_object_weak_unref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); g_object_weak_unref (G_OBJECT (object), (GWeakNotify) object_destroyed, self);
if (priv->g_connection) g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
dbus_g_connection_unregister_g_object (priv->g_connection, G_OBJECT (object));
if (priv->priv_server) {
g_hash_table_iter_init (&iter, priv->priv_server->connections);
while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) {
dbus_g_connection_unregister_g_object (dbus_connection_get_g_connection (connection),
G_OBJECT (object));
}
}
} }
/** /**
* nm_bus_manager_new_proxy: * nm_bus_manager_new_proxy:
* @self: the #NMBusManager * @self: the #NMBusManager
* @context: the method call context this proxy should be created * @context: the method call context this proxy should be created
* @proxy_type: the type of #GDBusProxy to create
* @name: any name on the message bus * @name: any name on the message bus
* @path: name of the object instance to call methods on * @path: name of the object instance to call methods on
* @iface: name of the interface to call methods on * @iface: name of the interface to call methods on
* *
* Creates a new proxy for a name on a given bus. Since the process which * Creates a new proxy (of type @proxy_type) for a name on a given bus. Since
* called the D-Bus method could be coming from a private connection or the * the process which called the D-Bus method could be coming from a private
* system bus connection, differnet proxies must be created for each case. This * connection or the system bus connection, different proxies must be created
* function abstracts that. * for each case. This function abstracts that.
* *
* Returns: a #DBusGProxy capable of calling D-Bus methods of the calling process * Returns: a #GDBusProxy capable of calling D-Bus methods of the calling process
*/ */
DBusGProxy * GDBusProxy *
nm_bus_manager_new_proxy (NMBusManager *self, nm_bus_manager_new_proxy (NMBusManager *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
GType proxy_type,
const char *name, const char *name,
const char *path, const char *path,
const char *iface) const char *iface)
{ {
NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self);
DBusGConnection *connection; GDBusConnection *connection;
GSList *iter; GSList *iter;
const char *owner; const char *owner;
GDBusProxy *proxy;
GError *error = NULL;
connection = dbus_g_method_invocation_get_g_connection (context); g_return_val_if_fail (g_type_is_a (proxy_type, G_TYPE_DBUS_PROXY), NULL);
connection = g_dbus_method_invocation_get_connection (context);
g_assert (connection); g_assert (connection);
/* Might be a private connection, for which we fake a sender */ /* Might be a private connection, for which @name is fake */
for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) { for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) {
PrivateServer *s = iter->data; PrivateServer *s = iter->data;
owner = private_server_get_connection_owner (s, connection); owner = private_server_get_connection_owner (s, connection);
if (owner) { if (owner) {
g_assert_cmpstr (owner, ==, name); g_assert_cmpstr (owner, ==, name);
return dbus_g_proxy_new_for_peer (connection, path, iface); name = NULL;
break;
} }
} }
return dbus_g_proxy_new_for_name (connection, name, path, iface); proxy = g_initable_new (proxy_type, NULL, &error,
"g-connection", connection,
"g-flags", (G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS),
"g-name", name,
"g-object-path", path,
"g-interface-name", iface,
NULL);
if (!proxy) {
nm_log_warn (LOGD_CORE, "Could not create proxy for %s on connection %s: %s",
iface, name, error->message);
g_error_free (error);
}
return proxy;
} }
#if !HAVE_DBUS_GLIB_GMI_GET_CONNECTION
struct _HACKDBusGMethodInvocation {
DBusGConnection *connection;
/* ... */
};
DBusGConnection *
dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context)
{
/* Evil hack; this method exists in dbus-glib >= 101, but if we don't
* have that, emulate it.
*/
return ((struct _HACKDBusGMethodInvocation *) context)->connection;
}
#endif /* HAVE_DBUS_GLIB_GMI_GET_CONNECTION */

View file

@ -23,17 +23,11 @@
#define __NM_BUS_MANAGER_H__ #define __NM_BUS_MANAGER_H__
#include "config.h" #include "config.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include "nm-default.h" #include "nm-default.h"
G_BEGIN_DECLS G_BEGIN_DECLS
typedef gboolean (* NMDBusSignalHandlerFunc) (DBusConnection * connection,
DBusMessage * message,
gpointer user_data);
#define NM_TYPE_BUS_MANAGER (nm_bus_manager_get_type ()) #define NM_TYPE_BUS_MANAGER (nm_bus_manager_get_type ())
#define NM_BUS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NM_TYPE_BUS_MANAGER, NMBusManager)) #define NM_BUS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NM_TYPE_BUS_MANAGER, NMBusManager))
#define NM_BUS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NM_TYPE_BUS_MANAGER, NMBusManagerClass)) #define NM_BUS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NM_TYPE_BUS_MANAGER, NMBusManagerClass))
@ -42,7 +36,6 @@ typedef gboolean (* NMDBusSignalHandlerFunc) (DBusConnection * connection,
#define NM_BUS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NM_TYPE_BUS_MANAGER, NMBusManagerClass)) #define NM_BUS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NM_TYPE_BUS_MANAGER, NMBusManagerClass))
#define NM_BUS_MANAGER_DBUS_CONNECTION_CHANGED "dbus-connection-changed" #define NM_BUS_MANAGER_DBUS_CONNECTION_CHANGED "dbus-connection-changed"
#define NM_BUS_MANAGER_NAME_OWNER_CHANGED "name-owner-changed"
#define NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW "private-connection-new" #define NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW "private-connection-new"
#define NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "private-connection-disconnected" #define NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "private-connection-disconnected"
@ -55,18 +48,13 @@ typedef struct {
/* Signals */ /* Signals */
void (*dbus_connection_changed) (NMBusManager *mgr, void (*dbus_connection_changed) (NMBusManager *mgr,
DBusConnection *connection); GDBusConnection *connection);
void (*name_owner_changed) (NMBusManager *mgr,
const char *name,
const char *old_owner,
const char *new_owner);
void (*private_connection_new) (NMBusManager *mgr, void (*private_connection_new) (NMBusManager *mgr,
DBusGConnection *connection); GDBusConnection *connection);
void (*private_connection_disconnected) (NMBusManager *mgr, void (*private_connection_disconnected) (NMBusManager *mgr,
DBusGConnection *connection); GDBusConnection *connection);
} NMBusManagerClass; } NMBusManagerClass;
GType nm_bus_manager_get_type (void); GType nm_bus_manager_get_type (void);
@ -74,20 +62,12 @@ GType nm_bus_manager_get_type (void);
NMBusManager * nm_bus_manager_get (void); NMBusManager * nm_bus_manager_get (void);
void nm_bus_manager_setup (NMBusManager *instance); void nm_bus_manager_setup (NMBusManager *instance);
char * nm_bus_manager_get_name_owner (NMBusManager *self,
const char *name,
GError **error);
gboolean nm_bus_manager_start_service (NMBusManager *self); gboolean nm_bus_manager_start_service (NMBusManager *self);
gboolean nm_bus_manager_name_has_owner (NMBusManager *self, GDBusConnection * nm_bus_manager_get_connection (NMBusManager *self);
const char *name);
DBusConnection * nm_bus_manager_get_dbus_connection (NMBusManager *self);
DBusGConnection * nm_bus_manager_get_connection (NMBusManager *self);
gboolean nm_bus_manager_get_caller_info (NMBusManager *self, gboolean nm_bus_manager_get_caller_info (NMBusManager *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
char **out_sender, char **out_sender,
gulong *out_uid, gulong *out_uid,
gulong *out_pid); gulong *out_pid);
@ -97,8 +77,8 @@ gboolean nm_bus_manager_get_unix_user (NMBusManager *self,
gulong *out_uid); gulong *out_uid);
gboolean nm_bus_manager_get_caller_info_from_message (NMBusManager *self, gboolean nm_bus_manager_get_caller_info_from_message (NMBusManager *self,
DBusConnection *connection, GDBusConnection *connection,
DBusMessage *message, GDBusMessage *message,
char **out_sender, char **out_sender,
gulong *out_uid, gulong *out_uid,
gulong *out_pid); gulong *out_pid);
@ -109,20 +89,20 @@ void nm_bus_manager_register_object (NMBusManager *self,
void nm_bus_manager_unregister_object (NMBusManager *self, gpointer object); void nm_bus_manager_unregister_object (NMBusManager *self, gpointer object);
gpointer nm_bus_manager_get_registered_object (NMBusManager *self,
const char *path);
void nm_bus_manager_private_server_register (NMBusManager *self, void nm_bus_manager_private_server_register (NMBusManager *self,
const char *path, const char *path,
const char *tag); const char *tag);
DBusGProxy *nm_bus_manager_new_proxy (NMBusManager *self, GDBusProxy *nm_bus_manager_new_proxy (NMBusManager *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
GType proxy_type,
const char *name, const char *name,
const char *path, const char *path,
const char *iface); const char *iface);
#if !HAVE_DBUS_GLIB_GMI_GET_CONNECTION
DBusGConnection *dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context);
#endif
G_END_DECLS G_END_DECLS
#endif /* __NM_BUS_MANAGER_H__ */ #endif /* __NM_BUS_MANAGER_H__ */

View file

@ -25,10 +25,10 @@
#include "nm-default.h" #include "nm-default.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-dhcp4-config.h" #include "nm-dhcp4-config.h"
#include "nm-dhcp4-config-glue.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nmdbus-dhcp4-config.h"
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate)) #define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate))
@ -128,11 +128,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case PROP_OPTIONS: case PROP_OPTIONS:
/* dbus_g_value_parse_g_variant() will call g_value_init(), but g_value_set_variant (value, priv->options);
* @value is already inited.
*/
g_value_unset (value);
dbus_g_value_parse_g_variant (priv->options, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -157,11 +153,13 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_OPTIONS, (object_class, PROP_OPTIONS,
g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "", g_param_spec_variant (NM_DHCP4_CONFIG_OPTIONS, "", "",
DBUS_TYPE_G_MAP_OF_VARIANT, G_VARIANT_TYPE ("a{sv}"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_dhcp4_config_object_info); NMDBUS_TYPE_DHCP4_CONFIG_SKELETON,
NULL);
} }

View file

@ -25,10 +25,10 @@
#include "nm-default.h" #include "nm-default.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-dhcp6-config.h" #include "nm-dhcp6-config.h"
#include "nm-dhcp6-config-glue.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nmdbus-dhcp6-config.h"
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate)) #define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate))
@ -128,11 +128,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case PROP_OPTIONS: case PROP_OPTIONS:
/* dbus_g_value_parse_g_variant() will call g_value_init(), but g_value_set_variant (value, priv->options);
* @value is already inited.
*/
g_value_unset (value);
dbus_g_value_parse_g_variant (priv->options, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -157,11 +153,13 @@ nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class)
/* properties */ /* properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_OPTIONS, (object_class, PROP_OPTIONS,
g_param_spec_boxed (NM_DHCP6_CONFIG_OPTIONS, "", "", g_param_spec_variant (NM_DHCP6_CONFIG_OPTIONS, "", "",
DBUS_TYPE_G_MAP_OF_VARIANT, G_VARIANT_TYPE ("a{sv}"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_dhcp6_config_object_info); NMDBUS_TYPE_DHCP6_CONFIG_SKELETON,
NULL);
} }

View file

@ -34,7 +34,6 @@
#include "nm-dhcp6-config.h" #include "nm-dhcp6-config.h"
#include "nm-ip4-config.h" #include "nm-ip4-config.h"
#include "nm-ip6-config.h" #include "nm-ip6-config.h"
#include "nm-dbus-glib-types.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"

View file

@ -20,10 +20,10 @@
#include "config.h" #include "config.h"
#include <stdarg.h>
#include <string.h> #include <string.h>
#include "nm-exported-object.h" #include "nm-exported-object.h"
#include "nm-dbus-glib-types.h"
#include "nm-bus-manager.h" #include "nm-bus-manager.h"
#include "nm-default.h" #include "nm-default.h"
@ -34,85 +34,374 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMExportedObject, nm_exported_object, G_TYPE_O
) )
typedef struct { typedef struct {
GSList *interfaces;
char *path; char *path;
GHashTable *pending_notifies; GVariantBuilder pending_notifies;
guint notify_idle_id; guint notify_idle_id;
} NMExportedObjectPrivate; } NMExportedObjectPrivate;
#define NM_EXPORTED_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_EXPORTED_OBJECT, NMExportedObjectPrivate)) #define NM_EXPORTED_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_EXPORTED_OBJECT, NMExportedObjectPrivate))
enum { typedef struct {
PROPERTIES_CHANGED, GType dbus_skeleton_type;
char *method_name;
LAST_SIGNAL GCallback impl;
}; } NMExportedObjectDBusMethodImpl;
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct { typedef struct {
GHashTable *properties; GHashTable *properties;
GSList *skeleton_types;
GArray *methods;
} NMExportedObjectClassInfo; } NMExportedObjectClassInfo;
GQuark nm_exported_object_class_info_quark (void); GQuark nm_exported_object_class_info_quark (void);
G_DEFINE_QUARK (NMExportedObjectClassInfo, nm_exported_object_class_info) G_DEFINE_QUARK (NMExportedObjectClassInfo, nm_exported_object_class_info)
/* "AddConnectionUnsaved" -> "handle-add-connection-unsaved" */
static char *
skeletonify_method_name (const char *dbus_method_name)
{
GString *out;
const char *p;
out = g_string_new ("handle");
for (p = dbus_method_name; *p; p++) {
if (g_ascii_isupper (*p) || p == dbus_method_name) {
g_string_append_c (out, '-');
g_string_append_c (out, g_ascii_tolower (*p));
} else
g_string_append_c (out, *p);
}
return g_string_free (out, FALSE);
}
/* "can-modify" -> "CanModify" */
static char *
dbusify_name (const char *gobject_name)
{
GString *out;
const char *p;
gboolean capitalize = TRUE;
out = g_string_new ("");
for (p = gobject_name; *p; p++) {
if (capitalize) {
g_string_append_c (out, g_ascii_toupper (*p));
capitalize = FALSE;
} else if (*p == '-')
capitalize = TRUE;
else
g_string_append_c (out, *p);
}
return g_string_free (out, FALSE);
}
/* "can_modify" -> "can-modify". Returns %NULL if @gobject_name contains no underscores */
static char *
hyphenify_name (const char *gobject_name)
{
char *hyphen_name, *p;
if (!strchr (gobject_name, '_'))
return NULL;
hyphen_name = g_strdup (gobject_name);
for (p = hyphen_name; *p; p++) {
if (*p == '_')
*p = '-';
}
return hyphen_name;
}
/* Called when an #NMExportedObject emits a signal that corresponds to a D-Bus
* signal, and re-emits that signal on the correct skeleton object as well.
*/
static gboolean
nm_exported_object_signal_hook (GSignalInvocationHint *ihint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
NMExportedObject *self = g_value_get_object (&param_values[0]);
NMExportedObjectPrivate *priv;
GSignalQuery *signal_info = data;
GDBusObjectSkeleton *interface = NULL;
GSList *iter;
GValue *dbus_param_values;
int i;
priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
if (!priv->path)
return TRUE;
for (iter = priv->interfaces; iter; iter = iter->next) {
if (g_type_is_a (G_OBJECT_TYPE (iter->data), signal_info->itype)) {
interface = iter->data;
break;
}
}
g_return_val_if_fail (interface != NULL, TRUE);
dbus_param_values = g_new0 (GValue, n_param_values);
g_value_init (&dbus_param_values[0], G_OBJECT_TYPE (interface));
g_value_set_object (&dbus_param_values[0], interface);
for (i = 1; i < n_param_values; i++) {
if (g_type_is_a (param_values[i].g_type, NM_TYPE_EXPORTED_OBJECT)) {
NMExportedObject *arg = g_value_get_object (&param_values[i]);
g_value_init (&dbus_param_values[i], G_TYPE_STRING);
if (arg && nm_exported_object_is_exported (arg))
g_value_set_string (&dbus_param_values[i], nm_exported_object_get_path (arg));
else
g_value_set_string (&dbus_param_values[i], "/");
} else {
g_value_init (&dbus_param_values[i], param_values[i].g_type);
g_value_copy (&param_values[i], &dbus_param_values[i]);
}
}
g_signal_emitv (dbus_param_values, signal_info->signal_id, 0, NULL);
for (i = 0; i < n_param_values; i++)
g_value_unset (&dbus_param_values[i]);
g_free (dbus_param_values);
return TRUE;
}
/** /**
* nm_exported_object_class_add_interface: * nm_exported_object_class_add_interface:
* @object_class: an #NMExportedObjectClass * @object_class: an #NMExportedObjectClass
* @info: generated #DBusGObjectInfo for the class * @dbus_skeleton_type: the type of the #GDBusObjectSkeleton to add
* @...: method name / handler pairs, %NULL-terminated
* *
* Adds @info to the list of D-Bus interfaces implemented by @object_class and * Adds @dbus_skeleton_type to the list of D-Bus interfaces implemented by
* sets up automatic dbus-glib handling for instances of that class. * @object_class. Instances of @object_class will automatically have a skeleton
* of that type created, which will be exported when you call
* nm_exported_object_export().
* *
* If @info includes any properties, then a "PropertiesChanged" signal will * The skeleton's properties will be initialized from the #NMExportedObject's,
* be emitted on @info's interface whenever any of those properties change on * and bidirectional bindings will be set up between them. When exported
* an exported instance of @object_class. * properties change, both the org.freedesktop.DBus.Properties.PropertiesChanged
* signal and the traditional NetworkManager PropertiesChanged signal will be
* emitted.
*
* When a signal is emitted on an #NMExportedObject that has the same name as a
* signal on @dbus_skeleton_type, it will automatically be emitted on the
* skeleton as well; #NMExportedObject arguments in the signal will be converted
* to D-Bus object paths in the skeleton signal.
*
* The arguments after @dbus_skeleton_type are pairs of D-Bus method names (in
* CamelCase), and the corresponding handlers for them (which must have the same
* prototype as the corresponding "handle-..." signal on @dbus_skeleton_type,
* except with no return value, and with the first argument being an object of
* @object_class's type, not of @dbus_skeleton_type).
*
* It is a programmer error if:
* - @object_class does not define a property of the same name and type as
* each of @dbus_skeleton_type's properties.
* - @object_class does not define a signal with the same name and arguments
* as each of @dbus_skeleton_type's signals.
* - the list of method names includes any names that do not correspond to
* "handle-" signals on @dbus_skeleton_type.
* - the list of method names does not include every method defined by
* @dbus_skeleton_type.
*/ */
void void
nm_exported_object_class_add_interface (NMExportedObjectClass *object_class, nm_exported_object_class_add_interface (NMExportedObjectClass *object_class,
const DBusGObjectInfo *info) GType dbus_skeleton_type,
...)
{ {
GType object_type = G_TYPE_FROM_CLASS (object_class);
NMExportedObjectClassInfo *classinfo; NMExportedObjectClassInfo *classinfo;
const char *properties_info, *dbus_name, *gobject_name, *tmp_access; NMExportedObjectDBusMethodImpl method;
char *hyphen_name, *p; va_list ap;
const char *method_name;
GCallback impl;
GType *interfaces;
guint n_interfaces;
guint *dbus_signals, n_signals, n_method_signals;
guint object_signal_id;
GSignalQuery query;
int i, s;
GObjectClass *dbus_object_class;
GParamSpec **dbus_properties, *object_property;
guint n_dbus_properties;
dbus_g_object_type_install_info (object_type, info); g_return_if_fail (NM_IS_EXPORTED_OBJECT_CLASS (object_class));
if (!info->exported_properties) g_return_if_fail (g_type_is_a (dbus_skeleton_type, G_TYPE_DBUS_INTERFACE_SKELETON));
return;
classinfo = g_type_get_qdata (object_type, nm_exported_object_class_info_quark ()); classinfo = g_slice_new (NMExportedObjectClassInfo);
if (!classinfo) { classinfo->skeleton_types = NULL;
classinfo = g_slice_new (NMExportedObjectClassInfo); classinfo->methods = g_array_new (FALSE, FALSE, sizeof (NMExportedObjectDBusMethodImpl));
classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal); classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal);
g_type_set_qdata (object_type, nm_exported_object_class_info_quark (), classinfo); g_type_set_qdata (G_TYPE_FROM_CLASS (object_class),
nm_exported_object_class_info_quark (), classinfo);
classinfo->skeleton_types = g_slist_prepend (classinfo->skeleton_types,
GSIZE_TO_POINTER (dbus_skeleton_type));
/* Ensure @dbus_skeleton_type's class_init has run, so its signals/properties
* will be defined.
*/
dbus_object_class = g_type_class_ref (dbus_skeleton_type);
/* Add method implementations from the varargs */
va_start (ap, dbus_skeleton_type);
while ((method_name = va_arg (ap, const char *)) && (impl = va_arg (ap, GCallback))) {
method.dbus_skeleton_type = dbus_skeleton_type;
method.method_name = skeletonify_method_name (method_name);
g_assert (g_signal_lookup (method.method_name, dbus_skeleton_type) != 0);
method.impl = impl;
g_array_append_val (classinfo->methods, method);
} }
va_end (ap);
properties_info = info->exported_properties; /* Properties */
while (*properties_info) { dbus_properties = g_object_class_list_properties (dbus_object_class, &n_dbus_properties);
/* The format is: "interface\0DBusPropertyName\0gobject_property_name\0access\0" */ for (i = 0; i < n_dbus_properties; i++) {
dbus_name = strchr (properties_info, '\0') + 1; char *hyphen_name;
gobject_name = strchr (dbus_name, '\0') + 1;
tmp_access = strchr (gobject_name, '\0') + 1;
properties_info = strchr (tmp_access, '\0') + 1;
if (strchr (gobject_name, '_')) { if (g_str_has_prefix (dbus_properties[i]->name, "g-"))
hyphen_name = g_strdup (gobject_name); continue;
for (p = hyphen_name; *p; p++) {
if (*p == '_') object_property = g_object_class_find_property (G_OBJECT_CLASS (object_class),
*p = '-'; dbus_properties[i]->name);
} g_assert (object_property != NULL);
g_assert (object_property->value_type == dbus_properties[i]->value_type);
g_assert (!g_hash_table_contains (classinfo->properties, dbus_properties[i]->name));
g_hash_table_insert (classinfo->properties,
g_strdup (dbus_properties[i]->name),
dbusify_name (dbus_properties[i]->name));
hyphen_name = hyphenify_name (dbus_properties[i]->name);
if (hyphen_name) {
g_assert (!g_hash_table_contains (classinfo->properties, hyphen_name)); g_assert (!g_hash_table_contains (classinfo->properties, hyphen_name));
g_hash_table_insert (classinfo->properties, g_hash_table_insert (classinfo->properties,
(char *) g_intern_string (hyphen_name), hyphen_name,
(char *) dbus_name); dbusify_name (dbus_properties[i]->name));
g_free (hyphen_name); }
} else { }
g_assert (!g_hash_table_contains (classinfo->properties, (char *) gobject_name));
g_hash_table_insert (classinfo->properties, /* Signals. Unlike g_object_class_list_properties(), g_signal_list_ids() is
(char *) gobject_name, * "shallow", so we need to query each implemented gdbus-generated interface
(char *) dbus_name); * separately.
*/
interfaces = g_type_interfaces (dbus_skeleton_type, &n_interfaces);
n_method_signals = 0;
for (i = 0; i < n_interfaces; i++) {
dbus_signals = g_signal_list_ids (interfaces[i], &n_signals);
for (s = 0; s < n_signals; s++) {
g_signal_query (dbus_signals[s], &query);
/* PropertiesChanged is handled specially */
if (!strcmp (query.signal_name, "properties-changed"))
continue;
if (g_str_has_prefix (query.signal_name, "handle-")) {
n_method_signals++;
continue;
}
object_signal_id = g_signal_lookup (query.signal_name, G_TYPE_FROM_CLASS (object_class));
g_assert (object_signal_id != 0);
g_signal_add_emission_hook (object_signal_id, 0,
nm_exported_object_signal_hook,
g_memdup (&query, sizeof (query)),
g_free);
}
}
g_assert_cmpint (n_method_signals, ==, classinfo->methods->len);
g_type_class_unref (dbus_object_class);
}
/* "meta-marshaller" that receives the skeleton "handle-foo" signal, replaces
* the skeleton object with an #NMExportedObject in the parameters, drops the
* user_data parameter, and adds a "TRUE" return value (indicating to gdbus that
* the signal was handled).
*/
static void
nm_exported_object_meta_marshal (GClosure *closure, GValue *return_value,
guint n_param_values, const GValue *param_values,
gpointer invocation_hint, gpointer marshal_data)
{
GValue *local_param_values;
local_param_values = g_new0 (GValue, n_param_values);
g_value_init (&local_param_values[0], G_TYPE_POINTER);
g_value_set_pointer (&local_param_values[0], closure->data);
memcpy (local_param_values + 1, param_values + 1, (n_param_values - 1) * sizeof (GValue));
g_cclosure_marshal_generic (closure, NULL,
n_param_values, local_param_values,
invocation_hint,
((GCClosure *)closure)->callback);
g_value_set_boolean (return_value, TRUE);
g_value_unset (&local_param_values[0]);
g_free (local_param_values);
}
static void
nm_exported_object_create_skeletons (NMExportedObject *self,
GType object_type)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
GObjectClass *object_class = g_type_class_peek (object_type);
NMExportedObjectClassInfo *classinfo;
GSList *iter;
GDBusObjectSkeleton *interface;
GParamSpec **properties;
guint n_properties;
int i;
classinfo = g_type_get_qdata (object_type, nm_exported_object_class_info_quark ());
if (!classinfo)
return;
for (iter = classinfo->skeleton_types; iter; iter = iter->next) {
GType dbus_skeleton_type = GPOINTER_TO_SIZE (iter->data);
interface = g_object_new (dbus_skeleton_type, NULL);
priv->interfaces = g_slist_prepend (priv->interfaces, interface);
/* Bind properties */
properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (interface), &n_properties);
for (i = 0; i < n_properties; i++) {
GParamSpec *nm_property;
GBindingFlags flags;
nm_property = g_object_class_find_property (object_class, properties[i]->name);
if (!nm_property)
continue;
flags = G_BINDING_SYNC_CREATE;
if ( (nm_property->flags & G_PARAM_WRITABLE)
&& !(nm_property->flags & G_PARAM_CONSTRUCT_ONLY))
flags |= G_BINDING_BIDIRECTIONAL;
g_object_bind_property (self, properties[i]->name,
interface, properties[i]->name,
flags);
}
/* Bind methods */
for (i = 0; i < classinfo->methods->len; i++) {
NMExportedObjectDBusMethodImpl *method = &g_array_index (classinfo->methods, NMExportedObjectDBusMethodImpl, i);
GClosure *closure;
if (method->dbus_skeleton_type != dbus_skeleton_type)
continue;
closure = g_cclosure_new_swap (method->impl, self, NULL);
g_closure_set_meta_marshal (closure, NULL, nm_exported_object_meta_marshal);
g_signal_connect_closure (interface, method->method_name, closure, FALSE);
} }
} }
} }
@ -135,7 +424,10 @@ const char *
nm_exported_object_export (NMExportedObject *self) nm_exported_object_export (NMExportedObject *self)
{ {
NMExportedObjectPrivate *priv; NMExportedObjectPrivate *priv;
NMBusManager *dbus_manager = nm_bus_manager_get ();
const char *class_export_path, *p; const char *class_export_path, *p;
GSList *iter;
GType type;
g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL); g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL);
priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
@ -160,7 +452,14 @@ nm_exported_object_export (NMExportedObject *self)
} else } else
priv->path = g_strdup (class_export_path); priv->path = g_strdup (class_export_path);
nm_bus_manager_register_object (nm_bus_manager_get (), priv->path, self); type = G_OBJECT_TYPE (self);
while (type != NM_TYPE_EXPORTED_OBJECT) {
nm_exported_object_create_skeletons (self, type);
type = g_type_parent (type);
}
for (iter = priv->interfaces; iter; iter = iter->next)
nm_bus_manager_register_object (dbus_manager, priv->path, iter->data);
return priv->path; return priv->path;
} }
@ -208,6 +507,7 @@ void
nm_exported_object_unexport (NMExportedObject *self) nm_exported_object_unexport (NMExportedObject *self)
{ {
NMExportedObjectPrivate *priv; NMExportedObjectPrivate *priv;
GSList *iter;
g_return_if_fail (NM_IS_EXPORTED_OBJECT (self)); g_return_if_fail (NM_IS_EXPORTED_OBJECT (self));
priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
@ -215,16 +515,11 @@ nm_exported_object_unexport (NMExportedObject *self)
g_return_if_fail (priv->path != NULL); g_return_if_fail (priv->path != NULL);
g_clear_pointer (&priv->path, g_free); g_clear_pointer (&priv->path, g_free);
nm_bus_manager_unregister_object (nm_bus_manager_get (), self);
}
static void for (iter = priv->interfaces; iter; iter = iter->next)
destroy_value (gpointer data) nm_bus_manager_unregister_object (nm_bus_manager_get (), iter->data);
{ g_slist_free_full (priv->interfaces, g_object_unref);
GValue *val = (GValue *) data; priv->interfaces = NULL;
g_value_unset (val);
g_slice_free (GValue, val);
} }
static void static void
@ -232,63 +527,77 @@ nm_exported_object_init (NMExportedObject *self)
{ {
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
priv->pending_notifies = g_hash_table_new_full (g_str_hash, g_str_equal, g_variant_builder_init (&priv->pending_notifies, G_VARIANT_TYPE_VARDICT);
NULL, destroy_value);
}
static void
add_to_string (gpointer key, gpointer value, gpointer user_data)
{
const char *name = (const char *) key;
GString *buf = user_data;
GValue str_val = G_VALUE_INIT;
g_value_init (&str_val, G_TYPE_STRING);
if (!g_value_transform ((GValue *) value, &str_val)) {
if (G_VALUE_HOLDS_OBJECT (value)) {
GObject *obj = g_value_get_object (value);
if (obj) {
g_string_append_printf (buf, "{%s: %p (%s)}, ", name, obj,
G_OBJECT_TYPE_NAME (obj));
} else
g_string_append_printf (buf, "{%s: %p}, ", name, obj);
} else
g_string_append_printf (buf, "{%s: <transform error>}, ", name);
} else
g_string_append_printf (buf, "{%s: %s}, ", name, g_value_get_string (&str_val));
g_value_unset (&str_val);
} }
static gboolean static gboolean
idle_emit_properties_changed (gpointer self) idle_emit_properties_changed (gpointer self)
{ {
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
GVariant *notifies;
GSList *iter;
GDBusObjectSkeleton *interface = NULL;
guint signal_id = 0;
priv->notify_idle_id = 0; priv->notify_idle_id = 0;
notifies = g_variant_builder_end (&priv->pending_notifies);
g_variant_ref_sink (notifies);
g_variant_builder_init (&priv->pending_notifies, G_VARIANT_TYPE_VARDICT);
for (iter = priv->interfaces; iter; iter = iter->next) {
signal_id = g_signal_lookup ("properties-changed", G_OBJECT_TYPE (iter->data));
if (signal_id != 0) {
interface = iter->data;
break;
}
}
g_return_val_if_fail (signal_id != 0, FALSE);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_DBUS_PROPS)) { if (nm_logging_enabled (LOGL_DEBUG, LOGD_DBUS_PROPS)) {
GString *buf = g_string_new (NULL); char *notification;
g_hash_table_foreach (priv->pending_notifies, add_to_string, buf); notification = g_variant_print (notifies, TRUE);
nm_log_dbg (LOGD_DBUS_PROPS, "%s -> %s", G_OBJECT_TYPE_NAME (self), buf->str); nm_log_dbg (LOGD_DBUS_PROPS, "PropertiesChanged %s %p: %s",
g_string_free (buf, TRUE); G_OBJECT_TYPE_NAME (self), self, notification);
g_free (notification);
} }
g_signal_emit (self, signals[PROPERTIES_CHANGED], 0, priv->pending_notifies); g_signal_emit (interface, signal_id, 0, notifies);
g_hash_table_remove_all (priv->pending_notifies); g_variant_unref (notifies);
return FALSE; return FALSE;
} }
static const GVariantType *
find_dbus_property_type (GDBusInterfaceSkeleton *skel,
const char *dbus_property_name)
{
GDBusInterfaceInfo *iinfo;
int i;
iinfo = g_dbus_interface_skeleton_get_info (skel);
for (i = 0; iinfo->properties[i]; i++) {
if (!strcmp (iinfo->properties[i]->name, dbus_property_name))
return G_VARIANT_TYPE (iinfo->properties[i]->signature);
}
return NULL;
}
static void static void
nm_exported_object_notify (GObject *object, GParamSpec *pspec) nm_exported_object_notify (GObject *object, GParamSpec *pspec)
{ {
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object); NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object);
NMExportedObjectClassInfo *classinfo; NMExportedObjectClassInfo *classinfo;
const char *dbus_property_name = NULL;
GValue *value;
GType type; GType type;
const char *dbus_property_name = NULL;
GValue value = G_VALUE_INIT;
const GVariantType *vtype;
GVariant *variant;
GSList *iter;
if (!priv->interfaces)
return;
for (type = G_OBJECT_TYPE (object); type; type = g_type_parent (type)) { for (type = G_OBJECT_TYPE (object); type; type = g_type_parent (type)) {
classinfo = g_type_get_qdata (type, nm_exported_object_class_info_quark ()); classinfo = g_type_get_qdata (type, nm_exported_object_class_info_quark ());
@ -305,10 +614,19 @@ nm_exported_object_notify (GObject *object, GParamSpec *pspec)
return; return;
} }
value = g_slice_new0 (GValue); g_value_init (&value, pspec->value_type);
g_value_init (value, pspec->value_type); g_object_get_property (G_OBJECT (object), pspec->name, &value);
g_object_get_property (object, pspec->name, value);
g_hash_table_insert (priv->pending_notifies, (char *) dbus_property_name, value); vtype = NULL;
for (iter = priv->interfaces; iter && !vtype; iter = iter->next)
vtype = find_dbus_property_type (iter->data, dbus_property_name);
g_return_if_fail (vtype != NULL);
variant = g_dbus_gvalue_to_gvariant (&value, vtype);
g_variant_builder_add (&priv->pending_notifies, "{sv}",
dbus_property_name,
variant);
g_value_unset (&value);
if (!priv->notify_idle_id) if (!priv->notify_idle_id)
priv->notify_idle_id = g_idle_add (idle_emit_properties_changed, object); priv->notify_idle_id = g_idle_add (idle_emit_properties_changed, object);
@ -322,22 +640,15 @@ nm_exported_object_dispose (GObject *object)
if (priv->path) if (priv->path)
nm_exported_object_unexport (NM_EXPORTED_OBJECT (object)); nm_exported_object_unexport (NM_EXPORTED_OBJECT (object));
g_hash_table_remove_all (priv->pending_notifies); g_variant_builder_clear (&priv->pending_notifies);
nm_clear_g_source (&priv->notify_idle_id); nm_clear_g_source (&priv->notify_idle_id);
g_slist_free_full (priv->interfaces, g_object_unref);
priv->interfaces = NULL;
G_OBJECT_CLASS (nm_exported_object_parent_class)->dispose (object); G_OBJECT_CLASS (nm_exported_object_parent_class)->dispose (object);
} }
static void
nm_exported_object_finalize (GObject *object)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object);
g_hash_table_destroy (priv->pending_notifies);
G_OBJECT_CLASS (nm_exported_object_parent_class)->finalize (object);
}
static void static void
nm_exported_object_class_init (NMExportedObjectClass *klass) nm_exported_object_class_init (NMExportedObjectClass *klass)
{ {
@ -345,14 +656,6 @@ nm_exported_object_class_init (NMExportedObjectClass *klass)
g_type_class_add_private (object_class, sizeof (NMExportedObjectPrivate)); g_type_class_add_private (object_class, sizeof (NMExportedObjectPrivate));
object_class->notify = nm_exported_object_notify; object_class->notify = nm_exported_object_notify;
object_class->dispose = nm_exported_object_dispose; object_class->dispose = nm_exported_object_dispose;
object_class->finalize = nm_exported_object_finalize;
signals[PROPERTIES_CHANGED] = g_signal_new ("properties-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT);
} }

View file

@ -21,9 +21,8 @@
#ifndef NM_EXPORTED_OBJECT_H #ifndef NM_EXPORTED_OBJECT_H
#define NM_EXPORTED_OBJECT_H #define NM_EXPORTED_OBJECT_H
#include <dbus/dbus-glib.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-types.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -47,7 +46,8 @@ typedef struct {
GType nm_exported_object_get_type (void); GType nm_exported_object_get_type (void);
void nm_exported_object_class_add_interface (NMExportedObjectClass *object_class, void nm_exported_object_class_add_interface (NMExportedObjectClass *object_class,
const DBusGObjectInfo *info); GType dbus_skeleton_type,
...) G_GNUC_NULL_TERMINATED;
const char *nm_exported_object_export (NMExportedObject *self); const char *nm_exported_object_export (NMExportedObject *self);
const char *nm_exported_object_get_path (NMExportedObject *self); const char *nm_exported_object_get_path (NMExportedObject *self);

View file

@ -29,14 +29,14 @@
#include "nm-default.h" #include "nm-default.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-dbus-glib-types.h"
#include "nm-ip4-config-glue.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-route-manager.h" #include "nm-route-manager.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-macros-internal.h" #include "nm-macros-internal.h"
#include "nmdbus-ip4-config.h"
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate)) #define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
@ -2139,15 +2139,6 @@ finalize (GObject *object)
G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object);
} }
static void
gvalue_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static void static void
get_property (GObject *object, guint prop_id, get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) GValue *value, GParamSpec *pspec)
@ -2161,127 +2152,116 @@ get_property (GObject *object, guint prop_id,
break; break;
case PROP_ADDRESS_DATA: case PROP_ADDRESS_DATA:
{ {
GPtrArray *addresses = g_ptr_array_new (); GVariantBuilder array_builder, addr_builder;
int naddr = nm_ip4_config_get_num_addresses (config); int naddr = nm_ip4_config_get_num_addresses (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}"));
for (i = 0; i < naddr; i++) { for (i = 0; i < naddr; i++) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i); const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
GHashTable *addr_hash;
GValue *val;
addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy); g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&addr_builder, "{sv}",
val = g_slice_new0 (GValue); "address",
g_value_init (val, G_TYPE_STRING); g_variant_new_string (nm_utils_inet4_ntop (address->address, NULL)));
g_value_set_string (val, nm_utils_inet4_ntop (address->address, NULL)); g_variant_builder_add (&addr_builder, "{sv}",
g_hash_table_insert (addr_hash, "address", val); "prefix",
g_variant_new_uint32 (address->plen));
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, address->plen);
g_hash_table_insert (addr_hash, "prefix", val);
if (*address->label) { if (*address->label) {
val = g_slice_new0 (GValue); g_variant_builder_add (&addr_builder, "{sv}",
g_value_init (val, G_TYPE_STRING); "label",
g_value_set_string (val, address->label); g_variant_new_string (address->label));
g_hash_table_insert (addr_hash, "label", val);
} }
g_ptr_array_add (addresses, addr_hash); g_variant_builder_add (&array_builder, "a{sv}", &addr_builder);
} }
g_value_take_boxed (value, addresses); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_ADDRESSES: case PROP_ADDRESSES:
{ {
GPtrArray *addresses = g_ptr_array_new (); GVariantBuilder array_builder;
int naddr = nm_ip4_config_get_num_addresses (config); int naddr = nm_ip4_config_get_num_addresses (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aau"));
for (i = 0; i < naddr; i++) { for (i = 0; i < naddr; i++) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i); const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); guint32 dbus_addr[3];
guint32 gateway = i == 0 ? priv->gateway : 0;
g_array_append_val (array, address->address); dbus_addr[0] = address->address;
g_array_append_val (array, address->plen); dbus_addr[1] = address->plen;
g_array_append_val (array, gateway); dbus_addr[2] = i == 0 ? priv->gateway : 0;
g_ptr_array_add (addresses, array); g_variant_builder_add (&array_builder, "@au",
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
dbus_addr, 3, sizeof (guint32)));
} }
g_value_take_boxed (value, addresses); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_ROUTE_DATA: case PROP_ROUTE_DATA:
{ {
GPtrArray *routes = g_ptr_array_new (); GVariantBuilder array_builder, route_builder;
guint nroutes = nm_ip4_config_get_num_routes (config); guint nroutes = nm_ip4_config_get_num_routes (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}"));
for (i = 0; i < nroutes; i++) { for (i = 0; i < nroutes; i++) {
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i); const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
GHashTable *route_hash;
GValue *val;
route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, nm_utils_inet4_ntop (route->network, NULL));
g_hash_table_insert (route_hash, "dest", val);
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, route->plen);
g_hash_table_insert (route_hash, "prefix", val);
g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&route_builder, "{sv}",
"dest",
g_variant_new_string (nm_utils_inet4_ntop (route->network, NULL)));
g_variant_builder_add (&route_builder, "{sv}",
"prefix",
g_variant_new_uint32 (route->plen));
if (route->gateway) { if (route->gateway) {
val = g_slice_new0 (GValue); g_variant_builder_add (&route_builder, "{sv}",
g_value_init (val, G_TYPE_STRING); "next-hop",
g_value_set_string (val, nm_utils_inet4_ntop (route->gateway, NULL)); g_variant_new_string (nm_utils_inet4_ntop (route->gateway, NULL)));
g_hash_table_insert (route_hash, "next-hop", val);
} }
g_variant_builder_add (&route_builder, "{sv}",
"metric",
g_variant_new_uint32 (route->metric));
val = g_slice_new0 (GValue); g_variant_builder_add (&array_builder, "a{sv}", &route_builder);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, route->metric);
g_hash_table_insert (route_hash, "metric", val);
g_ptr_array_add (routes, route_hash);
} }
g_value_take_boxed (value, routes); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_ROUTES: case PROP_ROUTES:
{ {
GPtrArray *routes = g_ptr_array_new (); GVariantBuilder array_builder;
guint nroutes = nm_ip4_config_get_num_routes (config); guint nroutes = nm_ip4_config_get_num_routes (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aau"));
for (i = 0; i < nroutes; i++) { for (i = 0; i < nroutes; i++) {
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i); const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
GArray *array; guint32 dbus_route[4];
/* legacy versions of nm_ip4_route_set_prefix() in libnm-util assert that the /* legacy versions of nm_ip4_route_set_prefix() in libnm-util assert that the
* plen is positive. Skip the default routes not to break older clients. */ * plen is positive. Skip the default routes not to break older clients. */
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
continue; continue;
array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4); dbus_route[0] = route->network;
g_array_append_val (array, route->network); dbus_route[1] = route->plen;
g_array_append_val (array, route->plen); dbus_route[2] = route->gateway;
g_array_append_val (array, route->gateway); dbus_route[3] = route->metric;
g_array_append_val (array, route->metric);
g_ptr_array_add (routes, array); g_variant_builder_add (&array_builder, "@au",
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
dbus_route, 4, sizeof (guint32)));
} }
g_value_take_boxed (value, routes); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_GATEWAY: case PROP_GATEWAY:
@ -2291,19 +2271,27 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, NULL); g_value_set_string (value, NULL);
break; break;
case PROP_NAMESERVERS: case PROP_NAMESERVERS:
g_value_set_boxed (value, priv->nameservers); g_value_take_variant (value,
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
priv->nameservers->data,
priv->nameservers->len,
sizeof (guint32)));
break; break;
case PROP_DOMAINS: case PROP_DOMAINS:
g_value_set_boxed (value, priv->domains); nm_utils_g_value_set_strv (value, priv->domains);
break; break;
case PROP_SEARCHES: case PROP_SEARCHES:
g_value_set_boxed (value, priv->searches); nm_utils_g_value_set_strv (value, priv->searches);
break; break;
case PROP_DNS_OPTIONS: case PROP_DNS_OPTIONS:
g_value_set_boxed (value, priv->dns_options); nm_utils_g_value_set_strv (value, priv->dns_options);
break; break;
case PROP_WINS_SERVERS: case PROP_WINS_SERVERS:
g_value_set_boxed (value, priv->wins); g_value_take_variant (value,
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
priv->wins->data,
priv->wins->len,
sizeof (guint32)));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -2344,65 +2332,72 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
object_class->finalize = finalize; object_class->finalize = finalize;
obj_properties[PROP_IFINDEX] = obj_properties[PROP_IFINDEX] =
g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "", g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "",
-1, G_MAXINT, -1, -1, G_MAXINT, -1,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDRESS_DATA] = obj_properties[PROP_ADDRESS_DATA] =
g_param_spec_boxed (NM_IP4_CONFIG_ADDRESS_DATA, "", "", g_param_spec_variant (NM_IP4_CONFIG_ADDRESS_DATA, "", "",
DBUS_TYPE_NM_IP_ADDRESSES, G_VARIANT_TYPE ("aa{sv}"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDRESSES] = obj_properties[PROP_ADDRESSES] =
g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "", g_param_spec_variant (NM_IP4_CONFIG_ADDRESSES, "", "",
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, G_VARIANT_TYPE ("aau"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTE_DATA] = obj_properties[PROP_ROUTE_DATA] =
g_param_spec_boxed (NM_IP4_CONFIG_ROUTE_DATA, "", "", g_param_spec_variant (NM_IP4_CONFIG_ROUTE_DATA, "", "",
DBUS_TYPE_NM_IP_ROUTES, G_VARIANT_TYPE ("aa{sv}"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTES] = obj_properties[PROP_ROUTES] =
g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "", g_param_spec_variant (NM_IP4_CONFIG_ROUTES, "", "",
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, G_VARIANT_TYPE ("aau"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_GATEWAY] = obj_properties[PROP_GATEWAY] =
g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "", g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "",
NULL, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_NAMESERVERS] = obj_properties[PROP_NAMESERVERS] =
g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, "", "", g_param_spec_variant (NM_IP4_CONFIG_NAMESERVERS, "", "",
DBUS_TYPE_G_UINT_ARRAY, G_VARIANT_TYPE ("au"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_DOMAINS] = obj_properties[PROP_DOMAINS] =
g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "", g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "",
DBUS_TYPE_G_ARRAY_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_SEARCHES] = obj_properties[PROP_SEARCHES] =
g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "", g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "",
DBUS_TYPE_G_ARRAY_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_DNS_OPTIONS] = obj_properties[PROP_DNS_OPTIONS] =
g_param_spec_boxed (NM_IP4_CONFIG_DNS_OPTIONS, "", "", g_param_spec_boxed (NM_IP4_CONFIG_DNS_OPTIONS, "", "",
DBUS_TYPE_G_ARRAY_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_WINS_SERVERS] = obj_properties[PROP_WINS_SERVERS] =
g_param_spec_boxed (NM_IP4_CONFIG_WINS_SERVERS, "", "", g_param_spec_variant (NM_IP4_CONFIG_WINS_SERVERS, "", "",
DBUS_TYPE_G_UINT_ARRAY, G_VARIANT_TYPE ("au"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, obj_properties); g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_ip4_config_object_info); NMDBUS_TYPE_IP4_CONFIG_SKELETON,
NULL);
} }

View file

@ -29,13 +29,13 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-dbus-glib-types.h"
#include "nm-ip6-config-glue.h"
#include "nm-route-manager.h" #include "nm-route-manager.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-macros-internal.h" #include "nm-macros-internal.h"
#include "nmdbus-ip6-config.h"
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate)) #define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate))
@ -1891,31 +1891,21 @@ finalize (GObject *object)
static void static void
nameservers_to_gvalue (GArray *array, GValue *value) nameservers_to_gvalue (GArray *array, GValue *value)
{ {
GPtrArray *dns; GVariantBuilder builder;
guint i = 0; guint i = 0;
dns = g_ptr_array_new (); g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
while (array && (i < array->len)) { while (array && (i < array->len)) {
struct in6_addr *addr; struct in6_addr *addr;
GByteArray *bytearray;
addr = &g_array_index (array, struct in6_addr, i++);
bytearray = g_byte_array_sized_new (16); addr = &g_array_index (array, struct in6_addr, i++);
g_byte_array_append (bytearray, (guint8 *) addr->s6_addr, 16); g_variant_builder_add (&builder, "@ay",
g_ptr_array_add (dns, bytearray); g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
&addr, 16, 1));
} }
g_value_take_boxed (value, dns); g_value_take_variant (value, g_variant_builder_end (&builder));
}
static void
gvalue_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
} }
static void static void
@ -1931,163 +1921,109 @@ get_property (GObject *object, guint prop_id,
break; break;
case PROP_ADDRESS_DATA: case PROP_ADDRESS_DATA:
{ {
GPtrArray *addresses = g_ptr_array_new (); GVariantBuilder array_builder, addr_builder;
int naddr = nm_ip6_config_get_num_addresses (config); int naddr = nm_ip6_config_get_num_addresses (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}"));
for (i = 0; i < naddr; i++) { for (i = 0; i < naddr; i++) {
const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i); const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i);
GHashTable *addr_hash;
GValue *val;
addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy); g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&addr_builder, "{sv}",
"address",
g_variant_new_string (nm_utils_inet6_ntop (&address->address, NULL)));
g_variant_builder_add (&addr_builder, "{sv}",
"prefix",
g_variant_new_uint32 (address->plen));
val = g_slice_new0 (GValue); g_variant_builder_add (&array_builder, "a{sv}", &addr_builder);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, nm_utils_inet6_ntop (&address->address, NULL));
g_hash_table_insert (addr_hash, "address", val);
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, address->plen);
g_hash_table_insert (addr_hash, "prefix", val);
g_ptr_array_add (addresses, addr_hash);
} }
g_value_take_boxed (value, addresses); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_ADDRESSES: case PROP_ADDRESSES:
{ {
GPtrArray *addresses = g_ptr_array_new (); GVariantBuilder array_builder;
const struct in6_addr *gateway = nm_ip6_config_get_gateway (config); const struct in6_addr *gateway = nm_ip6_config_get_gateway (config);
int naddr = nm_ip6_config_get_num_addresses (config); int naddr = nm_ip6_config_get_num_addresses (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a(ayuay)"));
for (i = 0; i < naddr; i++) { for (i = 0; i < naddr; i++) {
const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i); const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i);
GValueArray *array = g_value_array_new (3); g_variant_builder_add (&array_builder, "(@ayu@ay)",
GValue element = G_VALUE_INIT; g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
GByteArray *ba; &address->address, 16, 1),
address->plen,
/* IP address */ g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); (i == 0 && gateway ? gateway : &in6addr_any),
ba = g_byte_array_new (); 16, 1));
g_byte_array_append (ba, (guint8 *) &address->address, 16);
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
/* Prefix */
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, address->plen);
g_value_array_append (array, &element);
g_value_unset (&element);
/* Gateway */
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guint8 *) (i == 0 && gateway ? gateway : &in6addr_any), sizeof (*gateway));
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
g_ptr_array_add (addresses, array);
} }
g_value_take_boxed (value, addresses); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_ROUTE_DATA: case PROP_ROUTE_DATA:
{ {
GPtrArray *routes = g_ptr_array_new (); GVariantBuilder array_builder, route_builder;
guint nroutes = nm_ip6_config_get_num_routes (config); guint nroutes = nm_ip6_config_get_num_routes (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}"));
for (i = 0; i < nroutes; i++) { for (i = 0; i < nroutes; i++) {
const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i); const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i);
GHashTable *route_hash;
GValue *val;
route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, nm_utils_inet6_ntop (&route->network, NULL));
g_hash_table_insert (route_hash, "dest", val);
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, route->plen);
g_hash_table_insert (route_hash, "prefix", val);
g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&route_builder, "{sv}",
"dest",
g_variant_new_string (nm_utils_inet6_ntop (&route->network, NULL)));
g_variant_builder_add (&route_builder, "{sv}",
"prefix",
g_variant_new_uint32 (route->plen));
if (!IN6_IS_ADDR_UNSPECIFIED (&route->gateway)) { if (!IN6_IS_ADDR_UNSPECIFIED (&route->gateway)) {
val = g_slice_new0 (GValue); g_variant_builder_add (&route_builder, "{sv}",
g_value_init (val, G_TYPE_STRING); "next-hop",
g_value_set_string (val, nm_utils_inet6_ntop (&route->gateway, NULL)); g_variant_new_string (nm_utils_inet6_ntop (&route->gateway, NULL)));
g_hash_table_insert (route_hash, "next-hop", val);
} }
val = g_slice_new0 (GValue); g_variant_builder_add (&route_builder, "{sv}",
g_value_init (val, G_TYPE_UINT); "metric",
g_value_set_uint (val, route->metric); g_variant_new_uint32 (route->metric));
g_hash_table_insert (route_hash, "metric", val);
g_ptr_array_add (routes, route_hash); g_variant_builder_add (&array_builder, "a{sv}", &route_builder);
} }
g_value_take_boxed (value, routes); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_ROUTES: case PROP_ROUTES:
{ {
GPtrArray *routes = g_ptr_array_new (); GVariantBuilder array_builder;
int nroutes = nm_ip6_config_get_num_routes (config); int nroutes = nm_ip6_config_get_num_routes (config);
int i; int i;
g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a(ayuayu)"));
for (i = 0; i < nroutes; i++) { for (i = 0; i < nroutes; i++) {
GValueArray *array;
const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i); const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i);
GByteArray *ba;
GValue element = G_VALUE_INIT;
/* legacy versions of nm_ip6_route_set_prefix() in libnm-util assert that the /* legacy versions of nm_ip6_route_set_prefix() in libnm-util assert that the
* plen is positive. Skip the default routes not to break older clients. */ * plen is positive. Skip the default routes not to break older clients. */
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
continue; continue;
array = g_value_array_new (4); g_variant_builder_add (&array_builder, "(@ayu@ayu)",
g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); &route->network, 16, 1),
ba = g_byte_array_new (); g_variant_new_uint32 (route->plen),
g_byte_array_append (ba, (guint8 *) &route->network, sizeof (route->network)); g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
g_value_take_boxed (&element, ba); &route->gateway, 16, 1),
g_value_array_append (array, &element); g_variant_new_uint32 (route->metric));
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, route->plen);
g_value_array_append (array, &element);
g_value_unset (&element);
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guint8 *) &route->gateway, sizeof (route->gateway));
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, route->metric);
g_value_array_append (array, &element);
g_value_unset (&element);
g_ptr_array_add (routes, array);
} }
g_value_take_boxed (value, routes); g_value_take_variant (value, g_variant_builder_end (&array_builder));
} }
break; break;
case PROP_GATEWAY: case PROP_GATEWAY:
@ -2100,13 +2036,13 @@ get_property (GObject *object, guint prop_id,
nameservers_to_gvalue (priv->nameservers, value); nameservers_to_gvalue (priv->nameservers, value);
break; break;
case PROP_DOMAINS: case PROP_DOMAINS:
g_value_set_boxed (value, priv->domains); nm_utils_g_value_set_strv (value, priv->domains);
break; break;
case PROP_SEARCHES: case PROP_SEARCHES:
g_value_set_boxed (value, priv->searches); nm_utils_g_value_set_strv (value, priv->searches);
break; break;
case PROP_DNS_OPTIONS: case PROP_DNS_OPTIONS:
g_value_set_boxed (value, priv->dns_options); nm_utils_g_value_set_strv (value, priv->dns_options);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -2149,59 +2085,65 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
/* properties */ /* properties */
obj_properties[PROP_IFINDEX] = obj_properties[PROP_IFINDEX] =
g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "",
-1, G_MAXINT, -1, -1, G_MAXINT, -1,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDRESS_DATA] = obj_properties[PROP_ADDRESS_DATA] =
g_param_spec_boxed (NM_IP6_CONFIG_ADDRESS_DATA, "", "", g_param_spec_variant (NM_IP6_CONFIG_ADDRESS_DATA, "", "",
DBUS_TYPE_NM_IP_ADDRESSES, G_VARIANT_TYPE ("aa{sv}"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDRESSES] = obj_properties[PROP_ADDRESSES] =
g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "", g_param_spec_variant (NM_IP6_CONFIG_ADDRESSES, "", "",
DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, G_VARIANT_TYPE ("a(ayuay)"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTE_DATA] = obj_properties[PROP_ROUTE_DATA] =
g_param_spec_boxed (NM_IP6_CONFIG_ROUTE_DATA, "", "", g_param_spec_variant (NM_IP6_CONFIG_ROUTE_DATA, "", "",
DBUS_TYPE_NM_IP_ROUTES, G_VARIANT_TYPE ("aa{sv}"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTES] = obj_properties[PROP_ROUTES] =
g_param_spec_boxed (NM_IP6_CONFIG_ROUTES, "", "", g_param_spec_variant (NM_IP6_CONFIG_ROUTES, "", "",
DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE, G_VARIANT_TYPE ("a(ayuayu)"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_GATEWAY] = obj_properties[PROP_GATEWAY] =
g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "", g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "",
NULL, NULL,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_NAMESERVERS] = obj_properties[PROP_NAMESERVERS] =
g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS, "", "", g_param_spec_variant (NM_IP6_CONFIG_NAMESERVERS, "", "",
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR, G_VARIANT_TYPE ("aay"),
G_PARAM_READABLE | NULL,
G_PARAM_STATIC_STRINGS); G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_DOMAINS] = obj_properties[PROP_DOMAINS] =
g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "", g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "",
DBUS_TYPE_G_ARRAY_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_SEARCHES] = obj_properties[PROP_SEARCHES] =
g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "", g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "",
DBUS_TYPE_G_ARRAY_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_DNS_OPTIONS] = obj_properties[PROP_DNS_OPTIONS] =
g_param_spec_boxed (NM_IP6_CONFIG_DNS_OPTIONS, "", "", g_param_spec_boxed (NM_IP6_CONFIG_DNS_OPTIONS, "", "",
DBUS_TYPE_G_ARRAY_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, obj_properties); g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_ip6_config_object_info); NMDBUS_TYPE_IP6_CONFIG_SKELETON,
NULL);
} }

File diff suppressed because it is too large Load diff

View file

@ -75,18 +75,17 @@ typedef struct {
GType nm_manager_get_type (void); GType nm_manager_get_type (void);
/* nm_manager_new() should only be used by main.c */ /* nm_manager_setup() should only be used by main.c */
NMManager * nm_manager_new (NMSettings *settings, NMManager * nm_manager_setup (const char *state_file,
const char *state_file,
gboolean initial_net_enabled, gboolean initial_net_enabled,
gboolean initial_wifi_enabled, gboolean initial_wifi_enabled,
gboolean initial_wwan_enabled, gboolean initial_wwan_enabled,
gboolean initial_wimax_enabled, gboolean initial_wimax_enabled);
GError **error);
NMManager * nm_manager_get (void); NMManager * nm_manager_get (void);
void nm_manager_start (NMManager *manager); gboolean nm_manager_start (NMManager *manager,
GError **error);
void nm_manager_stop (NMManager *manager); void nm_manager_stop (NMManager *manager);
NMState nm_manager_get_state (NMManager *manager); NMState nm_manager_get_state (NMManager *manager);
const GSList *nm_manager_get_active_connections (NMManager *manager); const GSList *nm_manager_get_active_connections (NMManager *manager);

View file

@ -48,22 +48,7 @@
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
static void impl_ppp_manager_need_secrets (NMPPPManager *manager, #include "nmdbus-ppp-manager.h"
DBusGMethodInvocation *context);
static gboolean impl_ppp_manager_set_state (NMPPPManager *manager,
guint32 state,
GError **err);
static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
GHashTable *config,
GError **err);
static gboolean impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
GHashTable *config,
GError **err);
#include "nm-ppp-manager-glue.h"
static void _ppp_cleanup (NMPPPManager *manager); static void _ppp_cleanup (NMPPPManager *manager);
static void _ppp_kill (NMPPPManager *manager); static void _ppp_kill (NMPPPManager *manager);
@ -77,7 +62,7 @@ typedef struct {
char *parent_iface; char *parent_iface;
NMActRequest *act_req; NMActRequest *act_req;
DBusGMethodInvocation *pending_secrets_context; GDBusMethodInvocation *pending_secrets_context;
guint32 secrets_id; guint32 secrets_id;
const char *secrets_setting_name; const char *secrets_setting_name;
@ -341,14 +326,13 @@ ppp_secrets_cb (NMActRequest *req,
if (error) { if (error) {
nm_log_warn (LOGD_PPP, "%s", error->message); nm_log_warn (LOGD_PPP, "%s", error->message);
dbus_g_method_return_error (priv->pending_secrets_context, error); g_dbus_method_invocation_return_gerror (priv->pending_secrets_context, error);
goto out; goto out;
} }
if (!extract_details_from_connection (connection, priv->secrets_setting_name, &username, &password, &local)) { if (!extract_details_from_connection (connection, priv->secrets_setting_name, &username, &password, &local)) {
nm_log_warn (LOGD_PPP, "%s", local->message); nm_log_warn (LOGD_PPP, "%s", local->message);
dbus_g_method_return_error (priv->pending_secrets_context, local); g_dbus_method_invocation_take_error (priv->pending_secrets_context, local);
g_clear_error (&local);
goto out; goto out;
} }
@ -358,7 +342,9 @@ ppp_secrets_cb (NMActRequest *req,
* against libnm just to parse this. So instead, let's just send what * against libnm just to parse this. So instead, let's just send what
* it needs. * it needs.
*/ */
dbus_g_method_return (priv->pending_secrets_context, username, password); g_dbus_method_invocation_return_value (
priv->pending_secrets_context,
g_variant_new ("(ss)", username, password));
out: out:
priv->pending_secrets_context = NULL; priv->pending_secrets_context = NULL;
@ -368,7 +354,7 @@ ppp_secrets_cb (NMActRequest *req,
static void static void
impl_ppp_manager_need_secrets (NMPPPManager *manager, impl_ppp_manager_need_secrets (NMPPPManager *manager,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
NMConnection *connection; NMConnection *connection;
@ -391,8 +377,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager,
ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager); ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager);
} else { } else {
nm_log_warn (LOGD_PPP, "%s", error->message); nm_log_warn (LOGD_PPP, "%s", error->message);
dbus_g_method_return_error (priv->pending_secrets_context, error); g_dbus_method_invocation_take_error (priv->pending_secrets_context, error);
g_clear_error (&error);
} }
return; return;
} }
@ -418,33 +403,33 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager,
g_ptr_array_free (hints, TRUE); g_ptr_array_free (hints, TRUE);
} }
static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, static void
guint32 state, impl_ppp_manager_set_state (NMPPPManager *manager,
GError **err) GDBusMethodInvocation *context,
guint32 state)
{ {
g_signal_emit (manager, signals[STATE_CHANGED], 0, state); g_signal_emit (manager, signals[STATE_CHANGED], 0, state);
return TRUE; g_dbus_method_invocation_return_value (context, NULL);
} }
static gboolean static gboolean
set_ip_config_common (NMPPPManager *self, set_ip_config_common (NMPPPManager *self,
GHashTable *hash, GVariant *config_dict,
const char *iface_prop, const char *iface_prop,
guint32 *out_mtu) guint32 *out_mtu)
{ {
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
NMConnection *connection; NMConnection *connection;
NMSettingPpp *s_ppp; NMSettingPpp *s_ppp;
GValue *val; const char *iface;
val = g_hash_table_lookup (hash, iface_prop); if (!g_variant_lookup (config_dict, iface_prop, "&s", &iface)) {
if (!val || !G_VALUE_HOLDS_STRING (val)) {
nm_log_err (LOGD_PPP, "no interface received!"); nm_log_err (LOGD_PPP, "no interface received!");
return FALSE; return FALSE;
} }
if (priv->ip_iface == NULL) if (priv->ip_iface == NULL)
priv->ip_iface = g_value_dup_string (val); priv->ip_iface = g_strdup (iface);
/* Got successful IP config; obviously the secrets worked */ /* Got successful IP config; obviously the secrets worked */
connection = nm_act_request_get_connection (priv->act_req); connection = nm_act_request_get_connection (priv->act_req);
@ -460,17 +445,16 @@ set_ip_config_common (NMPPPManager *self,
return TRUE; return TRUE;
} }
static gboolean static void
impl_ppp_manager_set_ip4_config (NMPPPManager *manager, impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
GHashTable *config_hash, GDBusMethodInvocation *context,
GError **err) GVariant *config_dict)
{ {
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
NMIP4Config *config; NMIP4Config *config;
NMPlatformIP4Address address; NMPlatformIP4Address address;
GValue *val; guint32 u32;
int i; GVariantIter *iter;
guint32 mtu = 0;
nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received."); nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received.");
@ -481,19 +465,16 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof (address));
address.plen = 32; address.plen = 32;
val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY); if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &u32)) {
if (val) { nm_ip4_config_set_gateway (config, u32);
nm_ip4_config_set_gateway (config, g_value_get_uint (val)); address.peer_address = u32;
address.peer_address = g_value_get_uint (val);
} }
val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS); if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &u32))
if (val) address.address = u32;
address.address = g_value_get_uint (val);
val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX); if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32))
if (val) address.plen = u32;
address.plen = g_value_get_uint (val);
if (address.address && address.plen) { if (address.address && address.plen) {
address.source = NM_IP_CONFIG_SOURCE_PPP; address.source = NM_IP_CONFIG_SOURCE_PPP;
@ -503,55 +484,47 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
goto out; goto out;
} }
val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS); if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_DNS, "au", &iter)) {
if (val) { while (g_variant_iter_next (iter, "u", &u32))
GArray *dns = (GArray *) g_value_get_boxed (val); nm_ip4_config_add_nameserver (config, u32);
g_variant_iter_free (iter);
for (i = 0; i < dns->len; i++)
nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i));
} }
val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_WINS); if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_WINS, "au", &iter)) {
if (val) { while (g_variant_iter_next (iter, "u", &u32))
GArray *wins = (GArray *) g_value_get_boxed (val); nm_ip4_config_add_wins (config, u32);
g_variant_iter_free (iter);
for (i = 0; i < wins->len; i++)
nm_ip4_config_add_wins (config, g_array_index (wins, guint, i));
} }
if (!set_ip_config_common (manager, config_hash, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) if (!set_ip_config_common (manager, config_dict, NM_PPP_IP4_CONFIG_INTERFACE, &u32))
goto out; goto out;
if (mtu) if (u32)
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_PPP); nm_ip4_config_set_mtu (config, u32, NM_IP_CONFIG_SOURCE_PPP);
/* Push the IP4 config up to the device */ /* Push the IP4 config up to the device */
g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config); g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config);
out: out:
g_object_unref (config); g_object_unref (config);
return TRUE; g_dbus_method_invocation_return_value (context, NULL);
} }
/* Converts the named Interface Identifier item to an IPv6 LL address and /* Converts the named Interface Identifier item to an IPv6 LL address and
* returns the IID. * returns the IID.
*/ */
static gboolean static gboolean
iid_value_to_ll6_addr (GHashTable *hash, iid_value_to_ll6_addr (GVariant *dict,
const char *prop, const char *prop,
struct in6_addr *out_addr, struct in6_addr *out_addr,
NMUtilsIPv6IfaceId *out_iid) NMUtilsIPv6IfaceId *out_iid)
{ {
GValue *val;
guint64 iid; guint64 iid;
val = g_hash_table_lookup (hash, prop); if (!g_variant_lookup (dict, prop, "t", &iid)) {
if (!val || !G_VALUE_HOLDS (val, G_TYPE_UINT64)) {
nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop); nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop);
return FALSE; return FALSE;
} }
iid = g_value_get_uint64 (val);
g_return_val_if_fail (iid != 0, FALSE); g_return_val_if_fail (iid != 0, FALSE);
/* Construct an IPv6 LL address from the interface identifier. See /* Construct an IPv6 LL address from the interface identifier. See
@ -566,10 +539,10 @@ iid_value_to_ll6_addr (GHashTable *hash,
return TRUE; return TRUE;
} }
static gboolean static void
impl_ppp_manager_set_ip6_config (NMPPPManager *manager, impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
GHashTable *hash, GDBusMethodInvocation *context,
GError **err) GVariant *config_dict)
{ {
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
NMIP6Config *config; NMIP6Config *config;
@ -586,15 +559,15 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
memset (&addr, 0, sizeof (addr)); memset (&addr, 0, sizeof (addr));
addr.plen = 64; addr.plen = 64;
if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) {
nm_ip6_config_set_gateway (config, &a); nm_ip6_config_set_gateway (config, &a);
addr.peer_address = a; addr.peer_address = a;
} }
if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) {
nm_ip6_config_add_address (config, &addr); nm_ip6_config_add_address (config, &addr);
if (set_ip_config_common (manager, hash, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { if (set_ip_config_common (manager, config_dict, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) {
/* Push the IPv6 config and interface identifier up to the device */ /* Push the IPv6 config and interface identifier up to the device */
g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config); g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config);
} }
@ -602,7 +575,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
nm_log_err (LOGD_PPP, "invalid IPv6 address received!"); nm_log_err (LOGD_PPP, "invalid IPv6 address received!");
g_object_unref (config); g_object_unref (config);
return TRUE; g_dbus_method_invocation_return_value (context, NULL);
} }
static void static void
@ -667,7 +640,12 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class)
G_TYPE_UINT, G_TYPE_UINT); G_TYPE_UINT, G_TYPE_UINT);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class),
&dbus_glib_nm_ppp_manager_object_info); NMDBUS_TYPE_PPP_MANAGER_SKELETON,
"NeedSecrets", impl_ppp_manager_need_secrets,
"SetIp4Config", impl_ppp_manager_set_ip4_config,
"SetIp6Config", impl_ppp_manager_set_ip6_config,
"SetState", impl_ppp_manager_set_state,
NULL);
} }
/*******************************************/ /*******************************************/

View file

@ -15,7 +15,6 @@ AM_CPPFLAGS = \
AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
AM_LDFLAGS = \ AM_LDFLAGS = \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_LIBS) \
$(CODE_COVERAGE_LDFLAGS) $(CODE_COVERAGE_LDFLAGS)
@GNOME_CODE_COVERAGE_RULES@ @GNOME_CODE_COVERAGE_RULES@

View file

@ -23,16 +23,11 @@
#include <string.h> #include <string.h>
#include <pwd.h> #include <pwd.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-agent-manager.h" #include "nm-agent-manager.h"
#include "nm-secret-agent.h" #include "nm-secret-agent.h"
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-auth-utils.h"
#include "nm-setting-vpn.h" #include "nm-setting-vpn.h"
#include "nm-setting-connection.h" #include "nm-setting-connection.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
@ -41,6 +36,9 @@
#include "nm-session-monitor.h" #include "nm-session-monitor.h"
#include "nm-simple-connection.h" #include "nm-simple-connection.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-core-internal.h"
#include "nmdbus-agent-manager.h"
G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, NM_TYPE_EXPORTED_OBJECT) G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, NM_TYPE_EXPORTED_OBJECT)
@ -78,20 +76,6 @@ static void request_remove_agent (Request *req, NMSecretAgent *agent, GSList **p
static void request_next_agent (Request *req); static void request_next_agent (Request *req);
static void impl_agent_manager_register (NMAgentManager *self,
const char *identifier,
DBusGMethodInvocation *context);
static void impl_agent_manager_register_with_capabilities (NMAgentManager *self,
const char *identifier,
NMSecretAgentCapabilities capabilities,
DBusGMethodInvocation *context);
static void impl_agent_manager_unregister (NMAgentManager *self,
DBusGMethodInvocation *context);
#include "nm-agent-manager-glue.h"
/*************************************************************/ /*************************************************************/
static gboolean static gboolean
@ -130,6 +114,17 @@ remove_agent (NMAgentManager *self, const char *owner)
return TRUE; return TRUE;
} }
/* Call this *after* calling request_next_agent() */
static void
maybe_remove_agent_on_error (NMSecretAgent *agent,
GError *error)
{
if ( g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CLOSED)
|| g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_DISCONNECTED)
|| g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER))
remove_agent (nm_agent_manager_get (), nm_secret_agent_get_dbus_owner (agent));
}
/*************************************************************/ /*************************************************************/
static gboolean static gboolean
@ -190,7 +185,7 @@ validate_identifier (const char *identifier, GError **error)
static void static void
agent_register_permissions_done (NMAuthChain *chain, agent_register_permissions_done (NMAuthChain *chain,
GError *error, GError *error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data) gpointer user_data)
{ {
NMAgentManager *self = NM_AGENT_MANAGER (user_data); NMAgentManager *self = NM_AGENT_MANAGER (user_data);
@ -211,8 +206,7 @@ agent_register_permissions_done (NMAuthChain *chain,
NM_AGENT_MANAGER_ERROR_PERMISSION_DENIED, NM_AGENT_MANAGER_ERROR_PERMISSION_DENIED,
"Failed to request agent permissions: (%d) %s", "Failed to request agent permissions: (%d) %s",
error->code, error->message); error->code, error->message);
dbus_g_method_return_error (context, local); g_dbus_method_invocation_take_error (context, local);
g_error_free (local);
} else { } else {
agent = nm_auth_chain_steal_data (chain, "agent"); agent = nm_auth_chain_steal_data (chain, "agent");
g_assert (agent); g_assert (agent);
@ -229,7 +223,7 @@ agent_register_permissions_done (NMAuthChain *chain,
g_hash_table_insert (priv->agents, g_strdup (sender), agent); g_hash_table_insert (priv->agents, g_strdup (sender), agent);
nm_log_dbg (LOGD_AGENTS, "(%s) agent registered", nm_log_dbg (LOGD_AGENTS, "(%s) agent registered",
nm_secret_agent_get_description (agent)); nm_secret_agent_get_description (agent));
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
/* Signal an agent was registered */ /* Signal an agent was registered */
g_signal_emit (self, signals[AGENT_REGISTERED], 0, agent); g_signal_emit (self, signals[AGENT_REGISTERED], 0, agent);
@ -271,9 +265,9 @@ agent_disconnected_cb (NMSecretAgent *agent, gpointer user_data)
static void static void
impl_agent_manager_register_with_capabilities (NMAgentManager *self, impl_agent_manager_register_with_capabilities (NMAgentManager *self,
GDBusMethodInvocation *context,
const char *identifier, const char *identifier,
NMSecretAgentCapabilities capabilities, guint32 capabilities)
DBusGMethodInvocation *context)
{ {
NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self); NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self);
NMAuthSubject *subject; NMAuthSubject *subject;
@ -334,22 +328,21 @@ impl_agent_manager_register_with_capabilities (NMAgentManager *self,
done: done:
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
g_clear_object (&subject); g_clear_object (&subject);
} }
static void static void
impl_agent_manager_register (NMAgentManager *self, impl_agent_manager_register (NMAgentManager *self,
const char *identifier, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) const char *identifier)
{ {
impl_agent_manager_register_with_capabilities (self, identifier, 0, context); impl_agent_manager_register_with_capabilities (self, context, identifier, 0);
} }
static void static void
impl_agent_manager_unregister (NMAgentManager *self, impl_agent_manager_unregister (NMAgentManager *self,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
GError *error = NULL; GError *error = NULL;
char *sender = NULL; char *sender = NULL;
@ -373,19 +366,18 @@ impl_agent_manager_unregister (NMAgentManager *self,
goto done; goto done;
} }
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
done: done:
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
g_free (sender); g_free (sender);
} }
/*************************************************************/ /*************************************************************/
typedef void (*RequestCompleteFunc) (Request *req, typedef void (*RequestCompleteFunc) (Request *req,
GHashTable *secrets, GVariant *secrets,
const char *agent_dbus_owner, const char *agent_dbus_owner,
const char *agent_username, const char *agent_username,
GError *error, GError *error,
@ -481,7 +473,7 @@ request_free (Request *req)
static void static void
req_complete_success (Request *req, req_complete_success (Request *req,
GHashTable *secrets, GVariant *secrets,
const char *agent_dbus_owner, const char *agent_dbus_owner,
const char *agent_uname) const char *agent_uname)
{ {
@ -658,7 +650,7 @@ typedef struct {
char *setting_name; char *setting_name;
char **hints; char **hints;
GHashTable *existing_secrets; GVariant *existing_secrets;
NMAgentSecretsResultFunc callback; NMAgentSecretsResultFunc callback;
gpointer callback_data; gpointer callback_data;
@ -682,7 +674,7 @@ connection_request_free (gpointer data)
g_free (req->setting_name); g_free (req->setting_name);
g_strfreev (req->hints); g_strfreev (req->hints);
if (req->existing_secrets) if (req->existing_secrets)
g_hash_table_unref (req->existing_secrets); g_variant_unref (req->existing_secrets);
if (req->chain) if (req->chain)
nm_auth_chain_unref (req->chain); nm_auth_chain_unref (req->chain);
} }
@ -710,7 +702,7 @@ connection_request_add_agent (Request *parent, NMSecretAgent *agent)
static ConnectionRequest * static ConnectionRequest *
connection_request_new_get (NMConnection *connection, connection_request_new_get (NMConnection *connection,
NMAuthSubject *subject, NMAuthSubject *subject,
GHashTable *existing_secrets, GVariant *existing_secrets,
const char *setting_name, const char *setting_name,
const char *verb, const char *verb,
NMSecretAgentGetSecretsFlags flags, NMSecretAgentGetSecretsFlags flags,
@ -740,7 +732,7 @@ connection_request_new_get (NMConnection *connection,
req->connection = g_object_ref (connection); req->connection = g_object_ref (connection);
if (existing_secrets) if (existing_secrets)
req->existing_secrets = g_hash_table_ref (existing_secrets); req->existing_secrets = g_variant_ref (existing_secrets);
req->setting_name = g_strdup (setting_name); req->setting_name = g_strdup (setting_name);
req->hints = g_strdupv ((char **) hints); req->hints = g_strdupv ((char **) hints);
req->flags = flags; req->flags = flags;
@ -779,13 +771,13 @@ connection_request_new_other (NMConnection *connection,
static void static void
get_done_cb (NMSecretAgent *agent, get_done_cb (NMSecretAgent *agent,
gconstpointer call_id, gconstpointer call_id,
GHashTable *secrets, GVariant *secrets,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
Request *parent = user_data; Request *parent = user_data;
ConnectionRequest *req = user_data; ConnectionRequest *req = user_data;
GHashTable *setting_secrets; GVariant *setting_secrets;
const char *agent_dbus_owner; const char *agent_dbus_owner;
struct passwd *pw; struct passwd *pw;
char *agent_uname = NULL; char *agent_uname = NULL;
@ -799,7 +791,7 @@ get_done_cb (NMSecretAgent *agent,
error ? error->code : -1, error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)"); (error && error->message) ? error->message : "(unknown)");
if (dbus_g_error_has_name (error, NM_DBUS_INTERFACE_SECRET_AGENT ".UserCanceled")) { if (_nm_dbus_error_has_name (error, NM_DBUS_INTERFACE_SECRET_AGENT ".UserCanceled")) {
error = g_error_new_literal (NM_AGENT_MANAGER_ERROR, error = g_error_new_literal (NM_AGENT_MANAGER_ERROR,
NM_AGENT_MANAGER_ERROR_USER_CANCELED, NM_AGENT_MANAGER_ERROR_USER_CANCELED,
"User canceled the secrets request."); "User canceled the secrets request.");
@ -808,13 +800,14 @@ get_done_cb (NMSecretAgent *agent,
} else { } else {
/* Try the next agent */ /* Try the next agent */
request_next_agent (parent); request_next_agent (parent);
maybe_remove_agent_on_error (agent, error);
} }
return; return;
} }
/* Ensure the setting we wanted secrets for got returned and has something in it */ /* Ensure the setting we wanted secrets for got returned and has something in it */
setting_secrets = g_hash_table_lookup (secrets, req->setting_name); setting_secrets = g_variant_lookup_value (secrets, req->setting_name, NM_VARIANT_TYPE_SETTING);
if (!setting_secrets || !g_hash_table_size (setting_secrets)) { if (!setting_secrets || !g_variant_n_children (setting_secrets)) {
nm_log_dbg (LOGD_AGENTS, "(%s) agent returned no secrets for request %p/%s/%s", nm_log_dbg (LOGD_AGENTS, "(%s) agent returned no secrets for request %p/%s/%s",
nm_secret_agent_get_description (agent), nm_secret_agent_get_description (agent),
req, parent->detail, req->setting_name); req, parent->detail, req->setting_name);
@ -841,40 +834,40 @@ get_done_cb (NMSecretAgent *agent,
} }
static void static void
set_secrets_not_required (NMConnection *connection, GHashTable *hash) set_secrets_not_required (NMConnection *connection, GVariant *dict)
{ {
GHashTableIter iter, setting_iter; GVariantIter iter, setting_iter;
const char *setting_name = NULL; const char *setting_name = NULL;
GHashTable *setting_hash = NULL; GVariant *setting_dict = NULL;
/* Iterate through the settings hashes */ /* Iterate through the settings dicts */
g_hash_table_iter_init (&iter, hash); g_variant_iter_init (&iter, dict);
while (g_hash_table_iter_next (&iter, while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting_dict)) {
(gpointer *) &setting_name,
(gpointer *) &setting_hash)) {
const char *key_name = NULL; const char *key_name = NULL;
NMSetting *setting; NMSetting *setting;
GValue *val; GVariant *val;
setting = nm_connection_get_setting_by_name (connection, setting_name); setting = nm_connection_get_setting_by_name (connection, setting_name);
if (setting) { if (setting) {
/* Now through each secret in the setting and mark it as not required */ /* Now through each secret in the setting and mark it as not required */
g_hash_table_iter_init (&setting_iter, setting_hash); g_variant_iter_init (&setting_iter, setting_dict);
while (g_hash_table_iter_next (&setting_iter, (gpointer *) &key_name, (gpointer *) &val)) { while (g_variant_iter_next (&setting_iter, "{&sv}", &key_name, &val)) {
/* For each secret, set the flag that it's not required; VPN /* For each secret, set the flag that it's not required; VPN
* secrets need slightly different treatment here since the * secrets need slightly different treatment here since the
* "secrets" property is actually a hash table of secrets. * "secrets" property is actually a dictionary of secrets.
*/ */
if ( strcmp (setting_name, NM_SETTING_VPN_SETTING_NAME) == 0 if ( strcmp (setting_name, NM_SETTING_VPN_SETTING_NAME) == 0
&& strcmp (key_name, NM_SETTING_VPN_SECRETS) == 0) { && strcmp (key_name, NM_SETTING_VPN_SECRETS) == 0
GHashTableIter vpn_secret_iter; && g_variant_is_of_type (val, G_VARIANT_TYPE ("a{ss}"))) {
const char *secret_name; GVariantIter vpn_secret_iter;
const char *secret_name, *secret;
g_hash_table_iter_init (&vpn_secret_iter, g_value_get_boxed (val)); g_variant_iter_init (&vpn_secret_iter, val);
while (g_hash_table_iter_next (&vpn_secret_iter, (gpointer *) &secret_name, NULL)) while (g_variant_iter_next (&vpn_secret_iter, "{&s&s}", &secret_name, &secret))
nm_setting_set_secret_flags (setting, secret_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL); nm_setting_set_secret_flags (setting, secret_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL);
} else } else
nm_setting_set_secret_flags (setting, key_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL); nm_setting_set_secret_flags (setting, key_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL);
g_variant_unref (val);
} }
} }
} }
@ -889,13 +882,8 @@ get_agent_request_secrets (ConnectionRequest *req, gboolean include_system_secre
tmp = nm_simple_connection_new_clone (req->connection); tmp = nm_simple_connection_new_clone (req->connection);
nm_connection_clear_secrets (tmp); nm_connection_clear_secrets (tmp);
if (include_system_secrets) { if (include_system_secrets) {
if (req->existing_secrets) { if (req->existing_secrets)
GVariant *secrets_dict; (void) nm_connection_update_secrets (tmp, req->setting_name, req->existing_secrets, NULL);
secrets_dict = nm_utils_connection_hash_to_dict (req->existing_secrets);
(void) nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, NULL);
g_variant_unref (secrets_dict);
}
} else { } else {
/* Update secret flags in the temporary connection to indicate that /* Update secret flags in the temporary connection to indicate that
* the system secrets we're not sending to the agent aren't required, * the system secrets we're not sending to the agent aren't required,
@ -924,7 +912,7 @@ get_agent_request_secrets (ConnectionRequest *req, gboolean include_system_secre
static void static void
get_agent_modify_auth_cb (NMAuthChain *chain, get_agent_modify_auth_cb (NMAuthChain *chain,
GError *error, GError *error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data) gpointer user_data)
{ {
Request *parent = user_data; Request *parent = user_data;
@ -1058,19 +1046,18 @@ get_start (gpointer user_data)
{ {
Request *parent = user_data; Request *parent = user_data;
ConnectionRequest *req = user_data; ConnectionRequest *req = user_data;
GHashTable *setting_secrets = NULL; GVariant *setting_secrets = NULL;
parent->idle_id = 0; parent->idle_id = 0;
/* Check if there are any existing secrets */ /* Check if there are any existing secrets */
if (req->existing_secrets) if (req->existing_secrets)
setting_secrets = g_hash_table_lookup (req->existing_secrets, req->setting_name); setting_secrets = g_variant_lookup_value (req->existing_secrets, req->setting_name, NM_VARIANT_TYPE_SETTING);
if (setting_secrets && g_hash_table_size (setting_secrets)) { if (setting_secrets && g_variant_n_children (setting_secrets)) {
NMConnection *tmp; NMConnection *tmp;
GError *error = NULL; GError *error = NULL;
gboolean new_secrets = (req->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW); gboolean new_secrets = (req->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW);
GVariant *secrets_dict;
/* The connection already had secrets; check if any more are required. /* The connection already had secrets; check if any more are required.
* If no more are required, we're done. If secrets are still needed, * If no more are required, we're done. If secrets are still needed,
@ -1080,8 +1067,7 @@ get_start (gpointer user_data)
tmp = nm_simple_connection_new_clone (req->connection); tmp = nm_simple_connection_new_clone (req->connection);
g_assert (tmp); g_assert (tmp);
secrets_dict = nm_utils_connection_hash_to_dict (req->existing_secrets); if (!nm_connection_update_secrets (tmp, req->setting_name, req->existing_secrets, &error)) {
if (!nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, &error)) {
req_complete_error (parent, error); req_complete_error (parent, error);
g_clear_error (&error); g_clear_error (&error);
} else { } else {
@ -1107,7 +1093,6 @@ get_start (gpointer user_data)
request_next_agent (parent); request_next_agent (parent);
} }
} }
g_variant_unref (secrets_dict);
g_object_unref (tmp); g_object_unref (tmp);
} else { } else {
/* Couldn't get secrets from system settings, so now we ask the /* Couldn't get secrets from system settings, so now we ask the
@ -1117,12 +1102,15 @@ get_start (gpointer user_data)
request_next_agent (parent); request_next_agent (parent);
} }
if (setting_secrets)
g_variant_unref (setting_secrets);
return FALSE; return FALSE;
} }
static void static void
get_complete_cb (Request *parent, get_complete_cb (Request *parent,
GHashTable *secrets, GVariant *secrets,
const char *agent_dbus_owner, const char *agent_dbus_owner,
const char *agent_username, const char *agent_username,
GError *error, GError *error,
@ -1163,7 +1151,7 @@ guint32
nm_agent_manager_get_secrets (NMAgentManager *self, nm_agent_manager_get_secrets (NMAgentManager *self,
NMConnection *connection, NMConnection *connection,
NMAuthSubject *subject, NMAuthSubject *subject,
GHashTable *existing_secrets, GVariant *existing_secrets,
const char *setting_name, const char *setting_name,
NMSecretAgentGetSecretsFlags flags, NMSecretAgentGetSecretsFlags flags,
const char **hints, const char **hints,
@ -1233,7 +1221,7 @@ nm_agent_manager_cancel_secrets (NMAgentManager *self,
static void static void
save_done_cb (NMSecretAgent *agent, save_done_cb (NMSecretAgent *agent,
gconstpointer call_id, gconstpointer call_id,
GHashTable *secrets, GVariant *secrets,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
@ -1251,6 +1239,7 @@ save_done_cb (NMSecretAgent *agent,
(error && error->message) ? error->message : "(unknown)"); (error && error->message) ? error->message : "(unknown)");
/* Try the next agent */ /* Try the next agent */
request_next_agent (parent); request_next_agent (parent);
maybe_remove_agent_on_error (agent, error);
return; return;
} }
@ -1280,7 +1269,7 @@ save_next_cb (Request *parent)
static void static void
save_complete_cb (Request *req, save_complete_cb (Request *req,
GHashTable *secrets, GVariant *secrets,
const char *agent_dbus_owner, const char *agent_dbus_owner,
const char *agent_username, const char *agent_username,
GError *error, GError *error,
@ -1327,7 +1316,7 @@ nm_agent_manager_save_secrets (NMAgentManager *self,
static void static void
delete_done_cb (NMSecretAgent *agent, delete_done_cb (NMSecretAgent *agent,
gconstpointer call_id, gconstpointer call_id,
GHashTable *secrets, GVariant *secrets,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
@ -1347,6 +1336,8 @@ delete_done_cb (NMSecretAgent *agent,
/* Tell the next agent to delete secrets */ /* Tell the next agent to delete secrets */
request_next_agent (req); request_next_agent (req);
if (error)
maybe_remove_agent_on_error (agent, error);
} }
static void static void
@ -1367,7 +1358,7 @@ delete_next_cb (Request *parent)
static void static void
delete_complete_cb (Request *req, delete_complete_cb (Request *req,
GHashTable *secrets, GVariant *secrets,
const char *agent_dbus_owner, const char *agent_dbus_owner,
const char *agent_username, const char *agent_username,
GError *error, GError *error,
@ -1460,7 +1451,7 @@ nm_agent_manager_all_agents_have_capability (NMAgentManager *manager,
static void static void
agent_permissions_changed_done (NMAuthChain *chain, agent_permissions_changed_done (NMAuthChain *chain,
GError *error, GError *error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data) gpointer user_data)
{ {
NMAgentManager *self = NM_AGENT_MANAGER (user_data); NMAgentManager *self = NM_AGENT_MANAGER (user_data);
@ -1609,9 +1600,9 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class)
G_TYPE_OBJECT); G_TYPE_OBJECT);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (agent_manager_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (agent_manager_class),
&dbus_glib_nm_agent_manager_object_info); NMDBUS_TYPE_AGENT_MANAGER_SKELETON,
"Register", impl_agent_manager_register,
dbus_g_error_domain_register (NM_AGENT_MANAGER_ERROR, "RegisterWithCapabilities", impl_agent_manager_register_with_capabilities,
NM_DBUS_INTERFACE_AGENT_MANAGER, "Unregister", impl_agent_manager_unregister,
NM_TYPE_AGENT_MANAGER_ERROR); NULL);
} }

View file

@ -56,7 +56,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager,
gboolean agent_has_modify, gboolean agent_has_modify,
const char *setting_name, const char *setting_name,
NMSecretAgentGetSecretsFlags flags, NMSecretAgentGetSecretsFlags flags,
GHashTable *secrets, GVariant *secrets,
GError *error, GError *error,
gpointer user_data, gpointer user_data,
gpointer other_data2, gpointer other_data2,
@ -65,7 +65,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager,
guint32 nm_agent_manager_get_secrets (NMAgentManager *manager, guint32 nm_agent_manager_get_secrets (NMAgentManager *manager,
NMConnection *connection, NMConnection *connection,
NMAuthSubject *subject, NMAuthSubject *subject,
GHashTable *existing_secrets, GVariant *existing_secrets,
const char *setting_name, const char *setting_name,
NMSecretAgentGetSecretsFlags flags, NMSecretAgentGetSecretsFlags flags,
const char **hints, const char **hints,

View file

@ -23,17 +23,14 @@
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h> #include <pwd.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-secret-agent.h" #include "nm-secret-agent.h"
#include "nm-bus-manager.h" #include "nm-bus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-auth-subject.h" #include "nm-auth-subject.h"
#include "nm-simple-connection.h" #include "nm-simple-connection.h"
#include "NetworkManagerUtils.h"
#include "nmdbus-secret-agent.h"
G_DEFINE_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT) G_DEFINE_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT)
@ -52,7 +49,7 @@ typedef struct {
GSList *permissions; GSList *permissions;
DBusGProxy *proxy; NMDBusSecretAgent *proxy;
GHashTable *requests; GHashTable *requests;
} NMSecretAgentPrivate; } NMSecretAgentPrivate;
@ -68,7 +65,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
typedef struct { typedef struct {
NMSecretAgent *agent; NMSecretAgent *agent;
DBusGProxyCall *call; GCancellable *cancellable;
char *path; char *path;
char *setting_name; char *setting_name;
NMSecretAgentCallback callback; NMSecretAgentCallback callback;
@ -90,6 +87,7 @@ request_new (NMSecretAgent *agent,
r->setting_name = g_strdup (setting_name); r->setting_name = g_strdup (setting_name);
r->callback = callback; r->callback = callback;
r->callback_data = callback_data; r->callback_data = callback_data;
r->cancellable = g_cancellable_new ();
return r; return r;
} }
@ -98,6 +96,7 @@ request_free (Request *r)
{ {
g_free (r->path); g_free (r->path);
g_free (r->setting_name); g_free (r->setting_name);
g_object_unref (r->cancellable);
g_slice_free (Request, r); g_slice_free (Request, r);
} }
@ -258,25 +257,26 @@ nm_secret_agent_has_permission (NMSecretAgent *agent, const char *permission)
/*************************************************************/ /*************************************************************/
static void static void
get_callback (DBusGProxy *proxy, get_callback (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
void *user_data) gpointer user_data)
{ {
Request *r = user_data; Request *r = user_data;
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent);
GVariant *secrets = NULL;
GError *error = NULL; GError *error = NULL;
GHashTable *secrets = NULL;
g_return_if_fail (call == r->call); if (!g_cancellable_is_cancelled (r->cancellable)) {
nmdbus_secret_agent_call_get_secrets_finish (priv->proxy, &secrets, result, &error);
if (error)
g_dbus_error_strip_remote_error (error);
dbus_g_proxy_end_call (proxy, call, &error, r->callback (r->agent, r, secrets, error, r->callback_data);
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets, g_clear_pointer (&secrets, g_variant_unref);
G_TYPE_INVALID); g_clear_error (&error);
r->callback (r->agent, r->call, secrets, error, r->callback_data); }
if (secrets)
g_hash_table_unref (secrets); g_hash_table_remove (priv->requests, r);
g_clear_error (&error);
g_hash_table_remove (priv->requests, call);
} }
gconstpointer gconstpointer
@ -289,8 +289,8 @@ nm_secret_agent_get_secrets (NMSecretAgent *self,
gpointer callback_data) gpointer callback_data)
{ {
NMSecretAgentPrivate *priv; NMSecretAgentPrivate *priv;
static const char *no_hints[] = { NULL };
GVariant *dict; GVariant *dict;
GHashTable *hash;
Request *r; Request *r;
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
@ -301,123 +301,81 @@ nm_secret_agent_get_secrets (NMSecretAgent *self,
g_return_val_if_fail (priv->proxy != NULL, NULL); g_return_val_if_fail (priv->proxy != NULL, NULL);
dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
hash = nm_utils_connection_dict_to_hash (dict);
g_variant_unref (dict);
/* Mask off the private flags if present */ /* Mask off the private flags if present */
flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_ONLY_SYSTEM; flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_ONLY_SYSTEM;
flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_NO_ERRORS; flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_NO_ERRORS;
r = request_new (self, nm_connection_get_path (connection), setting_name, callback, callback_data); r = request_new (self, nm_connection_get_path (connection), setting_name, callback, callback_data);
r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, nmdbus_secret_agent_call_get_secrets (priv->proxy,
"GetSecrets", dict,
get_callback, nm_connection_get_path (connection),
r, setting_name,
NULL, hints ? hints : no_hints,
120000, /* 120 seconds */ flags,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, r->cancellable,
DBUS_TYPE_G_OBJECT_PATH, nm_connection_get_path (connection), get_callback, r);
G_TYPE_STRING, setting_name, g_hash_table_insert (priv->requests, r, r);
G_TYPE_STRV, hints,
G_TYPE_UINT, flags,
G_TYPE_INVALID);
g_hash_table_insert (priv->requests, r->call, r);
g_hash_table_destroy (hash); return r;
return r->call;
} }
static void static void
cancel_done (DBusGProxy *proxy, DBusGProxyCall *call_id, void *user_data) cancel_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
char *description = user_data;
GError *error = NULL; GError *error = NULL;
if (!dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) { if (!nmdbus_secret_agent_call_cancel_get_secrets_finish (NMDBUS_SECRET_AGENT (proxy), result, &error)) {
nm_log_dbg (LOGD_AGENTS, "(%s): agent failed to cancel secrets: (%d) %s", g_dbus_error_strip_remote_error (error);
(const char *) user_data, nm_log_dbg (LOGD_AGENTS, "(%s): agent failed to cancel secrets: %s",
error ? error->code : -1, description, error->message);
error && error->message ? error->message : "(unknown)");
g_clear_error (&error); g_clear_error (&error);
} }
g_free (description);
} }
void void
nm_secret_agent_cancel_secrets (NMSecretAgent *self, gconstpointer call) nm_secret_agent_cancel_secrets (NMSecretAgent *self, gconstpointer call)
{ {
NMSecretAgentPrivate *priv; NMSecretAgentPrivate *priv;
Request *r; Request *r = (gpointer) call;
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
priv = NM_SECRET_AGENT_GET_PRIVATE (self); priv = NM_SECRET_AGENT_GET_PRIVATE (self);
g_return_if_fail (priv->proxy != NULL); g_return_if_fail (priv->proxy != NULL);
r = g_hash_table_lookup (priv->requests, call);
g_return_if_fail (r != NULL); g_return_if_fail (r != NULL);
dbus_g_proxy_cancel_call (priv->proxy, (gpointer) call); g_cancellable_cancel (r->cancellable);
dbus_g_proxy_begin_call (priv->proxy, nmdbus_secret_agent_call_cancel_get_secrets (priv->proxy,
"CancelGetSecrets", r->path, r->setting_name,
cancel_done, NULL,
g_strdup (nm_secret_agent_get_description (self)), cancel_done,
g_free, g_strdup (nm_secret_agent_get_description (self)));
DBUS_TYPE_G_OBJECT_PATH, r->path,
G_TYPE_STRING, r->setting_name,
G_TYPE_INVALID);
g_hash_table_remove (priv->requests, call);
} }
/*************************************************************/ /*************************************************************/
static void static void
agent_save_delete_cb (DBusGProxy *proxy, agent_save_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
void *user_data) gpointer user_data)
{ {
Request *r = user_data; Request *r = user_data;
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent);
GError *error = NULL; GError *error = NULL;
g_return_if_fail (call == r->call); if (!g_cancellable_is_cancelled (r->cancellable)) {
nmdbus_secret_agent_call_save_secrets_finish (priv->proxy, result, &error);
if (error)
g_dbus_error_strip_remote_error (error);
r->callback (r->agent, r, NULL, error, r->callback_data);
g_clear_error (&error);
}
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); g_hash_table_remove (priv->requests, r);
r->callback (r->agent, r->call, NULL, error, r->callback_data);
g_clear_error (&error);
g_hash_table_remove (priv->requests, call);
}
static gpointer
agent_new_save_delete (NMSecretAgent *self,
NMConnection *connection,
NMConnectionSerializationFlags flags,
const char *method,
NMSecretAgentCallback callback,
gpointer callback_data)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GVariant *dict;
GHashTable *hash;
Request *r;
const char *cpath = nm_connection_get_path (connection);
dict = nm_connection_to_dbus (connection, flags);
hash = nm_utils_connection_dict_to_hash (dict);
g_variant_unref (dict);
r = request_new (self, cpath, NULL, callback, callback_data);
r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy,
method,
agent_save_delete_cb,
r,
NULL,
10000, /* 10 seconds */
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash,
DBUS_TYPE_G_OBJECT_PATH, cpath,
G_TYPE_INVALID);
g_hash_table_insert (priv->requests, r->call, r);
g_hash_table_destroy (hash);
return r->call;
} }
gconstpointer gconstpointer
@ -426,16 +384,46 @@ nm_secret_agent_save_secrets (NMSecretAgent *self,
NMSecretAgentCallback callback, NMSecretAgentCallback callback,
gpointer callback_data) gpointer callback_data)
{ {
NMSecretAgentPrivate *priv;
GVariant *dict;
Request *r;
const char *cpath;
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL);
priv = NM_SECRET_AGENT_GET_PRIVATE (self);
cpath = nm_connection_get_path (connection);
/* Caller should have ensured that only agent-owned secrets exist in 'connection' */ /* Caller should have ensured that only agent-owned secrets exist in 'connection' */
return agent_new_save_delete (self, dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
connection,
NM_CONNECTION_SERIALIZE_ALL, r = request_new (self, cpath, NULL, callback, callback_data);
"SaveSecrets", nmdbus_secret_agent_call_save_secrets (priv->proxy,
callback, dict, cpath,
callback_data); NULL,
agent_save_cb, r);
g_hash_table_insert (priv->requests, r, r);
return r;
}
static void
agent_delete_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
Request *r = user_data;
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent);
GError *error = NULL;
if (!g_cancellable_is_cancelled (r->cancellable)) {
nmdbus_secret_agent_call_delete_secrets_finish (priv->proxy, result, &error);
r->callback (r->agent, r, NULL, error, r->callback_data);
g_clear_error (&error);
}
g_hash_table_remove (priv->requests, r);
} }
gconstpointer gconstpointer
@ -444,54 +432,54 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self,
NMSecretAgentCallback callback, NMSecretAgentCallback callback,
gpointer callback_data) gpointer callback_data)
{ {
NMSecretAgentPrivate *priv;
GVariant *dict;
Request *r;
const char *cpath;
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL);
priv = NM_SECRET_AGENT_GET_PRIVATE (self);
cpath = nm_connection_get_path (connection);
/* No secrets sent; agents must be smart enough to track secrets using the UUID or something */ /* No secrets sent; agents must be smart enough to track secrets using the UUID or something */
return agent_new_save_delete (self, dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS);
connection,
NM_CONNECTION_SERIALIZE_NO_SECRETS, r = request_new (self, cpath, NULL, callback, callback_data);
"DeleteSecrets", nmdbus_secret_agent_call_delete_secrets (priv->proxy,
callback, dict, cpath,
callback_data); NULL,
agent_delete_cb, r);
g_hash_table_insert (priv->requests, r, r);
return r;
} }
static void proxy_cleanup (NMSecretAgent *self);
static void static void
name_owner_changed_cb (NMBusManager *dbus_mgr, name_owner_changed_cb (GObject *proxy,
const char *name, GParamSpec *pspec,
const char *old_owner,
const char *new_owner,
gpointer user_data) gpointer user_data)
{ {
NMSecretAgent *self = NM_SECRET_AGENT (user_data); NMSecretAgent *self = NM_SECRET_AGENT (user_data);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
char *owner;
if (!new_owner && !g_strcmp0 (old_owner, priv->dbus_owner)) owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
proxy_cleanup (self); if (!owner) {
} g_signal_handlers_disconnect_by_func (priv->proxy, name_owner_changed_cb, self);
static void
proxy_cleanup (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (priv->proxy) {
g_signal_handlers_disconnect_by_func (priv->proxy, proxy_cleanup, self);
g_clear_object (&priv->proxy); g_clear_object (&priv->proxy);
g_signal_handlers_disconnect_by_func (nm_bus_manager_get (), name_owner_changed_cb, self);
g_signal_emit (self, signals[DISCONNECTED], 0); g_signal_emit (self, signals[DISCONNECTED], 0);
g_clear_pointer (&priv->dbus_owner, g_free); g_clear_pointer (&priv->dbus_owner, g_free);
} } else
g_free (owner);
} }
/*************************************************************/ /*************************************************************/
NMSecretAgent * NMSecretAgent *
nm_secret_agent_new (DBusGMethodInvocation *context, nm_secret_agent_new (GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
const char *identifier, const char *identifier,
NMSecretAgentCapabilities capabilities) NMSecretAgentCapabilities capabilities)
@ -500,6 +488,7 @@ nm_secret_agent_new (DBusGMethodInvocation *context,
NMSecretAgentPrivate *priv; NMSecretAgentPrivate *priv;
char *hash_str; char *hash_str;
struct passwd *pw; struct passwd *pw;
GDBusProxy *proxy;
g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (context != NULL, NULL);
g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL); g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL);
@ -523,18 +512,17 @@ nm_secret_agent_new (DBusGMethodInvocation *context,
priv->hash = g_str_hash (hash_str); priv->hash = g_str_hash (hash_str);
g_free (hash_str); g_free (hash_str);
priv->proxy = nm_bus_manager_new_proxy (nm_bus_manager_get (), proxy = nm_bus_manager_new_proxy (nm_bus_manager_get (),
context, context,
priv->dbus_owner, NMDBUS_TYPE_SECRET_AGENT_PROXY,
NM_DBUS_PATH_SECRET_AGENT, priv->dbus_owner,
NM_DBUS_INTERFACE_SECRET_AGENT); NM_DBUS_PATH_SECRET_AGENT,
g_assert (priv->proxy); NM_DBUS_INTERFACE_SECRET_AGENT);
g_signal_connect_swapped (priv->proxy, "destroy", g_assert (proxy);
G_CALLBACK (proxy_cleanup), self); g_signal_connect (proxy, "notify::g-name-owner",
g_signal_connect (nm_bus_manager_get (),
NM_BUS_MANAGER_NAME_OWNER_CHANGED,
G_CALLBACK (name_owner_changed_cb), G_CALLBACK (name_owner_changed_cb),
self); self);
priv->proxy = NMDBUS_SECRET_AGENT (proxy);
return self; return self;
} }
@ -553,7 +541,7 @@ dispose (GObject *object)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (object); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (object);
proxy_cleanup (NM_SECRET_AGENT (object)); g_clear_object (&priv->proxy);
g_clear_object (&priv->subject); g_clear_object (&priv->subject);
G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object); G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object);

View file

@ -21,7 +21,6 @@
#ifndef __NETWORKMANAGER_SECRET_AGENT_H__ #ifndef __NETWORKMANAGER_SECRET_AGENT_H__
#define __NETWORKMANAGER_SECRET_AGENT_H__ #define __NETWORKMANAGER_SECRET_AGENT_H__
#include <nm-connection.h> #include <nm-connection.h>
#include "nm-default.h" #include "nm-default.h"
@ -46,7 +45,7 @@ typedef struct {
GType nm_secret_agent_get_type (void); GType nm_secret_agent_get_type (void);
NMSecretAgent *nm_secret_agent_new (DBusGMethodInvocation *context, NMSecretAgent *nm_secret_agent_new (GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
const char *identifier, const char *identifier,
NMSecretAgentCapabilities capabilities); NMSecretAgentCapabilities capabilities);
@ -78,7 +77,7 @@ gboolean nm_secret_agent_has_permission (NMSecretAgent *agent,
typedef void (*NMSecretAgentCallback) (NMSecretAgent *agent, typedef void (*NMSecretAgentCallback) (NMSecretAgent *agent,
gconstpointer call, gconstpointer call,
GHashTable *new_secrets, /* NULL for save & delete */ GVariant *new_secrets, /* NULL for save & delete */
GError *error, GError *error,
gpointer user_data); gpointer user_data);

View file

@ -24,12 +24,10 @@
#include <string.h> #include <string.h>
#include <nm-dbus-interface.h> #include <nm-dbus-interface.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-session-monitor.h" #include "nm-session-monitor.h"
#include "nm-dbus-glib-types.h"
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-auth-subject.h" #include "nm-auth-subject.h"
#include "nm-agent-manager.h" #include "nm-agent-manager.h"
@ -37,10 +35,11 @@
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-audit-manager.h" #include "nm-audit-manager.h"
#include "nmdbus-settings-connection.h"
#define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps"
#define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids"
#define _LOG_DOMAIN LOGD_SETTINGS #define _LOG_DOMAIN LOGD_SETTINGS
#define _LOG_PREFIX_NAME "settings-connection" #define _LOG_PREFIX_NAME "settings-connection"
@ -81,33 +80,6 @@
#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) #define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__)
#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) #define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__)
static void impl_settings_connection_get_settings (NMSettingsConnection *self,
DBusGMethodInvocation *context);
static void impl_settings_connection_update (NMSettingsConnection *self,
GHashTable *new_settings,
DBusGMethodInvocation *context);
static void impl_settings_connection_update_unsaved (NMSettingsConnection *self,
GHashTable *new_settings,
DBusGMethodInvocation *context);
static void impl_settings_connection_save (NMSettingsConnection *self,
DBusGMethodInvocation *context);
static void impl_settings_connection_delete (NMSettingsConnection *self,
DBusGMethodInvocation *context);
static void impl_settings_connection_get_secrets (NMSettingsConnection *self,
const gchar *setting_name,
DBusGMethodInvocation *context);
static void impl_settings_connection_clear_secrets (NMSettingsConnection *self,
DBusGMethodInvocation *context);
#include "nm-settings-connection-glue.h"
static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface); static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_EXPORTED_OBJECT, G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_EXPORTED_OBJECT,
@ -183,88 +155,93 @@ typedef struct {
typedef gboolean (*ForEachSecretFunc) (NMSettingSecretFlags flags, typedef gboolean (*ForEachSecretFunc) (NMSettingSecretFlags flags,
gpointer user_data); gpointer user_data);
static void static GVariant *
for_each_secret (NMConnection *self, for_each_secret (NMConnection *self,
GHashTable *secrets, GVariant *secrets,
gboolean remove_non_secrets, gboolean remove_non_secrets,
ForEachSecretFunc callback, ForEachSecretFunc callback,
gpointer callback_data) gpointer callback_data)
{ {
GHashTableIter iter; GVariantBuilder secrets_builder, setting_builder;
GVariantIter secrets_iter, *setting_iter;
const char *setting_name; const char *setting_name;
GHashTable *setting_hash;
/* This function, given a hash of hashes representing new secrets of /* This function, given a dict of dicts representing new secrets of
* an NMConnection, walks through each toplevel hash (which represents a * an NMConnection, walks through each toplevel dict (which represents a
* NMSetting), and for each setting, walks through that setting hash's * NMSetting), and for each setting, walks through that setting dict's
* properties. For each property that's a secret, it will check that * properties. For each property that's a secret, it will check that
* secret's flags in the backing NMConnection object, and call a supplied * secret's flags in the backing NMConnection object, and call a supplied
* callback. * callback.
* *
* The one complexity is that the VPN setting's 'secrets' property is * The one complexity is that the VPN setting's 'secrets' property is
* *also* a hash table (since the key/value pairs are arbitrary and known * *also* a dict (since the key/value pairs are arbitrary and known
* only to the VPN plugin itself). That means we have three levels of * only to the VPN plugin itself). That means we have three levels of
* GHashTables that we potentially have to traverse here. When we hit the * dicts that we potentially have to traverse here. When we hit the
* VPN setting's 'secrets' property, we special-case that and iterate over * VPN setting's 'secrets' property, we special-case that and iterate over
* each item in that 'secrets' hash table, calling the supplied callback * each item in that 'secrets' dict, calling the supplied callback
* each time. * each time.
*/ */
g_return_if_fail (callback); g_return_val_if_fail (callback, NULL);
/* Walk through the list of setting hashes */ g_variant_iter_init (&secrets_iter, secrets);
g_hash_table_iter_init (&iter, secrets); g_variant_builder_init (&secrets_builder, NM_VARIANT_TYPE_CONNECTION);
while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) { while (g_variant_iter_next (&secrets_iter, "{&sa{sv}}", &setting_name, &setting_iter)) {
NMSetting *setting; NMSetting *setting;
GHashTableIter secret_iter;
const char *secret_name; const char *secret_name;
GValue *val; GVariant *val;
if (g_hash_table_size (setting_hash) == 0)
continue;
/* Get the actual NMSetting from the connection so we can get secret flags
* from the connection data, since flags aren't secrets. What we're
* iterating here is just the secrets, not a whole connection.
*/
setting = nm_connection_get_setting_by_name (self, setting_name); setting = nm_connection_get_setting_by_name (self, setting_name);
if (setting == NULL) if (setting == NULL) {
g_variant_iter_free (setting_iter);
continue; continue;
}
/* Walk through the list of keys in each setting hash */ g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING);
g_hash_table_iter_init (&secret_iter, setting_hash); while (g_variant_iter_next (setting_iter, "{sv}", &secret_name, &val)) {
while (g_hash_table_iter_next (&secret_iter, (gpointer) &secret_name, (gpointer) &val)) {
NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
/* VPN secrets need slightly different treatment here since the /* VPN secrets need slightly different treatment here since the
* "secrets" property is actually a hash table of secrets. * "secrets" property is actually a hash table of secrets.
*/ */
if (NM_IS_SETTING_VPN (setting) && (g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS) == 0)) { if (NM_IS_SETTING_VPN (setting) && !g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS)) {
GHashTableIter vpn_secrets_iter; GVariantBuilder vpn_secrets_builder;
GVariantIter vpn_secrets_iter;
const char *vpn_secret_name, *secret;
/* Iterate through each secret from the VPN hash in the overall secrets hash */ /* Iterate through each secret from the VPN dict in the overall secrets dict */
g_hash_table_iter_init (&vpn_secrets_iter, g_value_get_boxed (val)); g_variant_builder_init (&vpn_secrets_builder, G_VARIANT_TYPE ("a{ss}"));
while (g_hash_table_iter_next (&vpn_secrets_iter, (gpointer) &secret_name, NULL)) { g_variant_iter_init (&vpn_secrets_iter, val);
secret_flags = NM_SETTING_SECRET_FLAG_NONE; while (g_variant_iter_next (&vpn_secrets_iter, "{&s&s}", &vpn_secret_name, &secret)) {
if (!nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL)) { if (!nm_setting_get_secret_flags (setting, vpn_secret_name, &secret_flags, NULL)) {
if (remove_non_secrets) if (!remove_non_secrets)
g_hash_table_iter_remove (&vpn_secrets_iter); g_variant_builder_add (&vpn_secrets_builder, "{ss}", vpn_secret_name, secret);
continue; continue;
} }
if (!callback (secret_flags, callback_data))
g_hash_table_iter_remove (&vpn_secrets_iter); if (callback (secret_flags, callback_data))
g_variant_builder_add (&vpn_secrets_builder, "{ss}", vpn_secret_name, secret);
} }
g_variant_builder_add (&setting_builder, "{sv}",
secret_name, g_variant_builder_end (&vpn_secrets_builder));
} else { } else {
if (!nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL)) { if (!nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL)) {
if (remove_non_secrets) if (!remove_non_secrets)
g_hash_table_iter_remove (&secret_iter); g_variant_builder_add (&setting_builder, "{sv}", secret_name, val);
continue; continue;
} }
if (!callback (secret_flags, callback_data)) if (callback (secret_flags, callback_data))
g_hash_table_iter_remove (&secret_iter); g_variant_builder_add (&setting_builder, "{sv}", secret_name, val);
} }
g_variant_unref (val);
} }
g_variant_iter_free (setting_iter);
g_variant_builder_add (&secrets_builder, "{sa{sv}}", setting_name, &setting_builder);
} }
return g_variant_builder_end (&secrets_builder);
} }
typedef gboolean (*FindSecretFunc) (NMSettingSecretFlags flags, typedef gboolean (*FindSecretFunc) (NMSettingSecretFlags flags,
@ -284,22 +261,24 @@ find_secret_for_each_func (NMSettingSecretFlags flags,
if (!data->found) if (!data->found)
data->found = data->find_func (flags, data->find_func_data); data->found = data->find_func (flags, data->find_func_data);
return TRUE; return FALSE;
} }
static gboolean static gboolean
find_secret (NMConnection *self, find_secret (NMConnection *self,
GHashTable *secrets, GVariant *secrets,
FindSecretFunc callback, FindSecretFunc callback,
gpointer callback_data) gpointer callback_data)
{ {
FindSecretData data; FindSecretData data;
GVariant *dummy;
data.find_func = callback; data.find_func = callback;
data.find_func_data = callback_data; data.find_func_data = callback_data;
data.found = FALSE; data.found = FALSE;
for_each_secret (self, secrets, FALSE, find_secret_for_each_func, &data); dummy = for_each_secret (self, secrets, FALSE, find_secret_for_each_func, &data);
g_variant_unref (dummy);
return data.found; return data.found;
} }
@ -836,7 +815,7 @@ agent_secrets_done_cb (NMAgentManager *manager,
gboolean agent_has_modify, gboolean agent_has_modify,
const char *setting_name, const char *setting_name,
NMSecretAgentGetSecretsFlags flags, NMSecretAgentGetSecretsFlags flags,
GHashTable *secrets, GVariant *secrets,
GError *error, GError *error,
gpointer user_data, gpointer user_data,
gpointer other_data2, gpointer other_data2,
@ -925,21 +904,19 @@ agent_secrets_done_cb (NMAgentManager *manager,
| NM_SETTING_SECRET_FLAG_NOT_REQUIRED); | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
} }
for_each_secret (NM_CONNECTION (self), secrets, TRUE, validate_secret_flags, &cmp_flags);
/* Update the connection with our existing secrets from backing storage */ /* Update the connection with our existing secrets from backing storage */
nm_connection_clear_secrets (NM_CONNECTION (self)); nm_connection_clear_secrets (NM_CONNECTION (self));
dict = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS); dict = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (!dict || nm_connection_update_secrets (NM_CONNECTION (self), setting_name, dict, &local)) { if (!dict || nm_connection_update_secrets (NM_CONNECTION (self), setting_name, dict, &local)) {
GVariant *secrets_dict; GVariant *filtered_secrets;
/* Update the connection with the agent's secrets; by this point if any /* Update the connection with the agent's secrets; by this point if any
* system-owned secrets exist in 'secrets' the agent that provided them * system-owned secrets exist in 'secrets' the agent that provided them
* will have been authenticated, so those secrets can replace the existing * will have been authenticated, so those secrets can replace the existing
* system secrets. * system secrets.
*/ */
secrets_dict = nm_utils_connection_hash_to_dict (secrets); filtered_secrets = for_each_secret (NM_CONNECTION (self), secrets, TRUE, validate_secret_flags, &cmp_flags);
if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets_dict, &local)) { if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, filtered_secrets, &local)) {
/* Now that all secrets are updated, copy and cache new secrets, /* Now that all secrets are updated, copy and cache new secrets,
* then save them to backing storage. * then save them to backing storage.
*/ */
@ -962,6 +939,8 @@ agent_secrets_done_cb (NMAgentManager *manager,
setting_name, setting_name,
call_id); call_id);
} }
g_variant_unref (filtered_secrets);
} else { } else {
_LOGD ("(%s:%u) failed to update with agent secrets: (%d) %s", _LOGD ("(%s:%u) failed to update with agent secrets: (%d) %s",
setting_name, setting_name,
@ -969,7 +948,6 @@ agent_secrets_done_cb (NMAgentManager *manager,
local ? local->code : -1, local ? local->code : -1,
(local && local->message) ? local->message : "(unknown)"); (local && local->message) ? local->message : "(unknown)");
} }
g_variant_unref (secrets_dict);
} else { } else {
_LOGD ("(%s:%u) failed to update with existing secrets: (%d) %s", _LOGD ("(%s:%u) failed to update with existing secrets: (%d) %s",
setting_name, setting_name,
@ -1012,7 +990,6 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
{ {
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
GVariant *existing_secrets; GVariant *existing_secrets;
GHashTable *existing_secrets_hash;
guint32 call_id = 0; guint32 call_id = 0;
gs_free char *joined_hints = NULL; gs_free char *joined_hints = NULL;
@ -1035,11 +1012,12 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
} }
existing_secrets = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS); existing_secrets = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
existing_secrets_hash = nm_utils_connection_dict_to_hash (existing_secrets); if (existing_secrets)
g_variant_ref_sink (existing_secrets);
call_id = nm_agent_manager_get_secrets (priv->agent_mgr, call_id = nm_agent_manager_get_secrets (priv->agent_mgr,
NM_CONNECTION (self), NM_CONNECTION (self),
subject, subject,
existing_secrets_hash, existing_secrets,
setting_name, setting_name,
flags, flags,
hints, hints,
@ -1047,8 +1025,6 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
self, self,
callback, callback,
callback_data); callback_data);
if (existing_secrets_hash)
g_hash_table_unref (existing_secrets_hash);
if (existing_secrets) if (existing_secrets)
g_variant_unref (existing_secrets); g_variant_unref (existing_secrets);
@ -1077,7 +1053,7 @@ nm_settings_connection_cancel_secrets (NMSettingsConnection *self,
/**** User authorization **************************************/ /**** User authorization **************************************/
typedef void (*AuthCallback) (NMSettingsConnection *self, typedef void (*AuthCallback) (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer data); gpointer data);
@ -1085,7 +1061,7 @@ typedef void (*AuthCallback) (NMSettingsConnection *self,
static void static void
pk_auth_cb (NMAuthChain *chain, pk_auth_cb (NMAuthChain *chain,
GError *chain_error, GError *chain_error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data) gpointer user_data)
{ {
NMSettingsConnection *self = NM_SETTINGS_CONNECTION (user_data); NMSettingsConnection *self = NM_SETTINGS_CONNECTION (user_data);
@ -1134,7 +1110,7 @@ pk_auth_cb (NMAuthChain *chain,
* Returns: the #NMAuthSubject on success, or %NULL on failure and sets @error * Returns: the #NMAuthSubject on success, or %NULL on failure and sets @error
*/ */
static NMAuthSubject * static NMAuthSubject *
_new_auth_subject (DBusGMethodInvocation *context, GError **error) _new_auth_subject (GDBusMethodInvocation *context, GError **error)
{ {
NMAuthSubject *subject; NMAuthSubject *subject;
@ -1151,7 +1127,7 @@ _new_auth_subject (DBusGMethodInvocation *context, GError **error)
static void static void
auth_start (NMSettingsConnection *self, auth_start (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
const char *check_permission, const char *check_permission,
AuthCallback callback, AuthCallback callback,
@ -1239,16 +1215,15 @@ check_writable (NMConnection *self, GError **error)
static void static void
get_settings_auth_cb (NMSettingsConnection *self, get_settings_auth_cb (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer data) gpointer data)
{ {
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
else { else {
GVariant *settings; GVariant *settings;
GHashTable *settings_hash;
NMConnection *dupl_con; NMConnection *dupl_con;
NMSettingConnection *s_con; NMSettingConnection *s_con;
NMSettingWireless *s_wifi; NMSettingWireless *s_wifi;
@ -1286,17 +1261,15 @@ get_settings_auth_cb (NMSettingsConnection *self,
*/ */
settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS); settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS);
g_assert (settings); g_assert (settings);
settings_hash = nm_utils_connection_dict_to_hash (settings); g_dbus_method_invocation_return_value (context,
dbus_g_method_return (context, settings_hash); g_variant_new ("(@a{sa{sv}})", settings));
g_hash_table_destroy (settings_hash);
g_variant_unref (settings);
g_object_unref (dupl_con); g_object_unref (dupl_con);
} }
} }
static void static void
impl_settings_connection_get_settings (NMSettingsConnection *self, impl_settings_connection_get_settings (NMSettingsConnection *self,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
NMAuthSubject *subject; NMAuthSubject *subject;
GError *error = NULL; GError *error = NULL;
@ -1305,14 +1278,12 @@ impl_settings_connection_get_settings (NMSettingsConnection *self,
if (subject) { if (subject) {
auth_start (self, context, subject, NULL, get_settings_auth_cb, NULL); auth_start (self, context, subject, NULL, get_settings_auth_cb, NULL);
g_object_unref (subject); g_object_unref (subject);
} else { } else
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
}
} }
typedef struct { typedef struct {
DBusGMethodInvocation *context; GDBusMethodInvocation *context;
NMAgentManager *agent_mgr; NMAgentManager *agent_mgr;
NMAuthSubject *subject; NMAuthSubject *subject;
NMConnection *new_settings; NMConnection *new_settings;
@ -1320,7 +1291,7 @@ typedef struct {
} UpdateInfo; } UpdateInfo;
typedef struct { typedef struct {
DBusGMethodInvocation *context; GDBusMethodInvocation *context;
NMAuthSubject *subject; NMAuthSubject *subject;
} CallbackInfo; } CallbackInfo;
@ -1384,9 +1355,9 @@ update_complete (NMSettingsConnection *self,
GError *error) GError *error)
{ {
if (error) if (error)
dbus_g_method_return_error (info->context, error); g_dbus_method_invocation_return_gerror (info->context, error);
else else
dbus_g_method_return (info->context); g_dbus_method_invocation_return_value (info->context, NULL);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_UPDATE, NM_CONNECTION (self), !error, nm_audit_log_connection_op (NM_AUDIT_OP_CONN_UPDATE, NM_CONNECTION (self), !error,
info->subject, error ? error->message : NULL); info->subject, error ? error->message : NULL);
@ -1424,7 +1395,7 @@ con_update_cb (NMSettingsConnection *self,
static void static void
update_auth_cb (NMSettingsConnection *self, update_auth_cb (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer data) gpointer data)
@ -1492,8 +1463,8 @@ get_update_modify_permission (NMConnection *old, NMConnection *new)
static void static void
impl_settings_connection_update_helper (NMSettingsConnection *self, impl_settings_connection_update_helper (NMSettingsConnection *self,
GHashTable *new_settings, GDBusMethodInvocation *context,
DBusGMethodInvocation *context, GVariant *new_settings,
gboolean save_to_disk) gboolean save_to_disk)
{ {
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
@ -1515,14 +1486,9 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
/* Check if the settings are valid first */ /* Check if the settings are valid first */
if (new_settings) { if (new_settings) {
GVariant *new_settings_dict = nm_utils_connection_hash_to_dict (new_settings); tmp = nm_simple_connection_new_from_dbus (new_settings, &error);
if (!tmp)
tmp = nm_simple_connection_new_from_dbus (new_settings_dict, &error);
g_variant_unref (new_settings_dict);
if (!tmp) {
g_assert (error);
goto error; goto error;
}
} }
subject = _new_auth_subject (context, &error); subject = _new_auth_subject (context, &error);
@ -1562,37 +1528,34 @@ error:
g_clear_object (&tmp); g_clear_object (&tmp);
g_clear_object (&subject); g_clear_object (&subject);
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
} }
static void static void
impl_settings_connection_update (NMSettingsConnection *self, impl_settings_connection_update (NMSettingsConnection *self,
GHashTable *new_settings, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) GVariant *new_settings)
{ {
g_assert (new_settings); impl_settings_connection_update_helper (self, context, new_settings, TRUE);
impl_settings_connection_update_helper (self, new_settings, context, TRUE);
} }
static void static void
impl_settings_connection_update_unsaved (NMSettingsConnection *self, impl_settings_connection_update_unsaved (NMSettingsConnection *self,
GHashTable *new_settings, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) GVariant *new_settings)
{ {
g_assert (new_settings); impl_settings_connection_update_helper (self, context, new_settings, FALSE);
impl_settings_connection_update_helper (self, new_settings, context, FALSE);
} }
static void static void
impl_settings_connection_save (NMSettingsConnection *self, impl_settings_connection_save (NMSettingsConnection *self,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
/* Do nothing if the connection is already synced with disk */ /* Do nothing if the connection is already synced with disk */
if (nm_settings_connection_get_unsaved (self)) if (nm_settings_connection_get_unsaved (self))
impl_settings_connection_update_helper (self, NULL, context, TRUE); impl_settings_connection_update_helper (self, context, NULL, TRUE);
else else
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
} }
static void static void
@ -1603,9 +1566,9 @@ con_delete_cb (NMSettingsConnection *self,
CallbackInfo *info = user_data; CallbackInfo *info = user_data;
if (error) if (error)
dbus_g_method_return_error (info->context, error); g_dbus_method_invocation_return_gerror (info->context, error);
else else
dbus_g_method_return (info->context); g_dbus_method_invocation_return_value (info->context, NULL);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self),
!error, info->subject, error ? error->message : NULL); !error, info->subject, error ? error->message : NULL);
@ -1614,7 +1577,7 @@ con_delete_cb (NMSettingsConnection *self,
static void static void
delete_auth_cb (NMSettingsConnection *self, delete_auth_cb (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer data) gpointer data)
@ -1624,7 +1587,7 @@ delete_auth_cb (NMSettingsConnection *self,
if (error) { if (error) {
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), FALSE, subject, nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), FALSE, subject,
error->message); error->message);
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
return; return;
} }
@ -1654,7 +1617,7 @@ get_modify_permission_basic (NMSettingsConnection *self)
static void static void
impl_settings_connection_delete (NMSettingsConnection *self, impl_settings_connection_delete (NMSettingsConnection *self,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
NMAuthSubject *subject = NULL; NMAuthSubject *subject = NULL;
GError *error = NULL; GError *error = NULL;
@ -1671,9 +1634,8 @@ impl_settings_connection_delete (NMSettingsConnection *self,
return; return;
out_err: out_err:
dbus_g_method_return_error (context, error);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), FALSE, subject, error->message); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), FALSE, subject, error->message);
g_error_free (error); g_dbus_method_invocation_take_error (context, error);
} }
/**************************************************************/ /**************************************************************/
@ -1687,14 +1649,13 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self,
gpointer user_data) gpointer user_data)
{ {
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
DBusGMethodInvocation *context = user_data; GDBusMethodInvocation *context = user_data;
GVariant *dict; GVariant *dict;
GHashTable *hash;
priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id)); priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id));
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
else { else {
/* Return secrets from agent and backing storage to the D-Bus caller; /* Return secrets from agent and backing storage to the D-Bus caller;
* nm_settings_connection_get_secrets() will have updated itself with * nm_settings_connection_get_secrets() will have updated itself with
@ -1702,20 +1663,15 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self,
* by the time we get here. * by the time we get here.
*/ */
dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS); dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (dict) if (!dict)
hash = nm_utils_connection_dict_to_hash (dict); dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
else g_dbus_method_invocation_return_value (context, g_variant_new ("(@a{s{a{sv}}})", dict));
hash = g_hash_table_new (NULL, NULL);
dbus_g_method_return (context, hash);
g_hash_table_destroy (hash);
if (dict)
g_variant_unref (dict);
} }
} }
static void static void
dbus_get_secrets_auth_cb (NMSettingsConnection *self, dbus_get_secrets_auth_cb (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
@ -1742,7 +1698,7 @@ dbus_get_secrets_auth_cb (NMSettingsConnection *self,
} }
if (error || local) { if (error || local) {
dbus_g_method_return_error (context, error ? error : local); g_dbus_method_invocation_return_gerror (context, error ? error : local);
g_clear_error (&local); g_clear_error (&local);
} }
@ -1751,8 +1707,8 @@ dbus_get_secrets_auth_cb (NMSettingsConnection *self,
static void static void
impl_settings_connection_get_secrets (NMSettingsConnection *self, impl_settings_connection_get_secrets (NMSettingsConnection *self,
const gchar *setting_name, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) const gchar *setting_name)
{ {
NMAuthSubject *subject; NMAuthSubject *subject;
GError *error = NULL; GError *error = NULL;
@ -1766,10 +1722,8 @@ impl_settings_connection_get_secrets (NMSettingsConnection *self,
dbus_get_secrets_auth_cb, dbus_get_secrets_auth_cb,
g_strdup (setting_name)); g_strdup (setting_name));
g_object_unref (subject); g_object_unref (subject);
} else { } else
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
}
} }
static void static void
@ -1780,9 +1734,9 @@ clear_secrets_cb (NMSettingsConnection *self,
CallbackInfo *info = user_data; CallbackInfo *info = user_data;
if (error) if (error)
dbus_g_method_return_error (info->context, error); g_dbus_method_invocation_return_gerror (info->context, error);
else else
dbus_g_method_return (info->context); g_dbus_method_invocation_return_value (info->context, NULL);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self), nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self),
!error, info->subject, error ? error->message : NULL); !error, info->subject, error ? error->message : NULL);
@ -1791,7 +1745,7 @@ clear_secrets_cb (NMSettingsConnection *self,
static void static void
dbus_clear_secrets_auth_cb (NMSettingsConnection *self, dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
@ -1800,7 +1754,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
CallbackInfo *info; CallbackInfo *info;
if (error) { if (error) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self), nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self),
FALSE, subject, error->message); FALSE, subject, error->message);
} else { } else {
@ -1824,7 +1778,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
static void static void
impl_settings_connection_clear_secrets (NMSettingsConnection *self, impl_settings_connection_clear_secrets (NMSettingsConnection *self,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
NMAuthSubject *subject; NMAuthSubject *subject;
GError *error = NULL; GError *error = NULL;
@ -1839,10 +1793,9 @@ impl_settings_connection_clear_secrets (NMSettingsConnection *self,
NULL); NULL);
g_object_unref (subject); g_object_unref (subject);
} else { } else {
dbus_g_method_return_error (context, error);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self), nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self),
FALSE, NULL, error->message); FALSE, NULL, error->message);
g_error_free (error); g_dbus_method_invocation_take_error (context, error);
} }
} }
@ -2586,7 +2539,15 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class)
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class),
&dbus_glib_nm_settings_connection_object_info); NMDBUS_TYPE_SETTINGS_CONNECTION_SKELETON,
"Update", impl_settings_connection_update,
"UpdateUnsaved", impl_settings_connection_update_unsaved,
"Delete", impl_settings_connection_delete,
"GetSettings", impl_settings_connection_get_settings,
"GetSecrets", impl_settings_connection_get_secrets,
"ClearSecrets", impl_settings_connection_clear_secrets,
"Save", impl_settings_connection_save,
NULL);
} }
static void static void

View file

@ -31,8 +31,6 @@
#include <string.h> #include <string.h>
#include <gmodule.h> #include <gmodule.h>
#include <pwd.h> #include <pwd.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#if HAVE_SELINUX #if HAVE_SELINUX
#include <selinux/selinux.h> #include <selinux/selinux.h>
@ -61,7 +59,6 @@
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-ethernet.h" #include "nm-device-ethernet.h"
#include "nm-dbus-glib-types.h"
#include "nm-settings.h" #include "nm-settings.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-system-config-interface.h" #include "nm-system-config-interface.h"
@ -78,6 +75,8 @@
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-dispatcher.h" #include "nm-dispatcher.h"
#include "nmdbus-settings.h"
#define LOG(level, ...) \ #define LOG(level, ...) \
G_STMT_START { \ G_STMT_START { \
nm_log ((level), LOGD_CORE, \ nm_log ((level), LOGD_CORE, \
@ -122,35 +121,6 @@ EXPORT(nm_settings_connection_replace_and_commit)
static void claim_connection (NMSettings *self, static void claim_connection (NMSettings *self,
NMSettingsConnection *connection); NMSettingsConnection *connection);
static gboolean impl_settings_list_connections (NMSettings *self,
GPtrArray **connections,
GError **error);
static void impl_settings_get_connection_by_uuid (NMSettings *self,
const char *uuid,
DBusGMethodInvocation *context);
static void impl_settings_add_connection (NMSettings *self,
GHashTable *settings,
DBusGMethodInvocation *context);
static void impl_settings_add_connection_unsaved (NMSettings *self,
GHashTable *settings,
DBusGMethodInvocation *context);
static void impl_settings_load_connections (NMSettings *self,
char **filenames,
DBusGMethodInvocation *context);
static void impl_settings_reload_connections (NMSettings *self,
DBusGMethodInvocation *context);
static void impl_settings_save_hostname (NMSettings *self,
const char *hostname,
DBusGMethodInvocation *context);
#include "nm-settings-glue.h"
static void unmanaged_specs_changed (NMSystemConfigInterface *config, gpointer user_data); static void unmanaged_specs_changed (NMSystemConfigInterface *config, gpointer user_data);
static void unrecognized_specs_changed (NMSystemConfigInterface *config, gpointer user_data); static void unrecognized_specs_changed (NMSystemConfigInterface *config, gpointer user_data);
@ -161,8 +131,6 @@ G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT, 0,
typedef struct { typedef struct {
NMBusManager *dbus_mgr;
NMAgentManager *agent_mgr; NMAgentManager *agent_mgr;
NMConfig *config; NMConfig *config;
@ -176,6 +144,7 @@ typedef struct {
GSList *unrecognized_specs; GSList *unrecognized_specs;
GSList *get_connections_cache; GSList *get_connections_cache;
gboolean started;
gboolean startup_complete; gboolean startup_complete;
struct { struct {
@ -309,20 +278,24 @@ nm_settings_for_each_connection (NMSettings *self,
for_each_func (self, NM_SETTINGS_CONNECTION (data), user_data); for_each_func (self, NM_SETTINGS_CONNECTION (data), user_data);
} }
static gboolean static void
impl_settings_list_connections (NMSettings *self, impl_settings_list_connections (NMSettings *self,
GPtrArray **connections, GDBusMethodInvocation *context)
GError **error)
{ {
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GPtrArray *connections;
GHashTableIter iter; GHashTableIter iter;
gpointer key; gpointer key;
*connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1);
g_hash_table_iter_init (&iter, priv->connections); g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, &key, NULL)) while (g_hash_table_iter_next (&iter, &key, NULL))
g_ptr_array_add (*connections, g_strdup ((const char *) key)); g_ptr_array_add (connections, key);
return TRUE; g_ptr_array_add (connections, NULL);
g_dbus_method_invocation_return_value (context,
g_variant_new ("(^ao)", connections->pdata));
g_ptr_array_unref (connections);
} }
NMSettingsConnection * NMSettingsConnection *
@ -348,8 +321,8 @@ nm_settings_get_connection_by_uuid (NMSettings *self, const char *uuid)
static void static void
impl_settings_get_connection_by_uuid (NMSettings *self, impl_settings_get_connection_by_uuid (NMSettings *self,
const char *uuid, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) const char *uuid)
{ {
NMSettingsConnection *connection = NULL; NMSettingsConnection *connection = NULL;
NMAuthSubject *subject = NULL; NMAuthSubject *subject = NULL;
@ -383,13 +356,14 @@ impl_settings_get_connection_by_uuid (NMSettings *self,
} }
g_clear_object (&subject); g_clear_object (&subject);
dbus_g_method_return (context, nm_connection_get_path (NM_CONNECTION (connection))); g_dbus_method_invocation_return_value (
context,
g_variant_new ("(o)", nm_connection_get_path (NM_CONNECTION (connection))));
return; return;
error: error:
g_assert (error); g_assert (error);
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
g_clear_object (&subject); g_clear_object (&subject);
} }
@ -561,6 +535,9 @@ nm_settings_get_hostname (NMSettings *self)
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
char *hostname = NULL; char *hostname = NULL;
if (!priv->started)
return NULL;
if (priv->hostname.hostnamed_proxy) { if (priv->hostname.hostnamed_proxy) {
hostname = g_strdup (priv->hostname.value); hostname = g_strdup (priv->hostname.value);
goto out; goto out;
@ -1185,7 +1162,7 @@ send_agent_owned_secrets (NMSettings *self,
static void static void
pk_add_cb (NMAuthChain *chain, pk_add_cb (NMAuthChain *chain,
GError *chain_error, GError *chain_error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data) gpointer user_data)
{ {
NMSettings *self = NM_SETTINGS (user_data); NMSettings *self = NM_SETTINGS (user_data);
@ -1273,11 +1250,11 @@ is_adhoc_wpa (NMConnection *connection)
void void
nm_settings_add_connection_dbus (NMSettings *self, nm_settings_add_connection_dbus (NMSettings *self,
NMConnection *connection, NMConnection *connection,
gboolean save_to_disk, gboolean save_to_disk,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMSettingsAddCallback callback, NMSettingsAddCallback callback,
gpointer user_data) gpointer user_data)
{ {
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
NMSettingConnection *s_con; NMSettingConnection *s_con;
@ -1381,15 +1358,17 @@ static void
impl_settings_add_connection_add_cb (NMSettings *self, impl_settings_add_connection_add_cb (NMSettings *self,
NMSettingsConnection *connection, NMSettingsConnection *connection,
GError *error, GError *error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
gpointer user_data) gpointer user_data)
{ {
if (error) { if (error) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NULL, FALSE, subject, error->message); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NULL, FALSE, subject, error->message);
} else { } else {
dbus_g_method_return (context, nm_connection_get_path (NM_CONNECTION (connection))); g_dbus_method_invocation_return_value (
context,
g_variant_new ("(o)", nm_connection_get_path (NM_CONNECTION (connection))));
nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NM_CONNECTION (connection), TRUE, nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NM_CONNECTION (connection), TRUE,
subject, NULL); subject, NULL);
} }
@ -1397,17 +1376,14 @@ impl_settings_add_connection_add_cb (NMSettings *self,
static void static void
impl_settings_add_connection_helper (NMSettings *self, impl_settings_add_connection_helper (NMSettings *self,
GHashTable *settings, GDBusMethodInvocation *context,
gboolean save_to_disk, GVariant *settings,
DBusGMethodInvocation *context) gboolean save_to_disk)
{ {
NMConnection *connection; NMConnection *connection;
GVariant *dict;
GError *error = NULL; GError *error = NULL;
dict = nm_utils_connection_hash_to_dict (settings); connection = nm_simple_connection_new_from_dbus (settings, &error);
connection = nm_simple_connection_new_from_dbus (dict, &error);
g_variant_unref (dict);
if (connection) { if (connection) {
nm_settings_add_connection_dbus (self, nm_settings_add_connection_dbus (self,
connection, connection,
@ -1418,30 +1394,29 @@ impl_settings_add_connection_helper (NMSettings *self,
g_object_unref (connection); g_object_unref (connection);
} else { } else {
g_assert (error); g_assert (error);
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
} }
} }
static void static void
impl_settings_add_connection (NMSettings *self, impl_settings_add_connection (NMSettings *self,
GHashTable *settings, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) GVariant *settings)
{ {
impl_settings_add_connection_helper (self, settings, TRUE, context); impl_settings_add_connection_helper (self, context, settings, TRUE);
} }
static void static void
impl_settings_add_connection_unsaved (NMSettings *self, impl_settings_add_connection_unsaved (NMSettings *self,
GHashTable *settings, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) GVariant *settings)
{ {
impl_settings_add_connection_helper (self, settings, FALSE, context); impl_settings_add_connection_helper (self, context, settings, FALSE);
} }
static gboolean static gboolean
ensure_root (NMBusManager *dbus_mgr, ensure_root (NMBusManager *dbus_mgr,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
gulong caller_uid; gulong caller_uid;
GError *error = NULL; GError *error = NULL;
@ -1450,16 +1425,14 @@ ensure_root (NMBusManager *dbus_mgr,
error = g_error_new_literal (NM_SETTINGS_ERROR, error = g_error_new_literal (NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED, NM_SETTINGS_ERROR_PERMISSION_DENIED,
"Unable to determine request UID."); "Unable to determine request UID.");
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
return FALSE; return FALSE;
} }
if (caller_uid != 0) { if (caller_uid != 0) {
error = g_error_new_literal (NM_SETTINGS_ERROR, error = g_error_new_literal (NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED, NM_SETTINGS_ERROR_PERMISSION_DENIED,
"Permission denied"); "Permission denied");
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_error_free (error);
return FALSE; return FALSE;
} }
@ -1468,15 +1441,15 @@ ensure_root (NMBusManager *dbus_mgr,
static void static void
impl_settings_load_connections (NMSettings *self, impl_settings_load_connections (NMSettings *self,
char **filenames, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) char **filenames)
{ {
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GPtrArray *failures; GPtrArray *failures;
GSList *iter; GSList *iter;
int i; int i;
if (!ensure_root (priv->dbus_mgr, context)) if (!ensure_root (nm_bus_manager_get (), context))
return; return;
failures = g_ptr_array_new (); failures = g_ptr_array_new ();
@ -1497,18 +1470,22 @@ impl_settings_load_connections (NMSettings *self,
} }
g_ptr_array_add (failures, NULL); g_ptr_array_add (failures, NULL);
dbus_g_method_return (context, failures->len == 1, failures->pdata); g_dbus_method_invocation_return_value (
context,
g_variant_new ("(b^as)",
failures->len == 1,
failures->pdata));
g_ptr_array_unref (failures); g_ptr_array_unref (failures);
} }
static void static void
impl_settings_reload_connections (NMSettings *self, impl_settings_reload_connections (NMSettings *self,
DBusGMethodInvocation *context) GDBusMethodInvocation *context)
{ {
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GSList *iter; GSList *iter;
if (!ensure_root (priv->dbus_mgr, context)) if (!ensure_root (nm_bus_manager_get (), context))
return; return;
for (iter = priv->plugins; iter; iter = g_slist_next (iter)) { for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
@ -1517,7 +1494,7 @@ impl_settings_reload_connections (NMSettings *self,
nm_system_config_interface_reload_connections (plugin); nm_system_config_interface_reload_connections (plugin);
} }
dbus_g_method_return (context, TRUE); g_dbus_method_invocation_return_value (context, g_variant_new ("(b)", TRUE));
} }
static gboolean static gboolean
@ -1590,7 +1567,7 @@ write_hostname (NMSettingsPrivate *priv, const char *hostname)
static void static void
pk_hostname_cb (NMAuthChain *chain, pk_hostname_cb (NMAuthChain *chain,
GError *chain_error, GError *chain_error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
gpointer user_data) gpointer user_data)
{ {
NMSettings *self = NM_SETTINGS (user_data); NMSettings *self = NM_SETTINGS (user_data);
@ -1626,11 +1603,10 @@ pk_hostname_cb (NMAuthChain *chain,
} }
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
else else
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
g_clear_error (&error);
nm_auth_chain_unref (chain); nm_auth_chain_unref (chain);
} }
@ -1663,8 +1639,8 @@ validate_hostname (const char *hostname)
static void static void
impl_settings_save_hostname (NMSettings *self, impl_settings_save_hostname (NMSettings *self,
const char *hostname, GDBusMethodInvocation *context,
DBusGMethodInvocation *context) const char *hostname)
{ {
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
NMAuthChain *chain; NMAuthChain *chain;
@ -1692,8 +1668,7 @@ impl_settings_save_hostname (NMSettings *self,
done: done:
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
} }
static void static void
@ -2094,25 +2069,35 @@ setup_hostname_file_monitors (NMSettings *self)
} }
NMSettings * NMSettings *
nm_settings_new (GError **error) nm_settings_new (void)
{ {
NMSettings *self; NMSettings *self;
NMSettingsPrivate *priv; NMSettingsPrivate *priv;
GDBusProxy *proxy;
GVariant *variant;
GError *local_error = NULL;
self = g_object_new (NM_TYPE_SETTINGS, NULL); self = g_object_new (NM_TYPE_SETTINGS, NULL);
priv = NM_SETTINGS_GET_PRIVATE (self); priv = NM_SETTINGS_GET_PRIVATE (self);
priv->config = nm_config_get (); priv->config = nm_config_get ();
priv->dbus_mgr = nm_bus_manager_get ();
nm_exported_object_export (NM_EXPORTED_OBJECT (self));
return self;
}
gboolean
nm_settings_start (NMSettings *self, GError **error)
{
NMSettingsPrivate *priv;
GDBusProxy *proxy;
GVariant *variant;
GError *local_error = NULL;
priv = NM_SETTINGS_GET_PRIVATE (self);
/* Load the plugins; fail if a plugin is not found. */ /* Load the plugins; fail if a plugin is not found. */
if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) { if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) {
g_object_unref (self); g_object_unref (self);
return NULL; return FALSE;
} }
load_connections (self); load_connections (self);
@ -2143,8 +2128,9 @@ nm_settings_new (GError **error)
if (!priv->hostname.hostnamed_proxy) if (!priv->hostname.hostnamed_proxy)
setup_hostname_file_monitors (self); setup_hostname_file_monitors (self);
nm_exported_object_export (NM_EXPORTED_OBJECT (self)); priv->started = TRUE;
return self; g_object_notify (G_OBJECT (self), NM_SETTINGS_HOSTNAME);
return TRUE;
} }
static void static void
@ -2182,8 +2168,6 @@ dispose (GObject *object)
g_slist_free_full (priv->auths, (GDestroyNotify) nm_auth_chain_unref); g_slist_free_full (priv->auths, (GDestroyNotify) nm_auth_chain_unref);
priv->auths = NULL; priv->auths = NULL;
priv->dbus_mgr = NULL;
g_object_unref (priv->agent_mgr); g_object_unref (priv->agent_mgr);
if (priv->hostname.hostnamed_proxy) { if (priv->hostname.hostnamed_proxy) {
@ -2239,17 +2223,18 @@ get_property (GObject *object, guint prop_id,
NMSettings *self = NM_SETTINGS (object); NMSettings *self = NM_SETTINGS (object);
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
const GSList *specs, *iter; const GSList *specs, *iter;
GSList *copy = NULL;
GHashTableIter citer; GHashTableIter citer;
GPtrArray *array; GPtrArray *array;
const char *path; const char *path;
switch (prop_id) { switch (prop_id) {
case PROP_UNMANAGED_SPECS: case PROP_UNMANAGED_SPECS:
array = g_ptr_array_new ();
specs = nm_settings_get_unmanaged_specs (self); specs = nm_settings_get_unmanaged_specs (self);
for (iter = specs; iter; iter = g_slist_next (iter)) for (iter = specs; iter; iter = g_slist_next (iter))
copy = g_slist_append (copy, g_strdup (iter->data)); g_ptr_array_add (array, g_strdup (iter->data));
g_value_take_boxed (value, copy); g_ptr_array_add (array, NULL);
g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE));
break; break;
case PROP_HOSTNAME: case PROP_HOSTNAME:
g_value_take_string (value, nm_settings_get_hostname (self)); g_value_take_string (value, nm_settings_get_hostname (self));
@ -2262,11 +2247,12 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, !!get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS)); g_value_set_boolean (value, !!get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS));
break; break;
case PROP_CONNECTIONS: case PROP_CONNECTIONS:
array = g_ptr_array_sized_new (g_hash_table_size (priv->connections)); array = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1);
g_hash_table_iter_init (&citer, priv->connections); g_hash_table_iter_init (&citer, priv->connections);
while (g_hash_table_iter_next (&citer, (gpointer) &path, NULL)) while (g_hash_table_iter_next (&citer, (gpointer) &path, NULL))
g_ptr_array_add (array, g_strdup (path)); g_ptr_array_add (array, g_strdup (path));
g_value_take_boxed (value, array); g_ptr_array_add (array, NULL);
g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE));
break; break;
case PROP_STARTUP_COMPLETE: case PROP_STARTUP_COMPLETE:
g_value_set_boolean (value, nm_settings_get_startup_complete (self)); g_value_set_boolean (value, nm_settings_get_startup_complete (self));
@ -2297,7 +2283,7 @@ nm_settings_class_init (NMSettingsClass *class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_UNMANAGED_SPECS, (object_class, PROP_UNMANAGED_SPECS,
g_param_spec_boxed (NM_SETTINGS_UNMANAGED_SPECS, "", "", g_param_spec_boxed (NM_SETTINGS_UNMANAGED_SPECS, "", "",
DBUS_TYPE_G_LIST_OF_STRING, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
@ -2318,7 +2304,7 @@ nm_settings_class_init (NMSettingsClass *class)
g_object_class_install_property g_object_class_install_property
(object_class, PROP_CONNECTIONS, (object_class, PROP_CONNECTIONS,
g_param_spec_boxed (NM_SETTINGS_CONNECTIONS, "", "", g_param_spec_boxed (NM_SETTINGS_CONNECTIONS, "", "",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
@ -2330,7 +2316,7 @@ nm_settings_class_init (NMSettingsClass *class)
G_STRUCT_OFFSET (NMSettingsClass, connection_added), G_STRUCT_OFFSET (NMSettingsClass, connection_added),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION);
signals[CONNECTION_UPDATED] = signals[CONNECTION_UPDATED] =
g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_UPDATED,
@ -2339,7 +2325,7 @@ nm_settings_class_init (NMSettingsClass *class)
G_STRUCT_OFFSET (NMSettingsClass, connection_updated), G_STRUCT_OFFSET (NMSettingsClass, connection_updated),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION);
signals[CONNECTION_UPDATED_BY_USER] = signals[CONNECTION_UPDATED_BY_USER] =
g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_UPDATED_BY_USER, g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_UPDATED_BY_USER,
@ -2348,7 +2334,7 @@ nm_settings_class_init (NMSettingsClass *class)
0, 0,
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION);
signals[CONNECTION_REMOVED] = signals[CONNECTION_REMOVED] =
g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_REMOVED,
@ -2357,7 +2343,7 @@ nm_settings_class_init (NMSettingsClass *class)
G_STRUCT_OFFSET (NMSettingsClass, connection_removed), G_STRUCT_OFFSET (NMSettingsClass, connection_removed),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION);
signals[CONNECTION_VISIBILITY_CHANGED] = signals[CONNECTION_VISIBILITY_CHANGED] =
g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED, g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED,
@ -2366,7 +2352,7 @@ nm_settings_class_init (NMSettingsClass *class)
G_STRUCT_OFFSET (NMSettingsClass, connection_visibility_changed), G_STRUCT_OFFSET (NMSettingsClass, connection_visibility_changed),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION);
signals[AGENT_REGISTERED] = signals[AGENT_REGISTERED] =
g_signal_new (NM_SETTINGS_SIGNAL_AGENT_REGISTERED, g_signal_new (NM_SETTINGS_SIGNAL_AGENT_REGISTERED,
@ -2375,7 +2361,7 @@ nm_settings_class_init (NMSettingsClass *class)
G_STRUCT_OFFSET (NMSettingsClass, agent_registered), G_STRUCT_OFFSET (NMSettingsClass, agent_registered),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SECRET_AGENT);
signals[NEW_CONNECTION] = signals[NEW_CONNECTION] =
@ -2383,16 +2369,17 @@ nm_settings_class_init (NMSettingsClass *class)
G_OBJECT_CLASS_TYPE (object_class), G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT); G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class),
&dbus_glib_nm_settings_object_info); NMDBUS_TYPE_SETTINGS_SKELETON,
"ListConnections", impl_settings_list_connections,
dbus_g_error_domain_register (NM_SETTINGS_ERROR, "GetConnectionByUuid", impl_settings_get_connection_by_uuid,
NM_DBUS_INTERFACE_SETTINGS, "AddConnection", impl_settings_add_connection,
NM_TYPE_SETTINGS_ERROR); "AddConnectionUnsaved", impl_settings_add_connection_unsaved,
dbus_g_error_domain_register (NM_CONNECTION_ERROR, "LoadConnections", impl_settings_load_connections,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "ReloadConnections", impl_settings_reload_connections,
NM_TYPE_CONNECTION_ERROR); "SaveHostname", impl_settings_save_hostname,
NULL);
} }

View file

@ -73,7 +73,8 @@ typedef struct {
GType nm_settings_get_type (void); GType nm_settings_get_type (void);
NMSettings *nm_settings_new (GError **error); NMSettings *nm_settings_new (void);
gboolean nm_settings_start (NMSettings *self, GError **error);
typedef void (*NMSettingsForEachFunc) (NMSettings *settings, typedef void (*NMSettingsForEachFunc) (NMSettings *settings,
NMSettingsConnection *connection, NMSettingsConnection *connection,
@ -86,14 +87,14 @@ void nm_settings_for_each_connection (NMSettings *settings,
typedef void (*NMSettingsAddCallback) (NMSettings *settings, typedef void (*NMSettingsAddCallback) (NMSettings *settings,
NMSettingsConnection *connection, NMSettingsConnection *connection,
GError *error, GError *error,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMAuthSubject *subject, NMAuthSubject *subject,
gpointer user_data); gpointer user_data);
void nm_settings_add_connection_dbus (NMSettings *self, void nm_settings_add_connection_dbus (NMSettings *self,
NMConnection *connection, NMConnection *connection,
gboolean save_to_disk, gboolean save_to_disk,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
NMSettingsAddCallback callback, NMSettingsAddCallback callback,
gpointer user_data); gpointer user_data);

View file

@ -20,7 +20,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \
-DSBINDIR=\"$(sbindir)\" -DSBINDIR=\"$(sbindir)\"

View file

@ -29,7 +29,6 @@
#include <nm-setting-connection.h> #include <nm-setting-connection.h>
#include "nm-default.h" #include "nm-default.h"
#include "nm-dbus-glib-types.h"
#include "nm-system-config-interface.h" #include "nm-system-config-interface.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"

View file

@ -20,7 +20,6 @@ AM_CPPFLAGS = \
AM_LDFLAGS = \ AM_LDFLAGS = \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_LIBS) \
$(CODE_COVERAGE_LDFLAGS) $(CODE_COVERAGE_LDFLAGS)
noinst_PROGRAMS = test-ibft noinst_PROGRAMS = test-ibft

View file

@ -2,15 +2,31 @@ SUBDIRS = . tests
@GNOME_CODE_COVERAGE_RULES@ @GNOME_CODE_COVERAGE_RULES@
nm-ifcfg-rh-glue.h: nm-ifcfg-rh.xml # See note about gdbus-codegen in introspection/Makefile.am
$(AM_V_GEN) dbus-binding-tool --prefix=nm_ifcfg_rh --mode=glib-server --output=$@ $<
BUILT_SOURCES = \ noinst_LTLIBRARIES = libnmdbus-ifcfg-rh.la
nm-ifcfg-rh-glue.h
nodist_libnmdbus_ifcfg_rh_la_SOURCES = \
nmdbus-ifcfg-rh.c \
nmdbus-ifcfg-rh.h
libnmdbus_ifcfg_rh_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(AM_CPPFLAGS))
nmdbus-ifcfg-rh.h: nm-ifcfg-rh.xml
$(AM_V_GEN) gdbus-codegen \
--generate-c-code $(basename $@) \
--c-namespace NMDBus \
--interface-prefix com.redhat \
$<
nmdbus-ifcfg-rh.c: nmdbus-ifcfg-rh.h
@true
BUILT_SOURCES = nmdbus-ifcfg-rh.h nmdbus-ifcfg-rh.c
pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la
noinst_LTLIBRARIES = libifcfg-rh-io.la noinst_LTLIBRARIES += libifcfg-rh-io.la
libifcfg_rh_io_la_SOURCES = \ libifcfg_rh_io_la_SOURCES = \
shvar.c \ shvar.c \
@ -33,7 +49,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
$(NSS_CFLAGS) \ $(NSS_CFLAGS) \
-DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \
@ -46,7 +61,7 @@ libnm_settings_plugin_ifcfg_rh_la_SOURCES = \
nm-ifcfg-connection.h nm-ifcfg-connection.h
libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version
libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la libnmdbus-ifcfg-rh.la
dbusservicedir = $(DBUS_SYS_DIR) dbusservicedir = $(DBUS_SYS_DIR)
dbusservice_DATA = nm-ifcfg-rh.conf dbusservice_DATA = nm-ifcfg-rh.conf

View file

@ -10,7 +10,6 @@
<tp:docstring> <tp:docstring>
Given an ifcfg file, return various internal information about it. Given an ifcfg file, return various internal information about it.
</tp:docstring> </tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ifcfgrh_get_ifcfg_details"/>
<arg name="ifcfg" type="s" direction="in"> <arg name="ifcfg" type="s" direction="in">
<tp:docstring> <tp:docstring>
The full path to an ifcfg file. The full path to an ifcfg file.

View file

@ -31,10 +31,6 @@
#include <gmodule.h> #include <gmodule.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#if HAVE_SELINUX #if HAVE_SELINUX
#include <selinux/selinux.h> #include <selinux/selinux.h>
#endif #endif
@ -43,7 +39,6 @@
#include "nm-default.h" #include "nm-default.h"
#include "common.h" #include "common.h"
#include "nm-dbus-glib-types.h"
#include "plugin.h" #include "plugin.h"
#include "nm-system-config-interface.h" #include "nm-system-config-interface.h"
#include "nm-config.h" #include "nm-config.h"
@ -54,6 +49,9 @@
#include "reader.h" #include "reader.h"
#include "writer.h" #include "writer.h"
#include "utils.h" #include "utils.h"
#include "nm-dbus-compat.h"
#include "nmdbus-ifcfg-rh.h"
#define IFCFGRH1_DBUS_SERVICE_NAME "com.redhat.ifcfgrh1" #define IFCFGRH1_DBUS_SERVICE_NAME "com.redhat.ifcfgrh1"
#define IFCFGRH1_DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1" #define IFCFGRH1_DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1"
@ -77,14 +75,6 @@
#define ERR_GET_MSG(err) (((err) && (err)->message) ? (err)->message : "(unknown)") #define ERR_GET_MSG(err) (((err) && (err)->message) ? (err)->message : "(unknown)")
static gboolean impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin,
const char *in_ifcfg,
const char **out_uuid,
const char **out_path,
GError **error);
#include "nm-ifcfg-rh-glue.h"
static NMIfcfgConnection *update_connection (SCPluginIfcfg *plugin, static NMIfcfgConnection *update_connection (SCPluginIfcfg *plugin,
NMConnection *source, NMConnection *source,
const char *full_path, const char *full_path,
@ -109,7 +99,7 @@ typedef struct {
GFileMonitor *ifcfg_monitor; GFileMonitor *ifcfg_monitor;
guint ifcfg_monitor_id; guint ifcfg_monitor_id;
DBusGConnection *bus; gboolean has_dbus_service;
} SCPluginIfcfgPrivate; } SCPluginIfcfgPrivate;
@ -696,12 +686,10 @@ add_connection (NMSystemConfigInterface *config,
return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error));
} }
static gboolean static void
impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin,
const char *in_ifcfg, GDBusMethodInvocation *context,
const char **out_uuid, const char *in_ifcfg)
const char **out_path,
GError **error)
{ {
NMIfcfgConnection *connection; NMIfcfgConnection *connection;
NMSettingConnection *s_con; NMSettingConnection *s_con;
@ -709,55 +697,53 @@ impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin,
const char *path; const char *path;
if (!g_path_is_absolute (in_ifcfg)) { if (!g_path_is_absolute (in_ifcfg)) {
g_set_error (error, g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"ifcfg path '%s' is not absolute", in_ifcfg); "ifcfg path '%s' is not absolute", in_ifcfg);
return FALSE; return;
} }
connection = find_by_path (plugin, in_ifcfg); connection = find_by_path (plugin, in_ifcfg);
if ( !connection if ( !connection
|| nm_ifcfg_connection_get_unmanaged_spec (connection) || nm_ifcfg_connection_get_unmanaged_spec (connection)
|| nm_ifcfg_connection_get_unrecognized_spec (connection)) { || nm_ifcfg_connection_get_unrecognized_spec (connection)) {
g_set_error (error, g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"ifcfg file '%s' unknown", in_ifcfg); "ifcfg file '%s' unknown", in_ifcfg);
return FALSE; return;
} }
s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
if (!s_con) { if (!s_con) {
g_set_error (error, g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_FAILED, NM_SETTINGS_ERROR_FAILED,
"unable to retrieve the connection setting"); "unable to retrieve the connection setting");
return FALSE; return;
} }
uuid = nm_setting_connection_get_uuid (s_con); uuid = nm_setting_connection_get_uuid (s_con);
if (!uuid) { if (!uuid) {
g_set_error (error, g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_FAILED, NM_SETTINGS_ERROR_FAILED,
"unable to get the UUID"); "unable to get the UUID");
return FALSE; return;
} }
path = nm_connection_get_path (NM_CONNECTION (connection)); path = nm_connection_get_path (NM_CONNECTION (connection));
if (!path) { if (!path) {
g_set_error (error, g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR, NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_FAILED, NM_SETTINGS_ERROR_FAILED,
"unable to get the connection D-Bus path"); "unable to get the connection D-Bus path");
return FALSE; return;
} }
*out_uuid = g_strdup (uuid); g_dbus_method_invocation_return_value (context,
*out_path = g_strdup (path); g_variant_new ("(so)", uuid, path));
return TRUE;
} }
static void static void
@ -770,46 +756,43 @@ sc_plugin_ifcfg_init (SCPluginIfcfg *plugin)
{ {
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
GError *error = NULL; GError *error = NULL;
gboolean success = FALSE; GDBusConnection *bus;
GVariant *ret;
guint32 result;
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!priv->bus) { if (!bus) {
_LOGW ("Couldn't connect to D-Bus: %s", error->message); _LOGW ("Couldn't connect to D-Bus: %s", error->message);
g_clear_error (&error); g_clear_error (&error);
} else { return;
DBusConnection *tmp;
DBusGProxy *proxy;
int result;
tmp = dbus_g_connection_get_connection (priv->bus);
dbus_connection_set_exit_on_disconnect (tmp, FALSE);
proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
if (!dbus_g_proxy_call (proxy, "RequestName", &error,
G_TYPE_STRING, IFCFGRH1_DBUS_SERVICE_NAME,
G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
G_TYPE_INVALID,
G_TYPE_UINT, &result,
G_TYPE_INVALID)) {
_LOGW ("Couldn't acquire D-Bus service: %s", error->message);
g_clear_error (&error);
} else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
_LOGW ("Couldn't acquire ifcfgrh1 D-Bus service (already taken)");
} else
success = TRUE;
} }
if (!success) { ret = g_dbus_connection_call_sync (bus,
if (priv->bus) { DBUS_SERVICE_DBUS,
dbus_g_connection_unref (priv->bus); DBUS_PATH_DBUS,
priv->bus = NULL; DBUS_INTERFACE_DBUS,
} "RequestName",
g_variant_new ("(su)",
IFCFGRH1_DBUS_SERVICE_NAME,
DBUS_NAME_FLAG_DO_NOT_QUEUE),
G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, &error);
g_object_unref (bus);
if (ret) {
g_variant_get (ret, "(u)", &result);
g_variant_unref (ret);
if (result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
priv->has_dbus_service = TRUE;
else
_LOGW ("Couldn't acquire ifcfgrh1 D-Bus service (already taken)");
} else {
_LOGW ("Couldn't acquire D-Bus service: %s", error->message);
g_clear_error (&error);
} }
} }
@ -819,11 +802,6 @@ dispose (GObject *object)
SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (object); SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (object);
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
if (priv->bus) {
dbus_g_connection_unref (priv->bus);
priv->bus = NULL;
}
if (priv->connections) { if (priv->connections) {
g_hash_table_destroy (priv->connections); g_hash_table_destroy (priv->connections);
priv->connections = NULL; priv->connections = NULL;
@ -875,9 +853,12 @@ static void
sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class) sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (req_class); GObjectClass *object_class = G_OBJECT_CLASS (req_class);
NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (req_class);
g_type_class_add_private (req_class, sizeof (SCPluginIfcfgPrivate)); g_type_class_add_private (req_class, sizeof (SCPluginIfcfgPrivate));
exported_object_class->export_path = IFCFGRH1_DBUS_OBJECT_PATH;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->set_property = set_property; object_class->set_property = set_property;
@ -895,7 +876,9 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES); NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (req_class), nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (req_class),
&dbus_glib_nm_ifcfg_rh_object_info); NMDBUS_TYPE_IFCFGRH1_SKELETON,
"GetIfcfgDetails", impl_ifcfgrh_get_ifcfg_details,
NULL);
} }
static void static void
@ -920,10 +903,8 @@ nm_system_config_factory (void)
if (!singleton) { if (!singleton) {
singleton = SC_PLUGIN_IFCFG (g_object_new (SC_TYPE_PLUGIN_IFCFG, NULL)); singleton = SC_PLUGIN_IFCFG (g_object_new (SC_TYPE_PLUGIN_IFCFG, NULL));
priv = SC_PLUGIN_IFCFG_GET_PRIVATE (singleton); priv = SC_PLUGIN_IFCFG_GET_PRIVATE (singleton);
if (priv->bus) if (priv->has_dbus_service)
dbus_g_connection_register_g_object (priv->bus, nm_exported_object_export (NM_EXPORTED_OBJECT (singleton));
IFCFGRH1_DBUS_OBJECT_PATH,
G_OBJECT (singleton));
_LOGD ("Acquired D-Bus service %s", IFCFGRH1_DBUS_SERVICE_NAME); _LOGD ("Acquired D-Bus service %s", IFCFGRH1_DBUS_SERVICE_NAME);
} else } else
g_object_ref (singleton); g_object_ref (singleton);

View file

@ -24,7 +24,6 @@ AM_CPPFLAGS = \
AM_LDFLAGS = \ AM_LDFLAGS = \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_LIBS) \
$(CODE_COVERAGE_LDFLAGS) $(CODE_COVERAGE_LDFLAGS)
noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils

View file

@ -13,7 +13,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DSYSCONFDIR=\"$(sysconfdir)\" -DSYSCONFDIR=\"$(sysconfdir)\"
-DSBINDIR=\"$(sbindir)\" -DSBINDIR=\"$(sbindir)\"

Some files were not shown because too many files have changed in this diff Show more