2004-04-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 2 Apr 2004 16:27:38 +0000 (16:27 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 2 Apr 2004 16:27:38 +0000 (16:27 -0000)
* config.h.in: added HAVE_GETPWUID_R
* configure.in: check for getpwuid_r.
* mono/io-layer/security.c: use getpwuid_r if available. This one is
thread-safe.

svn path=/trunk/mono/; revision=24977

ChangeLog
config.h.in
configure.in
mono/io-layer/ChangeLog
mono/io-layer/security.c

index 0083a1219a057be4f77ff882839a9a2734272a6b..c6f32ab71160b66b16883f74b431bf8cb89bcd53 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-04-02  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * config.h.in: added HAVE_GETPWUID_R
+       * configure.in: check for getpwuid_r.
+
 2004-03-23  Zoltan Varga  <vargaz@freemail.hu>
 
        * configure.in: Fix GNU ld check.
index 014306c13d43acc2f6513b3bcbf0fbcd18681fc8..7a138672477430eeb04e106930943178961d01d3 100644 (file)
@@ -56,6 +56,9 @@
 /* Define to 1 if you have the <gc.h> header file. */
 #undef HAVE_GC_H
 
+/* Define to 1 if you have the `getpwuid_r' function. */
+#undef HAVE_GETPWUID_R
+
 /* Define to 1 if you have the `inet_aton' function. */
 #undef HAVE_INET_ATON
 
index dfbd3a4fd9cc1a9a726bafb0dcfedf72caad0d59..4ca2eb7fbc88f324ecd41d766c33debe0919a12b 100644 (file)
@@ -322,6 +322,7 @@ dnl End of libgc checks
 dnl
 
 if test x$platform_win32 = xno; then
+       AC_CHECK_FUNCS(getpwuid_r)
        dnl ******************************************************************
        dnl *** Check for large file support                               ***
        dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
index 620c0a53f47198d76ede3e605ee4751269fbaf20..32728266bc54c815579519c147bda061d6c2a044 100644 (file)
@@ -1,3 +1,7 @@
+2004-04-02  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * security.c: use getpwuid_r if available. This one is thread-safe.
+
 2004-04-02  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Makefile.am: Added security.c|h.
index 4f736067d083650e6c108428a3ad44f12f071187..79f2ba34bddc26b5bb9fead6bf748651437a689d 100644 (file)
@@ -7,6 +7,7 @@
  * (C) 2004 Novell (http://www.novell.com)
  */
 
+#include <config.h>
 #include <mono/io-layer/io-layer.h>
 
 #include <pwd.h>
 #include <unistd.h>
 
 
-extern gboolean GetUserName (gchar *buffer, gint32 *size) 
+gboolean
+GetUserName (gchar *buffer, gint32 *size) 
 {
+#ifdef HAVE_GETPWUID_R
+       struct passwd *pbuf;
+       size_t fbufsize;
+       gchar *fbuf;
+#endif
        struct passwd *p;
        uid_t uid;
 
        if (!size) {
                SetLastError (ERROR_INVALID_PARAMETER);
-               return 0;
+               return FALSE;
        }
 
        uid = getuid ();
+#ifdef HAVE_GETPWUID_R
+       fbufsize = (size_t) sysconf (_SC_GETPW_R_SIZE_MAX);
+       fbuf = g_malloc0 (fbufsize);
+       pbuf = g_new0 (struct passwd, 1);
+       getpwuid_r (uid, pbuf, fbuf, fbufsize, &p);
+#else
        p = getpwuid (uid);
+#endif
        if (p) {
                gint32 sz = strlen (p->pw_name);
                if (buffer) {
@@ -35,12 +49,15 @@ extern gboolean GetUserName (gchar *buffer, gint32 *size)
                        strncpy (buffer, p->pw_name, sz);
                }
                *size = sz;
-               return 1;
+               return TRUE;
        }
 
-       // note: getpwuid return static data - no free here
+#ifdef HAVE_GETPWUID_R
+       g_free (pbuf);
+       g_free (fbuf);
+#endif
        *size = 0;
        SetLastError (ERROR_INVALID_HANDLE);
-       return 0;
+       return FALSE;
 }