mirror of
https://codeberg.org/scip/Crypt--PWSafe3.git
synced 2025-12-16 20:21:01 +01:00
write tmpfile into vault dir, if writable. added sample script, bump version
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
1.20:
|
||||
applied another patch by David Dick: writing tmp files in
|
||||
the same directory where the vault file resides (unless it's
|
||||
not writable).
|
||||
|
||||
1.19:
|
||||
applied patch by David Dick, which adds some more precautions
|
||||
of i/o error handling and flushing.
|
||||
|
||||
@@ -30,7 +30,7 @@ use Data::Dumper;
|
||||
use Exporter ();
|
||||
use vars qw(@ISA @EXPORT);
|
||||
|
||||
$Crypt::PWSafe3::VERSION = '1.19';
|
||||
$Crypt::PWSafe3::VERSION = '1.20';
|
||||
|
||||
use Crypt::PWSafe3::Field;
|
||||
use Crypt::PWSafe3::HeaderField;
|
||||
@@ -350,7 +350,25 @@ sub save {
|
||||
$this->addheader($whatsaved);
|
||||
$this->addheader($whosaved);
|
||||
|
||||
my $fd = File::Temp->new(TEMPLATE => '.vaultXXXXXXXX', TMPDIR => 1, EXLOCK => 0) or croak "Could not open tmpfile: $!\n";
|
||||
# open a temp vault file, first we try it in the same directory as the target vault file
|
||||
my $tmpdir;
|
||||
if (File::Spec->file_name_is_absolute($file)) {
|
||||
my ($volume, $directories, undef) = File::Spec->splitpath($file);
|
||||
$tmpdir = File::Spec->catdir($volume, $directories);
|
||||
}
|
||||
else {
|
||||
my ($volume, $directories, undef) = File::Spec->splitpath(File::Spec->rel2abs($file));
|
||||
$tmpdir = File::Spec->abs2rel(File::Spec->catdir($volume, $directories));
|
||||
}
|
||||
|
||||
my $fd;
|
||||
if (-w $tmpdir) {
|
||||
$fd = File::Temp->new(TEMPLATE => '.vaultXXXXXXXX', DIR => $tmpdir, EXLOCK => 0) or croak "Could not open tmpfile: $!\n";
|
||||
}
|
||||
else {
|
||||
# well, then we'll use one in the tmp dir of the system
|
||||
$fd = File::Temp->new(TEMPLATE => '.vaultXXXXXXXX', TMPDIR => 1, EXLOCK => 0) or croak "Could not open tmpfile: $!\n";
|
||||
}
|
||||
my $tmpfile = "$fd";
|
||||
|
||||
$this->{fd} = $fd;
|
||||
@@ -979,7 +997,7 @@ License 2.0, see: L<http://www.perlfoundation.org/artistic_license_2_0>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Crypt::PWSafe3 Version 1.19.
|
||||
Crypt::PWSafe3 Version 1.20.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
49
sample/test.pl
Executable file
49
sample/test.pl
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use lib qw(blib/lib);
|
||||
use Crypt::PWSafe3;
|
||||
|
||||
|
||||
my $file = shift;
|
||||
|
||||
if (!$file) {
|
||||
print STDERR "Usage $0 <vault>\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
my $create = 1;
|
||||
if (-e $file) {
|
||||
$create = 0;
|
||||
}
|
||||
|
||||
my $vault = Crypt::PWSafe3->new(file => $file, create => $create, password => 'blah') or die "$!";
|
||||
|
||||
if ($create) {
|
||||
my %record = (
|
||||
user => 'u3',
|
||||
passwd => 'p3',
|
||||
group => 'g3',
|
||||
title => 't3',
|
||||
notes => scalar localtime(time)
|
||||
);
|
||||
$vault->newrecord(%record);
|
||||
$vault->save();
|
||||
print "record saved to $file, execute $0 again to view it\n"
|
||||
}
|
||||
else {
|
||||
my @r = $vault->getrecords;
|
||||
foreach my $rec (@r) {
|
||||
printf qq(%s:
|
||||
User: %s
|
||||
Passwd: %s
|
||||
Group: %s
|
||||
Title: %s
|
||||
Notes: %s
|
||||
), $rec->uuid, $rec->user, $rec->passwd, $rec->group, $rec->title, $rec->notes;
|
||||
|
||||
$vault->modifyrecord($rec->uuid, notes => scalar localtime(time));
|
||||
}
|
||||
|
||||
$vault->save;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user