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@
25 This header and its corresponding implementation are intended to house functionality that's useful
26 throughtout SecTranslocate but isn't directly tied to the SPI or things that must be serialized.
29 #ifndef SecTranslocateUtilities_hpp
30 #define SecTranslocateUtilities_hpp
33 #include <sys/param.h>
34 #include <sys/mount.h>
35 #include <security_utilities/unix++.h>
40 #define NULLFS_FSTYPE "nullfs"
44 using namespace Security::UnixPlusPlus;
46 namespace SecTranslocate {
50 class ExtendedAutoFileDesc : public AutoFileDesc {
52 ExtendedAutoFileDesc() = delete; //Always want these initialized with a path
54 ExtendedAutoFileDesc(const char *path, int flag = O_RDONLY, mode_t mode = 0666)
55 : AutoFileDesc(path, flag, mode), originalPath(path) { init(); }
56 ExtendedAutoFileDesc(const std::string &path, int flag = O_RDONLY, mode_t mode = 0666)
57 : AutoFileDesc(path, flag, mode),originalPath(path) { init(); }
59 bool isFileSystemType(const string &fsType) const;
60 bool pathIsAbsolute() const;
61 bool isMountPoint() const;
62 bool isInPrefixDir(const string &prefixDir) const;
63 string getFsType() const;
64 string getMountPoint() const;
65 string getMountFromPath() const;
66 const string& getRealPath() const;
67 fsid_t const getFsid() const;
69 bool isUserApproved();
70 bool shouldTranslocate();
72 // implicit destructor should call AutoFileDesc destructor. Nothing else to clean up.
75 inline void notOpen() const { if(!isOpen()) UnixError::throwMe(EINVAL); };
80 bool quarantineFetched;
83 void fetchQuarantine();
88 void* checkedDlopen(const char* path, int mode);
89 void* checkedDlsym(void* handle, const char* symbol);
91 //Path parsing functions
92 vector<string> splitPath(const string &path);
93 string joinPath(vector<string>& path);
94 string joinPathUpTo(vector<string> &path, size_t index);
96 //File system utlities
97 string getRealPath(const string &path);
98 int getFDForDirectory(const string &directoryPath, bool *owned = NULL); //creates the directory if it can
101 //Translocation specific utilities
102 string translocationDirForUser();
104 } // namespace SecTranslocate
105 } // namespace Security
108 #endif /* SecTranslocateUtilities_hpp */