From 8ae9d5397a420befbe964d551a3d554af55a5fdd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kou=C5=99il?= Date: Tue, 17 Jan 2012 20:10:21 +0000 Subject: [PATCH] routines to establish authentication grouped into a single structure --- emi.canl.canl-c/src/canl.c | 6 +++++- emi.canl.canl-c/src/canl_locl.h | 37 +++++++++++++++++++++++++++++++++++-- emi.canl.canl-c/src/canl_ssl.c | 15 ++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index 8fbad61..24b753f 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -1,5 +1,9 @@ #include "canl_locl.h" +static struct canl_mech *mechs[] = { + &canl_mech_ssl, +}; + static void io_destroy(glb_ctx *cc, io_handler *io); static int init_io_content(glb_ctx *cc, io_handler *io); static int try_connect(glb_ctx *glb_cc, io_handler *io_cc, char *addr, @@ -14,7 +18,7 @@ canl_ctx canl_create_ctx() if (!ctx) return NULL; - ssl_init(); + ssl_initialize(); return ctx; } diff --git a/emi.canl.canl-c/src/canl_locl.h b/emi.canl.canl-c/src/canl_locl.h index d96a463..4c8d405 100644 --- a/emi.canl.canl-c/src/canl_locl.h +++ b/emi.canl.canl-c/src/canl_locl.h @@ -50,7 +50,9 @@ typedef enum _CANL_ERROR_ORIGIN typedef enum _CANL_AUTH_MECHANISM { x509 = 0, - kerberos = 1, /* and others may be added*/ + KRB5 = 1, /* and others may be added*/ + TLS, + GSSAPI, } CANL_AUTH_MECHANISM; typedef struct _cert_key_store { @@ -90,6 +92,37 @@ typedef struct _io_handler principal_int *princ_int; } io_handler; +typedef struct canl_mech { + CANL_AUTH_MECHANISM mech; + void *context; + + canl_err_code (*initialize) + (void); + + canl_err_code (*client_init) + (glb_ctx *); + + canl_err_code (*server_init) + (glb_ctx *); + + canl_err_code (*connect) + (glb_ctx *, io_handler *, struct timeval *, const char *); + + canl_err_code (*accept) + (glb_ctx *, io_handler *, struct timeval *); + + canl_err_code (*close) + (glb_ctx *, io_handler *); + + canl_err_code (*read) + (glb_ctx *, io_handler *, void *, size_t, struct timeval *); + + canl_err_code (*write) + (glb_ctx *, io_handler *, void *, size_t, struct timeval *); +} canl_mech; + +extern struct canl_mech canl_mech_ssl; + void reset_error (glb_ctx *cc, unsigned long err_code); int set_error (glb_ctx *cc, unsigned long err_code, CANL_ERROR_ORIGIN err_orig, const char *err_format, ...); @@ -107,6 +140,6 @@ int ssl_read(glb_ctx *cc, io_handler *io, void *buffer, size_t size, int ssl_write(glb_ctx *cc, io_handler *io, void *buffer, size_t size, struct timeval *tout); int ssl_close(glb_ctx *cc, io_handler *io); -int ssl_init(); +int ssl_initialize(); #endif diff --git a/emi.canl.canl-c/src/canl_ssl.c b/emi.canl.canl-c/src/canl_ssl.c index 7253306..f687c36 100644 --- a/emi.canl.canl-c/src/canl_ssl.c +++ b/emi.canl.canl-c/src/canl_ssl.c @@ -11,7 +11,7 @@ static int check_hostname_cert(glb_ctx *cc, io_handler *io, const char *host); static void dbg_print_ssl_error(int errorcode); #endif -int ssl_init() +int ssl_initialize() { SSL_library_init(); SSL_load_error_strings(); @@ -808,3 +808,16 @@ static void dbg_print_ssl_error(int errorcode) } } #endif + +struct canl_mech canl_mech_ssl = { + TLS, + NULL, + ssl_initialize, + ssl_client_init, + ssl_server_init, + ssl_connect, + ssl_accept, + ssl_close, + ssl_read, + ssl_write +}; -- 1.8.2.3