From 8260286272deb2bb288fdf08c860e237bda245fd Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Wed, 30 May 2012 17:19:28 +0000 Subject: [PATCH] errors revision --- emi.canl.canl-c/src/canl.c | 17 ++++++++++------- emi.canl.canl-c/src/canl_ssl.c | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index 4558df5..9abd339 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -49,16 +49,19 @@ canl_create_io_handler(canl_ctx cc, canl_io_handler *io) glb_ctx *g_cc = cc; int err = 0; - if (!g_cc || io == NULL) + if (!g_cc) return EINVAL; - + if (!io) + return set_error(g_cc, EINVAL, POSIX_ERROR, "IO handler not" + " initialized"); + /*create io handler*/ new_io_h = (io_handler *) calloc(1, sizeof(*new_io_h)); if (!new_io_h) return set_error(g_cc, ENOMEM, POSIX_ERROR, "Not enough memory"); /* allocate memory and initialize io content*/ - if ((err = init_io_content(g_cc ,new_io_h))){ + if ((err = init_io_content(g_cc, new_io_h))){ free(new_io_h); return err; } @@ -75,8 +78,8 @@ static int init_io_content(glb_ctx *cc, io_handler *io) } canl_err_code -canl_io_connect(canl_ctx cc, canl_io_handler io, const char *host, const char *service, - int port, gss_OID_set auth_mechs, +canl_io_connect(canl_ctx cc, canl_io_handler io, const char *host, + const char *service, int port, gss_OID_set auth_mechs, int flags, struct timeval *timeout) { int err = 0; @@ -482,13 +485,13 @@ find_mech(gss_OID oid) return &canl_mech_ssl; } -canl_err_code +canl_err_code canl_princ_name(canl_ctx cc, const canl_principal princ, char **name) { struct _principal_int *p = (struct _principal_int *) princ; if (cc == NULL) - return -1; + return EINVAL; if (princ == NULL) return set_error(cc, EINVAL, POSIX_ERROR, "Principal not initialized"); diff --git a/emi.canl.canl-c/src/canl_ssl.c b/emi.canl.canl-c/src/canl_ssl.c index 37d7ad9..d20dd43 100644 --- a/emi.canl.canl-c/src/canl_ssl.c +++ b/emi.canl.canl-c/src/canl_ssl.c @@ -371,6 +371,10 @@ ssl_server_init(glb_ctx *cc, void *v_ctx, void **ctx) return err; } } + if (err && (!m_ctx->cert_key || !m_ctx->cert_key->cert || + !m_ctx->cert_key->key)) + update_error(cc, EINVAL, POSIX_ERROR, "No key or certificate" + " found"); free(user_cert_fn); user_cert_fn = NULL; @@ -447,13 +451,16 @@ ssl_client_init(glb_ctx *cc, void *v_ctx, void **ctx) return EINVAL; if (ssl_ctx == NULL) - return set_error(cc, EINVAL, POSIX_ERROR, "SSL not initialized"); + return set_error(cc, EINVAL, POSIX_ERROR, "SSL context not" + " initialized"); err = proxy_get_filenames(0, NULL, NULL, &user_proxy_fn, &user_cert_fn, &user_key_fn); - if (!err && (!m_ctx->cert_key || !m_ctx->cert_key->cert || !m_ctx->cert_key->key)) { + if (!err && (!m_ctx->cert_key || !m_ctx->cert_key->cert || + !m_ctx->cert_key->key)) { if (user_proxy_fn && !access(user_proxy_fn, R_OK)) { - err = do_set_ctx_own_cert_file(cc, m_ctx, NULL, NULL, user_proxy_fn); + err = do_set_ctx_own_cert_file(cc, m_ctx, NULL, NULL, + user_proxy_fn); if (err) return err; } @@ -473,6 +480,11 @@ ssl_client_init(glb_ctx *cc, void *v_ctx, void **ctx) } } + if (err && (!m_ctx->cert_key || !m_ctx->cert_key->cert || + !m_ctx->cert_key->key)) + update_error(cc, EINVAL, POSIX_ERROR, "No key or certificate" + " found"); + free(user_cert_fn); user_cert_fn = NULL; free(user_key_fn); -- 1.8.2.3