LibSSH is a little too smart and eager, which can result in highly unexpected behavior. By default, it goes ahead and follows any instructions in the default OpenSSH configuration file, ~/.ssh/config.
Consider, for example, ~/.ssh/config containing this directive:
UserKnownHostsFile ~/Desktop/whatever
Now you can try all you want to override the known hosts file location in libcurl, it will be summarily ignored:
curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS, "im-just-gonna-ignore-this");
I posit this is rather unwelcome, unexpected behavior for the common libcurl developer, bound to cause much head-scratching as to what is going on. On the other hand, I feel reading the OpenSSH configuration files is a welcome feature for people using the command-line curl tool.
As such, I'm not entirely sure of the right solution here.
I have modified my lib/vssh/libssh.c like this:
if(data->set.str[STRING_SSH_KNOWNHOSTS]) {
+ bool bval = 0;
+ ssh_options_set(ssh->ssh_session, SSH_OPTIONS_PROCESS_CONFIG, &bval);
infof(data, "Known hosts: %s\n", data->set.str[STRING_SSH_KNOWNHOSTS]);
ssh_options_set(ssh->ssh_session, SSH_OPTIONS_KNOWNHOSTS,
data->set.str[STRING_SSH_KNOWNHOSTS]);
}
And that gives me back ultimate control over the known hosts location, making this libcurl developer happy, while also not entirely throwing away the OpenSSH config parsing feature in all use cases.
Still, if even this much is considered too drastic, I'd recommend adding a notice to the documentation page, something along the lines of: “When curl is built with libssh, this option will be entirely ignored if overridden by a UserKnownHostsFile directive in ~/.ssh/config“
None of these strange surprises of course if curl is compiled with libssh2 instead.
LibSSH is a little too smart and eager, which can result in highly unexpected behavior. By default, it goes ahead and follows any instructions in the default OpenSSH configuration file,
~/.ssh/config.Consider, for example,
~/.ssh/configcontaining this directive:Now you can try all you want to override the known hosts file location in libcurl, it will be summarily ignored:
I posit this is rather unwelcome, unexpected behavior for the common libcurl developer, bound to cause much head-scratching as to what is going on. On the other hand, I feel reading the OpenSSH configuration files is a welcome feature for people using the command-line curl tool.
As such, I'm not entirely sure of the right solution here.
I have modified my lib/vssh/libssh.c like this:
And that gives me back ultimate control over the known hosts location, making this libcurl developer happy, while also not entirely throwing away the OpenSSH config parsing feature in all use cases.
Still, if even this much is considered too drastic, I'd recommend adding a notice to the documentation page, something along the lines of: “When curl is built with libssh, this option will be entirely ignored if overridden by a UserKnownHostsFile directive in ~/.ssh/config“
None of these strange surprises of course if curl is compiled with libssh2 instead.