setEnvironmentVariable DBus method for wpasupplicant



Hi,

For implementing PKCS#11 support in the network manager gnome applet
using gnome keyring as the backing store, it's necessary to tell
wpasupplicant the environment variable of GNOME_KEYRING_SOCKET before
loading the gnome keyring PKCS#11 library. This socket will be protected
to the local user, but since wpasupplicant must run as root, it should
be able to access it and indeed it must.

This issue is currently being discussed in network manager's bugzilla at
http://bugzilla.gnome.org/show_bug.cgi?id=537239 .

Attached is a patch to add a DBus interface to set environment variables
in wpasupplicant. I hope this is an acceptable compromise. In the long
term, a better interface from keyring might be made available and then
any necessary changes to wpasupplicant could be made at that time, but
for now this is a rather trivial addition that would primarily be useful
for working with the current implementation.

Cheers,
- dds

From e41917c0e157c335e58d7e833870880bd1ab0e4d Mon Sep 17 00:00:00 2001
From: David Smith <dds google com>
Date: Thu, 24 Jul 2008 02:12:21 +0900
Subject: [PATCH] Add DBus interface to set environment variable

---
 wpa_supplicant/ctrl_iface_dbus.c          |    2 +
 wpa_supplicant/ctrl_iface_dbus_handlers.c |   39 +++++++++++++++++++++++++++++
 wpa_supplicant/ctrl_iface_dbus_handlers.h |    2 +
 3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface_dbus.c b/wpa_supplicant/ctrl_iface_dbus.c
index 59763d6..32b09b5 100644
--- a/wpa_supplicant/ctrl_iface_dbus.c
+++ b/wpa_supplicant/ctrl_iface_dbus.c
@@ -601,6 +601,8 @@ static DBusHandlerResult wpas_message_handler(DBusConnection *connection,
 		} else if (!strcmp(method, "getInterface")) {
 			reply = wpas_dbus_global_get_interface(
 				message, ctrl_iface->global);
+		} else if (!strcmp(method, "setEnvironmentVariable")) {
+			reply = wpas_dbus_global_set_envvar(message);
 		}
 	}
 
diff --git a/wpa_supplicant/ctrl_iface_dbus_handlers.c b/wpa_supplicant/ctrl_iface_dbus_handlers.c
index a8f9e2c..5b59f4a 100644
--- a/wpa_supplicant/ctrl_iface_dbus_handlers.c
+++ b/wpa_supplicant/ctrl_iface_dbus_handlers.c
@@ -279,6 +279,45 @@ out:
 
 
 /**
+ * wpas_dbus_global_set_envvar - Set an environment variable
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: a dbus message containing a UINT32 indicating success (1) or
+ *          failure (0), or returns a dbus error message with more information
+ *
+ * Handler function for "setEnvironmentVariable" method call.
+ */
+DBusMessage * wpas_dbus_global_set_envvar(DBusMessage *message)
+{
+	DBusMessage *reply = NULL;
+	const char *name;
+	const char *value;
+
+	if (!dbus_message_get_args(message, NULL,
+				   DBUS_TYPE_STRING, &name,
+				   DBUS_TYPE_INVALID)) {
+		reply = wpas_dbus_new_invalid_opts_error(message, NULL);
+		goto out;
+	}
+
+	if (!dbus_message_get_args(message, NULL,
+				   DBUS_TYPE_STRING, &value,
+				   DBUS_TYPE_INVALID)) {
+		reply = wpas_dbus_new_invalid_opts_error(message, NULL);
+		goto out;
+	}
+
+	if (NULL == value)
+		unsetenv(name);
+	else
+		setenv(name, value, 1);
+
+	reply = wpas_dbus_new_success_reply(message);
+out:
+	return reply;
+}
+
+/**
  * wpas_dbus_iface_scan - Request a wireless scan on an interface
  * @message: Pointer to incoming dbus message
  * @wpa_s: wpa_supplicant structure for a network interface
diff --git a/wpa_supplicant/ctrl_iface_dbus_handlers.h b/wpa_supplicant/ctrl_iface_dbus_handlers.h
index 9660f95..12a43cd 100644
--- a/wpa_supplicant/ctrl_iface_dbus_handlers.h
+++ b/wpa_supplicant/ctrl_iface_dbus_handlers.h
@@ -28,6 +28,8 @@ DBusMessage * wpas_dbus_global_remove_interface(DBusMessage *message,
 DBusMessage * wpas_dbus_global_get_interface(DBusMessage *message,
 					     struct wpa_global *global);
 
+DBusMessage * wpas_dbus_global_set_envvar(DBusMessage *message);
+
 DBusMessage * wpas_dbus_iface_scan(DBusMessage *message,
 				   struct wpa_supplicant *wpa_s);
 
-- 
1.5.4.3

Attachment: pgpTSJTLkms1M.pgp
Description: PGP signature



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