From a18ab60939f72eb4c4b4c057790d14bcdeb3ec56 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 16 Sep 2015 08:58:28 -0400 Subject: Add an option to only show users in a list of specified groups Ported to ArcticaGreeter: Mike Gabriel --- .../org.ArcticaProject.arctica-greeter.gschema.xml | 4 +++ src/settings.vala | 1 + src/user-list.vala | 31 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/data/org.ArcticaProject.arctica-greeter.gschema.xml b/data/org.ArcticaProject.arctica-greeter.gschema.xml index b4a8d59..aa40544 100644 --- a/data/org.ArcticaProject.arctica-greeter.gschema.xml +++ b/data/org.ArcticaProject.arctica-greeter.gschema.xml @@ -94,6 +94,10 @@ [] List of usernames that are hidden until a special key combination is hit + + [] + List of groups that users must be part of to be shown (empty list shows all users) + 300 Number of seconds of inactivity before blanking the screen. Set to 0 to never timeout. diff --git a/src/settings.vala b/src/settings.vala index 6757b9c..9aef819 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -40,6 +40,7 @@ public class AGSettings public static const string KEY_PLAY_READY_SOUND = "play-ready-sound"; public static const string KEY_INDICATORS = "indicators"; public static const string KEY_HIDDEN_USERS = "hidden-users"; + public static const string KEY_GROUP_FILTER = "group-filter"; public static const string KEY_IDLE_TIMEOUT = "idle-timeout"; public static const string KEY_REMOTE_SERVICE_FQDN = "remote-service-fqdn"; diff --git a/src/user-list.vala b/src/user-list.vala index 4805956..a4e4099 100644 --- a/src/user-list.vala +++ b/src/user-list.vala @@ -1044,6 +1044,9 @@ public class UserList : GreeterList return; } + if (!filter_group (user.name)) + return; + var label = user.real_name; if (user.real_name == "") label = user.name; @@ -1051,6 +1054,34 @@ public class UserList : GreeterList add_user (user.name, label, user.background, user.logged_in, user.has_messages, user.session); } + private bool filter_group (string user_name) + { + var group_filter = UGSettings.get_strv (UGSettings.KEY_GROUP_FILTER); + + /* Empty list means do not filter by group */ + if (group_filter.length == 0) + return true; + + foreach (var group_name in group_filter) + if (in_group (group_name, user_name)) + return true; + + return false; + } + + private bool in_group (string group_name, string user_name) + { + unowned Posix.Group? group = Posix.getgrnam (group_name); + if (group == null) + return false; + + foreach (var name in group.gr_mem) + if (name == user_name) + return true; + + return false; + } + private void user_removed_cb (LightDM.User user) { debug ("Removing user %s", user.name); -- cgit v1.2.3