r9183@datura: manu | 2008-06-04 09:59:07 +0200
[manu/suphp.git] / src / API.hpp
1 /*
2     suPHP - (c)2002-2005 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          * Checks whether UserInfo objects represents the super-user
122          */
123         virtual bool UserInfo_isSuperUser(const UserInfo& uinfo) const =0;
124
125         /**
126          * Returns groupname from GroupInfo
127          */
128         virtual std::string GroupInfo_getGroupname(const GroupInfo& ginfo) 
129             const throw (LookupException) =0;
130         
131         /**
132          * Checks whether file exists
133          */
134         virtual bool File_exists(const File& file) const =0;
135
136         /**
137          * Returns real path to file
138          */
139         virtual std::string File_getRealPath(const File& file) const 
140             throw (SystemException) =0;
141
142         /**
143          * Checks for a permission bit
144          */
145         virtual bool File_hasPermissionBit(const File& file, FileMode perm) 
146             const throw (SystemException) =0;
147
148         /**
149          * Returns UID of file
150          */
151         virtual UserInfo File_getUser(const File& file) const
152             throw (SystemException) =0;
153
154         /**
155          * Returns GID of file
156          */
157         virtual GroupInfo File_getGroup(const File& file) const
158             throw (SystemException) =0;
159         
160         /**
161          * Runs another program (replaces current process)
162          */
163         virtual void execute(std::string program, const CommandLine& cline, 
164                         const Environment& env) const
165             throw (SystemException) =0;
166
167         /**
168          * Returns current working directory
169          */
170         virtual std::string getCwd() const throw (SystemException) =0;
171
172
173         /**
174          * Sets current working directory
175          */
176         virtual void setCwd(const std::string& dir) const 
177             throw (SystemException) =0;
178         
179         /**
180          * Sets umask
181          */
182         virtual void setUmask(int umask) const throw (SystemException) =0;
183
184         /**
185          * Changes root directory for the current process
186          */
187         virtual void chroot(const std::string& dir) const
188             throw (SystemException) =0;
189     };
190 };
191
192 #endif // SUPHP_API_H