[nanny: 3/15] Add check_policy and obtain_auth dbus client side



commit 5cda0d77f67c59330758de734c2d98012ea5ed8b
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Sat Mar 13 15:40:46 2010 +0100

    Add check_policy and obtain_auth dbus client side

 client/common/src/DBusClient.py |   50 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/client/common/src/DBusClient.py b/client/common/src/DBusClient.py
index e11ca90..0229158 100644
--- a/client/common/src/DBusClient.py
+++ b/client/common/src/DBusClient.py
@@ -121,6 +121,56 @@ class DBusClient(gobject.GObject):
 
             self.nanny_notification.connect_to_signal ('UserNotification', self.__on_user_notification_cb)
 
+    
+    def check_policy(self, action_id):
+        pk_granted = None
+        pk_other = None
+        pk_details = None
+
+        try:
+            policykit = self.dbus.get_object("org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority")
+            pk_authority = dbus.Interface(policykit, "org.freedesktop.PolicyKit1.Authority")
+            pid = os.getpid()
+            (pk_granted,pk_other,pk_details) = pk_authority.CheckAuthorization(
+                ('unix-process',{'pid':dbus.UInt32(pid,variant_level=1),'start-time':dbus.UInt64(0,variant_level=1)}),
+                action_id ,{},dbus.UInt32(0),'',timeout=600)
+
+        except dbus.exceptions.DBusException, e:
+            print "exception: ", e
+            return False
+        except Exception, e:
+            print "other exception: ", e
+            return False
+
+        if pk_granted != None and pk_granted != False :
+            return True
+        else:
+            return False
+
+    def obtain_auth (self, action_id):
+        pk_granted = None
+        pk_other = None
+        pk_details = None
+
+        try:
+            policykit = self.dbus.get_object("org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority")
+            pk_authority = dbus.Interface(policykit, "org.freedesktop.PolicyKit1.Authority")
+            pid = os.getpid()
+            (pk_granted,pk_other,pk_details) = pk_authority.CheckAuthorization(
+                ('unix-process',{'pid':dbus.UInt32(pid,variant_level=1),'start-time':dbus.UInt64(0,variant_level=1)}),
+                action_id ,{},dbus.UInt32(1),'',timeout=600)
+
+        except dbus.exceptions.DBusException, e:
+            print "exception: ", e
+            return False
+        except Exception, e:
+            print "other exception: ", e
+            return False
+
+        if pk_granted != None and pk_granted != False :
+            return True
+        else:
+            return False
 
     def list_users(self):
         return self.nanny_admin.ListUsers ()



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