diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bio_lib.c')
-rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 147 |
1 files changed, 62 insertions, 85 deletions
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 7a66b0892e..b72688ea90 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
@@ -58,16 +58,15 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <errno.h> | 60 | #include <errno.h> |
61 | #include "crypto.h" | 61 | #include <openssl/crypto.h> |
62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
63 | #include "bio.h" | 63 | #include <openssl/bio.h> |
64 | #include "stack.h" | 64 | #include <openssl/stack.h> |
65 | 65 | ||
66 | static STACK *bio_meth=NULL; | 66 | static STACK *bio_meth=NULL; |
67 | static int bio_meth_num=0; | 67 | static int bio_meth_num=0; |
68 | 68 | ||
69 | BIO *BIO_new(method) | 69 | BIO *BIO_new(BIO_METHOD *method) |
70 | BIO_METHOD *method; | ||
71 | { | 70 | { |
72 | BIO *ret=NULL; | 71 | BIO *ret=NULL; |
73 | 72 | ||
@@ -85,9 +84,7 @@ BIO_METHOD *method; | |||
85 | return(ret); | 84 | return(ret); |
86 | } | 85 | } |
87 | 86 | ||
88 | int BIO_set(bio,method) | 87 | int BIO_set(BIO *bio, BIO_METHOD *method) |
89 | BIO *bio; | ||
90 | BIO_METHOD *method; | ||
91 | { | 88 | { |
92 | bio->method=method; | 89 | bio->method=method; |
93 | bio->callback=NULL; | 90 | bio->callback=NULL; |
@@ -110,8 +107,7 @@ BIO_METHOD *method; | |||
110 | return(1); | 107 | return(1); |
111 | } | 108 | } |
112 | 109 | ||
113 | int BIO_free(a) | 110 | int BIO_free(BIO *a) |
114 | BIO *a; | ||
115 | { | 111 | { |
116 | int ret=0,i; | 112 | int ret=0,i; |
117 | 113 | ||
@@ -121,7 +117,7 @@ BIO *a; | |||
121 | #ifdef REF_PRINT | 117 | #ifdef REF_PRINT |
122 | REF_PRINT("BIO",a); | 118 | REF_PRINT("BIO",a); |
123 | #endif | 119 | #endif |
124 | if (i > 0) return(1); | 120 | if (i > 0) return(1); |
125 | #ifdef REF_CHECK | 121 | #ifdef REF_CHECK |
126 | if (i < 0) | 122 | if (i < 0) |
127 | { | 123 | { |
@@ -141,10 +137,7 @@ BIO *a; | |||
141 | return(1); | 137 | return(1); |
142 | } | 138 | } |
143 | 139 | ||
144 | int BIO_read(b,out,outl) | 140 | int BIO_read(BIO *b, void *out, int outl) |
145 | BIO *b; | ||
146 | char *out; | ||
147 | int outl; | ||
148 | { | 141 | { |
149 | int i; | 142 | int i; |
150 | long (*cb)(); | 143 | long (*cb)(); |
@@ -162,11 +155,12 @@ int outl; | |||
162 | 155 | ||
163 | if (!b->init) | 156 | if (!b->init) |
164 | { | 157 | { |
165 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED); | 158 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); |
166 | return(-2); | 159 | return(-2); |
167 | } | 160 | } |
168 | 161 | ||
169 | i=b->method->bread(b,out,outl); | 162 | i=b->method->bread(b,out,outl); |
163 | |||
170 | if (i > 0) b->num_read+=(unsigned long)i; | 164 | if (i > 0) b->num_read+=(unsigned long)i; |
171 | 165 | ||
172 | if (cb != NULL) | 166 | if (cb != NULL) |
@@ -175,10 +169,7 @@ int outl; | |||
175 | return(i); | 169 | return(i); |
176 | } | 170 | } |
177 | 171 | ||
178 | int BIO_write(b,in,inl) | 172 | int BIO_write(BIO *b, const char *in, int inl) |
179 | BIO *b; | ||
180 | char *in; | ||
181 | int inl; | ||
182 | { | 173 | { |
183 | int i; | 174 | int i; |
184 | long (*cb)(); | 175 | long (*cb)(); |
@@ -199,22 +190,27 @@ int inl; | |||
199 | 190 | ||
200 | if (!b->init) | 191 | if (!b->init) |
201 | { | 192 | { |
202 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED); | 193 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); |
203 | return(-2); | 194 | return(-2); |
204 | } | 195 | } |
205 | 196 | ||
206 | i=b->method->bwrite(b,in,inl); | 197 | i=b->method->bwrite(b,in,inl); |
198 | |||
207 | if (i > 0) b->num_write+=(unsigned long)i; | 199 | if (i > 0) b->num_write+=(unsigned long)i; |
208 | 200 | ||
209 | if (cb != NULL) | 201 | /* This is evil and not thread safe. If the BIO has been freed, |
202 | * we must not call the callback. The only way to be able to | ||
203 | * determine this is the reference count which is now invalid since | ||
204 | * the memory has been free()ed. | ||
205 | */ | ||
206 | if (b->references <= 0) abort(); | ||
207 | if (cb != NULL) /* && (b->references >= 1)) */ | ||
210 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | 208 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, |
211 | 0L,(long)i); | 209 | 0L,(long)i); |
212 | return(i); | 210 | return(i); |
213 | } | 211 | } |
214 | 212 | ||
215 | int BIO_puts(b,in) | 213 | int BIO_puts(BIO *b, const char *in) |
216 | BIO *b; | ||
217 | char *in; | ||
218 | { | 214 | { |
219 | int i; | 215 | int i; |
220 | long (*cb)(); | 216 | long (*cb)(); |
@@ -233,7 +229,7 @@ char *in; | |||
233 | 229 | ||
234 | if (!b->init) | 230 | if (!b->init) |
235 | { | 231 | { |
236 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED); | 232 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); |
237 | return(-2); | 233 | return(-2); |
238 | } | 234 | } |
239 | 235 | ||
@@ -245,10 +241,7 @@ char *in; | |||
245 | return(i); | 241 | return(i); |
246 | } | 242 | } |
247 | 243 | ||
248 | int BIO_gets(b,in,inl) | 244 | int BIO_gets(BIO *b, char *in, int inl) |
249 | BIO *b; | ||
250 | char *in; | ||
251 | int inl; | ||
252 | { | 245 | { |
253 | int i; | 246 | int i; |
254 | long (*cb)(); | 247 | long (*cb)(); |
@@ -267,7 +260,7 @@ int inl; | |||
267 | 260 | ||
268 | if (!b->init) | 261 | if (!b->init) |
269 | { | 262 | { |
270 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED); | 263 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); |
271 | return(-2); | 264 | return(-2); |
272 | } | 265 | } |
273 | 266 | ||
@@ -279,11 +272,7 @@ int inl; | |||
279 | return(i); | 272 | return(i); |
280 | } | 273 | } |
281 | 274 | ||
282 | long BIO_int_ctrl(b,cmd,larg,iarg) | 275 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) |
283 | BIO *b; | ||
284 | int cmd; | ||
285 | long larg; | ||
286 | int iarg; | ||
287 | { | 276 | { |
288 | int i; | 277 | int i; |
289 | 278 | ||
@@ -291,10 +280,7 @@ int iarg; | |||
291 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); | 280 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); |
292 | } | 281 | } |
293 | 282 | ||
294 | char *BIO_ptr_ctrl(b,cmd,larg) | 283 | char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) |
295 | BIO *b; | ||
296 | int cmd; | ||
297 | long larg; | ||
298 | { | 284 | { |
299 | char *p=NULL; | 285 | char *p=NULL; |
300 | 286 | ||
@@ -304,11 +290,7 @@ long larg; | |||
304 | return(p); | 290 | return(p); |
305 | } | 291 | } |
306 | 292 | ||
307 | long BIO_ctrl(b,cmd,larg,parg) | 293 | long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) |
308 | BIO *b; | ||
309 | int cmd; | ||
310 | long larg; | ||
311 | char *parg; | ||
312 | { | 294 | { |
313 | long ret; | 295 | long ret; |
314 | long (*cb)(); | 296 | long (*cb)(); |
@@ -335,9 +317,22 @@ char *parg; | |||
335 | return(ret); | 317 | return(ret); |
336 | } | 318 | } |
337 | 319 | ||
320 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | ||
321 | * do; but those macros have inappropriate return type, and for interfacing | ||
322 | * from other programming languages, C macros aren't much of a help anyway. */ | ||
323 | size_t BIO_ctrl_pending(BIO *bio) | ||
324 | { | ||
325 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | ||
326 | } | ||
327 | |||
328 | size_t BIO_ctrl_wpending(BIO *bio) | ||
329 | { | ||
330 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | ||
331 | } | ||
332 | |||
333 | |||
338 | /* put the 'bio' on the end of b's list of operators */ | 334 | /* put the 'bio' on the end of b's list of operators */ |
339 | BIO *BIO_push(b,bio) | 335 | BIO *BIO_push(BIO *b, BIO *bio) |
340 | BIO *b,*bio; | ||
341 | { | 336 | { |
342 | BIO *lb; | 337 | BIO *lb; |
343 | 338 | ||
@@ -354,8 +349,7 @@ BIO *b,*bio; | |||
354 | } | 349 | } |
355 | 350 | ||
356 | /* Remove the first and return the rest */ | 351 | /* Remove the first and return the rest */ |
357 | BIO *BIO_pop(b) | 352 | BIO *BIO_pop(BIO *b) |
358 | BIO *b; | ||
359 | { | 353 | { |
360 | BIO *ret; | 354 | BIO *ret; |
361 | 355 | ||
@@ -373,9 +367,7 @@ BIO *b; | |||
373 | return(ret); | 367 | return(ret); |
374 | } | 368 | } |
375 | 369 | ||
376 | BIO *BIO_get_retry_BIO(bio,reason) | 370 | BIO *BIO_get_retry_BIO(BIO *bio, int *reason) |
377 | BIO *bio; | ||
378 | int *reason; | ||
379 | { | 371 | { |
380 | BIO *b,*last; | 372 | BIO *b,*last; |
381 | 373 | ||
@@ -391,15 +383,12 @@ int *reason; | |||
391 | return(last); | 383 | return(last); |
392 | } | 384 | } |
393 | 385 | ||
394 | int BIO_get_retry_reason(bio) | 386 | int BIO_get_retry_reason(BIO *bio) |
395 | BIO *bio; | ||
396 | { | 387 | { |
397 | return(bio->retry_reason); | 388 | return(bio->retry_reason); |
398 | } | 389 | } |
399 | 390 | ||
400 | BIO *BIO_find_type(bio,type) | 391 | BIO *BIO_find_type(BIO *bio, int type) |
401 | BIO *bio; | ||
402 | int type; | ||
403 | { | 392 | { |
404 | int mt,mask; | 393 | int mt,mask; |
405 | 394 | ||
@@ -421,8 +410,7 @@ int type; | |||
421 | return(NULL); | 410 | return(NULL); |
422 | } | 411 | } |
423 | 412 | ||
424 | void BIO_free_all(bio) | 413 | void BIO_free_all(BIO *bio) |
425 | BIO *bio; | ||
426 | { | 414 | { |
427 | BIO *b; | 415 | BIO *b; |
428 | int ref; | 416 | int ref; |
@@ -438,8 +426,7 @@ BIO *bio; | |||
438 | } | 426 | } |
439 | } | 427 | } |
440 | 428 | ||
441 | BIO *BIO_dup_chain(in) | 429 | BIO *BIO_dup_chain(BIO *in) |
442 | BIO *in; | ||
443 | { | 430 | { |
444 | BIO *ret=NULL,*eoc=NULL,*bio,*new; | 431 | BIO *ret=NULL,*eoc=NULL,*bio,*new; |
445 | 432 | ||
@@ -461,9 +448,9 @@ BIO *in; | |||
461 | goto err; | 448 | goto err; |
462 | } | 449 | } |
463 | 450 | ||
464 | /* copy app data */ | 451 | /* copy app data */ |
465 | if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) | 452 | if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) |
466 | goto err; | 453 | goto err; |
467 | 454 | ||
468 | if (ret == NULL) | 455 | if (ret == NULL) |
469 | { | 456 | { |
@@ -483,36 +470,26 @@ err: | |||
483 | return(NULL); | 470 | return(NULL); |
484 | } | 471 | } |
485 | 472 | ||
486 | void BIO_copy_next_retry(b) | 473 | void BIO_copy_next_retry(BIO *b) |
487 | BIO *b; | ||
488 | { | 474 | { |
489 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); | 475 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); |
490 | b->retry_reason=b->next_bio->retry_reason; | 476 | b->retry_reason=b->next_bio->retry_reason; |
491 | } | 477 | } |
492 | 478 | ||
493 | int BIO_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | 479 | int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), |
494 | long argl; | 480 | int (*dup_func)(), void (*free_func)()) |
495 | char *argp; | 481 | { |
496 | int (*new_func)(); | 482 | bio_meth_num++; |
497 | int (*dup_func)(); | 483 | return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, |
498 | void (*free_func)(); | 484 | argl,argp,new_func,dup_func,free_func)); |
499 | { | 485 | } |
500 | bio_meth_num++; | 486 | |
501 | return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, | 487 | int BIO_set_ex_data(BIO *bio, int idx, char *data) |
502 | argl,argp,new_func,dup_func,free_func)); | ||
503 | } | ||
504 | |||
505 | int BIO_set_ex_data(bio,idx,data) | ||
506 | BIO *bio; | ||
507 | int idx; | ||
508 | char *data; | ||
509 | { | 488 | { |
510 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | 489 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); |
511 | } | 490 | } |
512 | 491 | ||
513 | char *BIO_get_ex_data(bio,idx) | 492 | char *BIO_get_ex_data(BIO *bio, int idx) |
514 | BIO *bio; | ||
515 | int idx; | ||
516 | { | 493 | { |
517 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | 494 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); |
518 | } | 495 | } |