2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef H_LIBSECURITY_TRANSLOCATE
25 #define H_LIBSECURITY_TRANSLOCATE
27 #include <CoreFoundation/CoreFoundation.h>
29 CF_ASSUME_NONNULL_BEGIN
36 @function SecTranslocateStartListening
38 @abstract Initialize the SecTranslocate Library as the XPC Server, Disk Arbitration Listener, and Launch Services Notification listener
40 @param error On error will be populated with an error object describing the failure (a posix domain error such as EINVAL)
42 @result True on success False on failure
44 Boolean
SecTranslocateStartListening(CFErrorRef
* __nullable error
)
45 __OSX_AVAILABLE(10.12);
48 @function SecTranslocateStartListeningWithOptions
50 @abstract Initialize the SecTranslocate Library as the XPC Server, Disk Arbitration Listener, and Launch Services Notification listener
52 @param options (currently unused) A dictionary of options that could impact server startup
53 @param outError On error will be populated with an error object describing the failure (a posix domain error such as EINVAL)
55 @result True on success False on failure
57 Boolean
SecTranslocateStartListeningWithOptions(CFDictionaryRef options
, CFErrorRef
* __nullable outError
)
58 __OSX_AVAILABLE(10.12);
61 @function SecTranslocateCreateSecureDirectoryForURL
63 @abstract Create a CFURL pointing to a translocated location from which to access the directory specified by pathToTranslocate.
65 @param pathToTranslocate URL of the directory to be accessed from a translocated location.
66 @param destinationPath URL where the directory of interest should be translocated, or NULL for a random UUID location
67 @param error On error will be populated with an error object describing the failure (a posix domain error such as EINVAL)
69 @result A CFURL pointing to the translocated location of the directory.
72 Calls to this function and SecTranslocateDeleteSecureDirectory are serialized to ensure only one call to either
73 is operating at a time.
74 Translocations will be created in the calling users's DARWIN_USER_TEMPDIR/AppTranslocation/<UUID>
76 pathToTranslocated is expected to be of the form /some/dir/myApp.app
77 destinationPath is expected to be of the form /<DARWIN_USER_TEMPDIR>/AppTranslocation/<DIR>/d/myApp.app
79 Resulting translocations are of the form /<DARWIN_USER_TEMPDIR>/AppTranslocation/<DIR>/d/myApp.app
80 <DIR> will be a UUID if destinationPath isn't specified.
82 If pathToTranslocate is in a quarantined mountpoint, the quarantine attributes will be propagated to the
83 translocated location.
85 pathToTranslocate will cause a failure if it doesn't resolve to a path that exists, or it exceeds MAXPATHLEN
87 destinationPath will cause a failure if
88 1. it doesn't match the app (last directory) specified by path to translocate
89 2. it differs from an already existing mount location for pathToTranslocate
90 3. It isn't in the user's current temp dir
91 4. someone created a file with the same name as the provided path
92 5. It doesn't match the form /<DARWIN_USER_TEMPDIR>/AppTranslocation/<DIR>/d/myApp.app
94 pathToTranslocate is returned if it should not be translocated based on policy. It is retained if so it can be treated as a copy.
96 This function can be run from any process. If the process is not the xpc server, then an xpc call is made.
98 CFURLRef __nullable
SecTranslocateCreateSecureDirectoryForURL (CFURLRef pathToTranslocate
, CFURLRef __nullable destinationPath
, CFErrorRef
* __nullable error
)
99 __OSX_AVAILABLE(10.12);
102 @function SecTranslocateAppLaunchCheckin
104 @abstract Register that a translocated pid is running
106 @param pid the pid to register
108 @discussion this function will log if there is a problem. The actual work is either sent to the server via xpc, or dispatched async.
110 This function can be run from any process. If the process is not the xpc server, then an xpc call is made.
112 void SecTranslocateAppLaunchCheckin(pid_t pid
)
113 __OSX_AVAILABLE(10.12);
116 @function SecTranslocateURLShouldRunTranslocated
118 @abstract Implements policy to decide whether the entity defined by path should be run translocated
120 @param path URL to the entity in question
122 @param shouldTranslocate true if the path should be translocated, false otherwise
124 @param error On error will be populated with an error object describing the failure (a posix domain error such as EINVAL)
126 @result true on success, false on failure (on failure error is set if provided). shouldTranslocate gives the answer
128 @discussion The policy is as follows:
129 1. If path is already on a nullfs mountpoint - no translocation
130 2. No quarantine attributes - no translocation
131 3. If QTN_FLAG_DO_NOT_TRANSLOCATE is set or QTN_FLAG_TRANSLOCATE is not set - no translocations
132 4. Otherwise, if QTN_FLAG_TRANSLOCATE is set - translocation
134 This function can be called from any process or thread.
136 Boolean
SecTranslocateURLShouldRunTranslocated(CFURLRef path
, bool* shouldTranslocate
, CFErrorRef
* __nullable error
)
137 __OSX_AVAILABLE(10.12);
140 @function SecTranslocateIsTranslocatedURL
142 @abstract indicates whether the provided path is an original path or a translocated path
144 @param path path to check
146 @param isTranslocated true if the path is translocated, false otherwise
148 @param error On error will be populated with an error object describing the failure (a posix domain error such as EINVAL)
150 @result true on success, false on failure (on failure error is set if provided). isTranslocated gives the answer
152 @discussion will return
153 1. false and EPERM if the caller doesn't have read access to the path
154 2. false and ENOENT if the path doesn't exist
155 3. false and ENINVAL if the parameters are broken
156 4. true and isTranslocated = true if the path is on a nullfs mount
157 5. true and isTranslocated = false if the path is not on a nullfs mount
159 If path is a symlink, the results will reflect whatever the symlink actually points to.
161 This function can be called from any process or thread.
163 Boolean
SecTranslocateIsTranslocatedURL(CFURLRef path
, bool* isTranslocated
, CFErrorRef
* __nullable error
)
164 __OSX_AVAILABLE(10.12);
167 @function SecTranslocateCreateOriginalPathForURL
169 @abstract finds the original path to a file given a translocated path
171 @param translocatedPath the path to look up
173 @param error On error will be populated with an error object describing the failure (a posix domain error such as EINVAL)
175 @result A valid, existant path, or NULL on error
177 @discussion will return
178 1. NULL and EPERM if the caller doesn't have read access to the path
179 2. NULL and ENOENT if the path doesn't exist
180 3. NULL and ENINVAL if the parameters are broken
181 4. A retained copy of translocatedPath if it isn't translocated
182 5. The real path to original untranslocated file/directory.
184 If translocatedPath is a symlink, the results will reflect whatever the symlink actually points to.
186 This function can be called from any process or thread.
188 CFURLRef __nullable
SecTranslocateCreateOriginalPathForURL(CFURLRef translocatedPath
, CFErrorRef
* __nullable error
)
189 __OSX_AVAILABLE(10.12);
192 @function SecTranslocateDeleteSecureDirectory
194 @abstract Unmount the translocated directory structure and delete the mount point directory.
196 @param translocatedPath a CFURL pointing to a translocated location.
198 @param error On error will be populated with an error object describing the failure (a posix domain error such as EINVAL).
200 @result true on success, false on error.
202 @discussion This function will make sure that the translocatedPath belongs to the calling user before unmounting.
203 After an unmount, this function will iterate through all the directories in the user's AppTranslocation directory
204 and delete any that aren't currently mounted on.
205 This function can only be called from the XPC Server. An error will be returned if this is called from any other process.
208 Boolean
SecTranslocateDeleteSecureDirectory(CFURLRef translocatedPath
, CFErrorRef
* __nullable error
)
209 __OSX_AVAILABLE(10.12);
216 CF_ASSUME_NONNULL_END
218 #endif /* H_LIBSECURITY_TRANSLOCATE */