From ec18ca2c86786ff1eb26527a8f53bad3dda50b53 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Tue, 2 Jul 2019 07:08:34 -0400 Subject: Find agent-socket in new location. --- lib/GnuPGAgent.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/GnuPGAgent.hs b/lib/GnuPGAgent.hs index 2a68b4e..1e40269 100644 --- a/lib/GnuPGAgent.hs +++ b/lib/GnuPGAgent.hs @@ -14,6 +14,7 @@ module GnuPGAgent import Debug.Trace import Control.Monad import ControlMaybe +import Data.Bool import Data.Char import Data.Maybe import Data.OpenPGP @@ -21,6 +22,7 @@ import Data.OpenPGP.Util import Data.Word import Network.Socket import System.Directory +import System.Posix.User import System.Environment import System.IO import Text.Printf @@ -92,6 +94,18 @@ putenv (GnuPGAgent agent) env = do _ <- hGetLine agent return () +findAgentSocket :: FilePath -> IO FilePath +findAgentSocket gpghome = foldr ($) (return "./S.gpg-agent") + [ \nope -> do + uid <- show <$> getRealUserID + let f = "/run/user/"++uid++"/gnupg/S.gpg-agent" + b <- doesFileExist f + if b then return f else nope + , \nope -> do + let f = gpghome ++ "/gnupg/S.gpg-agent" + doesFileExist f >>= bool nope (return f) + ] + session :: IO (Maybe GnuPGAgent) session = do envhomedir Nothing gpgHomeSpec >>= \case @@ -99,7 +113,8 @@ session = do env <- getDisplay handleIO_ (launchAgent gpghome $ Just env) $ do sock <- socket AF_UNIX Stream defaultProtocol - connect sock (SockAddrUnix (gpghome ++ "/S.gpg-agent")) + agentpath <- findAgentSocket gpghome + connect sock (SockAddrUnix agentpath) agent <- socketToHandle sock ReadWriteMode hSetBuffering agent LineBuffering putenv (GnuPGAgent agent) env -- cgit v1.2.3