Skip to content

Commit f863ad0

Browse files
committed
Fix no-sock on Windows
Link errors were occurring on Windows because the header files were not correctly guarding some functions with OPENSSL_NO_SOCK Reviewed-by: Rich Salz <[email protected]>
1 parent 2469e76 commit f863ad0

File tree

3 files changed

+102
-87
lines changed

3 files changed

+102
-87
lines changed

apps/ocsp.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,13 @@ static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser)
10271027

10281028
static BIO *init_responder(const char *port)
10291029
{
1030-
BIO *acbio = NULL, *bufbio = NULL;
1031-
10321030
# ifdef OPENSSL_NO_SOCK
10331031
BIO_printf(bio_err,
10341032
"Error setting up accept BIO - sockets not supported.\n");
10351033
return NULL;
1036-
# endif
1034+
# else
1035+
BIO *acbio = NULL, *bufbio = NULL;
1036+
10371037
bufbio = BIO_new(BIO_f_buffer());
10381038
if (bufbio == NULL)
10391039
goto err;
@@ -1060,9 +1060,10 @@ static BIO *init_responder(const char *port)
10601060
BIO_free_all(acbio);
10611061
BIO_free(bufbio);
10621062
return NULL;
1063+
# endif
10631064
}
10641065

1065-
1066+
# ifndef OPENSSL_NO_SOCK
10661067
/*
10671068
* Decode %xx URL-decoding in-place. Ignores mal-formed sequences.
10681069
*/
@@ -1086,9 +1087,13 @@ static int urldecode(char *p)
10861087
*out = '\0';
10871088
return (int)(out - save);
10881089
}
1090+
# endif
10891091

10901092
static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio)
10911093
{
1094+
# ifdef OPENSSL_NO_SOCK
1095+
return 0;
1096+
# else
10921097
int len;
10931098
OCSP_REQUEST *req = NULL;
10941099
char inbuf[2048], reqbuf[2048];
@@ -1169,7 +1174,7 @@ static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio)
11691174
*preq = req;
11701175

11711176
return 1;
1172-
1177+
# endif
11731178
}
11741179

11751180
static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp)

include/openssl/bio.h

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -400,48 +400,51 @@ struct bio_dgram_sctp_prinfo {
400400
# define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
401401
# define BIO_get_app_data(s) BIO_get_ex_data(s,0)
402402

403+
# define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
404+
405+
# ifndef OPENSSL_NO_SOCK
403406
/* IP families we support, for BIO_s_connect() and BIO_s_accept() */
404407
/* Note: the underlying operating system may not support some of them */
405-
# define BIO_FAMILY_IPV4 4
406-
# define BIO_FAMILY_IPV6 6
407-
# define BIO_FAMILY_IPANY 256
408+
# define BIO_FAMILY_IPV4 4
409+
# define BIO_FAMILY_IPV6 6
410+
# define BIO_FAMILY_IPANY 256
408411

409412
/* BIO_s_connect() */
410-
# define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
411-
# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
412-
# define BIO_set_conn_address(b,addr) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)addr)
413-
# define BIO_set_conn_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f)
414-
# define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0,NULL))
415-
# define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1,NULL))
416-
# define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2,NULL))
417-
# define BIO_get_conn_ip_family(b) BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL)
418-
# define BIO_set_conn_mode(b,n) BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL)
419-
420-
# define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
413+
# define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
414+
# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
415+
# define BIO_set_conn_address(b,addr) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)addr)
416+
# define BIO_set_conn_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f)
417+
# define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0,NULL))
418+
# define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1,NULL))
419+
# define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2,NULL))
420+
# define BIO_get_conn_ip_family(b) BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL)
421+
# define BIO_set_conn_mode(b,n) BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL)
421422

422423
/* BIO_s_accept() */
423-
# define BIO_set_accept_name(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
424-
# define BIO_set_accept_port(b,port) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(char *)port)
425-
# define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0))
426-
# define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1))
427-
# define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2))
428-
# define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3))
424+
# define BIO_set_accept_name(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
425+
# define BIO_set_accept_port(b,port) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(char *)port)
426+
# define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0))
427+
# define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1))
428+
# define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2))
429+
# define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3))
429430
/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
430-
# define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL)
431-
# define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,3,(char *)bio)
432-
# define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f)
433-
# define BIO_get_accept_ip_family(b) BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL)
431+
# define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL)
432+
# define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,3,(char *)bio)
433+
# define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f)
434+
# define BIO_get_accept_ip_family(b) BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL)
434435

435436
/* Aliases kept for backward compatibility */
436-
# define BIO_BIND_NORMAL 0
437-
# define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR
438-
# define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR
439-
# define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
440-
# define BIO_get_bind_mode(b) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
437+
# define BIO_BIND_NORMAL 0
438+
# define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR
439+
# define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR
440+
# define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
441+
# define BIO_get_bind_mode(b) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
441442

442443
/* BIO_s_accept() and BIO_s_connect() */
443-
# define BIO_do_connect(b) BIO_do_handshake(b)
444-
# define BIO_do_accept(b) BIO_do_handshake(b)
444+
# define BIO_do_connect(b) BIO_do_handshake(b)
445+
# define BIO_do_accept(b) BIO_do_handshake(b)
446+
# endif /* OPENSSL_NO_SOCK */
447+
445448
# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
446449

447450
/* BIO_s_datagram(), BIO_s_fd(), BIO_s_socket(), BIO_s_accept() and BIO_s_connect() */
@@ -624,9 +627,11 @@ long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
624627
const BIO_METHOD *BIO_s_mem(void);
625628
const BIO_METHOD *BIO_s_secmem(void);
626629
BIO *BIO_new_mem_buf(const void *buf, int len);
630+
# ifndef OPENSSL_NO_SOCK
627631
const BIO_METHOD *BIO_s_socket(void);
628632
const BIO_METHOD *BIO_s_connect(void);
629633
const BIO_METHOD *BIO_s_accept(void);
634+
# endif
630635
const BIO_METHOD *BIO_s_fd(void);
631636
const BIO_METHOD *BIO_s_log(void);
632637
const BIO_METHOD *BIO_s_bio(void);
@@ -653,8 +658,10 @@ int BIO_dgram_sctp_msg_waiting(BIO *b);
653658
# endif
654659
# endif
655660

661+
# ifndef OPENSSL_NO_SOCK
656662
int BIO_sock_should_retry(int i);
657663
int BIO_sock_non_fatal_error(int error);
664+
# endif
658665

659666
int BIO_fd_should_retry(int i);
660667
int BIO_fd_non_fatal_error(int error);
@@ -671,6 +678,7 @@ int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);
671678
int BIO_hex_string(BIO *out, int indent, int width, unsigned char *data,
672679
int datalen);
673680

