How to Make a Gnome Login Screen (in Python)

In Ubuntu we use Gnome and the GDM (Gnome Display Manager) login screen called gdm-simple-greeter. This program is fairly fully featured for a normal Ubuntu install and even has a configuration in /etc/gdm/custom.conf which you can play around with.

But, I want to do something special, I’m making a computer lab with a registration screen and other fun stuff. I’ll blog about the designs and code for that in a future blog post. Today I’m going to talk about how I made a gdm greeter in python despite the lack of documentation and the round-about API challenges.

First thing to realise is that GDM 2.30 which shipped with Ubuntu 10.10 has a rich and full service/client API via DBus. This allows me to do what I’m going to do because it allows my program to act just like the shipped simple greeter. Only a single greeter can talk over the DBus API and it’s worth noting that the API isn’t over the normal System or Session Dbus, it’s over a private dbus unix socket to prevent all sorts of security issues with passing passwords around.

I first deactivated the GDM greeter: `mv /usr/share/gdm/autostart/LoginWindow/gdm-simple-greeter.desktop ~/Desktop/` this will now not allow you to log into Ubuntu!

Next I developed a script which uses python’s DBus lower layers to connect over the private dbus address. The address is given to us via an environment variable ‘GDM_GREETER_DBUS_ADDRESS’ and we just feed that in as it’s randomly generated. Fill in the PASSWORD and USERNAME variables to have GDM handle the communication and log in, this is certainly not a script you should leave installed and I have written a better one with a gui now, just use it as an example.

Finally I developed a .desktop file which will autoload the example script when the login is ready. Copying that into the directory `/usr/share/gdm/autostart/LoginWindow/`.

To restart GDM I used this command as root: `service gdm stop && sleep 1 && service gdm start`

I used a VirtualBox machine which I communicated over via SSH in order to test this out, over and over, hacking away at how this could be done. You can try the same. The log files you should be watching are in `/var/log/gdm/:0-greeter.log` you’ll get all the stderr messages from your login screen in there as well as all the errors.

You can use DBus System connections on org.gnome.DisplayManager.Display to control the display and org.gnome.DisplayManager.UserManager to get lists of users, user information and events for when users are added and removed from the system, same goes for network manager and a bunch of other services running during the login session.

I’ll blog more, and perhaps video when I’m finished. For now, if you’re interested in login screen development for Gnome2 (I don’t know what they’re doing for Gnome3) then this will interest you.

Tags: , , , , , ,

7 Responses to “How to Make a Gnome Login Screen (in Python)”

  1. Wow. You are really patient 🙂

  2. Antonis Kanouras says:

    Better to

    dpkg-divert –local –rename /usr/share/gdm/autostart/LoginWindow/gdm-simple-greeter.desktop

    so it won’t be back on the next GDM upgrade. This works for any dpkg-managed file on the system.

    PS: Please enable comment preview.

  3. doctormo says:

    Thanks for the tip!

  4. […] from my previous post: Here we have a branch containing a working gdm greeter user interface with a nice python module […]

  5. Jay says:

    Awesome work!
    I\m looking forward to the description of making gui parts for the greeter.
    Do you plan to use glade for this?

  6. doctormo says:

    Jay – Yes, I’m using glade + python, I’m actually using GtkBuilder and gir-gtk

  7. […] To Replace GDM And Dialog Sheets To Make An Appearance In Ubuntu 11.10 ( Owens: How to Make a Gnome Login Screen (in Python) ( 11.10 To Switch From GDM To LightDM ( Akhtar: GNOME3 on […]