[PATCH] add new dump command

Dusty Mabe dusty at dustymabe.com
Sat Feb 4 19:50:49 CET 2017



On 02/04/2017 01:09 PM, David A. wrote:
> On Sat,  4 Feb 2017 12:15:12 -0500, Dusty Mabe <dusty at dustymabe.com>
> wrote:
> 
>> This dump command will decrypt all passwords and print them.
> 
> ...
> 
>> +cmd_dump() {
>> +	pushd $PREFIX > /dev/null
>> +	find ./* -name *gpg | while read file; do
>> +		echo "[$file]" | sed 's/\.\///' | sed 's/\.gpg//'
>> +		$GPG ${GPG_OPTS[@]} -d $file
>> +		echo -en "\n\n"
>> +	done
>> +	popd > /dev/null
>> +}
> 
> I think this is very easily accomplished with a simple external script
> today.

Agree. I've been using an external alias in my bashrc for this. I
figured I'd try to contribute the functionality back upstream. The 
alias I've been using is:

alias passdump='find $PASSWORD_STORE_DIR -name *gpg | xargs -I{} bash -c "ls {} && gpg2 --decrypt {} && echo && echo"'

> However, I'll give you some feedback on your patch because I
> see several problems with it that would prevent acceptance.

Thanks

> 
> First, you should declare your variables as local.  So add 'local
> file' to the top.  As a matter of consistency it appears the pass
> script prefers to use 'passfile' instead of 'file'.

+1 

> 
> I have two problems and a suggestion for your find command:
> 
> I suggest 'find *' instead of 'find ./*' so you can eliminate the
> first sed.

+1

> 
> You should limit the find with '-type f'.  There could be directories
> that end in 'gpg'.

+1 
> 
> You need to quote the name filter.  If there are any entries in the
> root of the password store then your find will fail.  So change *gpg
> (unquoted) to '*gpg' (with quotes) and I would add the dot for
> accuracy so '*.gpg' is the way to go.

+1 

> 
> Since pass is written in bash you can eliminate both sed statements.
> It's faster to do string substitution in the shell than to spawn two
> processes.  Since we've already eliminated the first sed by changing
> find there's only one substitution to make so we can do it right on
> the echo command.  Change:
>    echo "[$file]" | sed ...
> to:
>    echo "[${file%.gpg}]"

+1

> 
> On the gpg command you need to add double quotes around ${GPG_OPTS[@]}
> and around $file.

+1
> 
> As a matter of style, why use this:
>    echo -en "\n\n"
> rather than this:
>    echo -e "\n"
> ?
> 

Changed.. I also added the docs that I forgot in the first submission.


More information about the Password-Store mailing list