From patchwork Tue Jul 14 18:06:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Frattaroli X-Patchwork-Id: 21014 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 54F6B449B60 for ; Tue, 14 Jul 2020 21:07:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 27DA4687FA2; Tue, 14 Jul 2020 21:07:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from fratti.ch (i.am.not.fratti.ch [148.251.88.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 966FF681868 for ; Tue, 14 Jul 2020 21:07:02 +0300 (EEST) From: Nicolas Frattaroli DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fratti.ch; s=mail; t=1594750021; bh=CpPYjUXuS/tS/X7o/jQr8c9uvPEk/DWKQzkiXtzwL6s=; h=From:To:Cc:Subject:Date:From; b=wWrGGnjTW+3l1TyxG3IDBTkRdwqDPsUFr4KknZAX4qP1uegP324sYnAt1Kzw9JIhI S/4USoWbTo2/wNAZt/4fk5odzDkeJZcHO2nPeRbEWUwKCd3Zewah/ofODd4azhDJF7 ffM2z3qQiEGF3QAxMw0bAH962PC0vIdoRjI3wFCI= To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 20:06:23 +0200 Message-Id: <20200714180623.779375-1-ffmpeg@fratti.ch> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/libssh: add AVOptions for authentication X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nicolas Frattaroli Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This introduces two new AVOption options for the SFTP protocol, one named sftp_user to supply the username to be used for auth, one named sftp_password to supply the password to be used for auth. These are useful for when an API user does not wish to deal with URL manipulation and percent encoding. Setting them while also having credentials in the URL will use the credentials from the URL. The rationale for this is that credentials embedded in the URL are probably more specific to what the user is trying to do than anything set by some API user. Signed-off-by: Nicolas Frattaroli --- doc/protocols.texi | 8 ++++++++ libavformat/libssh.c | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 64ad3f05d6..40c8c572e5 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -880,6 +880,14 @@ truncating. Default value is 1. Specify the path of the file containing private key to use during authorization. By default libssh searches for keys in the @file{~/.ssh/} directory. +@item sftp_user +Set a user to be used for authenticating to the SSH daemon. This is overridden by the +user in the SFTP URL. + +@item sftp_password +Set a password to be used for authenticating to the SSH daemon. This is overridden by +the password in the SFTP URL. + @end table Example: Play a file stored on remote server. diff --git a/libavformat/libssh.c b/libavformat/libssh.c index 21474f0f0a..a673e49a3a 100644 --- a/libavformat/libssh.c +++ b/libavformat/libssh.c @@ -39,6 +39,8 @@ typedef struct { int rw_timeout; int trunc; char *priv_key; + const char *option_user; + const char *option_password; } LIBSSHContext; static av_cold int libssh_create_ssh_session(LIBSSHContext *libssh, const char* hostname, unsigned int port) @@ -192,13 +194,13 @@ static av_cold int libssh_close(URLContext *h) static av_cold int libssh_connect(URLContext *h, const char *url, char *path, size_t path_size) { LIBSSHContext *libssh = h->priv_data; - char proto[10], hostname[1024], credencials[1024]; + char proto[10], hostname[1024], credentials[1024]; int port = 22, ret; const char *user = NULL, *pass = NULL; char *end = NULL; av_url_split(proto, sizeof(proto), - credencials, sizeof(credencials), + credentials, sizeof(credentials), hostname, sizeof(hostname), &port, path, path_size, @@ -214,8 +216,13 @@ static av_cold int libssh_connect(URLContext *h, const char *url, char *path, si if ((ret = libssh_create_ssh_session(libssh, hostname, port)) < 0) return ret; - user = av_strtok(credencials, ":", &end); - pass = av_strtok(end, ":", &end); + if(!*credentials) { + user = libssh->option_user; + pass = libssh->option_password; + } else { + user = av_strtok(credentials, ":", &end); + pass = av_strtok(end, ":", &end); + } if ((ret = libssh_authentication(libssh, user, pass)) < 0) return ret; @@ -479,6 +486,8 @@ static const AVOption options[] = { {"timeout", "set timeout of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E }, {"truncate", "Truncate existing files on write", OFFSET(trunc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, E }, {"private_key", "set path to private key", OFFSET(priv_key), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D|E }, + {"sftp_user", "user for SFTP login. Overridden by whatever is in the URL.", OFFSET(option_user), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, + {"sftp_password", "password for SFTP login. Overridden by whatever is in the URL.", OFFSET(option_password), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, {NULL} };