ReactOS 0.4.16-dev-2208-g6350669
security.h File Reference
#include <libxml/tree.h>
#include "xsltexports.h"
#include "xsltInternals.h"
Include dependency graph for security.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct _xsltSecurityPrefs xsltSecurityPrefs
 
typedef xsltSecurityPrefsxsltSecurityPrefsPtr
 
typedef int(* xsltSecurityCheck) (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const char *value)
 

Enumerations

enum  xsltSecurityOption {
  XSLT_SECPREF_READ_FILE = 1 , XSLT_SECPREF_WRITE_FILE , XSLT_SECPREF_CREATE_DIRECTORY , XSLT_SECPREF_READ_NETWORK ,
  XSLT_SECPREF_WRITE_NETWORK
}
 

Functions

XSLTPUBFUN xsltSecurityPrefsPtr XSLTCALL xsltNewSecurityPrefs (void)
 
XSLTPUBFUN void XSLTCALL xsltFreeSecurityPrefs (xsltSecurityPrefsPtr sec)
 
XSLTPUBFUN int XSLTCALL xsltSetSecurityPrefs (xsltSecurityPrefsPtr sec, xsltSecurityOption option, xsltSecurityCheck func)
 
XSLTPUBFUN xsltSecurityCheck XSLTCALL xsltGetSecurityPrefs (xsltSecurityPrefsPtr sec, xsltSecurityOption option)
 
XSLTPUBFUN void XSLTCALL xsltSetDefaultSecurityPrefs (xsltSecurityPrefsPtr sec)
 
XSLTPUBFUN xsltSecurityPrefsPtr XSLTCALL xsltGetDefaultSecurityPrefs (void)
 
XSLTPUBFUN int XSLTCALL xsltSetCtxtSecurityPrefs (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt)
 
XSLTPUBFUN int XSLTCALL xsltSecurityAllow (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const char *value)
 
XSLTPUBFUN int XSLTCALL xsltSecurityForbid (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const char *value)
 
XSLTPUBFUN int XSLTCALL xsltCheckWrite (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
 
XSLTPUBFUN int XSLTCALL xsltCheckRead (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
 

Typedef Documentation

◆ xsltSecurityCheck

typedef int(* xsltSecurityCheck) (xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const char *value)

xsltSecurityCheck:

User provided function to check the value of a string like a file path or an URL ...

Definition at line 51 of file security.h.

◆ xsltSecurityPrefs

xsltSecurityPref:

structure to indicate the preferences for security in the XSLT transformation.

Definition at line 29 of file security.h.

◆ xsltSecurityPrefsPtr

Definition at line 30 of file security.h.

Enumeration Type Documentation

◆ xsltSecurityOption

xsltSecurityOption:

the set of option that can be configured

Enumerator
XSLT_SECPREF_READ_FILE 
XSLT_SECPREF_WRITE_FILE 
XSLT_SECPREF_CREATE_DIRECTORY 
XSLT_SECPREF_READ_NETWORK 
XSLT_SECPREF_WRITE_NETWORK 

Definition at line 37 of file security.h.

37 {
xsltSecurityOption
Definition: security.h:37
@ XSLT_SECPREF_READ_NETWORK
Definition: security.h:41
@ XSLT_SECPREF_WRITE_NETWORK
Definition: security.h:42
@ XSLT_SECPREF_CREATE_DIRECTORY
Definition: security.h:40
@ XSLT_SECPREF_WRITE_FILE
Definition: security.h:39
@ XSLT_SECPREF_READ_FILE
Definition: security.h:38

Function Documentation

◆ xsltCheckRead()

XSLTPUBFUN int XSLTCALL xsltCheckRead ( xsltSecurityPrefsPtr  sec,
xsltTransformContextPtr  ctxt,
const xmlChar URL 
)

xsltCheckRead: @sec: the security options @ctxt: an XSLT transformation context @URL: the resource to be read

Check if the resource is allowed to be read

Return 1 if read is allowed, 0 if not and -1 in case or error.

Definition at line 419 of file security.c.

420 {
421 int ret;
424
425 if (xmlStrstr(URL, BAD_CAST "://") == NULL) {
427 if (check != NULL) {
428 ret = check(sec, ctxt, (const char *) URL);
429 if (ret == 0) {
431 "Local file read for %s refused\n", URL);
432 return(0);
433 }
434 }
435 return(1);
436 }
437
438 uri = xmlParseURI((const char *)URL);
439 if (uri == NULL) {
441 "xsltCheckRead: URL parsing failed for %s\n",
442 URL);
443 return(-1);
444 }
445 if ((uri->scheme == NULL) ||
446 (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
447
448 /*
449 * Check if we are allowed to read this file
450 */
452 if (check != NULL) {
453 ret = check(sec, ctxt, uri->path);
454 if (ret == 0) {
456 "Local file read for %s refused\n", URL);
458 return(0);
459 }
460 }
461 } else {
462 /*
463 * Check if we are allowed to write this network resource
464 */
466 if (check != NULL) {
467 ret = check(sec, ctxt, (const char *)URL);
468 if (ret == 0) {
470 "Network file read for %s refused\n", URL);
472 return(0);
473 }
474 }
475 }
477 return(1);
478}
#define NULL
Definition: types.h:112
xsltSecurityCheck xsltGetSecurityPrefs(xsltSecurityPrefsPtr sec, xsltSecurityOption option)
Definition: security.c:142
int(* xsltSecurityCheck)(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const char *value)
Definition: security.h:51
#define check(expected, result)
Definition: dplayx.c:32
return ret
Definition: mutex.c:146
const char * uri
Definition: sec_mgr.c:1588
Definition: uri.h:34
XMLPUBFUN void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1396
XMLPUBFUN xmlURIPtr xmlParseURI(const char *str)
Definition: uri.c:947
XMLPUBFUN const xmlChar * xmlStrstr(const xmlChar *str, const xmlChar *val)
Definition: xmlstring.c:347
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:162
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:762

