lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 6ad2e077b3b9b6b7176911f7ec36c469bba753fb
parent bbf8752038cd3ee1cb34cf3c06b06f159e4c7640
Author: Sean Enck <sean@ttypty.com>
Date:   Fri, 15 Jul 2022 19:04:18 -0400

fixing totp calling back into lb

Diffstat:
MMakefile | 5+++--
Mcmd/lb-totp/main.go | 10+++++++++-
Mcmd/lb/main.go | 12++++++++++--
Minternal/clip.go | 2+-
4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,11 +3,12 @@ DESTDIR := BUILD := bin/ TARGETS := $(BUILD)lb $(BUILD)lb-rw $(BUILD)lb-bash $(BUILD)lb-rekey $(BUILD)lb-textconv $(BUILD)lb-totp LIBEXEC := $(DESTDIR)libexec/lockbox/ +MAIN := $(DESTDIR)bin/lb all: $(TARGETS) $(TARGETS): cmd/$@/* internal/* go.* - go build -ldflags '-X main.version=$(VERSION) -X main.libExec=$(LIBEXEC)' -trimpath -buildmode=pie -mod=readonly -modcacherw -o $@ cmd/$(shell basename $@)/main.go + go build -ldflags '-X main.version=$(VERSION) -X main.libExec=$(LIBEXEC) -X main.mainExe=$(MAIN)' -trimpath -buildmode=pie -mod=readonly -modcacherw -o $@ cmd/$(shell basename $@)/main.go check: $(TARGETS) cd tests && make BUILD=../$(BUILD) @@ -16,6 +17,6 @@ clean: rm -rf $(BUILD) install: - install -Dm755 $(BUILD)lb $(DESTDIR)bin/lb + install -Dm755 $(BUILD)lb $(MAIN) install -Dm755 -d $(LIBEXEC) install -Dm755 $(BUILD)lb-* $(LIBEXEC) diff --git a/cmd/lb-totp/main.go b/cmd/lb-totp/main.go @@ -14,6 +14,10 @@ import ( otp "github.com/pquerna/otp/totp" ) +var ( + mainExe = "" +) + func list() ([]string, error) { files := []string{} token := totpToken() @@ -91,6 +95,10 @@ func display(token string, args internal.Arguments) error { if err != nil { return err } + exe := os.Getenv("LOCKBOX_EXE") + if exe == "" { + exe = mainExe + } totpToken := string(val) if !interactive { code, err := otp.GenerateCode(totpToken, time.Now()) @@ -148,7 +156,7 @@ func display(token string, args internal.Arguments) error { } } else { fmt.Printf("-> %s\n", expires) - internal.CopyToClipboard(code) + internal.CopyToClipboard(code, exe) return nil } if !args.Once { diff --git a/cmd/lb/main.go b/cmd/lb/main.go @@ -37,6 +37,14 @@ func getEntry(store string, args []string, idx int) string { return filepath.Join(store, args[idx]) + internal.Extension } +func getExecutable() string { + exe, err := os.Executable() + if err != nil { + internal.Die("unable to get exe", err) + } + return exe +} + func main() { args := os.Args if len(args) < 2 { @@ -212,7 +220,7 @@ func main() { } continue } - internal.CopyToClipboard(value) + internal.CopyToClipboard(value, getExecutable()) } if isDump { if !options.Yes { @@ -261,7 +269,7 @@ func main() { return } } - internal.CopyToClipboard("") + internal.CopyToClipboard("", getExecutable()) default: lib := os.Getenv("LOCKBOX_LIBEXEC") if lib == "" { diff --git a/internal/clip.go b/internal/clip.go @@ -63,7 +63,7 @@ func GetClipboardCommand() ([]string, []string, error) { } // CopyToClipboard will copy to clipboard, if non-empty will clear later. -func CopyToClipboard(value string) { +func CopyToClipboard(value, executable string) { cp, _, err := GetClipboardCommand() if err != nil { fmt.Printf("unable to copy to clipboard: %v\n", err)