MagickCore 6.9.13-53
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 "magick/resource-private.h"
26#include "magick/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
39static inline MagickBooleanType IsPathContainsSymlink(const char *path)
40{
41 char
42 partial[MagickPathExtent];
43
44 const char
45 *p;
46
47 ssize_t
48 offset = 0;
49
50 if (path == (const char *) NULL)
51 return(MagickFalse);
52 *partial='\0';
53 p=path;
54 if (*p == *DirectorySeparator)
55 {
56 /*
57 Path starts with a directory separator, include it.
58 */
59 if ((offset+1) >= (ssize_t) sizeof(partial))
60 return(MagickFalse);
61 partial[offset++]=(*p++);
62 partial[offset]='\0';
63 }
64 while (*p != '\0')
65 {
66 char
67 component[MagickPathExtent];
68
69 ssize_t
70 i = 0;
71
72 /*
73 Copy next component into a temporary buffer.
74 */
75 while ((*p != '\0') && (*p != *DirectorySeparator) &&
76 ((i+1) < (ssize_t) sizeof(component)))
77 component[i++]=(*p++);
78 component[i]='\0';
79 if (i == 0)
80 {
81 /*
82 skip repeated separators.
83 */
84 if (*p == *DirectorySeparator)
85 p++;
86 continue;
87 }
88 if ((offset > 0) && (partial[offset-1] != *DirectorySeparator))
89 {
90 /*
91 Append separator if needed.
92 */
93 if ((offset+1) >= (ssize_t) sizeof(partial))
94 return MagickFalse;
95 partial[offset++]=(*DirectorySeparator);
96 partial[offset]='\0';
97 }
98 /*
99 Append component.
100 */
101 if ((offset+i) >= (ssize_t) sizeof(partial))
102 return(MagickFalse);
103 (void) memcpy(partial+offset,component,i);
104 offset+=i;
105 partial[offset]='\0';
106 if (*p != '\0')
107 {
108 /*
109 Check whether this prefix is a symlink.
110 */
111 if (is_symlink_utf8(partial) != MagickFalse)
112 return(MagickTrue);
113 }
114 /*
115 Skip separator.
116 */
117 if (*p == *DirectorySeparator)
118 p++;
119 }
120 return(MagickFalse);
121}
122
123static inline MagickBooleanType IsPathAuthorized(const PolicyRights rights,
124 const char *path)
125{
126 MagickBooleanType symlink_follow_allowed = IsRightsAuthorizedByName(
127 SystemPolicyDomain,"symlink",rights,"follow");
128 MagickBooleanType status =
129 ((IsRightsAuthorized(PathPolicyDomain,rights,path) != MagickFalse) &&
130 ((symlink_follow_allowed != MagickFalse) ||
131 (is_symlink_utf8(path) == MagickFalse))) ? MagickTrue : MagickFalse;
132 if ((status != MagickFalse) && (symlink_follow_allowed == MagickFalse))
133 {
134 if ((is_symlink_utf8(path) != MagickFalse) ||
135 (IsPathContainsSymlink(path) != MagickFalse))
136 status=MagickFalse;
137 }
138 if (status != MagickFalse)
139 status=IsFileResourceIdentityValid(path);
140 return(status);
141}
142
143#if defined(__cplusplus) || defined(c_plusplus)
144}
145#endif
146
147#endif