% July 1992 %
% %
% %
-% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#define PolicyFilename "policy.xml"
\f
/*
- Declare policy map.
-*/
-static const char
- *PolicyMap = (const char *)
- "<?xml version=\"1.0\"?>"
- "<policymap>"
- "</policymap>";
-\f
-/*
- Domaindef declarations.
+ Typedef declarations.
*/
struct _PolicyInfo
{
char
- *path,
- *name;
+ *path;
PolicyDomain
domain;
rights;
char
+ *name,
*pattern,
*value;
MagickBooleanType
+ exempt,
stealth,
debug;
SemaphoreInfo
*semaphore;
- unsigned long
+ size_t
signature;
};
+
+typedef struct _PolicyMapInfo
+{
+ const PolicyDomain
+ domain;
+
+ const PolicyRights
+ rights;
+
+ const char
+ *name,
+ *pattern,
+ *value;
+} PolicyMapInfo;
\f
/*
Static declarations.
*/
+static const PolicyMapInfo
+ PolicyMap[] =
+ {
+ { UndefinedPolicyDomain, UndefinedPolicyRights, (const char *) NULL,
+ (const char *) NULL, (const char *) NULL }
+ };
+
static LinkedListInfo
*policy_list = (LinkedListInfo *) NULL;
% %
% %
% %
-+ D e s t r o y P o l i c y F a c i l i t y %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% DestroyPolicyFacility() destroys the policy facility.
-%
-% The format of the DestroyPolicyFacility method is:
-%
-% DestroyPolicyFacility(void)
-%
-*/
-
-static void *DestroyPolicyElement(void *policy_info)
-{
- register PolicyInfo
- *p;
-
- p=(PolicyInfo *) policy_info;
- if (p->value != (char *) NULL)
- p->value=DestroyString(p->value);
- if (p->pattern != (char *) NULL)
- p->pattern=DestroyString(p->pattern);
- if (p->name != (char *) NULL)
- p->name=DestroyString(p->name);
- if (p->path != (char *) NULL)
- p->path=DestroyString(p->path);
- p=(PolicyInfo *) RelinquishMagickMemory(p);
- return((void *) NULL);
-}
-
-MagickExport void DestroyPolicyFacility(void)
-{
- AcquireSemaphoreInfo(&policy_semaphore);
- if (policy_list != (LinkedListInfo *) NULL)
- policy_list=DestroyLinkedList(policy_list,DestroyPolicyElement);
- instantiate_policy=MagickFalse;
- RelinquishSemaphoreInfo(policy_semaphore);
- DestroySemaphoreInfo(&policy_semaphore);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
+ G e t P o l i c y I n f o %
% %
% %
/*
Search for policy tag.
*/
- AcquireSemaphoreInfo(&policy_semaphore);
+ LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_list);
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
while (p != (PolicyInfo *) NULL)
break;
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
}
- if (p == (PolicyInfo *) NULL)
- (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
- "UnrecognizedPolicy","`%s'",name);
- else
+ if (p != (PolicyInfo *) NULL)
(void) InsertValueInLinkedList(policy_list,0,
RemoveElementByValueFromLinkedList(policy_list,p));
- RelinquishSemaphoreInfo(policy_semaphore);
+ UnlockSemaphoreInfo(policy_semaphore);
return(p);
}
\f
% The format of the GetPolicyInfoList function is:
%
% const PolicyInfo **GetPolicyInfoList(const char *pattern,
-% unsigned long *number_policies,ExceptionInfo *exception)
+% size_t *number_policies,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
%
*/
MagickExport const PolicyInfo **GetPolicyInfoList(const char *pattern,
- unsigned long *number_policies,ExceptionInfo *exception)
+ size_t *number_policies,ExceptionInfo *exception)
{
const PolicyInfo
**policies;
register const PolicyInfo
*p;
- register long
+ register ssize_t
i;
/*
*/
assert(pattern != (char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
- assert(number_policies != (unsigned long *) NULL);
+ assert(number_policies != (size_t *) NULL);
*number_policies=0;
p=GetPolicyInfo("*",exception);
if (p == (const PolicyInfo *) NULL)
/*
Generate policy list.
*/
- AcquireSemaphoreInfo(&policy_semaphore);
+ LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_list);
p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
for (i=0; p != (const PolicyInfo *) NULL; )
policies[i++]=p;
p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
}
- RelinquishSemaphoreInfo(policy_semaphore);
+ UnlockSemaphoreInfo(policy_semaphore);
policies[i]=(PolicyInfo *) NULL;
- *number_policies=(unsigned long) i;
+ *number_policies=(size_t) i;
return(policies);
}
\f
%
% The format of the GetPolicyList function is:
%
-% char **GetPolicyList(const char *pattern,unsigned long *number_policies,
+% char **GetPolicyList(const char *pattern,size_t *number_policies,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
*/
MagickExport char **GetPolicyList(const char *pattern,
- unsigned long *number_policies,ExceptionInfo *exception)
+ size_t *number_policies,ExceptionInfo *exception)
{
char
**policies;
register const PolicyInfo
*p;
- register long
+ register ssize_t
i;
/*
*/
assert(pattern != (char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
- assert(number_policies != (unsigned long *) NULL);
+ assert(number_policies != (size_t *) NULL);
*number_policies=0;
p=GetPolicyInfo("*",exception);
if (p == (const PolicyInfo *) NULL)
/*
Generate policy list.
*/
- AcquireSemaphoreInfo(&policy_semaphore);
+ LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_list);
p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
for (i=0; p != (const PolicyInfo *) NULL; )
policies[i++]=ConstantString(p->name);
p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
}
- RelinquishSemaphoreInfo(policy_semaphore);
+ UnlockSemaphoreInfo(policy_semaphore);
policies[i]=(char *) NULL;
- *number_policies=(unsigned long) i;
+ *number_policies=(size_t) i;
return(policies);
}
\f
if ((policy_list == (LinkedListInfo *) NULL) &&
(instantiate_policy == MagickFalse))
{
- AcquireSemaphoreInfo(&policy_semaphore);
+ if (policy_semaphore == (SemaphoreInfo *) NULL)
+ AcquireSemaphoreInfo(&policy_semaphore);
+ LockSemaphoreInfo(policy_semaphore);
if ((policy_list == (LinkedListInfo *) NULL) &&
(instantiate_policy == MagickFalse))
{
(void) LoadPolicyLists(PolicyFilename,exception);
instantiate_policy=MagickTrue;
}
- RelinquishSemaphoreInfo(policy_semaphore);
+ UnlockSemaphoreInfo(policy_semaphore);
}
return(policy_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
}
% %
% %
% %
-+ I n s t a n t i a t e P o l i c y F a c i l i t y %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% InstantiatePolicyFacility() instantiates the policy facility.
-%
-% The format of the InstantiatePolicyFacility method is:
-%
-% MagickBooleanType InstantiatePolicyFacility(void)
-%
-*/
-MagickExport MagickBooleanType InstantiatePolicyFacility(void)
-{
- AcquireSemaphoreInfo(&policy_semaphore);
- RelinquishSemaphoreInfo(policy_semaphore);
- return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% I s R i g h t s A u t h o r i z e d %
% %
% %
if (policy_info == (PolicyInfo *) NULL)
return(MagickTrue);
authorized=MagickTrue;
- AcquireSemaphoreInfo(&policy_semaphore);
+ LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_list);
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
while ((p != (PolicyInfo *) NULL) && (authorized != MagickFalse))
}
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
}
- RelinquishSemaphoreInfo(policy_semaphore);
+ UnlockSemaphoreInfo(policy_semaphore);
return(authorized);
}
\f
const PolicyInfo
**policy_info;
- register long
+ register ssize_t
i;
- unsigned long
+ size_t
number_policies;
/*
if (policy_info == (const PolicyInfo **) NULL)
return(MagickFalse);
path=(const char *) NULL;
- for (i=0; i < (long) number_policies; i++)
+ for (i=0; i < (ssize_t) number_policies; i++)
{
if (policy_info[i]->stealth != MagickFalse)
continue;
domain=MagickOptionToMnemonic(MagickPolicyDomainOptions,
policy_info[i]->domain);
(void) fprintf(file," Policy: %s\n",domain);
- if (policy_info[i]->domain == ResourcePolicyDomain)
+ if ((policy_info[i]->domain == ResourcePolicyDomain) ||
+ (policy_info[i]->domain == SystemPolicyDomain))
{
if (policy_info[i]->name != (char *) NULL)
(void) fprintf(file," name: %s\n",policy_info[i]->name);
% The format of the LoadPolicyList method is:
%
% MagickBooleanType LoadPolicyList(const char *xml,const char *filename,
-% const unsigned long depth,ExceptionInfo *exception)
+% const size_t depth,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
%
*/
static MagickBooleanType LoadPolicyList(const char *xml,const char *filename,
- const unsigned long depth,ExceptionInfo *exception)
+ const size_t depth,ExceptionInfo *exception)
{
char
keyword[MaxTextExtent],
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
(void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
policy_info->path=ConstantString(filename);
+ policy_info->exempt=MagickFalse;
policy_info->signature=MagickSignature;
continue;
}
static MagickBooleanType LoadPolicyLists(const char *filename,
ExceptionInfo *exception)
{
-#if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
- return(LoadPolicyList(PolicyMap,"built-in",0,exception));
-#else
const StringInfo
*option;
MagickStatusType
status;
+ register ssize_t
+ i;
+
+ /*
+ Load built-in policy map.
+ */
status=MagickFalse;
+ if (policy_list == (LinkedListInfo *) NULL)
+ {
+ policy_list=NewLinkedList(0);
+ if (policy_list == (LinkedListInfo *) NULL)
+ {
+ ThrowFileException(exception,ResourceLimitError,
+ "MemoryAllocationFailed",filename);
+ return(MagickFalse);
+ }
+ }
+ for (i=0; i < (ssize_t) (sizeof(PolicyMap)/sizeof(*PolicyMap)); i++)
+ {
+ PolicyInfo
+ *policy_info;
+
+ register const PolicyMapInfo
+ *p;
+
+ p=PolicyMap+i;
+ policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info));
+ if (policy_info == (PolicyInfo *) NULL)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name);
+ continue;
+ }
+ (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
+ policy_info->path=(char *) "[built-in]";
+ policy_info->domain=p->domain;
+ policy_info->rights=p->rights;
+ policy_info->name=(char *) p->name;
+ policy_info->pattern=(char *) p->pattern;
+ policy_info->value=(char *) p->value;
+ policy_info->exempt=MagickTrue;
+ policy_info->signature=MagickSignature;
+ status=AppendValueToLinkedList(policy_list,policy_info);
+ if (status == MagickFalse)
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name);
+ }
+ /*
+ Load external policy map.
+ */
options=GetConfigureOptions(filename,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyConfigureOptions(options);
- if ((policy_list == (LinkedListInfo *) NULL) ||
- (IsLinkedListEmpty(policy_list) != MagickFalse))
- status|=LoadPolicyList(PolicyMap,"built-in",0,exception);
return(status != 0 ? MagickTrue : MagickFalse);
-#endif
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ P o l i c y C o m p o n e n t G e n e s i s %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% PolicyComponentGenesis() instantiates the policy component.
+%
+% The format of the PolicyComponentGenesis method is:
+%
+% MagickBooleanType PolicyComponentGenesis(void)
+%
+*/
+MagickExport MagickBooleanType PolicyComponentGenesis(void)
+{
+ AcquireSemaphoreInfo(&policy_semaphore);
+ return(MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ P o l i c y C o m p o n e n t T e r m i n u s %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% PolicyComponentTerminus() destroys the policy component.
+%
+% The format of the PolicyComponentTerminus method is:
+%
+% PolicyComponentTerminus(void)
+%
+*/
+
+static void *DestroyPolicyElement(void *policy_info)
+{
+ register PolicyInfo
+ *p;
+
+ p=(PolicyInfo *) policy_info;
+ if (p->exempt == MagickFalse)
+ {
+ if (p->value != (char *) NULL)
+ p->value=DestroyString(p->value);
+ if (p->pattern != (char *) NULL)
+ p->pattern=DestroyString(p->pattern);
+ if (p->name != (char *) NULL)
+ p->name=DestroyString(p->name);
+ if (p->path != (char *) NULL)
+ p->path=DestroyString(p->path);
+ }
+ p=(PolicyInfo *) RelinquishMagickMemory(p);
+ return((void *) NULL);
+}
+
+MagickExport void PolicyComponentTerminus(void)
+{
+ if (policy_semaphore == (SemaphoreInfo *) NULL)
+ AcquireSemaphoreInfo(&policy_semaphore);
+ LockSemaphoreInfo(policy_semaphore);
+ if (policy_list != (LinkedListInfo *) NULL)
+ policy_list=DestroyLinkedList(policy_list,DestroyPolicyElement);
+ instantiate_policy=MagickFalse;
+ UnlockSemaphoreInfo(policy_semaphore);
+ DestroySemaphoreInfo(&policy_semaphore);
}