From 27ab9830f16642b03ee97e7257d8973573a6d919 Mon Sep 17 00:00:00 2001 From: guilhem Date: Fri, 29 Mar 2013 01:34:07 +0100 Subject: Make git-annex-shell call the command with its (safe) options. --- Utility/Rsync.hs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'Utility') diff --git a/Utility/Rsync.hs b/Utility/Rsync.hs index afb3dcbc8..93c63c989 100644 --- a/Utility/Rsync.hs +++ b/Utility/Rsync.hs @@ -11,6 +11,7 @@ import Common import Utility.Metered import Data.Char +import System.Console.GetOpt {- Generates parameters to make rsync use a specified command as its remote - shell. -} @@ -23,13 +24,14 @@ rsyncShell command = [Param "-e", Param $ unwords $ map escape (toCommand comman escape s = "'" ++ join "''" (split "'" s) ++ "'" {- Runs rsync in server mode to send a file. -} -rsyncServerSend :: FilePath -> IO Bool -rsyncServerSend file = rsync $ - rsyncServerParams ++ [Param "--sender", File file] +rsyncServerSend :: [CommandParam] -> FilePath -> IO Bool +rsyncServerSend options file = rsync $ + rsyncServerParams ++ Param "--sender" : options ++ [File file] {- Runs rsync in server mode to receive a file. -} -rsyncServerReceive :: FilePath -> IO Bool -rsyncServerReceive file = rsync $ rsyncServerParams ++ [File file] +rsyncServerReceive :: [CommandParam] -> FilePath -> IO Bool +rsyncServerReceive options file = rsync $ + rsyncServerParams ++ options ++ [File file] rsyncServerParams :: [CommandParam] rsyncServerParams = @@ -127,3 +129,14 @@ parseRsyncProgress = go [] . reverse . progresschunks ([], _) -> Nothing (_, []) -> Nothing (b, _) -> readish b + +{- To prevent an evil client to run harmful options on the server, we + - cherry-pick those that are harmless. Them only are passed to rsync + - when executed through 'git-annex-shell'. + - Note: Ensure that when calling getopt, the first component of the + - outupt is a subset of the input. + -} +rsyncSafeOptions :: [OptDescr String] +rsyncSafeOptions = [ Option [] ["bwlimit"] (reqArgLong "bwlimit") "" ] + where + reqArgLong x = ReqArg (\v -> "--" ++ x ++ "=" ++ v) "" -- cgit v1.2.3