From: Bradley Baetz Date: Fri, 8 Dec 2017 00:46:40 +0000 (+1100) Subject: ITS#8791 fix OpenSSL 1.1.1 BIO_method compat X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e5ee07785e9d820ec8db08187aa39697584ca1b7;p=openldap ITS#8791 fix OpenSSL 1.1.1 BIO_method compat Use the new methods unconditionally, define helper functions for older versions. --- diff --git a/libraries/libldap/tls_o.c b/libraries/libldap/tls_o.c index 2cf503bcf9..c97ed71fb3 100644 --- a/libraries/libldap/tls_o.c +++ b/libraries/libldap/tls_o.c @@ -54,6 +54,9 @@ typedef SSL_CTX tlso_ctx; typedef SSL tlso_session; +static BIO_METHOD * tlso_bio_method = NULL; +static BIO_METHOD * tlso_bio_setup( void ); + static int tlso_opt_trace = 1; static void tlso_report_error( void ); @@ -113,6 +116,43 @@ static void tlso_thr_init( void ) {} #endif #endif /* OpenSSL 1.1 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000 +/* + * OpenSSL 1.1 API and later makes the BIO method concrete types internal. + */ + +static const BIO_METHOD * +BIO_meth_new( int type, const char *name ) +{ + BIO_METHOD *method = LDAP_MALLOC( sizeof(BIO_METHOD) ); + memset( method, 0, sizeof(BIO_METHOD) ); + + method->type = type; + method->name = name; + + return method; +} + +static void +BIO_meth_free( BIO_METHOD *meth ) +{ + if ( meth == NULL ) { + return; + } + + LDAP_FREE( meth ); +} + +#define BIO_meth_set_write(m, f) (m)->bwrite = (f) +#define BIO_meth_set_read(m, f) (m)->bread = (f) +#define BIO_meth_set_puts(m, f) (m)->bputs = (f) +#define BIO_meth_set_gets(m, f) (m)->bgets = (f) +#define BIO_meth_set_ctrl(m, f) (m)->ctrl = (f) +#define BIO_meth_set_create(m, f) (m)->create = (f) +#define BIO_meth_set_destroy(m, f) (m)->destroy = (f) + +#endif /* OpenSSL 1.1 */ + static STACK_OF(X509_NAME) * tlso_ca_list( char * bundle, char * dir, X509 *cert ) { @@ -176,6 +216,8 @@ tlso_init( void ) /* FIXME: mod_ssl does this */ X509V3_add_standard_extensions(); + tlso_bio_method = tlso_bio_setup(); + return 0; } @@ -187,6 +229,8 @@ tlso_destroy( void ) { struct ldapoptions *lo = LDAP_INT_GLOBAL_OPT(); + BIO_meth_free( tlso_bio_method ); + #if OPENSSL_VERSION_NUMBER < 0x10100000 EVP_cleanup(); #if OPENSSL_VERSION_NUMBER < 0x10000000 @@ -1016,33 +1060,21 @@ tlso_bio_puts( BIO *b, const char *str ) return tlso_bio_write( b, str, strlen( str ) ); } -#if OPENSSL_VERSION_NUMBER >= 0x10100000 -struct bio_method_st { - int type; - const char *name; - int (*bwrite) (BIO *, const char *, int); - int (*bread) (BIO *, char *, int); - int (*bputs) (BIO *, const char *); - int (*bgets) (BIO *, char *, int); - long (*ctrl) (BIO *, int, long, void *); - int (*create) (BIO *); - int (*destroy) (BIO *); - long (*callback_ctrl) (BIO *, int, bio_info_cb *); -}; -#endif - -static BIO_METHOD tlso_bio_method = +static BIO_METHOD * +tlso_bio_setup( void ) { - ( 100 | 0x400 ), /* it's a source/sink BIO */ - "sockbuf glue", - tlso_bio_write, - tlso_bio_read, - tlso_bio_puts, - tlso_bio_gets, - tlso_bio_ctrl, - tlso_bio_create, - tlso_bio_destroy -}; + /* it's a source/sink BIO */ + BIO_METHOD * method = BIO_meth_new( 100 | 0x400, "sockbuf glue" ); + BIO_meth_set_write( method, tlso_bio_write ); + BIO_meth_set_read( method, tlso_bio_read ); + BIO_meth_set_puts( method, tlso_bio_puts ); + BIO_meth_set_gets( method, tlso_bio_gets ); + BIO_meth_set_ctrl( method, tlso_bio_ctrl ); + BIO_meth_set_create( method, tlso_bio_create ); + BIO_meth_set_destroy( method, tlso_bio_destroy ); + + return method; +} static int tlso_sb_setup( Sockbuf_IO_Desc *sbiod, void *arg ) @@ -1059,7 +1091,7 @@ tlso_sb_setup( Sockbuf_IO_Desc *sbiod, void *arg ) p->session = arg; p->sbiod = sbiod; - bio = BIO_new( &tlso_bio_method ); + bio = BIO_new( tlso_bio_method ); BIO_set_data( bio, p ); SSL_set_bio( p->session, bio, bio ); sbiod->sbiod_pvt = p;