From a7c020a0e088b1df83a7787ee6c265506002df31 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 18 Jul 2005 22:12:43 +0000 Subject: [PATCH] pullup from trunk 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 --- src/ChangeLog | 6 ++++ src/configure.in | 6 +++- src/include/ChangeLog | 7 ++++ src/include/configure.in | 45 ++++++++++++++++-------- src/include/k5-platform.h | 57 +++++++++++++++++++++++++++++++ src/lib/gssapi/krb5/ChangeLog | 4 +++ src/lib/gssapi/krb5/import_name.c | 16 ++------- src/lib/krb5/os/ChangeLog | 4 +++ src/lib/krb5/os/kuserok.c | 14 +------- src/util/profile/ChangeLog | 5 +++ src/util/profile/configure.in | 2 +- src/util/profile/prof_file.c | 19 ++--------- 12 files changed, 126 insertions(+), 59 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e053ae05d..30d0277a4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2005-03-25 Ken Raeburn + + * 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 * aclocal.m4 (AC_LIBRARY_NET): Also check for res_ndestroy. diff --git a/src/configure.in b/src/configure.in index fc567f298..26c48d3f0 100644 --- a/src/configure.in +++ b/src/configure.in @@ -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="" diff --git a/src/include/ChangeLog b/src/include/ChangeLog index 73aa7922b..1246894e4 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -5,6 +5,13 @@ 2005-03-25 Ken Raeburn + * 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 diff --git a/src/include/configure.in b/src/include/configure.in index 450eea556..74b3986bc 100644 --- a/src/include/configure.in +++ b/src/include/configure.in @@ -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 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 + 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 - 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 diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index b178622d8..8a88cacf3 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -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 */ diff --git a/src/lib/gssapi/krb5/ChangeLog b/src/lib/gssapi/krb5/ChangeLog index edcd9a2fe..eddec9724 100644 --- a/src/lib/gssapi/krb5/ChangeLog +++ b/src/lib/gssapi/krb5/ChangeLog @@ -3,6 +3,10 @@ * Makefile.in (gssapi_krb5.h): Use awk hack to work around quoting problem. +2005-03-25 Ken Raeburn + + * import_name.c (krb5_gss_import_name): Use k5_getpwuid_r. + 2005-01-13 Jeffrey Altman * init_sec_context.c, acquire_cred.c: fix calls to diff --git a/src/lib/gssapi/krb5/import_name.c b/src/lib/gssapi/krb5/import_name.c index ed78b1e25..7969cca3a 100644 --- a/src/lib/gssapi/krb5/import_name.c +++ b/src/lib/gssapi/krb5/import_name.c @@ -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)) { diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index d3e7a8595..78679a84e 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -6,6 +6,10 @@ reference counter if they have been previously called within the application. +2005-03-25 Ken Raeburn + + * kuserok.c (krb5_kuserok): Use k5_getpwnam_r. + 2005-03-22 Tom Yu * dnsglue.h: Define ns_rr_class to ns_rr_cl if ns_rr_class doesn't diff --git a/src/lib/krb5/os/kuserok.c b/src/lib/krb5/os/kuserok.c index c0111b995..356b98706 100644 --- a/src/lib/krb5/os/kuserok.c +++ b/src/lib/krb5/os/kuserok.c @@ -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'; diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index 1c9a04f37..91cbc657e 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,8 @@ +2005-03-25 Ken Raeburn + + * configure.in: Don't check for getpwuid_r here. + * prof_file.c (profile_open_file): Use k5_getpwuid_r. + 2005-03-03 Ken Raeburn * prof_tree.c (profile_node_iterator): After checking skip_num diff --git a/src/util/profile/configure.in b/src/util/profile/configure.in index 38fb9e426..680a69594 100644 --- a/src/util/profile/configure.in +++ b/src/util/profile/configure.in @@ -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= diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index af298816d..5d69fa6fb 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -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 -- 2.26.2