From b9b661ef2fa5bcf965a75a53057ffdb810f6e401 Mon Sep 17 00:00:00 2001
From: Angie Byron <webchick@24967.no-reply.drupal.org>
Date: Mon, 3 Jan 2011 02:20:45 +0000
Subject: [PATCH] #1010506 by dww, chx, hgurol: Fixed FileTransfer doesn't
 properly handle any advanced settings nor the ssh username

---
 includes/filetransfer/filetransfer.inc |  9 ++++++++-
 includes/filetransfer/ftp.inc          | 10 +++++-----
 includes/filetransfer/ssh.inc          | 10 +++++-----
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/includes/filetransfer/filetransfer.inc b/includes/filetransfer/filetransfer.inc
index 8d4271760994..cd62f1d51b1b 100644
--- a/includes/filetransfer/filetransfer.inc
+++ b/includes/filetransfer/filetransfer.inc
@@ -28,8 +28,15 @@ function __construct($jail) {
    * Classes that extend this class must override the factory() static method.
    *
    * @param string $jail
+   *   The full path where all file operations performed by this object will
+   *   be restricted to. This prevents the FileTransfer classes from being
+   *   able to touch other parts of the filesystem.
    * @param array $settings
-   * @return object New instance of the appropriate FileTransfer subclass.
+   *   An array of connection settings for the FileTransfer subclass. If the
+   *   getSettingsForm() method uses any nested settings, the same structure
+   *   will be assumed here.
+   * @return object
+   *   New instance of the appropriate FileTransfer subclass.
    */
   static function factory($jail, $settings) {
     throw new FileTransferException('FileTransfer::factory() static method not overridden by FileTransfer subclass.');
diff --git a/includes/filetransfer/ftp.inc b/includes/filetransfer/ftp.inc
index 3d4cc9f6455c..ddb0d3eae8b2 100644
--- a/includes/filetransfer/ftp.inc
+++ b/includes/filetransfer/ftp.inc
@@ -24,10 +24,10 @@ public function __construct($jail, $username, $password, $hostname, $port) {
    *   options. If the FTP PHP extension is available, use it.
    */
   static function factory($jail, $settings) {
-    $settings['username'] = empty($settings['username']) ? '' : $settings['username'];
-    $settings['password'] = empty($settings['password']) ? '' : $settings['password'];
-    $settings['hostname'] = empty($settings['hostname']) ? 'localhost' : $settings['hostname'];
-    $settings['port'] = empty($settings['port']) ? 21 : $settings['port'];
+    $username = empty($settings['username']) ? '' : $settings['username'];
+    $password = empty($settings['password']) ? '' : $settings['password'];
+    $hostname = empty($settings['advanced']['hostname']) ? 'localhost' : $settings['advanced']['hostname'];
+    $port = empty($settings['advanced']['port']) ? 21 : $settings['advanced']['port'];
 
     if (function_exists('ftp_connect')) {
       $class = 'FileTransferFTPExtension';
@@ -36,7 +36,7 @@ static function factory($jail, $settings) {
       throw new FileTransferException('No FTP backend available.');
     }
 
-    return new $class($jail, $settings['username'], $settings['password'], $settings['hostname'], $settings['port']);
+    return new $class($jail, $username, $password, $hostname, $port);
   }
 
   /**
diff --git a/includes/filetransfer/ssh.inc b/includes/filetransfer/ssh.inc
index d47360f9cc3c..8113478a3a4f 100644
--- a/includes/filetransfer/ssh.inc
+++ b/includes/filetransfer/ssh.inc
@@ -25,11 +25,11 @@ function connect() {
   }
 
   static function factory($jail, $settings) {
-    $settings['username'] = empty($settings['hostname']) ? '' : $settings['username'];
-    $settings['password'] = empty($settings['password']) ? '' : $settings['password'];
-    $settings['hostname'] = empty($settings['hostname']) ? 'localhost' : $settings['hostname'];
-    $settings['port'] = empty($settings['port']) ? 22 : $settings['port'];
-    return new FileTransferSSH($jail, $settings['username'], $settings['password'], $settings['hostname'], $settings['port']);
+    $username = empty($settings['username']) ? '' : $settings['username'];
+    $password = empty($settings['password']) ? '' : $settings['password'];
+    $hostname = empty($settings['advanced']['hostname']) ? 'localhost' : $settings['advanced']['hostname'];
+    $port = empty($settings['advanced']['port']) ? 22 : $settings['advanced']['port'];
+    return new FileTransferSSH($jail, $username, $password, $hostname, $port);
   }
 
   protected function copyFileJailed($source, $destination) {
-- 
GitLab