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"
129 { UndefinedPolicyDomain, UndefinedPolicyRights, (
const char *) NULL,
130 (
const char *) NULL, (
const char *) NULL }
142static MagickBooleanType
144 LoadPolicyCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
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);
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));
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);
287 policyname[MagickPathExtent],
300 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
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);
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);
346 if ((domain == UndefinedPolicyDomain) || (policy->domain == domain))
347 if (LocaleCompare(policyname,policy->name) == 0)
354 (
void) SetHeadElementInLinkedList(policy_cache,p);
355 UnlockSemaphoreInfo(policy_semaphore);
386MagickExport
const PolicyInfo **GetPolicyInfoList(
const char *pattern,
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)
405 policies=(
const PolicyInfo **) AcquireQuantumMemory((
size_t)
406 GetNumberOfElementsInLinkedList(policy_cache)+1UL,
sizeof(*policies));
409 LockSemaphoreInfo(policy_semaphore);
410 p=GetHeadElementInLinkedList(policy_cache);
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);
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,
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);
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);
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));
600static inline MagickBooleanType IsPathContainsSymlink(
const char *path)
603 partial[MagickPathExtent];
611 if (path == (
const char *) NULL)
615 if (*p == *DirectorySeparator)
620 if ((offset+1) >= (ssize_t)
sizeof(partial))
622 partial[offset++]=(*p++);
623 partial[offset]=
'\0';
628 component[MagickPathExtent];
636 while ((*p !=
'\0') && (*p != *DirectorySeparator) &&
637 ((i+1) < (ssize_t)
sizeof(component)))
638 component[i++]=(*p++);
645 if (*p == *DirectorySeparator)
649 if ((offset > 0) && (partial[offset-1] != *DirectorySeparator))
654 if ((offset+1) >= (ssize_t)
sizeof(partial))
656 partial[offset++]=(*DirectorySeparator);
657 partial[offset]=
'\0';
662 if ((offset+i) >= (ssize_t)
sizeof(partial))
664 (void) memcpy(partial+offset,component,i);
666 partial[offset]=
'\0';
672 if (is_symlink_utf8(partial) != MagickFalse)
678 if (*p == *DirectorySeparator)
684MagickExport MagickBooleanType IsPathAuthorized(
const PolicyRights rights,
687 MagickBooleanType symlink_follow_allowed = IsRightsAuthorizedByName(
688 SystemPolicyDomain,
"symlink",rights,
"follow");
689 MagickBooleanType status =
690 ((IsRightsAuthorized(PathPolicyDomain,rights,path) != MagickFalse) &&
691 ((symlink_follow_allowed != MagickFalse) ||
692 (is_symlink_utf8(path) == MagickFalse))) ? MagickTrue : MagickFalse;
693 if ((status != MagickFalse) && (symlink_follow_allowed == MagickFalse))
695 if ((is_symlink_utf8(path) != MagickFalse) ||
696 (IsPathContainsSymlink(path) != MagickFalse))
699 if (status != MagickFalse)
700 status=IsFileResourceIdentityValid(path);
727static MagickBooleanType IsPolicyCacheInstantiated(
ExceptionInfo *exception)
731 (void) GetMaxMemoryRequest();
733 ActivateSemaphoreInfo(&policy_semaphore);
734 LockSemaphoreInfo(policy_semaphore);
736 policy_cache=AcquirePolicyCache(PolicyFilename,exception);
737 UnlockSemaphoreInfo(policy_semaphore);
739 return(policy_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
776MagickExport MagickBooleanType IsRightsAuthorizedByName(
777 const PolicyDomain domain,
const char *name,
const PolicyRights rights,
781 *canonical_directory = (
char *) NULL,
782 *canonical_path = (
char *) NULL,
783 *canonical_candidate = (
char *) NULL,
784 directory[MagickPathExtent],
785 filename[MagickPathExtent];
794 canonical_matched_any = MagickFalse,
795 matched_any = MagickFalse,
796 paths_provisioned = MagickFalse,
800 canonical_allowed_accumulator = AllPolicyRights,
801 effective_rights = AllPolicyRights;
806 if ((GetLogEventMask() & PolicyEvent) != 0)
807 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
808 "Domain: %s; name: %s; rights=%s; pattern=\"%s\"; ...",
809 CommandOptionToMnemonic(MagickPolicyDomainOptions,domain),
810 name == (
const char *) NULL ?
"undefined" : name,
811 CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),
812 pattern == (const char *) NULL ?
"undefined" : pattern);
813 exception=AcquireExceptionInfo();
814 status=IsPolicyCacheInstantiated(exception);
815 exception=DestroyExceptionInfo(exception);
816 if (status == MagickFalse)
818 if ((GetLogEventMask() & PolicyEvent) != 0)
819 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
820 " authorized: true (no security policies found)");
827 LockSemaphoreInfo(policy_semaphore);
828 ResetLinkedListIterator(policy_cache);
829 p=GetHeadElementInLinkedList(policy_cache);
837 matched_canonical = MagickFalse;
839 if (policy->domain != domain)
841 if ((name != (
char *) NULL) && (LocaleCompare(name,policy->name) != 0))
843 match=GlobExpression(pattern,policy->pattern,MagickFalse);
844 if (policy->domain == PathPolicyDomain)
846 if (paths_provisioned == MagickFalse)
851 paths_provisioned=MagickTrue;
852 GetPathComponent(pattern,HeadPath,directory);
853 GetPathComponent(pattern,TailPath,filename);
854 canonical_directory=realpath_utf8(directory);
855 if ((canonical_directory != (
char *) NULL) && (*filename !=
'\0'))
860 length=strlen(canonical_directory)+strlen(filename)+2;
861 canonical_candidate=(
char *) AcquireCriticalMemory(length*
862 sizeof(*canonical_candidate));
863 if (canonical_candidate != (
char *) NULL)
864 (
void) FormatLocaleString(canonical_candidate,length,
"%s%s%s",
865 canonical_directory,DirectorySeparator,filename);
867 canonical_path=realpath_utf8(pattern);
872 if ((canonical_directory != (
char *) NULL) && (match == MagickFalse))
873 match=GlobExpression(canonical_directory,policy->pattern,MagickFalse);
874 if ((canonical_candidate != (
char *) NULL) && (match == MagickFalse))
875 match=GlobExpression(canonical_candidate,policy->pattern,MagickFalse);
876 if ((canonical_path != (
char *) NULL) && (match == MagickFalse))
877 match=GlobExpression(canonical_path,policy->pattern,MagickFalse);
878 if ((canonical_path != (
char *) NULL) &&
879 (GlobExpression(canonical_path,policy->pattern,MagickFalse) != MagickFalse))
880 matched_canonical=MagickTrue;
882 if ((canonical_candidate != (
char *) NULL) &&
883 (GlobExpression(canonical_candidate,policy->pattern,MagickFalse) != MagickFalse))
884 matched_canonical=MagickTrue;
886 if ((canonical_directory != (
char *) NULL) &&
887 (GlobExpression(canonical_directory,policy->pattern,MagickFalse) != MagickFalse))
888 matched_canonical=MagickTrue;
890 if (match == MagickFalse)
892 matched_any=MagickTrue;
893 effective_rights=policy->rights;
894 if (matched_canonical != MagickFalse)
899 canonical_matched_any=MagickTrue;
900 canonical_allowed_accumulator&=policy->rights;
903 UnlockSemaphoreInfo(policy_semaphore);
904 if (canonical_directory != (
char *) NULL)
905 canonical_directory=DestroyString(canonical_directory);
906 if (canonical_candidate != (
char *) NULL)
907 canonical_candidate=DestroyString(canonical_candidate);
908 if (canonical_path != (
char *) NULL)
909 canonical_path=DestroyString(canonical_path);
914 if (matched_any != MagickFalse)
916 if (((rights & ReadPolicyRights) != 0) &&
917 ((effective_rights & ReadPolicyRights) == 0))
919 if (((rights & WritePolicyRights) != 0) &&
920 ((effective_rights & WritePolicyRights) == 0))
922 if (((rights & ExecutePolicyRights) != 0) &&
923 ((effective_rights & ExecutePolicyRights) == 0))
929 if (canonical_matched_any != MagickFalse)
931 PolicyRights canonical_denied_mask = (AllPolicyRights &
932 ~canonical_allowed_accumulator);
933 if ((canonical_denied_mask & rights) != 0)
936 if ((GetLogEventMask() & PolicyEvent) != 0)
937 (
void) LogMagickEvent(PolicyEvent,GetMagickModule(),
938 " authorized: %s",status == MagickFalse ?
"false" :
"true");
942MagickExport MagickBooleanType IsRightsAuthorized(
const PolicyDomain domain,
943 const PolicyRights rights,
const char *pattern)
945 return(IsRightsAuthorizedByName(domain,(
const char *) NULL,rights,pattern));
972MagickExport MagickBooleanType ListPolicyInfo(FILE *file,
991 if (file == (
const FILE *) NULL)
993 policy_info=GetPolicyInfoList(
"*",&number_policies,exception);
994 if (policy_info == (
const PolicyInfo **) NULL)
996 path=(
const char *) NULL;
997 for (i=0; i < (ssize_t) number_policies; i++)
999 if (policy_info[i]->stealth != MagickFalse)
1001 if (((path == (
const char *) NULL) ||
1002 (LocaleCompare(path,policy_info[i]->path) != 0)) &&
1003 (policy_info[i]->path != (
char *) NULL))
1004 (
void) FormatLocaleFile(file,
"\nPath: %s\n",policy_info[i]->path);
1005 path=policy_info[i]->path;
1006 domain=CommandOptionToMnemonic(MagickPolicyDomainOptions,
1007 policy_info[i]->domain);
1008 (void) FormatLocaleFile(file,
" Policy: %s\n",domain);
1009 if ((policy_info[i]->domain == CachePolicyDomain) ||
1010 (policy_info[i]->domain == ResourcePolicyDomain) ||
1011 (policy_info[i]->domain == SystemPolicyDomain))
1013 if (policy_info[i]->name != (
char *) NULL)
1014 (
void) FormatLocaleFile(file,
" name: %s\n",policy_info[i]->name);
1015 if (policy_info[i]->value != (
char *) NULL)
1016 (void) FormatLocaleFile(file,
" value: %s\n",policy_info[i]->value);
1020 (void) FormatLocaleFile(file,
" rights: ");
1021 if (policy_info[i]->rights == NoPolicyRights)
1022 (void) FormatLocaleFile(file,
"None ");
1023 if ((policy_info[i]->rights & ReadPolicyRights) != 0)
1024 (
void) FormatLocaleFile(file,
"Read ");
1025 if ((policy_info[i]->rights & WritePolicyRights) != 0)
1026 (void) FormatLocaleFile(file,
"Write ");
1027 if ((policy_info[i]->rights & ExecutePolicyRights) != 0)
1028 (
void) FormatLocaleFile(file,
"Execute ");
1029 (void) FormatLocaleFile(file,
"\n");
1030 if (policy_info[i]->pattern != (
char *) NULL)
1031 (
void) FormatLocaleFile(file,
" pattern: %s\n",
1032 policy_info[i]->pattern);
1035 policy_info=(
const PolicyInfo **) RelinquishMagickMemory((
void *)
1037 (void) fflush(file);
1072 const char *policy,
const char *filename,
const size_t depth,
1076 keyword[MagickPathExtent],
1094 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1095 "Loading policy file \"%s\" ...",filename);
1096 if (policy == (
char *) NULL)
1097 return(MagickFalse);
1100 token=AcquirePolicyString(policy,MagickPathExtent);
1101 extent=strlen(token)+MagickPathExtent;
1102 for (q=policy; *q !=
'\0'; )
1107 (void) GetNextToken(q,&q,extent,token);
1110 (void) CopyMagickString(keyword,token,MagickPathExtent);
1111 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
1116 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
1117 (
void) GetNextToken(q,&q,extent,token);
1120 if (LocaleNCompare(keyword,
"<!--",4) == 0)
1125 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
1126 (void) GetNextToken(q,&q,extent,token);
1129 if (LocaleCompare(keyword,
"<include") == 0)
1134 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1136 (void) CopyMagickString(keyword,token,MagickPathExtent);
1137 (void) GetNextToken(q,&q,extent,token);
1140 (void) GetNextToken(q,&q,extent,token);
1141 if (LocaleCompare(keyword,
"file") == 0)
1143 if (depth > MagickMaxRecursionDepth)
1144 (void) ThrowMagickException(exception,GetMagickModule(),
1145 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
1149 path[MagickPathExtent],
1152 GetPathComponent(filename,HeadPath,path);
1154 (void) ConcatenateMagickString(path,DirectorySeparator,
1156 if (*token == *DirectorySeparator)
1157 (void) CopyMagickString(path,token,MagickPathExtent);
1159 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
1160 file_xml=FileToXML(path,~0UL);
1161 if (file_xml != (
char *) NULL)
1163 status&=(MagickStatusType) LoadPolicyCache(cache,file_xml,
1164 path,depth+1,exception);
1165 file_xml=DestroyString(file_xml);
1172 if (LocaleCompare(keyword,
"<policy") == 0)
1177 policy_info=(
PolicyInfo *) AcquireCriticalMemory(
sizeof(*policy_info));
1178 (void) memset(policy_info,0,
sizeof(*policy_info));
1179 policy_info->path=AcquirePolicyString(filename,1);
1180 policy_info->exempt=MagickFalse;
1181 policy_info->signature=MagickCoreSignature;
1186 if ((LocaleCompare(keyword,
"/>") == 0) ||
1187 (LocaleCompare(keyword,
"</policy>") == 0))
1189 status=AppendValueToLinkedList(cache,policy_info);
1190 if (status == MagickFalse)
1191 (void) ThrowMagickException(exception,GetMagickModule(),
1192 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1197 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1200 (void) GetNextToken(q,&q,extent,token);
1201 (void) GetNextToken(q,&q,extent,token);
1207 if (LocaleCompare((
char *) keyword,
"domain") == 0)
1209 policy_info->domain=(PolicyDomain) ParseCommandOption(
1210 MagickPolicyDomainOptions,MagickTrue,token);
1218 if (LocaleCompare((
char *) keyword,
"name") == 0)
1220 policy_info->name=AcquirePolicyString(token,1);
1228 if (LocaleCompare((
char *) keyword,
"pattern") == 0)
1230 policy_info->pattern=AcquirePolicyString(token,1);
1238 if (LocaleCompare((
char *) keyword,
"rights") == 0)
1240 policy_info->rights=(PolicyRights) ParseCommandOption(
1241 MagickPolicyRightsOptions,MagickTrue,token);
1249 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
1251 policy_info->stealth=IsStringTrue(token);
1259 if (LocaleCompare((
char *) keyword,
"value") == 0)
1261 policy_info->value=AcquirePolicyString(token,1);
1270 token=(
char *) RelinquishMagickMemory(token);
1271 return(status != 0 ? MagickTrue : MagickFalse);
1292MagickPrivate MagickBooleanType PolicyComponentGenesis(
void)
1295 policy_semaphore=AcquireSemaphoreInfo();
1318static void *DestroyPolicyElement(
void *policy_info)
1324 if (p->exempt == MagickFalse)
1326 if (p->value != (
char *) NULL)
1327 p->value=DestroyString(p->value);
1328 if (p->pattern != (
char *) NULL)
1329 p->pattern=DestroyString(p->pattern);
1330 if (p->name != (
char *) NULL)
1331 p->name=DestroyString(p->name);
1332 if (p->path != (
char *) NULL)
1333 p->path=DestroyString(p->path);
1336 return((
void *) NULL);
1339MagickPrivate
void PolicyComponentTerminus(
void)
1342 ActivateSemaphoreInfo(&policy_semaphore);
1343 LockSemaphoreInfo(policy_semaphore);
1345 policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement);
1346 UnlockSemaphoreInfo(policy_semaphore);
1347 RelinquishSemaphoreInfo(&policy_semaphore);
1377static MagickBooleanType ValidateSecurityPolicy(
const char *policy,
1380#if defined(MAGICKCORE_XML_DELEGATE)
1387 document=xmlReadMemory(policy,(
int) strlen(policy),url,NULL,
1388 XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
1389 if (document == (xmlDocPtr) NULL)
1391 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
1392 "PolicyValidationException",
"'%s'",url);
1393 return(MagickFalse);
1395 xmlFreeDoc(document);
1404MagickExport MagickBooleanType SetMagickSecurityPolicy(
const char *policy,
1420 if (policy == (
const char *) NULL)
1421 return(MagickFalse);
1422 if (ValidateSecurityPolicy(policy,PolicyFilename,exception) == MagickFalse)
1423 return(MagickFalse);
1424 status=LoadPolicyCache(policy_cache,policy,
"[user-policy]",0,exception);
1425 if (status == MagickFalse)
1430 user_policies=NewLinkedList(0);
1431 status=LoadPolicyCache(user_policies,policy,
"[user-policy]",0,exception);
1432 if (status == MagickFalse)
1434 user_policies=DestroyLinkedList(user_policies,DestroyPolicyElement);
1435 return(MagickFalse);
1437 ResetLinkedListIterator(user_policies);
1438 p=(
PolicyInfo *) GetNextValueInLinkedList(user_policies);
1441 if ((p->name != (
char *) NULL) && (p->value != (
char *) NULL))
1442 (
void) SetMagickSecurityPolicyValue(p->domain,p->name,p->value,exception);
1443 p=(
PolicyInfo *) GetNextValueInLinkedList(user_policies);
1445 user_policies=DestroyLinkedList(user_policies,DestroyPolicyElement);
1482MagickExport MagickBooleanType SetMagickSecurityPolicyValue(
1483 const PolicyDomain domain,
const char *name,
const char *value,
1486 magick_unreferenced(exception);
1488 if ((name == (
const char *) NULL) || (value == (
const char *) NULL))
1489 return(MagickFalse);
1492 case CachePolicyDomain:
1494 if (LocaleCompare(name,
"memory-map") == 0)
1496 if (LocaleCompare(value,
"anonymous") != 0)
1497 return(MagickFalse);
1498 ResetCacheAnonymousMemory();
1499 ResetStreamAnonymousMemory();
1504 case ResourcePolicyDomain:
1509 type=ParseCommandOption(MagickResourceOptions,MagickFalse,name);
1515 limit=MagickResourceInfinity;
1516 if (LocaleCompare(
"unlimited",value) != 0)
1517 limit=StringToMagickSizeType(value,100.0);
1518 if ((ResourceType) type == TimeResource)
1519 limit=(MagickSizeType) ParseMagickTimeToLive(value);
1520 return(SetMagickResourceLimit((ResourceType) type,limit));
1524 case SystemPolicyDomain:
1526 if (LocaleCompare(name,
"max-memory-request") == 0)
1531 limit=MagickResourceInfinity;
1532 if (LocaleCompare(
"unlimited",value) != 0)
1533 limit=StringToMagickSizeType(value,100.0);
1534 SetMaxMemoryRequest(limit);
1537 if (LocaleCompare(name,
"max-profile-size") == 0)
1542 limit=MagickResourceInfinity;
1543 if (LocaleCompare(
"unlimited",value) != 0)
1544 limit=StringToMagickSizeType(value,100.0);
1545 SetMaxProfileSize(limit);
1548 if (LocaleCompare(name,
"memory-map") == 0)
1550 if (LocaleCompare(value,
"anonymous") != 0)
1551 return(MagickFalse);
1552 ResetVirtualAnonymousMemory();
1555 if (LocaleCompare(name,
"precision") == 0)
1560 limit=StringToInteger(value);
1561 SetMagickPrecision(limit);
1566 case CoderPolicyDomain:
1567 case DelegatePolicyDomain:
1568 case FilterPolicyDomain:
1569 case ModulePolicyDomain:
1570 case PathPolicyDomain:
1574 return(MagickFalse);