return NULL;
for (i = 0; i < sizeof(mechs)/sizeof(mechs[0]); i++)
- mechs[i]->initialize(ctx, &mechs[i]->glb_ctx);
+ mechs[i]->initialize(ctx); /*TODO every mech must have its own ctx*/
return ctx;
}
break;
case TRY_AGAIN:
err = update_error(glb_cc, ETIMEDOUT, POSIX_ERROR,
- "Cannot resolve the server hostname (%s)", host);
+ " Timeout reached when connecting to (%s)", host);
goto end;
case NETDB_INTERNAL:
err = update_error(glb_cc, errno, POSIX_ERROR,
if (err)
continue;
- err = mech->client_init(glb_cc, mech->glb_ctx, &ctx);
+ err = mech->client_init(glb_cc, &ctx);
if (err) {
canl_io_close(glb_cc, io_cc);
continue;
io_cc->sock = new_fd;
- err = mech->server_init(glb_cc, mech->glb_ctx, &conn_ctx);
+ err = mech->server_init(glb_cc, &conn_ctx);
if (err)
goto end;
/* XXX Do we need to keep these two:? */
canl_err_origin err_orig;
long original_err_code;
+ void *mech_ctx;
} glb_ctx;
typedef struct _asyn_result {
typedef struct canl_mech {
CANL_AUTH_MECHANISM mech;
- void *glb_ctx;
canl_err_code (*initialize)
- (glb_ctx *, void **);
+ (glb_ctx *);
canl_err_code (*set_flags)
(glb_ctx *cc, unsigned int *mech_flags, unsigned int flags);
(glb_ctx *, void *);
canl_err_code (*client_init)
- (glb_ctx *, void *, void **);
+ (glb_ctx *, void **);
canl_err_code (*server_init)
- (glb_ctx *, void *, void **);
+ (glb_ctx *, void **);
canl_err_code (*free_ctx)
(glb_ctx *, void *);
static canl_err_code
-ssl_initialize(glb_ctx *cc, void **v_glb_ctx)
+ssl_initialize(glb_ctx *cc)
{
- mech_glb_ctx **m_glb_ctx = (mech_glb_ctx **)v_glb_ctx;
+ mech_glb_ctx **m_glb_ctx = (mech_glb_ctx **)cc->mech_ctx;
int err = 0;
char *ca_cert_fn, *user_cert_fn, *user_key_fn, *user_proxy_fn;
char *ca_cert_dirn = NULL;
}
static canl_err_code
-ssl_server_init(glb_ctx *cc, void *v_ctx, void **ctx)
+ssl_server_init(glb_ctx *cc, void **ctx)
{
- mech_glb_ctx *m_ctx = (mech_glb_ctx *)v_ctx;
- SSL_CTX *ssl_ctx = (SSL_CTX *) m_ctx->mech_ctx;
+ mech_glb_ctx *m_ctx = (mech_glb_ctx *)cc->mech_ctx;
+ SSL_CTX *ssl_ctx = NULL;
SSL *ssl = NULL;
char *user_cert_fn, *user_key_fn, *user_proxy_fn;
int err = 0;
if (cc == NULL)
return EINVAL;
- if (ssl_ctx == NULL)
- return set_error(cc, EINVAL, POSIX_ERROR, "SSL not initialized");
+ if (!m_ctx || !m_ctx->mech_ctx)
+ return set_error(cc, EINVAL, POSIX_ERROR, "SSL context not"
+ " initialized");
+ ssl_ctx = (SSL_CTX *) m_ctx->mech_ctx;
err = proxy_get_filenames(0, NULL, NULL, &user_proxy_fn,
&user_cert_fn, &user_key_fn);
}
static canl_err_code
-ssl_client_init(glb_ctx *cc, void *v_ctx, void **ctx)
+ssl_client_init(glb_ctx *cc, void **ctx)
{
- mech_glb_ctx *m_ctx = (mech_glb_ctx *)v_ctx;
- SSL_CTX *ssl_ctx = (SSL_CTX *) m_ctx->mech_ctx;
+ mech_glb_ctx *m_ctx = (mech_glb_ctx *)cc->mech_ctx;
+ SSL_CTX *ssl_ctx = NULL;
SSL *ssl = NULL;
int err = 0, i = 0;
char *user_cert_fn, *user_key_fn, *user_proxy_fn;
user_cert_fn = user_key_fn = user_proxy_fn = NULL;
-
+
if (cc == NULL)
return EINVAL;
-
- if (ssl_ctx == NULL)
+
+ if (!m_ctx || !m_ctx->mech_ctx)
return set_error(cc, EINVAL, POSIX_ERROR, "SSL context not"
" initialized");
+ ssl_ctx = (SSL_CTX *) m_ctx->mech_ctx;
err = proxy_get_filenames(0, NULL, NULL, &user_proxy_fn,
&user_cert_fn, &user_key_fn);
{
glb_ctx *glb_cc = (glb_ctx*) cc;
int err = 0;
+ mech_glb_ctx *m_ctx = (mech_glb_ctx *)glb_cc->mech_ctx;
- mech_glb_ctx *m_ctx = canl_mech_ssl.glb_ctx;
+ if (!m_ctx)
+ return set_error(cc, EINVAL, POSIX_ERROR, "SSL context not"
+ " initialized");
if (!cc)
return EINVAL;
canl_ctx_set_crl_dir(canl_ctx cc, const char *dir)
{
glb_ctx *glb_cc = (glb_ctx*) cc;
- struct canl_mech *mech = find_mech(GSS_C_NO_OID); //TODO for now
- mech_glb_ctx *m_ctx = (mech_glb_ctx *)mech->glb_ctx;
+ mech_glb_ctx *m_ctx = (mech_glb_ctx *)glb_cc->mech_ctx;
if (!cc)
return EINVAL;
+ if (!m_ctx)
+ return set_error(glb_cc, EINVAL, POSIX_ERROR, "SSL context not"
+ " initialized");
+
return ssl_set_dir(glb_cc, &m_ctx->crl_dir, dir);
}
canl_ctx_set_ca_dir(canl_ctx cc, const char *dir)
{
glb_ctx *glb_cc = (glb_ctx*) cc;
- struct canl_mech *mech = find_mech(GSS_C_NO_OID); //TODO for now
- mech_glb_ctx *m_ctx = (mech_glb_ctx *)mech->glb_ctx;
+ mech_glb_ctx *m_ctx = (mech_glb_ctx *)glb_cc->mech_ctx;
if (!cc)
return EINVAL;
+ if (!m_ctx)
+ return set_error(glb_cc, EINVAL, POSIX_ERROR, "SSL context not"
+ " initialized");
+
return ssl_set_dir(glb_cc, &m_ctx->ca_dir, dir);
}
return 0;
}
-mech_glb_ctx ssl_glb_ctx;
-
canl_mech canl_mech_ssl = {
TLS,
- &ssl_glb_ctx,
ssl_initialize,
ssl_set_flags,
ssl_finish,