#!/usr/bin/python # # Copyright Martin Owens, 2011 # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see # """ Attempt to connect to the GDM2 greeter dbus service. This python attempts to replace the greeter with an experimental replacement, to show it's possible. No user listing yet. """ USERNAME = "Your USERNAME here" PASSWORD = "Your PASSWORD here" import os import sys import gobject import dbus import dbus.bus import dbus.exceptions import dbus.mainloop.glib sys.stderr.write("Experimental Greeter Started\n") dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) mainloop = gobject.MainLoop() class GdmDbusService(object): """Basic wrapper to create the correct interfaces and proxy signals""" def __init__(self): try: # The first is access to the object and any interfaces. self.raw = self.connection.get_object(self.address, self.path) except dbus.exceptions.DBusException: sys.stderr.write("Failed to get Dbus object %s\n" % self.path) raise # The second is access to the interface, which is more interesting. self.obj = dbus.Interface(self.raw, self.interface) # Watch all signals on this interface self.connection.add_signal_receiver(self.got_signal, dbus_interface=self.interface, signal_name=None, bus_name=None, path=self.path, sender_keyword="sent", destination_keyword="dest", interface_keyword=None, member_keyword="name", path_keyword=None, message_keyword=None ) def got_signal(self, *args, **kwargs): """Log all signals and call the proxy method for it.""" name = kwargs.pop('name', 'Unknown') # Call the object's signal proxy method if hasattr(self, name): getattr(self, name)( *args ) else: for key in kwargs.keys(): if kwargs[key] == None: kwargs.pop(key) if kwargs: sys.stderr.write( "%s:%s%s %s\n" % ( self.interface, name, str(args), str(kwargs)) ) else: sys.stderr.write("%s:%s%s\n" % (self.interface, name, str(args))) class GdmGreeter(GdmDbusService): """Connects tot he greeter client""" path = '/org/gnome/DisplayManager/GreeterServer' address = 'org.gnome.DisplayManager.GreeterServer' interface = 'org.gnome.DisplayManager.GreeterServer' def __init__(self, address): try: self.connection = dbus.connection.Connection(address) sys.stderr.write("Connected to Greeter-Service on %s\n" % address) except dbus.exceptions.DBusException: sys.stderr.write("Failed to connect to Greeter-Service on %s\n" % address) raise super(GdmGreeter, self).__init__() self.display = GdmDisplay(self.obj.GetDisplayId()) def Ready(self): """Called when greeter service is ready""" sys.stderr.write("Server is Ready\n") # Will signal InfoQuery for Username first, then password #self.obj.BeginVerification() # Will signal SecrateInfoQuery for Password only self.obj.BeginVerificationForUser(USERNAME) def InfoQuery(self, text): """Server wants to ask the user for something""" sys.stderr.write("Asking user for '%s'\n" % text) # XXX We don't do anything def SecretInfoQuery(self, text): """Server wants to ask for some secrate info""" sys.stderr.write("Secrate request for '%s'\n" % text) self.obj.AnswerQuery(PASSWORD) def UserAuthorized(self): """User is ready to go, lets get them in""" self.obj.StartSessionWhenReady( True ) sys.exit(0) class GdmDisplay(GdmDbusService): """Connect to the display bus""" address = 'org.gnome.DisplayManager' interface = 'org.gnome.DisplayManager.Display' def __init__(self, path): self.connection = dbus.SystemBus() self.path = path super(GdmDisplay, self).__init__() # Start the client using the address for the private dbus greeter = GdmGreeter(os.environ['GDM_GREETER_DBUS_ADDRESS']) mainloop.run()