Imported Debian patch 0.7.1-1
[hcoop/zz_old/debian/suphp.git] / src / API.hpp
1 /*
2 suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
3
4 This file is part of suPHP.
5
6 suPHP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 suPHP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef SUPHP_API_H
22
23 namespace suPHP {
24 class API;
25 };
26
27 #define SUPHP_API_H
28
29 #include <string>
30 #include "CommandLine.hpp"
31 #include "Environment.hpp"
32 #include "UserInfo.hpp"
33 #include "GroupInfo.hpp"
34 #include "File.hpp"
35 #include "Logger.hpp"
36
37 namespace suPHP {
38 /**
39 * Class encapsulating system-specific API.
40 */
41 class API {
42
43 public:
44 /**
45 * Get environment variable
46 */
47 virtual Environment getProcessEnvironment() =0;
48
49 /**
50 * Get UserInfo from username
51 */
52 virtual UserInfo getUserInfo(const std::string username)
53 throw (LookupException) =0;
54
55 /**
56 * Get UserInfo from UID
57 */
58 virtual UserInfo getUserInfo(const int uid) =0;
59
60 /**
61 * Get GroupInfo from groupname
62 */
63 virtual GroupInfo getGroupInfo(const std::string groupname)
64 throw (LookupException) =0;
65
66 /**
67 * Get GroupInfo from GID
68 */
69 virtual GroupInfo getGroupInfo(const int gid) =0;
70
71 /**
72 * Get UserInfo for effective UID
73 */
74 virtual UserInfo getEffectiveProcessUser() =0;
75
76 /**
77 * Get UserInfo for real UID
78 */
79 virtual UserInfo getRealProcessUser() =0;
80
81 /**
82 * Get GroupInfo for effective GID
83 */
84 virtual GroupInfo getEffectiveProcessGroup() =0;
85
86 /**
87 * Get GroupInfo for real GID
88 */
89 virtual GroupInfo getRealProcessGroup() =0;
90
91 /**
92 * Get Logger implementation
93 */
94 virtual Logger& getSystemLogger() =0;
95
96 /**
97 * Set UID of current process
98 */
99 virtual void setProcessUser(const UserInfo& user) const
100 throw (SystemException) =0;
101
102 /**
103 * Set GID of current process
104 */
105 virtual void setProcessGroup(const GroupInfo& group) const
106 throw (SystemException) =0;
107
108 /**
109 * Returns username from UserInfo
110 */
111 virtual std::string UserInfo_getUsername(const UserInfo& uinfo) const
112 throw (LookupException) =0;
113
114 /**
115 * Returns group from UserInfo
116 */
117 virtual GroupInfo UserInfo_getGroupInfo(const UserInfo& uinfo) const
118 throw (LookupException) =0;
119
120 /**
121 * Returns home directory from UserInfo
122 */
123 virtual std::string UserInfo_getHomeDirectory(const UserInfo& uinfo) const
124 throw (LookupException) =0;
125
126 /**
127 * Checks whether UserInfo objects represents the super-user
128 */
129 virtual bool UserInfo_isSuperUser(const UserInfo& uinfo) const =0;
130
131 /**
132 * Returns groupname from GroupInfo
133 */
134 virtual std::string GroupInfo_getGroupname(const GroupInfo& ginfo)
135 const throw (LookupException) =0;
136
137 /**
138 * Checks whether file exists
139 */
140 virtual bool File_exists(const File& file) const =0;
141
142 /**
143 * Returns real path to file
144 */
145 virtual std::string File_getRealPath(const File& file) const
146 throw (SystemException) =0;
147
148 /**
149 * Checks for a permission bit
150 */
151 virtual bool File_hasPermissionBit(const File& file, FileMode perm)
152 const throw (SystemException) =0;
153
154 /**
155 * Returns UID of file
156 */
157 virtual UserInfo File_getUser(const File& file) const
158 throw (SystemException) =0;
159
160 /**
161 * Returns GID of file
162 */
163 virtual GroupInfo File_getGroup(const File& file) const
164 throw (SystemException) =0;
165
166 /**
167 * Checks whether a file is a symlink
168 */
169 virtual bool File_isSymlink(const File& file) const
170 throw (SystemException) =0;
171
172 /**
173 * Runs another program (replaces current process)
174 */
175 virtual void execute(std::string program, const CommandLine& cline,
176 const Environment& env) const
177 throw (SystemException) =0;
178
179 /**
180 * Returns current working directory
181 */
182 virtual std::string getCwd() const throw (SystemException) =0;
183
184
185 /**
186 * Sets current working directory
187 */
188 virtual void setCwd(const std::string& dir) const
189 throw (SystemException) =0;
190
191 /**
192 * Sets umask
193 */
194 virtual void setUmask(int umask) const throw (SystemException) =0;
195
196 /**
197 * Changes root directory for the current process
198 */
199 virtual void chroot(const std::string& dir) const
200 throw (SystemException) =0;
201 };
202 };
203
204 #endif // SUPHP_API_H