Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Restore user args to keepassxc-cli in cache password mode #3476

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Restore user args to keepassxc-cli in cache password mode
  • Loading branch information
twpayne committed Jan 12, 2024
commit 0221436fdfd1e2ce0777b3bd7abc4d7996595479
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