diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_file.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 68 |
1 files changed, 13 insertions, 55 deletions
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 59e48e6659..c92c4753aa 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -86,7 +86,7 @@ | |||
86 | #include <stdio.h> | 86 | #include <stdio.h> |
87 | #include <errno.h> | 87 | #include <errno.h> |
88 | #include "cryptlib.h" | 88 | #include "cryptlib.h" |
89 | #include "bio_lcl.h" | 89 | #include <openssl/bio.h> |
90 | #include <openssl/err.h> | 90 | #include <openssl/err.h> |
91 | 91 | ||
92 | #if !defined(OPENSSL_NO_STDIO) | 92 | #if !defined(OPENSSL_NO_STDIO) |
@@ -134,7 +134,6 @@ BIO | |||
134 | return (NULL); | 134 | return (NULL); |
135 | } | 135 | } |
136 | 136 | ||
137 | BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | ||
138 | BIO_set_fp(ret, file, BIO_CLOSE); | 137 | BIO_set_fp(ret, file, BIO_CLOSE); |
139 | return (ret); | 138 | return (ret); |
140 | } | 139 | } |
@@ -147,7 +146,6 @@ BIO | |||
147 | if ((ret = BIO_new(BIO_s_file())) == NULL) | 146 | if ((ret = BIO_new(BIO_s_file())) == NULL) |
148 | return (NULL); | 147 | return (NULL); |
149 | 148 | ||
150 | BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ | ||
151 | BIO_set_fp(ret, stream, close_flag); | 149 | BIO_set_fp(ret, stream, close_flag); |
152 | return (ret); | 150 | return (ret); |
153 | } | 151 | } |
@@ -164,7 +162,7 @@ file_new(BIO *bi) | |||
164 | bi->init = 0; | 162 | bi->init = 0; |
165 | bi->num = 0; | 163 | bi->num = 0; |
166 | bi->ptr = NULL; | 164 | bi->ptr = NULL; |
167 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ | 165 | bi->flags=0; |
168 | return (1); | 166 | return (1); |
169 | } | 167 | } |
170 | 168 | ||
@@ -175,12 +173,9 @@ file_free(BIO *a) | |||
175 | return (0); | 173 | return (0); |
176 | if (a->shutdown) { | 174 | if (a->shutdown) { |
177 | if ((a->init) && (a->ptr != NULL)) { | 175 | if ((a->init) && (a->ptr != NULL)) { |
178 | if (a->flags&BIO_FLAGS_UPLINK) | 176 | fclose (a->ptr); |
179 | UP_fclose (a->ptr); | ||
180 | else | ||
181 | fclose (a->ptr); | ||
182 | a->ptr = NULL; | 177 | a->ptr = NULL; |
183 | a->flags = BIO_FLAGS_UPLINK; | 178 | a->flags = 0; |
184 | } | 179 | } |
185 | a->init = 0; | 180 | a->init = 0; |
186 | } | 181 | } |
@@ -193,12 +188,8 @@ file_read(BIO *b, char *out, int outl) | |||
193 | int ret = 0; | 188 | int ret = 0; |
194 | 189 | ||
195 | if (b->init && (out != NULL)) { | 190 | if (b->init && (out != NULL)) { |
196 | if (b->flags&BIO_FLAGS_UPLINK) | 191 | ret = fread(out, 1,(int)outl,(FILE *)b->ptr); |
197 | ret = UP_fread(out, 1,(int)outl, b->ptr); | 192 | if (ret == 0 && ferror((FILE *)b->ptr)) { |
198 | else | ||
199 | ret = fread(out, 1,(int)outl,(FILE *)b->ptr); | ||
200 | if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ? | ||
201 | UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) { | ||
202 | SYSerr(SYS_F_FREAD, errno); | 193 | SYSerr(SYS_F_FREAD, errno); |
203 | BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); | 194 | BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); |
204 | ret = -1; | 195 | ret = -1; |
@@ -213,10 +204,7 @@ file_write(BIO *b, const char *in, int inl) | |||
213 | int ret = 0; | 204 | int ret = 0; |
214 | 205 | ||
215 | if (b->init && (in != NULL)) { | 206 | if (b->init && (in != NULL)) { |
216 | if (b->flags&BIO_FLAGS_UPLINK) | 207 | ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); |
217 | ret = UP_fwrite(in,(int)inl, 1, b->ptr); | ||
218 | else | ||
219 | ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); | ||
220 | if (ret) | 208 | if (ret) |
221 | ret = inl; | 209 | ret = inl; |
222 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | 210 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ |
@@ -238,41 +226,20 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
238 | switch (cmd) { | 226 | switch (cmd) { |
239 | case BIO_C_FILE_SEEK: | 227 | case BIO_C_FILE_SEEK: |
240 | case BIO_CTRL_RESET: | 228 | case BIO_CTRL_RESET: |
241 | if (b->flags&BIO_FLAGS_UPLINK) | 229 | ret = (long)fseek(fp, num, 0); |
242 | ret = (long)UP_fseek(b->ptr, num, 0); | ||
243 | else | ||
244 | ret = (long)fseek(fp, num, 0); | ||
245 | break; | 230 | break; |
246 | case BIO_CTRL_EOF: | 231 | case BIO_CTRL_EOF: |
247 | if (b->flags&BIO_FLAGS_UPLINK) | 232 | ret = (long)feof(fp); |
248 | ret = (long)UP_feof(fp); | ||
249 | else | ||
250 | ret = (long)feof(fp); | ||
251 | break; | 233 | break; |
252 | case BIO_C_FILE_TELL: | 234 | case BIO_C_FILE_TELL: |
253 | case BIO_CTRL_INFO: | 235 | case BIO_CTRL_INFO: |
254 | if (b->flags&BIO_FLAGS_UPLINK) | 236 | ret = ftell(fp); |
255 | ret = UP_ftell(b->ptr); | ||
256 | else | ||
257 | ret = ftell(fp); | ||
258 | break; | 237 | break; |
259 | case BIO_C_SET_FILE_PTR: | 238 | case BIO_C_SET_FILE_PTR: |
260 | file_free(b); | 239 | file_free(b); |
261 | b->shutdown = (int)num&BIO_CLOSE; | 240 | b->shutdown = (int)num&BIO_CLOSE; |
262 | b->ptr = ptr; | 241 | b->ptr = ptr; |
263 | b->init = 1; | 242 | b->init = 1; |
264 | #if BIO_FLAGS_UPLINK!=0 | ||
265 | #if defined(_IOB_ENTRIES) | ||
266 | /* Safety net to catch purely internal BIO_set_fp calls */ | ||
267 | if ((size_t)ptr >= (size_t)stdin && | ||
268 | (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) | ||
269 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); | ||
270 | #endif | ||
271 | #endif | ||
272 | #ifdef UP_fsetmod | ||
273 | if (b->flags&BIO_FLAGS_UPLINK) | ||
274 | UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b')); | ||
275 | #endif | ||
276 | break; | 243 | break; |
277 | case BIO_C_SET_FILENAME: | 244 | case BIO_C_SET_FILENAME: |
278 | file_free(b); | 245 | file_free(b); |
@@ -302,7 +269,6 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
302 | } | 269 | } |
303 | b->ptr = fp; | 270 | b->ptr = fp; |
304 | b->init = 1; | 271 | b->init = 1; |
305 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | ||
306 | break; | 272 | break; |
307 | case BIO_C_GET_FILE_PTR: | 273 | case BIO_C_GET_FILE_PTR: |
308 | /* the ptr parameter is actually a FILE ** in this case. */ | 274 | /* the ptr parameter is actually a FILE ** in this case. */ |
@@ -318,10 +284,7 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
318 | b->shutdown = (int)num; | 284 | b->shutdown = (int)num; |
319 | break; | 285 | break; |
320 | case BIO_CTRL_FLUSH: | 286 | case BIO_CTRL_FLUSH: |
321 | if (b->flags&BIO_FLAGS_UPLINK) | 287 | fflush((FILE *)b->ptr); |
322 | UP_fflush(b->ptr); | ||
323 | else | ||
324 | fflush((FILE *)b->ptr); | ||
325 | break; | 288 | break; |
326 | case BIO_CTRL_DUP: | 289 | case BIO_CTRL_DUP: |
327 | ret = 1; | 290 | ret = 1; |
@@ -344,13 +307,8 @@ file_gets(BIO *bp, char *buf, int size) | |||
344 | int ret = 0; | 307 | int ret = 0; |
345 | 308 | ||
346 | buf[0] = '\0'; | 309 | buf[0] = '\0'; |
347 | if (bp->flags&BIO_FLAGS_UPLINK) { | 310 | if (!fgets(buf, size,(FILE *)bp->ptr)) |
348 | if (!UP_fgets(buf, size, bp->ptr)) | 311 | goto err; |
349 | goto err; | ||
350 | } else { | ||
351 | if (!fgets(buf, size,(FILE *)bp->ptr)) | ||
352 | goto err; | ||
353 | } | ||
354 | if (buf[0] != '\0') | 312 | if (buf[0] != '\0') |
355 | ret = strlen(buf); | 313 | ret = strlen(buf); |
356 | err: | 314 | err: |