Commit e7125f4e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use getpwuid_r - thread safety

parent 04a4af73
...@@ -464,7 +464,7 @@ dnl Check for system libs needed ...@@ -464,7 +464,7 @@ dnl Check for system libs needed
need_libc=false need_libc=false
dnl Check for usual libc functions dnl Check for usual libc functions
AC_CHECK_FUNCS([gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy strdup strndup strnlen atof lldiv posix_fadvise posix_madvise]) AC_CHECK_FUNCS([gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid_r memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy strdup strndup strnlen atof lldiv posix_fadvise posix_madvise])
AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)]) AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)])
AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)]) AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)])
AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)]) AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)])
......
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
# include <unistd.h> /* getuid() */ # include <unistd.h> /* getuid() */
#endif #endif
#if defined(HAVE_GETPWUID) #if defined(HAVE_GETPWUID_R)
# include <pwd.h> /* getpwuid() */ # include <pwd.h>
#endif #endif
#if defined( HAVE_SYS_STAT_H ) #if defined( HAVE_SYS_STAT_H )
...@@ -617,13 +617,6 @@ const char *config_GetDataDir( void ) ...@@ -617,13 +617,6 @@ const char *config_GetDataDir( void )
#endif #endif
} }
/*****************************************************************************
* config_GetHomeDir, config_GetUserDir: find the user's home directory.
*****************************************************************************
* This function will try by different ways to find the user's home path.
* Note that this function is not reentrant, it should be called only once
* at the beginning of main where the result will be stored for later use.
*****************************************************************************/
static char *GetDir( bool b_appdata ) static char *GetDir( bool b_appdata )
{ {
const char *psz_localhome = NULL; const char *psz_localhome = NULL;
...@@ -671,7 +664,7 @@ static char *GetDir( bool b_appdata ) ...@@ -671,7 +664,7 @@ static char *GetDir( bool b_appdata )
} }
#elif defined(UNDER_CE) #elif defined(UNDER_CE)
(void)b_appdata;
#ifndef CSIDL_APPDATA #ifndef CSIDL_APPDATA
# define CSIDL_APPDATA 0x1A # define CSIDL_APPDATA 0x1A
#endif #endif
...@@ -681,25 +674,25 @@ static char *GetDir( bool b_appdata ) ...@@ -681,25 +674,25 @@ static char *GetDir( bool b_appdata )
/* get the "Application Data" folder for the current user */ /* get the "Application Data" folder for the current user */
if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) ) if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
return FromWide( whomedir ); return FromWide( whomedir );
#else
(void)b_appdata;
#endif #endif
psz_localhome = getenv( "HOME" ); psz_localhome = getenv( "HOME" );
#if defined(HAVE_GETPWUID_R)
char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
if( psz_localhome == NULL ) if( psz_localhome == NULL )
{ {
#if defined(HAVE_GETPWUID) struct passwd pw, *res;
struct passwd *p_pw;
(void)b_appdata;
if( ( p_pw = getpwuid( getuid() ) ) != NULL ) if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
psz_localhome = p_pw->pw_dir; psz_localhome = pw.pw_dir;
else
#endif
{
psz_localhome = getenv( "TMP" );
if( psz_localhome == NULL )
psz_localhome = "/tmp";
}
} }
#endif
if (psz_localhome == NULL)
psz_localhome = getenv( "TMP" );
if (psz_localhome == NULL)
psz_localhome = "/tmp";
return FromLocaleDup( psz_localhome ); return FromLocaleDup( psz_localhome );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment