pullup from trunk
authorTom Yu <tlyu@mit.edu>
Mon, 18 Jul 2005 22:12:43 +0000 (22:12 +0000)
committerTom Yu <tlyu@mit.edu>
Mon, 18 Jul 2005 22:12:43 +0000 (22:12 +0000)
ticket: 2982
version_fixed: 1.4.2

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17306 dc483132-0cff-0310-8789-dd5450dbe970

12 files changed:
src/ChangeLog
src/configure.in
src/include/ChangeLog
src/include/configure.in
src/include/k5-platform.h
src/lib/gssapi/krb5/ChangeLog
src/lib/gssapi/krb5/import_name.c
src/lib/krb5/os/ChangeLog
src/lib/krb5/os/kuserok.c
src/util/profile/ChangeLog
src/util/profile/configure.in
src/util/profile/prof_file.c

index e053ae05d74668eba21b873fe2c73276edbdc443..30d0277a4b2cd8f1ca7936dc556b2326a98c51be 100644 (file)
@@ -1,3 +1,9 @@
+2005-03-25  Ken Raeburn  <raeburn@mit.edu>
+
+       * configure.in: Don't check for getpwnam_r and getpwuid_r in the
+       thread-safety warnings.  The tests done elsewhere in the tree are
+       stricter and may not agree.
+
 2005-01-12  Tom Yu  <tlyu@mit.edu>
 
        * aclocal.m4 (AC_LIBRARY_NET): Also check for res_ndestroy.
index fc567f2980c46e2b019c7c2563a11cf08e64f3db..26c48d3f04c9db0fdcd5e37e2ac3992ba4b83e1b 100644 (file)
@@ -133,7 +133,11 @@ dnl
 dnl
 dnl Check for thread safety issues.
 dnl (Is there a better place for this?)
-tsfuncs="getpwnam_r getpwuid_r gethostbyname_r getservbyname_r gmtime_r localtime_r"
+dnl tsfuncs="getpwnam_r getpwuid_r gethostbyname_r getservbyname_r gmtime_r localtime_r"
+dnl Removed getpwnam_r and getpwuid_r because include/configure.in has some
+dnl more careful checks, and may decide to pretend that they're not found if
+dnl the function signatures can't be figured out.
+tsfuncs="gethostbyname_r getservbyname_r gmtime_r localtime_r"
 AC_CHECK_FUNCS($tsfuncs)
 if test "$enable_thread_support" = yes; then
   tsmissing=""
index 73aa7922bfaea17037bd237347b864a18b6a5035..1246894e4afe39564b59c8b761a122ad0c0585ba 100644 (file)
@@ -5,6 +5,13 @@
 
 2005-03-25  Ken Raeburn  <raeburn@mit.edu>
 
+       * configure.in: Don't check for getpwnam_r and getpwuid_r with
+       AC_CHECK_FUNCS; use AC_CHECK_FUNC, and only set shell variables.
+       Run stricter tests on return types and numbers of arguments, and
+       only define the C macros if these parameters can actually be
+       determined.
+       * k5-platform.h (k5_getpwnam_r, k5_getpwuid_r): New macros.
+
        * k5-platform.h: Expand on init/fini comments some more.
        (MAKE_FINI_FUNCTION): Add an HP-UX specific variant that defines
        an auxiliary function fitting the signature of HP-UX 10 library
index 450eea556bd664dc6457187fd7678f2aa37a45d6..74b3986bca87eacfb45c77e2139d18dd9d4b75c4 100644 (file)
@@ -9,7 +9,7 @@ AC_PROG_INSTALL
 AC_PROG_AWK
 AC_PROG_LEX
 AC_C_CONST
-AC_CHECK_FUNCS(strdup setvbuf inet_ntoa inet_aton seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strftime strptime geteuid setenv unsetenv getenv gethostbyname2 getifaddrs getpwnam_r getpwuid_r gmtime_r localtime_r pthread_mutex_lock sched_yield)
+AC_CHECK_FUNCS(strdup setvbuf inet_ntoa inet_aton seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strftime strptime geteuid setenv unsetenv getenv gethostbyname2 getifaddrs gmtime_r localtime_r pthread_mutex_lock sched_yield)
 AC_CHECK_FUNCS( mkstemp)
 AC_HEADER_STDARG
 AC_CHECK_HEADERS(unistd.h paths.h regex.h regexp.h regexpr.h fcntl.h memory.h ifaddrs.h sys/filio.h sched.h)
@@ -50,6 +50,8 @@ fi
 ])
 dnl
 
