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 /* Purpose: This header exposes shared functions that actually implement mount creation, policy question
25 answering and mount deletion.
27 Important: None of these functions implement synchronization and they all throw exceptions. It is up
28 to the caller to handle those concerns.
32 #include "SecTranslocateUtilities.hpp"
34 #ifndef SecTranslocateShared_hpp
35 #define SecTranslocateShared_hpp
39 namespace SecTranslocate {
43 /* XPC Function keys */
44 extern const char* kSecTranslocateXPCFuncCreate;
45 extern const char* kSecTranslocateXPCFuncCheckIn;
47 /* XPC message argument keys */
48 extern const char* kSecTranslocateXPCMessageFunction;
49 extern const char* kSecTranslocateXPCMessageOriginalPath;
50 extern const char* kSecTranslocateXPCMessageDestinationPath;
51 extern const char* kSecTranslocateXPCMessageOptions;
52 extern const char* kSecTranslocateXPCMessagePid;
54 /*XPC message reply keys */
55 extern const char* kSecTranslocateXPCReplyError;
56 extern const char* kSecTranslocateXPCReplySecurePath;
58 enum class TranslocationOptions : int64_t {
64 class GenericTranslocationPath
67 GenericTranslocationPath(const string& path, TranslocationOptions opts);
68 inline bool shouldTranslocate() const { return should; };
69 inline const string & getOriginalRealPath() const { return realOriginalPath; };
70 inline const string & getComponentNameToTranslocate() const { return componentNameToTranslocate; };
71 inline TranslocationOptions getOptions() const { return options; };
73 GenericTranslocationPath() = delete;
76 string realOriginalPath;
77 string componentNameToTranslocate;
78 TranslocationOptions options;
81 class TranslocationPath
84 TranslocationPath(string originalPath, TranslocationOptions opts);
85 inline bool shouldTranslocate() const { return should; };
86 inline const string & getOriginalRealPath() const { return realOriginalPath; };
87 inline const string & getPathToTranslocate() const { return pathToTranslocate; };
88 inline const string & getPathInsideTranslocation() const { return pathInsideTranslocationPoint; };
89 inline const string & getComponentNameToTranslocate() const { return componentNameToTranslocate; };
90 string getTranslocatedPathToOriginalPath(const string &translocationPoint) const;
91 inline TranslocationOptions getOptions() const { return options; };
93 TranslocationPath() = delete;
96 string realOriginalPath;
97 string pathToTranslocate;
98 string componentNameToTranslocate; //the final component of pathToTranslocate
99 string pathInsideTranslocationPoint;
100 TranslocationOptions options;
102 ExtendedAutoFileDesc findOuterMostCodeBundleForFD(ExtendedAutoFileDesc &fd);
105 string getOriginalPath(const ExtendedAutoFileDesc& fd, bool* isDir); //throws
107 // For methods below, the caller is responsible for ensuring that only one thread is
108 // accessing/modifying the mount table at a time
109 string translocatePathForUser(const TranslocationPath &originalPath, const string &destPath); //throws
110 string translocatePathForUser(const GenericTranslocationPath &originalPath, const string &destPath); //throws
111 bool destroyTranslocatedPathForUser(const string &translocatedPath); //throws
112 bool destroyTranslocatedPathsForUserOnVolume(const string &volumePath = ""); //throws
113 void tryToDestroyUnusedTranslocationMounts();
115 } //namespace SecTranslocate
116 }// namespace Security
119 #endif /* SecTranslocateShared_hpp */