fix directory checking to handle mangled directory names

relative, containing ~/ etc

Also, fix parsing of directory name parameter out of git-shell command.
This commit is contained in:
Joey Hess 2012-11-05 20:15:36 -04:00
parent e6581b4d9b
commit 3a40a54807

View file

@ -17,6 +17,7 @@ import Command
import Annex.UUID import Annex.UUID
import qualified Option import qualified Option
import Fields import Fields
import Utility.UserInfo
import qualified Command.ConfigList import qualified Command.ConfigList
import qualified Command.InAnnex import qualified Command.InAnnex
@ -96,7 +97,8 @@ external :: [String] -> IO ()
external params = do external params = do
{- Normal git-shell commands all have the directory as their last {- Normal git-shell commands all have the directory as their last
- parameter. -} - parameter. -}
checkDirectory $ lastMaybe params let lastparam = lastMaybe =<< shellUnEscape <$> lastMaybe params
checkDirectory lastparam
checkNotLimited checkNotLimited
unlessM (boolSystem "git-shell" $ map Param $ "-c":fst (partitionParams params)) $ unlessM (boolSystem "git-shell" $ map Param $ "-c":fst (partitionParams params)) $
error "git-shell failed" error "git-shell failed"
@ -140,12 +142,30 @@ checkDirectory mdir = do
v <- getEnv "GIT_ANNEX_SHELL_DIRECTORY" v <- getEnv "GIT_ANNEX_SHELL_DIRECTORY"
case (v, mdir) of case (v, mdir) of
(Nothing, _) -> noop (Nothing, _) -> noop
(Just d, Nothing) -> req d (Just d, Nothing) -> req d Nothing
(Just d, Just dir) (Just d, Just dir)
| d `equalFilePath` dir -> noop | d `equalFilePath` dir -> noop
| otherwise -> req d | otherwise -> do
home <- myHomeDir
d' <- canondir home d
dir' <- canondir home dir
if d' `equalFilePath` dir'
then noop
else req d' (Just dir')
where where
req d = error $ "Only allowed to access " ++ d req d mdir' = error $ unwords
[ "Only allowed to access"
, d
, maybe "and could not determine directory from command line" ("not " ++) mdir'
]
{- A directory may start with ~/ or in some cases, even /~/,
- or could just be relative to home, or of course could
- be absolute. -}
canondir home d
| "~/" `isPrefixOf` d = return d
| "/~/" `isPrefixOf` d = return $ drop 1 d
| otherwise = relHome $ absPathFrom home d
checkEnv :: String -> IO () checkEnv :: String -> IO ()
checkEnv var = do checkEnv var = do