~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH chathistorysync] askpass: accept passwords from stdin

Details
Message ID
<20220807110451.98307-1-umar@handlerug.me>
DKIM signature
missing
Download raw message
Patch: +12 -23
Also remove the dependency on golang.org/x/crypto/ssh/terminal.
---
 askpass.go | 26 ++++++++++++--------------
 go.mod     |  1 -
 go.sum     |  8 --------
 3 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/askpass.go b/askpass.go
index 40f0b3a..e9a1941 100644
--- a/askpass.go
+++ b/askpass.go
@@ -4,26 +4,24 @@ import (
	"fmt"
	"os"

	"golang.org/x/crypto/ssh/terminal"
	"golang.org/x/term"
)

func askPass(prompt string) (string, error) {
	f := os.Stdin
	fd := int(f.Fd())
	if !term.IsTerminal(fd) {
		// This can happen if stdin is used for piping data
		// TODO: the following assumes Unix
		var err error
		if f, err = os.Open("/dev/tty"); err != nil {
	if term.IsTerminal(int(os.Stdin.Fd())) {
		fmt.Printf("Password: ")
		password, err := term.ReadPassword(int(os.Stdin.Fd()))
		if err != nil {
			return "", err
		}
		defer f.Close()
		fmt.Printf("\n")
		return string(password), nil
	}
	fmt.Fprintf(os.Stderr, "%v: ", prompt)
	b, err := terminal.ReadPassword(fd)
	if err == nil {
		fmt.Fprintf(os.Stderr, "\n")

	var password string
	fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n")
	if _, err := fmt.Scanln(&password); err != nil {
		return "", err
	}
	return string(b), err
	return password, nil
}
diff --git a/go.mod b/go.mod
index d34b4db..51eb8b7 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,6 @@ module git.sr.ht/~emersion/chathistorysync
go 1.17

require (
	golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce
	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
	gopkg.in/irc.v3 v3.1.4
)
diff --git a/go.sum b/go.sum
index 278637b..04d1031 100644
--- a/go.sum
+++ b/go.sum
@@ -5,19 +5,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce h1:Roh6XWxHFKrPgC/EQhVubSAGQ6Ozk6IdxHSzt1mR0EI=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/irc.v3 v3.1.4 h1:DYGMRFbtseXEh+NadmMUFzMraqyuUj4I3iWYFEzDZPc=
gopkg.in/irc.v3 v3.1.4/go.mod h1:shO2gz8+PVeS+4E6GAny88Z0YVVQSxQghdrMVGQsR9s=
-- 
2.32.1 (Apple Git-133)

[chathistorysync/patches/.build.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CLZQXRDFE6SA.194QY7DAAPMP9@cirno>
In-Reply-To
<20220807110451.98307-1-umar@handlerug.me> (view parent)
DKIM signature
missing
Download raw message
chathistorysync/patches/.build.yml: SUCCESS in 33s

[askpass: accept passwords from stdin][0] from [Umar Getagazov][1]

[0]: https://lists.sr.ht/~emersion/public-inbox/patches/34509
[1]: umar@handlerug.me

✓ #818362 SUCCESS chathistorysync/patches/.build.yml https://builds.sr.ht/~emersion/job/818362
Details
Message ID
<J6EB9HCVJ3fNtjRhSCjkS8oUSf61pfwYy7ppf5Y3QyJLoaZDZeJ07wJIgW1uQaX-s4owIa8JqBtsHUCAfVqTeB9ZZrz6j0U7f7I6cJihwhg=@emersion.fr>
In-Reply-To
<20220807110451.98307-1-umar@handlerug.me> (view parent)
DKIM signature
missing
Download raw message
On Sunday, August 7th, 2022 at 13:04, Umar Getagazov <umar@handlerug.me> wrote:

> + if _, err := fmt.Scanln(&password); err != nil {

This doesn't work with passwords containing a space character.
Reply to thread Export thread (mbox)