Changeset 86


Ignore:
Timestamp:
Jan 20, 2007, 11:04:59 PM (18 years ago)
Author:
rainer
Message:

More thorough fix for ticket #47, and corresponding regression test.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/sh_error.h

    r27 r86  
    117117void sh_error_only_stderr (int flag);
    118118
     119/* facilities unsafe for closeall()
     120 */
     121void sh_error_enable_unsafe (int flag);
     122
    119123/* set syslog facility
    120124 */
  • trunk/include/sh_gpg.h

    r1 r86  
    2727int sh_gpg_check_sign (long file_1, long file_2, int what);
    2828
     29/* log successful startup
     30 */
     31void sh_gpg_log_startup ();
     32
    2933#endif
    3034
  • trunk/src/samhain.c

    r84 r86  
    14431443
    14441444#if (defined(WITH_GPG) || defined(WITH_PGP))
    1445   /* do nothing -- we exit earlier if error */
     1445  /* log startup */
     1446  sh_gpg_log_startup ();
    14461447#else
    14471448  sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_1H,
     
    14651466    {
    14661467#if (defined(WITH_GPG) || defined(WITH_PGP))
    1467       /* do nothing -- we exit earlier if error */
     1468      /* log startup */
     1469      sh_gpg_log_startup ();
    14681470#else
    14691471      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_2H,
     
    14761478    {
    14771479#if (defined(WITH_GPG) || defined(WITH_PGP))
    1478       /* do nothing -- we exit earlier if error */
     1480      /* log startup */
     1481      sh_gpg_log_startup ();
    14791482#else
    14801483      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_1H,
  • trunk/src/sh_error.c

    r65 r86  
    110110int  OnlyStderr    = S_TRUE;
    111111
     112/* --- Enable facilities not safe for closeall(). ---
     113 */
     114int  enableUnsafe  = S_FALSE;
    112115
    113116/*********************************************
     
    145148{
    146149  OnlyStderr    = flag;
     150  return;
     151}
     152
     153void sh_error_enable_unsafe (int flag)
     154{
     155  enableUnsafe    = flag;
    147156  return;
    148157}
     
    10261035  /* Full logging enabled.
    10271036   */
    1028   if (OnlyStderr == BAD)  /* full error logging enabled */
     1037  if (OnlyStderr == S_FALSE)  /* full error logging enabled */
    10291038    {
    10301039
     
    10831092          class != AUD)
    10841093        {
    1085           if (database_block == 0)
     1094          if (database_block == 0 && enableUnsafe == S_TRUE)
    10861095            {
    10871096              /* truncates; query_max is 16k
     
    12091218          )
    12101219        {
    1211           if (prelude_block == 0)
     1220          if (prelude_block == 0 && enableUnsafe == S_TRUE)
    12121221            {
    12131222              /* will truncate to 998 bytes
  • trunk/src/sh_gpg.c

    r34 r86  
    115115
    116116#ifdef GPG_HASH
     117
    117118static int sh_gpg_checksum (SL_TICKET checkfd, int flag)
    118119{
     
    202203}
    203204#endif
     205
     206struct startup_info {
     207  long   line;
     208  char * program;
     209  long   uid;
     210  char * path;
     211  char * key_uid;
     212  char * key_id;
     213};
     214
     215static struct startup_info startInfo = { 0, NULL, 0, NULL, NULL, NULL };
     216
     217void sh_gpg_log_startup ()
     218{
     219  if (startInfo.program != NULL)
     220    {
     221      sh_error_handle ((-1), FIL__, startInfo.line, 0, MSG_START_GH,
     222                       startInfo.program, startInfo.uid,
     223                       startInfo.path,
     224                       startInfo.key_uid, startInfo.key_id);
     225    }
     226  return;
     227}
     228
     229static void sh_gpg_fill_startup (long line, char * program, long uid, char * path,
     230                                 char * key_uid, char * key_id)
     231{
     232  startInfo.line    = line;
     233  startInfo.program = sh_util_strdup(program);
     234  startInfo.uid     = uid;
     235  startInfo.path    = sh_util_strdup(path);
     236  startInfo.key_uid = sh_util_strdup(key_uid);
     237  startInfo.key_id  = sh_util_strdup(key_id);
     238  return;
     239}
    204240
    205241static FILE * sh_gpg_popen (sh_gpg_popen_t  *source, int fd,
     
    9681004            {
    9691005              tmp  = sh_util_safe_name(gp.conf_id);
    970               sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_GH,
     1006              sh_gpg_fill_startup (
     1007                                   /* sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_GH, */
    9711008                               sh.prg_name, sh.real.uid,
    9721009                               (sh.flag.hidefile == S_TRUE) ?
     
    9951032        {
    9961033          tmp = sh_util_safe_name(gp.conf_id);
    997           sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_GH,
     1034          sh_gpg_fill_startup (__LINE__,
     1035          /* sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_GH, */
    9981036                           sh.prg_name, sh.real.uid,
    9991037                           (sh.flag.hidefile == S_TRUE) ?
  • trunk/src/sh_prelude.c

    r40 r86  
    967967}
    968968
    969 
     969/* Allow initialization of prelude; to be called
     970 * after forking the daemon. Delays heartbeat
     971 * start after config read until it is safe.
     972 */
    970973void sh_prelude_reset(void)
    971974{
  • trunk/src/sh_unix.c

    r84 r86  
    18801880        }
    18811881
     1882      sh_error_enable_unsafe (S_TRUE);
    18821883#if defined(HAVE_LIBPRELUDE)
    18831884      sh_prelude_reset ();
     
    19131914    {
    19141915      sh_unix_closeall(3, -1);  /* if not daemon */
     1916      sh_error_enable_unsafe (S_TRUE);
    19151917#if defined(HAVE_LIBPRELUDE)
    19161918      sh_prelude_reset ();
  • trunk/test/testrc_2.in

    r34 r86  
     1-----BEGIN PGP SIGNED MESSAGE-----
     2Hash: SHA1
     3
    14#####################################################################
    25#
     
    103106#AddToDBHash=log_msg
    104107# AddToDBHash=log_host
    105 
     108UsePersistent = True
    106109
    107110[Utmp]
     
    201204
    202205[Clients]
     206-----BEGIN PGP SIGNATURE-----
     207Version: GnuPG v1.4.2.2 (GNU/Linux)
     208
     209iD8DBQFFsTXBGq0myA9XH2wRAju6AKDsNT3cVYHVs4z+ZHdFgPwOdvESewCfcIAY
     210RsnSZyhwBGtlA+rf35/gcQw=
     211=Rb0p
     212-----END PGP SIGNATURE-----
  • trunk/test/testrun_2c.sh

    r85 r86  
    2424CLIENT_BUILDOPTS="--quiet  $TRUST --prefix=$PW_DIR --with-tmp-dir=$PW_DIR --localstatedir=$PW_DIR --enable-network=client --disable-mail --disable-external-scripts --enable-login-watch --enable-xml-log --enable-db-reload --with-logserver=localhost --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock"; export CLIENT_BUILDOPTS
    2525
     26MAXTEST=3; export MAXTEST
     27
     28testrun_threesockets () {
     29
     30    GPG="$1"
     31
     32    [ -z "$verbose" ] || {
     33        echo;
     34        echo Working directory: $PW_DIR; echo MAKE is $MAKE; echo GPG is $GPG;
     35        echo;
     36    }
     37
     38    [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
     39
     40    if test -r "Makefile"; then
     41        $MAKE distclean
     42    fi
     43
     44    ${TOP_SRCDIR}/configure --with-gpg=${GPG} --with-checksum=no ${SERVER_BUILDOPTS} >/dev/null 2>&1
     45
     46    if test x$? = x0; then
     47        [ -z "$verbose" ] ||     log_msg_ok "configure...";
     48        $MAKE  > /dev/null 2>>test_log
     49        if test x$? = x0; then
     50            [ -z "$verbose" ] || log_msg_ok "make...";
     51        else
     52            [ -z "$quiet" ] &&   log_msg_fail "make...";
     53            return 1
     54        fi
     55    else
     56        [ -z "$quiet" ] &&       log_msg_fail "configure...";
     57        return 1
     58    fi
     59
     60    rm -f ./.samhain_file
     61    rm -f ./.samhain_log
     62    rm -f ./.samhain_lock
     63    rm -f ./rc.${SH_LOCALHOST}
     64    rm -f ./file.${SH_LOCALHOST}
     65   
     66    cp ${SCRIPTDIR}/testrc_2.in testrc_2
     67   
     68    ORIGINAL="DatabaseSeverity=none"
     69    REPLACEMENT="DatabaseSeverity=warn"
     70    ex -s $RCFILE <<EOF
     71%s/$ORIGINAL/$REPLACEMENT/g
     72wq
     73EOF
     74
     75    ORIGINAL="MailSeverity=none"
     76    REPLACEMENT="MailSeverity=crit"
     77    ex -s $RCFILE <<EOF
     78%s/$ORIGINAL/$REPLACEMENT/g
     79wq
     80EOF
     81    return 0
     82 }
     83
    2684check_mysql_log () {
    2785    DATE="$1"
     
    58116    return 0
    59117}
    60 
    61 MAXTEST=2; export MAXTEST
    62118
    63119testrun2c ()
     
    127183        PID=`cat .samhain_lock`
    128184        kill $PID
     185    else
     186        log_fail 2 ${MAXTEST} "Three sockets open";
     187    fi
     188    #
     189    GPG=`find_path gpg`
     190    if [ -z "$GPG" ]; then
     191        log_skip 1 $MAXTEST 'gpg not found in $PATH'
     192    else
     193        eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
     194        if [ $? -ne 0 ]; then
     195            log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
     196        else
     197            testrun_threesockets "$GPG"
     198
     199            if [ -f ./yule ]; then
     200                ./yule -D >/dev/null 2>>test_log
     201                five_sec_sleep
     202                netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
     203                if [ $? -ne 0 ]; then
     204                    [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Three sockets open (gpg)";
     205                else
     206                    NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
     207                    if [ $NSOCK -ne 2 ]; then
     208                        [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Three sockets open (gpg)";
     209                        netstat -pand 2>/dev/null | grep yule
     210                    else
     211                        [ -z "$quiet" ] && log_ok   3 ${MAXTEST} "Three sockets open (gpg)";
     212                    fi
     213                fi
     214                PID=`cat .samhain_lock`
     215                kill $PID
     216            else
     217                log_fail 3 ${MAXTEST} "Three sockets open (gpg)";
     218            fi
     219        fi
    129220    fi
    130221    #
Note: See TracChangeset for help on using the changeset viewer.