18#ifndef MAGICKCORE_POLICY_PRIVATE_H
19#define MAGICKCORE_POLICY_PRIVATE_H
21#if defined(__cplusplus) || defined(c_plusplus)
25#include "MagickCore/resource-private.h"
26#include "MagickCore/utility-private.h"
28#if MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
34 *ZeroConfigurationPolicy = \
39extern MagickPrivate MagickBooleanType
40 PolicyComponentGenesis(
void);
42extern MagickPrivate
void
43 PolicyComponentTerminus(
void);
45static inline MagickBooleanType IsPathContainsSymlink(
const char *path)
48 partial[MagickPathExtent];
56 if (path == (
const char *) NULL)
60 if (*p == *DirectorySeparator)
65 if ((offset+1) >= (ssize_t)
sizeof(partial))
67 partial[offset++]=(*p++);
73 component[MagickPathExtent];
81 while ((*p !=
'\0') && (*p != *DirectorySeparator) &&
82 ((i+1) < (ssize_t)
sizeof(component)))
83 component[i++]=(*p++);
90 if (*p == *DirectorySeparator)
94 if ((offset > 0) && (partial[offset-1] != *DirectorySeparator))
99 if ((offset+1) >= (ssize_t)
sizeof(partial))
101 partial[offset++]=(*DirectorySeparator);
102 partial[offset]=
'\0';
107 if ((offset+i) >= (ssize_t)
sizeof(partial))
109 (void) memcpy(partial+offset,component,i);
111 partial[offset]=
'\0';
117 if (is_symlink_utf8(partial) != MagickFalse)
123 if (*p == *DirectorySeparator)
129static inline MagickBooleanType IsPathAuthorized(
const PolicyRights rights,
132 MagickBooleanType symlink_follow_allowed = IsRightsAuthorizedByName(
133 SystemPolicyDomain,
"symlink",rights,
"follow");
134 MagickBooleanType status =
135 ((IsRightsAuthorized(PathPolicyDomain,rights,path) != MagickFalse) &&
136 ((symlink_follow_allowed != MagickFalse) ||
137 (is_symlink_utf8(path) == MagickFalse))) ? MagickTrue : MagickFalse;
138 if ((status != MagickFalse) && (symlink_follow_allowed == MagickFalse))
140 if ((is_symlink_utf8(path) != MagickFalse) ||
141 (IsPathContainsSymlink(path) != MagickFalse))
144 if (status != MagickFalse)
145 status=IsFileResourceIdentityValid(path);
149#if defined(__cplusplus) || defined(c_plusplus)