Windows: RAND_file_name() should look up profile path
If RANDFILE and HOME environment variables aren't defined, failover to looking up the user's profile path. In particular, default to a file named .rnd in the user's local (non-roamin) application data directory.
This commit is contained in:
@@ -46,6 +46,10 @@
|
|||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include<shlobj.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @page page_rand RAND - random number
|
* @page page_rand RAND - random number
|
||||||
*
|
*
|
||||||
@@ -352,6 +356,8 @@ RAND_file_name(char *filename, size_t size)
|
|||||||
if (e)
|
if (e)
|
||||||
pathp = 1;
|
pathp = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
/*
|
/*
|
||||||
* Here we really want to call getpwuid(getuid()) but this will
|
* Here we really want to call getpwuid(getuid()) but this will
|
||||||
* cause recursive lookups if the nss library uses
|
* cause recursive lookups if the nss library uses
|
||||||
@@ -359,7 +365,6 @@ RAND_file_name(char *filename, size_t size)
|
|||||||
*
|
*
|
||||||
* So at least return the unix /dev/random if we have one
|
* So at least return the unix /dev/random if we have one
|
||||||
*/
|
*/
|
||||||
#ifndef _WIN32
|
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@@ -367,7 +372,22 @@ RAND_file_name(char *filename, size_t size)
|
|||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
#else /* Win32 */
|
||||||
|
|
||||||
|
if (e == NULL) {
|
||||||
|
char profile[MAX_PATH];
|
||||||
|
|
||||||
|
if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
|
||||||
|
SHGFP_TYPE_CURRENT, profile) == S_OK) {
|
||||||
|
ret = snprintf(filename, size, "%s\\.rnd", profile);
|
||||||
|
|
||||||
|
if (ret > 0 && ret < size)
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (e == NULL)
|
if (e == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user