aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-03-19 23:36:39 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-03-20 00:13:09 +0100
commite1d324e345f431e3552dbca32d3c448bea873f8b (patch)
treefa540118dc0973560b00d3c80453e961cbf0747b
parentcc9fda4d36f3ae5427fa05564a4bdd5b53e94ce5 (diff)
wibble
-rwxr-xr-xicevault78
1 files changed, 39 insertions, 39 deletions
diff --git a/icevault b/icevault
index 40eaf4b..c0dd55b 100755
--- a/icevault
+++ b/icevault
@@ -104,7 +104,7 @@ sub firstIdx(&@) {
local $_ = $list[$i];
return $i if $code->();
}
- return undef;
+ return;
}
sub groupByName(@) {
@@ -255,22 +255,22 @@ sub getIdentityFile($) {
or error "Invalid identity C<%s>", $id;
my ($s, $h, $i) = ($1, $2, $3);
- my $file = $CONFIG{store};
- $file =~ s{\%(.)}{ $1 eq '%' ? '%' :
- $1 eq 's' ? $s :
- $1 eq 'h' ? $h :
- $1 eq 'i' ? $i :
- die "Invalid placeholder %$1" }ge;
- return $file;
+ my $filename = $CONFIG{store};
+ $filename =~ s{\%(.)}{ $1 eq '%' ? '%' :
+ $1 eq 's' ? $s :
+ $1 eq 'h' ? $h :
+ $1 eq 'i' ? $i :
+ die "Invalid placeholder %$1" }ge;
+ return $filename;
}
# Decrypt the given identity file and return the YAML-parsed form.
sub loadIdentityFile($) {
- my $file = shift;
- myprintf \*STDERR, "Decrypting identity file C<%s>", $file if $CONFIG{debug};
+ my $filename = shift;
+ myprintf \*STDERR, "Decrypting identity file C<%s>", $filename if $CONFIG{debug};
require 'YAML/Tiny.pm'; # XXX use Tiny::YAML instead?
- my $pid = open my $fh, '-|', $CONFIG{gpg}, qw/-o - --decrypt --/, $file
+ my $pid = open my $fh, '-|', $CONFIG{gpg}, qw/-o - --decrypt --/, $filename
or error "Can't fork: %s", $!;
my $str = do { local $/ = undef; <$fh> };
waitpid $pid, 0;
@@ -283,17 +283,17 @@ sub loadIdentityFile($) {
# Dump and encrypt a form into the given filename.
sub saveIdentityFile($$) {
- my ($form, $file) = @_;
+ my ($form, $filename) = @_;
$form->{fields} = [ grep defined, @{$form->{fields}} ]; # remove undefined fields
- myprintf \*STDERR, "Saving identity file C<%s>", $file if $CONFIG{debug};
+ myprintf \*STDERR, "Saving identity file C<%s>", $filename if $CONFIG{debug};
require 'File/Copy.pm';
require 'File/Path.pm';
require 'File/Temp.pm';
require 'IPC/Open2.pm';
require 'YAML/Tiny.pm'; # XXX use Tiny::YAML instead?
- # don't encrypt directly into the destination $file so we don't
- # end up with a messed up $file if something goes wrong
+ # don't encrypt directly into the destination file so we don't
+ # end up with a messed up file if something goes wrong
my $outfh = File::Temp->new(SUFFIX => '.gpg', UNLINK => 0, TMPDIR => 1);
my $pid = IPC::Open2::open2(">&".$outfh->fileno, my $infh, $CONFIG{gpg},
qw/-o - --no-encrypt-to --recipient/, $CONFIG{keyid}, '--encrypt')
@@ -304,11 +304,11 @@ sub saveIdentityFile($$) {
error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $? and $? != -1;
$outfh->close;
- my $parent_dir = $file =~ s/\/[^\/]+$//r;
+ my $parent_dir = $filename =~ s/\/[^\/]+$//r;
File::Path::make_path $parent_dir unless -d $parent_dir; # create parent directories recursively
- File::Copy::move $outfh->filename, $file or error "Can't move C<%s>: %s", $outfh->filename, $!;
+ File::Copy::move $outfh->filename, $filename or error "Can't move C<%s>: %s", $outfh->filename, $!;
- # TODO: git add $file; git commit
+ # TODO: git add $filename; git commit
}
# Get the visible form list from the server, and croak if it's empty.
@@ -509,8 +509,8 @@ if ($command eq 'insert') {
}
}
- my $file = getIdentityFile "$uri/$id";
- error "Identity C<%s> already exists", "$uri/$id" if -e $file;
+ my $filename = getIdentityFile "$uri/$id";
+ error "Identity C<%s> already exists", "$uri/$id" if -e $filename;
my @passIdx = grepIdx { $_->{type} eq 'password' } @{$form->{fields}};
my @dontsave;
@@ -548,7 +548,7 @@ if ($command eq 'insert') {
}
}
elsif ($#passIdx >= 3) {
- print STDERR "Assuming all ".($#passIdx+1)." passwords are independent\n";
+ print STDERR "Assuming all ".scalar(@passIdx)." passwords are independent\n";
foreach my $i (@passIdx) {
next unless $form->{fields}->[$i]->{value} eq '';
pwgen $form->{fields}->[$i];
@@ -561,14 +561,14 @@ if ($command eq 'insert') {
undef @{$form->{fields}}[@dontsave] if @dontsave; # remove the field we don't want to save
myprintf "Saving identity C<%s>", "$uri/$id";
- saveIdentityFile $form, $file;
+ saveIdentityFile $form, $filename;
}
elsif ($command eq 'fill') {
usage(1) unless $#ARGV == 0;
my $id = shift;
- my $file = getIdentityFile $id;
- error "No such identity C<%s>", $id unless -f $file;
+ my $filename = getIdentityFile $id;
+ error "No such identity C<%s>", $id unless -f $filename;
my $uri = &connect($CONFIG{socket});
error "Possible phishing attempt! (URI C<%s> doesn't match identity.) Aborting.", $uri
@@ -576,7 +576,7 @@ elsif ($command eq 'fill') {
# get the list of forms and load the known form from disk
my @forms = getForms();
- my $myform = loadIdentityFile $file;
+ my $myform = loadIdentityFile $filename;
my $formIdx = findForm $myform, @forms;
my $form = $forms[$formIdx];
my @fill = map {undef} (0 .. $#{$form->{fields}});
@@ -705,17 +705,17 @@ elsif ($command eq 'fill') {
if ($changed) {
my $r = promptYN "Save changes?", 0;
- saveIdentityFile ($myform, $file) if $r;
+ saveIdentityFile ($myform, $filename) if $r;
}
}
elsif ($command eq 'dump') {
usage(1) unless $#ARGV == 0;
my $id = shift;
- my $file = getIdentityFile $id;
- error "No such identity C<%s>", $id unless -f $file;
+ my $filename = getIdentityFile $id;
+ error "No such identity C<%s>", $id unless -f $filename;
- my $form = loadIdentityFile $file;
+ my $form = loadIdentityFile $filename;
$_->{value} = safeValue($_) foreach @{$form->{fields}}; # redact the passwords
my $str = YAML::Tiny::Dump($form);
@@ -725,8 +725,8 @@ elsif ($command eq 'dump') {
elsif ($command eq 'edit') {
usage(1) unless $#ARGV == 0;
my $id = shift;
- my $file = getIdentityFile $id;
- error "No such identity C<%s>", $id unless -f $file;
+ my $filename = getIdentityFile $id;
+ error "No such identity C<%s>", $id unless -f $filename;
require 'File/Copy.pm';
require 'File/Temp.pm';
@@ -736,12 +736,12 @@ elsif ($command eq 'edit') {
my $fh = File::Temp->new(SUFFIX => '.yaml', UNLINK => 0, TMPDIR => 1);
END { unlink $fh->filename if defined $fh; } # never leave cleartext lying around
- myprintf \*STDERR, "Decrypting identity file C<%s>", $file if $CONFIG{debug};
+ myprintf \*STDERR, "Decrypting identity file C<%s>", $filename if $CONFIG{debug};
# XXX use loadIdentityFile
open my $NULL, '<', '/dev/null';
require 'IPC/Open2.pm';
- my $pid = IPC::Open2::open2(">&".$fh->fileno, "<&".fileno($NULL), $CONFIG{gpg}, qw/-o - --decrypt --/, $file)
+ my $pid = IPC::Open2::open2(">&".$fh->fileno, "<&".fileno($NULL), $CONFIG{gpg}, qw/-o - --decrypt --/, $filename)
or error "Can't fork: %s", $!;
waitpid $pid, 0;
error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $? and $? != -1;
@@ -756,8 +756,8 @@ elsif ($command eq 'edit') {
}
else {
# XXX use saveIdentityFile
- # don't encrypt directly into the destination $file so we don't
- # end up with a messed up $file if something goes wrong
+ # don't encrypt directly into the destination file so we don't
+ # end up with a messed up file if something goes wrong
myprintf "Saving user changes for identity C<%s>", $id;
my $outfh = File::Temp->new(SUFFIX => '.gpg', UNLINK => 0, TMPDIR => 1);
my $pid = open2(">&".$outfh->fileno, "<&".fileno($NULL),
@@ -768,7 +768,7 @@ elsif ($command eq 'edit') {
error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $? and $? != -1;
$outfh->close;
- File::Copy::move $outfh->filename, $file or error "Can't move C<%s>: %s", $outfh->filename, $!;
+ File::Copy::move $outfh->filename, $filename or error "Can't move C<%s>: %s", $outfh->filename, $!;
}
close $NULL;
@@ -777,10 +777,10 @@ elsif ($command eq 'edit') {
elsif ($command eq 'clip') {
usage(1) unless $#ARGV == 0;
my $id = shift;
- my $file = getIdentityFile $id;
- error "No such identity C<%s>", $id unless -f $file;
+ my $filename = getIdentityFile $id;
+ error "No such identity C<%s>", $id unless -f $filename;
- my $form = loadIdentityFile $file;
+ my $form = loadIdentityFile $filename;
my $pw = first { $_->{type} eq 'password' } @{$form->{fields}};
error "No password found in C<%s>", $id unless defined $pw;