From: Marcel Poul Date: Wed, 18 Jan 2012 21:47:22 +0000 (+0000) Subject: canl_cred_save_(chain, cert) methods def. X-Git-Tag: emi-canl-c_R_1_0_0_0~23 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=0c822f01f328081e15e6e736e9e5b1d3898f2d0b;p=jra1mw.git canl_cred_save_(chain, cert) methods def. --- diff --git a/emi.canl.canl-c/src/canl_cred.c b/emi.canl.canl-c/src/canl_cred.c index 525209c..9a8f38d 100644 --- a/emi.canl.canl-c/src/canl_cred.c +++ b/emi.canl.canl-c/src/canl_cred.c @@ -278,14 +278,66 @@ canl_cred_save_proxyfile(canl_ctx ctx, canl_cred cred, const char *proxy_file) canl_err_code CANL_CALLCONV canl_cred_save_cert(canl_ctx ctx, canl_cred cred, X509 ** cert) -{ - return ENOSYS; +{ + glb_ctx *cc = (glb_ctx*) ctx; + creds *crd = (creds*) cred; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + if (!cert) + return set_error(cc, EINVAL, posix_error, "Invalid cert." + " handler"); + + if (*cert) { + X509_free(*cert); + *cert = NULL; + } + + *cert = X509_dup(crd->c_cert); + if (*cert) + return set_error(cc, ENOMEM, posix_error, "Cannot copy" + " certificate" ); //TODO check ret val + + return 0; } canl_err_code CANL_CALLCONV canl_cred_save_chain(canl_ctx ctx, canl_cred cred, STACK_OF(X509) **cert_stack) { - return ENOSYS; + glb_ctx *cc = (glb_ctx*) ctx; + creds *crd = (creds*) cred; + int count = 0; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + + if (!cert_stack) + return set_error(cc, EINVAL, posix_error, "Invalid stack value"); + + if (!crd->c_cert_chain) + return 0; //TODO is empty cert_stack error? + + count = sk_X509_num(crd->c_cert_chain); + if (!count) + return 0; //TODO is empty cert_stack error? + + if (*cert_stack) { + sk_X509_pop_free(*cert_stack, X509_free); + *cert_stack = NULL; + } + *cert_stack = sk_X509_dup(crd->c_cert_chain); + if (*cert_stack) + return set_error(cc, ENOMEM, posix_error, "Cannot copy" + " certificate chain" ); //TODO check ret val + return 0; } /* handle requests*/