[nanny: 6/15] Caching pid process auth==ok server side



commit 09a6d56b83c59ba7a8221695eaff33fbf9199c66
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Sat Mar 13 21:49:52 2010 +0100

    Caching pid process auth==ok server side

 daemon/src/NannyDBus.py |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/daemon/src/NannyDBus.py b/daemon/src/NannyDBus.py
index 8bee8fc..99782f9 100644
--- a/daemon/src/NannyDBus.py
+++ b/daemon/src/NannyDBus.py
@@ -28,6 +28,7 @@ import os
 import dbus
 import dbus.service
 import dbus.mainloop.glib
+import gtop
 
 class PermissionDeniedByPolicy(dbus.DBusException):
     _dbus_error_name = 'org.gnome.nanny.PermissionDeniedByPolicy'
@@ -47,6 +48,14 @@ class NannyDBus(dbus.service.Object):
         
         self.dbus_info = None
         self.polkit = None
+        self.auth_pid_cache = []
+
+        gobject.timeout_add(1000, self.__polling_cb)
+
+    def __polling_cb(self):
+        self.auth_pid_cache = list(set(gtop.proclist()).intersection(set(self.auth_pid_cache)))
+        print self.auth_pid_cache
+        return True
 
     # Taken from Jockey 0.5.8.
     def _check_polkit_privilege(self, sender, conn, privilege):
@@ -70,6 +79,9 @@ class NannyDBus(dbus.service.Object):
                 '/org/freedesktop/DBus/Bus', False), 'org.freedesktop.DBus')
         pid = self.dbus_info.GetConnectionUnixProcessID(sender)
 
+        if int(pid) in self.auth_pid_cache :
+            return
+
         # query PolicyKit
         if self.polkit is None:
             self.polkit = dbus.Interface(dbus.SystemBus().get_object(
@@ -93,11 +105,44 @@ class NannyDBus(dbus.service.Object):
         if not is_auth:
             print '_check_polkit_privilege: sender %s on connection %s pid %i is not authorized for %s: %s' % (sender, conn, pid, privilege, str(details))
             raise PermissionDeniedByPolicy(privilege)
+        else:
+            if int(pid) not in self.auth_pid_cache :
+                self.auth_pid_cache.append(int(pid))
 
     # org.gnome.Nanny
     # --------------------------------------------------------------
     
     @dbus.service.method("org.gnome.Nanny",
+                         in_signature='', out_signature='b',
+                         sender_keyword='sender', connection_keyword='conn')
+    def IsUnLocked(self, sender=None, conn=None):
+        # get peer PID
+        if self.dbus_info is None:
+            self.dbus_info = dbus.Interface(conn.get_object('org.freedesktop.DBus',
+                '/org/freedesktop/DBus/Bus', False), 'org.freedesktop.DBus')
+        pid = self.dbus_info.GetConnectionUnixProcessID(sender)
+
+        if int(pid) in self.auth_pid_cache :
+            return True
+        else:
+            return False
+
+    @dbus.service.method("org.gnome.Nanny",
+                         in_signature='', out_signature='b',
+                         sender_keyword='sender', connection_keyword='conn')
+    def UnLock(self, sender=None, conn=None):
+        self._check_polkit_privilege(sender, conn, 'org.gnome.nanny.admin')
+        if self.dbus_info is None:
+            self.dbus_info = dbus.Interface(conn.get_object('org.freedesktop.DBus',
+                '/org/freedesktop/DBus/Bus', False), 'org.freedesktop.DBus')
+        pid = self.dbus_info.GetConnectionUnixProcessID(sender)
+
+        if int(pid) in self.auth_pid_cache :
+            return True
+        else:
+            return False
+
+    @dbus.service.method("org.gnome.Nanny",
                          in_signature='', out_signature='a(sss)')
     def ListUsers(self):
         return self.quarterback.usersmanager.get_users()



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