Changes in / [3:1]


Ignore:
Location:
/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • /trunk/docs/Changelog

    r3 r1  
    1 
    212.1.1:
    3         * sh_calls.c: protect sh_calls_set_bind_addr against overriding
    4         * comINSTALL, updateDB: use locking
    5         * samhainadmin.pl: use locking
    62        * fix typos in samhainrc.solaris (noticed by Robby Cauwerts)
    73        * improve zAVLSearch (remove redundant strcmp)
    8         * use AVL tree in sh_files.c instead of linked list (better scaling)
     4        * use AVL tree in sh_files.c instead of linked list (scales way better)
    95        * fix bug with suidcheck (no update/check in one-shot mode with
    106          schedule instead of check interval; noticed by R. Rati)
  • /trunk/dsys/comINSTALL

    r3 r1  
    340340    #---------------------------------------------------------------------
    341341
    342     instlock="${yule_conf}.lockdir";
    343     trap "rm -rf ${instlock}" 1 2 13 15
    344 
    345     if test x"$simulate" = x0
    346     then
    347         #
    348         # A lockfile will not work, because 'root' can write anyway.
    349         # However, 'mkdir' an existing directory will fail even for root
    350         #
    351         until (umask 222; mkdir "${instlock}") 2>/dev/null   # test & set
    352         do
    353            printINFO "Waiting for lock"
    354            sleep 1
    355         done
    356     fi
    357 
    358342    Replace=`"${yule_exec}" -P "${is_passwd}" | sed s%HOSTNAME%${host}%g`
    359343    if test "x$Replace" = x
    360344    then
    361         rm -rf "${instlock}"
    362345        printFATAL "Could not execute ${yule_exec} -P ${is_passwd}."
    363346    fi
     
    373356            then
    374357                Seen=y
    375                 echo "$Replace" >>"$tmpF"
    376                 if [ $? -ne 0 ]; then
    377                         rm -rf "${instlock}"
    378                         printFATAL "Cannot write new server configuration."
    379                 fi
     358                echo "$Replace" >>"$tmpF" || printFATAL "Cannot write new server configuration."
    380359            fi
    381360        else
     
    384363                :
    385364            else
    386                 echo "$line" >>"$tmpF"
    387                 if [ $? -ne 0 ]; then
    388                         rm -rf "${instlock}"
    389                         printFATAL "Cannot write new server configuration."
    390                 fi
     365                echo "$line" >>"$tmpF" || printFATAL "Cannot write new server configuration."
    391366            fi
    392367        fi
     
    405380    if test x"$simulate" = x0
    406381    then
    407         ageFILE "${yule_conf}"
    408         if [ $? -ne 0 ]; then
    409                 rm -rf "${instlock}"
    410                 printFATAL "Could not backup ${yule_conf}"
    411         fi
    412 
    413         rm -f "${yule_conf}" && cp "$tmpF"  "${yule_conf}"
    414         if [ $? -ne 0 ]; then
    415                 rm -rf "${instlock}"
    416                 printFATAL "Could not write new server config. Backup is ${yule_conf}.1"
    417         fi
    418 
    419         chown ${rcfile_owner}:${rcfile_group} "${yule_conf}"
    420         if [ $? -ne 0 ]; then
    421                 rm -rf "${instlock}"
    422                 printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_conf}"
    423         fi
    424 
    425         chmod ${rcfile_perm} "${yule_conf}"
    426         if [ $? -ne 0 ]; then
    427                 rm -rf "${instlock}"
    428                 printFATAL "Could not chmod ${rcfile_perm} ${yule_conf}"
    429         fi
     382        ageFILE "${yule_conf}" || printFATAL "Could not backup ${yule_conf}."
     383        rm -f "${yule_conf}" && { cp "$tmpF"  "${yule_conf}" || printFATAL "Could not write new server config. Backup is ${yule_conf}.1"; }
     384        chown ${rcfile_owner}:${rcfile_group} "${yule_conf}" || printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_conf}"
     385        chmod ${rcfile_perm} "${yule_conf}" || printFATAL "Could not chmod ${rcfile_perm} ${yule_conf}"
    430386    else
    431387        printINFO "Backup and update ${yule_conf}"
     
    467423        sleep 5
    468424        #
    469         rm -rf "${instlock}"
    470425    else
    471426        printINFO "Reloading server configuration."
     
    473428
    474429    printLOG "Server configuration updated and reloaded."
    475 
    476430
    477431    #---------------------------------------------------------------------
  • /trunk/dsys/funcINSTALL

    r3 r1  
    9191        DATABASE="${basedir}/${defdatabase}"
    9292    fi
    93 
    94     updlock="${DATABASE}.lockdir"
    95     trap "rm -rf ${updlock}" 1 2 13 15
    96 
    97     #
    98     # A lockfile will not work, because 'root' can write anyway.
    99     # However, 'mkdir' an existing directory will fail even for root
    100     #
    101     until (umask 222; mkdir "${updlock}") 2>/dev/null   # test & set
    102     do
    103        printINFO "Waiting for lock"
    104        sleep 1
    105     done
    106 
    10793
    10894    IDATE=`date +"%Y-%m-%d %H:%M:%S"`
     
    237223    fi
    238224
    239     chown ${rcfile_owner}:${rcfile_group} "${DATABASE}"
    240     if [ $? -ne 0 ]; then
    241         rm -rf "${instlock}"
    242         printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${DATABASE}"
    243     fi
    244     chmod ${rcfile_perm} "${DATABASE}"
    245     if [ $? -ne 0 ]; then
    246         rm -rf "${instlock}"
    247         printFATAL "Could not chmod ${rcfile_perm} ${DATABASE}"
    248     fi
    249 
    250     rm -rf "${updlock}"
     225    chown ${rcfile_owner}:${rcfile_group} "${DATABASE}" || printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${DATABASE}"
     226    chmod ${rcfile_perm} "${DATABASE}" || printFATAL "Could not chmod ${rcfile_perm} ${DATABASE}"
     227
    251228}
    252229
  • /trunk/man/samhain.8

    r3 r1  
    1414{
    1515.I \-t update|\-\-set\-checksum\-test=update
    16 } [\-D | \-\-daemon | \-\-foreground] [\-\-forever] [\-r DEPTH|\-\-recursion=DEPTH] [log-options]
     16} [\-r DEPTH|\-\-recursion=DEPTH] [log-options]
    1717
    1818.B samhain
     
    195195[\-r DEPTH|\-\-recursion=DEPTH]
    196196Set the (global) recursion depth.
    197 .TP
    198 [\-D|\-\-daemon]
    199 Run as daemon. File checks are performed as specified by the timing
    200 options in the configuration file. Updates are saved after each file check.
    201 .TP
    202 [\-\-foreground]
    203 Run in the foreground. This will cause samhain to exit after the update,
    204 unless the option
    205 .I "\-\-forever"
    206 is used.
    207 .TP
    208 [\-\-forever]
    209 If not running as daemon, do not exit after finishing the update, but
    210 loop forever, and perform checks with corresponding database updates
    211 according to the timing options in the
    212 configuration file.
    213197
    214198.PP
  • /trunk/scripts/samhainadmin.pl.in

    r3 r1  
    2323use Getopt::Long;
    2424use File::Basename;
    25 use File::Copy;
    2625use File::stat;
    2726use File::Temp qw/ tempfile tempdir unlink0 /;
    2827use IO::Handle;
    29 use Fcntl qw(:DEFAULT :flock);
    3028
    3129File::Temp->safe_level( File::Temp::HIGH );
     
    3836my $return_from_sign = 0;
    3937my $no_print_examine = 0;
    40 my $no_remove_lock   = 0;
    4138my $base = basename($0);
    4239
     
    4542my $daemon   = "@sbindir@/@install_name@";
    4643my $gpg      = "@mygpg@";
    47 
    48 $cfgfile  =~ s/^REQ_FROM_SERVER//;
    49 $datafile =~ s/^REQ_FROM_SERVER//;
    5044
    5145$gpg = "gpg" if ($gpg eq "");
     
    192186
    193187    my $dir = tempdir( CLEANUP => 1 );
    194     $filename = $dir . "/exa_jhfdbilw." . $$;
     188    $filename = $dir . "/exa_jhfdbilw";
    195189    open $fh, ">$filename" or die "Cannot open $filename";
    196190    autoflush $fh 1;
     
    287281    open FH, "<$file1" or die "Cannot open file $file1 for read: $!";
    288282    if (!($file1 =~ /^\-$/)) {
    289         flock(FH, LOCK_EX) unless ($no_remove_lock == 1);
    290283        my $dir = tempdir( CLEANUP => 1 ) or die "Tempdir failed";
    291         $filename = $dir . "/rem_iqegBCQb." . $$;
     284        $filename = $dir . "/rem_iqegBCQb";
    292285        open $fh, ">$filename" or die "Cannot open $filename";
    293286        $stats = stat($file1);
     
    320313    }
    321314    if (!($file1 =~ /^\-$/)) {
    322         copy("$filename", "$file1")
    323             or die "Copy $filename to $file1 failed: $!";
     315        my $command = "cp $filename $file1";
     316        system ($command) == 0
     317            or die "system $command failed: $?";
    324318        chmod $stats->mode, $file1;
    325319        chown $stats->uid, $stats->gid, $file1;
    326         flock(FH, LOCK_UN) unless ($no_remove_lock == 1);
    327         close FH;
    328320    }
    329321    unlink0( $fh, $filename ) or die "Cannot unlink $filename safely";
     
    394386    if ($file1 =~ /^\-$/) {
    395387        my $dir = tempdir( CLEANUP => 1 ) or die "Tempdir failed";
    396         $filename1 = $dir . "/sig_vs8827sd." . $$;
     388        $filename1 = $dir . "/sig_vs8827sd";
    397389        open $fh1, ">$filename1" or die "Cannot open $filename1";
    398390        $flag1 = 1;
     
    427419        $fileout = '-';
    428420    } else {
    429         open (LOCKFILE, "<$file1") or die "Cannot open $file1: $!";
    430         flock(LOCKFILE, LOCK_EX);
    431421        $no_print_examine = 1;
    432         $no_remove_lock   = 1;
    433422        if (examine() < 2) {
    434423            remove();
    435424        }
    436425        $fileout = $file1 . ".asc";
    437         $stats   = stat($file1)
    438             or die "No file $file1: $!";
     426        $stats   = stat($file1);
    439427    }
    440428
     
    458446        die ("Signed file is smaller than unsigned file")
    459447            unless ($st_new->size > $st_old->size);
    460         move("$fileout", "$file2")
    461             or die "Move $fileout to $file2 failed: $!";
     448        system ("mv $fileout $file2") == 0
     449            or die "system mv $fileout $file2 failed: $?";
    462450        chmod $stats->mode, $file2;
    463451        chown $stats->uid, $stats->gid, $file2;
    464         flock(LOCKFILE, LOCK_UN);
    465452    }
    466453
  • /trunk/src/sh_calls.c

    r3 r1  
    138138int sh_calls_set_bind_addr (char * str)
    139139{
    140   static int reject = 0;
    141 
    142   if (reject == 1)
    143     return (0);
    144 
    145   if (sh.flag.opts == S_TRUE) 
    146     reject = 1;
    147 
    148140  if (0 == /*@-unrecog@*/inet_aton(str, &bind_addr)/*@+unrecog@*/)
    149141    {
  • /trunk/src/sh_database.c

    r3 r1  
    3838#include "sh_error.h"
    3939#include "sh_utils.h"
    40 
    41 extern int safe_logger (int signal, int method, pid_t thepid);
    4240
    4341#undef  FIL__
     
    10111009{
    10121010  int               status = 0;
    1013   const char      * p;
     1011  char            * p;
    10141012  static MYSQL    * db_conn = NULL;
    10151013  static SH_TIMEOUT sh_timer = { 0, 3600, S_TRUE };
     
    14491447          retv = S_FALSE;
    14501448        }
    1451       else if (*p == '\"' && escp == 0)
    1452         {
    1453           retv = S_FALSE;
    1454         }
    14551449      else
    14561450        {
     
    14591453      ++p;
    14601454    }
    1461   if (escp == 1)
    1462     retv = S_FALSE;
    14631455  return retv;
    14641456}
     
    15541546
    15551547              if (S_FALSE == is_escaped(&p[j+2])) {
    1556                 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
    1557                                 _("Message not properly escaped"),
    1558                                 _("sh_database_parse"));
    15591548                SL_RETURN(NULL, _("sh_database_parse"));
    15601549              }
  • /trunk/src/sh_forward.c

    r3 r1  
    19441944  SL_RET0(_("free_client"));
    19451945}
    1946 
    1947 extern int safe_logger (int signal, int method, pid_t thepid);
    19481946
    19491947int sh_forward_register_client (char * str)
  • /trunk/src/sh_hash.c

    r3 r1  
    653653{
    654654  sh_file_t * p;
    655   sh_file_t * q;
    656655  int key;
    657656
     
    675674              strlen(s->fullpath) == strlen(p->fullpath))
    676675            {
    677               q = p->next;
    678               SH_FREE(p->fullpath);
    679               if(p->linkpath)
    680                 SH_FREE(p->linkpath);
    681               memcpy(p, s, sizeof(sh_file_t));
    682               p->next = q;
     676              SH_FREE(s->fullpath);
     677              if(s->linkpath)
     678                SH_FREE(s->linkpath);
    683679              SH_FREE(s);
    684680              s = NULL;
  • /trunk/src/sh_kern.c

    r3 r1  
    859859   * Stored(old) is system_call_code[]
    860860   */
    861   if (sh.flag.checkSum == SH_CHECK_INIT || sh.flag.update == S_TRUE)
     861  if (sh.flag.checkSum == SH_CHECK_INIT)
    862862    {
    863863      store0 = 0; store1 = 0; store2 = 0;
     
    935935   * Stored(old) is sh_syscalls[] array.
    936936   */
    937   if (sh.flag.checkSum == SH_CHECK_INIT || sh.flag.update == S_TRUE)
     937  if (sh.flag.checkSum == SH_CHECK_INIT)
    938938    {
    939939      for (i = 0; i < SH_MAXCALLS; ++i)
     
    11251125  if (ShKernIDT == S_TRUE)
    11261126    {
    1127       if (sh.flag.checkSum == SH_CHECK_INIT || sh.flag.update == S_TRUE)
     1127      if (sh.flag.checkSum == SH_CHECK_INIT)
    11281128        {
    11291129          datasize = 8;
     
    14471447   * Stored(old) is sh_syscalls[] array.
    14481448   */
    1449   if (sh.flag.checkSum == SH_CHECK_INIT || sh.flag.update == S_TRUE)
     1449  if (sh.flag.checkSum == SH_CHECK_INIT)
    14501450    {
    14511451      for (i = 0; i < SH_MAXCALLS; ++i)
  • /trunk/src/sh_prelude.c

    r3 r1  
    795795       
    796796        if ( strstr(message, _("path=")) ) {
    797 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
    798797                if ( msgid != MSG_FI_ADD && msgid != MSG_FI_ADD2 )
    799798                        get_file_infos(target, message, IDMEF_FILE_CATEGORY_ORIGINAL);
    800 #endif
    801799               
    802800                get_file_infos(target, message, IDMEF_FILE_CATEGORY_CURRENT);
Note: See TracChangeset for help on using the changeset viewer.