From patchwork Sat Oct 26 22:37:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Frattaroli X-Patchwork-Id: 15978 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 82418449EE8 for ; Sun, 27 Oct 2019 01:38:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5C2F168AECC; Sun, 27 Oct 2019 01:38:38 +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 29FCC68AC76 for ; Sun, 27 Oct 2019 01:38:32 +0300 (EEST) From: Nicolas Frattaroli DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fratti.ch; s=mail; t=1572129510; bh=kpfzc83zaQmJ9MIgElMXNIg/VZnk74GFGvmY2Hmx73w=; h=From:To:Cc:Subject:Date:From; b=qtaFABzXlE2RJVzf84AGLxY07KjiyOQ17mWXt8jLvRiqAyS5JL3oe4BNiJ5e8R+aL Iawcf94Y6UB6mSGZGPalHkJUJZAvs6qsY9g+C58BiOOu2KbeNlKzjK99ZzuCwk1XH8 hYiVb3oq3RqUNdJV3PZySiDTgTc5ywivjavwWNX8= To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Oct 2019 00:37:32 +0200 Message-Id: <20191026223732.305811-1-ffmpeg@fratti.ch> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/ftp: 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 FTP protocol, one named ftp-user to supply the username to be used for auth, one named ftp-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/ftp.c | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index b03432e3e5..0e18a49dda 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -228,6 +228,14 @@ Set timeout in microseconds of socket I/O operations used by the underlying low operation. By default it is set to -1, which means that the timeout is not specified. +@item ftp-user +Set a user to be used for authenticating to the FTP server. This is overridden by the +user in the FTP URL. + +@item ftp-password +Set a password to be used for authenticating to the FTP server. This is overridden by +the password in the FTP URL, or by @option{ftp-anonymous-password} if no user is set. + @item ftp-anonymous-password Password used when login as anonymous user. Typically an e-mail address should be used. diff --git a/libavformat/ftp.c b/libavformat/ftp.c index 3adc04ee1f..e3cbe5f8f0 100644 --- a/libavformat/ftp.c +++ b/libavformat/ftp.c @@ -69,6 +69,8 @@ typedef struct { size_t dir_buffer_size; size_t dir_buffer_offset; int utf8; + const char *option_user; /**< User to be used if none given in the URL */ + const char *option_password; /**< Password to be used if none given in the URL */ } FTPContext; #define OFFSET(x) offsetof(FTPContext, x) @@ -78,6 +80,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 }, {"ftp-write-seekable", "control seekability of connection during encoding", OFFSET(write_seekable), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E }, {"ftp-anonymous-password", "password for anonymous login. E-mail address should be used.", OFFSET(anonymous_password), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, + {"ftp-user", "user for FTP login. Overridden by whatever is in the URL.", OFFSET(option_user), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, + {"ftp-password", "password for FTP login. Overridden by whatever is in the URL.", OFFSET(option_password), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, {NULL} }; @@ -652,7 +656,7 @@ static int ftp_abort(URLContext *h) static int ftp_connect(URLContext *h, const char *url) { - char proto[10], path[MAX_URL_SIZE], credencials[MAX_URL_SIZE], hostname[MAX_URL_SIZE]; + char proto[10], path[MAX_URL_SIZE], credentials[MAX_URL_SIZE], hostname[MAX_URL_SIZE]; const char *tok_user = NULL, *tok_pass = NULL; char *end = NULL, *newpath = NULL; int err; @@ -665,17 +669,24 @@ static int ftp_connect(URLContext *h, const char *url) s->features = NULL; av_url_split(proto, sizeof(proto), - credencials, sizeof(credencials), + credentials, sizeof(credentials), hostname, sizeof(hostname), &s->server_control_port, path, sizeof(path), url); - tok_user = av_strtok(credencials, ":", &end); + tok_user = av_strtok(credentials, ":", &end); tok_pass = av_strtok(end, ":", &end); if (!tok_user) { - tok_user = "anonymous"; - tok_pass = av_x_if_null(s->anonymous_password, "nopassword"); + if (!s->option_user) { + tok_user = "anonymous"; + tok_pass = av_x_if_null(s->anonymous_password, "nopassword"); + } else { + tok_user = s->option_user; + } + } + if (!tok_pass) { + tok_pass = s->option_password; } s->user = av_strdup(tok_user); s->password = av_strdup(tok_pass);