From 1da6145352f403a880890266ca79b57c992cb0dc Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Fri, 5 Jul 2019 23:11:24 -0400 Subject: Give useful error when kiki init is non-root. --- kiki.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kiki.hs b/kiki.hs index 11f9fb4..bca3ca5 100644 --- a/kiki.hs +++ b/kiki.hs @@ -53,6 +53,7 @@ import qualified Data.Map as Map import Control.Arrow (first,second) import Data.Monoid ( (<>) ) import Data.Binary.Put +import System.Posix.User import CommandLine import Data.OpenPGP.Util (verify, fingerprint, GenerateKeyParams(..)) @@ -1335,6 +1336,8 @@ kiki "merge" [] = do , " don't write)." , "" , " --create=(rsa:SIZE|cmd:CMD)" + , " Note: With --flow=spill, a dummy file name must still be" + , " provided so that the command line can be parsed." , "" , " --autosign[=no]" , "" @@ -1557,7 +1560,16 @@ kiki "init" args | "--help" `elem` args = do , "" ] ++ documentHomeDir ++ [""] ++ documentPassphraseFDFlag True True True -kiki "init" args = run args $ importAndRefresh <$> dashdashChroot <*> dashdashHomedir <*> dashdashCipher +kiki "init" args = do + rootOK <- case runArgs ([],args) dashdashChroot of + Left e -> hPutStrLn stderr (usageErrorMessage e) >> return False + Right root -> if root "x" /= root "x" + then return True + else fmap (==0) $ getEffectiveUserID + if rootOK + then run args $ importAndRefresh <$> dashdashChroot <*> dashdashHomedir <*> dashdashCipher + else do hPutStrLn stderr "Missing --chroot option. Permision denied." + exitFailure kiki "spawn" args | "--help" `elem` args = putStr . unlines $ [ "kiki spawn [ --passphrase-fd=FD" -- cgit v1.2.3