Import upstream 0.7.1
[manu/suphp.git] / src / API_Linux.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_LINUX_H
22
23 namespace suPHP {
24     class API_Linux;
25 };
26
27 #define SUPHP_API_LINUX_H
28
29 #include <string>
30
31 #include "API.hpp"
32 #include "Environment.hpp"
33 #include "SmartPtr.hpp"
34 #include "File.hpp"
35 #include "API_Linux_Logger.hpp"
36
37
38 namespace suPHP {
39     /**
40      * Class encapsulating system-specific API for Linux.
41      */
42     class API_Linux : public API {
43     private:
44         static SmartPtr<API_Linux_Logger> logger;
45         /**
46          * Internal function for checking wheter path
47          * points to a symlink
48          */
49         bool isSymlink(const std::string path) const 
50             throw (SystemException);
51
52         /**
53          * Internal function to read the target of a symlink
54          */
55         std::string readSymlink(const std::string path) const 
56             throw (SystemException);
57
58     public:
59         /**
60          * Get environment variable
61          */
62         virtual Environment getProcessEnvironment();
63
64         /**
65          * Get UserInfo from username
66          */
67         virtual UserInfo getUserInfo(const std::string username) 
68             throw (LookupException);
69         
70         /**
71          * Get UserInfo from UID
72          */
73         virtual UserInfo getUserInfo(const int uid);
74         
75         /**
76          * Get GroupInfo from groupname
77          */
78         virtual GroupInfo getGroupInfo(const std::string groupname) 
79             throw (LookupException);
80         
81         /**
82          * Get GroupInfo from GID
83          */
84         virtual GroupInfo getGroupInfo(const int gid);
85
86         /**
87          * Get UserInfo for effective UID
88          */
89         virtual UserInfo getEffectiveProcessUser();
90
91         /**
92          * Get UserInfo for real UID
93          */
94         virtual UserInfo getRealProcessUser();
95
96         /**
97          * Get GroupInfo for effective GID
98          */
99         virtual GroupInfo getEffectiveProcessGroup();
100
101         /**
102          * Get GroupInfo for real GID
103          */
104         virtual GroupInfo getRealProcessGroup();
105
106         
107         virtual Logger& getSystemLogger();
108            
109         /**
110          * Set UID of current process
111          */
112         virtual void setProcessUser(const UserInfo& user) const
113             throw (SystemException);
114         
115         /**
116          * Set GID of current process
117          */
118         virtual void setProcessGroup(const GroupInfo& group) const
119             throw (SystemException);
120
121         /**
122          * Returns username from UserInfo
123          */
124         virtual std::string UserInfo_getUsername(const UserInfo& uinfo) const
125             throw (LookupException);
126         
127         /**
128          * Returns group from UserInfo
129          */
130         virtual GroupInfo UserInfo_getGroupInfo(const UserInfo& uinfo) const throw (LookupException);
131         
132         /**
133          * Returns home directory from UserInfo
134          */
135         virtual std::string UserInfo_getHomeDirectory(const UserInfo& uinfo) const
136             throw (LookupException);
137         
138         /**
139          * Checks whether UserInfo objects represents the super-user
140          */
141         virtual bool UserInfo_isSuperUser(const UserInfo& uinfo) const;
142
143         /**
144          * Returns groupname from GroupInfo
145          */
146         std::string GroupInfo_getGroupname(const GroupInfo& ginfo) const 
147             throw (LookupException);
148         
149         /**
150          * Checks whether file exists
151          */
152         virtual bool File_exists(const File& file) const;
153
154         /**
155          * Returns real path to file
156          */
157         virtual std::string File_getRealPath(const File& file) const 
158             throw (SystemException);
159
160         /**
161          * Checks for a permission bit
162          */
163         virtual bool File_hasPermissionBit(const File& file, FileMode perm) 
164             const throw (SystemException);
165
166         /**
167          * Returns UID of file
168          */
169         virtual UserInfo File_getUser(const File& file) const
170             throw (SystemException);
171
172         /**
173          * Returns GID of file
174          */
175         virtual GroupInfo File_getGroup(const File& file) const
176             throw (SystemException);
177         
178         /**
179          * Checks whether a file is a symlink
180          */
181         virtual bool File_isSymlink(const File& file) const throw (SystemException);
182
183         /**
184          * Runs another program (replaces current process)
185          */
186         virtual void execute(std::string program, const CommandLine& cline, 
187                         const Environment& env) const
188             throw (SystemException);
189         
190         /**
191          * Returns current working directory
192          */
193         virtual std::string getCwd() const throw (SystemException);
194
195         /**
196          * Sets current working directory
197          */
198         virtual void setCwd(const std::string& dir) const 
199             throw (SystemException);
200
201         /**
202          * Sets umask
203          */
204         virtual void setUmask(int umask) const throw (SystemException);
205
206         /**
207          * Sets new root directory for current process
208          */
209         virtual void chroot(const std::string& dir) const 
210             throw (SystemException);
211     };
212 };
213
214 #endif // SUPHP_API_LINUX_H