diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-02 07:08:34 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-02 07:08:34 -0400 |
commit | ec18ca2c86786ff1eb26527a8f53bad3dda50b53 (patch) | |
tree | ec9b4968d418698e1aa89f614349467650b0f549 /lib/GnuPGAgent.hs | |
parent | 4e87e15398728286efeacdb54d3feba6070ed1b1 (diff) |
Find agent-socket in new location.
Diffstat (limited to 'lib/GnuPGAgent.hs')
-rw-r--r-- | lib/GnuPGAgent.hs | 17 |
1 files changed, 16 insertions, 1 deletions
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 | |||
14 | import Debug.Trace | 14 | import Debug.Trace |
15 | import Control.Monad | 15 | import Control.Monad |
16 | import ControlMaybe | 16 | import ControlMaybe |
17 | import Data.Bool | ||
17 | import Data.Char | 18 | import Data.Char |
18 | import Data.Maybe | 19 | import Data.Maybe |
19 | import Data.OpenPGP | 20 | import Data.OpenPGP |
@@ -21,6 +22,7 @@ import Data.OpenPGP.Util | |||
21 | import Data.Word | 22 | import Data.Word |
22 | import Network.Socket | 23 | import Network.Socket |
23 | import System.Directory | 24 | import System.Directory |
25 | import System.Posix.User | ||
24 | import System.Environment | 26 | import System.Environment |
25 | import System.IO | 27 | import System.IO |
26 | import Text.Printf | 28 | import Text.Printf |
@@ -92,6 +94,18 @@ putenv (GnuPGAgent agent) env = do | |||
92 | _ <- hGetLine agent | 94 | _ <- hGetLine agent |
93 | return () | 95 | return () |
94 | 96 | ||
97 | findAgentSocket :: FilePath -> IO FilePath | ||
98 | findAgentSocket gpghome = foldr ($) (return "./S.gpg-agent") | ||
99 | [ \nope -> do | ||
100 | uid <- show <$> getRealUserID | ||
101 | let f = "/run/user/"++uid++"/gnupg/S.gpg-agent" | ||
102 | b <- doesFileExist f | ||
103 | if b then return f else nope | ||
104 | , \nope -> do | ||
105 | let f = gpghome ++ "/gnupg/S.gpg-agent" | ||
106 | doesFileExist f >>= bool nope (return f) | ||
107 | ] | ||
108 | |||
95 | session :: IO (Maybe GnuPGAgent) | 109 | session :: IO (Maybe GnuPGAgent) |
96 | session = do | 110 | session = do |
97 | envhomedir Nothing gpgHomeSpec >>= \case | 111 | envhomedir Nothing gpgHomeSpec >>= \case |
@@ -99,7 +113,8 @@ session = do | |||
99 | env <- getDisplay | 113 | env <- getDisplay |
100 | handleIO_ (launchAgent gpghome $ Just env) $ do | 114 | handleIO_ (launchAgent gpghome $ Just env) $ do |
101 | sock <- socket AF_UNIX Stream defaultProtocol | 115 | sock <- socket AF_UNIX Stream defaultProtocol |
102 | connect sock (SockAddrUnix (gpghome ++ "/S.gpg-agent")) | 116 | agentpath <- findAgentSocket gpghome |
117 | connect sock (SockAddrUnix agentpath) | ||
103 | agent <- socketToHandle sock ReadWriteMode | 118 | agent <- socketToHandle sock ReadWriteMode |
104 | hSetBuffering agent LineBuffering | 119 | hSetBuffering agent LineBuffering |
105 | putenv (GnuPGAgent agent) env | 120 | putenv (GnuPGAgent agent) env |