+AC_CHECK_FUNC(getpwnam_r,ac_cv_func_getpwnam_r=yes,ac_cv_func_getpwnam_r=no)
+AC_CHECK_FUNC(getpwuid_r,ac_cv_func_getpwuid_r=yes,ac_cv_func_getpwuid_r=no)
 if test "$ac_cv_func_getpwnam_r" = yes; then
   AC_MSG_CHECKING([return type of getpwnam_r])
   AC_CACHE_VAL(krb5_cv_getpwnam_r_return_type,
@@ -68,7 +70,7 @@ if test "$ac_cv_func_getpwnam_r" = yes; then
   if test $krb5_cv_getpwnam_r_return_type = int; then
     AC_DEFINE(GETPWNAM_R_RETURNS_INT, 1, [Define if getpwnam_r returns an int])
   elif test $krb5_cv_getpwnam_r_return_type = unknown; then
-    AC_MSG_WARN([Cannot determine getpwnam_r return type, disabling])
+    AC_MSG_WARN([Cannot determine getpwnam_r return type, disabling getpwnam_r])
     ac_cv_func_getpwnam_r=no
   fi
 fi
@@ -77,23 +79,38 @@ if test "$ac_cv_func_getpwnam_r" = yes; then
   AC_CACHE_VAL(krb5_cv_getpwnam_r_args,
   [AC_TRY_COMPILE([#include <pwd.h>
    struct passwd pwx; char buf[1024];],
-   [getpwnam_r("", &pwx, buf, sizeof(buf));],
-   krb5_cv_getpwnam_r_args=4,krb5_cv_getpwnam_r_args=5)])
+   [getpwnam_r("", &pwx, buf, sizeof(buf));], args4=yes, args4=no)
+   AC_TRY_COMPILE([#include <pwd.h>
+   struct passwd pwx, *p; char buf[1024];],
+   [getpwnam_r("", &pwx, buf, sizeof(buf), &p);], args5=yes, args5=no)
+   case $args4/$args5 in
+     yes/no) krb5_cv_getpwnam_r_args=4 ;;
+     no/yes) krb5_cv_getpwnam_r_args=5 ;;
+     *) krb5_cv_getpwnam_r_args=unknown ;;
+   esac])
   AC_MSG_RESULT($krb5_cv_getpwnam_r_args)
-  if test "$krb5_cv_getpwnam_r_args" = 4; then
-    AC_DEFINE(GETPWNAM_R_4_ARGS,1,[Define if getpwnam_r exists but takes only 4 arguments (e.g., POSIX draft 6 implementations like some Solaris releases).])
+  if test "$krb5_cv_getpwnam_r_args" = unknown; then
+    AC_MSG_WARN([Cannot determine number of arguments to getpwnam_r, disabling its use.])
+    ac_cv_func_getpwnam_r=no
+  else
+    AC_DEFINE(HAVE_GETPWNAM_R,1,[Define if getpwnam_r is available and useful.])
+    if test "$krb5_cv_getpwnam_r_args" = 4; then
+      AC_DEFINE(GETPWNAM_R_4_ARGS,1,[Define if getpwnam_r exists but takes only 4 arguments (e.g., POSIX draft 6 implementations like some Solaris releases).])
+    fi
   fi
 fi
 
+if test "$ac_cv_func_getpwnam_r" = no && test "$ac_cv_func_getpwuid_r" = yes; then
+  # Actually, we could do this check, and the corresponding checks
+  # for return type and number of arguments, but I doubt we'll run
+  # into a system where we'd get to use getpwuid_r but not getpwnam_r.
+  AC_MSG_NOTICE([getpwnam_r not useful, so disabling getpwuid_r too])
+  ac_cv_func_getpwuid_r=no
+fi
 if test "$ac_cv_func_getpwuid_r" = yes; then
-  AC_MSG_CHECKING([number of arguments to getpwuid_r])
-  AC_CACHE_VAL(krb5_cv_getpwuid_r_args,
-  [AC_TRY_COMPILE([#include <pwd.h>
-   struct passwd pwx; char buf[1024];],
-   [getpwuid_r(0, &pwx, buf, sizeof(buf));],
-   krb5_cv_getpwuid_r_args=4,krb5_cv_getpwuid_r_args=5)])
-  AC_MSG_RESULT($krb5_cv_getpwuid_r_args)
-  if test "$krb5_cv_getpwuid_r_args" = 4; then
+  AC_DEFINE(HAVE_GETPWUID_R,1,[Define if getpwuid_r is available and useful.])
+  # Hack: Assume getpwuid_r is the shorter form if getpwnam_r is.
+  if test "$krb5_cv_getpwnam_r_args" = 4; then
     AC_DEFINE(GETPWUID_R_4_ARGS,1,[Define if getpwuid_r exists but takes only 4 arguments (e.g., POSIX draft 6 implementations like some Solaris releases).])
   fi
 fi
