2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % PPPP OOO L IIIII CCCC Y Y %
9 % P OOO LLLLL IIIII CCCC Y %
12 % MagickCore Policy Methods %
19 % Copyright 1999-2014 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 % http://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"
65 #define PolicyFilename "policy.xml"
98 typedef struct _PolicyMapInfo
115 static const PolicyMapInfo
118 { UndefinedPolicyDomain, UndefinedPolicyRights, (const char *) NULL,
119 (const char *) NULL, (const char *) NULL }
122 static LinkedListInfo
123 *policy_cache = (LinkedListInfo *) NULL;
126 *policy_semaphore = (SemaphoreInfo *) NULL;
129 Forward declarations.
131 static MagickBooleanType
132 IsPolicyCacheInstantiated(ExceptionInfo *),
133 LoadPolicyCache(const char *,const char *,const size_t,ExceptionInfo *);
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % A c q u i r e P o l i c y C a c h e %
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 % AcquirePolicyCache() caches one or more policy configurations which provides
147 % a mapping between policy attributes and a policy name.
149 % The format of the AcquirePolicyCache method is:
151 % LinkedListInfo *AcquirePolicyCache(const char *filename,
152 % ExceptionInfo *exception)
154 % A description of each parameter follows:
156 % o filename: the font file name.
158 % o exception: return any errors or warnings in this structure.
161 static LinkedListInfo *AcquirePolicyCache(const char *filename,
162 ExceptionInfo *exception)
178 Load external policy map.
180 policy_cache=NewLinkedList(0);
181 if (policy_cache == (LinkedListInfo *) NULL)
182 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
184 options=GetConfigureOptions(filename,exception);
185 option=(const StringInfo *) GetNextValueInLinkedList(options);
186 while (option != (const StringInfo *) NULL)
188 status&=LoadPolicyCache((const char *) GetStringInfoDatum(option),
189 GetStringInfoPath(option),0,exception);
190 option=(const StringInfo *) GetNextValueInLinkedList(options);
192 options=DestroyConfigureOptions(options);
194 Load built-in policy map.
196 for (i=0; i < (ssize_t) (sizeof(PolicyMap)/sizeof(*PolicyMap)); i++)
201 register const PolicyMapInfo
205 policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info));
206 if (policy_info == (PolicyInfo *) NULL)
208 (void) ThrowMagickException(exception,GetMagickModule(),
209 ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name);
212 (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
213 policy_info->path=(char *) "[built-in]";
214 policy_info->domain=p->domain;
215 policy_info->rights=p->rights;
216 policy_info->name=(char *) p->name;
217 policy_info->pattern=(char *) p->pattern;
218 policy_info->value=(char *) p->value;
219 policy_info->exempt=MagickTrue;
220 policy_info->signature=MagickSignature;
221 status&=AppendValueToLinkedList(policy_cache,policy_info);
222 if (status == MagickFalse)
223 (void) ThrowMagickException(exception,GetMagickModule(),
224 ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name);
226 return(policy_cache);
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 + G e t P o l i c y I n f o %
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % GetPolicyInfo() searches the policy list for the specified name and if found
241 % returns attributes for that policy.
243 % The format of the GetPolicyInfo method is:
245 % PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
247 % A description of each parameter follows:
249 % o name: the policy name.
251 % o exception: return any errors or warnings in this structure.
254 static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
257 policyname[MaxTextExtent];
265 assert(exception != (ExceptionInfo *) NULL);
266 if (IsPolicyCacheInstantiated(exception) == MagickFalse)
267 return((PolicyInfo *) NULL);
269 Strip names of whitespace.
272 if (name != (const char *) NULL)
273 (void) CopyMagickString(policyname,name,MaxTextExtent);
274 for (q=policyname; *q != '\0'; q++)
276 if (isspace((int) ((unsigned char) *q)) == 0)
278 (void) CopyMagickString(q,q+1,MaxTextExtent);
282 Search for policy tag.
284 LockSemaphoreInfo(policy_semaphore);
285 ResetLinkedListIterator(policy_cache);
286 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
287 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
289 UnlockSemaphoreInfo(policy_semaphore);
292 while (p != (PolicyInfo *) NULL)
294 if (LocaleCompare(policyname,p->name) == 0)
296 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
298 if (p != (PolicyInfo *) NULL)
299 (void) InsertValueInLinkedList(policy_cache,0,
300 RemoveElementByValueFromLinkedList(policy_cache,p));
301 UnlockSemaphoreInfo(policy_semaphore);
306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % G e t P o l i c y I n f o L i s t %
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 % GetPolicyInfoList() returns any policies that match the specified pattern.
318 % The format of the GetPolicyInfoList function is:
320 % const PolicyInfo **GetPolicyInfoList(const char *pattern,
321 % size_t *number_policies,ExceptionInfo *exception)
323 % A description of each parameter follows:
325 % o pattern: Specifies a pointer to a text string containing a pattern.
327 % o number_policies: returns the number of policies in the list.
329 % o exception: return any errors or warnings in this structure.
332 MagickExport const PolicyInfo **GetPolicyInfoList(const char *pattern,
333 size_t *number_policies,ExceptionInfo *exception)
338 register const PolicyInfo
345 Allocate policy list.
347 assert(pattern != (char *) NULL);
348 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
349 assert(number_policies != (size_t *) NULL);
351 p=GetPolicyInfo("*",exception);
352 if (p == (const PolicyInfo *) NULL)
353 return((const PolicyInfo **) NULL);
354 policies=(const PolicyInfo **) AcquireQuantumMemory((size_t)
355 GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies));
356 if (policies == (const PolicyInfo **) NULL)
357 return((const PolicyInfo **) NULL);
359 Generate policy list.
361 LockSemaphoreInfo(policy_semaphore);
362 ResetLinkedListIterator(policy_cache);
363 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
364 for (i=0; p != (const PolicyInfo *) NULL; )
366 if ((p->stealth == MagickFalse) &&
367 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
369 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
371 UnlockSemaphoreInfo(policy_semaphore);
372 policies[i]=(PolicyInfo *) NULL;
373 *number_policies=(size_t) i;
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382 % G e t P o l i c y L i s t %
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 % GetPolicyList() returns any policies that match the specified pattern.
390 % The format of the GetPolicyList function is:
392 % char **GetPolicyList(const char *pattern,size_t *number_policies,
393 % ExceptionInfo *exception)
395 % A description of each parameter follows:
397 % o pattern: a pointer to a text string containing a pattern.
399 % o number_policies: returns the number of policies in the list.
401 % o exception: return any errors or warnings in this structure.
404 MagickExport char **GetPolicyList(const char *pattern,
405 size_t *number_policies,ExceptionInfo *exception)
410 register const PolicyInfo
417 Allocate policy list.
419 assert(pattern != (char *) NULL);
420 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
421 assert(number_policies != (size_t *) NULL);
423 p=GetPolicyInfo("*",exception);
424 if (p == (const PolicyInfo *) NULL)
425 return((char **) NULL);
426 policies=(char **) AcquireQuantumMemory((size_t)
427 GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies));
428 if (policies == (char **) NULL)
429 return((char **) NULL);
431 Generate policy list.
433 LockSemaphoreInfo(policy_semaphore);
434 ResetLinkedListIterator(policy_cache);
435 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
436 for (i=0; p != (const PolicyInfo *) NULL; )
438 if ((p->stealth == MagickFalse) &&
439 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
440 policies[i++]=ConstantString(p->name);
441 p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
443 UnlockSemaphoreInfo(policy_semaphore);
444 policies[i]=(char *) NULL;
445 *number_policies=(size_t) i;
450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454 % G e t P o l i c y V a l u e %
458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 % GetPolicyValue() returns the value associated with the named policy.
462 % The format of the GetPolicyValue method is:
464 % char *GetPolicyValue(const char *name)
466 % A description of each parameter follows:
468 % o policy_info: The policy info.
471 MagickExport char *GetPolicyValue(const char *name)
482 assert(name != (const char *) NULL);
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
484 exception=AcquireExceptionInfo();
485 policy_info=GetPolicyInfo(name,exception);
486 exception=DestroyExceptionInfo(exception);
487 if (policy_info == (PolicyInfo *) NULL)
488 return((char *) NULL);
489 value=policy_info->value;
490 if ((value == (const char *) NULL) || (*value == '\0'))
491 return((char *) NULL);
492 return(ConstantString(value));
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 + 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 %
504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 % IsPolicyCacheInstantiated() determines if the policy list is instantiated.
507 % If not, it instantiates the list and returns it.
509 % The format of the IsPolicyInstantiated method is:
511 % MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
513 % A description of each parameter follows.
515 % o exception: return any errors or warnings in this structure.
518 static MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
520 if (policy_cache == (LinkedListInfo *) NULL)
522 if (policy_semaphore == (SemaphoreInfo *) NULL)
523 ActivateSemaphoreInfo(&policy_semaphore);
524 LockSemaphoreInfo(policy_semaphore);
525 if (policy_cache == (LinkedListInfo *) NULL)
526 policy_cache=AcquirePolicyCache(PolicyFilename,exception);
527 UnlockSemaphoreInfo(policy_semaphore);
529 return(policy_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537 % I s R i g h t s A u t h o r i z e d %
541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
543 % IsRightsAuthorized() returns MagickTrue if the policy authorizes the
544 % requested rights for the specified domain.
546 % The format of the IsRightsAuthorized method is:
548 % MagickBooleanType IsRightsAuthorized(const PolicyDomain domain,
549 % const PolicyRights rights,const char *pattern)
551 % A description of each parameter follows:
553 % o domain: the policy domain.
555 % o rights: the policy rights.
557 % o pattern: the coder, delegate, filter, or path pattern.
560 MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain,
561 const PolicyRights rights,const char *pattern)
575 (void) LogMagickEvent(PolicyEvent,GetMagickModule(),
576 "Domain: %s; rights=%s; pattern=\"%s\" ...",
577 CommandOptionToMnemonic(MagickPolicyDomainOptions,domain),
578 CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),pattern);
579 exception=AcquireExceptionInfo();
580 policy_info=GetPolicyInfo("*",exception);
581 exception=DestroyExceptionInfo(exception);
582 if (policy_info == (PolicyInfo *) NULL)
584 authorized=MagickTrue;
585 LockSemaphoreInfo(policy_semaphore);
586 ResetLinkedListIterator(policy_cache);
587 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
588 while ((p != (PolicyInfo *) NULL) && (authorized != MagickFalse))
590 if ((p->domain == domain) &&
591 (GlobExpression(pattern,p->pattern,MagickFalse) != MagickFalse))
593 if (((rights & ReadPolicyRights) != 0) &&
594 ((p->rights & ReadPolicyRights) == 0))
595 authorized=MagickFalse;
596 if (((rights & WritePolicyRights) != 0) &&
597 ((p->rights & WritePolicyRights) == 0))
598 authorized=MagickFalse;
599 if (((rights & ExecutePolicyRights) != 0) &&
600 ((p->rights & ExecutePolicyRights) == 0))
601 authorized=MagickFalse;
603 p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
605 UnlockSemaphoreInfo(policy_semaphore);
610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614 % L i s t P o l i c y I n f o %
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620 % ListPolicyInfo() lists policies to the specified file.
622 % The format of the ListPolicyInfo method is:
624 % MagickBooleanType ListPolicyInfo(FILE *file,ExceptionInfo *exception)
626 % A description of each parameter follows.
628 % o file: List policy names to this file handle.
630 % o exception: return any errors or warnings in this structure.
633 MagickExport MagickBooleanType ListPolicyInfo(FILE *file,
634 ExceptionInfo *exception)
650 List name and attributes of each policy in the list.
652 if (file == (const FILE *) NULL)
654 policy_info=GetPolicyInfoList("*",&number_policies,exception);
655 if (policy_info == (const PolicyInfo **) NULL)
657 path=(const char *) NULL;
658 for (i=0; i < (ssize_t) number_policies; i++)
660 if (policy_info[i]->stealth != MagickFalse)
662 if (((path == (const char *) NULL) ||
663 (LocaleCompare(path,policy_info[i]->path) != 0)) &&
664 (policy_info[i]->path != (char *) NULL))
665 (void) FormatLocaleFile(file,"\nPath: %s\n",policy_info[i]->path);
666 path=policy_info[i]->path;
667 domain=CommandOptionToMnemonic(MagickPolicyDomainOptions,
668 policy_info[i]->domain);
669 (void) FormatLocaleFile(file," Policy: %s\n",domain);
670 if ((policy_info[i]->domain == ResourcePolicyDomain) ||
671 (policy_info[i]->domain == SystemPolicyDomain))
673 if (policy_info[i]->name != (char *) NULL)
674 (void) FormatLocaleFile(file," name: %s\n",policy_info[i]->name);
675 if (policy_info[i]->value != (char *) NULL)
676 (void) FormatLocaleFile(file," value: %s\n",policy_info[i]->value);
680 (void) FormatLocaleFile(file," rights: ");
681 if (policy_info[i]->rights == NoPolicyRights)
682 (void) FormatLocaleFile(file,"None ");
683 if ((policy_info[i]->rights & ReadPolicyRights) != 0)
684 (void) FormatLocaleFile(file,"Read ");
685 if ((policy_info[i]->rights & WritePolicyRights) != 0)
686 (void) FormatLocaleFile(file,"Write ");
687 if ((policy_info[i]->rights & ExecutePolicyRights) != 0)
688 (void) FormatLocaleFile(file,"Execute ");
689 (void) FormatLocaleFile(file,"\n");
690 if (policy_info[i]->pattern != (char *) NULL)
691 (void) FormatLocaleFile(file," pattern: %s\n",
692 policy_info[i]->pattern);
695 policy_info=(const PolicyInfo **) RelinquishMagickMemory((void *)
702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
706 + L o a d P o l i c y L i s t %
710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 % LoadPolicyCache() loads the policy configurations which provides a mapping
713 % between policy attributes and a policy domain.
715 % The format of the LoadPolicyCache method is:
717 % MagickBooleanType LoadPolicyCache(const char *xml,const char *filename,
718 % const size_t depth,ExceptionInfo *exception)
720 % A description of each parameter follows:
722 % o xml: The policy list in XML format.
724 % o filename: The policy list filename.
726 % o depth: depth of <include /> statements.
728 % o exception: return any errors or warnings in this structure.
731 static MagickBooleanType LoadPolicyCache(const char *xml,const char *filename,
732 const size_t depth,ExceptionInfo *exception)
735 keyword[MaxTextExtent],
748 Load the policy map file.
750 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
751 "Loading policy file \"%s\" ...",filename);
752 if (xml == (char *) NULL)
754 if (policy_cache == (LinkedListInfo *) NULL)
756 policy_cache=NewLinkedList(0);
757 if (policy_cache == (LinkedListInfo *) NULL)
759 ThrowFileException(exception,ResourceLimitError,
760 "MemoryAllocationFailed",filename);
765 policy_info=(PolicyInfo *) NULL;
766 token=AcquireString(xml);
767 for (q=(const char *) xml; *q != '\0'; )
772 GetMagickToken(q,&q,token);
775 (void) CopyMagickString(keyword,token,MaxTextExtent);
776 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
781 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
782 GetMagickToken(q,&q,token);
785 if (LocaleNCompare(keyword,"<!--",4) == 0)
790 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
791 GetMagickToken(q,&q,token);
794 if (LocaleCompare(keyword,"<include") == 0)
799 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
801 (void) CopyMagickString(keyword,token,MaxTextExtent);
802 GetMagickToken(q,&q,token);
805 GetMagickToken(q,&q,token);
806 if (LocaleCompare(keyword,"file") == 0)
809 (void) ThrowMagickException(exception,GetMagickModule(),
810 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
817 GetPathComponent(filename,HeadPath,path);
819 (void) ConcatenateMagickString(path,DirectorySeparator,
821 if (*token == *DirectorySeparator)
822 (void) CopyMagickString(path,token,MaxTextExtent);
824 (void) ConcatenateMagickString(path,token,MaxTextExtent);
825 xml=FileToString(path,~0UL,exception);
826 if (xml != (char *) NULL)
828 status=LoadPolicyCache(xml,path,depth+1,exception);
829 xml=(char *) RelinquishMagickMemory(xml);
836 if (LocaleCompare(keyword,"<policy") == 0)
841 policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info));
842 if (policy_info == (PolicyInfo *) NULL)
843 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
844 (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
845 policy_info->path=ConstantString(filename);
846 policy_info->exempt=MagickFalse;
847 policy_info->signature=MagickSignature;
850 if (policy_info == (PolicyInfo *) NULL)
852 if (LocaleCompare(keyword,"/>") == 0)
854 status=AppendValueToLinkedList(policy_cache,policy_info);
855 if (status == MagickFalse)
856 (void) ThrowMagickException(exception,GetMagickModule(),
857 ResourceLimitError,"MemoryAllocationFailed","`%s'",
859 policy_info=(PolicyInfo *) NULL;
862 GetMagickToken(q,(const char **) NULL,token);
865 GetMagickToken(q,&q,token);
866 GetMagickToken(q,&q,token);
872 if (LocaleCompare((char *) keyword,"domain") == 0)
874 policy_info->domain=(PolicyDomain) ParseCommandOption(
875 MagickPolicyDomainOptions,MagickTrue,token);
883 if (LocaleCompare((char *) keyword,"name") == 0)
885 policy_info->name=ConstantString(token);
893 if (LocaleCompare((char *) keyword,"pattern") == 0)
895 policy_info->pattern=ConstantString(token);
903 if (LocaleCompare((char *) keyword,"rights") == 0)
905 policy_info->rights=(PolicyRights) ParseCommandOption(
906 MagickPolicyRightsOptions,MagickTrue,token);
914 if (LocaleCompare((char *) keyword,"stealth") == 0)
916 policy_info->stealth=IsStringTrue(token);
924 if (LocaleCompare((char *) keyword,"value") == 0)
926 policy_info->value=ConstantString(token);
935 token=(char *) RelinquishMagickMemory(token);
940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
944 + P o l i c y C o m p o n e n t G e n e s i s %
948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 % PolicyComponentGenesis() instantiates the policy component.
952 % The format of the PolicyComponentGenesis method is:
954 % MagickBooleanType PolicyComponentGenesis(void)
957 MagickPrivate MagickBooleanType PolicyComponentGenesis(void)
959 policy_semaphore=AcquireSemaphoreInfo();
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 + P o l i c y C o m p o n e n t T e r m i n u s %
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974 % PolicyComponentTerminus() destroys the policy component.
976 % The format of the PolicyComponentTerminus method is:
978 % PolicyComponentTerminus(void)
982 static void *DestroyPolicyElement(void *policy_info)
987 p=(PolicyInfo *) policy_info;
988 if (p->exempt == MagickFalse)
990 if (p->value != (char *) NULL)
991 p->value=DestroyString(p->value);
992 if (p->pattern != (char *) NULL)
993 p->pattern=DestroyString(p->pattern);
994 if (p->name != (char *) NULL)
995 p->name=DestroyString(p->name);
996 if (p->path != (char *) NULL)
997 p->path=DestroyString(p->path);
999 p=(PolicyInfo *) RelinquishMagickMemory(p);
1000 return((void *) NULL);
1003 MagickPrivate void PolicyComponentTerminus(void)
1005 if (policy_semaphore == (SemaphoreInfo *) NULL)
1006 ActivateSemaphoreInfo(&policy_semaphore);
1007 LockSemaphoreInfo(policy_semaphore);
1008 if (policy_cache != (LinkedListInfo *) NULL)
1009 policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement);
1010 UnlockSemaphoreInfo(policy_semaphore);
1011 RelinquishSemaphoreInfo(&policy_semaphore);