diff options
author | Matt Caswell <matt@openssl.org> | 2016-06-15 11:14:30 -0400 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-06-17 17:26:18 +0100 |
commit | 13c03c8d6da334bb1cde6ce4133e7c75b3b76947 (patch) | |
tree | 488a74f29a2db17f65502eac3b59926b2e4970c9 /crypto/rand/randfile.c | |
parent | 4813ad2d245cbf7fed2898d173eaa9e2a00e3e23 (diff) |
Change default directory for storing the .rnd file on Windows
Previously we would try %RANDFILE%, then %HOME% and finally "C:".
Unfortunately this often ends up being "C:" which the user may not
have write permission for.
Now we try %RANDFILE% first, and then the same set of environment vars
as GetTempFile() uses, i.e. %TMP%, then %TEMP%, %USERPROFILE% and
%SYSTEMROOT%. If all else fails we fall back to %HOME% and only then "C:".
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/rand/randfile.c')
-rw-r--r-- | crypto/rand/randfile.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index 49f5405dbc..19cce2c7a8 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -286,8 +286,22 @@ const char *RAND_file_name(char *buf, size_t size) if (OPENSSL_strlcpy(buf, s, size) >= size) return NULL; } else { +#ifdef OPENSSL_SYS_WINDOWS + /* + * We use the same env variables as GetTempFile() - but that function + * uses TCHARs, but getenv() gives us chars so its easier to do it this + * way + */ + if ((s = getenv("TMP")) == NULL + && (s = getenv("TEMP")) == NULL + && (s = getenv("USERPROFILE")) == NULL + && (s = getenv("SYSTEMROOT")) == NULL) { + s = getenv("HOME"); + } +#else if (OPENSSL_issetugid() == 0) s = getenv("HOME"); +#endif #ifdef DEFAULT_HOME if (s == NULL) { s = DEFAULT_HOME; |