Skip to content

Commit

Permalink
cachedb_mongodb: fix regression in commit 69ed4f7
Browse files Browse the repository at this point in the history
Loading the cachedb_mongodb module alongside the tls_openssl module, but
before tls_mgm would cause a crash. This is a result of the OpenSIPS versus
mongoc library openssl initialization issues (initially fixed in commit
298bf6b). Commit 69ed4f7 split all the openssl related code from the tls_mgm
module into a new tls_openssl module but some openssl initialization bypasses
from the cachedb_mongodb module were left to depend on loading the tls_mgm
module (instead of the new tls_openssl module).

Fixes #3072

(cherry picked from commit ce177c1)
  • Loading branch information
rvlad-patrascu committed Jun 20, 2023
1 parent 6a2567e commit 0c4c5ab
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions ssl_init_tweaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
{
int (*real_OPENSSL_init_ssl)(uint64_t, const OPENSSL_INIT_SETTINGS *);
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return 1;
} else {
real_OPENSSL_init_ssl = dlsym(RTLD_NEXT, "OPENSSL_init_ssl");
Expand All @@ -48,12 +48,12 @@ int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
{
int (*real_OPENSSL_init_crypto)(uint64_t, const OPENSSL_INIT_SETTINGS *);
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return 1;
} else {
real_OPENSSL_init_crypto = dlsym(RTLD_NEXT, "OPENSSL_init_crypto");
Expand All @@ -67,12 +67,12 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
int ERR_load_BIO_strings(void)
{
int (*real_ERR_load_BIO_strings)(void);
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return 1;
} else {
real_ERR_load_BIO_strings = dlsym(RTLD_NEXT, "ERR_load_BIO_strings");
Expand All @@ -88,12 +88,12 @@ int ERR_load_BIO_strings(void)
int SSL_library_init(void)
{
int (*real_SSL_library_init)(void);
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return 1;
} else {
real_SSL_library_init = dlsym(RTLD_NEXT, "SSL_library_init");
Expand All @@ -107,12 +107,12 @@ int SSL_library_init(void)
void ERR_load_BIO_strings(void)
{
int (*real_ERR_load_BIO_strings)(void);
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return;
} else {
real_ERR_load_BIO_strings = dlsym(RTLD_NEXT, "ERR_load_BIO_strings");
Expand All @@ -128,12 +128,12 @@ void CRYPTO_set_locking_callback(void (*func)(int mode, int type,
{
int (*real_CRYPTO_set_locking_callback)(void (*)(int, int,
const char *, int));
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return;
} else {
real_CRYPTO_set_locking_callback = dlsym(RTLD_NEXT,
Expand All @@ -149,12 +149,12 @@ void CRYPTO_set_locking_callback(void (*func)(int mode, int type,
void CRYPTO_set_id_callback(unsigned long (*func) (void))
{
int (*real_CRYPTO_set_id_callback)(unsigned long (*)(void));
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return;
} else {
real_CRYPTO_set_id_callback = dlsym(RTLD_NEXT, "CRYPTO_set_id_callback");
Expand All @@ -169,12 +169,12 @@ void CRYPTO_set_id_callback(unsigned long (*func) (void))
int CRYPTO_THREADID_set_callback(void (*threadid_func) (CRYPTO_THREADID *))
{
int (*real_CRYPTO_THREADID_set_callback)(void (*)(CRYPTO_THREADID *));
static int have_tls_mgm = -1;
static int have_openssl = -1;

if (have_tls_mgm == -1)
have_tls_mgm = module_loaded("tls_mgm");
if (have_openssl == -1)
have_openssl = module_loaded("tls_openssl");

if (have_tls_mgm) {
if (have_openssl) {
return 0;
} else {
real_CRYPTO_THREADID_set_callback = dlsym(RTLD_NEXT,
Expand Down

0 comments on commit 0c4c5ab

Please sign in to comment.