Referenced by xsltLoadDocument(), xsltLoadStyleDocument(), xsltParseStylesheetFile(), and xsltParseStylesheetImport().

◆ xsltCheckWrite()

XSLTPUBFUN int XSLTCALL xsltCheckWrite ( xsltSecurityPrefsPtr  sec,
xsltTransformContextPtr  ctxt,
const xmlChar URL 
)

xsltCheckWrite: @sec: the security options @ctxt: an XSLT transformation context @URL: the resource to be written

Check if the resource is allowed to be written, if necessary makes some preliminary work like creating directories

Return 1 if write is allowed, 0 if not and -1 in case or error.

Definition at line 352 of file security.c.

353 {
354 int ret;
357
358 uri = xmlParseURI((const char *)URL);
359 if (uri == NULL) {
360 uri = xmlCreateURI();
361 if (uri == NULL) {
363 "xsltCheckWrite: out of memory for %s\n", URL);
364 return(-1);
365 }
366 uri->path = (char *)xmlStrdup(URL);
367 }
368 if ((uri->scheme == NULL) ||
369 (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
370
371#if defined(_WIN32)
372 if ((uri->path)&&(uri->path[0]=='/')&&
373 (uri->path[1]!='\0')&&(uri->path[2]==':'))
374 ret = xsltCheckWritePath(sec, ctxt, uri->path+1);
375 else
376#endif
377 {
378 /*
379 * Check if we are allowed to write this file
380 */
381 ret = xsltCheckWritePath(sec, ctxt, uri->path);
382 }
383
384 if (ret <= 0) {
386 return(ret);
387 }
388 } else {
389 /*
390 * Check if we are allowed to write this network resource
391 */
393 if (check != NULL) {
394 ret = check(sec, ctxt, (const char *)URL);
395 if (ret == 0) {
397 "File write for %s refused\n", URL);
399 return(0);
400 }
401 }
402 }
404 return(1);
405}
static int xsltCheckWritePath(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const char *path)
Definition: security.c:290
XMLPUBFUN xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1027
XMLPUBFUN xmlChar * xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:69

Referenced by xsltApplyStylesheetInternal(), and xsltDocumentElem().

◆ xsltFreeSecurityPrefs()

XSLTPUBFUN void XSLTCALL xsltFreeSecurityPrefs ( xsltSecurityPrefsPtr  sec)

xsltFreeSecurityPrefs: @sec: the security block to free

Free up a security preference block

Definition at line 95 of file security.c.

95 {
96 if (sec == NULL)
97 return;
98 xmlFree(sec);
99}
xmlFreeFunc xmlFree
Definition: globals.c:184

◆ xsltGetDefaultSecurityPrefs()

XSLTPUBFUN xsltSecurityPrefsPtr XSLTCALL xsltGetDefaultSecurityPrefs ( void  )

xsltGetDefaultSecurityPrefs:

Get the default security preference application-wide

Returns the current xsltSecurityPrefsPtr in use or NULL if none

Definition at line 180 of file security.c.

