From 07fddff440bcbde0da298ae6d704794c300fb943 Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Wed, 22 May 2019 20:17:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20thanks=20to=20@DavieDavie?= =?UTF-8?q?Dave=20(nextcloud/apps#56):=20SSH=20password=20authentication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- README.md | 22 +++++++++++++++++++++ appinfo/app.php | 1 + lib/ssh.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lib/ssh.php diff --git a/README.md b/README.md index 38f477f..98ffa07 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,28 @@ Add the following to your `config.php`: [BasicAuth_0]: https://en.wikipedia.org/wiki/Basic_access_authentication +SSH +--- + +Authenticates users via SSH. You can use any SSH2 server, but it must accept password authentication. + +### Configuration +The only supported parameter is the hostname of the remote machine. + +Add the following to your `config.php`: + + 'user_backends' => array( + array( + 'class' => 'OC_User_SSH', + 'arguments' => array('127.0.0.1'), + ), + ), + + +### Dependencies +Requires the php-ssh2 PECL module installed. + + XMPP (Prosody) ---- Authenticate Nextcloud users against a Prosody XMPP MySQL database. diff --git a/appinfo/app.php b/appinfo/app.php index c5b2519..6c3b095 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -3,4 +3,5 @@ OC::$CLASSPATH['OC_User_IMAP']='user_external/lib/imap.php'; OC::$CLASSPATH['OC_User_SMB']='user_external/lib/smb.php'; OC::$CLASSPATH['OC_User_FTP']='user_external/lib/ftp.php'; OC::$CLASSPATH['OC_User_BasicAuth']='user_external/lib/basicauth.php'; +OC::$CLASSPATH['OC_User_SSH']='user_external/lib/ssh.php'; OC::$CLASSPATH['OC_User_XMPP']='user_external/lib/xmpp.php'; diff --git a/lib/ssh.php b/lib/ssh.php new file mode 100644 index 0000000..ae575ba --- /dev/null +++ b/lib/ssh.php @@ -0,0 +1,51 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * User authentication against a FTP/FTPS server + * + * @category Apps + * @package UserExternal + * @author David Fullard + * @license http://www.gnu.org/licenses/agpl AGPL + * @link http://github.com/owncloud/apps + */ + + +class OC_User_SSH extends \OCA\user_external\Base { + private $host; + + /** + * Create a new SSH authentication provider + * + * @param string $host Hostname or IP address of SSH servr + */ + public function __construct($host) { + parent::__construct($host); + $this->host =$host; + } + + /** + * Check if the password is correct without logging in + * Requires the php-ssh2 pecl extension + * + * @param string $uid The username + * @param string $password The password + * + * @return true/false + */ + public function checkPassword($uid, $password) { + $connection = ssh2_connect($this->host); + if (ssh2_auth_password($connection, $uid, $password)) { + $this->storeUser($uid); + return $uid; + } else { + return false; + } + } +}