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