summaryrefslogtreecommitdiff
path: root/Annex/Ssh.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-07-22 15:06:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-07-22 15:09:41 -0400
commit24a01209c9fc5b8da50813e861e392c09455b2c2 (patch)
tree4628844a0432547edc4886d7f4f98beca22d8b68 /Annex/Ssh.hs
parent92fb0e19d14213a37ab7cddf9a319a98d1f7da01 (diff)
For long hostnames, use a hash of the hostname to generate the socket file for ssh connection caching.
This is ok to do now that the socket filename never needs to be mapped back to a hostname. Short hostnames will still appear in the clear, which is less obfuscated. So this cannot possibly make ssh connection caching fail for a hostname it used to work for.
Diffstat (limited to 'Annex/Ssh.hs')
-rw-r--r--Annex/Ssh.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs
index 397fdb75c..182cc0298 100644
--- a/Annex/Ssh.hs
+++ b/Annex/Ssh.hs
@@ -15,6 +15,7 @@ module Annex.Ssh (
) where
import qualified Data.Map as M
+import Data.Hash.MD5
import Common.Annex
import Annex.LockPool
@@ -127,9 +128,17 @@ sshCleanup = go =<< sshCacheDir
-- Cannot remove the lock file; other processes may
-- be waiting on our exclusive lock to use it.
+{- This needs to be as short as possible, due to limitations on the length
+ - of the path to a socket file. At the same time, it needs to be unique
+ - for each host.
+ -}
hostport2socket :: String -> Maybe Integer -> FilePath
-hostport2socket host Nothing = host
-hostport2socket host (Just port) = host ++ "!" ++ show port
+hostport2socket host Nothing = hostport2socket' host
+hostport2socket host (Just port) = hostport2socket' $ host ++ "!" ++ show port
+hostport2socket' :: String -> FilePath
+hostport2socket' s
+ | length s > 32 = md5s (Str s)
+ | otherwise = s
socket2lock :: FilePath -> FilePath
socket2lock socket = socket ++ lockExt