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,
148 *DestroyPolicyElement(
void *);
192 cache=NewLinkedList(0);
194#if MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
195 magick_unreferenced(filename);
196 status=LoadPolicyCache(cache,ZeroConfigurationPolicy,
"[zero-configuration]",0,
206 options=GetConfigureOptions(filename,exception);
207 option=(
const StringInfo *) GetNextValueInLinkedList(options);
210 status=LoadPolicyCache(cache,(
const char *) GetStringInfoDatum(option),
211 GetStringInfoPath(option),0,exception);
212 if (status == MagickFalse)
214 option=(
const StringInfo *) GetNextValueInLinkedList(options);
216 options=DestroyConfigureOptions(options);
219 if (status == MagickFalse)
221 cache=DestroyLinkedList(cache,DestroyPolicyElement);
222 CatchException(exception);
228 for (i=0; i < (ssize_t) (
sizeof(PolicyMap)/
sizeof(*PolicyMap)); i++)
237 policy_info=(
PolicyInfo *) AcquireMagickMemory(
sizeof(*policy_info));
240 (void) ThrowMagickException(exception,GetMagickModule(),
241 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
242 p->name == (
char *) NULL ?
"" : p->name);
243 CatchException(exception);
246 (void) memset(policy_info,0,
sizeof(*policy_info));
247 policy_info->path=(
char *)
"[built-in]";
248 policy_info->domain=p->domain;
249 policy_info->rights=p->rights;
250 policy_info->name=(
char *) p->name;
251 policy_info->pattern=(
char *) p->pattern;
252 policy_info->value=(
char *) p->value;
253 policy_info->exempt=MagickTrue;
254 policy_info->signature=MagickCoreSignature;
255 status=AppendValueToLinkedList(cache,policy_info);
256 if (status == MagickFalse)
258 (void) ThrowMagickException(exception,GetMagickModule(),
259 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
260 p->name == (
char *) NULL ?
"" : p->name);
261 CatchException(exception);
295 policyname[MagickPathExtent],
308 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
314 if (name != (
const char *) NULL)
315 (void) CopyMagickString(policyname,name,MagickPathExtent);
316 for (q=policyname; *q !=
'\0'; q++)
318 if (isspace((
int) ((
unsigned char) *q)) == 0)
320 (void) CopyMagickString(q,q+1,MagickPathExtent);
326 domain=UndefinedPolicyDomain;
327 for (q=policyname; *q !=
'\0'; q++)
332 domain=(PolicyDomain) ParseCommandOption(MagickPolicyDomainOptions,
333 MagickTrue,policyname);
334 (void) CopyMagickString(policyname,q+1,MagickPathExtent);
341 LockSemaphoreInfo(policy_semaphore);
342 ResetLinkedListIterator(policy_cache);
343 p=GetHeadElementInLinkedList(policy_cache);
344 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
346 UnlockSemaphoreInfo(policy_semaphore);
354 if ((domain == UndefinedPolicyDomain) || (policy->domain == domain))
355 if (LocaleCompare(policyname,policy->name) == 0)
362 (
void) SetHeadElementInLinkedList(policy_cache,p);
363 UnlockSemaphoreInfo(policy_semaphore);
394MagickExport
const PolicyInfo **GetPolicyInfoList(
const char *pattern,
406 assert(pattern != (
char *) NULL);
407 assert(number_policies != (
size_t *) NULL);
408 if (IsEventLogging() != MagickFalse)
409 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
411 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
413 policies=(
const PolicyInfo **) AcquireQuantumMemory((
size_t)
414 GetNumberOfElementsInLinkedList(policy_cache)+1UL,
sizeof(*policies));
417 LockSemaphoreInfo(policy_semaphore);
418 p=GetHeadElementInLinkedList(policy_cache);
425 if ((policy->stealth == MagickFalse) &&
426 (GlobExpression(policy->name,pattern,MagickFalse) != MagickFalse))
427 policies[i++]=policy;
430 UnlockSemaphoreInfo(policy_semaphore);
432 policies=(
const PolicyInfo **) RelinquishMagickMemory((
void*) policies);
435 *number_policies=(size_t) i;
467static char *AcquirePolicyString(
const char *source,
const size_t pad)
476 if (source != (
char *) NULL)
477 length+=strlen(source);
478 destination=(
char *) NULL;
481 destination=(
char *) AcquireMagickMemory((length+pad)*
sizeof(*destination));
482 if (destination == (
char *) NULL)
483 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
484 if (source != (
char *) NULL)
485 (void) memcpy(destination,source,length*
sizeof(*destination));
486 destination[length]=
'\0';
490MagickExport
char **GetPolicyList(
const char *pattern,
size_t *number_policies,
502 assert(pattern != (
char *) NULL);
503 assert(number_policies != (
size_t *) NULL);
504 if (IsEventLogging() != MagickFalse)
505 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
507 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
508 return((
char **) NULL);
509 policies=(
char **) AcquireQuantumMemory((
size_t)
510 GetNumberOfElementsInLinkedList(policy_cache)+1UL,
sizeof(*policies));
511 if (policies == (
char **) NULL)
512 return((
char **) NULL);
513 LockSemaphoreInfo(policy_semaphore);
514 p=GetHeadElementInLinkedList(policy_cache);
521 if ((policy->stealth == MagickFalse) &&
522 (GlobExpression(policy->name,pattern,MagickFalse) != MagickFalse))
523 policies[i++]=AcquirePolicyString(policy->name,1);
526 UnlockSemaphoreInfo(policy_semaphore);
528 policies=(
char **) RelinquishMagickMemory(policies);
530 policies[i]=(
char *) NULL;
531 *number_policies=(size_t) i;
557MagickExport
char *GetPolicyValue(
const char *name)
568 assert(name != (
const char *) NULL);
569 if (IsEventLogging() != MagickFalse)
570 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
571 exception=AcquireExceptionInfo();
572 policy_info=GetPolicyInfo(name,exception);
573 exception=DestroyExceptionInfo(exception);
575 return((
char *) NULL);
576 value=policy_info->value;
577 if ((value == (
const char *) NULL) || (*value ==
'\0'))
578 return((
char *) NULL);
579 return(AcquirePolicyString(value,1));
609static inline MagickBooleanType IsPolicyPathSeparator(
const char c)
611#if defined(MAGICKCORE_WINDOWS_SUPPORT)
612 if ((c ==
'/') || (c ==
'\\'))
615 return(c == *DirectorySeparator ? MagickTrue : MagickFalse);
618static inline MagickBooleanType IsPathContainsSymlink(
const char *path)
621 partial[MagickPathExtent];
629 if (path == (
const char *) NULL)
633 if (IsPolicyPathSeparator(*p) != MagickFalse)
638 if ((offset+1) >= (ssize_t)
sizeof(partial))
640 partial[offset++]=(*DirectorySeparator);
642 partial[offset]=
'\0';
647 component[MagickPathExtent];
655 while ((*p !=
'\0') && (IsPolicyPathSeparator(*p) == MagickFalse) &&
656 ((i+1) < (ssize_t)
sizeof(component)))
657 component[i++]=(*p++);
664 if (IsPolicyPathSeparator(*p) != MagickFalse)
668 if ((offset > 0) && (partial[offset-1] != *DirectorySeparator))
673 if ((offset+1) >= (ssize_t)
sizeof(partial))
675 partial[offset++]=(*DirectorySeparator);
676 partial[offset]=
'\0';
681 if ((offset+i) >= (ssize_t)
sizeof(partial))
683 (void) memcpy(partial+offset,component,i);
685 partial[offset]=
'\0';
691 if (is_symlink_utf8(partial) != MagickFalse)
697 if (IsPolicyPathSeparator(*p) != MagickFalse)
703MagickExport MagickBooleanType IsPathAuthorized(
const PolicyRights rights,
706 MagickBooleanType symlink_follow_allowed = IsRightsAuthorizedByName(
707 SystemPolicyDomain,
"symlink",rights,
"follow");
708 MagickBooleanType status =
709 ((IsRightsAuthorized(PathPolicyDomain,rights,path) != MagickFalse) &&
710 ((symlink_follow_allowed != MagickFalse) ||
711 (is_symlink_utf8(path) == MagickFalse))) ? MagickTrue : MagickFalse;
712 if ((status != MagickFalse) && (symlink_follow_allowed == MagickFalse))
714 if ((is_symlink_utf8(path) != MagickFalse) ||
715 (IsPathContainsSymlink(path) != MagickFalse))
718 if (status != MagickFalse)
719 status=IsFileResourceIdentityValid(path);
746static MagickBooleanType IsPolicyCacheInstantiated(
ExceptionInfo *exception)
750 (void) GetMaxMemoryRequest();
752 ActivateSemaphoreInfo(&policy_semaphore);
753 LockSemaphoreInfo(policy_semaphore);
755 policy_cache=AcquirePolicyCache(PolicyFilename,exception);
756 UnlockSemaphoreInfo(policy_semaphore);
758 return(policy_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
795static MagickBooleanType IsPathPolicyMatch(
const char *path,
const char *pattern)
797#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
806 normalized_path=AcquireString(path);
807 normalized_pattern=AcquireString(pattern);
808 for (p=normalized_path; *p !=
'\0'; p++)
811 for (p=normalized_pattern; *p !=
'\0'; p++)
814 match=GlobExpression(normalized_path,normalized_pattern,MagickFalse);
815 normalized_path=DestroyString(normalized_path);
816 normalized_pattern=DestroyString(normalized_pattern);
819 return(GlobExpression(path,pattern,MagickFalse));
823MagickExport MagickBooleanType IsRightsAuthorizedByName(
824 const PolicyDomain domain,
const char *name,
const PolicyRights rights,
828 *canonical_directory = (
char *) NULL,
829 *canonical_path = (
char *) NULL,
830 *canonical_candidate = (
char *) NULL,
831 directory[MagickPathExtent],
832 filename[MagickPathExtent];
841 matched_any = MagickFalse,
842 paths_provisioned = MagickFalse,
843 resolved_matched_any = MagickFalse,
847 effective_rights = AllPolicyRights,
848 resolved_rights = AllPolicyRights;
853 if ((GetLogEventMask() & PolicyEvent) != 0)
854 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
855 "Domain: %s; name: %s; rights=%s; pattern=\"%s\"; ...",
856 CommandOptionToMnemonic(MagickPolicyDomainOptions,domain),
857 name == (
const char *) NULL ?
"undefined" : name,
858 CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),
859 pattern == (
const char *) NULL ?
"undefined" : pattern);
860 exception=AcquireExceptionInfo();
861 status=IsPolicyCacheInstantiated(exception);
862 exception=DestroyExceptionInfo(exception);
863 if (status == MagickFalse)
865 if ((GetLogEventMask() & PolicyEvent) != 0)
866 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
867 " authorized: false (security policies could not be loaded)");
877 LockSemaphoreInfo(policy_semaphore);
878 ResetLinkedListIterator(policy_cache);
879 p=GetHeadElementInLinkedList(policy_cache);
888 if (policy->domain != domain)
890 if ((name != (
char *) NULL) && (LocaleCompare(name,policy->name) != 0))
892 if (policy->domain == PathPolicyDomain)
894 match=IsPathPolicyMatch(pattern,policy->pattern);
895 if (paths_provisioned == MagickFalse)
900 paths_provisioned=MagickTrue;
901 GetPathComponent(pattern,HeadPath,directory);
902 GetPathComponent(pattern,TailPath,filename);
903 canonical_directory=realpath_utf8(directory);
904 if ((canonical_directory != (
char *) NULL) && (*filename !=
'\0'))
909 length=strlen(canonical_directory)+strlen(filename)+2;
910 canonical_candidate=(
char *) AcquireCriticalMemory(length*
911 sizeof(*canonical_candidate));
912 if (canonical_candidate != (
char *) NULL)
913 (void) FormatLocaleString(canonical_candidate,length,
"%s%s%s",
914 canonical_directory,DirectorySeparator,filename);
916 canonical_path=realpath_utf8(pattern);
921 if ((canonical_directory != (
char *) NULL) && (match == MagickFalse))
922 match=IsPathPolicyMatch(canonical_directory,policy->pattern);
923 if ((canonical_candidate != (
char *) NULL) && (match == MagickFalse))
924 match=IsPathPolicyMatch(canonical_candidate,policy->pattern);
928 if ((canonical_path != (
char *) NULL) &&
929 (IsPathPolicyMatch(canonical_path,policy->pattern) != MagickFalse))
931 resolved_matched_any=MagickTrue;
932 resolved_rights=policy->rights;
936 match=GlobExpression(pattern,policy->pattern,MagickFalse);
937 if (match == MagickFalse)
939 matched_any=MagickTrue;
940 effective_rights=policy->rights;
942 UnlockSemaphoreInfo(policy_semaphore);
947 if (matched_any != MagickFalse)
949 if (((rights & ReadPolicyRights) != 0) &&
950 ((effective_rights & ReadPolicyRights) == 0))
952 if (((rights & WritePolicyRights) != 0) &&
953 ((effective_rights & WritePolicyRights) == 0))
955 if (((rights & ExecutePolicyRights) != 0) &&
956 ((effective_rights & ExecutePolicyRights) == 0))
959 if (resolved_matched_any != MagickFalse)
961 if (((rights & ReadPolicyRights) != 0) &&
962 ((resolved_rights & ReadPolicyRights) == 0))
964 if (((rights & WritePolicyRights) != 0) &&
965 ((resolved_rights & WritePolicyRights) == 0))
967 if (((rights & ExecutePolicyRights) != 0) &&
968 ((resolved_rights & ExecutePolicyRights) == 0))
975 if ((paths_provisioned != MagickFalse) && (canonical_path == (
char *) NULL) &&
976 (is_symlink_utf8(pattern) != MagickFalse))
978 if (canonical_directory != (
char *) NULL)
979 canonical_directory=DestroyString(canonical_directory);
980 if (canonical_candidate != (
char *) NULL)
981 canonical_candidate=DestroyString(canonical_candidate);
982 if (canonical_path != (
char *) NULL)
983 canonical_path=DestroyString(canonical_path);
984 if ((GetLogEventMask() & PolicyEvent) != 0)
985 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
986 " authorized: %s",status == MagickFalse ?
"false" :
"true");
990MagickExport MagickBooleanType IsRightsAuthorized(
const PolicyDomain domain,
991 const PolicyRights rights,
const char *pattern)
993 return(IsRightsAuthorizedByName(domain,(
const char *) NULL,rights,pattern));
1020MagickExport MagickBooleanType ListPolicyInfo(FILE *file,
1039 if (file == (
const FILE *) NULL)
1041 policy_info=GetPolicyInfoList(
"*",&number_policies,exception);
1042 if (policy_info == (
const PolicyInfo **) NULL)
1043 return(MagickFalse);
1044 path=(
const char *) NULL;
1045 for (i=0; i < (ssize_t) number_policies; i++)
1047 if (policy_info[i]->stealth != MagickFalse)
1049 if (((path == (
const char *) NULL) ||
1050 (LocaleCompare(path,policy_info[i]->path) != 0)) &&
1051 (policy_info[i]->path != (
char *) NULL))
1052 (void) FormatLocaleFile(file,
"\nPath: %s\n",policy_info[i]->path);
1053 path=policy_info[i]->path;
1054 domain=CommandOptionToMnemonic(MagickPolicyDomainOptions,
1055 policy_info[i]->domain);
1056 (void) FormatLocaleFile(file,
" Policy: %s\n",domain);
1057 if ((policy_info[i]->domain == CachePolicyDomain) ||
1058 (policy_info[i]->domain == ResourcePolicyDomain) ||
1059 (policy_info[i]->domain == SystemPolicyDomain))
1061 if (policy_info[i]->name != (
char *) NULL)
1062 (void) FormatLocaleFile(file,
" name: %s\n",policy_info[i]->name);
1063 if (policy_info[i]->value != (
char *) NULL)
1064 (void) FormatLocaleFile(file,
" value: %s\n",policy_info[i]->value);
1068 (void) FormatLocaleFile(file,
" rights: ");
1069 if (policy_info[i]->rights == NoPolicyRights)
1070 (void) FormatLocaleFile(file,
"None ");
1071 if ((policy_info[i]->rights & ReadPolicyRights) != 0)
1072 (void) FormatLocaleFile(file,
"Read ");
1073 if ((policy_info[i]->rights & WritePolicyRights) != 0)
1074 (void) FormatLocaleFile(file,
"Write ");
1075 if ((policy_info[i]->rights & ExecutePolicyRights) != 0)
1076 (void) FormatLocaleFile(file,
"Execute ");
1077 (void) FormatLocaleFile(file,
"\n");
1078 if (policy_info[i]->pattern != (
char *) NULL)
1079 (void) FormatLocaleFile(file,
" pattern: %s\n",
1080 policy_info[i]->pattern);
1083 policy_info=(
const PolicyInfo **) RelinquishMagickMemory((
void *)
1085 (void) fflush(file);
1120static void *DestroyPolicyElement(
void *policy_info)
1126 if (p->exempt == MagickFalse)
1128 if (p->value != (
char *) NULL)
1129 p->value=DestroyString(p->value);
1130 if (p->pattern != (
char *) NULL)
1131 p->pattern=DestroyString(p->pattern);
1132 if (p->name != (
char *) NULL)
1133 p->name=DestroyString(p->name);
1134 if (p->path != (
char *) NULL)
1135 p->path=DestroyString(p->path);
1138 return((
void *) NULL);
1142 const char *policy,
const char *filename,
const size_t depth,
1146 keyword[MagickPathExtent],
1164 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1165 "Loading policy file \"%s\" ...",filename);
1166 if (policy == (
char *) NULL)
1167 return(MagickFalse);
1170 token=AcquirePolicyString(policy,MagickPathExtent);
1171 extent=strlen(token)+MagickPathExtent;
1172 for (q=policy; *q !=
'\0'; )
1177 if (SkipXMLComment(&q) == MagickFalse)
1179 (void) ThrowMagickException(exception,GetMagickModule(),
1180 ConfigureError,
"UnterminatedComment",
"`%s'",filename);
1184 (void) GetNextToken(q,&q,extent,token);
1187 (void) CopyMagickString(keyword,token,MagickPathExtent);
1188 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
1190 if (SkipXMLDocType(&q) == MagickFalse)
1195 (void) ThrowMagickException(exception,GetMagickModule(),
1196 ConfigureError,
"UnterminatedDOCTYPE",
"`%s'",filename);
1202 if (LocaleCompare(keyword,
"<include") == 0)
1207 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1209 (void) CopyMagickString(keyword,token,MagickPathExtent);
1210 (void) GetNextToken(q,&q,extent,token);
1213 (void) GetNextToken(q,&q,extent,token);
1214 if (LocaleCompare(keyword,
"file") == 0)
1216 if (depth >= MagickMaxRecursionDepth)
1217 (void) ThrowMagickException(exception,GetMagickModule(),
1218 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
1222 path[MagickPathExtent],
1225 GetPathComponent(filename,HeadPath,path);
1227 (void) ConcatenateMagickString(path,DirectorySeparator,
1229 if (*token == *DirectorySeparator)
1230 (void) CopyMagickString(path,token,MagickPathExtent);
1232 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
1233 file_xml=FileToXML(path,~0UL);
1234 if (file_xml != (
char *) NULL)
1236 if (LoadPolicyCache(cache,file_xml,path,depth+1,exception) == MagickFalse)
1238 file_xml=DestroyString(file_xml);
1239 if (status == MagickFalse)
1245 if (status == MagickFalse)
1249 if (LocaleCompare(keyword,
"<policy") == 0)
1254 policy_info=(
PolicyInfo *) AcquireCriticalMemory(
sizeof(*policy_info));
1255 (void) memset(policy_info,0,
sizeof(*policy_info));
1256 policy_info->path=AcquirePolicyString(filename,1);
1257 policy_info->exempt=MagickFalse;
1258 policy_info->signature=MagickCoreSignature;
1263 if ((LocaleCompare(keyword,
"/>") == 0) ||
1264 (LocaleCompare(keyword,
"</policy>") == 0))
1266 status=AppendValueToLinkedList(cache,policy_info);
1267 if (status == MagickFalse)
1268 (void) ThrowMagickException(exception,GetMagickModule(),
1269 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1274 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1277 (void) GetNextToken(q,&q,extent,token);
1278 (void) GetNextToken(q,&q,extent,token);
1284 if (LocaleCompare((
char *) keyword,
"domain") == 0)
1286 policy_info->domain=(PolicyDomain) ParseCommandOption(
1287 MagickPolicyDomainOptions,MagickTrue,token);
1295 if (LocaleCompare((
char *) keyword,
"name") == 0)
1297 policy_info->name=AcquirePolicyString(token,1);
1305 if (LocaleCompare((
char *) keyword,
"pattern") == 0)
1307 policy_info->pattern=AcquirePolicyString(token,1);
1315 if (LocaleCompare((
char *) keyword,
"rights") == 0)
1317 policy_info->rights=(PolicyRights) ParseCommandOption(
1318 MagickPolicyRightsOptions,MagickTrue,token);
1326 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
1328 policy_info->stealth=IsStringTrue(token);
1336 if (LocaleCompare((
char *) keyword,
"value") == 0)
1338 policy_info->value=AcquirePolicyString(token,1);
1348 (void) DestroyPolicyElement(policy_info);
1349 token=(
char *) RelinquishMagickMemory(token);
1371MagickPrivate MagickBooleanType PolicyComponentGenesis(
void)
1374 policy_semaphore=AcquireSemaphoreInfo();
1396MagickPrivate
void PolicyComponentTerminus(
void)
1399 ActivateSemaphoreInfo(&policy_semaphore);
1400 LockSemaphoreInfo(policy_semaphore);
1402 policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement);
1403 UnlockSemaphoreInfo(policy_semaphore);
1404 RelinquishSemaphoreInfo(&policy_semaphore);
1434static MagickBooleanType ValidateSecurityPolicy(
const char *policy,
1437#if defined(MAGICKCORE_XML_DELEGATE)
1444 document=xmlReadMemory(policy,(
int) strlen(policy),url,NULL,
1445 XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
1446 if (document == (xmlDocPtr) NULL)
1448 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
1449 "PolicyValidationException",
"'%s'",url);
1450 return(MagickFalse);
1452 xmlFreeDoc(document);
1461MagickExport MagickBooleanType SetMagickSecurityPolicy(
const char *policy,
1477 if (policy == (
const char *) NULL)
1478 return(MagickFalse);
1479 if (ValidateSecurityPolicy(policy,PolicyFilename,exception) == MagickFalse)
1480 return(MagickFalse);
1481 LockSemaphoreInfo(policy_semaphore);
1482 status=LoadPolicyCache(policy_cache,policy,
"[user-policy]",0,exception);
1483 UnlockSemaphoreInfo(policy_semaphore);
1484 if (status == MagickFalse)
1489 user_policies=NewLinkedList(0);
1490 status=LoadPolicyCache(user_policies,policy,
"[user-policy]",0,exception);
1491 if (status == MagickFalse)
1493 user_policies=DestroyLinkedList(user_policies,DestroyPolicyElement);
1494 return(MagickFalse);
1496 ResetLinkedListIterator(user_policies);
1497 p=(
PolicyInfo *) GetNextValueInLinkedList(user_policies);
1500 if ((p->name != (
char *) NULL) && (p->value != (
char *) NULL))
1501 (void) SetMagickSecurityPolicyValue(p->domain,p->name,p->value,exception);
1502 p=(
PolicyInfo *) GetNextValueInLinkedList(user_policies);
1504 user_policies=DestroyLinkedList(user_policies,DestroyPolicyElement);
1541MagickExport MagickBooleanType SetMagickSecurityPolicyValue(
1542 const PolicyDomain domain,
const char *name,
const char *value,
1545 magick_unreferenced(exception);
1547 if ((name == (
const char *) NULL) || (value == (
const char *) NULL))
1548 return(MagickFalse);
1551 case CachePolicyDomain:
1553 if (LocaleCompare(name,
"memory-map") == 0)
1555 if (LocaleCompare(value,
"anonymous") != 0)
1556 return(MagickFalse);
1557 ResetCacheAnonymousMemory();
1558 ResetStreamAnonymousMemory();
1563 case ResourcePolicyDomain:
1568 type=ParseCommandOption(MagickResourceOptions,MagickFalse,name);
1574 limit=MagickResourceInfinity;
1575 if (LocaleCompare(
"unlimited",value) != 0)
1576 limit=StringToMagickSizeType(value,100.0);
1577 if ((ResourceType) type == TimeResource)
1578 limit=(MagickSizeType) ParseMagickTimeToLive(value);
1579 return(SetMagickResourceLimit((ResourceType) type,limit));
1583 case SystemPolicyDomain:
1585 if (LocaleCompare(name,
"max-memory-request") == 0)
1590 limit=MagickResourceInfinity;
1591 if (LocaleCompare(
"unlimited",value) != 0)
1592 limit=StringToMagickSizeType(value,100.0);
1593 SetMaxMemoryRequest(limit);
1596 if (LocaleCompare(name,
"max-profile-size") == 0)
1601 limit=MagickResourceInfinity;
1602 if (LocaleCompare(
"unlimited",value) != 0)
1603 limit=StringToMagickSizeType(value,100.0);
1604 SetMaxProfileSize(limit);
1607 if (LocaleCompare(name,
"memory-map") == 0)
1609 if (LocaleCompare(value,
"anonymous") != 0)
1610 return(MagickFalse);
1611 ResetVirtualAnonymousMemory();
1614 if (LocaleCompare(name,
"precision") == 0)
1619 limit=StringToInteger(value);
1620 SetMagickPrecision(limit);
1625 case CoderPolicyDomain:
1626 case DelegatePolicyDomain:
1627 case FilterPolicyDomain:
1628 case ModulePolicyDomain:
1629 case PathPolicyDomain:
1633 return(MagickFalse);