180 {
182}
static xsltSecurityPrefsPtr xsltDefaultSecurityPrefs
Definition: security.c:57

Referenced by xsltLoadStyleDocument(), xsltNewTransformContext(), xsltParseStylesheetFile(), and xsltParseStylesheetImport().

◆ xsltGetSecurityPrefs()

XSLTPUBFUN xsltSecurityCheck XSLTCALL xsltGetSecurityPrefs ( xsltSecurityPrefsPtr  sec,
xsltSecurityOption  option 
)

xsltGetSecurityPrefs: @sec: the security block to update @option: the option to lookup

Lookup the security option to get the callback checking function

Returns NULL if not found, the function otherwise

Definition at line 142 of file security.c.

142 {
143 if (sec == NULL)
144 return(NULL);
145 switch (option) {
147 return(sec->readFile);
149 return(sec->createFile);
151 return(sec->createDir);
153 return(sec->readNet);
155 return(sec->writeNet);
156 }
157 return(NULL);
158}
xsltSecurityCheck readFile
Definition: security.c:50
xsltSecurityCheck createFile
Definition: security.c:51
xsltSecurityCheck createDir
Definition: security.c:52
xsltSecurityCheck readNet
Definition: security.c:53
xsltSecurityCheck writeNet
Definition: security.c:54
Definition: getopt.h:109

Referenced by xsltCheckRead(), xsltCheckWrite(), and xsltCheckWritePath().

◆ xsltNewSecurityPrefs()

XSLTPUBFUN xsltSecurityPrefsPtr XSLTCALL xsltNewSecurityPrefs ( void  )

xsltNewSecurityPrefs:

Create a new security preference block

Returns a pointer to the new block or NULL in case of error

Definition at line 73 of file security.c.

73 {
75
77
79 if (ret == NULL) {
81 "xsltNewSecurityPrefs : malloc failed\n");
82 return(NULL);
83 }
84 memset(ret, 0, sizeof(xsltSecurityPrefs));
85 return(ret);
86}
void xsltInitGlobals(void)
Definition: extensions.c:2282
xsltSecurityPrefs * xsltSecurityPrefsPtr
Definition: security.h:30
xmlMallocFunc xmlMalloc
Definition: globals.c:193
#define memset(x, y, z)
Definition: compat.h:39

◆ xsltSecurityAllow()

XSLTPUBFUN int XSLTCALL xsltSecurityAllow ( xsltSecurityPrefsPtr  sec,
xsltTransformContextPtr  ctxt,
const char value 
)

◆ xsltSecurityForbid()

XSLTPUBFUN int XSLTCALL xsltSecurityForbid ( xsltSecurityPrefsPtr  sec,
xsltTransformContextPtr  ctxt,
const char value 
)

◆ xsltSetCtxtSecurityPrefs()

XSLTPUBFUN int XSLTCALL xsltSetCtxtSecurityPrefs ( xsltSecurityPrefsPtr  sec,
xsltTransformContextPtr  ctxt 
)

xsltSetCtxtSecurityPrefs: @sec: the security block to use @ctxt: an XSLT transformation context

Set the security preference for a specific transformation

Returns -1 in case of error, 0 otherwise

Definition at line 194 of file security.c.

195 {
196 if (ctxt == NULL)
197 return(-1);
198 ctxt->sec = (void *) sec;
199 return(0);
200}

◆ xsltSetDefaultSecurityPrefs()

XSLTPUBFUN void XSLTCALL xsltSetDefaultSecurityPrefs ( xsltSecurityPrefsPtr  sec)

xsltSetDefaultSecurityPrefs: @sec: the security block to use

Set the default security preference application-wide

Definition at line 167 of file security.c.

167 {
168
170}

◆ xsltSetSecurityPrefs()

XSLTPUBFUN int XSLTCALL xsltSetSecurityPrefs ( xsltSecurityPrefsPtr  sec,
xsltSecurityOption  option,
xsltSecurityCheck  func 
)

xsltSetSecurityPrefs: @sec: the security block to update @option: the option to update @func: the user callback to use for this option

Update the security option to use the new callback checking function

Returns -1 in case of error, 0 otherwise

Definition at line 112 of file security.c.

113 {
115 if (sec == NULL)
116 return(-1);
117 switch (option) {
119 sec->readFile = func; return(0);
121 sec->createFile = func; return(0);
123 sec->createDir = func; return(0);
125 sec->readNet = func; return(0);
127 sec->writeNet = func; return(0);
128 }
129 return(-1);
130}
GLenum func
Definition: glext.h:6028