diff options
| author | beck <> | 2000-04-15 06:18:51 +0000 |
|---|---|---|
| committer | beck <> | 2000-04-15 06:18:51 +0000 |
| commit | b608c7f2b175e121f2c22d53341a317153afdc8e (patch) | |
| tree | e94b160b3fcd8180df79e4251d68d24d665f0195 /src/lib/libcrypto/rand/randfile.c | |
| parent | c8d6701c396cebdcd0d45eac73b762e9498f6b01 (diff) | |
| download | openbsd-b608c7f2b175e121f2c22d53341a317153afdc8e.tar.gz openbsd-b608c7f2b175e121f2c22d53341a317153afdc8e.tar.bz2 openbsd-b608c7f2b175e121f2c22d53341a317153afdc8e.zip | |
OpenSSL 0.9.5a merge
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index 658a8d6b65..9ff3974cc7 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
| @@ -133,35 +133,20 @@ int RAND_write_file(const char *file) | |||
| 133 | int i,ret=0,err=0; | 133 | int i,ret=0,err=0; |
| 134 | FILE *out = NULL; | 134 | FILE *out = NULL; |
| 135 | int n; | 135 | int n; |
| 136 | 136 | ||
| 137 | #ifdef VMS | 137 | #if defined(O_CREAT) && defined(O_EXCL) && !defined(WIN32) |
| 138 | /* Under VMS, fopen(file, "wb") will create a new version of the | 138 | /* For some reason Win32 can't write to files created this way */ |
| 139 | same file. This is not good, so let's try updating an existing | 139 | |
| 140 | one, and create file only if it doesn't already exist. */ | 140 | /* chmod(..., 0600) is too late to protect the file, |
| 141 | /* At the same time, if we just update a file, we also need to | 141 | * permissions should be restrictive from the start */ |
| 142 | truncate it, and unfortunately, ftruncate() and truncate() do | 142 | int fd = open(file, O_CREAT | O_EXCL, 0600); |
| 143 | not exist everywhere. All that remains is to delete old versions | 143 | if (fd != -1) |
| 144 | of the random data file (done at the end). */ | 144 | out = fdopen(fd, "wb"); |
| 145 | #if 0 | ||
| 146 | out=fopen(file,"rb+"); | ||
| 147 | if (out == NULL && errno != ENOENT) | ||
| 148 | goto err; | ||
| 149 | #endif | ||
| 150 | #endif | 145 | #endif |
| 146 | if (out == NULL) | ||
| 147 | out = fopen(file,"wb"); | ||
| 148 | if (out == NULL) goto err; | ||
| 151 | 149 | ||
| 152 | if (out == NULL) | ||
| 153 | { | ||
| 154 | #if defined O_CREAT && defined O_EXCL | ||
| 155 | /* chmod(..., 0600) is too late to protect the file, | ||
| 156 | * permissions should be restrictive from the start */ | ||
| 157 | int fd = open(file, O_CREAT | O_EXCL, 0600); | ||
| 158 | if (fd != -1) | ||
| 159 | out = fdopen(fd, "wb"); | ||
| 160 | #else | ||
| 161 | out=fopen(file,"wb"); | ||
| 162 | #endif | ||
| 163 | } | ||
| 164 | if (out == NULL) goto err; | ||
| 165 | #ifndef NO_CHMOD | 150 | #ifndef NO_CHMOD |
| 166 | chmod(file,0600); | 151 | chmod(file,0600); |
| 167 | #endif | 152 | #endif |
| @@ -180,14 +165,8 @@ int RAND_write_file(const char *file) | |||
| 180 | } | 165 | } |
| 181 | ret+=i; | 166 | ret+=i; |
| 182 | if (n <= 0) break; | 167 | if (n <= 0) break; |
| 183 | } | 168 | } |
| 184 | #ifdef VMS | 169 | #ifdef VMS |
| 185 | /* We may have updated an existing file using mode "rb+", | ||
| 186 | * now remove any old extra bytes */ | ||
| 187 | #if 0 | ||
| 188 | if (ret > 0) | ||
| 189 | ftruncate(fileno(out), ret); | ||
| 190 | #else | ||
| 191 | /* Try to delete older versions of the file, until there aren't | 170 | /* Try to delete older versions of the file, until there aren't |
| 192 | any */ | 171 | any */ |
| 193 | { | 172 | { |
| @@ -205,8 +184,7 @@ int RAND_write_file(const char *file) | |||
| 205 | some point... */ | 184 | some point... */ |
| 206 | } | 185 | } |
| 207 | } | 186 | } |
| 208 | #endif | 187 | #endif /* VMS */ |
| 209 | #endif | ||
| 210 | 188 | ||
| 211 | fclose(out); | 189 | fclose(out); |
| 212 | memset(buf,0,BUFSIZE); | 190 | memset(buf,0,BUFSIZE); |
