Author: lslezak
Date: Fri Mar 6 18:06:14 2009
New Revision: 55997
URL: http://svn.opensuse.org/viewcvs/yast?rev=55997&view=rev
Log:
- DBus service: register PolicyKit IO watch callbacks for monitoring
PolicyKit config changes
Modified:
branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc
branches/tmp/lslezak/core/liby2dbus/src/PolKit.h
Modified: branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc?rev=55997&r1=55996&r2=55997&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc Fri Mar 6 18:06:14 2009
@@ -7,14 +7,94 @@
#include
+#include<map>
+
+typedef std::map PolKitMapping;
+
+// PolKitContext * -> PolKit * mapping
+// for routing the policykit callbacks to the correct PolKit object
+PolKitMapping polkit_mapping;
+
+PolKit* findPolKitObj(PolKitContext *context)
+{
+ PolKitMapping::const_iterator it = polkit_mapping.find(context);
+
+ if (it == polkit_mapping.end())
+ {
+ y2error("Cannot find PolKit object for PolKitContext %p", context);
+ return NULL;
+ }
+ else
+ {
+ return it->second;
+ }
+}
+
+static void _polkitConfigChanged(PolKitContext *context, void *data)
+{
+ y2debug("PolicyKit context %p has been changed", context);
+
+ PolKit *pk = findPolKitObj(context);
+
+ if (pk != NULL)
+ {
+ pk->configChanged();
+ }
+}
+
+static int _polkitIOAddWatch(PolKitContext *context, int fd)
+{
+ y2debug("PolicyKit context %p: adding IO watch: %d", context, fd);
+
+ PolKit *pk = findPolKitObj(context);
+
+ if (pk == NULL)
+ {
+ return 0;
+ }
+ else
+ {
+ pk->addWatch(fd);
+ }
+
+ // TODO: Polkit doc says the result must be unique ID, is this OK??
+ return fd;
+}
+
+static void _polkitIORemoveWatch(PolKitContext *context, int fd)
+{
+ y2debug("PolicyKit context %p removing IO watch: %d", context, fd);
+
+ PolKit *pk = findPolKitObj(context);
+
+ if (pk != NULL)
+ {
+ pk->removeWatch(fd);
+ }
+}
+
PolKit::PolKit() : polkit_error(NULL)
{
context = polkit_context_new();
+
+ // add object mapping
+ polkit_mapping.insert(std::make_pair(context, this));
+
+ // set PolicyKit config change callback
+ polkit_context_set_config_changed(context, _polkitConfigChanged, NULL);
+
+ // set PolicyKit config watch callbacks
+ polkit_context_set_io_watch_functions(context, _polkitIOAddWatch, _polkitIORemoveWatch);
+
polkit_context_init(context, &polkit_error);
}
PolKit::~PolKit()
{
+ // release this object from mapping
+ polkit_mapping.erase(context);
+
+ // release the PolKitContext object
polkit_context_unref(context);
}
@@ -148,3 +228,36 @@
return polkit_action_validate_id(action.c_str());
}
+void PolKit::checkPolkitChanges()
+{
+#warning TODO: polkit_context_io_func() is not called
+
+ // TODO: check the registered file descriptors here,
+ // if there is something to read then call
+ // polkit_context_io_func(context, ready_fd)
+}
+
+void PolKit::addWatch(int fd)
+{
+ y2milestone("Adding Polkit watch fd: %d", fd);
+
+ // add the fd to the internal list
+ fd_watch_list.push_back(fd);
+
+ y2debug("%zd file descriptors in the watch list", fd_watch_list.size());
+}
+
+void PolKit::removeWatch(int fd)
+{
+ y2milestone("Removing Polkit watch fd: %d", fd);
+
+ // remove the fd from the internal list
+ fd_watch_list.remove_if(std::bind2nd(std::equal_to<int>(), fd));
+
+ y2debug("%zd file descriptors in the watch list", fd_watch_list.size());
+}
+
+void PolKit::configChanged()
+{
+ y2milestone("PolicyKit config has been changed");
+}
Modified: branches/tmp/lslezak/core/liby2dbus/src/PolKit.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/PolKit.h?rev=55997&r1=55996&r2=55997&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/PolKit.h (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/PolKit.h Fri Mar 6 18:06:14 2009
@@ -8,6 +8,7 @@
#include <string>
+#include <list>
#include
#include
@@ -22,6 +23,12 @@
bool isDBusUserAuthorized(const std::string &action_id, const std::string &dbus_caller,
DBusConnection *con, DBusError*err);
+ void checkPolkitChanges();
+
+ void addWatch(int fd);
+ void removeWatch(int fd);
+ void configChanged();
+
static std::string createActionId(const std::string &prefix, const std::string &path,
const std::string &method, const std::string &arg = std::string(),
const std::string &opt = std::string());
@@ -34,6 +41,8 @@
PolKitError *polkit_error;
PolKitContext *context;
+
+ std::list<int> fd_watch_list;
};
#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org