aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/accounts.go24
-rw-r--r--main.go5
2 files changed, 28 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))
}
diff --git a/main.go b/main.go
index efdbf653..66c2ed1a 100644
--- a/main.go
+++ b/main.go
@@ -21,6 +21,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/hooks"
"git.sr.ht/~rjarry/aerc/lib/ipc"
"git.sr.ht/~rjarry/aerc/lib/log"
+ "git.sr.ht/~rjarry/aerc/lib/pinentry"
"git.sr.ht/~rjarry/aerc/lib/templates"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
@@ -221,6 +222,10 @@ func main() {
}
close(deferLoop)
+ config.EnablePinentry = pinentry.Enable
+ config.DisablePinentry = pinentry.Disable
+ config.SetPinentryEnv = pinentry.SetCmdEnv
+
startup, startupDone := context.WithCancel(context.Background())
if !noIPC {