[xmlsec] disable xslt read/write by default and allow user to overwrite it
- From: Aleksey Sanin <aleksey src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [xmlsec] disable xslt read/write by default and allow user to overwrite it
- Date: Wed, 30 Mar 2011 01:05:03 +0000 (UTC)
commit 35eaacde6093d6711339754fc2146341b8b9f5fa
Author: Aleksey Sanin <aleksey aleksey com>
Date: Tue Mar 29 18:04:53 2011 -0700
disable xslt read/write by default and allow user to overwrite it
include/xmlsec/private/Makefile.am | 1 +
include/xmlsec/private/xslt.h | 34 +++++++++++++++++++++++
include/xmlsec/transforms.h | 3 ++
src/transforms.c | 10 +++++++
src/xslt.c | 53 ++++++++++++++++++++++++++++++++++++
5 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/include/xmlsec/private/Makefile.am b/include/xmlsec/private/Makefile.am
index aab78c8..74de46a 100644
--- a/include/xmlsec/private/Makefile.am
+++ b/include/xmlsec/private/Makefile.am
@@ -3,6 +3,7 @@ NULL =
xmlsecprivateincdir = $(includedir)/xmlsec1/xmlsec/private
xmlsecprivateinc_HEADERS = \
+xslt.h \
xkms.h \
$(NULL)
diff --git a/include/xmlsec/private/xslt.h b/include/xmlsec/private/xslt.h
new file mode 100644
index 0000000..e9ba697
--- /dev/null
+++ b/include/xmlsec/private/xslt.h
@@ -0,0 +1,34 @@
+/**
+ * XML Security Library (http://www.aleksey.com/xmlsec).
+ *
+ * XSLT helper functions
+ *
+ * This is free software; see Copyright file in the source
+ * distribution for preciese wording.
+ *
+ * Copyright (C) 2002-2003 Aleksey Sanin <aleksey aleksey com>
+ */
+#ifndef __XMLSEC_PRIVATE_XSLT_H__
+#define __XMLSEC_PRIVATE_XSLT_H__
+
+#ifndef XMLSEC_PRIVATE
+#error "xmlsec/private/xslt.h file contains private xmlsec definitions and should not be used outside xmlsec or xmlsec-<crypto> libraries"
+#endif /* XMLSEC_PRIVATE */
+
+#ifndef XMLSEC_NO_XSLT
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+void xmlSecTransformXsltInitialize (void);
+void xmlSecTransformXsltShutdown (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* XMLSEC_NO_XSLT */
+
+#endif /* __XMLSEC_PRIVATE_XSLT_H__ */
+
diff --git a/include/xmlsec/transforms.h b/include/xmlsec/transforms.h
index f0d3d08..f0c70c9 100644
--- a/include/xmlsec/transforms.h
+++ b/include/xmlsec/transforms.h
@@ -950,6 +950,8 @@ XMLSEC_EXPORT int xmlSecTransformXPointerSetExpr (xmlSecT
xmlSecNodeSetType nodeSetType,
xmlNodePtr hereNode);
#ifndef XMLSEC_NO_XSLT
+#include <libxslt/security.h>
+
/**
* xmlSecTransformXsltId:
*
@@ -958,6 +960,7 @@ XMLSEC_EXPORT int xmlSecTransformXPointerSetExpr (xmlSecT
#define xmlSecTransformXsltId \
xmlSecTransformXsltGetKlass()
XMLSEC_EXPORT xmlSecTransformId xmlSecTransformXsltGetKlass (void);
+XMLSEC_EXPORT void xmlSecTransformXsltSetDefaultSecurityPrefs(xsltSecurityPrefsPtr sec);
#endif /* XMLSEC_NO_XSLT */
/**
diff --git a/src/transforms.c b/src/transforms.c
index 8ef38b5..8a2ded2 100644
--- a/src/transforms.c
+++ b/src/transforms.c
@@ -61,6 +61,8 @@
#include <xmlsec/parser.h>
#include <xmlsec/errors.h>
+#include <xmlsec/private/xslt.h>
+
/**************************************************************************
*
* Global xmlSecTransformIds list functions
@@ -113,6 +115,10 @@ xmlSecTransformIdsInit(void) {
return(-1);
}
+#ifndef XMLSEC_NO_XSLT
+ xmlSecTransformXsltInitialize();
+#endif /* XMLSEC_NO_XSLT */
+
return(0);
}
@@ -124,6 +130,10 @@ xmlSecTransformIdsInit(void) {
*/
void
xmlSecTransformIdsShutdown(void) {
+#ifndef XMLSEC_NO_XSLT
+ xmlSecTransformXsltShutdown();
+#endif /* XMLSEC_NO_XSLT */
+
xmlSecPtrListFinalize(xmlSecTransformIdsGet());
}
diff --git a/src/xslt.c b/src/xslt.c
index 21b502d..b752c35 100644
--- a/src/xslt.c
+++ b/src/xslt.c
@@ -28,6 +28,7 @@
#include <xmlsec/keys.h>
#include <xmlsec/parser.h>
#include <xmlsec/errors.h>
+#include <xmlsec/private/xslt.h>
/**************************************************************************
*
@@ -95,6 +96,51 @@ static xmlSecTransformKlass xmlSecXsltKlass = {
NULL, /* void* reserved1; */
};
+
+#define XMLSEC_XSLT_COPY_SEC_PREF(src, dst, pref) \
+ xsltSetSecurityPrefs((dst), (pref), xsltGetSecurityPrefs((src), (pref)))
+
+static xsltSecurityPrefsPtr g_xslt_default_security_prefs = NULL;
+
+void xmlSecTransformXsltInitialize(void) {
+ xmlSecAssert(g_xslt_default_security_prefs == NULL);
+
+ g_xslt_default_security_prefs = xsltNewSecurityPrefs();
+ xmlSecAssert(g_xslt_default_security_prefs != NULL);
+ xsltSetSecurityPrefs(g_xslt_default_security_prefs, XSLT_SECPREF_READ_FILE, xsltSecurityForbid);
+ xsltSetSecurityPrefs(g_xslt_default_security_prefs, XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid);
+ xsltSetSecurityPrefs(g_xslt_default_security_prefs, XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
+ xsltSetSecurityPrefs(g_xslt_default_security_prefs, XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid);
+ xsltSetSecurityPrefs(g_xslt_default_security_prefs, XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid);
+}
+
+void xmlSecTransformXsltShutdown(void) {
+ if(g_xslt_default_security_prefs != NULL) {
+ xsltFreeSecurityPrefs(g_xslt_default_security_prefs);
+ g_xslt_default_security_prefs = NULL;
+ }
+}
+
+/**
+ * xmlSecTransformXsltSetDefaultSecurityPrefs:
+ * @sec: the new security preferences
+ *
+ * Sets the new default security preferences. The xmlsec default security policy is
+ * to disable everything.
+ */
+XMLSEC_EXPORT void
+xmlSecTransformXsltSetDefaultSecurityPrefs(xsltSecurityPrefsPtr sec) {
+ xmlSecAssert(sec != NULL);
+ xmlSecAssert(g_xslt_default_security_prefs != NULL);
+
+ /* copy prefs */
+ XMLSEC_XSLT_COPY_SEC_PREF(sec, g_xslt_default_security_prefs, XSLT_SECPREF_READ_FILE);
+ XMLSEC_XSLT_COPY_SEC_PREF(sec, g_xslt_default_security_prefs, XSLT_SECPREF_WRITE_FILE);
+ XMLSEC_XSLT_COPY_SEC_PREF(sec, g_xslt_default_security_prefs, XSLT_SECPREF_CREATE_DIRECTORY);
+ XMLSEC_XSLT_COPY_SEC_PREF(sec, g_xslt_default_security_prefs, XSLT_SECPREF_READ_NETWORK);
+ XMLSEC_XSLT_COPY_SEC_PREF(sec, g_xslt_default_security_prefs, XSLT_SECPREF_WRITE_NETWORK);
+}
+
/**
* xmlSecTransformXsltGetKlass:
*
@@ -135,6 +181,7 @@ xmlSecTransformXsltGetKlass(void) {
static int
xmlSecXsltInitialize(xmlSecTransformPtr transform) {
xmlSecXsltCtxPtr ctx;
+ int ret;
xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformXsltId), -1);
xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecXsltSize), -1);
@@ -144,6 +191,12 @@ xmlSecXsltInitialize(xmlSecTransformPtr transform) {
/* initialize context */
memset(ctx, 0, sizeof(xmlSecXsltCtx));
+
+ /* set security prefs */
+ ret = xsltSetCtxtSecurityPrefs(g_xslt_default_security_prefs, ctx);
+ xmlSecAssert2(ret == 0, -1);
+
+ /* done */
return(0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]