Changes in trunk/scripts/samhainadmin.pl.in [1:3]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/samhainadmin.pl.in
r1 r3 23 23 use Getopt::Long; 24 24 use File::Basename; 25 use File::Copy; 25 26 use File::stat; 26 27 use File::Temp qw/ tempfile tempdir unlink0 /; 27 28 use IO::Handle; 29 use Fcntl qw(:DEFAULT :flock); 28 30 29 31 File::Temp->safe_level( File::Temp::HIGH ); … … 36 38 my $return_from_sign = 0; 37 39 my $no_print_examine = 0; 40 my $no_remove_lock = 0; 38 41 my $base = basename($0); 39 42 … … 42 45 my $daemon = "@sbindir@/@install_name@"; 43 46 my $gpg = "@mygpg@"; 47 48 $cfgfile =~ s/^REQ_FROM_SERVER//; 49 $datafile =~ s/^REQ_FROM_SERVER//; 44 50 45 51 $gpg = "gpg" if ($gpg eq ""); … … 186 192 187 193 my $dir = tempdir( CLEANUP => 1 ); 188 $filename = $dir . "/exa_jhfdbilw ";194 $filename = $dir . "/exa_jhfdbilw." . $$; 189 195 open $fh, ">$filename" or die "Cannot open $filename"; 190 196 autoflush $fh 1; … … 281 287 open FH, "<$file1" or die "Cannot open file $file1 for read: $!"; 282 288 if (!($file1 =~ /^\-$/)) { 289 flock(FH, LOCK_EX) unless ($no_remove_lock == 1); 283 290 my $dir = tempdir( CLEANUP => 1 ) or die "Tempdir failed"; 284 $filename = $dir . "/rem_iqegBCQb ";291 $filename = $dir . "/rem_iqegBCQb." . $$; 285 292 open $fh, ">$filename" or die "Cannot open $filename"; 286 293 $stats = stat($file1); … … 313 320 } 314 321 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: $!"; 318 324 chmod $stats->mode, $file1; 319 325 chown $stats->uid, $stats->gid, $file1; 326 flock(FH, LOCK_UN) unless ($no_remove_lock == 1); 327 close FH; 320 328 } 321 329 unlink0( $fh, $filename ) or die "Cannot unlink $filename safely"; … … 386 394 if ($file1 =~ /^\-$/) { 387 395 my $dir = tempdir( CLEANUP => 1 ) or die "Tempdir failed"; 388 $filename1 = $dir . "/sig_vs8827sd ";396 $filename1 = $dir . "/sig_vs8827sd." . $$; 389 397 open $fh1, ">$filename1" or die "Cannot open $filename1"; 390 398 $flag1 = 1; … … 419 427 $fileout = '-'; 420 428 } else { 429 open (LOCKFILE, "<$file1") or die "Cannot open $file1: $!"; 430 flock(LOCKFILE, LOCK_EX); 421 431 $no_print_examine = 1; 432 $no_remove_lock = 1; 422 433 if (examine() < 2) { 423 434 remove(); 424 435 } 425 436 $fileout = $file1 . ".asc"; 426 $stats = stat($file1); 437 $stats = stat($file1) 438 or die "No file $file1: $!"; 427 439 } 428 440 … … 446 458 die ("Signed file is smaller than unsigned file") 447 459 unless ($st_new->size > $st_old->size); 448 system ("mv $fileout $file2") == 0449 or die " system mv $fileout $file2 failed: $?";460 move("$fileout", "$file2") 461 or die "Move $fileout to $file2 failed: $!"; 450 462 chmod $stats->mode, $file2; 451 463 chown $stats->uid, $stats->gid, $file2; 464 flock(LOCKFILE, LOCK_UN); 452 465 } 453 466
Note:
See TracChangeset
for help on using the changeset viewer.