index b178622d8702840f205742f0e0bb38aa7bc449bc..8a88cacf318834d9f416b7a3122203f1c39df14e 100644 (file)
@@ -32,6 +32,7 @@
  * + 64-bit types and load/store code
  * + SIZE_MAX
  * + shared library init/fini hooks
+ * + consistent getpwnam/getpwuid interfaces
  */
 
 #ifndef K5_PLATFORM_H
@@ -492,4 +493,60 @@ load_64_le (unsigned char *p)
     return ((UINT64_TYPE)load_32_le(p+4) << 32) | load_32_le(p);
 }
 
+
+/* Make the interfaces to getpwnam and getpwuid consistent.
+   Model the wrappers on the POSIX thread-safe versions, but
+   use the unsafe system versions if the safe ones don't exist
+   or we can't figure out their interfaces.  */
+
+/* int k5_getpwnam_r(const char *, blah blah) */
+#ifdef HAVE_GETPWNAM_R
+# ifndef GETPWNAM_R_4_ARGS
+/* POSIX */
+#  define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \
+       getpwnam_r(NAME,REC,BUF,BUFSIZE,OUT)
+# else
+/* POSIX drafts? */
+#  ifdef GETPWNAM_R_RETURNS_INT
+#   define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \
+       (getpwnam_r(NAME,REC,BUF,BUFSIZE) == 0          \
+        ? (*(OUT) = REC, 0)                            \
+        : (*(OUT) = NULL, -1))
+#  else
+#   define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT)  \
+       (*(OUT) = getpwnam_r(NAME,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0)
+#  endif
+# endif
+#else /* no getpwnam_r, or can't figure out #args or return type */
+/* Will get warnings about unused variables.  */
+# define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \
+       (*(OUT) = getpwnam(NAME), *(OUT) == NULL ? -1 : 0)
+#endif
+
+/* int k5_getpwuid_r(uid_t, blah blah) */
+#ifdef HAVE_GETPWUID_R
+# ifndef GETPWUID_R_4_ARGS
+/* POSIX */
+#  define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \
+       getpwuid_r(UID,REC,BUF,BUFSIZE,OUT)
+# else
+/* POSIX drafts?  Yes, I mean to test GETPWNAM... here.  Less junk to
+   do at configure time.  */
+#  ifdef GETPWNAM_R_RETURNS_INT
+#   define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT)  \
+       (getpwuid_r(UID,REC,BUF,BUFSIZE) == 0           \
+        ? (*(OUT) = REC, 0)                            \
+        : (*(OUT) = NULL, -1))
+#  else
+#   define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT)  \
+       (*(OUT) = getpwuid_r(UID,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0)
+#  endif
+# endif
+#else /* no getpwuid_r, or can't figure out #args or return type */
+/* Will get warnings about unused variables.  */
+# define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \
+       (*(OUT) = getpwuid(UID), *(OUT) == NULL ? -1 : 0)
+#endif
+
+
 #endif /* K5_PLATFORM_H */
index edcd9a2fecc301a1999c7d43d2c111aa389fe11f..eddec9724be91817e22cb6920ca6c2af4f869941 100644 (file)
@@ -3,6 +3,10 @@
        * Makefile.in (gssapi_krb5.h): Use awk hack to work around quoting
        problem.
 
+2005-03-25  Ken Raeburn  <raeburn@mit.edu>
+
+       * import_name.c (krb5_gss_import_name): Use k5_getpwuid_r.
+
 2005-01-13 Jeffrey Altman <jaltman@mit.edu>
 
         * init_sec_context.c, acquire_cred.c: fix calls to 
index ed78b1e258f42a4824b200123acd4e43c0839a72..7969cca3aa88f89d72fbe662f3b82972d1c21981 100644 (file)
@@ -121,10 +121,8 @@ krb5_gss_import_name(minor_status, input_name_buffer,
    } else {
 #ifndef NO_PASSWORD
       uid_t uid;
-#ifdef HAVE_GETPWUID_R
       struct passwd pwx;
       char pwbuf[BUFSIZ];
-#endif
 #endif
 
       stringrep = NULL;
@@ -148,18 +146,8 @@ krb5_gss_import_name(minor_status, input_name_buffer,
       } else if (g_OID_equal(input_name_type, gss_nt_machine_uid_name)) {
         uid = *(uid_t *) input_name_buffer->value;
       do_getpwuid:
-#ifndef HAVE_GETPWUID_R
-        pw = getpwuid(uid);
-#elif defined(GETPWUID_R_4_ARGS)
-        /* old POSIX drafts */
-        pw = getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf));
-#else
-        /* POSIX */
-        if (getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf), &pw) != 0)
-            pw = NULL;
-#endif
-        if (pw)
-           stringrep = pw->pw_name;
+        if (k5_getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf), &pw) == 0)
+            stringrep = pw->pw_name;
         else
            *minor_status = (OM_uint32) G_NOUSER;
       } else if (g_OID_equal(input_name_type, gss_nt_string_uid_name)) {
index d3e7a8595b7c2d2cf73d355ac1268e9d0167f3cd..78679a84e1c5e23e72749335430c0029888a4a5a 100644 (file)
@@ -6,6 +6,10 @@
         reference counter if they have been previously called
         within the application.
 
+2005-03-25  Ken Raeburn  <raeburn@mit.edu>
+
+       * kuserok.c (krb5_kuserok): Use k5_getpwnam_r.
+
 2005-03-22  Tom Yu  <tlyu@mit.edu>
 
        * dnsglue.h: Define ns_rr_class to ns_rr_cl if ns_rr_class doesn't
index c0111b995e2343280cb6bd49332c8e866c5dc0d1..356b98706f22c02f9c294da57e9e8463f0e7ab0c 100644 (file)
@@ -74,21 +74,9 @@ krb5_kuserok(krb5_context context, krb5_principal principal, const char *luser)
     int gobble;
 
     /* no account => no access */
-#ifdef HAVE_GETPWNAM_R
     char pwbuf[BUFSIZ];
     struct passwd pwx;
-#if !defined(GETPWNAM_R_4_ARGS)
-    /* POSIX */
-    if (getpwnam_r(luser, &pwx, pwbuf, sizeof(pwbuf), &pwd) != 0)
-       pwd = NULL;
-#else
-    /* draft POSIX */
-    pwd = getpwnam_r(luser, &pwx, pwbuf, sizeof(pwbuf));
-#endif
-#else
-    pwd = getpwnam(luser);
-#endif
-    if (pwd == NULL)
+    if (k5_getpwnam_r(luser, &pwx, pwbuf, sizeof(pwbuf), &pwd) != 0)
        return(FALSE);
     (void) strncpy(pbuf, pwd->pw_dir, sizeof(pbuf) - 1);
     pbuf[sizeof(pbuf) - 1] = '\0';
index 1c9a04f3745862c21b643ef9321e442bfbb01083..91cbc657e1f930f60c470ba2d99d6273f8941979 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-25  Ken Raeburn  <raeburn@mit.edu>
+
+       * configure.in: Don't check for getpwuid_r here.
+       * prof_file.c (profile_open_file): Use k5_getpwuid_r.
+
 2005-03-03  Ken Raeburn  <raeburn@mit.edu>
 
        * prof_tree.c (profile_node_iterator): After checking skip_num
index 38fb9e426a383bea0b001ff1068b9cf9f44c4ae6..680a695944d0f5a0b0f6fda3642c51265a891cc2 100644 (file)
@@ -5,7 +5,7 @@ AC_CHECK_SIZEOF(short)
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_HEADERS(unistd.h stdlib.h pwd.h)
-AC_CHECK_FUNCS(stat access strdup getpwuid_r)
+AC_CHECK_FUNCS(stat access strdup)
 AC_PROG_AWK
 AC_KRB5_TCL
 DO_TCL=
index af298816d87970b7a6ffb4ba66c1b39d9b85bb46..5d69fa6fb82287f9310fd42410dd288a4215178a 100644 (file)
@@ -203,25 +203,12 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
 #ifdef HAVE_PWD_H
                if (home_env == NULL) {
                    uid_t uid;
-                   struct passwd *pw;
-#ifdef HAVE_GETPWUID_R
-                   struct passwd pwx;
+                   struct passwd *pw, pwx;
                    char pwbuf[BUFSIZ];
-#endif
 
                    uid = getuid();
-#ifndef HAVE_GETPWUID_R
-                   pw = getpwuid(uid);
-#elif defined(GETPWUID_R_4_ARGS)
-                   /* earlier POSIX drafts */
-                   pw = getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf));
-#else
-                   /* POSIX */
-                   if (getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf), &pw) != 0)
-                       /* Probably already null, but let's make sure.  */
-                       pw = NULL;
-#endif /* getpwuid variants */
-                   if (pw != NULL && pw->pw_dir[0] != 0)
+                   if (!k5_getpwuid_r(uid, &pwx, pwbuf, sizeof(pwbuf), &pw)
+                       && pw != NULL && pw->pw_dir[0] != 0)
                        home_env = pw->pw_dir;
                }
 #endif