webapp: Escape unusual characters in ssh hostnames when generating mangled hostnames. This allows IPv6 addresses to be used on filesystems not supporting : in filenames.

This commit is contained in:
Joey Hess 2016-07-19 11:37:03 -04:00
parent 242868eadb
commit 50e63f75d1
Failed to extract signature
3 changed files with 34 additions and 8 deletions

View file

@ -341,15 +341,31 @@ setSshConfig sshdata config = do
{- This hostname is specific to a given repository on the ssh host, {- This hostname is specific to a given repository on the ssh host,
- so it is based on the real hostname, the username, and the directory. - so it is based on the real hostname, the username, and the directory.
- -
- The mangled hostname has the form "git-annex-realhostname-username-port_dir". - The mangled hostname has the form:
- The only use of "-" is to separate the parts shown; this is necessary - "git-annex-realhostname-username_port_dir"
- to allow unMangleSshHostName to work. Any unusual characters in the - Note that "-" is only used in the realhostname and as a separator;
- username or directory are url encoded, except using "." rather than "%" - this is necessary to allow unMangleSshHostName to work.
-
- Unusual characters are url encoded, but using "." rather than "%"
- (the latter has special meaning to ssh). - (the latter has special meaning to ssh).
-
- In the username and directory, unusual characters are any
- non-alphanumerics, other than "_"
-
- The real hostname is not normally encoded at all. This is done for
- backwards compatability and to avoid unnecessary ugliness in the
- filename. However, when it contains special characters
- (notably ":" which cannot be used on some filesystems), it is url
- encoded. To indicate it was encoded, the mangled hostname
- has the form
- "git-annex-.encodedhostname-username_port_dir"
-} -}
mangleSshHostName :: SshData -> String mangleSshHostName :: SshData -> String
mangleSshHostName sshdata = "git-annex-" ++ T.unpack (sshHostName sshdata) mangleSshHostName sshdata = intercalate "-"
++ "-" ++ escape extra [ "git-annex"
, escapehostname (T.unpack (sshHostName sshdata))
, escape extra
]
where where
extra = intercalate "_" $ map T.unpack $ catMaybes extra = intercalate "_" $ map T.unpack $ catMaybes
[ sshUserName sshdata [ sshUserName sshdata
@ -361,12 +377,18 @@ mangleSshHostName sshdata = "git-annex-" ++ T.unpack (sshHostName sshdata)
| c == '_' = True | c == '_' = True
| otherwise = False | otherwise = False
escape s = replace "%" "." $ escapeURIString safe s escape s = replace "%" "." $ escapeURIString safe s
escapehostname s
| all (\c -> c == '.' || safe c) s = s
| otherwise = '.' : escape s
{- Extracts the real hostname from a mangled ssh hostname. -} {- Extracts the real hostname from a mangled ssh hostname. -}
unMangleSshHostName :: String -> String unMangleSshHostName :: String -> String
unMangleSshHostName h = case split "-" h of unMangleSshHostName h = case split "-" h of
("git":"annex":rest) -> intercalate "-" (beginning rest) ("git":"annex":rest) -> unescape (intercalate "-" (beginning rest))
_ -> h _ -> h
where
unescape ('.':s) = unEscapeString (replace "." "%" s)
unescape s = s
{- Does ssh have known_hosts data for a hostname? -} {- Does ssh have known_hosts data for a hostname? -}
knownHost :: Text -> IO Bool knownHost :: Text -> IO Bool

View file

@ -25,6 +25,9 @@ git-annex (6.20160614) UNRELEASED; urgency=medium
* Support checking presence of content at a http url that redirects to * Support checking presence of content at a http url that redirects to
a ftp url. a ftp url.
* log: Added --all option. * log: Added --all option.
* webapp: Escape unusual characters in ssh hostnames when generating
mangled hostnames. This allows IPv6 addresses to be used on filesystems
not supporting : in filenames.
-- Joey Hess <id@joeyh.name> Mon, 13 Jun 2016 21:52:24 -0400 -- Joey Hess <id@joeyh.name> Mon, 13 Jun 2016 21:52:24 -0400

View file

@ -60,4 +60,5 @@ The key's randomart image is:
Yeah, it works great on my Linux machines. I'm just getting started with the web app, though; I'm trying to set up limited-access key-based SSH, and the web app seems to be also trying to do that... Yeah, it works great on my Linux machines. I'm just getting started with the web app, though; I'm trying to set up limited-access key-based SSH, and the web app seems to be also trying to do that...
> Fixed by escaping the hostname when it contains any unusual characters.
> [[done]] --[[Joey]]