summaryrefslogtreecommitdiff
authorChristian Hesse <mail@earthworm.de>2012-05-08 15:03:50 (GMT)
committer Ray Strode <rstrode@redhat.com>2012-05-08 15:15:28 (GMT)
commit6fdffae03f973e924fbcaf090ce4685e134d60d7 (patch) (side-by-side diff)
tree9b22f523f731c453b07e43d07969c3eab8ccc142
parentf879ee5e6e16766c291fe38420cd8a33273b0afa (diff)
downloadaccountsservice-master.zip
accountsservice-master.tar.gz
daemon: exclude users without valid shellHEADmaster
This patch makes sure only users with valid shells from /etc/shells get returned by ListCachedUsers. Minor changes by Ray Strode.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/daemon.c18
-rw-r--r--src/user.c6
-rw-r--r--src/user.h1
3 files changed, 23 insertions, 2 deletions
diff --git a/src/daemon.c b/src/daemon.c
index 2c53ac0..6bfff91 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -30,7 +30,6 @@
#include <pwd.h>
#include <unistd.h>
#include <errno.h>
-#include <unistd.h>
#include <sys/types.h>
#ifdef HAVE_UTMPX_H
#include <utmpx.h>
@@ -172,6 +171,19 @@ daemon_local_user_is_excluded (Daemon *daemon, const gchar *username, const gcha
if (shell != NULL) {
char *basename, *nologin_basename, *false_basename;
+#ifdef HAVE_GETUSERSHELL
+ char *valid_shell;
+
+ ret = TRUE;
+ setusershell ();
+ while ((valid_shell = getusershell ()) != NULL) {
+ if (g_strcmp0 (shell, valid_shell) != 0)
+ continue;
+ ret = FALSE;
+ }
+ endusershell ();
+#endif
+
basename = g_path_get_basename (shell);
nologin_basename = g_path_get_basename (PATH_NOLOGIN);
false_basename = g_path_get_basename (PATH_FALSE);
@@ -839,13 +851,15 @@ finish_list_cached_users (gpointer user_data)
const gchar *name;
User *user;
uid_t uid;
+ const gchar *shell;
object_paths = g_ptr_array_new ();
g_hash_table_iter_init (&iter, data->daemon->priv->users);
while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&user)) {
uid = user_local_get_uid (user);
- if (!daemon_local_user_is_excluded (data->daemon, name, NULL)) {
+ shell = user_local_get_shell (user);
+ if (!daemon_local_user_is_excluded (data->daemon, name, shell)) {
g_debug ("user %s %ld not excluded\n", name, (long) uid);
g_ptr_array_add (object_paths, (gpointer) user_local_get_object_path (user));
}
diff --git a/src/user.c b/src/user.c
index 4703883..01507fe 100644
--- a/src/user.c
+++ b/src/user.c
@@ -483,6 +483,12 @@ user_local_get_uid (User *user)
return user->uid;
}
+const gchar *
+user_local_get_shell(User *user)
+{
+ return user->shell;
+}
+
static void
throw_error (GDBusMethodInvocation *context,
gint error_code,
diff --git a/src/user.h b/src/user.h
index 06523d7..fd6dc99 100644
--- a/src/user.h
+++ b/src/user.h
@@ -65,6 +65,7 @@ const gchar *user_local_get_user_name (User *user);
const gchar *user_local_get_user_name (User *user);
const gchar *user_local_get_object_path (User *user);
uid_t user_local_get_uid (User *user);
+const gchar *user_local_get_shell (User *user);
G_END_DECLS