Changeset 279

Show
Ignore:
Timestamp:
05/08/08 00:13:42 (7 months ago)
Author:
mbr
Message:
  • Changed --Obfuscate-filenames format to not include the gpgdir PID.
    This allows directories to be encrypted/decrypted under -O multiple
    times without creating new filenames (which would pollute encrypted
    directories under rsync to other systems). The new -O encrypted
    filename format is just "gpgdir_<num>.gpg".
  • Added PID locking against directories so that multiple gpgdir processes
    cannot operate against the same top-level directory simultaneously.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gpgdir/trunk/ChangeLog

    r275 r279  
     1gpgdir-1.9 (05//2008): 
     2    - Changed --Obfuscate-filenames format to not include the gpgdir PID. 
     3      This allows directories to be encrypted/decrypted under -O multiple 
     4      times without creating new filenames (which would pollute encrypted 
     5      directories under rsync to other systems).  The new -O encrypted 
     6      filename format is just "gpgdir_<num>.gpg". 
     7    - Added PID locking against directories so that multiple gpgdir processes 
     8      cannot operate against the same top-level directory simultaneously. 
     9 
    110gpgdir-1.8 (04/04/2008): 
    211    - Updated the test suite to validate the gpgdir --Obfuscate-filenames 
  • gpgdir/trunk/gpgdir

    r275 r279  
    1313# Version: 1.8 
    1414# 
    15 # Copyright (C) 2002-2007 Michael Rash (mbr@cipherdyne.org) 
     15# Copyright (C) 2002-2008 Michael Rash (mbr@cipherdyne.org) 
    1616# 
    1717# License (GNU General Public License): 
     
    6161my $include_pat     = ''; 
    6262my $include_file    = ''; 
     63my $pid_file        = ''; 
    6364my $total_encrypted = 0; 
    6465my $total_decrypted = 0; 
     
    295296$skip_test_mode = 1 if $trial_run; 
    296297 
     298if ($dir eq '.') { 
     299    $dir = $initial_dir; 
     300} elsif ($dir !~ m|^/|) { 
     301    $dir = $initial_dir . '/' . $dir; 
     302} 
     303$dir =~ s|/$||;  ### remove any trailing slash 
     304 
     305### make sure another gpgdir process is not trying to operate 
     306### on the same directory 
     307$pid_file = "$dir/.gpgdir.pid"; 
     308&unique_pid(); 
     309&write_pid(); 
     310 
    297311if ($symmetric_mode) { 
    298312    &get_password(); 
     
    301315} 
    302316 
    303 if ($dir eq '.') { 
    304     $dir = $initial_dir; 
    305 } elsif ($dir !~ m|^/|) { 
    306     $dir = $initial_dir . '/' . $dir; 
    307 } 
    308 $dir =~ s|/$||;  ### remove any trailing slash 
    309  
    310317### run a test to make sure gpgdir and encrypt and decrypt a file 
    311318unless ($skip_test_mode) { 
     
    330337unless ($obfuscate_mode) { 
    331338    if ($have_obfuscated_file) { 
    332         print "[-] Obfuscated filenames detected, try decrypting with -O.\n" 
     339        print "[-] Obfuscated filenames detected, try decrypting with -O\n" 
    333340            unless $quiet; 
    334341    } 
     
    341348    print "[+] Total number of files decrypted: " . 
    342349        "$total_decrypted\n" unless $quiet; 
     350} 
     351 
     352if (-e $pid_file) { 
     353    unlink $pid_file or die "[*] Could not remove pid file $pid_file: $!"; 
    343354} 
    344355 
     
    599610                } 
    600611 
    601                 $encrypt_filename = 'gpgdir_' . $$ . '_' 
    602                         . $obfuscate_ctrs{$dir} . '.gpg'; 
     612                $encrypt_filename = 'gpgdir_' . $obfuscate_ctrs{$dir} . '.gpg'; 
    603613            } 
    604614 
     
    684694 
    685695            } else { 
    686                 if (not $force_mode and $file =~ /gpgdir_\d+_\d+.gpg/) { 
     696                if (not $force_mode and ($file =~ /gpgdir_\d+_\d+\.gpg/ 
     697                        or $file =~ /gpgdir_\d+\.gpg/)) { 
    687698                    ### be careful not to decrypt obfuscated file unless we 
    688699                    ### are running in -O mode.  This ensures that the 
     
    854865        "$obfuscate_map_filename: $!"; 
    855866    while (<F>) { 
    856         if (/^\s*.*\s+(gpgdir_\d+_\d+.gpg)/) { 
     867        if (/^\s*.*\s+(gpgdir_\d+_\d+\.gpg)/) { 
     868            if (-e $1) { 
     869                push @existing_obfuscated_files, $_; 
     870            } 
     871        } elsif (/^\s*.*\s+(gpgdir_\d+\.gpg)/) { 
    857872            if (-e $1) { 
    858873                push @existing_obfuscated_files, $_; 
     
    896911        "$obfuscate_map_filename: $!"; 
    897912    while (<G>) { 
    898         if (/^\s*(.*)\s+(gpgdir_\d+_\d+.gpg)/) { 
     913        if (/^\s*(.*)\s+(gpgdir_\d+_\d+\.gpg)/) { 
     914            $obfuscated_dirs{$dir}{$2} = $1; 
     915            $total_mapped_files++; 
     916        } elsif (/^\s*(.*)\s+(gpgdir_\d+\.gpg)/) { 
    899917            $obfuscated_dirs{$dir}{$2} = $1; 
    900918            $total_mapped_files++; 
     
    11561174    return 1 if $ans eq 'y'; 
    11571175    return 0; 
     1176} 
     1177 
     1178sub unique_pid() { 
     1179    return unless -e $pid_file; 
     1180    open P, "< $pid_file" or die "[*] Could not open $pid_file: $!"; 
     1181    my $pid = <P>; 
     1182    chomp $pid; 
     1183    close P; 
     1184    if (kill 0, $pid) { 
     1185        die "[*] Another gpgdir process (pid: $pid) is already ", 
     1186            "running against\n    $dir"; 
     1187    } 
     1188    return; 
     1189} 
     1190 
     1191sub write_pid() { 
     1192    open P, "> $pid_file" or die "[*] Could not open $pid_file: $!"; 
     1193    print P $$, "\n"; 
     1194    close P; 
     1195    return; 
    11581196} 
    11591197 
  • gpgdir/trunk/test/gpgdir_test.pl

    r269 r279  
    236236    for my $file (@data_dir_files) { 
    237237        if (-f $file and not ($file =~ m|^\.| or $file =~ m|/\.|)) { 
    238             ### gpgdir_20089_1.gpg 
    239             unless ($file =~ m|gpgdir_\d+_\d+\.gpg$|) { 
     238            ### gpgdir_1.gpg 
     239            unless ($file =~ m|gpgdir_\d+\.gpg$|) { 
    240240                return &print_errors("fail ($test_num)\n[*] " . 
    241241                    "File $file not encrypted and obfuscated");