0.6.0-1 release
[manu/suphp.git] / src / API_Linux.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_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          * Checks whether UserInfo objects represents the super-user
134          */
135         virtual bool UserInfo_isSuperUser(const UserInfo& uinfo) const;
136
137         /**
138          * Returns groupname from GroupInfo
139          */
140         std::string GroupInfo_getGroupname(const GroupInfo& ginfo) const 
141             throw (LookupException);
142         
143         /**
144          * Checks whether file exists
145          */
146         virtual bool File_exists(const File& file) const;
147
148         /**
149          * Returns real path to file
150          */
151         virtual std::string File_getRealPath(const File& file) const 
152             throw (SystemException);
153
154         /**
155          * Checks for a permission bit
156          */
157         virtual bool File_hasPermissionBit(const File& file, FileMode perm) 
158             const throw (SystemException);
159
160         /**
161          * Returns UID of file
162          */
163         virtual UserInfo File_getUser(const File& file) const
164             throw (SystemException);
165
166         /**
167          * Returns GID of file
168          */
169         virtual GroupInfo File_getGroup(const File& file) const
170             throw (SystemException);
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);
178         
179         /**
180          * Returns current working directory
181          */
182         virtual std::string getCwd() const throw (SystemException);
183
184         /**
185          * Sets current working directory
186          */
187         virtual void setCwd(const std::string& dir) const 
188             throw (SystemException);
189
190         /**
191          * Sets umask
192          */
193         virtual void setUmask(int umask) const throw (SystemException);
194     };
195 };
196
197 #endif // SUPHP_API_LINUX_H