]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl/config2setopts: move SSH related options into same block
authorDaniel Stenberg <daniel@haxx.se>
Tue, 29 Oct 2024 09:15:53 +0000 (10:15 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 29 Oct 2024 10:05:22 +0000 (11:05 +0100)
Move the code setting SSH specific libcurl options into the same block
to avoid having a separate almost identical condition later.

Closes #15444

src/tool_operate.c

index 65485c8968c4eaedc7a83c7949a191e8a530a6c5..a1212c9dded073aaac9ec400b05964cfe1f4649a 100644 (file)
@@ -1169,6 +1169,22 @@ static CURLcode config2setopts(struct GlobalConfig *global,
     /* new in libcurl 7.56.0 */
     if(config->ssh_compression)
       my_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L);
+
+    if(!config->insecure_ok) {
+      char *known = findfile(".ssh/known_hosts", FALSE);
+      if(known) {
+        /* new in curl 7.19.6 */
+        result = res_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known);
+        curl_free(known);
+        if(result == CURLE_UNKNOWN_OPTION)
+          /* libssh2 version older than 1.1.1 */
+          result = CURLE_OK;
+        if(result)
+          return result;
+      }
+      else
+        warnf(global, "Couldn't find a known_hosts file");
+    }
   }
 
   if(config->cacert)
@@ -1344,23 +1360,6 @@ static CURLcode config2setopts(struct GlobalConfig *global,
   if(config->path_as_is)
     my_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
 
-  if((use_proto == proto_scp || use_proto == proto_sftp) &&
-     !config->insecure_ok) {
-    char *known = findfile(".ssh/known_hosts", FALSE);
-    if(known) {
-      /* new in curl 7.19.6 */
-      result = res_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known);
-      curl_free(known);
-      if(result == CURLE_UNKNOWN_OPTION)
-        /* libssh2 version older than 1.1.1 */
-        result = CURLE_OK;
-      if(result)
-        return result;
-    }
-    else
-      warnf(global, "Couldn't find a known_hosts file");
-  }
-
   if(config->no_body || config->remote_time) {
     /* no body or use remote time */
     my_setopt(curl, CURLOPT_FILETIME, 1L);