2 suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
4 This file is part of suPHP.
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.
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.
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
21 #ifndef SUPHP_API_LINUX_H
27 #define SUPHP_API_LINUX_H
32 #include "Environment.hpp"
33 #include "SmartPtr.hpp"
35 #include "API_Linux_Logger.hpp"
40 * Class encapsulating system-specific API for Linux.
42 class API_Linux
: public API
{
44 static SmartPtr
<API_Linux_Logger
> logger
;
46 * Internal function for checking wheter path
49 bool isSymlink(const std::string path
) const
50 throw (SystemException
);
53 * Internal function to read the target of a symlink
55 std::string
readSymlink(const std::string path
) const
56 throw (SystemException
);
60 * Get environment variable
62 virtual Environment
getProcessEnvironment();
65 * Get UserInfo from username
67 virtual UserInfo
getUserInfo(const std::string username
)
68 throw (LookupException
);
71 * Get UserInfo from UID
73 virtual UserInfo
getUserInfo(const int uid
);
76 * Get GroupInfo from groupname
78 virtual GroupInfo
getGroupInfo(const std::string groupname
)
79 throw (LookupException
);
82 * Get GroupInfo from GID
84 virtual GroupInfo
getGroupInfo(const int gid
);
87 * Get UserInfo for effective UID
89 virtual UserInfo
getEffectiveProcessUser();
92 * Get UserInfo for real UID
94 virtual UserInfo
getRealProcessUser();
97 * Get GroupInfo for effective GID
99 virtual GroupInfo
getEffectiveProcessGroup();
102 * Get GroupInfo for real GID
104 virtual GroupInfo
getRealProcessGroup();
107 virtual Logger
& getSystemLogger();
110 * Set UID of current process
112 virtual void setProcessUser(const UserInfo
& user
) const
113 throw (SystemException
);
116 * Set GID of current process
118 virtual void setProcessGroup(const GroupInfo
& group
) const
119 throw (SystemException
);
122 * Returns username from UserInfo
124 virtual std::string
UserInfo_getUsername(const UserInfo
& uinfo
) const
125 throw (LookupException
);
128 * Returns group from UserInfo
130 virtual GroupInfo
UserInfo_getGroupInfo(const UserInfo
& uinfo
) const throw (LookupException
);
133 * Returns home directory from UserInfo
135 virtual std::string
UserInfo_getHomeDirectory(const UserInfo
& uinfo
) const
136 throw (LookupException
);
139 * Checks whether UserInfo objects represents the super-user
141 virtual bool UserInfo_isSuperUser(const UserInfo
& uinfo
) const;
144 * Returns groupname from GroupInfo
146 std::string
GroupInfo_getGroupname(const GroupInfo
& ginfo
) const
147 throw (LookupException
);
150 * Checks whether file exists
152 virtual bool File_exists(const File
& file
) const;
155 * Returns real path to file
157 virtual std::string
File_getRealPath(const File
& file
) const
158 throw (SystemException
);
161 * Checks for a permission bit
163 virtual bool File_hasPermissionBit(const File
& file
, FileMode perm
)
164 const throw (SystemException
);
167 * Returns UID of file
169 virtual UserInfo
File_getUser(const File
& file
) const
170 throw (SystemException
);
173 * Returns GID of file
175 virtual GroupInfo
File_getGroup(const File
& file
) const
176 throw (SystemException
);
179 * Checks whether a file is a symlink
181 virtual bool File_isSymlink(const File
& file
) const throw (SystemException
);
184 * Runs another program (replaces current process)
186 virtual void execute(std::string program
, const CommandLine
& cline
,
187 const Environment
& env
) const
188 throw (SystemException
);
191 * Returns current working directory
193 virtual std::string
getCwd() const throw (SystemException
);
196 * Sets current working directory
198 virtual void setCwd(const std::string
& dir
) const
199 throw (SystemException
);
204 virtual void setUmask(int umask
) const throw (SystemException
);
207 * Sets new root directory for current process
209 virtual void chroot(const std::string
& dir
) const
210 throw (SystemException
);
214 #endif // SUPHP_API_LINUX_H