+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.
/* 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
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) ***
+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.
* (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) {
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;
}