diff options
author | djm <> | 2009-01-09 12:15:52 +0000 |
---|---|---|
committer | djm <> | 2009-01-09 12:15:52 +0000 |
commit | 23f8d96f0f508b8bef2602049feee9c44228d34c (patch) | |
tree | a2a7787bc00e8f6a29153b8c6d9eb5e8f73d6269 /src/lib/libcrypto/rand/randfile.c | |
parent | 30562050421d947c3eb3c10edde6e87730b17471 (diff) | |
download | openbsd-23f8d96f0f508b8bef2602049feee9c44228d34c.tar.gz openbsd-23f8d96f0f508b8bef2602049feee9c44228d34c.tar.bz2 openbsd-23f8d96f0f508b8bef2602049feee9c44228d34c.zip |
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/rand/randfile.c')
-rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index 005cb38cb0..f63fbc1731 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -81,10 +81,25 @@ | |||
81 | # include <sys/stat.h> | 81 | # include <sys/stat.h> |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | #ifdef _WIN32 | ||
85 | #define stat _stat | ||
86 | #define chmod _chmod | ||
87 | #define open _open | ||
88 | #define fdopen _fdopen | ||
89 | #endif | ||
90 | |||
84 | #undef BUFSIZE | 91 | #undef BUFSIZE |
85 | #define BUFSIZE 1024 | 92 | #define BUFSIZE 1024 |
86 | #define RAND_DATA 1024 | 93 | #define RAND_DATA 1024 |
87 | 94 | ||
95 | #ifdef OPENSSL_SYS_VMS | ||
96 | /* This declaration is a nasty hack to get around vms' extension to fopen | ||
97 | * for passing in sharing options being disabled by our /STANDARD=ANSI89 */ | ||
98 | static FILE *(*const vms_fopen)(const char *, const char *, ...) = | ||
99 | (FILE *(*)(const char *, const char *, ...))fopen; | ||
100 | #define VMS_OPEN_ATTRS "shr=get,put,upd,del","ctx=bin,stm","rfm=stm","rat=none","mrs=0" | ||
101 | #endif | ||
102 | |||
88 | /* #define RFILE ".rnd" - defined in ../../e_os.h */ | 103 | /* #define RFILE ".rnd" - defined in ../../e_os.h */ |
89 | 104 | ||
90 | /* Note that these functions are intended for seed files only. | 105 | /* Note that these functions are intended for seed files only. |
@@ -106,7 +121,11 @@ int RAND_load_file(const char *file, long bytes) | |||
106 | RAND_add(&sb,sizeof(sb),0.0); | 121 | RAND_add(&sb,sizeof(sb),0.0); |
107 | if (bytes == 0) return(ret); | 122 | if (bytes == 0) return(ret); |
108 | 123 | ||
124 | #ifdef OPENSSL_SYS_VMS | ||
125 | in=vms_fopen(file,"rb",VMS_OPEN_ATTRS); | ||
126 | #else | ||
109 | in=fopen(file,"rb"); | 127 | in=fopen(file,"rb"); |
128 | #endif | ||
110 | if (in == NULL) goto err; | 129 | if (in == NULL) goto err; |
111 | #if defined(S_IFBLK) && defined(S_IFCHR) | 130 | #if defined(S_IFBLK) && defined(S_IFCHR) |
112 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | 131 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { |
@@ -167,7 +186,7 @@ int RAND_write_file(const char *file) | |||
167 | #endif | 186 | #endif |
168 | } | 187 | } |
169 | 188 | ||
170 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) | 189 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) |
171 | { | 190 | { |
172 | /* For some reason Win32 can't write to files created this way */ | 191 | /* For some reason Win32 can't write to files created this way */ |
173 | 192 | ||
@@ -178,8 +197,34 @@ int RAND_write_file(const char *file) | |||
178 | out = fdopen(fd, "wb"); | 197 | out = fdopen(fd, "wb"); |
179 | } | 198 | } |
180 | #endif | 199 | #endif |
200 | |||
201 | #ifdef OPENSSL_SYS_VMS | ||
202 | /* VMS NOTE: Prior versions of this routine created a _new_ | ||
203 | * version of the rand file for each call into this routine, then | ||
204 | * deleted all existing versions named ;-1, and finally renamed | ||
205 | * the current version as ';1'. Under concurrent usage, this | ||
206 | * resulted in an RMS race condition in rename() which could | ||
207 | * orphan files (see vms message help for RMS$_REENT). With the | ||
208 | * fopen() calls below, openssl/VMS now shares the top-level | ||
209 | * version of the rand file. Note that there may still be | ||
210 | * conditions where the top-level rand file is locked. If so, this | ||
211 | * code will then create a new version of the rand file. Without | ||
212 | * the delete and rename code, this can result in ascending file | ||
213 | * versions that stop at version 32767, and this routine will then | ||
214 | * return an error. The remedy for this is to recode the calling | ||
215 | * application to avoid concurrent use of the rand file, or | ||
216 | * synchronize usage at the application level. Also consider | ||
217 | * whether or not you NEED a persistent rand file in a concurrent | ||
218 | * use situation. | ||
219 | */ | ||
220 | |||
221 | out = vms_fopen(file,"rb+",VMS_OPEN_ATTRS); | ||
222 | if (out == NULL) | ||
223 | out = vms_fopen(file,"wb",VMS_OPEN_ATTRS); | ||
224 | #else | ||
181 | if (out == NULL) | 225 | if (out == NULL) |
182 | out = fopen(file,"wb"); | 226 | out = fopen(file,"wb"); |
227 | #endif | ||
183 | if (out == NULL) goto err; | 228 | if (out == NULL) goto err; |
184 | 229 | ||
185 | #ifndef NO_CHMOD | 230 | #ifndef NO_CHMOD |
@@ -201,25 +246,6 @@ int RAND_write_file(const char *file) | |||
201 | ret+=i; | 246 | ret+=i; |
202 | if (n <= 0) break; | 247 | if (n <= 0) break; |
203 | } | 248 | } |
204 | #ifdef OPENSSL_SYS_VMS | ||
205 | /* Try to delete older versions of the file, until there aren't | ||
206 | any */ | ||
207 | { | ||
208 | char *tmpf; | ||
209 | |||
210 | tmpf = OPENSSL_malloc(strlen(file) + 4); /* to add ";-1" and a nul */ | ||
211 | if (tmpf) | ||
212 | { | ||
213 | strcpy(tmpf, file); | ||
214 | strcat(tmpf, ";-1"); | ||
215 | while(delete(tmpf) == 0) | ||
216 | ; | ||
217 | rename(file,";1"); /* Make sure it's version 1, or we | ||
218 | will reach the limit (32767) at | ||
219 | some point... */ | ||
220 | } | ||
221 | } | ||
222 | #endif /* OPENSSL_SYS_VMS */ | ||
223 | 249 | ||
224 | fclose(out); | 250 | fclose(out); |
225 | OPENSSL_cleanse(buf,BUFSIZE); | 251 | OPENSSL_cleanse(buf,BUFSIZE); |