From 67623e8db7aef5bbe49bf57614de4892c6baedeb Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 7 Jul 2004 00:29:31 +0000 Subject: [PATCH] * import_name.c (krb5_gss_import_name) [HAVE_GETPWUID_R]: Use getpwuid_r git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16548 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/gssapi/krb5/ChangeLog | 6 ++++++ src/lib/gssapi/krb5/import_name.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/lib/gssapi/krb5/ChangeLog b/src/lib/gssapi/krb5/ChangeLog index 0004e6621..2b77951aa 100644 --- a/src/lib/gssapi/krb5/ChangeLog +++ b/src/lib/gssapi/krb5/ChangeLog @@ -1,3 +1,9 @@ +2004-07-06 Ken Raeburn + + * import_name.c [HAVE_GETPWUID_R]: Include stdio.h. + (krb5_gss_import_name) [HAVE_GETPWUID_R]: Use getpwuid_r instead + of getpwuid, for thread safety. + 2004-06-17 Tom Yu * ser_sctx.c (kg_ctx_size, kg_ctx_externalize): diff --git a/src/lib/gssapi/krb5/import_name.c b/src/lib/gssapi/krb5/import_name.c index c9f95857d..ed78b1e25 100644 --- a/src/lib/gssapi/krb5/import_name.c +++ b/src/lib/gssapi/krb5/import_name.c @@ -28,6 +28,9 @@ #ifndef NO_PASSWORD #include +#ifdef HAVE_GETPWUID_R +#include +#endif #endif #ifdef HAVE_STRING_H @@ -116,6 +119,14 @@ krb5_gss_import_name(minor_status, input_name_buffer, return(GSS_S_FAILURE); } } else { +#ifndef NO_PASSWORD + uid_t uid; +#ifdef HAVE_GETPWUID_R + struct passwd pwx; + char pwbuf[BUFSIZ]; +#endif +#endif + stringrep = NULL; if ((tmp = @@ -135,15 +146,25 @@ krb5_gss_import_name(minor_status, input_name_buffer, stringrep = (char *) tmp; #ifndef NO_PASSWORD } else if (g_OID_equal(input_name_type, gss_nt_machine_uid_name)) { - if ((pw = getpwuid(*((uid_t *) input_name_buffer->value)))) + 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; else *minor_status = (OM_uint32) G_NOUSER; } else if (g_OID_equal(input_name_type, gss_nt_string_uid_name)) { - if ((pw = getpwuid((uid_t) atoi(tmp)))) - stringrep = pw->pw_name; - else - *minor_status = (OM_uint32) G_NOUSER; + uid = atoi(tmp); + goto do_getpwuid; #endif } else if (g_OID_equal(input_name_type, gss_nt_exported_name)) { cp = tmp; -- 2.26.2