OSDN Git Service

Add HAVE_PW_GECOS_IN_PASSWD configuration flag
authorMike Lockwood <lockwood@google.com>
Wed, 28 Dec 2011 18:59:08 +0000 (13:59 -0500)
committerMike Lockwood <lockwood@google.com>
Wed, 28 Dec 2011 18:59:08 +0000 (13:59 -0500)
Change-Id: I2571f00b4b6ba41b7795c8c78c58253e5d0205dd
Signed-off-by: Mike Lockwood <lockwood@google.com>
auth.c
config.h.in
configure
configure.ac
misc.c
monitor.c
monitor_wrap.c

diff --git a/auth.c b/auth.c
index cd95da9..ddb4248 100644 (file)
--- 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
index baf0011..eccd37f 100644 (file)
 /* 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
 
index 43c4372..902d850 100755 (executable)
--- 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 <pwd.h>
+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 :
index 7a91527..bf540b1 100644 (file)
@@ -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 <pwd.h> ]],
+       [[ 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 (file)
--- 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
index a166fed..f865057 100644 (file)
--- 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
index 1f60658..3c3856a 100644 (file)
@@ -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