]>
Commit | Line | Data |
---|---|---|
fa7225c8 A |
1 | /* |
2 | * Copyright (c) 2016 Apple Inc. All Rights Reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
11 | * file. | |
12 | * | |
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. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | /* Purpose: | |
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. | |
27 | */ | |
28 | ||
29 | #ifndef SecTranslocateUtilities_hpp | |
30 | #define SecTranslocateUtilities_hpp | |
31 | ||
32 | #include <stdio.h> | |
33 | #include <sys/param.h> | |
34 | #include <sys/mount.h> | |
35 | #include <security_utilities/unix++.h> | |
36 | ||
37 | #include <string> | |
38 | #include <vector> | |
39 | ||
40 | #define NULLFS_FSTYPE "nullfs" | |
41 | ||
42 | namespace Security { | |
43 | ||
44 | using namespace Security::UnixPlusPlus; | |
45 | ||
46 | namespace SecTranslocate { | |
47 | ||
48 | using namespace std; | |
49 | ||
50 | class ExtendedAutoFileDesc : public AutoFileDesc { | |
51 | public: | |
52 | ExtendedAutoFileDesc() = delete; //Always want these initialized with a path | |
53 | ||
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(); } | |
58 | ||
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; | |
68 | bool isQuarantined(); | |
69 | bool isUserApproved(); | |
70 | bool shouldTranslocate(); | |
71 | ||
72 | // implicit destructor should call AutoFileDesc destructor. Nothing else to clean up. | |
73 | private: | |
74 | void init(); | |
75 | inline void notOpen() const { if(!isOpen()) UnixError::throwMe(EINVAL); }; | |
76 | ||
77 | struct statfs fsInfo; | |
78 | string realPath; | |
79 | string originalPath; | |
80 | bool quarantineFetched; | |
81 | bool quarantined; | |
82 | uint32_t qtn_flags; | |
83 | void fetchQuarantine(); | |
84 | }; | |
85 | ||
86 | //General utilities | |
87 | string makeUUID(); | |
88 | void* checkedDlopen(const char* path, int mode); | |
89 | void* checkedDlsym(void* handle, const char* symbol); | |
90 | ||
91 | //Path parsing functions | |
92 | vector<string> splitPath(const string &path); | |
93 | string joinPath(vector<string>& path); | |
d64be36e | 94 | string joinPathUpTo(vector<string> &path, size_t index); |
fa7225c8 A |
95 | |
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 | |
99 | ||
100 | ||
101 | //Translocation specific utilities | |
102 | string translocationDirForUser(); | |
103 | ||
104 | } // namespace SecTranslocate | |
105 | } // namespace Security | |
106 | ||
107 | ||
108 | #endif /* SecTranslocateUtilities_hpp */ |