% MagickCore Policy Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2015 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 %
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
\f
/*
Define declarations.
};
static LinkedListInfo
- *policy_list = (LinkedListInfo *) NULL;
+ *policy_cache = (LinkedListInfo *) NULL;
static SemaphoreInfo
*policy_semaphore = (SemaphoreInfo *) NULL;
-
-static volatile MagickBooleanType
- instantiate_policy = MagickFalse;
\f
/*
Forward declarations.
*/
static MagickBooleanType
- InitializePolicyList(ExceptionInfo *),
- LoadPolicyLists(const char *,ExceptionInfo *);
+ IsPolicyCacheInstantiated(ExceptionInfo *),
+ LoadPolicyCache(LinkedListInfo *,const char *,const char *,const size_t,
+ ExceptionInfo *);
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% A c q u i r e P o l i c y C a c h e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% AcquirePolicyCache() caches one or more policy configurations which provides
+% a mapping between policy attributes and a policy name.
+%
+% The format of the AcquirePolicyCache method is:
+%
+% LinkedListInfo *AcquirePolicyCache(const char *filename,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o filename: the font file name.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+static LinkedListInfo *AcquirePolicyCache(const char *filename,
+ ExceptionInfo *exception)
+{
+ const StringInfo
+ *option;
+
+ LinkedListInfo
+ *options,
+ *policy_cache;
+
+ MagickStatusType
+ status;
+
+ register ssize_t
+ i;
+
+ /*
+ Load external policy map.
+ */
+ policy_cache=NewLinkedList(0);
+ if (policy_cache == (LinkedListInfo *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ status=MagickTrue;
+ options=GetConfigureOptions(filename,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ while (option != (const StringInfo *) NULL)
+ {
+ status&=LoadPolicyCache(policy_cache,(const char *)
+ GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ }
+ options=DestroyConfigureOptions(options);
+ /*
+ Load built-in policy map.
+ */
+ 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'",p->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=MagickCoreSignature;
+ status&=AppendValueToLinkedList(policy_cache,policy_info);
+ if (status == MagickFalse)
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name);
+ }
+ return(policy_cache);
+}
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
{
char
- policyname[MaxTextExtent];
+ policyname[MagickPathExtent];
register PolicyInfo
*p;
*q;
assert(exception != (ExceptionInfo *) NULL);
- if ((policy_list == (LinkedListInfo *) NULL) ||
- (instantiate_policy == MagickFalse))
- if (InitializePolicyList(exception) == MagickFalse)
- return((PolicyInfo *) NULL);
- if ((policy_list == (LinkedListInfo *) NULL) ||
- (IsLinkedListEmpty(policy_list) != MagickFalse))
+ if (IsPolicyCacheInstantiated(exception) == MagickFalse)
return((PolicyInfo *) NULL);
- if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
- return((PolicyInfo *) GetValueFromLinkedList(policy_list,0));
/*
Strip names of whitespace.
*/
- (void) CopyMagickString(policyname,name,MaxTextExtent);
+ *policyname='\0';
+ if (name != (const char *) NULL)
+ (void) CopyMagickString(policyname,name,MagickPathExtent);
for (q=policyname; *q != '\0'; q++)
{
if (isspace((int) ((unsigned char) *q)) == 0)
continue;
- (void) CopyMagickString(q,q+1,MaxTextExtent);
+ (void) CopyMagickString(q,q+1,MagickPathExtent);
q--;
}
/*
Search for policy tag.
*/
LockSemaphoreInfo(policy_semaphore);
- ResetLinkedListIterator(policy_list);
- p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ ResetLinkedListIterator(policy_cache);
+ p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
+ if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
+ {
+ UnlockSemaphoreInfo(policy_semaphore);
+ return(p);
+ }
while (p != (PolicyInfo *) NULL)
{
if (LocaleCompare(policyname,p->name) == 0)
break;
- p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
}
if (p != (PolicyInfo *) NULL)
- (void) InsertValueInLinkedList(policy_list,0,
- RemoveElementByValueFromLinkedList(policy_list,p));
+ (void) InsertValueInLinkedList(policy_cache,0,
+ RemoveElementByValueFromLinkedList(policy_cache,p));
UnlockSemaphoreInfo(policy_semaphore);
return(p);
}
if (p == (const PolicyInfo *) NULL)
return((const PolicyInfo **) NULL);
policies=(const PolicyInfo **) AcquireQuantumMemory((size_t)
- GetNumberOfElementsInLinkedList(policy_list)+1UL,sizeof(*policies));
+ GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies));
if (policies == (const PolicyInfo **) NULL)
return((const PolicyInfo **) NULL);
/*
Generate policy list.
*/
LockSemaphoreInfo(policy_semaphore);
- ResetLinkedListIterator(policy_list);
- p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ ResetLinkedListIterator(policy_cache);
+ p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
for (i=0; p != (const PolicyInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
policies[i++]=p;
- p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
}
UnlockSemaphoreInfo(policy_semaphore);
policies[i]=(PolicyInfo *) NULL;
if (p == (const PolicyInfo *) NULL)
return((char **) NULL);
policies=(char **) AcquireQuantumMemory((size_t)
- GetNumberOfElementsInLinkedList(policy_list)+1UL,sizeof(*policies));
+ GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies));
if (policies == (char **) NULL)
return((char **) NULL);
/*
Generate policy list.
*/
LockSemaphoreInfo(policy_semaphore);
- ResetLinkedListIterator(policy_list);
- p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ ResetLinkedListIterator(policy_cache);
+ p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
for (i=0; p != (const PolicyInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
policies[i++]=ConstantString(p->name);
- p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache);
}
UnlockSemaphoreInfo(policy_semaphore);
policies[i]=(char *) NULL;
% %
% %
% %
-+ I n i t i a l i z e P o l i c y L i s t %
++ 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 %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% InitializePolicyList() initializes the policy list.
+% IsPolicyCacheInstantiated() determines if the policy list is instantiated.
+% If not, it instantiates the list and returns it.
%
-% The format of the InitializePolicyList method is:
+% The format of the IsPolicyInstantiated method is:
%
-% MagickBooleanType InitializePolicyList(ExceptionInfo *exception)
+% MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
%
% A description of each parameter follows.
%
% o exception: return any errors or warnings in this structure.
%
*/
-static MagickBooleanType InitializePolicyList(ExceptionInfo *exception)
+static MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception)
{
- if ((policy_list == (LinkedListInfo *) NULL) &&
- (instantiate_policy == MagickFalse))
+ if (policy_cache == (LinkedListInfo *) NULL)
{
if (policy_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&policy_semaphore);
+ ActivateSemaphoreInfo(&policy_semaphore);
LockSemaphoreInfo(policy_semaphore);
- if ((policy_list == (LinkedListInfo *) NULL) &&
- (instantiate_policy == MagickFalse))
- {
- (void) LoadPolicyLists(PolicyFilename,exception);
- instantiate_policy=MagickTrue;
- }
+ if (policy_cache == (LinkedListInfo *) NULL)
+ policy_cache=AcquirePolicyCache(PolicyFilename,exception);
UnlockSemaphoreInfo(policy_semaphore);
}
- return(policy_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
+ return(policy_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
}
\f
/*
return(MagickTrue);
authorized=MagickTrue;
LockSemaphoreInfo(policy_semaphore);
- ResetLinkedListIterator(policy_list);
- p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ ResetLinkedListIterator(policy_cache);
+ p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
while ((p != (PolicyInfo *) NULL) && (authorized != MagickFalse))
{
if ((p->domain == domain) &&
((p->rights & ExecutePolicyRights) == 0))
authorized=MagickFalse;
}
- p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
+ p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
}
UnlockSemaphoreInfo(policy_semaphore);
return(authorized);
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% LoadPolicyList() loads the policy configuration file which provides a mapping
+% LoadPolicyCache() loads the policy configurations which provides a mapping
% between policy attributes and a policy domain.
%
-% The format of the LoadPolicyList method is:
+% The format of the LoadPolicyCache method is:
%
-% MagickBooleanType LoadPolicyList(const char *xml,const char *filename,
-% const size_t depth,ExceptionInfo *exception)
+% MagickBooleanType LoadPolicyCache(LinkedListInfo *policy_cache,
+% const char *xml,const char *filename,const size_t depth,
+% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o exception: return any errors or warnings in this structure.
%
*/
-static MagickBooleanType LoadPolicyList(const char *xml,const char *filename,
- const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadPolicyCache(LinkedListInfo *policy_cache,
+ const char *xml,const char *filename,const size_t depth,
+ ExceptionInfo *exception)
{
char
- keyword[MaxTextExtent],
+ keyword[MagickPathExtent],
*token;
- PolicyInfo
- *policy_info;
-
const char
*q;
- MagickBooleanType
+ MagickStatusType
status;
+ PolicyInfo
+ *policy_info;
+
/*
Load the policy map file.
*/
"Loading policy file \"%s\" ...",filename);
if (xml == (char *) NULL)
return(MagickFalse);
- if (policy_list == (LinkedListInfo *) NULL)
- {
- policy_list=NewLinkedList(0);
- if (policy_list == (LinkedListInfo *) NULL)
- {
- ThrowFileException(exception,ResourceLimitError,
- "MemoryAllocationFailed",filename);
- return(MagickFalse);
- }
- }
status=MagickTrue;
policy_info=(PolicyInfo *) NULL;
token=AcquireString(xml);
GetMagickToken(q,&q,token);
if (*token == '\0')
break;
- (void) CopyMagickString(keyword,token,MaxTextExtent);
+ (void) CopyMagickString(keyword,token,MagickPathExtent);
if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
{
/*
*/
while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
{
- (void) CopyMagickString(keyword,token,MaxTextExtent);
+ (void) CopyMagickString(keyword,token,MagickPathExtent);
GetMagickToken(q,&q,token);
if (*token != '=')
continue;
else
{
char
- path[MaxTextExtent],
+ path[MagickPathExtent],
*xml;
GetPathComponent(filename,HeadPath,path);
if (*path != '\0')
(void) ConcatenateMagickString(path,DirectorySeparator,
- MaxTextExtent);
+ MagickPathExtent);
if (*token == *DirectorySeparator)
- (void) CopyMagickString(path,token,MaxTextExtent);
+ (void) CopyMagickString(path,token,MagickPathExtent);
else
- (void) ConcatenateMagickString(path,token,MaxTextExtent);
- xml=FileToString(path,~0,exception);
+ (void) ConcatenateMagickString(path,token,MagickPathExtent);
+ xml=FileToXML(path,~0UL);
if (xml != (char *) NULL)
{
- status=LoadPolicyList(xml,path,depth+1,exception);
+ status&=LoadPolicyCache(policy_cache,xml,path,depth+1,
+ exception);
xml=(char *) RelinquishMagickMemory(xml);
}
}
(void) ResetMagickMemory(policy_info,0,sizeof(*policy_info));
policy_info->path=ConstantString(filename);
policy_info->exempt=MagickFalse;
- policy_info->signature=MagickSignature;
+ policy_info->signature=MagickCoreSignature;
continue;
}
if (policy_info == (PolicyInfo *) NULL)
continue;
if (LocaleCompare(keyword,"/>") == 0)
{
- status=AppendValueToLinkedList(policy_list,policy_info);
+ status=AppendValueToLinkedList(policy_cache,policy_info);
if (status == MagickFalse)
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
policy_info->name);
policy_info=(PolicyInfo *) NULL;
+ continue;
}
GetMagickToken(q,(const char **) NULL,token);
if (*token != '=')
{
if (LocaleCompare((char *) keyword,"stealth") == 0)
{
- policy_info->stealth=IsMagickTrue(token);
+ policy_info->stealth=IsStringTrue(token);
break;
}
break;
}
}
token=(char *) RelinquishMagickMemory(token);
- return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-% L o a d P o l i c y L i s t s %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% LoadPolicyList() loads one or more policy configuration file which provides a
-% mapping between policy attributes and a policy name.
-%
-% The format of the LoadPolicyLists method is:
-%
-% MagickBooleanType LoadPolicyLists(const char *filename,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o filename: the font file name.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadPolicyLists(const char *filename,
- ExceptionInfo *exception)
-{
- const StringInfo
- *option;
-
- LinkedListInfo
- *options;
-
- 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)
- {
- status|=LoadPolicyList((const char *) GetStringInfoDatum(option),
- GetStringInfoPath(option),0,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- }
- options=DestroyConfigureOptions(options);
return(status != 0 ? MagickTrue : MagickFalse);
}
\f
*/
MagickPrivate MagickBooleanType PolicyComponentGenesis(void)
{
- AcquireSemaphoreInfo(&policy_semaphore);
+ if (policy_semaphore == (SemaphoreInfo *) NULL)
+ policy_semaphore=AcquireSemaphoreInfo();
return(MagickTrue);
}
\f
MagickPrivate void PolicyComponentTerminus(void)
{
if (policy_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&policy_semaphore);
+ ActivateSemaphoreInfo(&policy_semaphore);
LockSemaphoreInfo(policy_semaphore);
- if (policy_list != (LinkedListInfo *) NULL)
- policy_list=DestroyLinkedList(policy_list,DestroyPolicyElement);
- instantiate_policy=MagickFalse;
+ if (policy_cache != (LinkedListInfo *) NULL)
+ policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement);
UnlockSemaphoreInfo(policy_semaphore);
- DestroySemaphoreInfo(&policy_semaphore);
+ RelinquishSemaphoreInfo(&policy_semaphore);
}