diff --git a/autogen.sh b/autogen.sh index 4fcacfc5..bf0e0d3a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -27,7 +27,10 @@ cd "$srcdir" DIE=1 } -if automake-1.15 --version < /dev/null > /dev/null 2>&1; then +if automake-1.16 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.16 + ACLOCAL=aclocal-1.16 +elif automake-1.15 --version < /dev/null > /dev/null 2>&1; then AUTOMAKE=automake-1.15 ACLOCAL=aclocal-1.15 elif automake-1.14 --version < /dev/null > /dev/null 2>&1; then diff --git a/lasso/id-wsf/wsf_profile.c b/lasso/id-wsf/wsf_profile.c index 0aca2043..112dfeeb 100644 --- a/lasso/id-wsf/wsf_profile.c +++ b/lasso/id-wsf/wsf_profile.c @@ -59,7 +59,6 @@ #include "../id-ff/providerprivate.h" #include "../id-ff/sessionprivate.h" #include "../xml/misc_text_node.h" -#include <../xml/xmlsec_soap.h> /** * SECTION:wsf_profile @@ -1369,7 +1368,7 @@ lasso_wsf_profile_add_saml_signature(LassoWsfProfile *wsf_profile, xmlDoc *doc) /* Lookup all referenced node and their Ids */ envelope = xmlDocGetRootElement(doc); - header = xmlSecSoap11GetHeader(envelope); + header = lasso_xml_soap11_get_header(envelope); provider = xmlSecFindNode(header, (xmlChar*) "Provider", (xmlChar*) LASSO_SOAP_BINDING_HREF); @@ -1377,7 +1376,7 @@ lasso_wsf_profile_add_saml_signature(LassoWsfProfile *wsf_profile, xmlDoc *doc) (xmlChar*) LASSO_SOAP_BINDING_HREF); interaction = xmlSecFindNode(header, (xmlChar*) "UserInteraction", (xmlChar*) LASSO_IS_HREF); - body = xmlSecSoap11GetBody(envelope); + body = lasso_xml_soap11_get_body(envelope); xmlSecAddIDs(doc, envelope, ids); 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); diff --git a/lasso/xml/Makefile.am b/lasso/xml/Makefile.am index 884d520d..162c437d 100644 --- a/lasso/xml/Makefile.am +++ b/lasso/xml/Makefile.am @@ -243,7 +243,6 @@ liblassoinclude_HEADERS = \ samlp_status_code.h \ xml_enc.h \ tools.h \ - xmlsec_soap.h \ $(WSF_H_FILES) lasso_private_h_sources = \ diff --git a/lasso/xml/private.h b/lasso/xml/private.h index e989e270..52a21e56 100644 --- a/lasso/xml/private.h +++ b/lasso/xml/private.h @@ -265,8 +265,19 @@ xmlDocPtr lasso_xml_parse_memory(const char *buffer, int size); xmlNode* lasso_xml_get_soap_content(xmlNode *root); +xmlNodePtr lasso_xml_next_element_node(xmlNodePtr node); + +const xmlChar* lasso_xml_get_node_ns_href(const xmlNodePtr node); + +gboolean lasso_xml_is_element_node(const xmlNodePtr node, + const xmlChar *name, const xmlChar *ns); + gboolean lasso_xml_is_soap(xmlNode *root); +xmlNodePtr lasso_xml_soap11_get_header(xmlNodePtr envelope_node); + +xmlNodePtr lasso_xml_soap11_get_body(xmlNodePtr envelope_node); + gboolean lasso_eval_xpath_expression(xmlXPathContextPtr xpath_ctx, const char *expression, xmlXPathObjectPtr *xpath_object_ptr, int *xpath_error_code); diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c index 59ffe6ea..a024d82f 100644 --- a/lasso/xml/tools.c +++ b/lasso/xml/tools.c @@ -70,7 +70,6 @@ #include #include #include "../lasso_config.h" -#include /** * SECTION:tools @@ -1677,30 +1676,156 @@ cleanup: return rc; } +/** + * lasso_xml_next_element_node: + * @node: the pointer to an XML node. + * + * Seraches for the next element node. + * + * Returns: the pointer to next element node or NULL if it is not found. + */ +xmlNodePtr +lasso_xml_next_element_node(xmlNodePtr node) +{ + + for (; node != NULL && node->type != XML_ELEMENT_NODE; node = node->next); + return node; +} + +/** + * lasso_xml_get_node_ns_href: + * @node: the pointer to node. + * + * Get's node's namespace href. + * + * Returns: node's namespace href. + */ +const xmlChar* +lasso_xml_get_node_ns_href(const xmlNodePtr node) +{ + xmlNsPtr ns; + + if (node == NULL) { + return NULL; + } + + /* do we have a namespace in the node? */ + if (node->ns != NULL) { + return node->ns->href; + } + + /* search for default namespace */ + ns = xmlSearchNs(node->doc, node, NULL); + if (ns != NULL) { + return ns->href; + } + + return NULL; +} + +/** + * lasso_xml_is_element_node: + * @node: the pointer to an XML node. + * @name: the name, + * @ns: the namespace href. + * + * Checks that the node has a given name and a given namespace href. + * + * Returns: true if the node matches false otherwise. + */ +gboolean +lasso_xml_is_element_node(const xmlNodePtr node, + const xmlChar *name, const xmlChar *ns) +{ + if (node == NULL) { + return FALSE; + } + + return (node->type == XML_ELEMENT_NODE && + xmlStrEqual(node->name, name) && + xmlStrEqual(lasso_xml_get_node_ns_href(node), ns)); +} + gboolean lasso_xml_is_soap(xmlNode *root) { - return xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap11Ns) || - xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap12Ns); + return lasso_xml_is_element_node(root, BAD_CAST "Envelope", + BAD_CAST LASSO_SOAP_ENV_HREF); +} + +/** + * lasso_xml_soap11_get_header: + * @envelope_node: the pointer to node. + * + * Gets pointer to the node. + * + * Returns: pointer to node or NULL if an error occurs. + */ +xmlNodePtr +lasso_xml_soap11_get_header(xmlNodePtr envelope_node) +{ + xmlNodePtr node; + + if (envelope_node == NULL) { + return NULL; + } + + /* optional Header node is first */ + node = lasso_xml_next_element_node(envelope_node->children); + if (lasso_xml_is_element_node(node, BAD_CAST "Header", + BAD_CAST LASSO_SOAP_ENV_HREF)) { + return node; + } + + return NULL; +} + +/** + * lasso_xml_soap11_get_body: + * @envelope_node: the pointer to node. + * + * Gets pointer to the node. + * + * Returns: pointer to node or NULL if an error occurs. + */ +xmlNodePtr +lasso_xml_soap11_get_body(xmlNodePtr envelope_node) +{ + xmlNodePtr node; + + if (envelope_node == NULL) { + return NULL; + } + + /* optional Header node first */ + node = lasso_xml_next_element_node(envelope_node->children); + if (lasso_xml_is_element_node(node, BAD_CAST "Header", + BAD_CAST LASSO_SOAP_ENV_HREF)) { + node = lasso_xml_next_element_node(node->next); + } + + /* Body node is next */ + if (!lasso_xml_is_element_node(node, BAD_CAST "Body", + BAD_CAST LASSO_SOAP_ENV_HREF)) { + return NULL; + } + + return node; } xmlNode* lasso_xml_get_soap_content(xmlNode *root) { gboolean is_soap11 = FALSE; - gboolean is_soap12 = FALSE; xmlNode *content = NULL; - is_soap11 = xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap11Ns); - is_soap12 = xmlSecCheckNodeName(root, xmlSecNodeEnvelope, xmlSecSoap12Ns); - - if (is_soap11 || is_soap12) { + is_soap11 = lasso_xml_is_element_node(root, BAD_CAST "Envelope", + BAD_CAST LASSO_SOAP_ENV_HREF); + if (is_soap11) { xmlNode *body; if (is_soap11) { - body = xmlSecSoap11GetBody(root); - } else { - body = xmlSecSoap12GetBody(root); + body = lasso_xml_soap11_get_body(root); } if (body) { content = xmlSecGetNextElementNode(body->children); diff --git a/lasso/xml/xmlsec_soap.h b/lasso/xml/xmlsec_soap.h deleted file mode 100644 index 11fc3dbd..00000000 --- a/lasso/xml/xmlsec_soap.h +++ /dev/null @@ -1,112 +0,0 @@ -/* $Id$ - * - * Lasso - A free implementation of the Liberty Alliance specifications. - * - * Copyright (C) 2004-2007 Entr'ouvert - * http://lasso.entrouvert.org - * - * Authors: See AUTHORS file in top-level directory. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef __LASSO_XMLSEC_SOAP_H__ -#define __LASSO_XMLSEC_SOAP_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include - -#include -#include -#include - - -/** Replacement for xmlsec/soap.h */ - -#define xmlSecSoap11Ns ((xmlChar*)"http://schemas.xmlsoap.org/soap/envelope/") -#define xmlSecSoap12Ns ((xmlChar*)"http://www.w3.org/2003/05/soap-envelope") - -static inline xmlNodePtr -xmlSecSoap11GetHeader(xmlNodePtr envNode) { - xmlNodePtr cur; - - xmlSecAssert2(envNode != NULL, NULL); - - /* optional Header node is first */ - cur = xmlSecGetNextElementNode(envNode->children); - if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHeader, xmlSecSoap11Ns)) { - return(cur); - } - - return(NULL); -} - -static inline xmlNodePtr -xmlSecSoap11GetBody(xmlNodePtr envNode) { - xmlNodePtr cur; - - xmlSecAssert2(envNode != NULL, NULL); - - /* optional Header node first */ - cur = xmlSecGetNextElementNode(envNode->children); - if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHeader, xmlSecSoap11Ns)) { - cur = xmlSecGetNextElementNode(cur->next); - } - - /* Body node is next */ - if((cur == NULL) || !xmlSecCheckNodeName(cur, xmlSecNodeBody, xmlSecSoap11Ns)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeBody), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); - return(NULL); - } - - return(cur); -} - -static inline xmlNodePtr -xmlSecSoap12GetBody(xmlNodePtr envNode) { - xmlNodePtr cur; - - xmlSecAssert2(envNode != NULL, NULL); - - /* optional Header node first */ - cur = xmlSecGetNextElementNode(envNode->children); - if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHeader, xmlSecSoap12Ns)) { - cur = xmlSecGetNextElementNode(cur->next); - } - - /* Body node is next */ - if((cur == NULL) || !xmlSecCheckNodeName(cur, xmlSecNodeBody, xmlSecSoap12Ns)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - xmlSecErrorsSafeString(xmlSecNodeBody), - XMLSEC_ERRORS_R_NODE_NOT_FOUND, - XMLSEC_ERRORS_NO_MESSAGE); - return(NULL); - } - - return(cur); -} - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __LASSO_XMLSEC_SOAP_H__ */