From 5a23d09353c6f48613ae99383cca7b0d82550908 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 6 Apr 2013 08:54:52 -0400 Subject: [PATCH] Check for getgrent() and other struct passwd members. --- configure.ac | 36 +++++++++++++++++++++++++++++++++++- src/modules/passwd.c | 19 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 3c2cbc5..8ecc26b 100644 --- a/configure.ac +++ b/configure.ac @@ -43,9 +43,43 @@ AC_FUNC_STAT AC_FUNC_STRFTIME AC_FUNC_MMAP AC_CHECK_FUNCS([memset getspnam munmap setpassent setgroupent strchr strdup \ - strerror strsep]) + strerror strsep getgrent]) AC_CHECK_FUNC([__progname]) +# Test for struct passwd members. +AC_MSG_CHECKING([for pw_change member in struct passwd]) +AC_TRY_COMPILE([#include ], + [struct passwd pwd; + (void)pwd.pw_change;], have_passwd_change=yes) +if test x"$have_passwd_change" = "xyes"; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_PASSWD_CHANGE, 1, [Define if struct passwd contains pw_change.]) +else + AC_MSG_RESULT([no]) +fi + +AC_MSG_CHECKING([for pw_expire member in struct passwd]) +AC_TRY_COMPILE([#include ], + [struct passwd pwd; + (void)pwd.pw_expire;], [have_passwd_expire=yes]) +if test x"$have_passwd_expire" = "xyes"; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_PASSWD_EXPIRE, 1, [Define if struct passwd contains pw_expire.]) +else + AC_MSG_RESULT([no]) +fi + +AC_MSG_CHECKING([for pw_gecos member in struct passwd]) +AC_TRY_COMPILE([#include ], + [struct passwd pwd; + (void)pwd.pw_gecos;], [have_passwd_gecos=yes]) +if test x"$have_passwd_gecos" = "xyes"; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_PASSWD_GECOS, 1, [Define if struct passwd contains pw_gecos.]) +else + AC_MSG_RESULT([no]) +fi + dnl /proc filesystem support AC_MSG_CHECKING(for /proc filesystem) diff --git a/src/modules/passwd.c b/src/modules/passwd.c index 6c6be87..ccf0552 100644 --- a/src/modules/passwd.c +++ b/src/modules/passwd.c @@ -108,7 +108,9 @@ void ui_module_exit() #endif endpwent(); +#ifdef HAVE_GETGRENT endgrent(); +#endif } /* See if the gecos options are valid. */ @@ -215,7 +217,7 @@ static void groups(const struct passwd *pw, const int multi, (verbose) ? "(" : "", (verbose) ? grp->gr_name : "", (verbose) ? ")" : "", multi); safe_strncat(line, tmp, sizeof(line)); - +#ifdef HAVE_GETGRENT #ifdef HAVE_SETGROUPENT setgroupent(1); #else @@ -237,9 +239,10 @@ static void groups(const struct passwd *pw, const int multi, } } } +#endif /* - * Trim the remaining multi-string deliminator. + * Trim the remaining multi-string deliminator. */ line[strlen(line) - 1] = '\0'; @@ -309,12 +312,20 @@ int ui_module_exec(char ***s, const struct passwd *pw, const int multi_char, break; #else case 'c': +#ifdef HAVE_PASSWD_CHANGE snprintf(tmp, sizeof(tmp), "%li", (long) pw->pw_change); add_string(&strings, tmp); +#else + add_string(&strings, "!"); +#endif break; case 'e': +#ifdef HAVE_PASSWD_EXPIRE snprintf(tmp, sizeof(tmp), "%li", (long) pw->pw_expire); add_string(&strings, tmp); +#else + add_string(&strings, "!"); +#endif break; #endif case 'l': @@ -356,7 +367,11 @@ int ui_module_exec(char ***s, const struct passwd *pw, const int multi_char, add_string(&strings, tmp); break; case 'i': +#ifdef HAVE_PASSWD_GECOS gecos_strings(pw->pw_gecos); +#else + add_string(&strings, "!"); +#endif break; default: break; -- 2.11.4.GIT