about summary refs log tree commit diff stats
path: root/adapter/protocol
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-26 19:08:39 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-26 19:09:54 +0200
commit3554f4c3241664d794d656240ccfa43cd99d84df (patch)
tree83f5dd3b594153928fdfeec15ba54b3d9ef66dcf /adapter/protocol
parentc1bcb8a4d833d035eb199546aabc44dbe10252c6 (diff)
downloadchawan-3554f4c3241664d794d656240ccfa43cd99d84df.tar.gz
ftp: support multiple arguments in ssh config Host
Diffstat (limited to 'adapter/protocol')
-rw-r--r--adapter/protocol/ftp.nim44
1 files changed, 31 insertions, 13 deletions
diff --git a/adapter/protocol/ftp.nim b/adapter/protocol/ftp.nim
index 09ad4cd3..ee571130 100644
--- a/adapter/protocol/ftp.nim
+++ b/adapter/protocol/ftp.nim
@@ -168,6 +168,12 @@ proc matchesPattern(s, pat: openArray[char]): bool =
     inc i
   return true
 
+proc matchesPattern(s: string; pats: openArray[string]): bool =
+  for pat in pats:
+    if s.matchesPattern(pat):
+      return true
+  return false
+
 proc parseSSHConfig(f: File; curl: CURL; host: string; idSet: var bool) =
   var skipTillNext = false
   var line: string
@@ -183,28 +189,40 @@ proc parseSSHConfig(f: File; curl: CURL; host: string; idSet: var bool) =
       i = line.skipBlanks(i + 1)
     if i == line.len or line[i] == '#':
       continue
-    var arg = ""
-    let isStr = line[i] in {'"', '\''}
-    if isStr:
-      inc i
-    var quot = false
-    while i < line.len and (quot or line[i] != '"' or not isStr):
-      if not quot and line[i] == '\\':
-        quot = true
-      else:
+    var args = newSeq[string]()
+    while i < line.len:
+      let isStr = line[i] in {'"', '\''}
+      if isStr:
+        inc i
+      var quot = false
+      var arg = ""
+      while i < line.len:
+        if not quot:
+          if line[i] == '\\':
+            quot = true
+            continue
+          elif line[i] == '"' and isStr or line[i] == ' ' and not isStr:
+            inc i
+            break
         quot = false
         arg &= line[i]
-      inc i
+        inc i
+      if arg.len > 0:
+        args.add(arg)
     if k == "Match": #TODO support this
       skipTillNext = true
     elif k == "Host":
-      skipTillNext = not host.matchesPattern(arg)
+      skipTillNext = not host.matchesPattern(args)
     elif skipTillNext:
       continue
     elif k == "IdentityFile":
-      identityFile = expandTilde(arg)
+      if args.len != 1:
+        continue # error
+      identityFile = expandTilde(args[0])
     elif k == "CertificateFile":
-      certificateFile = expandTilde(arg)
+      if args.len != 1:
+        continue # error
+      certificateFile = expandTilde(args[0])
   if identityFile != "":
     curl.setopt(CURLOPT_SSH_PRIVATE_KEYFILE, identityFile)
     idSet = true