bool suPHP::API_Linux::File_exists(const File& file) const {
struct stat dummy;
- if (::stat(file.getPath().c_str(), &dummy) == 0)
- return true;
+ if (::lstat(file.getPath().c_str(), &dummy) == 0)
+ return true;
else
- return false;
+ return false;
}
std::string suPHP::API_Linux::File_getRealPath(const File& file) const
std::string resolvedpath = "";
bool failed = true;
- if (currentpath.at(0) != '/') {
+ if ((currentpath.size() == 0) || (currentpath.at(0) != '/')) {
currentpath = this->getCwd() + std::string("/") + currentpath;
}
bool suPHP::API_Linux::File_hasPermissionBit(const File& file, FileMode perm)
const throw (SystemException) {
struct stat temp;
- if (stat(file.getPath().c_str(), &temp) == -1) {
+ if (lstat(file.getPath().c_str(), &temp) == -1) {
throw SystemException(std::string("Could not stat \"")
+ file.getPath() + "\": "
+ ::strerror(errno), __FILE__, __LINE__);
break;
case FILEMODE_GROUP_EXEC:
- if ((temp.st_mode & S_IWGRP) == S_IWGRP)
+ if ((temp.st_mode & S_IXGRP) == S_IXGRP)
return true;
break;
UserInfo suPHP::API_Linux::File_getUser(const File& file) const
throw (SystemException) {
struct stat temp;
- if (stat(file.getPath().c_str(), &temp) == -1) {
+ if (lstat(file.getPath().c_str(), &temp) == -1) {
throw SystemException(std::string("Could not stat \"")
+ file.getPath() + "\": "
+ ::strerror(errno), __FILE__, __LINE__);
GroupInfo suPHP::API_Linux::File_getGroup(const File& file) const
throw (SystemException) {
struct stat temp;
- if (stat(file.getPath().c_str(), &temp) == -1) {
+ if (lstat(file.getPath().c_str(), &temp) == -1) {
throw SystemException(std::string("Could not stat \"")
+ file.getPath() + "\": "
+ ::strerror(errno), __FILE__, __LINE__);
}
+bool suPHP::API_Linux::File_isSymlink(const File& file) const throw (SystemException) {
+ return this->isSymlink(file.getPath());
+}
+
+
void suPHP::API_Linux::execute(std::string program, const CommandLine& cline,
const Environment& env) const
throw (SystemException) {
void suPHP::API_Linux::setUmask(int mode) const throw (SystemException) {
::umask(mode);
}
+
+void suPHP::API_Linux::chroot(const std::string& dir) const
+ throw (SystemException) {
+ if (::chroot(dir.c_str())) {
+ throw SystemException(std::string("chroot() failed: ")
+ + ::strerror(errno), __FILE__, __LINE__);
+ }
+}