From b8e0c2f55ae4875bbd7d336f4f20a1a5a7332aea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kou=C5=99il?= Date: Tue, 10 Feb 2009 14:04:56 +0000 Subject: [PATCH] Reverted to API compatible with 3.1 - glite_gsplugin_set_credential renamed to glite_gsplugin_use_credential - glite_gsplugin_set_credential takes filenames again - examples changed accordingly --- .../examples/wscalc_srv_ex.c | 25 +++++++++++++--------- .../examples/wscalc_srv_ex2.c | 17 ++++++++++----- .../interface/glite_gsplugin.h | 3 ++- .../src/glite_gsplugin.c | 19 ++++++++-------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c index e79555a..d711b9f 100644 --- a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c +++ b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c @@ -46,23 +46,28 @@ main(int argc, char **argv) } } - if ( cert || key ) { - if ( glite_gsplugin_init_context(&ctx) ) { perror("init context"); exit(1); } - if (edg_wll_gss_acquire_cred_gsi(cert, key, &cred, NULL) != 0) { - fprintf (stderr, "Failed to set credentials\n"); - exit(1); - } - glite_gsplugin_set_credential(ctx, cred); - } - soap_init(&soap); soap_set_namespaces(&soap, namespaces); - if ( soap_register_plugin_arg(&soap, glite_gsplugin, ctx? : NULL) ) { + if ( soap_register_plugin_arg(&soap, glite_gsplugin, NULL) ) { fprintf(stderr, "Can't register plugin\n"); exit(1); } + if ( cert || key ) { + ctx = glite_gsplugin_get_context(&soap); + if (ctx == NULL) { + fprintf(stderr, "Can't get context\n"); + exit(1); + } + + if (glite_gsplugin_set_credential(ctx, cert, key) != 0) { + fprintf(stderr, "Can't set credentials: %s\n", + glite_gsplugin_errdesc(&soap)); + exit(1); + } + } + if ( soap_bind(&soap, NULL, 19999, 100) < 0 ) { soap_print_fault(&soap, stderr); exit(1); diff --git a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c index cdab78c..d65e625 100644 --- a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c +++ b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c @@ -31,6 +31,8 @@ main(int argc, char **argv) { struct soap soap; edg_wll_GssStatus gss_code; + edg_wll_GssCred cred = NULL; + edg_wll_GssConnection connection; glite_gsplugin_Context ctx; struct sockaddr_in a; int alen; @@ -56,16 +58,18 @@ main(int argc, char **argv) } } - if ( edg_wll_gss_acquire_cred_gsi(cert_filename, key_filename, &ctx->cred, &gss_code) ) { + if ( edg_wll_gss_acquire_cred_gsi(cert_filename, key_filename, &cred, &gss_code) ) { edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg); fprintf(stderr, "%s\n", msg); free(msg); exit(1); } - if (ctx->cred->name) { - printf("server running with certificate: %s\n", ctx->cred->name); + if (cred->name) { + printf("server running with certificate: %s\n", cred->name); } + glite_gsplugin_use_credential(ctx, cred); + soap_init(&soap); soap_set_namespaces(&soap, namespaces); @@ -81,7 +85,6 @@ main(int argc, char **argv) a.sin_addr.s_addr = INADDR_ANY; if ( bind(sock, (struct sockaddr *)&a, sizeof(a)) ) { perror("bind()"); exit(1); } if ( listen(sock, 100) ) { perror("listen()"); exit(1); } - if ( !(ctx->connection = malloc(sizeof(*ctx->connection))) ) exit(1); bzero((char *) &a, alen); @@ -94,13 +97,15 @@ main(int argc, char **argv) perror("accept"); exit(1); } - if ( edg_wll_gss_accept(ctx->cred,conn,ctx->timeout,ctx->connection,&gss_code) ){ + if ( edg_wll_gss_accept(cred,conn,ctx->timeout,&connection,&gss_code) ){ edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg); fprintf(stderr, "%s\n", msg); free(msg); exit(1); } + glite_gsplugin_set_connection(ctx, &connection); + printf("serving connection\n"); if ( soap_serve(&soap) ) { soap_print_fault(&soap, stderr); @@ -109,11 +114,13 @@ main(int argc, char **argv) soap_destroy(&soap); /* clean up class instances */ soap_end(&soap); /* clean up everything and close socket */ + edg_wll_gss_close(&connection, NULL); } soap_done(&soap); /* close master socket */ glite_gsplugin_free_context(ctx); + edg_wll_gss_release_cred(&cred, NULL); return 0; } diff --git a/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h b/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h index 7bee0f2..e1e7a91 100644 --- a/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h +++ b/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h @@ -20,7 +20,8 @@ extern void *glite_gsplugin_get_udata(struct soap *); extern void glite_gsplugin_set_udata(struct soap *, void *); extern void glite_gsplugin_set_timeout(glite_gsplugin_Context, struct timeval const *); -extern void glite_gsplugin_set_credential(glite_gsplugin_Context, edg_wll_GssCred); +extern int glite_gsplugin_set_credential(glite_gsplugin_Context, const char *, const char *); +extern void glite_gsplugin_use_credential(glite_gsplugin_Context, edg_wll_GssCred); extern int glite_gsplugin_set_connection(glite_gsplugin_Context, edg_wll_GssConnection *); extern int glite_gsplugin(struct soap *, struct soap_plugin *, void *); diff --git a/org.glite.security.gsoap-plugin/src/glite_gsplugin.c b/org.glite.security.gsoap-plugin/src/glite_gsplugin.c index 711a4cd..444bf36 100644 --- a/org.glite.security.gsoap-plugin/src/glite_gsplugin.c +++ b/org.glite.security.gsoap-plugin/src/glite_gsplugin.c @@ -113,33 +113,34 @@ void glite_gsplugin_set_timeout(glite_gsplugin_Context ctx, struct timeval const else ctx->timeout = NULL; } -#if 0 int glite_gsplugin_set_credential(glite_gsplugin_Context ctx, const char *cert, const char *key) { edg_wll_GssStatus gss_code; + edg_wll_GssCred cred = NULL; + int ret; - ret = edg_wll_gss_acquire_cred_gsi((char *)cert, (char *)key, &ctx->cred, &gss_code); + ret = edg_wll_gss_acquire_cred_gsi((char *)cert, (char *)key, &cred, &gss_code); if (ret) { - /* XXX propagate error description */ + edg_wll_gss_get_error(&gss_code, "failed to load GSI credentials", + &ctx->error_msg); return EINVAL; } - free(ctx->cert_filename); - free(ctx->key_filename); + if (ctx->internal_credentials && ctx->cred != NULL) + edg_wll_gss_release_cred(&ctx->cred, NULL); - ctx->cert_filename = strdup(cert); - ctx->key_filename = strdup(key); + ctx->cred = cred; + ctx->internal_credentials = 1; return 0; } -#endif void -glite_gsplugin_set_credential(glite_gsplugin_Context ctx, +glite_gsplugin_use_credential(glite_gsplugin_Context ctx, edg_wll_GssCred cred) { ctx->cred = cred; -- 1.8.2.3