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* kSecTranslocateXPCMessagePid;
53 /*XPC message reply keys */
54 extern const char* kSecTranslocateXPCReplyError;
55 extern const char* kSecTranslocateXPCReplySecurePath;
57 class TranslocationPath
60 TranslocationPath(string originalPath);
61 inline bool shouldTranslocate() const { return should; };
62 inline const string & getOriginalRealPath() const { return realOriginalPath; };
63 inline const string & getPathToTranslocate() const { return pathToTranslocate; };
64 inline const string & getPathInsideTranslocation() const { return pathInsideTranslocationPoint; };
65 inline const string & getComponentNameToTranslocate() const { return componentNameToTranslocate; };
66 string getTranslocatedPathToOriginalPath(const string &translocationPoint) const;
68 TranslocationPath() = delete;
71 string realOriginalPath;
72 string pathToTranslocate;
73 string componentNameToTranslocate; //the final component of pathToTranslocate
74 string pathInsideTranslocationPoint;
76 ExtendedAutoFileDesc findOuterMostCodeBundleForFD(ExtendedAutoFileDesc &fd);
79 string getOriginalPath(const ExtendedAutoFileDesc& fd, bool* isDir); //throws
81 // For methods below, the caller is responsible for ensuring that only one thread is
82 // accessing/modifying the mount table at a time
83 string translocatePathForUser(const TranslocationPath &originalPath, const string &destPath); //throws
84 bool destroyTranslocatedPathForUser(const string &translocatedPath); //throws
85 bool destroyTranslocatedPathsForUserOnVolume(const string &volumePath = ""); //throws
86 void tryToDestroyUnusedTranslocationMounts();
88 } //namespace SecTranslocate
89 }// namespace Security
91 #endif /* SecTranslocateShared_hpp */