681+
# ifndef OPENSSL_NO_SOCK
674682
BIO_ADDR *BIO_ADDR_new(void);
675683
int BIO_ADDR_rawmake(BIO_ADDR *ap, int family,
676684
const void *where, size_t wherelen, unsigned short port);
@@ -705,9 +713,9 @@ int BIO_sock_error(int sock);
705713
int BIO_socket_ioctl(int fd, long type, void *arg);
706714
int BIO_socket_nbio(int fd, int mode);
707715
int BIO_sock_init(void);
708-
#if OPENSSL_API_COMPAT < 0x10100000L
709-
# define BIO_sock_cleanup() while(0) continue
710-
#endif
716+
# if OPENSSL_API_COMPAT < 0x10100000L
717+
# define BIO_sock_cleanup() while(0) continue
718+
# endif
711719
int BIO_set_tcp_ndelay(int sock, int turn_on);
712720

713721
DEPRECATEDIN_1_1_0(struct hostent *BIO_gethostbyname(const char *name))
@@ -725,11 +733,11 @@ enum BIO_sock_info_type {
725733
int BIO_sock_info(int sock,
726734
enum BIO_sock_info_type type, union BIO_sock_info_u *info);
727735

728-
# define BIO_SOCK_REUSEADDR 0x01
729-
# define BIO_SOCK_V6_ONLY 0x02
730-
# define BIO_SOCK_KEEPALIVE 0x04
731-
# define BIO_SOCK_NONBLOCK 0x08
732-
# define BIO_SOCK_NODELAY 0x10
736+
# define BIO_SOCK_REUSEADDR 0x01
737+
# define BIO_SOCK_V6_ONLY 0x02
738+
# define BIO_SOCK_KEEPALIVE 0x04
739+
# define BIO_SOCK_NONBLOCK 0x08
740+
# define BIO_SOCK_NODELAY 0x10
733741

734742
int BIO_socket(int domain, int socktype, int protocol, int options);
735743
int BIO_connect(int sock, const BIO_ADDR *addr, int options);
@@ -738,9 +746,11 @@ int BIO_accept_ex(int accept_sock, BIO_ADDR *addr, int options);
738746
int BIO_closesocket(int sock);
739747

740748
BIO *BIO_new_socket(int sock, int close_flag);
741-
BIO *BIO_new_fd(int fd, int close_flag);
742749
BIO *BIO_new_connect(const char *host_port);
743750
BIO *BIO_new_accept(const char *host_port);
751+
# endif /* OPENSSL_NO_SOCK*/
752+
753+
BIO *BIO_new_fd(int fd, int close_flag);
744754

745755
int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
746756
BIO **bio2, size_t writebuf2);

0 commit comments

Comments
 (0)