Author: lslezak
Date: Tue Jul 1 11:48:16 2008
New Revision: 48707
URL: http://svn.opensuse.org/viewcvs/yast?rev=48707&view=rev
Log:
- added missing Polkit.* files
Added:
branches/tmp/lslezak/workshop/core/libscr/src/PolKit.cc
branches/tmp/lslezak/workshop/core/libscr/src/PolKit.h
Added: branches/tmp/lslezak/workshop/core/libscr/src/PolKit.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/libscr/src/PolKit.cc?rev=48707&view=auto
==============================================================================
--- branches/tmp/lslezak/workshop/core/libscr/src/PolKit.cc (added)
+++ branches/tmp/lslezak/workshop/core/libscr/src/PolKit.cc Tue Jul 1 11:48:16 2008
@@ -0,0 +1,143 @@
+
+/*
+ PolKit implementation
+*/
+
+#include "PolKit.h"
+
+#include
+#include
+
+#include
+#include
+
+#include
+
+PolKit::PolKit()
+{
+}
+
+PolKit::~PolKit()
+{
+}
+
+bool PolKit::isUserAuthorized(const std::string &action_id)
+{
+ // root is always authorized
+ if (getuid() == 0)
+ {
+ y2debug("User root is authorized");
+ return true;
+ }
+
+ bool ret = false;
+ DBusError dbus_error;
+ DBusConnection *bus = NULL;
+ PolKitCaller *caller = NULL;
+ PolKitAction *action = NULL;
+ PolKitContext *context = NULL;
+ PolKitError *polkit_error = NULL;
+ PolKitSession *session = NULL;
+ PolKitResult polkit_result;
+
+ dbus_error_init(&dbus_error);
+
+ if (!(bus = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error))) {
+ goto finish;
+ }
+
+ if (!(caller = polkit_caller_new_from_pid(bus, getpid(), &dbus_error))) {
+ goto finish;
+ }
+
+ if (!(polkit_caller_set_uid(caller, getuid()))) {
+ goto finish;
+ }
+
+ if (!(polkit_caller_get_ck_session(caller, &session))) {
+ goto finish;
+ }
+
+ if (!(polkit_session_set_uid(session, getuid()))) {
+ goto finish;
+ }
+
+ if (!(action = polkit_action_new())) {
+ goto finish;
+ }
+
+ if (!polkit_action_set_action_id(action, action_id.c_str())) {
+ goto finish;
+ }
+
+ if (!(context = polkit_context_new())) {
+ goto finish;
+ }
+
+ if (!polkit_context_init(context, &polkit_error)) {
+ goto finish;
+ }
+
+ for (;;) {
+
+ polkit_result = polkit_context_is_caller_authorized(context, action, caller, FALSE, &polkit_error);
+
+ if (polkit_error_is_set(polkit_error)) {
+ goto finish;
+ }
+
+ printf("Action: %s Result: %s\n", action_id.c_str(), polkit_result_to_string_representation(polkit_result));
+
+ if (polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_SESSION ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_ALWAYS ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS ||
+ polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT
+ ) {
+ printf("Obtaining the authentication...\n");
+
+ int obtained = polkit_auth_obtain(action_id.c_str(), 0, getpid(), &dbus_error);
+
+ printf("Obtained: %d\n", obtained);
+
+ if (obtained) {
+ polkit_result = POLKIT_RESULT_YES;
+ break;
+ }
+
+ if (dbus_error_is_set(&dbus_error)) {
+ printf("DBUS error\n");
+ goto finish;
+ }
+ }
+
+ break;
+ }
+
+ ret = polkit_result == POLKIT_RESULT_YES;
+
+finish:
+
+ if (caller)
+ polkit_caller_unref(caller);
+
+ if (action)
+ polkit_action_unref(action);
+
+ if (context)
+ polkit_context_unref(context);
+
+ if (bus)
+ dbus_connection_unref(bus);
+
+ dbus_error_free(&dbus_error);
+
+ if (polkit_error)
+ polkit_error_free(polkit_error);
+
+ return ret;
+}
+
Added: branches/tmp/lslezak/workshop/core/libscr/src/PolKit.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/libscr/src/PolKit.h?rev=48707&view=auto
==============================================================================
--- branches/tmp/lslezak/workshop/core/libscr/src/PolKit.h (added)
+++ branches/tmp/lslezak/workshop/core/libscr/src/PolKit.h Tue Jul 1 11:48:16 2008
@@ -0,0 +1,26 @@
+
+/*
+ PolicyKit access
+*/
+
+#ifndef PolKit_h
+#define PolKit_h
+
+
+#include <string>
+
+class PolKit
+{
+ public:
+
+ PolKit();
+ ~PolKit();
+
+ static bool isUserAuthorized(const std::string &action_id);
+
+ private:
+
+};
+
+#endif
+
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org