mirror of
https://github.com/curl/curl.git
synced 2026-08-25 21:23:32 +03:00
tool_getparam: add --knownhosts
To allow users to specify a known hosts file that is not the default one: ~/.ssh/known_hosts URL: https://github.com/curl/curl/discussions/18784 Closes #18859
This commit is contained in:
parent
762ce8801b
commit
aae18c4bdc
11 changed files with 48 additions and 14 deletions
|
|
@ -195,7 +195,7 @@ static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl)
|
|||
my_setopt_long(curl, CURLOPT_SSH_COMPRESSION, 1);
|
||||
|
||||
if(!config->insecure_ok) {
|
||||
char *known = global->knownhosts;
|
||||
char *known = config->knownhosts;
|
||||
|
||||
if(!known)
|
||||
known = findfile(".ssh/known_hosts", FALSE);
|
||||
|
|
@ -203,12 +203,12 @@ static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl)
|
|||
/* new in curl 7.19.6 */
|
||||
result = my_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known);
|
||||
if(result) {
|
||||
global->knownhosts = NULL;
|
||||
config->knownhosts = NULL;
|
||||
curl_free(known);
|
||||
return result;
|
||||
}
|
||||
/* store it in global to avoid repeated checks */
|
||||
global->knownhosts = known;
|
||||
config->knownhosts = known;
|
||||
}
|
||||
else if(!config->hostpubmd5 && !config->hostpubsha256) {
|
||||
errorf("Couldn't find a known_hosts file");
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ static void free_config_fields(struct OperationConfig *config)
|
|||
tool_safefree(config->ech);
|
||||
tool_safefree(config->ech_config);
|
||||
tool_safefree(config->ech_public);
|
||||
tool_safefree(config->knownhosts);
|
||||
}
|
||||
|
||||
void config_free(struct OperationConfig *config)
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ struct OperationConfig {
|
|||
char *proxyuserpwd;
|
||||
char *proxy;
|
||||
char *noproxy;
|
||||
char *knownhosts;
|
||||
char *mail_from;
|
||||
struct curl_slist *mail_rcpt;
|
||||
char *mail_auth;
|
||||
|
|
@ -335,8 +336,6 @@ struct GlobalConfig {
|
|||
FILE *trace_stream;
|
||||
char *libcurl; /* Output libcurl code to this filename */
|
||||
char *ssl_sessions; /* file to load/save SSL session tickets */
|
||||
char *knownhosts; /* known host path, if set. curl_free()
|
||||
this */
|
||||
struct tool_var *variables;
|
||||
struct OperationConfig *first;
|
||||
struct OperationConfig *current;
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ static const struct LongShort aliases[]= {
|
|||
{"keepalive-time", ARG_STRG, ' ', C_KEEPALIVE_TIME},
|
||||
{"key", ARG_FILE, ' ', C_KEY},
|
||||
{"key-type", ARG_STRG|ARG_TLS, ' ', C_KEY_TYPE},
|
||||
{"knownhosts", ARG_FILE, ' ', C_KNOWNHOSTS},
|
||||
{"krb", ARG_STRG|ARG_DEPR, ' ', C_KRB},
|
||||
{"krb4", ARG_STRG|ARG_DEPR, ' ', C_KRB4},
|
||||
{"libcurl", ARG_STRG, ' ', C_LIBCURL},
|
||||
|
|
@ -2224,6 +2225,9 @@ static ParameterError opt_file(struct OperationConfig *config,
|
|||
case C_KEY: /* --key */
|
||||
err = getstr(&config->key, nextarg, DENY_BLANK);
|
||||
break;
|
||||
case C_KNOWNHOSTS: /* --knownhosts */
|
||||
err = getstr(&config->knownhosts, nextarg, DENY_BLANK);
|
||||
break;
|
||||
case C_NETRC_FILE: /* --netrc-file */
|
||||
err = getstr(&config->netrc_file, nextarg, DENY_BLANK);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ typedef enum {
|
|||
C_KEEPALIVE_TIME,
|
||||
C_KEY,
|
||||
C_KEY_TYPE,
|
||||
C_KNOWNHOSTS,
|
||||
C_KRB,
|
||||
C_KRB4,
|
||||
C_LIBCURL,
|
||||
|
|
|
|||
|
|
@ -341,6 +341,9 @@ const struct helptxt helptext[] = {
|
|||
{" --key-type <type>",
|
||||
"Private key file type (DER/PEM/ENG)",
|
||||
CURLHELP_TLS},
|
||||
{" --knownhosts <file>",
|
||||
"Specify knownhosts path",
|
||||
CURLHELP_SSH},
|
||||
{" --krb <level>",
|
||||
"Enable Kerberos with security <level>",
|
||||
CURLHELP_DEPRECATED},
|
||||
|
|
|
|||
|
|
@ -2273,7 +2273,6 @@ CURLcode operate(int argc, argv_item_t argv[])
|
|||
}
|
||||
|
||||
varcleanup();
|
||||
curl_free(global->knownhosts);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue