From 820abf1636edde09ce7c41dbeb8f4591854101d5 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Mon, 12 May 2014 11:25:39 +0400 Subject: [PATCH] File permissions fix --- GPG.pm | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/GPG.pm b/GPG.pm index 3011137..82cf004 100644 --- a/GPG.pm +++ b/GPG.pm @@ -10,10 +10,10 @@ sub new { my $home = $ENV{HOME}; my $db = $home . "/.PM/db.sqlite"; - my $self = { - _db => $db, + my $self = { + _db => $db, _home => $home, - }; + }; bless $self, $class; return $self; @@ -33,22 +33,20 @@ sub encrypt_db { my @enc_cmd; my $recipient; if ( -e $self->{_home} . "/.PM/.key" ) { - open my $key_f, "<" , $self->{_home} . "/.PM/.key" + open my $key_f, "<", $self->{_home} . "/.PM/.key" or die "Cannot open file: $!\n"; - while ( <$key_f> ) { + while (<$key_f>) { $recipient = $_; } @enc_cmd = ( - "gpg", "--output", "$db", - "-a", "--recipient", "$recipient", - "--encrypt", "$file", + "gpg", "--output", "$db", "-a", + "--recipient", "$recipient", "--encrypt", "$file", ); } else { # gpg --output test.gpg --encrypt test -a --default-recipient-self @enc_cmd = ( - "gpg", "--output", "$db", - "-a", "--default-recipient-self", + "gpg", "--output", "$db", "-a", "--default-recipient-self", "--encrypt", "$file", ); } @@ -60,6 +58,10 @@ sub encrypt_db { @rm_cmd = ( "rm", "-f", "$file" ); system(@rm_cmd) == 0 or die "Cannot remove file $file: $!\n"; + # Change file permissions + @chmod_cmd = ( "chmod", 600, $db ); + system(@chmod_cmd) == 0 or die "Cannot chmod $file: $!\n"; + return 0; } @@ -81,6 +83,10 @@ sub decrypt_db { @dec_cmd = ( "$gpg", "--output", "$file", "--decrypt", "$db" ); system(@dec_cmd) == 0 or die "Cannot decrypt $db: $!\n"; + # Change file permissions + @chmod_cmd = ( "chmod", 600, $file ); + system(@chmod_cmd) == 0 or die "Cannot chmod $file: $!\n"; + return $file; }