Skip to content

Commit

Permalink
fix: Restore user args to keepassxc-cli in cache password mode
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 12, 2024
1 parent 9437b62 commit 85464dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion internal/cmd/keepassxctemplatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ func (c *Config) keepassxcOutput(command string, args ...string) ([]byte, error)
// keepassxcOutputCachePassword returns the output of command and args,
// prompting the user for the password and caching it for later use.
func (c *Config) keepassxcOutputCachePassword(command string, args ...string) ([]byte, error) {
cmdArgs := append([]string{command, c.Keepassxc.Database.String()}, args...)
cmdArgs := []string{command}
cmdArgs = append(cmdArgs, c.Keepassxc.Args...)
cmdArgs = append(cmdArgs, c.Keepassxc.Database.String())
cmdArgs = append(cmdArgs, args...)
cmd := exec.Command(c.Keepassxc.Command, cmdArgs...) //nolint:gosec
if c.Keepassxc.password == "" && c.Keepassxc.Prompt {
password, err := c.readPassword(fmt.Sprintf("Enter password to unlock %s: ", c.Keepassxc.Database))
Expand Down
13 changes: 7 additions & 6 deletions internal/cmd/testdata/scripts/keepassxc.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ case "$*" in
"--version")
echo "2.7.0"
;;
"attachment-export /secrets.kdbx --quiet --stdout example.com attachment")
"attachment-export --key-file /secrets.key /secrets.kdbx --quiet --stdout example.com attachment")
echo "# contents of attachment"
;;
"show /secrets.kdbx --quiet --show-protected example.com")
"show --key-file /secrets.key /secrets.kdbx --quiet --show-protected example.com")
cat <<EOF
Title: example.com
UserName: examplelogin
Expand All @@ -35,7 +35,7 @@ URL:
Notes:
EOF
;;
"show /secrets.kdbx example.com --attributes host-name --quiet --show-protected")
"show --key-file /secrets.key /secrets.kdbx example.com --attributes host-name --quiet --show-protected")
echo "example.com"
;;
*)
Expand All @@ -46,22 +46,23 @@ esac
@echo off
IF "%*" == "--version" (
echo 2.7.0
) ELSE IF "%*" == "attachment-export C:/secrets.kdbx --quiet --stdout example.com attachment" (
) ELSE IF "%*" == "attachment-export --key-file /secrets.key C:/secrets.kdbx --quiet --stdout example.com attachment" (
echo.# contents of attachment
) ELSE IF "%*" == "show C:/secrets.kdbx --quiet --show-protected example.com" (
) ELSE IF "%*" == "show --key-file /secrets.key C:/secrets.kdbx --quiet --show-protected example.com" (
echo.Title: example.com
echo.UserName: examplelogin
echo.Password: examplepassword
echo.URL:
echo.Notes:
) ELSE IF "%*" == "show C:/secrets.kdbx example.com --attributes host-name --quiet --show-protected" (
) ELSE IF "%*" == "show --key-file /secrets.key C:/secrets.kdbx example.com --attributes host-name --quiet --show-protected" (
echo.example.com
) ELSE (
echo keepass-test: invalid command: %*
exit /b 1
)
-- home/user/.config/chezmoi/chezmoi.toml --
[keepassxc]
args = ["--key-file", "/secrets.key"]
database = "/secrets.kdbx"
-- home/user/input --
fakepassword

0 comments on commit 85464dd

Please sign in to comment.