2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % PPPP OOO L IIIII CCCC Y Y %
9 % P OOO LLLLL IIIII CCCC Y %
12 % MagickCore Policy Methods %
19 % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % https://www.imagemagick.org/script/license.php %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 % We use linked-lists because splay-trees do not currently support duplicate
36 % key / value pairs (.e.g X11 green compliance and SVG green compliance).
43 #include "MagickCore/studio.h"
44 #include "MagickCore/client.h"
45 #include "MagickCore/configure.h"
46 #include "MagickCore/configure-private.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/memory_.h"
50 #include "MagickCore/monitor.h"
51 #include "MagickCore/monitor-private.h"
52 #include "MagickCore/option.h"
53 #include "MagickCore/policy.h"
54 #include "MagickCore/policy-private.h"
55 #include "MagickCore/semaphore.h"
56 #include "MagickCore/string_.h"
57 #include "MagickCore/token.h"
58 #include "MagickCore/utility.h"
59 #include "MagickCore/utility-private.h"
60 #include "MagickCore/xml-tree.h"
61 #include "MagickCore/xml-tree-private.h"
66 #define PolicyFilename "policy.xml"
99 typedef struct _PolicyMapInfo
116 static const PolicyMapInfo
119 { UndefinedPolicyDomain, UndefinedPolicyRights, (const char *) NULL,
120 (const char *) NULL, (const char *) NULL }
123 static LinkedListInfo
124 *policy_cache = (LinkedListInfo *) NULL;
127 *policy_semaphore = (SemaphoreInfo *) NULL;
130 Forward declarations.
132 static MagickBooleanType
133 IsPolicyCacheInstantiated(ExceptionInfo *),
134 LoadPolicyCache(LinkedListInfo *,const char *,const char *,const size_t,
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % A c q u i r e P o l i c y C a c h e %
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % AcquirePolicyCache() caches one or more policy configurations which provides
149 % a mapping between policy attributes and a policy name.
151 % The format of the AcquirePolicyCache method is:
153 % LinkedListInfo *AcquirePolicyCache(const char *filename,
154 % ExceptionInfo *exception)
156 % A description of each parameter follows:
158 % o filename: the font file name.
160 % o exception: return any errors or warnings in this structure.
163 static LinkedListInfo *AcquirePolicyCache(const char *filename,
164 ExceptionInfo *exception)
176 Load external policy map.
178 cache=NewLinkedList(0);
179 if (cache == (LinkedListInfo *) NULL)
180 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
182 #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
190 options=GetConfigureOptions(filename,exception);
191 option=(const StringInfo *) GetNextValueInLinkedList(options);
192 while (option != (const StringInfo *) NULL)
194 status&=LoadPolicyCache(cache,(const char *)
195 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
196 option=(const StringInfo *) GetNextValueInLinkedList(options);
198 options=DestroyConfigureOptions(options);
202 Load built-in policy map.
204 for (i=0; i < (ssize_t) (sizeof(PolicyMap)/sizeof(*PolicyMap)); i++)
209 register const PolicyMapInfo
213 policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info));
214 if (policy_info == (PolicyInfo *) NULL)
216 (void) ThrowMagickException(exception,GetMagickModule(),
217 ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name);
220 (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
221 policy_info->path=(char *) "[built-in]";
222 policy_info->domain=p->domain;
223 policy_info->rights=p->rights;
224 policy_info->name=(char *) p->name;
225 policy_info->pattern=(char *) p->pattern;
226 policy_info->value=(char *) p->value;
227 policy_info->exempt=MagickTrue;
228 policy_info->signature=MagickCoreSignature;
229 status&=AppendValueToLinkedList(cache,policy_info);
230 if (status == MagickFalse)
231 (void) ThrowMagickException(exception,GetMagickModule(),
232 ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name);
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 + G e t P o l i c y I n f o %
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 % GetPolicyInfo() searches the policy list for the specified name and if found
249 % returns attributes for that policy.
251 % The format of the GetPolicyInfo method is:
253 % PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
255 % A description of each parameter follows:
257 % o name: the policy name.
259 % o exception: return any errors or warnings in this structure.
262 static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
265 policyname[MagickPathExtent];
276 assert(exception != (ExceptionInfo *) NULL);
277 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
278 return((PolicyInfo *) NULL);
280 Strip names of whitespace.
283 if (name != (const char *) NULL)
284 (void) CopyMagickString(policyname,name,MagickPathExtent);
285 for (q=policyname; *q != '\0'; q++)
287 if (isspace((int) ((unsigned char) *q)) == 0)
289 (void) CopyMagickString(q,q+1,MagickPathExtent);
293 Strip domain from policy name (e.g. resource:map).
295 domain=UndefinedPolicyDomain;
296 for (q=policyname; *q != '\0'; q++)
301 domain=(PolicyDomain) ParseCommandOption(MagickPolicyDomainOptions,
302 MagickTrue,policyname);
303 (void) CopyMagickString(policyname,q+1,MagickPathExtent);
307 Search for policy tag.
309 LockSemaphoreInfo(policy_semaphore);
310 ResetLinkedListIterator(policy_cache);
311 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
312 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
314 UnlockSemaphoreInfo(policy_semaphore);
317 while (p != (PolicyInfo *) NULL)
319 if ((domain == UndefinedPolicyDomain) || (p->domain == domain))
320 if (LocaleCompare(policyname,p->name) == 0)
322 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
324 if (p != (PolicyInfo *) NULL)
325 (void) InsertValueInLinkedList(policy_cache,0,
326 RemoveElementByValueFromLinkedList(policy_cache,p));
327 UnlockSemaphoreInfo(policy_semaphore);
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 % G e t P o l i c y I n f o L i s t %
340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 % GetPolicyInfoList() returns any policies that match the specified pattern.
344 % The format of the GetPolicyInfoList function is:
346 % const PolicyInfo **GetPolicyInfoList(const char *pattern,
347 % size_t *number_policies,ExceptionInfo *exception)
349 % A description of each parameter follows:
351 % o pattern: Specifies a pointer to a text string containing a pattern.
353 % o number_policies: returns the number of policies in the list.
355 % o exception: return any errors or warnings in this structure.
358 MagickExport const PolicyInfo **GetPolicyInfoList(const char *pattern,
359 size_t *number_policies,ExceptionInfo *exception)
364 register const PolicyInfo
371 Allocate policy list.
373 assert(pattern != (char *) NULL);
374 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
375 assert(number_policies != (size_t *) NULL);
377 p=GetPolicyInfo("*",exception);
378 if (p == (const PolicyInfo *) NULL)
379 return((const PolicyInfo **) NULL);
380 policies=(const PolicyInfo **) AcquireQuantumMemory((size_t)
381 GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies));
382 if (policies == (const PolicyInfo **) NULL)
383 return((const PolicyInfo **) NULL);
385 Generate policy list.
387 LockSemaphoreInfo(policy_semaphore);
388 ResetLinkedListIterator(policy_cache);
389 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
390 for (i=0; p != (const PolicyInfo *) NULL; )
392 if ((p->stealth == MagickFalse) &&
393 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
395 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
397 UnlockSemaphoreInfo(policy_semaphore);
398 policies[i]=(PolicyInfo *) NULL;
399 *number_policies=(size_t) i;
404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 % G e t P o l i c y L i s t %
412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 % GetPolicyList() returns any policies that match the specified pattern.
416 % The format of the GetPolicyList function is:
418 % char **GetPolicyList(const char *pattern,size_t *number_policies,
419 % ExceptionInfo *exception)
421 % A description of each parameter follows:
423 % o pattern: a pointer to a text string containing a pattern.
425 % o number_policies: returns the number of policies in the list.
427 % o exception: return any errors or warnings in this structure.
430 MagickExport char **GetPolicyList(const char *pattern,
431 size_t *number_policies,ExceptionInfo *exception)
436 register const PolicyInfo
443 Allocate policy list.
445 assert(pattern != (char *) NULL);
446 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
447 assert(number_policies != (size_t *) NULL);
449 p=GetPolicyInfo("*",exception);
450 if (p == (const PolicyInfo *) NULL)
451 return((char **) NULL);
452 policies=(char **) AcquireQuantumMemory((size_t)
453 GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies));
454 if (policies == (char **) NULL)
455 return((char **) NULL);
457 Generate policy list.
459 LockSemaphoreInfo(policy_semaphore);
460 ResetLinkedListIterator(policy_cache);
461 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
462 for (i=0; p != (const PolicyInfo *) NULL; )
464 if ((p->stealth == MagickFalse) &&
465 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
466 policies[i++]=ConstantString(p->name);
467 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
469 UnlockSemaphoreInfo(policy_semaphore);
470 policies[i]=(char *) NULL;
471 *number_policies=(size_t) i;
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 % G e t P o l i c y V a l u e %
484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 % GetPolicyValue() returns the value associated with the named policy.
488 % The format of the GetPolicyValue method is:
490 % char *GetPolicyValue(const char *name)
492 % A description of each parameter follows:
494 % o policy_info: The policy info.
497 MagickExport char *GetPolicyValue(const char *name)
508 assert(name != (const char *) NULL);
509 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
510 exception=AcquireExceptionInfo();
511 policy_info=GetPolicyInfo(name,exception);
512 exception=DestroyExceptionInfo(exception);
513 if (policy_info == (PolicyInfo *) NULL)
514 return((char *) NULL);
515 value=policy_info->value;
516 if ((value == (const char *) NULL) || (*value == '\0'))
517 return((char *) NULL);
518 return(ConstantString(value));
522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
526 + I s P o l i c y C a c h e I n s t a n t i a t e d %
530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 % IsPolicyCacheInstantiated() determines if the policy list is instantiated.
533 % If not, it instantiates the list and returns it.
535 % The format of the IsPolicyInstantiated method is:
537 % MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
539 % A description of each parameter follows.
541 % o exception: return any errors or warnings in this structure.
544 static MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
546 if (policy_cache == (LinkedListInfo *) NULL)
548 if (policy_semaphore == (SemaphoreInfo *) NULL)
549 ActivateSemaphoreInfo(&policy_semaphore);
550 LockSemaphoreInfo(policy_semaphore);
551 if (policy_cache == (LinkedListInfo *) NULL)
552 policy_cache=AcquirePolicyCache(PolicyFilename,exception);
553 UnlockSemaphoreInfo(policy_semaphore);
555 return(policy_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563 % I s R i g h t s A u t h o r i z e d %
567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
569 % IsRightsAuthorized() returns MagickTrue if the policy authorizes the
570 % requested rights for the specified domain.
572 % The format of the IsRightsAuthorized method is:
574 % MagickBooleanType IsRightsAuthorized(const PolicyDomain domain,
575 % const PolicyRights rights,const char *pattern)
577 % A description of each parameter follows:
579 % o domain: the policy domain.
581 % o rights: the policy rights.
583 % o pattern: the coder, delegate, filter, or path pattern.
586 MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain,
587 const PolicyRights rights,const char *pattern)
601 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
602 "Domain: %s; rights=%s; pattern=\"%s\" ...",
603 CommandOptionToMnemonic(MagickPolicyDomainOptions,domain),
604 CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),pattern);
605 exception=AcquireExceptionInfo();
606 policy_info=GetPolicyInfo("*",exception);
607 exception=DestroyExceptionInfo(exception);
608 if (policy_info == (PolicyInfo *) NULL)
610 authorized=MagickTrue;
611 LockSemaphoreInfo(policy_semaphore);
612 ResetLinkedListIterator(policy_cache);
613 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
614 while (p != (PolicyInfo *) NULL)
616 if ((p->domain == domain) &&
617 (GlobExpression(pattern,p->pattern,MagickFalse) != MagickFalse))
619 if ((rights & ReadPolicyRights) != 0)
620 authorized=(p->rights & ReadPolicyRights) != 0 ? MagickTrue :
622 if ((rights & WritePolicyRights) != 0)
623 authorized=(p->rights & WritePolicyRights) != 0 ? MagickTrue :
625 if ((rights & ExecutePolicyRights) != 0)
626 authorized=(p->rights & ExecutePolicyRights) != 0 ? MagickTrue :
629 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
631 UnlockSemaphoreInfo(policy_semaphore);
636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
640 % L i s t P o l i c y I n f o %
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 % ListPolicyInfo() lists policies to the specified file.
648 % The format of the ListPolicyInfo method is:
650 % MagickBooleanType ListPolicyInfo(FILE *file,ExceptionInfo *exception)
652 % A description of each parameter follows.
654 % o file: List policy names to this file handle.
656 % o exception: return any errors or warnings in this structure.
659 MagickExport MagickBooleanType ListPolicyInfo(FILE *file,
660 ExceptionInfo *exception)
676 List name and attributes of each policy in the list.
678 if (file == (const FILE *) NULL)
680 policy_info=GetPolicyInfoList("*",&number_policies,exception);
681 if (policy_info == (const PolicyInfo **) NULL)
683 path=(const char *) NULL;
684 for (i=0; i < (ssize_t) number_policies; i++)
686 if (policy_info[i]->stealth != MagickFalse)
688 if (((path == (const char *) NULL) ||
689 (LocaleCompare(path,policy_info[i]->path) != 0)) &&
690 (policy_info[i]->path != (char *) NULL))
691 (void) FormatLocaleFile(file,"\nPath: %s\n",policy_info[i]->path);
692 path=policy_info[i]->path;
693 domain=CommandOptionToMnemonic(MagickPolicyDomainOptions,
694 policy_info[i]->domain);
695 (void) FormatLocaleFile(file," Policy: %s\n",domain);
696 if ((policy_info[i]->domain == CachePolicyDomain) ||
697 (policy_info[i]->domain == ResourcePolicyDomain) ||
698 (policy_info[i]->domain == SystemPolicyDomain))
700 if (policy_info[i]->name != (char *) NULL)
701 (void) FormatLocaleFile(file," name: %s\n",policy_info[i]->name);
702 if (policy_info[i]->value != (char *) NULL)
703 (void) FormatLocaleFile(file," value: %s\n",policy_info[i]->value);
707 (void) FormatLocaleFile(file," rights: ");
708 if (policy_info[i]->rights == NoPolicyRights)
709 (void) FormatLocaleFile(file,"None ");
710 if ((policy_info[i]->rights & ReadPolicyRights) != 0)
711 (void) FormatLocaleFile(file,"Read ");
712 if ((policy_info[i]->rights & WritePolicyRights) != 0)
713 (void) FormatLocaleFile(file,"Write ");
714 if ((policy_info[i]->rights & ExecutePolicyRights) != 0)
715 (void) FormatLocaleFile(file,"Execute ");
716 (void) FormatLocaleFile(file,"\n");
717 if (policy_info[i]->pattern != (char *) NULL)
718 (void) FormatLocaleFile(file," pattern: %s\n",
719 policy_info[i]->pattern);
722 policy_info=(const PolicyInfo **) RelinquishMagickMemory((void *)
729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733 + L o a d P o l i c y C a c h e %
737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
739 % LoadPolicyCache() loads the policy configurations which provides a mapping
740 % between policy attributes and a policy domain.
742 % The format of the LoadPolicyCache method is:
744 % MagickBooleanType LoadPolicyCache(LinkedListInfo *cache,const char *xml,
745 % const char *filename,const size_t depth,ExceptionInfo *exception)
747 % A description of each parameter follows:
749 % o xml: The policy list in XML format.
751 % o filename: The policy list filename.
753 % o depth: depth of <include /> statements.
755 % o exception: return any errors or warnings in this structure.
758 static MagickBooleanType LoadPolicyCache(LinkedListInfo *cache,const char *xml,
759 const char *filename,const size_t depth,ExceptionInfo *exception)
762 keyword[MagickPathExtent],
778 Load the policy map file.
780 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
781 "Loading policy file \"%s\" ...",filename);
782 if (xml == (char *) NULL)
785 policy_info=(PolicyInfo *) NULL;
786 token=AcquireString(xml);
787 extent=strlen(token)+MagickPathExtent;
788 for (q=(const char *) xml; *q != '\0'; )
793 GetNextToken(q,&q,extent,token);
796 (void) CopyMagickString(keyword,token,MagickPathExtent);
797 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
802 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
803 GetNextToken(q,&q,extent,token);
806 if (LocaleNCompare(keyword,"<!--",4) == 0)
811 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
812 GetNextToken(q,&q,extent,token);
815 if (LocaleCompare(keyword,"<include") == 0)
820 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
822 (void) CopyMagickString(keyword,token,MagickPathExtent);
823 GetNextToken(q,&q,extent,token);
826 GetNextToken(q,&q,extent,token);
827 if (LocaleCompare(keyword,"file") == 0)
830 (void) ThrowMagickException(exception,GetMagickModule(),
831 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
835 path[MagickPathExtent],
838 GetPathComponent(filename,HeadPath,path);
840 (void) ConcatenateMagickString(path,DirectorySeparator,
842 if (*token == *DirectorySeparator)
843 (void) CopyMagickString(path,token,MagickPathExtent);
845 (void) ConcatenateMagickString(path,token,MagickPathExtent);
846 file_xml=FileToXML(path,~0UL);
847 if (file_xml != (char *) NULL)
849 status&=LoadPolicyCache(cache,file_xml,path,
851 file_xml=DestroyString(file_xml);
858 if (LocaleCompare(keyword,"<policy") == 0)
863 policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info));
864 if (policy_info == (PolicyInfo *) NULL)
865 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
866 (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
867 policy_info->path=ConstantString(filename);
868 policy_info->exempt=MagickFalse;
869 policy_info->signature=MagickCoreSignature;
872 if (policy_info == (PolicyInfo *) NULL)
874 if ((LocaleCompare(keyword,"/>") == 0) ||
875 (LocaleCompare(keyword,"</policy>") == 0))
877 status=AppendValueToLinkedList(cache,policy_info);
878 if (status == MagickFalse)
879 (void) ThrowMagickException(exception,GetMagickModule(),
880 ResourceLimitError,"MemoryAllocationFailed","`%s'",
882 policy_info=(PolicyInfo *) NULL;
885 GetNextToken(q,(const char **) NULL,extent,token);
888 GetNextToken(q,&q,extent,token);
889 GetNextToken(q,&q,extent,token);
895 if (LocaleCompare((char *) keyword,"domain") == 0)
897 policy_info->domain=(PolicyDomain) ParseCommandOption(
898 MagickPolicyDomainOptions,MagickTrue,token);
906 if (LocaleCompare((char *) keyword,"name") == 0)
908 policy_info->name=ConstantString(token);
916 if (LocaleCompare((char *) keyword,"pattern") == 0)
918 policy_info->pattern=ConstantString(token);
926 if (LocaleCompare((char *) keyword,"rights") == 0)
928 policy_info->rights=(PolicyRights) ParseCommandOption(
929 MagickPolicyRightsOptions,MagickTrue,token);
937 if (LocaleCompare((char *) keyword,"stealth") == 0)
939 policy_info->stealth=IsStringTrue(token);
947 if (LocaleCompare((char *) keyword,"value") == 0)
949 policy_info->value=ConstantString(token);
958 token=(char *) RelinquishMagickMemory(token);
959 return(status != 0 ? MagickTrue : MagickFalse);
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 + P o l i c y C o m p o n e n t G e n e s i s %
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % PolicyComponentGenesis() instantiates the policy component.
975 % The format of the PolicyComponentGenesis method is:
977 % MagickBooleanType PolicyComponentGenesis(void)
980 MagickPrivate MagickBooleanType PolicyComponentGenesis(void)
982 if (policy_semaphore == (SemaphoreInfo *) NULL)
983 policy_semaphore=AcquireSemaphoreInfo();
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 + P o l i c y C o m p o n e n t T e r m i n u s %
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
998 % PolicyComponentTerminus() destroys the policy component.
1000 % The format of the PolicyComponentTerminus method is:
1002 % PolicyComponentTerminus(void)
1006 static void *DestroyPolicyElement(void *policy_info)
1011 p=(PolicyInfo *) policy_info;
1012 if (p->exempt == MagickFalse)
1014 if (p->value != (char *) NULL)
1015 p->value=DestroyString(p->value);
1016 if (p->pattern != (char *) NULL)
1017 p->pattern=DestroyString(p->pattern);
1018 if (p->name != (char *) NULL)
1019 p->name=DestroyString(p->name);
1020 if (p->path != (char *) NULL)
1021 p->path=DestroyString(p->path);
1023 p=(PolicyInfo *) RelinquishMagickMemory(p);
1024 return((void *) NULL);
1027 MagickPrivate void PolicyComponentTerminus(void)
1029 if (policy_semaphore == (SemaphoreInfo *) NULL)
1030 ActivateSemaphoreInfo(&policy_semaphore);
1031 LockSemaphoreInfo(policy_semaphore);
1032 if (policy_cache != (LinkedListInfo *) NULL)
1033 policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement);
1034 UnlockSemaphoreInfo(policy_semaphore);
1035 RelinquishSemaphoreInfo(&policy_semaphore);