diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-08-06 22:37:30 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-10-12 00:12:49 +0200 |
commit | 835493b0bb86b66e8dd12f5bf2dd9d785e7f152f (patch) | |
tree | 3be6daddeb6e3063c9c02a950890893f96114c11 /config | |
parent | 4b25d04509371664883e344aaa9fbf2f403529f3 (diff) | |
download | aerc-835493b0bb86b66e8dd12f5bf2dd9d785e7f152f.tar.gz |
config: add pinentry support to cred commands
Add pinentry support for the source-cred-cmd and outgoing-cred-cmd. Do a
little dance around an unallowed import cycle.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config')
-rw-r--r-- | config/accounts.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/config/accounts.go b/config/accounts.go index 5bbae39f..35046f67 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -1,6 +1,7 @@ package config import ( + "bytes" "errors" "fmt" "net/url" @@ -18,6 +19,12 @@ import ( "github.com/go-ini/ini" ) +var ( + EnablePinentry func() + DisablePinentry func() + SetPinentryEnv func(*exec.Cmd) +) + type RemoteConfig struct { Value string PasswordCmd string @@ -52,11 +59,26 @@ func (c *RemoteConfig) ConnectionString() (string, error) { pw := c.cache if pw == "" { + usePinentry := EnablePinentry != nil && + DisablePinentry != nil && + SetPinentryEnv != nil + cmd := exec.Command("sh", "-c", c.PasswordCmd) cmd.Stdin = os.Stdin + + buf := new(bytes.Buffer) + cmd.Stderr = buf + + if usePinentry { + EnablePinentry() + defer DisablePinentry() + SetPinentryEnv(cmd) + } + output, err := cmd.Output() if err != nil { - return "", fmt.Errorf("failed to read password: %w", err) + return "", fmt.Errorf("failed to read password: %v: %w", + buf.String(), err) } pw = strings.TrimSpace(string(output)) } |