diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-27 03:31:21 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-27 03:31:21 +0000 |
commit | 91bb0683770bc38f0c5b24475398d1996c67ab61 (patch) | |
tree | a357911e15f377cce2296444f0b5c2522d3fa6d8 /includes/filetransfer/local.inc | |
parent | f4d17e018cff383cfd92a06d1d69e217b79a964f (diff) | |
download | brdo-91bb0683770bc38f0c5b24475398d1996c67ab61.tar.gz brdo-91bb0683770bc38f0c5b24475398d1996c67ab61.tar.bz2 |
#609728 by dww and JacobSingh: Skip authorize.php step in update manager if webroot files are owned by the httpd user.
Diffstat (limited to 'includes/filetransfer/local.inc')
-rw-r--r-- | includes/filetransfer/local.inc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/includes/filetransfer/local.inc b/includes/filetransfer/local.inc new file mode 100644 index 000000000..268735077 --- /dev/null +++ b/includes/filetransfer/local.inc @@ -0,0 +1,77 @@ +<?php +// $Id$ + +/** + * The local connection class for copying files as the httpd user. + */ +class FileTransferLocal extends FileTransfer implements FileTransferChmodInterface { + + function connect() { + // No-op. + } + + static function factory($jail, $settings) { + return new FileTransferLocal($jail); + } + + protected function copyFileJailed($source, $destination) { + if (@!copy($source, $destination)) { + throw new FileTransferException('Cannot copy %source to %destination.', NULL, array('%source' => $source, '%destination' => $destination)); + } + } + + protected function createDirectoryJailed($directory) { + if (!is_dir($directory) && @!mkdir($directory, 0777, TRUE)) { + throw new FileTransferException('Cannot create directory %directory.', NULL, array('%directory' => $directory)); + } + } + + protected function removeDirectoryJailed($directory) { + if (!is_dir($directory)) { + // Programmer error assertion, not something we expect users to see. + throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, array('%directory' => $directory)); + } + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) { + if ($file->isDir()) { + if (@!rmdir($filename)) { + throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename)); + } + } + elseif ($file->isFile()) { + if (@!unlink($filename)) { + throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $filename)); + } + } + } + if (@!rmdir($directory)) { + throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $directory)); + } + } + + protected function removeFileJailed($file) { + if (@!unlink($file)) { + throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $file)); + } + } + + public function isDirectory($path) { + return is_dir($path); + } + + public function isFile($path) { + return is_file($path); + } + + public function chmodJailed($path, $mode, $recursive) { + if ($recursive && is_dir($path)) { + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) { + if (@!chmod($filename, $mode)) { + throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $filename)); + } + } + } + elseif (@!chmod($path, $mode)) { + throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $path)); + } + } +} |