MagickCore 7.1.2-28
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
policy-private.h
1/*
2 Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License. You may
6 obtain a copy of the License at
7
8 https://imagemagick.org/license/
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore private policy methods.
17*/
18#ifndef MAGICKCORE_POLICY_PRIVATE_H
19#define MAGICKCORE_POLICY_PRIVATE_H
20
21#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
25#include "MagickCore/resource-private.h"
26#include "MagickCore/utility-private.h"
27
28#if MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
29/*
30 Zero configuration security policy. Discussion @
31 https://imagemagick.org/script/security-policy.php.
32*/
33static const char
34 *ZeroConfigurationPolicy = \
35"<policymap> \
36</policymap>";
37#endif
38
39extern MagickPrivate MagickBooleanType
40 PolicyComponentGenesis(void);
41
42extern MagickPrivate void
43 PolicyComponentTerminus(void);
44
45static inline MagickBooleanType IsPathContainsSymlink(const char *path)
46{
47 char
48 partial[MagickPathExtent];
49
50 const char
51 *p;
52
53 ssize_t
54 offset = 0;
55
56 if (path == (const char *) NULL)
57 return(MagickFalse);
58 *partial='\0';
59 p=path;
60 if (*p == *DirectorySeparator)
61 {
62 /*
63 Path starts with a directory separator, include it.
64 */
65 if ((offset+1) >= (ssize_t) sizeof(partial))
66 return(MagickFalse);
67 partial[offset++]=(*p++);
68 partial[offset]='\0';
69 }
70 while (*p != '\0')
71 {
72 char
73 component[MagickPathExtent];
74
75 ssize_t
76 i = 0;
77
78 /*
79 Copy next component into a temporary buffer.
80 */
81 while ((*p != '\0') && (*p != *DirectorySeparator) &&
82 ((i+1) < (ssize_t) sizeof(component)))
83 component[i++]=(*p++);
84 component[i]='\0';
85 if (i == 0)
86 {
87 /*
88 skip repeated separators.
89 */
90 if (*p == *DirectorySeparator)
91 p++;
92 continue;
93 }
94 if ((offset > 0) && (partial[offset-1] != *DirectorySeparator))
95 {
96 /*
97 Append separator if needed.
98 */
99 if ((offset+1) >= (ssize_t) sizeof(partial))
100 return MagickFalse;
101 partial[offset++]=(*DirectorySeparator);
102 partial[offset]='\0';
103 }
104 /*
105 Append component.
106 */
107 if ((offset+i) >= (ssize_t) sizeof(partial))
108 return(MagickFalse);
109 (void) memcpy(partial+offset,component,i);
110 offset+=i;
111 partial[offset]='\0';
112 if (*p != '\0')
113 {
114 /*
115 Check whether this prefix is a symlink.
116 */
117 if (is_symlink_utf8(partial) != MagickFalse)
118 return(MagickTrue);
119 }
120 /*
121 Skip separator.
122 */
123 if (*p == *DirectorySeparator)
124 p++;
125 }
126 return(MagickFalse);
127}
128
129static inline MagickBooleanType IsPathAuthorized(const PolicyRights rights,
130 const char *path)
131{
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))
139 {
140 if ((is_symlink_utf8(path) != MagickFalse) ||
141 (IsPathContainsSymlink(path) != MagickFalse))
142 status=MagickFalse;
143 }
144 if (status != MagickFalse)
145 status=IsFileResourceIdentityValid(path);
146 return(status);
147}
148
149#if defined(__cplusplus) || defined(c_plusplus)
150}
151#endif
152
153#endif