enh(passmanger/keepass): change library for keepass v4 (#2929)

This commit is contained in:
qgarnier 2021-07-02 10:16:44 +02:00 committed by GitHub
parent 37af2201a8
commit 6861109760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 19 deletions

View File

@ -24,7 +24,7 @@ use strict;
use warnings;
use JSON::Path;
use Data::Dumper;
use File::KeePass;
use KeePass::Reader;
use vars qw($keepass_connections);
@ -43,18 +43,18 @@ sub new {
}
$options{options}->add_options(arguments => {
"keepass-endpoint:s" => { name => 'keepass_endpoint' },
"keepass-endpoint-file:s" => { name => 'keepass_endpoint_file' },
"keepass-file:s" => { name => 'keepass_file' },
"keepass-password:s" => { name => 'keepass_password' },
"keepass-search-value:s@" => { name => 'keepass_search_value' },
"keepass-map-option:s@" => { name => 'keepass_map_option' },
'keepass-endpoint:s' => { name => 'keepass_endpoint' },
'keepass-endpoint-file:s' => { name => 'keepass_endpoint_file' },
'keepass-file:s' => { name => 'keepass_file' },
'keepass-password:s' => { name => 'keepass_password' },
'keepass-search-value:s@' => { name => 'keepass_search_value' },
'keepass-map-option:s@' => { name => 'keepass_map_option' }
});
$options{options}->add_help(package => __PACKAGE__, sections => 'KEEPASS OPTIONS');
$self->{output} = $options{output};
$JSON::Path::Safe = 0;
return $self;
}
@ -143,19 +143,15 @@ sub manage_options {
$self->build_api_args(%options);
return if (!defined($self->{connection_info}->{file}));
my $keepassfile;
eval {
$keepassfile = File::KeePass->new();
$keepassfile->load_db($self->{connection_info}->{file}, $self->{connection_info}->{password});
$keepassfile->unlock;
$self->{output}->output_add(long_msg => Data::Dumper::Dumper($keepassfile->groups), debug => 1) if ($self->{output}->is_debug());
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot read keepass file: $@");
my $keepass = KeePass::Reader->new();
my $content = $keepass->load_db(file => $self->{connection_info}->{file}, password => $self->{connection_info}->{password});
if (!defined($content)) {
$self->{output}->add_option_msg(short_msg => "Cannot read keepass file: " . $keepass->error());
$self->{output}->option_exit();
}
$self->do_lookup(%options, json => $keepassfile->groups);
$self->{output}->output_add(long_msg => Data::Dumper::Dumper($content), debug => 1) if ($self->{output}->is_debug());
$self->do_lookup(%options, json => $content);
$self->do_map(%options);
}