40#include "MagickCore/studio.h"
41#include "MagickCore/cache-private.h"
42#include "MagickCore/client.h"
43#include "MagickCore/configure.h"
44#include "MagickCore/configure-private.h"
45#include "MagickCore/exception.h"
46#include "MagickCore/exception-private.h"
47#include "MagickCore/linked-list-private.h"
48#include "MagickCore/magick-private.h"
49#include "MagickCore/memory_.h"
50#include "MagickCore/memory-private.h"
51#include "MagickCore/monitor.h"
52#include "MagickCore/monitor-private.h"
53#include "MagickCore/option.h"
54#include "MagickCore/policy.h"
55#include "MagickCore/policy-private.h"
56#include "MagickCore/resource_.h"
57#include "MagickCore/resource-private.h"
58#include "MagickCore/semaphore.h"
59#include "MagickCore/stream-private.h"
60#include "MagickCore/string_.h"
61#include "MagickCore/string-private.h"
62#include "MagickCore/token.h"
63#include "MagickCore/timer-private.h"
64#include "MagickCore/utility.h"
65#include "MagickCore/utility-private.h"
66#include "MagickCore/xml-tree.h"
67#include "MagickCore/xml-tree-private.h"
68#if defined(MAGICKCORE_XML_DELEGATE)
69# include <libxml/parser.h>
70# include <libxml/tree.h>
76#define PolicyFilename "policy.xml"
126static const PolicyMapInfo
129 { UndefinedPolicyDomain, UndefinedPolicyRights, (
const char *) NULL,
130 (
const char *) NULL, (
const char *) NULL }
134 *policy_cache = (LinkedListInfo *) NULL;
142static MagickBooleanType
143 IsPolicyCacheInstantiated(ExceptionInfo *),
144 LoadPolicyCache(LinkedListInfo *,
const char *,
const char *,
const size_t,
173static LinkedListInfo *AcquirePolicyCache(
const char *filename,
174 ExceptionInfo *exception)
188 cache=NewLinkedList(0);
190#if MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
191 magick_unreferenced(filename);
192 status=LoadPolicyCache(cache,ZeroConfigurationPolicy,
"[zero-configuration]",0,
194 if (status == MagickFalse)
195 CatchException(exception);
204 options=GetConfigureOptions(filename,exception);
205 option=(
const StringInfo *) GetNextValueInLinkedList(options);
206 while (option != (
const StringInfo *) NULL)
208 status=LoadPolicyCache(cache,(
const char *) GetStringInfoDatum(option),
209 GetStringInfoPath(option),0,exception);
210 if (status == MagickFalse)
211 CatchException(exception);
212 option=(
const StringInfo *) GetNextValueInLinkedList(options);
214 options=DestroyConfigureOptions(options);
220 for (i=0; i < (ssize_t) (
sizeof(PolicyMap)/
sizeof(*PolicyMap)); i++)
229 policy_info=(PolicyInfo *) AcquireMagickMemory(
sizeof(*policy_info));
230 if (policy_info == (PolicyInfo *) NULL)
232 (void) ThrowMagickException(exception,GetMagickModule(),
233 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
234 p->name == (
char *) NULL ?
"" : p->name);
235 CatchException(exception);
238 (void) memset(policy_info,0,
sizeof(*policy_info));
239 policy_info->path=(
char *)
"[built-in]";
240 policy_info->domain=p->domain;
241 policy_info->rights=p->rights;
242 policy_info->name=(
char *) p->name;
243 policy_info->pattern=(
char *) p->pattern;
244 policy_info->value=(
char *) p->value;
245 policy_info->exempt=MagickTrue;
246 policy_info->signature=MagickCoreSignature;
247 status=AppendValueToLinkedList(cache,policy_info);
248 if (status == MagickFalse)
250 (void) ThrowMagickException(exception,GetMagickModule(),
251 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
252 p->name == (
char *) NULL ?
"" : p->name);
253 CatchException(exception);
284static PolicyInfo *GetPolicyInfo(
const char *name,ExceptionInfo *exception)
287 policyname[MagickPathExtent],
299 assert(exception != (ExceptionInfo *) NULL);
300 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
301 return((PolicyInfo *) NULL);
306 if (name != (
const char *) NULL)
307 (void) CopyMagickString(policyname,name,MagickPathExtent);
308 for (q=policyname; *q !=
'\0'; q++)
310 if (isspace((
int) ((
unsigned char) *q)) == 0)
312 (void) CopyMagickString(q,q+1,MagickPathExtent);
318 domain=UndefinedPolicyDomain;
319 for (q=policyname; *q !=
'\0'; q++)
324 domain=(PolicyDomain) ParseCommandOption(MagickPolicyDomainOptions,
325 MagickTrue,policyname);
326 (void) CopyMagickString(policyname,q+1,MagickPathExtent);
332 policy=(PolicyInfo *) NULL;
333 LockSemaphoreInfo(policy_semaphore);
334 ResetLinkedListIterator(policy_cache);
335 p=GetHeadElementInLinkedList(policy_cache);
336 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
338 UnlockSemaphoreInfo(policy_semaphore);
339 if (p != (ElementInfo *) NULL)
340 policy=(PolicyInfo *) p->value;
343 while (p != (ElementInfo *) NULL)
345 policy=(PolicyInfo *) p->value;
346 if ((domain == UndefinedPolicyDomain) || (policy->domain == domain))
347 if (LocaleCompare(policyname,policy->name) == 0)
351 if (p == (ElementInfo *) NULL)
352 policy=(PolicyInfo *) NULL;
354 (
void) SetHeadElementInLinkedList(policy_cache,p);
355 UnlockSemaphoreInfo(policy_semaphore);
386MagickExport
const PolicyInfo **GetPolicyInfoList(
const char *pattern,
387 size_t *number_policies,ExceptionInfo *exception)
398 assert(pattern != (
char *) NULL);
399 assert(number_policies != (
size_t *) NULL);
400 if (IsEventLogging() != MagickFalse)
401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
403 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
404 return((
const PolicyInfo **) NULL);
405 policies=(
const PolicyInfo **) AcquireQuantumMemory((
size_t)
406 GetNumberOfElementsInLinkedList(policy_cache)+1UL,
sizeof(*policies));
407 if (policies == (
const PolicyInfo **) NULL)
408 return((
const PolicyInfo **) NULL);
409 LockSemaphoreInfo(policy_semaphore);
410 p=GetHeadElementInLinkedList(policy_cache);
411 for (i=0; p != (ElementInfo *) NULL; )
416 policy=(
const PolicyInfo *) p->value;
417 if ((policy->stealth == MagickFalse) &&
418 (GlobExpression(policy->name,pattern,MagickFalse) != MagickFalse))
419 policies[i++]=policy;
422 UnlockSemaphoreInfo(policy_semaphore);
424 policies=(
const PolicyInfo **) RelinquishMagickMemory((
void*) policies);
426 policies[i]=(PolicyInfo *) NULL;
427 *number_policies=(size_t) i;
459static char *AcquirePolicyString(
const char *source,
const size_t pad)
468 if (source != (
char *) NULL)
469 length+=strlen(source);
470 destination=(
char *) NULL;
473 destination=(
char *) AcquireMagickMemory((length+pad)*
sizeof(*destination));
474 if (destination == (
char *) NULL)
475 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
476 if (source != (
char *) NULL)
477 (void) memcpy(destination,source,length*
sizeof(*destination));
478 destination[length]=
'\0';
482MagickExport
char **GetPolicyList(
const char *pattern,
size_t *number_policies,
483 ExceptionInfo *exception)
494 assert(pattern != (
char *) NULL);
495 assert(number_policies != (
size_t *) NULL);
496 if (IsEventLogging() != MagickFalse)
497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
499 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
500 return((
char **) NULL);
501 policies=(
char **) AcquireQuantumMemory((
size_t)
502 GetNumberOfElementsInLinkedList(policy_cache)+1UL,
sizeof(*policies));
503 if (policies == (
char **) NULL)
504 return((
char **) NULL);
505 LockSemaphoreInfo(policy_semaphore);
506 p=GetHeadElementInLinkedList(policy_cache);
507 for (i=0; p != (ElementInfo *) NULL; )
512 policy=(
const PolicyInfo *) p->value;
513 if ((policy->stealth == MagickFalse) &&
514 (GlobExpression(policy->name,pattern,MagickFalse) != MagickFalse))
515 policies[i++]=AcquirePolicyString(policy->name,1);
518 UnlockSemaphoreInfo(policy_semaphore);
520 policies=(
char **) RelinquishMagickMemory(policies);
522 policies[i]=(
char *) NULL;
523 *number_policies=(size_t) i;
549MagickExport
char *GetPolicyValue(
const char *name)
560 assert(name != (
const char *) NULL);
561 if (IsEventLogging() != MagickFalse)
562 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
563 exception=AcquireExceptionInfo();
564 policy_info=GetPolicyInfo(name,exception);
565 exception=DestroyExceptionInfo(exception);
566 if (policy_info == (PolicyInfo *) NULL)
567 return((
char *) NULL);
568 value=policy_info->value;
569 if ((value == (
const char *) NULL) || (*value ==
'\0'))
570 return((
char *) NULL);
571 return(AcquirePolicyString(value,1));
597static MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
599 if (policy_cache == (LinkedListInfo *) NULL)
601 (void) GetMaxMemoryRequest();
603 ActivateSemaphoreInfo(&policy_semaphore);
604 LockSemaphoreInfo(policy_semaphore);
605 if (policy_cache == (LinkedListInfo *) NULL)
606 policy_cache=AcquirePolicyCache(PolicyFilename,exception);
607 UnlockSemaphoreInfo(policy_semaphore);
609 return(policy_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
646MagickExport MagickBooleanType IsRightsAuthorizedByName(
647 const PolicyDomain domain,
const char *name,
const PolicyRights rights,
651 *canonical_directory = (
char *) NULL,
652 *canonical_path = (
char *) NULL,
653 *canonical_candidate = (
char *) NULL,
654 directory[MagickPathExtent],
655 filename[MagickPathExtent];
664 canonical_matched_any = MagickFalse,
665 matched_any = MagickFalse,
666 paths_provisioned = MagickFalse,
670 canonical_allowed_accumulator = AllPolicyRights,
671 effective_rights = AllPolicyRights;
676 if ((GetLogEventMask() & PolicyEvent) != 0)
677 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
678 "Domain: %s; name: %s; rights=%s; pattern=\"%s\"; ...",
679 CommandOptionToMnemonic(MagickPolicyDomainOptions,domain),
680 name == (
const char *) NULL ?
"undefined" : name,
681 CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),
682 pattern == (
const char *) NULL ?
"undefined" : pattern);
683 exception=AcquireExceptionInfo();
684 status=IsPolicyCacheInstantiated(exception);
685 exception=DestroyExceptionInfo(exception);
686 if (status == MagickFalse)
688 if ((GetLogEventMask() & PolicyEvent) != 0)
689 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
690 " authorized: true (no security policies found)");
697 LockSemaphoreInfo(policy_semaphore);
698 ResetLinkedListIterator(policy_cache);
699 p=GetHeadElementInLinkedList(policy_cache);
700 for ( ; p != (ElementInfo *) NULL; p=p->next)
703 *policy = (PolicyInfo *) p->value;
707 matched_canonical = MagickFalse;
709 if (policy->domain != domain)
711 if ((name != (
char *) NULL) && (LocaleCompare(name,policy->name) != 0))
713 match=GlobExpression(pattern,policy->pattern,MagickFalse);
714 if (policy->domain == PathPolicyDomain)
716 if (paths_provisioned == MagickFalse)
721 paths_provisioned=MagickTrue;
722 GetPathComponent(pattern,HeadPath,directory);
723 GetPathComponent(pattern,TailPath,filename);
724 canonical_directory=realpath_utf8(directory);
725 if ((canonical_directory != (
char *) NULL) && (*filename !=
'\0'))
730 length=strlen(canonical_directory)+strlen(filename)+2;
731 canonical_candidate=(
char *) AcquireCriticalMemory(length*
732 sizeof(*canonical_candidate));
733 if (canonical_candidate != (
char *) NULL)
734 (void) FormatLocaleString(canonical_candidate,length,
"%s%s%s",
735 canonical_directory,DirectorySeparator,filename);
737 canonical_path=realpath_utf8(pattern);
742 if ((canonical_directory != (
char *) NULL) && (match == MagickFalse))
743 match=GlobExpression(canonical_directory,policy->pattern,MagickFalse);
744 if ((canonical_candidate != (
char *) NULL) && (match == MagickFalse))
745 match=GlobExpression(canonical_candidate,policy->pattern,MagickFalse);
746 if ((canonical_path != (
char *) NULL) && (match == MagickFalse))
747 match=GlobExpression(canonical_path,policy->pattern,MagickFalse);
748 if ((canonical_path != (
char *) NULL) &&
749 (GlobExpression(canonical_path,policy->pattern,MagickFalse) != MagickFalse))
750 matched_canonical=MagickTrue;
752 if ((canonical_candidate != (
char *) NULL) &&
753 (GlobExpression(canonical_candidate,policy->pattern,MagickFalse) != MagickFalse))
754 matched_canonical=MagickTrue;
756 if ((canonical_directory != (
char *) NULL) &&
757 (GlobExpression(canonical_directory,policy->pattern,MagickFalse) != MagickFalse))
758 matched_canonical=MagickTrue;
760 if (match == MagickFalse)
762 matched_any=MagickTrue;
763 effective_rights=policy->rights;
764 if (matched_canonical != MagickFalse)
769 canonical_matched_any=MagickTrue;
770 canonical_allowed_accumulator=(PolicyRights) ((
int)
771 canonical_allowed_accumulator & (
int) policy->rights);
774 UnlockSemaphoreInfo(policy_semaphore);
775 if (canonical_directory != (
char *) NULL)
776 canonical_directory=DestroyString(canonical_directory);
777 if (canonical_candidate != (
char *) NULL)
778 canonical_candidate=DestroyString(canonical_candidate);
779 if (canonical_path != (
char *) NULL)
780 canonical_path=DestroyString(canonical_path);
785 if (matched_any != MagickFalse)
787 if (((rights & ReadPolicyRights) != 0) &&
788 ((effective_rights & ReadPolicyRights) == 0))
790 if (((rights & WritePolicyRights) != 0) &&
791 ((effective_rights & WritePolicyRights) == 0))
793 if (((rights & ExecutePolicyRights) != 0) &&
794 ((effective_rights & ExecutePolicyRights) == 0))
800 if (canonical_matched_any != MagickFalse)
802 PolicyRights canonical_denied_mask = (PolicyRights) ((
int)
803 AllPolicyRights & (
int) ~canonical_allowed_accumulator);
804 if ((canonical_denied_mask & rights) != 0)
807 if ((GetLogEventMask() & PolicyEvent) != 0)
808 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
809 " authorized: %s",status == MagickFalse ?
"false" :
"true");
813MagickExport MagickBooleanType IsRightsAuthorized(
const PolicyDomain domain,
814 const PolicyRights rights,
const char *pattern)
816 return(IsRightsAuthorizedByName(domain,(
const char *) NULL,rights,pattern));
843MagickExport MagickBooleanType ListPolicyInfo(FILE *file,
844 ExceptionInfo *exception)
862 if (file == (
const FILE *) NULL)
864 policy_info=GetPolicyInfoList(
"*",&number_policies,exception);
865 if (policy_info == (
const PolicyInfo **) NULL)
867 path=(
const char *) NULL;
868 for (i=0; i < (ssize_t) number_policies; i++)
870 if (policy_info[i]->stealth != MagickFalse)
872 if (((path == (
const char *) NULL) ||
873 (LocaleCompare(path,policy_info[i]->path) != 0)) &&
874 (policy_info[i]->path != (
char *) NULL))
875 (void) FormatLocaleFile(file,
"\nPath: %s\n",policy_info[i]->path);
876 path=policy_info[i]->path;
877 domain=CommandOptionToMnemonic(MagickPolicyDomainOptions,
878 policy_info[i]->domain);
879 (void) FormatLocaleFile(file,
" Policy: %s\n",domain);
880 if ((policy_info[i]->domain == CachePolicyDomain) ||
881 (policy_info[i]->domain == ResourcePolicyDomain) ||
882 (policy_info[i]->domain == SystemPolicyDomain))
884 if (policy_info[i]->name != (
char *) NULL)
885 (void) FormatLocaleFile(file,
" name: %s\n",policy_info[i]->name);
886 if (policy_info[i]->value != (
char *) NULL)
887 (void) FormatLocaleFile(file,
" value: %s\n",policy_info[i]->value);
891 (void) FormatLocaleFile(file,
" rights: ");
892 if (policy_info[i]->rights == NoPolicyRights)
893 (void) FormatLocaleFile(file,
"None ");
894 if ((policy_info[i]->rights & ReadPolicyRights) != 0)
895 (void) FormatLocaleFile(file,
"Read ");
896 if ((policy_info[i]->rights & WritePolicyRights) != 0)
897 (void) FormatLocaleFile(file,
"Write ");
898 if ((policy_info[i]->rights & ExecutePolicyRights) != 0)
899 (void) FormatLocaleFile(file,
"Execute ");
900 (void) FormatLocaleFile(file,
"\n");
901 if (policy_info[i]->pattern != (
char *) NULL)
902 (void) FormatLocaleFile(file,
" pattern: %s\n",
903 policy_info[i]->pattern);
906 policy_info=(
const PolicyInfo **) RelinquishMagickMemory((
void *)
942static MagickBooleanType LoadPolicyCache(LinkedListInfo *cache,
943 const char *policy,
const char *filename,
const size_t depth,
944 ExceptionInfo *exception)
947 keyword[MagickPathExtent],
965 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
966 "Loading policy file \"%s\" ...",filename);
967 if (policy == (
char *) NULL)
970 policy_info=(PolicyInfo *) NULL;
971 token=AcquirePolicyString(policy,MagickPathExtent);
972 extent=strlen(token)+MagickPathExtent;
973 for (q=policy; *q !=
'\0'; )
978 (void) GetNextToken(q,&q,extent,token);
981 (void) CopyMagickString(keyword,token,MagickPathExtent);
982 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
987 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
988 (void) GetNextToken(q,&q,extent,token);
991 if (LocaleNCompare(keyword,
"<!--",4) == 0)
996 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
997 (void) GetNextToken(q,&q,extent,token);
1000 if (LocaleCompare(keyword,
"<include") == 0)
1005 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1007 (void) CopyMagickString(keyword,token,MagickPathExtent);
1008 (void) GetNextToken(q,&q,extent,token);
1011 (void) GetNextToken(q,&q,extent,token);
1012 if (LocaleCompare(keyword,
"file") == 0)
1014 if (depth > MagickMaxRecursionDepth)
1015 (void) ThrowMagickException(exception,GetMagickModule(),
1016 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
1020 path[MagickPathExtent],
1023 GetPathComponent(filename,HeadPath,path);
1025 (void) ConcatenateMagickString(path,DirectorySeparator,
1027 if (*token == *DirectorySeparator)
1028 (void) CopyMagickString(path,token,MagickPathExtent);
1030 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
1031 file_xml=FileToXML(path,~0UL);
1032 if (file_xml != (
char *) NULL)
1034 status&=(MagickStatusType) LoadPolicyCache(cache,file_xml,
1035 path,depth+1,exception);
1036 file_xml=DestroyString(file_xml);
1043 if (LocaleCompare(keyword,
"<policy") == 0)
1048 policy_info=(PolicyInfo *) AcquireCriticalMemory(
sizeof(*policy_info));
1049 (void) memset(policy_info,0,
sizeof(*policy_info));
1050 policy_info->path=AcquirePolicyString(filename,1);
1051 policy_info->exempt=MagickFalse;
1052 policy_info->signature=MagickCoreSignature;
1055 if (policy_info == (PolicyInfo *) NULL)
1057 if ((LocaleCompare(keyword,
"/>") == 0) ||
1058 (LocaleCompare(keyword,
"</policy>") == 0))
1060 status=AppendValueToLinkedList(cache,policy_info);
1061 if (status == MagickFalse)
1062 (void) ThrowMagickException(exception,GetMagickModule(),
1063 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1065 policy_info=(PolicyInfo *) NULL;
1068 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1071 (void) GetNextToken(q,&q,extent,token);
1072 (void) GetNextToken(q,&q,extent,token);
1078 if (LocaleCompare((
char *) keyword,
"domain") == 0)
1080 policy_info->domain=(PolicyDomain) ParseCommandOption(
1081 MagickPolicyDomainOptions,MagickTrue,token);
1089 if (LocaleCompare((
char *) keyword,
"name") == 0)
1091 policy_info->name=AcquirePolicyString(token,1);
1099 if (LocaleCompare((
char *) keyword,
"pattern") == 0)
1101 policy_info->pattern=AcquirePolicyString(token,1);
1109 if (LocaleCompare((
char *) keyword,
"rights") == 0)
1111 policy_info->rights=(PolicyRights) ParseCommandOption(
1112 MagickPolicyRightsOptions,MagickTrue,token);
1120 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
1122 policy_info->stealth=IsStringTrue(token);
1130 if (LocaleCompare((
char *) keyword,
"value") == 0)
1132 policy_info->value=AcquirePolicyString(token,1);
1141 token=(
char *) RelinquishMagickMemory(token);
1142 return(status != 0 ? MagickTrue : MagickFalse);
1163MagickPrivate MagickBooleanType PolicyComponentGenesis(
void)
1166 policy_semaphore=AcquireSemaphoreInfo();
1189static void *DestroyPolicyElement(
void *policy_info)
1194 p=(PolicyInfo *) policy_info;
1195 if (p->exempt == MagickFalse)
1197 if (p->value != (
char *) NULL)
1198 p->value=DestroyString(p->value);
1199 if (p->pattern != (
char *) NULL)
1200 p->pattern=DestroyString(p->pattern);
1201 if (p->name != (
char *) NULL)
1202 p->name=DestroyString(p->name);
1203 if (p->path != (
char *) NULL)
1204 p->path=DestroyString(p->path);
1206 p=(PolicyInfo *) RelinquishMagickMemory(p);
1207 return((
void *) NULL);
1210MagickPrivate
void PolicyComponentTerminus(
void)
1213 ActivateSemaphoreInfo(&policy_semaphore);
1214 LockSemaphoreInfo(policy_semaphore);
1215 if (policy_cache != (LinkedListInfo *) NULL)
1216 policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement);
1217 UnlockSemaphoreInfo(policy_semaphore);
1218 RelinquishSemaphoreInfo(&policy_semaphore);
1248static MagickBooleanType ValidateSecurityPolicy(
const char *policy,
1249 const char *url,ExceptionInfo *exception)
1251#if defined(MAGICKCORE_XML_DELEGATE)
1258 document=xmlReadMemory(policy,(
int) strlen(policy),url,NULL,
1259 XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
1260 if (document == (xmlDocPtr) NULL)
1262 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
1263 "PolicyValidationException",
"'%s'",url);
1264 return(MagickFalse);
1266 xmlFreeDoc(document);
1275MagickExport MagickBooleanType SetMagickSecurityPolicy(
const char *policy,
1276 ExceptionInfo *exception)
1290 assert(exception != (ExceptionInfo *) NULL);
1291 if (policy == (
const char *) NULL)
1292 return(MagickFalse);
1293 if (ValidateSecurityPolicy(policy,PolicyFilename,exception) == MagickFalse)
1294 return(MagickFalse);
1295 status=LoadPolicyCache(policy_cache,policy,
"[user-policy]",0,exception);
1296 if (status == MagickFalse)
1301 user_policies=NewLinkedList(0);
1302 status=LoadPolicyCache(user_policies,policy,
"[user-policy]",0,exception);
1303 if (status == MagickFalse)
1305 user_policies=DestroyLinkedList(user_policies,DestroyPolicyElement);
1306 return(MagickFalse);
1308 ResetLinkedListIterator(user_policies);
1309 p=(PolicyInfo *) GetNextValueInLinkedList(user_policies);
1310 while (p != (PolicyInfo *) NULL)
1312 if ((p->name != (
char *) NULL) && (p->value != (
char *) NULL))
1313 (void) SetMagickSecurityPolicyValue(p->domain,p->name,p->value,exception);
1314 p=(PolicyInfo *) GetNextValueInLinkedList(user_policies);
1316 user_policies=DestroyLinkedList(user_policies,DestroyPolicyElement);
1353MagickExport MagickBooleanType SetMagickSecurityPolicyValue(
1354 const PolicyDomain domain,
const char *name,
const char *value,
1355 ExceptionInfo *exception)
1357 magick_unreferenced(exception);
1358 assert(exception != (ExceptionInfo *) NULL);
1359 if ((name == (
const char *) NULL) || (value == (
const char *) NULL))
1360 return(MagickFalse);
1363 case CachePolicyDomain:
1365 if (LocaleCompare(name,
"memory-map") == 0)
1367 if (LocaleCompare(value,
"anonymous") != 0)
1368 return(MagickFalse);
1369 ResetCacheAnonymousMemory();
1370 ResetStreamAnonymousMemory();
1375 case ResourcePolicyDomain:
1380 type=ParseCommandOption(MagickResourceOptions,MagickFalse,name);
1386 limit=MagickResourceInfinity;
1387 if (LocaleCompare(
"unlimited",value) != 0)
1388 limit=StringToMagickSizeType(value,100.0);
1389 if ((ResourceType) type == TimeResource)
1390 limit=(MagickSizeType) ParseMagickTimeToLive(value);
1391 return(SetMagickResourceLimit((ResourceType) type,limit));
1395 case SystemPolicyDomain:
1397 if (LocaleCompare(name,
"max-memory-request") == 0)
1402 limit=MagickResourceInfinity;
1403 if (LocaleCompare(
"unlimited",value) != 0)
1404 limit=StringToMagickSizeType(value,100.0);
1405 SetMaxMemoryRequest(limit);
1408 if (LocaleCompare(name,
"max-profile-size") == 0)
1413 limit=MagickResourceInfinity;
1414 if (LocaleCompare(
"unlimited",value) != 0)
1415 limit=StringToMagickSizeType(value,100.0);
1416 SetMaxProfileSize(limit);
1419 if (LocaleCompare(name,
"memory-map") == 0)
1421 if (LocaleCompare(value,
"anonymous") != 0)
1422 return(MagickFalse);
1423 ResetVirtualAnonymousMemory();
1426 if (LocaleCompare(name,
"precision") == 0)
1431 limit=StringToInteger(value);
1432 SetMagickPrecision(limit);
1437 case CoderPolicyDomain:
1438 case DelegatePolicyDomain:
1439 case FilterPolicyDomain:
1440 case ModulePolicyDomain:
1441 case PathPolicyDomain:
1445 return(MagickFalse);