Changeset 3 for trunk/scripts


Ignore:
Timestamp:
Dec 21, 2005, 10:07:54 PM (19 years ago)
Author:
rainer
Message:

More fixes for update function, released 2.1.1 version.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/samhainadmin.pl.in

    r1 r3  
    2323use Getopt::Long;
    2424use File::Basename;
     25use File::Copy;
    2526use File::stat;
    2627use File::Temp qw/ tempfile tempdir unlink0 /;
    2728use IO::Handle;
     29use Fcntl qw(:DEFAULT :flock);
    2830
    2931File::Temp->safe_level( File::Temp::HIGH );
     
    3638my $return_from_sign = 0;
    3739my $no_print_examine = 0;
     40my $no_remove_lock   = 0;
    3841my $base = basename($0);
    3942
     
    4245my $daemon   = "@sbindir@/@install_name@";
    4346my $gpg      = "@mygpg@";
     47
     48$cfgfile  =~ s/^REQ_FROM_SERVER//;
     49$datafile =~ s/^REQ_FROM_SERVER//;
    4450
    4551$gpg = "gpg" if ($gpg eq "");
     
    186192
    187193    my $dir = tempdir( CLEANUP => 1 );
    188     $filename = $dir . "/exa_jhfdbilw";
     194    $filename = $dir . "/exa_jhfdbilw." . $$;
    189195    open $fh, ">$filename" or die "Cannot open $filename";
    190196    autoflush $fh 1;
     
    281287    open FH, "<$file1" or die "Cannot open file $file1 for read: $!";
    282288    if (!($file1 =~ /^\-$/)) {
     289        flock(FH, LOCK_EX) unless ($no_remove_lock == 1);
    283290        my $dir = tempdir( CLEANUP => 1 ) or die "Tempdir failed";
    284         $filename = $dir . "/rem_iqegBCQb";
     291        $filename = $dir . "/rem_iqegBCQb." . $$;
    285292        open $fh, ">$filename" or die "Cannot open $filename";
    286293        $stats = stat($file1);
     
    313320    }
    314321    if (!($file1 =~ /^\-$/)) {
    315         my $command = "cp $filename $file1";
    316         system ($command) == 0
    317             or die "system $command failed: $?";
     322        copy("$filename", "$file1")
     323            or die "Copy $filename to $file1 failed: $!";
    318324        chmod $stats->mode, $file1;
    319325        chown $stats->uid, $stats->gid, $file1;
     326        flock(FH, LOCK_UN) unless ($no_remove_lock == 1);
     327        close FH;
    320328    }
    321329    unlink0( $fh, $filename ) or die "Cannot unlink $filename safely";
     
    386394    if ($file1 =~ /^\-$/) {
    387395        my $dir = tempdir( CLEANUP => 1 ) or die "Tempdir failed";
    388         $filename1 = $dir . "/sig_vs8827sd";
     396        $filename1 = $dir . "/sig_vs8827sd." . $$;
    389397        open $fh1, ">$filename1" or die "Cannot open $filename1";
    390398        $flag1 = 1;
     
    419427        $fileout = '-';
    420428    } else {
     429        open (LOCKFILE, "<$file1") or die "Cannot open $file1: $!";
     430        flock(LOCKFILE, LOCK_EX);
    421431        $no_print_examine = 1;
     432        $no_remove_lock   = 1;
    422433        if (examine() < 2) {
    423434            remove();
    424435        }
    425436        $fileout = $file1 . ".asc";
    426         $stats   = stat($file1);
     437        $stats   = stat($file1)
     438            or die "No file $file1: $!";
    427439    }
    428440
     
    446458        die ("Signed file is smaller than unsigned file")
    447459            unless ($st_new->size > $st_old->size);
    448         system ("mv $fileout $file2") == 0
    449             or die "system mv $fileout $file2 failed: $?";
     460        move("$fileout", "$file2")
     461            or die "Move $fileout to $file2 failed: $!";
    450462        chmod $stats->mode, $file2;
    451463        chown $stats->uid, $stats->gid, $file2;
     464        flock(LOCKFILE, LOCK_UN);
    452465    }
    453466
Note: See TracChangeset for help on using the changeset viewer.