summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Infra/UseIO.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-03-03 15:42:57 +0000
committerhallgren <hallgren@chalmers.se>2011-03-03 15:42:57 +0000
commit2c1feccd1736c5535251bc5a7f484b5f2c35b9fc (patch)
tree713b711c03fc573dc35e5e7671658a0179adcd19 /src/compiler/GF/Infra/UseIO.hs
parentb190d30fad3dba5ff63c4bdeeb089916b9c1e66f (diff)
GF shell restricted mode
By setting the environment variable GF_RESTRICTED before starting GF, the shell will be run in restricted mode. This will prevent the GF shell from starting arbitrary system commands (most uses of System.Cmd.system are blocked) and writing arbitrary files (most commands that use writeFile et al are blocked). Restricted mode is intended minimize the potential security risks involved in allowing public access to the GF shell over the internet. It should be used in conjuction with system level protection mechanisms (e.g. file permissions) to make sure that a publicly acessible GF shell does not give access to parts of the system that should not be publicly accessible.
Diffstat (limited to 'src/compiler/GF/Infra/UseIO.hs')
-rw-r--r--src/compiler/GF/Infra/UseIO.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/compiler/GF/Infra/UseIO.hs b/src/compiler/GF/Infra/UseIO.hs
index 3940e6be1..72875f70d 100644
--- a/src/compiler/GF/Infra/UseIO.hs
+++ b/src/compiler/GF/Infra/UseIO.hs
@@ -26,6 +26,7 @@ import System.IO.Error
import System.Environment
import System.Exit
import System.CPUTime
+import System.Cmd
import Text.Printf
import Control.Monad
import Control.Exception(evaluate)
@@ -191,3 +192,19 @@ writeUTF8File fpath content = do
hSetEncoding h utf8
hPutStr h content
hClose h
+
+-- * Functions to limit acesss to arbitrary IO and system commands
+restricted io =
+ either (const io) (const $ fail message) =<< try (getEnv "GF_RESTRICTED")
+ where
+ message =
+ "This operation is not allowed when GF is running in restricted mode."
+
+restrictedSystem = restricted . system
+
+
+-- Because GHC adds the confusing text "user error" for failures cased by
+-- calls to fail.
+ioErrorText e = if isUserError e
+ then ioeGetErrorString e
+ else show e