summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schouten <ed@80386.nl>2011-10-13 14:49:44 +0200
committerMatthias Clasen <mclasen@redhat.com>2011-10-17 15:30:22 -0400
commitdfa1a6239b01c823ce0fec781c6c9541c988f56e (patch)
tree58724aa128e8ca581f2b325be94d667c31f4097a
parent3b67e7ffc8a25e25460378832aef0387b8bcfcf4 (diff)
Don't use the non-standard fgetpwent() if not available.
The fgetpwent() function seems to be a Linux-specific extension. POSIX does not specify such a function. I think we can even get rid of fgetpwent() altogether, since we use it on /etc/passwd, which is already the default. Signed-off-by: Ed Schouten <ed@80386.nl> https://bugs.freedesktop.org/show_bug.cgi?id=41747
-rw-r--r--configure.ac1
-rw-r--r--src/daemon.c14
2 files changed, 14 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 352adde..09dc2eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -121,6 +121,7 @@ WARN_CFLAGS="$accountsservice_cv_warn_cflags"
AC_SUBST(WARN_CFLAGS)
AC_CHECK_HEADERS([shadow.h utmpx.h])
+AC_CHECK_FUNCS([fgetpwent])
dnl ---------------------------------------------------------------------------
dnl - DocBook Documentation
diff --git a/src/daemon.c b/src/daemon.c
index c6ae9e0..35267f6 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -335,22 +335,32 @@ reload_passwd (Daemon *daemon)
GSList *old_users;
GSList *new_users;
GSList *list;
+#ifdef HAVE_FGETPWENT
FILE *fp;
+#endif
User *user = NULL;
old_users = NULL;
new_users = NULL;
+#ifdef HAVE_FGETPWENT
errno = 0;
fp = fopen (PATH_PASSWD, "r");
if (fp == NULL) {
g_warning ("Unable to open %s: %s", PATH_PASSWD, g_strerror (errno));
goto out;
}
+#else
+ setpwent();
+#endif
g_hash_table_foreach (daemon->priv->users, listify_hash_values_hfunc, &old_users);
g_slist_foreach (old_users, (GFunc) g_object_ref, NULL);
- for (pwent = fgetpwent (fp); pwent != NULL; pwent = fgetpwent (fp)) {
+#ifdef HAVE_FGETPWENT
+ while ((pwent = fgetpwent (fp)) != NULL) {
+#else
+ while ((pwent = getpwent ()) != NULL) {
+#endif
/* Skip users below MINIMAL_UID... */
if (daemon_local_user_is_excluded (daemon, pwent->pw_name, pwent->pw_uid)) {
g_debug ("skipping user: %s", pwent->pw_name);
@@ -400,10 +410,12 @@ reload_passwd (Daemon *daemon)
}
}
+#ifdef HAVE_FGETPWENT
out:
/* Cleanup */
fclose (fp);
+#endif
g_slist_foreach (new_users, (GFunc) g_object_thaw_notify, NULL);
g_slist_foreach (new_users, (GFunc) g_object_unref, NULL);