From d05402268f6518b93ed146fa74c738d7ffa561e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kou=C5=99il?= Date: Tue, 17 Jan 2012 20:11:47 +0000 Subject: [PATCH] added ssl_free() to cleanup per-connection contexts --- emi.canl.canl-c/src/canl.c | 14 ++++++++------ emi.canl.canl-c/src/canl_locl.h | 5 +++++ emi.canl.canl-c/src/canl_ssl.c | 8 ++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index cd08f39..96f203c 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -72,6 +72,7 @@ static int init_io_content(glb_ctx *cc, io_handler *io) if (!io->s_ctx) return set_error(cc, ENOMEM, posix_error, "Not enough memory"); + io->authn_mech.type = AUTH_UNDEF; io->sock = -1; return 0; } @@ -283,13 +284,14 @@ static void io_destroy(glb_ctx *cc, io_handler *io) io_handler *io_cc = (io_handler*) io; if (io_cc->s_ctx) { - if (io_cc->s_ctx->ssl_io) { - SSL_free(io_cc->s_ctx->ssl_io); - io_cc->s_ctx->ssl_io = NULL; - } + if (io_cc->s_ctx->ssl_io) + ssl_free(cc, io_cc->s_ctx->ssl_io); + + free (io_cc->s_ctx); + io_cc->s_ctx = NULL; } - free (io_cc->s_ctx); - io_cc->s_ctx = NULL; + + return; } diff --git a/emi.canl.canl-c/src/canl_locl.h b/emi.canl.canl-c/src/canl_locl.h index 090f5be..8d94bb0 100644 --- a/emi.canl.canl-c/src/canl_locl.h +++ b/emi.canl.canl-c/src/canl_locl.h @@ -49,6 +49,7 @@ typedef enum _CANL_ERROR_ORIGIN typedef enum _CANL_AUTH_MECHANISM { + AUTH_UNDEF = -1, x509 = 0, KRB5 = 1, /* and others may be added*/ TLS, @@ -109,6 +110,9 @@ typedef struct canl_mech { canl_err_code (*server_init) (glb_ctx *, void *); + canl_err_code (*free_ctx) + (glb_ctx *, void *); + canl_err_code (*connect) (glb_ctx *, void *, io_handler *, struct timeval *, const char *); @@ -137,6 +141,7 @@ int asyn_getservbyname(int a_family, asyn_result *ares_result,char const *name, struct timeval *timeout); int ssl_client_init(glb_ctx *cc, io_handler *io); int ssl_server_init(glb_ctx *cc); +int ssl_free(glb_ctx *cc, void *ctx); int ssl_connect(glb_ctx *cc, io_handler *io, struct timeval *timeout, const char * host); int ssl_accept(glb_ctx *cc, io_handler *io, struct timeval *timeout); diff --git a/emi.canl.canl-c/src/canl_ssl.c b/emi.canl.canl-c/src/canl_ssl.c index ea21047..ca68d55 100644 --- a/emi.canl.canl-c/src/canl_ssl.c +++ b/emi.canl.canl-c/src/canl_ssl.c @@ -749,6 +749,13 @@ int ssl_close(glb_ctx *cc, io_handler *io) } } +int +ssl_free(glb_ctx *cc, void *ctx) +{ + SSL_free(ctx); + return 0; +} + canl_err_code canl_ctx_set_ssl_cred(canl_ctx cc, char *cert, char *key, canl_password_callback cb, void *userdata) @@ -815,6 +822,7 @@ struct canl_mech canl_mech_ssl = { ssl_initialize, ssl_client_init, ssl_server_init, + ssl_free, ssl_connect, ssl_accept, ssl_close, -- 1.8.2.3