diff options
Diffstat (limited to 'src/lib/libcrypto/rand/randfile.c')
-rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index f5d0843d13..cfbec2ac1f 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -56,9 +56,6 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | /* We need to define this to get macros like S_IFBLK and S_IFCHR */ | ||
60 | #define _XOPEN_SOURCE 1 | ||
61 | |||
62 | #include <errno.h> | 59 | #include <errno.h> |
63 | #include <stdio.h> | 60 | #include <stdio.h> |
64 | #include <stdlib.h> | 61 | #include <stdlib.h> |
@@ -67,7 +64,6 @@ | |||
67 | #include "e_os.h" | 64 | #include "e_os.h" |
68 | #include <openssl/crypto.h> | 65 | #include <openssl/crypto.h> |
69 | #include <openssl/rand.h> | 66 | #include <openssl/rand.h> |
70 | #include <openssl/buffer.h> | ||
71 | 67 | ||
72 | #ifdef OPENSSL_SYS_VMS | 68 | #ifdef OPENSSL_SYS_VMS |
73 | #include <unixio.h> | 69 | #include <unixio.h> |
@@ -110,7 +106,6 @@ int RAND_load_file(const char *file, long bytes) | |||
110 | 106 | ||
111 | in=fopen(file,"rb"); | 107 | in=fopen(file,"rb"); |
112 | if (in == NULL) goto err; | 108 | if (in == NULL) goto err; |
113 | #if defined(S_IFBLK) && defined(S_IFCHR) | ||
114 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | 109 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { |
115 | /* this file is a device. we don't want read an infinite number | 110 | /* this file is a device. we don't want read an infinite number |
116 | * of bytes from a random device, nor do we want to use buffered | 111 | * of bytes from a random device, nor do we want to use buffered |
@@ -119,7 +114,6 @@ int RAND_load_file(const char *file, long bytes) | |||
119 | bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */ | 114 | bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */ |
120 | setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */ | 115 | setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */ |
121 | } | 116 | } |
122 | #endif | ||
123 | for (;;) | 117 | for (;;) |
124 | { | 118 | { |
125 | if (bytes > 0) | 119 | if (bytes > 0) |
@@ -153,7 +147,6 @@ int RAND_write_file(const char *file) | |||
153 | 147 | ||
154 | i=stat(file,&sb); | 148 | i=stat(file,&sb); |
155 | if (i != -1) { | 149 | if (i != -1) { |
156 | #if defined(S_IFBLK) && defined(S_IFCHR) | ||
157 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | 150 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { |
158 | /* this file is a device. we don't write back to it. | 151 | /* this file is a device. we don't write back to it. |
159 | * we "succeed" on the assumption this is some sort | 152 | * we "succeed" on the assumption this is some sort |
@@ -162,7 +155,6 @@ int RAND_write_file(const char *file) | |||
162 | */ | 155 | */ |
163 | return(1); | 156 | return(1); |
164 | } | 157 | } |
165 | #endif | ||
166 | } | 158 | } |
167 | 159 | ||
168 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) | 160 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) |
@@ -227,20 +219,18 @@ const char *RAND_file_name(char *buf, size_t size) | |||
227 | { | 219 | { |
228 | char *s=NULL; | 220 | char *s=NULL; |
229 | int ok = 0; | 221 | int ok = 0; |
230 | #ifdef __OpenBSD__ | ||
231 | struct stat sb; | 222 | struct stat sb; |
232 | #endif | ||
233 | 223 | ||
234 | if (OPENSSL_issetugid() == 0) | 224 | if (issetugid() == 0) |
235 | s=getenv("RANDFILE"); | 225 | s=getenv("RANDFILE"); |
236 | if (s != NULL && *s && strlen(s) + 1 < size) | 226 | if (s != NULL && *s && strlen(s) + 1 < size) |
237 | { | 227 | { |
238 | if (BUF_strlcpy(buf,s,size) >= size) | 228 | if (strlcpy(buf,s,size) >= size) |
239 | return NULL; | 229 | return NULL; |
240 | } | 230 | } |
241 | else | 231 | else |
242 | { | 232 | { |
243 | if (OPENSSL_issetugid() == 0) | 233 | if (issetugid() == 0) |
244 | s=getenv("HOME"); | 234 | s=getenv("HOME"); |
245 | #ifdef DEFAULT_HOME | 235 | #ifdef DEFAULT_HOME |
246 | if (s == NULL) | 236 | if (s == NULL) |
@@ -250,11 +240,11 @@ const char *RAND_file_name(char *buf, size_t size) | |||
250 | #endif | 240 | #endif |
251 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) | 241 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) |
252 | { | 242 | { |
253 | BUF_strlcpy(buf,s,size); | 243 | strlcpy(buf,s,size); |
254 | #ifndef OPENSSL_SYS_VMS | 244 | #ifndef OPENSSL_SYS_VMS |
255 | BUF_strlcat(buf,"/",size); | 245 | strlcat(buf,"/",size); |
256 | #endif | 246 | #endif |
257 | BUF_strlcat(buf,RFILE,size); | 247 | strlcat(buf,RFILE,size); |
258 | ok = 1; | 248 | ok = 1; |
259 | } | 249 | } |
260 | else | 250 | else |
@@ -270,11 +260,11 @@ const char *RAND_file_name(char *buf, size_t size) | |||
270 | */ | 260 | */ |
271 | 261 | ||
272 | if (!ok) | 262 | if (!ok) |
273 | if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { | 263 | if (strlcpy(buf,"/dev/arandom",size) >= size) { |
274 | return(NULL); | 264 | return(NULL); |
275 | } | 265 | } |
276 | if (stat(buf,&sb) == -1) | 266 | if (stat(buf,&sb) == -1) |
277 | if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { | 267 | if (strlcpy(buf,"/dev/arandom",size) >= size) { |
278 | return(NULL); | 268 | return(NULL); |
279 | } | 269 | } |
280 | 270 | ||