notification-daemon based handler
authorJoachim Breitner <mail@joachim-breitner.de>
Fri, 8 Aug 2008 02:47:32 +0000 (02:47 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Fri, 8 Aug 2008 02:47:32 +0000 (02:47 +0000)
dummy/pam-dbus-notification-daemon.py [new file with mode: 0644]

diff --git a/dummy/pam-dbus-notification-daemon.py b/dummy/pam-dbus-notification-daemon.py
new file mode 100644 (file)
index 0000000..7ff780a
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+
+import pygtk
+import gtk
+import gobject
+
+import dbus
+import dbus.service
+import dbus.glib
+
+import pynotify
+
+# list of Notifications around, kept to prevent the garbage collector to handle them.
+ns = []
+
+def notify_cb(n, action, pam_cb):
+    if pam_cb is not None:
+        if action == "permit":
+            pam_cb(True)
+        else:
+            pam_cb(False)
+        pam_cb = None
+    ns.remove(n)
+
+# Initializite pynotify
+if not pynotify.init("pam-dbus"):
+    sys.exit(1)
+
+# dbus object to answer the request
+class PamDbusAnswer(dbus.service.Object):
+     def __init__(self, bus_name, object_path="/de/nomeata/pam_dbus"):
+         dbus.service.Object.__init__(self, bus_name, object_path)
+     @dbus.service.method(dbus_interface='de.nomeata.pam_dbus',
+                          in_signature='ssss', out_signature='b',
+                          async_callbacks=('ret_cb', 'error_cb'))
+     def MayLogin(self, service, user, rhost, ruser, ret_cb, error_cb):
+
+         n = pynotify.Notification("Login request","Someone " + 
+                            ("named %s " % ruser if ruser else "") +
+                            "tries to log in via %s " % service + 
+                            ("from %s " % rhost if rhost else "") + 
+                            "as user %s. " % user + 
+                            "Do you want to allow that?")
+
+         n.set_timeout(5*60*1000)
+         n.add_action("permit", "Permit login", notify_cb, ret_cb)
+         n.add_action("deny", "Deny login", notify_cb,ret_cb)
+         n.connect("closed",lambda n: notify_cb(n,"closed", ret_cb))
+
+         if not n.show():
+             print "Failed to send notification"
+             sys.exit(1)
+
+         ns.append(n)
+system_bus = dbus.SystemBus()
+name = dbus.service.BusName("de.nomeata.pam_dbus", bus=system_bus)
+object = PamDbusAnswer(name)
+
+gtk.main()
+