diff options
Diffstat (limited to 'src/lib/libcrypto/bio/b_sock.c')
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 269 |
1 files changed, 2 insertions, 267 deletions
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index cd62f889ab..3ccebf77f4 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -184,14 +184,7 @@ BIO_get_port(const char *str, unsigned short *port_ptr) | |||
184 | *port_ptr = (unsigned short)i; | 184 | *port_ptr = (unsigned short)i; |
185 | else { | 185 | else { |
186 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); | 186 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); |
187 | /* Note: under VMS with SOCKETSHR, it seems like the first | ||
188 | * parameter is 'char *', instead of 'const char *' | ||
189 | */ | ||
190 | #ifndef CONST_STRICT | ||
191 | s = getservbyname((char *)str, "tcp"); | ||
192 | #else | ||
193 | s = getservbyname(str, "tcp"); | 187 | s = getservbyname(str, "tcp"); |
194 | #endif | ||
195 | if (s != NULL) | 188 | if (s != NULL) |
196 | *port_ptr = ntohs((unsigned short)s->s_port); | 189 | *port_ptr = ntohs((unsigned short)s->s_port); |
197 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); | 190 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); |
@@ -247,260 +240,24 @@ BIO_sock_error(int sock) | |||
247 | return (j); | 240 | return (j); |
248 | } | 241 | } |
249 | 242 | ||
250 | #if 0 | 243 | struct hostent * |
251 | long | 244 | BIO_gethostbyname(const char *name) |
252 | BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | ||
253 | { | ||
254 | int i; | ||
255 | char **p; | ||
256 | |||
257 | switch (cmd) { | ||
258 | case BIO_GHBN_CTRL_HITS: | ||
259 | return (BIO_ghbn_hits); | ||
260 | /* break; */ | ||
261 | case BIO_GHBN_CTRL_MISSES: | ||
262 | return (BIO_ghbn_miss); | ||
263 | /* break; */ | ||
264 | case BIO_GHBN_CTRL_CACHE_SIZE: | ||
265 | return (GHBN_NUM); | ||
266 | /* break; */ | ||
267 | case BIO_GHBN_CTRL_GET_ENTRY: | ||
268 | if ((iarg >= 0) && (iarg < GHBN_NUM) && | ||
269 | (ghbn_cache[iarg].order > 0)) { | ||
270 | p = (char **)parg; | ||
271 | if (p == NULL) | ||
272 | return (0); | ||
273 | *p = ghbn_cache[iarg].name; | ||
274 | ghbn_cache[iarg].name[128] = '\0'; | ||
275 | return (1); | ||
276 | } | ||
277 | return (0); | ||
278 | /* break; */ | ||
279 | case BIO_GHBN_CTRL_FLUSH: | ||
280 | for (i = 0; i < GHBN_NUM; i++) | ||
281 | ghbn_cache[i].order = 0; | ||
282 | break; | ||
283 | default: | ||
284 | return (0); | ||
285 | } | ||
286 | return (1); | ||
287 | } | ||
288 | #endif | ||
289 | |||
290 | #if 0 | ||
291 | static struct hostent | ||
292 | *ghbn_dup(struct hostent *a) | ||
293 | { | 245 | { |
294 | struct hostent *ret; | ||
295 | int i, j; | ||
296 | |||
297 | MemCheck_off(); | ||
298 | ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent)); | ||
299 | if (ret == NULL) | ||
300 | return (NULL); | ||
301 | memset(ret, 0, sizeof(struct hostent)); | ||
302 | |||
303 | for (i = 0; a->h_aliases[i] != NULL; i++) | ||
304 | ; | ||
305 | i++; | ||
306 | ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *)); | ||
307 | if (ret->h_aliases == NULL) | ||
308 | goto err; | ||
309 | memset(ret->h_aliases, 0, i*sizeof(char *)); | ||
310 | |||
311 | for (i = 0; a->h_addr_list[i] != NULL; i++) | ||
312 | ; | ||
313 | i++; | ||
314 | ret->h_addr_list = (char **)OPENSSL_malloc(i*sizeof(char *)); | ||
315 | if (ret->h_addr_list == NULL) | ||
316 | goto err; | ||
317 | memset(ret->h_addr_list, 0, i*sizeof(char *)); | ||
318 | |||
319 | j = strlen(a->h_name) + 1; | ||
320 | if ((ret->h_name = OPENSSL_malloc(j)) == NULL) | ||
321 | goto err; | ||
322 | memcpy((char *)ret->h_name, a->h_name, j); | ||
323 | for (i = 0; a->h_aliases[i] != NULL; i++) { | ||
324 | j = strlen(a->h_aliases[i]) + 1; | ||
325 | if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL) | ||
326 | goto err; | ||
327 | memcpy(ret->h_aliases[i], a->h_aliases[i], j); | ||
328 | } | ||
329 | ret->h_length = a->h_length; | ||
330 | ret->h_addrtype = a->h_addrtype; | ||
331 | for (i = 0; a->h_addr_list[i] != NULL; i++) { | ||
332 | if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL) | ||
333 | goto err; | ||
334 | memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length); | ||
335 | } | ||
336 | if (0) { | ||
337 | err: | ||
338 | if (ret != NULL) | ||
339 | ghbn_free(ret); | ||
340 | ret = NULL; | ||
341 | } | ||
342 | MemCheck_on(); | ||
343 | return (ret); | ||
344 | } | ||
345 | |||
346 | static void | ||
347 | ghbn_free(struct hostent *a) | ||
348 | { | ||
349 | int i; | ||
350 | |||
351 | if (a == NULL) | ||
352 | return; | ||
353 | |||
354 | if (a->h_aliases != NULL) { | ||
355 | for (i = 0; a->h_aliases[i] != NULL; i++) | ||
356 | OPENSSL_free(a->h_aliases[i]); | ||
357 | OPENSSL_free(a->h_aliases); | ||
358 | } | ||
359 | if (a->h_addr_list != NULL) { | ||
360 | for (i = 0; a->h_addr_list[i] != NULL; i++) | ||
361 | OPENSSL_free(a->h_addr_list[i]); | ||
362 | OPENSSL_free(a->h_addr_list); | ||
363 | } | ||
364 | if (a->h_name != NULL) | ||
365 | OPENSSL_free(a->h_name); | ||
366 | OPENSSL_free(a); | ||
367 | } | ||
368 | |||
369 | #endif | ||
370 | |||
371 | struct hostent | ||
372 | *BIO_gethostbyname(const char *name) | ||
373 | { | ||
374 | #if 1 | ||
375 | /* Caching gethostbyname() results forever is wrong, | ||
376 | * so we have to let the true gethostbyname() worry about this */ | ||
377 | #if (defined(NETWARE_BSDSOCK) && !defined(__NOVELL_LIBC__)) | ||
378 | return gethostbyname((char*)name); | ||
379 | #else | ||
380 | return gethostbyname(name); | 246 | return gethostbyname(name); |
381 | #endif | ||
382 | #else | ||
383 | struct hostent *ret; | ||
384 | int i, lowi = 0, j; | ||
385 | unsigned long low = (unsigned long) - 1; | ||
386 | |||
387 | |||
388 | # if 0 | ||
389 | /* It doesn't make sense to use locking here: The function interface | ||
390 | * is not thread-safe, because threads can never be sure when | ||
391 | * some other thread destroys the data they were given a pointer to. | ||
392 | */ | ||
393 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
394 | # endif | ||
395 | j = strlen(name); | ||
396 | if (j < 128) { | ||
397 | for (i = 0; i < GHBN_NUM; i++) { | ||
398 | if (low > ghbn_cache[i].order) { | ||
399 | low = ghbn_cache[i].order; | ||
400 | lowi = i; | ||
401 | } | ||
402 | if (ghbn_cache[i].order > 0) { | ||
403 | if (strncmp(name, ghbn_cache[i].name, 128) == 0) | ||
404 | break; | ||
405 | } | ||
406 | } | ||
407 | } else | ||
408 | i = GHBN_NUM; | ||
409 | |||
410 | if (i == GHBN_NUM) /* no hit*/ | ||
411 | { | ||
412 | BIO_ghbn_miss++; | ||
413 | /* Note: under VMS with SOCKETSHR, it seems like the first | ||
414 | * parameter is 'char *', instead of 'const char *' | ||
415 | */ | ||
416 | # ifndef CONST_STRICT | ||
417 | ret = gethostbyname((char *)name); | ||
418 | # else | ||
419 | ret = gethostbyname(name); | ||
420 | # endif | ||
421 | |||
422 | if (ret == NULL) | ||
423 | goto end; | ||
424 | if (j > 128) /* too big to cache */ | ||
425 | { | ||
426 | # if 0 | ||
427 | /* If we were trying to make this function thread-safe (which | ||
428 | * is bound to fail), we'd have to give up in this case | ||
429 | * (or allocate more memory). */ | ||
430 | ret = NULL; | ||
431 | # endif | ||
432 | goto end; | ||
433 | } | ||
434 | |||
435 | /* else add to cache */ | ||
436 | if (ghbn_cache[lowi].ent != NULL) | ||
437 | ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ | ||
438 | ghbn_cache[lowi].name[0] = '\0'; | ||
439 | |||
440 | if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) { | ||
441 | BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE); | ||
442 | goto end; | ||
443 | } | ||
444 | strncpy(ghbn_cache[lowi].name, name, 128); | ||
445 | ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits; | ||
446 | } else { | ||
447 | BIO_ghbn_hits++; | ||
448 | ret = ghbn_cache[i].ent; | ||
449 | ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits; | ||
450 | } | ||
451 | end: | ||
452 | # if 0 | ||
453 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
454 | # endif | ||
455 | return (ret); | ||
456 | #endif | ||
457 | } | 247 | } |
458 | 248 | ||
459 | 249 | ||
460 | int | 250 | int |
461 | BIO_sock_init(void) | 251 | BIO_sock_init(void) |
462 | { | 252 | { |
463 | #ifdef WATT32 | ||
464 | extern int _watt_do_exit; | ||
465 | _watt_do_exit = 0; | ||
466 | /* don't make sock_init() call exit() */ | ||
467 | if (sock_init()) | ||
468 | return (-1); | ||
469 | #endif | ||
470 | |||
471 | #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) | ||
472 | WORD wVerReq; | ||
473 | WSADATA wsaData; | ||
474 | int err; | ||
475 | |||
476 | if (!wsa_init_done) { | ||
477 | wsa_init_done = 1; | ||
478 | wVerReq = MAKEWORD( 2, 0 ); | ||
479 | err = WSAStartup(wVerReq, &wsaData); | ||
480 | if (err != 0) { | ||
481 | SYSerr(SYS_F_WSASTARTUP, err); | ||
482 | BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); | ||
483 | return (-1); | ||
484 | } | ||
485 | } | ||
486 | #endif | ||
487 | |||
488 | return (1); | 253 | return (1); |
489 | } | 254 | } |
490 | 255 | ||
491 | void | 256 | void |
492 | BIO_sock_cleanup(void) | 257 | BIO_sock_cleanup(void) |
493 | { | 258 | { |
494 | #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) | ||
495 | if (wsa_init_done) { | ||
496 | wsa_init_done = 0; | ||
497 | WSACleanup(); | ||
498 | } | ||
499 | #endif | ||
500 | } | 259 | } |
501 | 260 | ||
502 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 | ||
503 | |||
504 | int | 261 | int |
505 | BIO_socket_ioctl(int fd, long type, void *arg) | 262 | BIO_socket_ioctl(int fd, long type, void *arg) |
506 | { | 263 | { |
@@ -509,28 +266,7 @@ BIO_socket_ioctl(int fd, long type, void *arg) | |||
509 | #ifdef __DJGPP__ | 266 | #ifdef __DJGPP__ |
510 | i = ioctl(fd, type, (char *)arg); | 267 | i = ioctl(fd, type, (char *)arg); |
511 | #else | 268 | #else |
512 | # if defined(OPENSSL_SYS_VMS) | ||
513 | /* 2011-02-18 SMS. | ||
514 | * VMS ioctl() can't tolerate a 64-bit "void *arg", but we | ||
515 | * observe that all the consumers pass in an "unsigned long *", | ||
516 | * so we arrange a local copy with a short pointer, and use | ||
517 | * that, instead. | ||
518 | */ | ||
519 | # if __INITIAL_POINTER_SIZE == 64 | ||
520 | # define ARG arg_32p | ||
521 | # pragma pointer_size save | ||
522 | # pragma pointer_size 32 | ||
523 | unsigned long arg_32; | ||
524 | unsigned long *arg_32p; | ||
525 | # pragma pointer_size restore | ||
526 | arg_32p = &arg_32; | ||
527 | arg_32 = *((unsigned long *) arg); | ||
528 | # else /* __INITIAL_POINTER_SIZE == 64 */ | ||
529 | # define ARG arg | ||
530 | # endif /* __INITIAL_POINTER_SIZE == 64 [else] */ | ||
531 | # else /* defined(OPENSSL_SYS_VMS) */ | ||
532 | # define ARG arg | 269 | # define ARG arg |
533 | # endif /* defined(OPENSSL_SYS_VMS) [else] */ | ||
534 | 270 | ||
535 | i = ioctl(fd, type, ARG); | 271 | i = ioctl(fd, type, ARG); |
536 | #endif /* __DJGPP__ */ | 272 | #endif /* __DJGPP__ */ |
@@ -538,7 +274,6 @@ BIO_socket_ioctl(int fd, long type, void *arg) | |||
538 | SYSerr(SYS_F_IOCTLSOCKET, errno); | 274 | SYSerr(SYS_F_IOCTLSOCKET, errno); |
539 | return (i); | 275 | return (i); |
540 | } | 276 | } |
541 | #endif /* __VMS_VER */ | ||
542 | 277 | ||
543 | /* The reason I have implemented this instead of using sscanf is because | 278 | /* The reason I have implemented this instead of using sscanf is because |
544 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ | 279 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ |