Skip to content

Commit

Permalink
main/opnessl: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed May 13, 2022
1 parent c9d6152 commit 529e7d7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 128 deletions.
9 changes: 1 addition & 8 deletions src/main/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ int libre_init(void)
goto out;

out:
if (err) {
if (err)
net_sock_close();
#ifdef USE_OPENSSL
openssl_close();
#endif
}

return err;
}
Expand All @@ -50,7 +46,4 @@ void libre_close(void)
{
(void)fd_setsize(0);
net_sock_close();
#ifdef USE_OPENSSL
openssl_close();
#endif
}
120 changes: 0 additions & 120 deletions src/main/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,84 +18,6 @@
#include "main.h"


#if defined (HAVE_PTHREAD) && (OPENSSL_VERSION_NUMBER < 0x10100000L)


static pthread_mutex_t *lockv;


static inline unsigned long threadid(void)
{
#if defined (DARWIN) || defined (FREEBSD) || defined (OPENBSD) || \
defined (NETBSD) || defined (DRAGONFLY)
return (unsigned long)(void *)pthread_self();
#else
return (unsigned long)pthread_self();
#endif
}


static void threadid_handler(CRYPTO_THREADID *id)
{
CRYPTO_THREADID_set_numeric(id, threadid());
}


static void locking_handler(int mode, int type, const char *file, int line)
{
(void)file;
(void)line;

if (mode & CRYPTO_LOCK)
(void)pthread_mutex_lock(&lockv[type]);
else
(void)pthread_mutex_unlock(&lockv[type]);
}


#endif


#if OPENSSL_VERSION_NUMBER < 0x10100000L
static struct CRYPTO_dynlock_value *dynlock_create_handler(const char *file,
int line)
{
struct lock *lock;
(void)file;
(void)line;

if (lock_alloc(&lock))
return NULL;

return (struct CRYPTO_dynlock_value *)lock;
}


static void dynlock_lock_handler(int mode, struct CRYPTO_dynlock_value *l,
const char *file, int line)
{
struct lock *lock = (struct lock *)l;
(void)file;
(void)line;

if (mode & CRYPTO_LOCK)
lock_write_get(lock);
else
lock_rel(lock);
}


static void dynlock_destroy_handler(struct CRYPTO_dynlock_value *l,
const char *file, int line)
{
(void)file;
(void)line;

mem_deref(l);
}
#endif


#ifdef SIGPIPE
static void sigpipe_handler(int x)
{
Expand All @@ -108,56 +30,14 @@ static void sigpipe_handler(int x)
int openssl_init(void)
{
int err;
#if defined (HAVE_PTHREAD) && (OPENSSL_VERSION_NUMBER < 0x10100000L)
int i;

lockv = mem_zalloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks(), NULL);
if (!lockv)
return ENOMEM;

for (i=0; i<CRYPTO_num_locks(); i++) {

err = pthread_mutex_init(&lockv[i], NULL);
if (err) {
lockv = mem_deref(lockv);
return err;
}
}

CRYPTO_THREADID_set_callback(threadid_handler);

CRYPTO_set_locking_callback(locking_handler);
#endif

#if OPENSSL_VERSION_NUMBER < 0x10100000L
CRYPTO_set_dynlock_create_callback(dynlock_create_handler);
CRYPTO_set_dynlock_lock_callback(dynlock_lock_handler);
CRYPTO_set_dynlock_destroy_callback(dynlock_destroy_handler);
#endif

#ifdef SIGPIPE
(void)signal(SIGPIPE, sigpipe_handler);
#endif

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
err = OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
if (!err)
return !err;
#else
SSL_library_init();
SSL_load_error_strings();
#endif

return 0;
}


void openssl_close(void)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
ERR_free_strings();
#endif
#if defined (HAVE_PTHREAD) && (OPENSSL_VERSION_NUMBER < 0x10100000L)
lockv = mem_deref(lockv);
#endif
}

0 comments on commit 529e7d7

Please sign in to comment.