Changeset 242

Show
Ignore:
Timestamp:
04/12/07 11:33:15 (2 years ago)
Author:
kindlund
Message:

Fixed Registry code so that each Registry $object can be serialized to memory or disk.
The only gotcha, is that $object→closeFiles() must be called before calling any Storable function on it, since Storable can't serialize any open file handle.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/lib/HoneyClient/Agent/Integrity/Registry.pm

    r240 r242  
    8787=head1 DESCRIPTION 
    8888 
    89 This library allows the Agent module to easily baseline and check 
     89This library allows the Integrity module to easily baseline and check 
    9090the Windows OS registry hives for any changes that may occur, while 
    9191instrumenting a target application. 
     
    102102use warnings; 
    103103use Carp (); 
    104  
    105 # Traps signals, allowing END: blocks to perform cleanup. 
    106 #use sigtrap qw(die untrapped normal-signals error-signals); 
    107104 
    108105# Include Global Configuration Processing Library 
     
    445442    _checkpoint_parsers => { },  
    446443 
    447     # A hashtable of file names, where the hash key is the file parser 
    448     # and the hash value is the file name. 
    449     # (For internal use only.) 
    450     _filenames => { }, 
    451  
    452444    # A hashtable of current key info objects, where the hash key is the 
    453445    # file parser and the hash value is the info object. 
     
    487479        $parser = $self->{_baseline_parsers}->{$hive}; 
    488480        if (defined($parser)) { 
    489             $fname = $self->{_filenames}->{$parser}; 
    490             $LOG->debug("Deleting baseline of hive '" . $hive . "' in '" . 
    491                         $fname . "'."); 
    492             if (!unlink($fname)) { 
    493                 $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    494                 Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
     481            $fname = $parser->getFilename(); 
     482            if (defined($fname) && (-f $fname)) { 
     483                $LOG->debug("Deleting baseline of hive '" . $hive . "' in '" . 
     484                            $fname . "'."); 
     485                if (!unlink($fname)) { 
     486                    $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
     487                    Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
     488                } 
    495489            } 
    496             delete($self->{_filenames}->{$parser}); 
    497490            delete($self->{_baseline_parsers}->{$hive}); 
    498491        } 
    499492        $parser = $self->{_checkpoint_parsers}->{$hive}; 
    500493        if (defined($parser)) { 
    501             $fname = $self->{_filenames}->{$parser}; 
    502             $LOG->debug("Deleting checkpoint of hive '" . $hive . "' in '" . 
    503                         $fname . "'."); 
    504             if (!unlink($fname)) { 
    505                 $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    506                 Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
     494            $fname = $parser->getFilename(); 
     495            if (defined($fname) && (-f $fname)) { 
     496                $LOG->debug("Deleting checkpoint of hive '" . $hive . "' in '" . 
     497                            $fname . "'."); 
     498                if (!unlink($fname)) { 
     499                    $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
     500                    Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
     501                } 
    507502            } 
    508             delete($self->{_filenames}->{$parser}); 
    509503            delete($self->{_checkpoint_parsers}->{$hive}); 
    510504        } 
     
    547541 
    548542        $parser_collection->{$hive} = $parser; 
    549         $self->{_filenames}->{$parser} = $fname; 
    550543    } 
    551544} 
     
    618611    if (!defined($self->{_currentKeys}->{$parser})) { 
    619612        $LOG->fatal("Error: Unable to read registry keys from '" . 
    620                     $self->{_filenames}->{$parser} . "'."); 
     613                    $parser->getFilename() . "'."); 
    621614        Carp::croak("Error: Unable to read registry keys from '" . 
    622                     $self->{_filenames}->{$parser} . "'."); 
     615                    $parser->getFilename() . "'."); 
    623616    } 
    624617 
     
    686679 
    687680    # Get the corresponding file names. 
    688     my $src_filename = $self->{_filenames}->{$src_parser}
    689     my $tgt_filename = $self->{_filenames}->{$tgt_parser}
     681    my $src_filename = $src_parser->getFilename()
     682    my $tgt_filename = $tgt_parser->getFilename()
    690683 
    691684    my $fname_tmp = tmpnam();  
     
    14701463        $before_parser = HoneyClient::Agent::Integrity::Registry::Parser->init(input_file   => $args{'before_file'}, 
    14711464                                                                               index_groups => 1); 
    1472         $self->{_filenames}->{$before_parser} = $args{'before_file'}; 
    14731465    } 
    14741466 
     
    14801472        $after_parser = HoneyClient::Agent::Integrity::Registry::Parser->init(input_file   => $args{'after_file'}, 
    14811473                                                                              index_groups => 1); 
    1482         $self->{_filenames}->{$after_parser} = $args{'after_file'}; 
    14831474    } 
    14841475 
     
    15611552    $LOG->debug(Dumper(\%args)); 
    15621553 
    1563     return values(%{$self->{_filenames}}); 
     1554    my @parsers = values(%{$self->{_baseline_parsers}}); 
     1555    push (@parsers, values(%{$self->{_checkpoint_parsers}})); 
     1556 
     1557    my @files; 
     1558    foreach my $parser (@parsers) { 
     1559        push (@files, $parser->getFilename()); 
     1560    } 
     1561 
     1562    return @files; 
    15641563} 
    15651564