* import_name.c (krb5_gss_import_name) [HAVE_GETPWUID_R]: Use getpwuid_r
authorKen Raeburn <raeburn@mit.edu>
Wed, 7 Jul 2004 00:29:31 +0000 (00:29 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 7 Jul 2004 00:29:31 +0000 (00:29 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16548 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/gssapi/krb5/ChangeLog
src/lib/gssapi/krb5/import_name.c

index 0004e662139308196d7a1c7d38ebe856a7ca7dc6..2b77951aa152d91588284399b5922c3f6f283496 100644 (file)
@@ -1,3 +1,9 @@
+2004-07-06  Ken Raeburn  <raeburn@mit.edu>
+
+       * 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  <tlyu@mit.edu>
 
        * ser_sctx.c (kg_ctx_size, kg_ctx_externalize):
index c9f95857d44ddfff41be2e240602de583d77e8db..ed78b1e258f42a4824b200123acd4e43c0839a72 100644 (file)
@@ -28,6 +28,9 @@
 
 #ifndef NO_PASSWORD
 #include <pwd.h>
+#ifdef HAVE_GETPWUID_R
+#include <stdio.h>
+#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;