summaryrefslogtreecommitdiffstats
path: root/lasso/xml
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 /lasso/xml
parentce3c049c7cc8f10e55ff7b572d6a5b7c03730091 (diff)
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'.
Diffstat (limited to 'lasso/xml')
-rw-r--r--lasso/xml/lib_logout_request.c4
-rw-r--r--lasso/xml/tools.c24
-rw-r--r--lasso/xml/xml.c28
3 files changed, 28 insertions, 28 deletions
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);