From b3c795dc4784e64e2756d3736ce953a1e507f509 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Jan 2018 15:13:35 -0400 Subject: Run su with --login To avoid inheriting some problematic environment variables, such as TMP, from the caller. The only potential breakage from this change would be if something used setEnv before one of the affected properties. Audited propellor's source for that, and nothing does. Anything that did would could fail in a concurrent context anyway. --- src/Propellor/Property/Cmd.hs | 3 ++- src/Propellor/Property/Gpg.hs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/Property/Cmd.hs b/src/Propellor/Property/Cmd.hs index f2de1a27..fbe112cc 100644 --- a/src/Propellor/Property/Cmd.hs +++ b/src/Propellor/Property/Cmd.hs @@ -94,6 +94,7 @@ scriptProperty script = cmdProperty "sh" ["-c", shellcmd] -- | A property that can satisfied by running a script -- as user (cd'd to their home directory). userScriptProperty :: User -> Script -> UncheckedProperty UnixLike -userScriptProperty (User user) script = cmdProperty "su" ["--shell", "/bin/sh", "-c", shellcmd, user] +userScriptProperty (User user) script = cmdProperty "su" + ["--login", "--shell", "/bin/sh", "-c", shellcmd, user] where shellcmd = intercalate " ; " ("set -e" : "cd" : script) diff --git a/src/Propellor/Property/Gpg.hs b/src/Propellor/Property/Gpg.hs index 27baa4ba..ac057b2e 100644 --- a/src/Propellor/Property/Gpg.hs +++ b/src/Propellor/Property/Gpg.hs @@ -33,7 +33,7 @@ keyImported key@(GpgKeyId keyid) user@(User u) = prop ifM (liftIO $ hasGpgKey (parse keylines)) ( return NoChange , makeChange $ withHandle StdinHandle createProcessSuccess - (proc "su" ["-c", "gpg --import", u]) $ \h -> do + (proc "su" ["--login", "-c", "gpg --import", u]) $ \h -> do hPutStr h (unlines keylines) hClose h ) @@ -49,11 +49,11 @@ keyImported key@(GpgKeyId keyid) user@(User u) = prop hasPrivKey :: GpgKeyId -> User -> IO Bool hasPrivKey (GpgKeyId keyid) (User u) = catchBoolIO $ - snd <$> processTranscript "su" ["-c", "gpg --list-secret-keys " ++ shellEscape keyid, u] Nothing + snd <$> processTranscript "su" ["--login", "-c", "gpg --list-secret-keys " ++ shellEscape keyid, u] Nothing hasPubKey :: GpgKeyId -> User -> IO Bool hasPubKey (GpgKeyId keyid) (User u) = catchBoolIO $ - snd <$> processTranscript "su" ["-c", "gpg --list-public-keys " ++ shellEscape keyid, u] Nothing + snd <$> processTranscript "su" ["--login", "-c", "gpg --list-public-keys " ++ shellEscape keyid, u] Nothing dotDir :: User -> IO FilePath dotDir (User u) = do -- cgit v1.2.3