summaryrefslogtreecommitdiff
path: root/Utility/Rsync.hs
diff options
context:
space:
mode:
authorGravatar guilhem <guilhem@fripost.org>2013-03-29 01:34:07 +0100
committerGravatar Joey Hess <joey@kitenet.net>2013-03-30 18:49:43 -0400
commit27ab9830f16642b03ee97e7257d8973573a6d919 (patch)
tree9ff6abb1d871c73fee38d40d7a61c58a7ff1e109 /Utility/Rsync.hs
parent53bec08da77705b1a50585e741854453322573a9 (diff)
Make git-annex-shell call the command with its (safe) options.
Diffstat (limited to 'Utility/Rsync.hs')
-rw-r--r--Utility/Rsync.hs23
1 files changed, 18 insertions, 5 deletions
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) ""