tool_operate: only set SSH related libcurl options for SSH URLs

For example, this avoids trying to find and set the known_hosts file (or
warn for its absence) if SFTP or SCP are not used.

Closes #8040
This commit is contained in:
Daniel Stenberg 2021-11-21 15:52:58 +01:00
parent 3f8fde366f
commit 18270893ab
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 83 additions and 36 deletions

View file

@ -661,6 +661,29 @@ static void single_transfer_cleanup(struct OperationConfig *config)
}
}
/*
* Return the proto bit for the scheme used in the given URL
*/
static long url_proto(char *url)
{
CURLU *uh = curl_url();
long proto = 0;
if(url) {
if(!curl_url_set(uh, CURLUPART_URL, url,
CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME)) {
char *schemep = NULL;
if(!curl_url_get(uh, CURLUPART_SCHEME, &schemep,
CURLU_DEFAULT_SCHEME) &&
schemep) {
proto = scheme2protocol(schemep);
curl_free(schemep);
}
}
curl_url_cleanup(uh);
}
return proto;
}
/* create the next (singular) transfer */
static CURLcode single_transfer(struct GlobalConfig *global,
@ -801,6 +824,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
struct OutStruct *etag_save;
struct HdrCbData *hdrcbdata = NULL;
struct OutStruct etag_first;
long use_proto;
CURL *curl;
/* --etag-save */
@ -1194,6 +1218,15 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(result)
break;
/* here */
use_proto = url_proto(per->this_url);
#if 0
if(!(use_proto & built_in_protos)) {
warnf(global, "URL is '%s' but no support for the scheme\n",
per->this_url);
}
#endif
if(!config->tcp_nodelay)
my_setopt(curl, CURLOPT_TCP_NODELAY, 0L);
@ -1410,7 +1443,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
my_setopt_str(curl, CURLOPT_KEYPASSWD, config->key_passwd);
my_setopt_str(curl, CURLOPT_PROXY_KEYPASSWD, config->proxy_key_passwd);
if(built_in_protos & (CURLPROTO_SCP|CURLPROTO_SFTP)) {
if(use_proto & (CURLPROTO_SCP|CURLPROTO_SFTP)) {
/* SSH and SSL private key uses same command-line option */
/* new in libcurl 7.16.1 */
@ -1681,7 +1714,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->path_as_is)
my_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
if((built_in_protos & (CURLPROTO_SCP|CURLPROTO_SFTP)) &&
if((use_proto & (CURLPROTO_SCP|CURLPROTO_SFTP)) &&
!config->insecure_ok) {
char *home = homedir(NULL);
if(home) {