summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2009-04-22 23:49:29 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2009-04-22 23:49:29 +0000
commit52e60ecb097216e2deb0eda898d38425ed665a07 (patch)
treebf06a5fdcfe36cceb9fc2d1879ed162dd2e2b202
parentce3c049c7cc8f10e55ff7b572d6a5b7c03730091 (diff)
downloadlasso-52e60ecb097216e2deb0eda898d38425ed665a07.tar.gz
lasso-52e60ecb097216e2deb0eda898d38425ed665a07.tar.xz
lasso-52e60ecb097216e2deb0eda898d38425ed665a07.zip
Rework cleanup handling
* lasso/utils.h: change 'goto exit' for 'goto cleanup'. rename all goto_exit macros to goto_cleanup_. rename goto_cleanup_if_fail to goto_cleanup_if_fail_with_rc and add a goto_cleanup_if_fail for function which do not return an integer value. add documentation for goto_cleanup macro family. * lasso/id-ff/login.c: * lasso/id-ff/provider.c: * lasso/id-ff/server.c: * lasso/id-ff/session.c: * lasso/id-wsf/discovery.c: * lasso/id-wsf/wsf_profile.c: * lasso/saml-2.0/profile.c: * lasso/utils.h: * lasso/xml/lib_logout_request.c: * lasso/xml/tools.c: * lasso/xml/xml.c: update name of goto_exit_if_fail macros. rename 'exit' labels to 'cleanup'.
-rw-r--r--lasso/id-ff/login.c8
-rw-r--r--lasso/id-ff/provider.c32
-rw-r--r--lasso/id-ff/server.c6
-rw-r--r--lasso/id-ff/session.c12
-rw-r--r--lasso/id-wsf/discovery.c12
-rw-r--r--lasso/id-wsf/wsf_profile.c92
-rw-r--r--lasso/utils.h60
-rw-r--r--lasso/xml/lib_logout_request.c4
-rw-r--r--lasso/xml/tools.c24
-rw-r--r--lasso/xml/xml.c28
10 files changed, 162 insertions, 116 deletions
diff --git a/lasso/id-ff/login.c b/lasso/id-ff/login.c
index 8d8875ad..dd1fc8d5 100644
--- a/lasso/id-ff/login.c
+++ b/lasso/id-ff/login.c
@@ -629,13 +629,13 @@ lasso_login_process_response_status_and_assertion(LassoLogin *login)
assertion_xmlnode = lasso_node_get_original_xmlnode(LASSO_NODE(assertion));
assertion_issuer = (gchar*)xmlGetProp(assertion_xmlnode, (xmlChar*)"Issuer");
- goto_exit_if_fail(assertion_issuer, LASSO_PROFILE_ERROR_MISSING_ISSUER);
- goto_exit_if_fail(strcmp(assertion_issuer, profile->remote_providerID) == 0,
+ goto_cleanup_if_fail_with_rc(assertion_issuer, LASSO_PROFILE_ERROR_MISSING_ISSUER);
+ goto_cleanup_if_fail_with_rc(strcmp(assertion_issuer, profile->remote_providerID) == 0,
LASSO_PROFILE_ERROR_INVALID_ISSUER);
if (assertion_xmlnode) {
profile->signature_status = lasso_provider_verify_saml_signature(idp, assertion_xmlnode, NULL);
- goto_exit_if_fail(profile->signature_status == 0, profile->signature_status);
+ goto_cleanup_if_fail_with_rc(profile->signature_status == 0, profile->signature_status);
}
}
@@ -664,7 +664,7 @@ lasso_login_process_response_status_and_assertion(LassoLogin *login)
}
}
-exit:
+cleanup:
return rc;
}
diff --git a/lasso/id-ff/provider.c b/lasso/id-ff/provider.c
index c4f9db96..bb243147 100644
--- a/lasso/id-ff/provider.c
+++ b/lasso/id-ff/provider.c
@@ -703,9 +703,9 @@ lasso_provider_load_metadata_from_buffer(LassoProvider *provider, const gchar *m
lasso_release(extract);
return FALSE;
}
- goto_exit_if_fail (lasso_provider_load_metadata_from_doc(provider, doc), FALSE);
+ goto_cleanup_if_fail_with_rc (lasso_provider_load_metadata_from_doc(provider, doc), FALSE);
lasso_assign_string(provider->metadata_filename, metadata);
-exit:
+cleanup:
lasso_release_doc(doc);
return rc;
@@ -731,11 +731,11 @@ lasso_provider_load_metadata(LassoProvider *provider, const gchar *path)
return FALSE;
}
doc = xmlParseFile(path);
- goto_exit_if_fail(doc != NULL, FALSE);
- goto_exit_if_fail(lasso_provider_load_metadata_from_doc(provider, doc), FALSE);
+ goto_cleanup_if_fail_with_rc(doc != NULL, FALSE);
+ goto_cleanup_if_fail_with_rc(lasso_provider_load_metadata_from_doc(provider, doc), FALSE);
/** Conserve metadata path for future dump/reload */
lasso_assign_string(provider->metadata_filename, path);
-exit:
+cleanup:
lasso_release_doc(doc);
return rc;
}
@@ -1090,16 +1090,16 @@ lasso_provider_verify_saml_signature(LassoProvider *provider,
(strcmp((char*)node_ns, LASSO_SAML2_ASSERTION_HREF) == 0)) {
id_attribute_name = "ID";
}
- goto_exit_if_fail(id_attribute_name, LASSO_PARAM_ERROR_INVALID_VALUE);
+ goto_cleanup_if_fail_with_rc(id_attribute_name, LASSO_PARAM_ERROR_INVALID_VALUE);
/* Get provider credentials */
public_key = lasso_provider_get_public_key(provider);
keys_manager = lasso_load_certs_from_pem_certs_chain_file(provider->ca_cert_chain);
- goto_exit_if_fail_with_warning(public_key || keys_manager,
+ goto_cleanup_if_fail_with_rc_with_warning(public_key || keys_manager,
LASSO_DS_ERROR_PUBLIC_KEY_LOAD_FAILED);
rc = lasso_verify_signature(signed_node, doc, id_attribute_name, keys_manager, public_key,
NO_OPTION, NULL);
lasso_release_key_manager(keys_manager);
-exit:
+cleanup:
lasso_release_key_manager(keys_manager);
return rc;
}
@@ -1144,7 +1144,7 @@ lasso_provider_verify_signature(LassoProvider *provider,
msg = g_malloc(strlen(message));
len = xmlSecBase64Decode((xmlChar*)message, (xmlChar*)msg, strlen(message));
if (len < 0) {
- goto_exit_with_rc(LASSO_PROFILE_ERROR_INVALID_MSG);
+ goto_cleanup_with_rc(LASSO_PROFILE_ERROR_INVALID_MSG);
}
doc = lasso_xml_parse_memory(msg, strlen(msg));
} else {
@@ -1159,7 +1159,7 @@ lasso_provider_verify_signature(LassoProvider *provider,
if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr ) {
xmlnode = xpathObj->nodesetval->nodeTab[0];
}
- goto_exit_if_fail (xmlnode != NULL, LASSO_PROFILE_ERROR_INVALID_MSG);
+ goto_cleanup_if_fail_with_rc (xmlnode != NULL, LASSO_PROFILE_ERROR_INVALID_MSG);
} else {
xmlnode = xmlDocGetRootElement(doc);
}
@@ -1186,7 +1186,7 @@ lasso_provider_verify_signature(LassoProvider *provider,
}
}
- goto_exit_if_fail (sign != NULL, LASSO_DS_ERROR_SIGNATURE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc (sign != NULL, LASSO_DS_ERROR_SIGNATURE_NOT_FOUND);
if (id_attr_name) {
xmlChar *id_value = xmlGetProp(xmlnode, (xmlChar*)id_attr_name);
@@ -1201,23 +1201,23 @@ lasso_provider_verify_signature(LassoProvider *provider,
if (x509data != NULL && provider->ca_cert_chain != NULL) {
keys_mngr = lasso_load_certs_from_pem_certs_chain_file(
provider->ca_cert_chain);
- goto_exit_if_fail (keys_mngr != NULL, LASSO_DS_ERROR_CA_CERT_CHAIN_LOAD_FAILED);
+ goto_cleanup_if_fail_with_rc (keys_mngr != NULL, LASSO_DS_ERROR_CA_CERT_CHAIN_LOAD_FAILED);
}
dsigCtx = xmlSecDSigCtxCreate(keys_mngr);
if (keys_mngr == NULL) {
dsigCtx->signKey = xmlSecKeyDuplicate(lasso_provider_get_public_key(provider));
- goto_exit_if_fail (dsigCtx->signKey != NULL, LASSO_DS_ERROR_PUBLIC_KEY_LOAD_FAILED);
+ goto_cleanup_if_fail_with_rc (dsigCtx->signKey != NULL, LASSO_DS_ERROR_PUBLIC_KEY_LOAD_FAILED);
}
- goto_exit_if_fail (xmlSecDSigCtxVerify(dsigCtx, sign) >= 0, LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED);
+ goto_cleanup_if_fail_with_rc (xmlSecDSigCtxVerify(dsigCtx, sign) >= 0, LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED);
if (dsigCtx->status != xmlSecDSigStatusSucceeded) {
rc = LASSO_DS_ERROR_INVALID_SIGNATURE;
- goto exit;
+ goto cleanup;
}
-exit:
+cleanup:
lasso_release_string(msg);
lasso_release_key_manager(keys_mngr);
lasso_release_signature_context(dsigCtx);
diff --git a/lasso/id-ff/server.c b/lasso/id-ff/server.c
index 4a14bfbd..6998685d 100644
--- a/lasso/id-ff/server.c
+++ b/lasso/id-ff/server.c
@@ -321,10 +321,10 @@ lasso_server_load_affiliation(LassoServer *server, const gchar *filename)
int rc = 0;
doc = xmlParseFile(filename);
- goto_exit_if_fail (doc != NULL, LASSO_XML_ERROR_INVALID_FILE);
+ goto_cleanup_if_fail_with_rc (doc != NULL, LASSO_XML_ERROR_INVALID_FILE);
node = xmlDocGetRootElement(doc);
- goto_exit_if_fail (node != NULL && node->ns != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc (node != NULL && node->ns != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
if (provider->private_data->conformance == LASSO_PROTOCOL_SAML_2_0) {
rc = lasso_saml20_server_load_affiliation(server, node);
@@ -332,7 +332,7 @@ lasso_server_load_affiliation(LassoServer *server, const gchar *filename)
/* affiliations are not supported in ID-FF 1.2 mode */
rc = LASSO_ERROR_UNIMPLEMENTED;
}
-exit:
+cleanup:
lasso_release_doc(doc);
return rc;
}
diff --git a/lasso/id-ff/session.c b/lasso/id-ff/session.c
index a4bd629b..a45ff83b 100644
--- a/lasso/id-ff/session.c
+++ b/lasso/id-ff/session.c
@@ -498,17 +498,17 @@ xmlNode_to_base64(xmlNode *node) {
handler = xmlFindCharEncodingHandler("utf-8");
if (! handler)
- goto exit;
+ goto cleanup;
buf = xmlAllocOutputBuffer(handler);
if (! buf)
- goto exit;
+ goto cleanup;
xmlNodeDumpOutput(buf, NULL, node, 0, 0, "utf-8");
xmlOutputBufferFlush(buf);
buffer = buf->conv ? buf->conv->content : buf->buffer->content;
ret = xmlSecBase64Encode(buffer, strlen((char*)buffer), 0);
-exit:
+cleanup:
if (buf)
xmlOutputBufferClose(buf);
@@ -607,15 +607,15 @@ base64_to_xmlNode(xmlChar *buffer) {
decoded = g_malloc(l1);
l2 = xmlSecBase64Decode(buffer, decoded, l1);
if (l2 < 0)
- goto exit;
+ goto cleanup;
doc = xmlParseMemory((char*)decoded, l2);
if (doc == NULL)
- goto exit;
+ goto cleanup;
ret = xmlDocGetRootElement(doc);
if (ret) {
ret = xmlCopyNode(ret, 1);
}
-exit:
+cleanup:
lasso_release(decoded);
lasso_release_doc(doc);
diff --git a/lasso/id-wsf/discovery.c b/lasso/id-wsf/discovery.c
index 20a7208d..1fb450c6 100644
--- a/lasso/id-wsf/discovery.c
+++ b/lasso/id-wsf/discovery.c
@@ -447,12 +447,12 @@ lasso_discovery_init_query(LassoDiscovery *discovery, const gchar *security_mech
* object with get getted resource offering. get discovery service
* resource id from principal assertion */
offering = lasso_discovery_get_resource_offering_auto(discovery, LASSO_DISCO_HREF);
- goto_exit_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(offering),
+ goto_cleanup_if_fail_with_rc(LASSO_IS_DISCO_RESOURCE_OFFERING(offering),
LASSO_PROFILE_ERROR_MISSING_RESOURCE_OFFERING);
lasso_wsf_profile_set_resource_offering(&discovery->parent, offering);
rc = lasso_wsf_profile_set_security_mech_id(&discovery->parent, security_mech_id);
if (rc)
- goto exit;
+ goto cleanup;
/* Create SOAP envelope and set profile->request */
lasso_wsf_profile_init_soap_request(profile, LASSO_NODE(query));
assign_resource_id(offering, query);
@@ -463,7 +463,7 @@ lasso_discovery_init_query(LassoDiscovery *discovery, const gchar *security_mech
} else {
rc = LASSO_WSF_PROFILE_ERROR_MISSING_ENDPOINT;
}
-exit:
+cleanup:
lasso_release_gobject(query);
return rc;
}
@@ -927,7 +927,7 @@ lasso_discovery_process_query_response_msg(LassoDiscovery *discovery, const gcha
profile = LASSO_WSF_PROFILE(discovery);
rc = lasso_wsf_profile_process_soap_response_msg(profile, message);
if (rc)
- goto exit;
+ goto cleanup;
response = LASSO_DISCO_QUERY_RESPONSE(profile->response);
if (strcmp(response->Status->code, LASSO_DISCO_STATUS_CODE_OK) != 0 &&
strcmp(response->Status->code, LASSO_DISCO_STATUS_CODE_DISCO_OK) != 0) {
@@ -948,11 +948,11 @@ lasso_discovery_process_query_response_msg(LassoDiscovery *discovery, const gcha
assertion);
} else {
rc = LASSO_PROFILE_ERROR_SESSION_NOT_FOUND;
- goto exit;
+ goto cleanup;
}
}
}
-exit:
+cleanup:
return rc;
}
diff --git a/lasso/id-wsf/wsf_profile.c b/lasso/id-wsf/wsf_profile.c
index af2a1122..2b9dd2f3 100644
--- a/lasso/id-wsf/wsf_profile.c
+++ b/lasso/id-wsf/wsf_profile.c
@@ -118,9 +118,9 @@ lasso_wsf_profile_comply_with_saml_authentication(LassoWsfProfile *profile)
/* Lookup in the session the credential ref from the description and
* add them to the SOAP header wsse:Security. */
/* FIXME: should we really add every credentials to the message ? */
- goto_exit_if_fail(description != NULL, LASSO_WSF_PROFILE_ERROR_MISSING_DESCRIPTION);
+ goto_cleanup_if_fail_with_rc(description != NULL, LASSO_WSF_PROFILE_ERROR_MISSING_DESCRIPTION);
credentialRefs = description->CredentialRef;
- goto_exit_if_fail(credentialRefs != NULL, LASSO_WSF_PROFILE_ERROR_MISSING_CREDENTIAL_REF);
+ goto_cleanup_if_fail_with_rc(credentialRefs != NULL, LASSO_WSF_PROFILE_ERROR_MISSING_CREDENTIAL_REF);
while (credentialRefs) {
char *ref = (char*)credentialRefs->data;
xmlNode *assertion = lasso_session_get_assertion_by_id(session, ref);
@@ -133,7 +133,7 @@ lasso_wsf_profile_comply_with_saml_authentication(LassoWsfProfile *profile)
header = soap->Header;
lasso_list_add_gobject(header->Other, wsse_security);
wsse_security = NULL;
-exit:
+cleanup:
if (wsse_security) {
lasso_release_gobject(wsse_security);
}
@@ -678,11 +678,11 @@ lasso_wsf_profile_build_soap_request_msg(LassoWsfProfile *profile)
if (lasso_security_mech_id_is_saml_authentication(sec_mech_id)) {
rc = lasso_wsf_profile_add_saml_signature(profile, doc);
if (rc != 0) {
- goto exit;
+ goto cleanup;
}
} else if (lasso_security_mech_id_is_null_authentication(sec_mech_id) == FALSE) {
rc = LASSO_WSF_PROFILE_ERROR_UNSUPPORTED_SECURITY_MECHANISM;
- goto exit;
+ goto cleanup;
}
/* Dump soap request */
handler = xmlFindCharEncodingHandler("utf-8");
@@ -693,7 +693,7 @@ lasso_wsf_profile_build_soap_request_msg(LassoWsfProfile *profile)
(char*)(buf->conv ? buf->conv->content : buf->buffer->content));
lasso_release_output_buffer(buf);
-exit:
+cleanup:
lasso_release_doc(doc);
return rc;
}
@@ -752,16 +752,16 @@ lasso_wsf_profile_process_soap_request_msg(LassoWsfProfile *profile, const gchar
g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE);
doc = lasso_xml_parse_memory(message, strlen(message));
- goto_exit_if_fail (doc != NULL, critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG));
+ goto_cleanup_if_fail_with_rc (doc != NULL, critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG));
/* Get soap request and his message id */
envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_xmlNode(xmlDocGetRootElement(doc)));
if (LASSO_IS_SOAP_ENVELOPE(envelope)) {
lasso_assign_gobject(profile->soap_envelope_request, LASSO_SOAP_ENVELOPE(envelope));
} else {
- goto_exit_if_fail(FALSE, LASSO_PROFILE_ERROR_INVALID_SOAP_MSG);
+ goto_cleanup_if_fail_with_rc(FALSE, LASSO_PROFILE_ERROR_INVALID_SOAP_MSG);
}
- goto_exit_if_fail(envelope != NULL, LASSO_SOAP_ERROR_MISSING_ENVELOPE);
- goto_exit_if_fail(envelope->Body != NULL, LASSO_SOAP_ERROR_MISSING_BODY);
+ goto_cleanup_if_fail_with_rc(envelope != NULL, LASSO_SOAP_ERROR_MISSING_ENVELOPE);
+ goto_cleanup_if_fail_with_rc(envelope->Body != NULL, LASSO_SOAP_ERROR_MISSING_BODY);
if (envelope->Body->any) {
profile->request = LASSO_NODE(envelope->Body->any->data);
} else {
@@ -770,20 +770,20 @@ lasso_wsf_profile_process_soap_request_msg(LassoWsfProfile *profile, const gchar
}
/* Get the correlation header */
- goto_exit_if_fail(envelope->Header != NULL, LASSO_SOAP_ERROR_MISSING_HEADER);
+ goto_cleanup_if_fail_with_rc(envelope->Header != NULL, LASSO_SOAP_ERROR_MISSING_HEADER);
for (iter = envelope->Header->Other; iter != NULL; iter = iter->next) {
if (LASSO_IS_SOAP_BINDING_CORRELATION(iter->data)) {
correlation = LASSO_SOAP_BINDING_CORRELATION(iter->data);
break;
}
}
- goto_exit_if_fail (correlation != NULL && correlation->messageID != NULL,
+ goto_cleanup_if_fail_with_rc (correlation != NULL && correlation->messageID != NULL,
LASSO_WSF_PROFILE_ERROR_MISSING_CORRELATION);
messageId = correlation->messageID;
/* Comply with security mechanism */
if (lasso_security_mech_id_is_null_authentication(security_mech_id) == FALSE) {
/** FIXME: add security mechanisms */
- goto_exit_if_fail(FALSE, LASSO_WSF_PROFILE_ERROR_UNSUPPORTED_SECURITY_MECHANISM);
+ goto_cleanup_if_fail_with_rc(FALSE, LASSO_WSF_PROFILE_ERROR_UNSUPPORTED_SECURITY_MECHANISM);
}
/* Set soap response */
@@ -792,7 +792,7 @@ lasso_wsf_profile_process_soap_request_msg(LassoWsfProfile *profile, const gchar
LASSO_PROVIDER(profile->server)->ProviderID);
lasso_assign_gobject(LASSO_WSF_PROFILE(profile)->soap_envelope_response, envelope);
-exit:
+cleanup:
if (envelope) {
lasso_release_gobject(envelope);
}
@@ -827,17 +827,17 @@ lasso_wsf_profile_process_soap_response_msg(LassoWsfProfile *profile, const gcha
LASSO_PARAM_ERROR_INVALID_VALUE);
doc = lasso_xml_parse_memory(message, strlen(message));
- goto_exit_if_fail (doc != NULL, critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG));
+ goto_cleanup_if_fail_with_rc (doc != NULL, critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG));
root = xmlDocGetRootElement(doc);
/* Parse the message */
envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_xmlNode(root));
if (LASSO_IS_SOAP_ENVELOPE(envelope)) {
lasso_assign_gobject(profile->soap_envelope_response, LASSO_SOAP_ENVELOPE(envelope));
} else {
- goto_exit_if_fail(FALSE, LASSO_PROFILE_ERROR_INVALID_SOAP_MSG);
+ goto_cleanup_if_fail_with_rc(FALSE, LASSO_PROFILE_ERROR_INVALID_SOAP_MSG);
}
- goto_exit_if_fail(envelope != NULL, LASSO_SOAP_ERROR_MISSING_ENVELOPE);
- goto_exit_if_fail(envelope->Body != NULL, LASSO_SOAP_ERROR_MISSING_BODY);
+ goto_cleanup_if_fail_with_rc(envelope != NULL, LASSO_SOAP_ERROR_MISSING_ENVELOPE);
+ goto_cleanup_if_fail_with_rc(envelope->Body != NULL, LASSO_SOAP_ERROR_MISSING_BODY);
if (envelope->Body->any) {
lasso_assign_gobject(profile->response, LASSO_NODE(envelope->Body->any->data));
} else {
@@ -865,7 +865,7 @@ lasso_wsf_profile_process_soap_response_msg(LassoWsfProfile *profile, const gcha
rc = LASSO_WSF_PROFILE_ERROR_SOAP_FAULT;
}
}
-exit:
+cleanup:
if (envelope) {
lasso_release_gobject(envelope);
}
@@ -1063,7 +1063,7 @@ add_signature_template(LassoServer *server, xmlDoc *doc, xmlNode *node, xmlNode
break;
default:
rc = LASSO_DS_ERROR_SIGNATURE_TMPL_CREATION_FAILED;
- goto exit;
+ goto cleanup;
}
@@ -1074,7 +1074,7 @@ add_signature_template(LassoServer *server, xmlDoc *doc, xmlNode *node, xmlNode
if (node) {
xmlAddChild(node, signature);
}
-exit:
+cleanup:
return rc;
}
@@ -1085,14 +1085,14 @@ add_reference_to_non_enveloping_id(xmlNode *signature, xmlChar *id)
char *uri = NULL;
xmlNode *reference = NULL;
- goto_exit_if_fail(signature != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
- goto_exit_if_fail(id != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
+ goto_cleanup_if_fail_with_rc(signature != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
+ goto_cleanup_if_fail_with_rc(id != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
uri = g_strdup_printf("#%s", id);
reference = xmlSecTmplSignatureAddReference(signature,
xmlSecTransformSha1Id, NULL, (xmlChar*)uri, NULL);
/* add exclusive C14N transform */
xmlSecTmplReferenceAddTransform(reference, xmlSecTransformExclC14NId);
-exit:
+cleanup:
lasso_release(uri);
return rc;
}
@@ -1114,18 +1114,18 @@ create_signature_context(LassoServer *server, xmlSecDSigCtx **ctx_ptr) {
dsig_ctx->signKey = xmlSecCryptoAppKeyLoad(server->private_key,
xmlSecKeyDataFormatPem,
NULL, NULL, NULL);
- goto_exit_if_fail(dsig_ctx->signKey != NULL, LASSO_DS_ERROR_PRIVATE_KEY_LOAD_FAILED);
+ goto_cleanup_if_fail_with_rc(dsig_ctx->signKey != NULL, LASSO_DS_ERROR_PRIVATE_KEY_LOAD_FAILED);
/* Load the certificate chain if needed */
if (server->certificate) {
gint ret = xmlSecCryptoAppKeyCertLoad(dsig_ctx->signKey,
server->certificate,
xmlSecKeyDataFormatPem);
- goto_exit_if_fail(ret >= 0, LASSO_DS_ERROR_CERTIFICATE_LOAD_FAILED);
+ goto_cleanup_if_fail_with_rc(ret >= 0, LASSO_DS_ERROR_CERTIFICATE_LOAD_FAILED);
}
/* Transfer the reference */
*ctx_ptr = dsig_ctx;
dsig_ctx = NULL;
-exit:
+cleanup:
if (dsig_ctx) {
xmlSecDSigCtxDestroy(dsig_ctx);
}
@@ -1213,10 +1213,10 @@ lasso_wsf_profile_add_saml_signature(LassoWsfProfile *wsf_profile, xmlDoc *doc)
(xmlChar*) LASSO_IS_HREF);
body = xmlSecSoap11GetBody(envelope);
xmlSecAddIDs(doc, envelope, ids);
- goto_exit_if_fail(header != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
- goto_exit_if_fail(provider != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
- goto_exit_if_fail(correlation != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
- goto_exit_if_fail(body != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(header != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(provider != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(correlation != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(body != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
provider_id = xmlGetProp(provider, (xmlChar*) "id");
correlation_id = xmlGetProp(correlation, (xmlChar*) "id");
@@ -1224,57 +1224,57 @@ lasso_wsf_profile_add_saml_signature(LassoWsfProfile *wsf_profile, xmlDoc *doc)
interaction_id = xmlGetProp(interaction, (xmlChar*) "id");
}
body_id = xmlGetProp(body, (xmlChar*) "Id");
- goto_exit_if_fail(provider_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
- goto_exit_if_fail(correlation_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
- goto_exit_if_fail(body_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
- goto_exit_if_fail(interaction == NULL || interaction_id != NULL,
+ goto_cleanup_if_fail_with_rc(provider_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(correlation_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(body_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(interaction == NULL || interaction_id != NULL,
LASSO_XML_ERROR_ATTR_NOT_FOUND);
/* Lookup the assertion Id for the KeyInfo node generation */
security = xmlSecFindNode(header, (xmlChar*) "Security", (xmlChar*) LASSO_WSSE1_HREF);
- goto_exit_if_fail(security != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(security != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
assertion = xmlSecFindNode(security, (xmlChar*) "Assertion", (xmlChar*) LASSO_SAML_ASSERTION_HREF);
- goto_exit_if_fail(assertion != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(assertion != NULL, LASSO_XML_ERROR_NODE_NOT_FOUND);
assertion_id = xmlGetProp(assertion, (xmlChar*)"AssertionID");
- goto_exit_if_fail(assertion_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc(assertion_id != NULL, LASSO_XML_ERROR_ATTR_NOT_FOUND);
/* Create the signature template */
rc = add_signature_template(wsf_profile->server, doc, security, &signature);
if (rc != 0) {
- goto exit;
+ goto cleanup;
}
rc = add_reference_to_non_enveloping_id(signature, provider_id);
if (rc != 0) {
- goto exit;
+ goto cleanup;
}
rc = add_reference_to_non_enveloping_id(signature, correlation_id);
if (rc != 0) {
- goto exit;
+ goto cleanup;
}
rc = add_reference_to_non_enveloping_id(signature, body_id);
if (rc != 0) {
- goto exit;
+ goto cleanup;
}
if (interaction_id) {
rc = add_reference_to_non_enveloping_id(signature, interaction_id);
if (rc != 0) {
- goto exit;
+ goto cleanup;
}
}
/* Create signature context */
xmlSetTreeDoc(envelope, doc);
rc = create_signature_context(wsf_profile->server, &dsig_ctx);
if (rc != 0)
- goto exit;
+ goto cleanup;
/* Sign ! */
sec_ret = xmlSecDSigCtxSign(dsig_ctx, signature);
if (sec_ret < 0) {
rc = LASSO_DS_ERROR_SIGNATURE_FAILED;
- goto exit;
+ goto cleanup;
}
add_key_info_security_token_reference(doc, signature, assertion_id);
-exit:
+cleanup:
if (dsig_ctx) {
xmlSecDSigCtxDestroy(dsig_ctx);
}
diff --git a/lasso/utils.h b/lasso/utils.h
index 4766420e..1f0e9239 100644
--- a/lasso/utils.h
+++ b/lasso/utils.h
@@ -335,26 +335,72 @@
#define lasso_null_param(name) \
g_return_val_if_fail(name != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
-#define goto_exit_with_rc(rc_value) \
+/**
+ * The following macros are made to create some formalism for function's cleanup code.
+ *
+ * The exit label should be called 'cleanup'. And for functions returning an integer error code, the
+ * error code should be named 'rc' and 'return rc;' should be the last statement of the function.
+ */
+
+/**
+ * goto_cleanup_with_rc:
+ * @rc_value: integer return value
+ *
+ * This macro jump to the 'cleanup' label and set the return value to @rc_value.
+ *
+ */
+#define goto_cleanup_with_rc(rc_value) \
{\
rc = (rc_value); \
- goto exit; \
+ goto cleanup; \
}
-#define goto_exit_if_fail(condition, rc_value) \
+/**
+ * goto_cleanup_if_fail:
+ * @condition: a boolean condition
+ *
+ * Jump to the 'cleanup' label if the @condition is FALSE.
+ *
+ */
+#define goto_cleanup_if_fail(condition) \
+ {\
+ if (! (condition) ) {\
+ goto cleanup; \
+ } \
+ }
+
+/**
+ * goto_cleanup_if_fail_with_rc:
+ * @condition: a boolean condition
+ * @rc_value: integer return value
+ *
+ * Jump to the 'cleanup' label if the @condition is FALSE and set the return value to
+ * @rc_value.
+ *
+ */
+#define goto_cleanup_if_fail_with_rc(condition, rc_value) \
{\
if (! (condition) ) {\
rc = (rc_value); \
- goto exit; \
+ goto cleanup; \
} \
}
-#define goto_exit_if_fail_with_warning(condition, rc_value) \
+/**
+ * goto_cleanup_if_fail_with_rc_with_warning:
+ * @condition: a boolean condition
+ * @rc_value: integer return value
+ *
+ * Jump to the 'cleanup' label if the @condition is FALSE and set the return value to
+ * @rc_value. Also emit a warning, showing the condition and the return value.
+ *
+ */
+#define goto_cleanup_if_fail_with_rc_with_warning(condition, rc_value) \
{\
if (! (condition) ) {\
- g_warning("%s %s", __STRING(condition), __STRING(rc_value));\
+ g_warning("%s failed, returning %s", __STRING(condition), __STRING(rc_value));\
rc = (rc_value); \
- goto exit; \
+ goto cleanup; \
} \
}
diff --git a/lasso/xml/lib_logout_request.c b/lasso/xml/lib_logout_request.c
index f5f6442a..caf41b43 100644
--- a/lasso/xml/lib_logout_request.c
+++ b/lasso/xml/lib_logout_request.c
@@ -100,7 +100,7 @@ init_from_query(LassoNode *node, char **query_fields)
rc = parent_class->init_from_query(node, query_fields);
if (! rc)
- goto exit;
+ goto cleanup;
if (request->ProviderID == NULL ||
request->NameIdentifier == NULL ||
@@ -113,7 +113,7 @@ init_from_query(LassoNode *node, char **query_fields)
lasso_assign_string(request->NameIdentifier->Format,
"LASSO_SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED");
}
- exit:
+cleanup:
return rc;
}
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index 2b18ff40..7a2b92da 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -1020,12 +1020,12 @@ lasso_verify_signature(xmlNode *signed_node, xmlDoc *doc, const char *id_attr_na
}
/* Find signature */
signature = xmlSecFindNode(signed_node, xmlSecNodeSignature, xmlSecDSigNs);
- goto_exit_if_fail (signature, LASSO_DS_ERROR_SIGNATURE_NOT_FOUND);
+ goto_cleanup_if_fail_with_rc (signature, LASSO_DS_ERROR_SIGNATURE_NOT_FOUND);
/* Create a temporary doc, if needed */
if (doc == NULL) {
doc = xmlNewDoc((xmlChar*)XML_DEFAULT_VERSION);
- goto_exit_if_fail(doc, LASSO_ERROR_OUT_OF_MEMORY);
+ goto_cleanup_if_fail_with_rc(doc, LASSO_ERROR_OUT_OF_MEMORY);
xmlDocSetRootElement(doc, signed_node);
free_the_doc = TRUE;
}
@@ -1038,11 +1038,11 @@ lasso_verify_signature(xmlNode *signed_node, xmlDoc *doc, const char *id_attr_na
/* Create DSig context */
dsigCtx = xmlSecDSigCtxCreate(keys_manager);
- goto_exit_if_fail(doc, LASSO_DS_ERROR_CONTEXT_CREATION_FAILED);
+ goto_cleanup_if_fail_with_rc(doc, LASSO_DS_ERROR_CONTEXT_CREATION_FAILED);
/* XXX: Is xmlSecTransformUriTypeSameEmpty permitted ?
* I would say yes only if signed_node == signature->parent. */
dsigCtx->enabledReferenceUris = xmlSecTransformUriTypeSameDocument;
- goto_exit_if_fail(lasso_saml_constrain_dsigctxt(dsigCtx),
+ goto_cleanup_if_fail_with_rc(lasso_saml_constrain_dsigctxt(dsigCtx),
LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED);
/* Given a public key use it to validate the signature ! */
if (public_key) {
@@ -1050,18 +1050,18 @@ lasso_verify_signature(xmlNode *signed_node, xmlDoc *doc, const char *id_attr_na
}
/* Verify signature */
- goto_exit_if_fail(xmlSecDSigCtxVerify(dsigCtx, signature) >= 0,
+ goto_cleanup_if_fail_with_rc(xmlSecDSigCtxVerify(dsigCtx, signature) >= 0,
LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED);
- goto_exit_if_fail(dsigCtx->status == xmlSecDSigStatusSucceeded,
+ goto_cleanup_if_fail_with_rc(dsigCtx->status == xmlSecDSigStatusSucceeded,
LASSO_DS_ERROR_SIGNATURE_VERIFICATION_FAILED);
/* There should be only one reference */
- goto_exit_if_fail(((signature_verification_option & NO_SINGLE_REFERENCE) == 0) &&
+ goto_cleanup_if_fail_with_rc(((signature_verification_option & NO_SINGLE_REFERENCE) == 0) &&
xmlSecPtrListGetSize(&(dsigCtx->signedInfoReferences)) == 1, LASSO_DS_ERROR_TOO_MUCH_REFERENCES);
/* The reference should be to the signed node */
reference_uri = g_strdup_printf("#%s", id);
dsig_reference_ctx = (xmlSecDSigReferenceCtx*)xmlSecPtrListGetItem(&(dsigCtx->signedInfoReferences), 0);
- goto_exit_if_fail(dsig_reference_ctx != 0 &&
+ goto_cleanup_if_fail_with_rc(dsig_reference_ctx != 0 &&
strcmp((char*)dsig_reference_ctx->uri, reference_uri) == 0,
LASSO_DS_ERROR_INVALID_REFERENCE_FOR_SAML);
/* Keep URI of all nodes signed if asked */
@@ -1083,7 +1083,7 @@ lasso_verify_signature(xmlNode *signed_node, xmlDoc *doc, const char *id_attr_na
rc = 0;
}
-exit:
+cleanup:
lasso_release_string(reference_uri);
lasso_release_signature_context(dsigCtx);
if (free_the_doc) {
@@ -1526,7 +1526,7 @@ lasso_url_add_parameters(char *url,
break;
}
encoded_key = xmlURIEscapeStr((xmlChar*)key, NULL);
- goto_exit_if_fail(encoded_key, 0);
+ goto_cleanup_if_fail_with_rc(encoded_key, 0);
value = va_arg(ap, char*);
if (! value) {
@@ -1534,7 +1534,7 @@ lasso_url_add_parameters(char *url,
break;
}
encoded_value = xmlURIEscapeStr((xmlChar*)value, NULL);
- goto_exit_if_fail(encoded_value, 0);
+ goto_cleanup_if_fail_with_rc(encoded_value, 0);
if (old_url) {
new_url = g_strdup_printf("%s&%s=%s", old_url, (char*)encoded_key, (char*)encoded_value);
@@ -1546,7 +1546,7 @@ lasso_url_add_parameters(char *url,
lasso_release_xml_string(encoded_key);
lasso_release_xml_string(encoded_value);
}
-exit:
+cleanup:
va_end(ap);
if (free && new_url != url) {
lasso_release(url);
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index b418912e..e3d63116 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -498,7 +498,7 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
if (encryption_public_key == NULL || !xmlSecKeyIsValid(encryption_public_key)) {
message(G_LOG_LEVEL_WARNING, "Invalid encryption key");
- goto exit;
+ goto cleanup;
}
/* Create a document to contain the node to encrypt */
@@ -526,12 +526,12 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
if (encrypted_data == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to create encryption template");
- goto exit;
+ goto cleanup;
}
if (xmlSecTmplEncDataEnsureCipherValue(encrypted_data) == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to add CipherValue node");
- goto exit;
+ goto cleanup;
}
/* create and initialize keys manager, we use a simple list based
@@ -541,13 +541,13 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
key_manager = xmlSecKeysMngrCreate();
if (key_manager == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to create keys manager");
- goto exit;
+ goto cleanup;
}
if (xmlSecCryptoAppDefaultKeysMngrInit(key_manager) < 0) {
message(G_LOG_LEVEL_WARNING, "Failed to initialize keys manager");
xmlSecKeysMngrDestroy(key_manager);
- goto exit;
+ goto cleanup;
}
/* add key to keys manager, from now on keys manager is responsible
@@ -555,14 +555,14 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
*/
if (xmlSecCryptoAppDefaultKeysMngrAdoptKey(key_manager, encryption_public_key) < 0) {
xmlSecKeysMngrDestroy(key_manager);
- goto exit;
+ goto cleanup;
}
/* add <dsig:KeyInfo/> */
key_info_node = xmlSecTmplEncDataEnsureKeyInfo(encrypted_data, NULL);
if (key_info_node == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to add key info");
- goto exit;
+ goto cleanup;
}
/* add <enc:EncryptedKey/> to store the encrypted session key */
@@ -570,27 +570,27 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
xmlSecTransformRsaPkcs1Id, NULL, NULL, NULL);
if (encrypted_key_node == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to add encrypted key");
- goto exit;
+ goto cleanup;
}
/* we want to put encrypted key in the <enc:CipherValue/> node */
if (xmlSecTmplEncDataEnsureCipherValue(encrypted_key_node) == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to add CipherValue node");
- goto exit;
+ goto cleanup;
}
/* add <dsig:KeyInfo/> and <dsig:KeyName/> nodes to <enc:EncryptedKey/> */
key_info_node2 = xmlSecTmplEncDataEnsureKeyInfo(encrypted_key_node, NULL);
if (key_info_node2 == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to add key info");
- goto exit;
+ goto cleanup;
}
/* create encryption context */
enc_ctx = (xmlSecEncCtxPtr)xmlSecEncCtxCreate(key_manager);
if (enc_ctx == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to create encryption context");
- goto exit;
+ goto cleanup;
}
/* generate a symetric key */
@@ -612,13 +612,13 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
if (enc_ctx->encKey == NULL) {
message(G_LOG_LEVEL_WARNING, "Failed to generate session des key");
- goto exit;
+ goto cleanup;
}
/* encrypt the data */
if (xmlSecEncCtxXmlEncrypt(enc_ctx, encrypted_data, orig_node) < 0) {
message(G_LOG_LEVEL_WARNING, "Encryption failed");
- goto exit;
+ goto cleanup;
}
/* Create a new EncryptedElement */
@@ -628,7 +628,7 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
lasso_assign_xml_node(encrypted_element->EncryptedData, xmlCopyNode(xmlDocGetRootElement(doc), 1));
lasso_transfer_gobject(ret, encrypted_element);
-exit:
+cleanup:
lasso_release_gobject(encrypted_element);
lasso_release_encrypt_context(enc_ctx);
lasso_release_doc(doc);