From d62cf1eb84c245692d63a45c9ef71583bd2bfda1 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Wed, 28 Dec 2011 13:59:08 -0500 Subject: [PATCH] Add HAVE_PW_GECOS_IN_PASSWD configuration flag Change-Id: I0a1997bfa45966f619f9ec5ffaeb8f9be9f741e9 Signed-off-by: Mike Lockwood --- auth.c | 2 ++ config.h.in | 3 +++ configure | 34 ++++++++++++++++++++++++++++++++++ configure.ac | 13 +++++++++++++ misc.c | 4 +++- monitor.c | 2 ++ monitor_wrap.c | 2 ++ 7 files changed, 59 insertions(+), 1 deletion(-) diff --git a/auth.c b/auth.c index cd95da9..ddb4248 100644 --- a/auth.c +++ b/auth.c @@ -682,7 +682,9 @@ fakepw(void) fake.pw_name = "NOUSER"; fake.pw_passwd = "$2a$06$r3.juUaHZDlIbQaO2dS9FuYxL1W9M81R1Tc92PoSNmzvpEqLkLGrK"; +#ifdef HAVE_PW_GECOS_IN_PASSWD fake.pw_gecos = "NOUSER"; +#endif fake.pw_uid = privsep_pw == NULL ? (uid_t)-1 : privsep_pw->pw_uid; fake.pw_gid = privsep_pw == NULL ? (gid_t)-1 : privsep_pw->pw_gid; #ifdef HAVE_PW_CLASS_IN_PASSWD diff --git a/config.h.in b/config.h.in index baf0011..eccd37f 100644 --- a/config.h.in +++ b/config.h.in @@ -732,6 +732,9 @@ /* Define if your password has a pw_change field */ #undef HAVE_PW_CHANGE_IN_PASSWD +/* Define if your password has a pw_gecos field */ +#undef HAVE_PW_GECOS_IN_PASSWD + /* Define if your password has a pw_class field */ #undef HAVE_PW_CLASS_IN_PASSWD diff --git a/configure b/configure index 43c4372..902d850 100755 --- a/configure +++ b/configure @@ -13620,6 +13620,40 @@ $as_echo "#define HAVE_PW_CHANGE_IN_PASSWD 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pw_gecos field in struct passwd" >&5 +$as_echo_n "checking for pw_gecos field in struct passwd... " >&6; } +if ${ac_cv_have_pw_gecos_in_struct_passwd+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + #include +int +main () +{ + struct passwd p; p.pw_gecos = 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_have_pw_gecos_in_struct_passwd="yes" +else + ac_cv_have_pw_gecos_in_struct_passwd="no" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_pw_gecos_in_struct_passwd" >&5 +$as_echo "$ac_cv_have_pw_gecos_in_struct_passwd" >&6; } +if test "x$ac_cv_have_pw_gecos_in_struct_passwd" = "xyes" ; then + +$as_echo "#define HAVE_PW_GECOS_IN_PASSWD 1" >>confdefs.h + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for msg_accrights field in struct msghdr" >&5 $as_echo_n "checking for msg_accrights field in struct msghdr... " >&6; } if ${ac_cv_have_accrights_in_msghdr+:} false; then : diff --git a/configure.ac b/configure.ac index 7a91527..bf540b1 100644 --- a/configure.ac +++ b/configure.ac @@ -3100,6 +3100,19 @@ if test "x$ac_cv_have_pw_change_in_struct_passwd" = "xyes" ; then [Define if your password has a pw_change field]) fi +AC_CACHE_CHECK([for pw_gecos field in struct passwd], + ac_cv_have_pw_gecos_in_struct_passwd, [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ struct passwd p; p.pw_gecos = 0; ]])], + [ ac_cv_have_pw_gecos_in_struct_passwd="yes" ], + [ ac_cv_have_pw_gecos_in_struct_passwd="no" + ]) +]) +if test "x$ac_cv_have_pw_gecos_in_struct_passwd" = "xyes" ; then + AC_DEFINE([HAVE_PW_GECOS_IN_PASSWD], [1], + [Define if your password has a pw_gecos field]) +fi + dnl make sure we're using the real structure members and not defines AC_CACHE_CHECK([for msg_accrights field in struct msghdr], ac_cv_have_accrights_in_msghdr, [ diff --git a/misc.c b/misc.c index 5f63090..b2b3bae 100644 --- a/misc.c +++ b/misc.c @@ -205,8 +205,10 @@ pwcopy(struct passwd *pw) struct passwd *copy = xcalloc(1, sizeof(*copy)); copy->pw_name = xstrdup(pw->pw_name); - copy->pw_passwd = xstrdup(pw->pw_passwd); + copy->pw_passwd = pw->pw_passwd ? xstrdup(pw->pw_passwd) : NULL; +#ifdef HAVE_PW_GECOS_IN_PASSWD copy->pw_gecos = xstrdup(pw->pw_gecos); +#endif copy->pw_uid = pw->pw_uid; copy->pw_gid = pw->pw_gid; #ifdef HAVE_PW_EXPIRE_IN_PASSWD diff --git a/monitor.c b/monitor.c index a166fed..f865057 100644 --- a/monitor.c +++ b/monitor.c @@ -761,7 +761,9 @@ mm_answer_pwnamallow(int sock, Buffer *m) buffer_put_string(m, pwent, sizeof(struct passwd)); buffer_put_cstring(m, pwent->pw_name); buffer_put_cstring(m, "*"); +#ifdef HAVE_PW_GECOS_IN_PASSWD buffer_put_cstring(m, pwent->pw_gecos); +#endif #ifdef HAVE_PW_CLASS_IN_PASSWD buffer_put_cstring(m, pwent->pw_class); #endif diff --git a/monitor_wrap.c b/monitor_wrap.c index 1f60658..3c3856a 100644 --- a/monitor_wrap.c +++ b/monitor_wrap.c @@ -259,7 +259,9 @@ mm_getpwnamallow(const char *username) fatal("%s: struct passwd size mismatch", __func__); pw->pw_name = buffer_get_string(&m, NULL); pw->pw_passwd = buffer_get_string(&m, NULL); +#ifdef HAVE_PW_GECOS_IN_PASSWD pw->pw_gecos = buffer_get_string(&m, NULL); +#endif #ifdef HAVE_PW_CLASS_IN_PASSWD pw->pw_class = buffer_get_string(&m, NULL); #endif -- 2.11.0