From b72ec1777981357ea2b820d6bb569a6e4bd1ef7c Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Thu, 13 Oct 2011 14:49:44 +0200 Subject: [PATCH 4/4] 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 --- configure.ac | 1 + src/daemon.c | 14 +++++++++++++- 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); -- 1.7.7