Changeset 577


Ignore:
Timestamp:
May 1, 2022, 12:24:37 AM (2 years ago)
Author:
katerina
Message:

Implement ticket #465 (server option to register alias for hostname).

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r572 r577  
    1212dnl start
    1313dnl
    14 AM_INIT_AUTOMAKE(samhain, 4.4.7)
     14AM_INIT_AUTOMAKE(samhain, 4.4.8)
    1515AC_DEFINE([SAMHAIN], 1, [Application is samhain])
    1616AC_CANONICAL_HOST
  • trunk/docs/Changelog

    r576 r577  
    1 4.4.7:
     14.4.8:
     2        * new server option Alias=alias@hostname (based on
     3        patch by A. Hofland)
     4
     54.4.7 (07-03-2022):
    26        * fix compile error on MacOS
    37        * disable dnmalloc for gcc 11 (regexec does not work)
  • trunk/include/sh_cat.h

    r525 r577  
    229229 MSG_TCP_EBGN,   
    230230                 
    231  MSG_TCP_CREG,   
     231 MSG_TCP_CREG,
     232 MSG_TCP_AREG,
    232233 MSG_TCP_FAUTH,   
    233234 MSG_TCP_TIMOUT, 
  • trunk/include/sh_string.h

    r265 r577  
    6868 * lengths in 'lengths'.
    6969 * A single delimiter will return two empty fields.
     70 * The returned array is allocated memory, and its fields
     71 * are modified parts of the 'line' parameter.
    7072 */
    7173char ** split_array(char *line, unsigned int * nfields,
     
    7880 * An empty string will return zero fields.
    7981 * If nfields < actual fields, last string will be remainder.
     82 * The returned array is allocated memory, and its fields
     83 * are modified parts of the 'line' parameter.
    8084 */
    8185char ** split_array_ws(char *line, unsigned int * nfields, size_t * lengths);
  • trunk/include/sh_xfer.h

    r481 r577  
    8484void sh_xfer_html_write(void);
    8585
     86/* register an alias
     87 */
     88int sh_xfer_register_alias (const char * str);
     89
    8690/* register a client
    8791 */
  • trunk/src/sh_cat.c

    r525 r577  
    225225
    226226  { MSG_TCP_CREG,    SH_ERR_ALL,     TCP,   N_("msg=\"Registered %s, salt %s, verifier %s\"")},
     227  { MSG_TCP_AREG,    SH_ERR_ALL,     TCP,   N_("msg=\"Registered %s, hostname %s\"")},
    227228  { MSG_TCP_FAUTH,   SH_ERR_INFO,    TCP,   N_("msg=\"Force authentication\" host=\"%s\"")},
    228229
     
    569570
    570571  { MSG_TCP_CREG,    SH_ERR_ALL,     TCP,   N_("msg=<Registered %s, salt %s, verifier %s>")},
     572  { MSG_TCP_AREG,    SH_ERR_ALL,     TCP,   N_("msg=<Registered %s, hostname %s>")},
    571573  { MSG_TCP_FAUTH,   SH_ERR_INFO,    TCP,   N_("msg=<Force authentication>, client=<%s>")},
    572574
  • trunk/src/sh_readconf.c

    r550 r577  
    11481148  { N_("setserverinterface"),  SH_SECTION_SRV,  SH_SECTION_MISC,
    11491149    sh_xfer_set_interface },
     1150  { N_("alias"),               SH_SECTION_CLIENTS,           SH_SECTION_NONE,
     1151    sh_xfer_register_alias },
    11501152  { N_("client"),              SH_SECTION_CLIENTS,           SH_SECTION_NONE,
    11511153    sh_xfer_register_client },
  • trunk/src/sh_xfer_server.c

    r575 r577  
    419419 */
    420420
     421typedef struct client_alias {
     422  char                  * alias;
     423  char                  * hostname;
     424} alias_t;
     425
    421426#include "zAVLTree.h"
    422427
     
    435440
    436441/* Function to return the key for indexing
    437  * the argument
     442 * the argument (for the client list)
    438443 */
    439444zAVLKey sh_avl_key (void const * arg)
     
    444449
    445450zAVLTree * all_clients = NULL;
     451
     452/* Function to return the key for indexing
     453 * the argument (for the aliases list)
     454 */
     455zAVLKey sh_avl_alias (void const * arg)
     456{
     457  const alias_t * sa = (const alias_t *) arg;
     458  return (zAVLKey) sa->alias;
     459}
     460
     461zAVLTree * all_aliases = NULL;
    446462
    447463void sh_xfer_html_write()
     
    470486
    471487
    472 /* the destructor
     488/* the destructor (client list item)
    473489 */
    474490void free_client(void * inptr)
     
    490506  SH_FREE(here);
    491507  SL_RET0(_("free_client"));
     508}
     509
     510/* the destructor (alias list item)
     511 */
     512void free_alias(void * inptr)
     513{
     514  alias_t * here;
     515
     516  SL_ENTER(_("free_alias"));
     517  if (inptr == NULL)
     518    SL_RET0(_("free_alias"));
     519  else
     520    here = (alias_t *) inptr;
     521
     522  if (here->alias != NULL)
     523    SH_FREE(here->alias);
     524  if (here->hostname != NULL)
     525    SH_FREE(here->hostname);
     526  SH_FREE(here);
     527  SL_RET0(_("free_alias"));
     528}
     529
     530int sh_xfer_register_alias (const char * str)
     531{
     532  alias_t    * newalias;
     533  alias_t    * testalias;
     534
     535  const char * ptr;
     536  int          sepnum  = 0;
     537  int          sep     = 0;
     538  register int i       = 0;
     539  int          siz_str = 0;
     540
     541  SL_ENTER(_("sh_xfer_register_alias"));
     542
     543  ptr = str;
     544  while (*ptr) {
     545    if (*ptr == '@' && sepnum < 1)
     546      {
     547        sep = i;
     548        ++sepnum;
     549      }
     550    ++ptr; ++i;
     551  }
     552
     553  if (all_aliases == NULL)
     554    {
     555      all_aliases = zAVLAllocTree (sh_avl_alias, zAVL_KEY_STRING);
     556      if (all_aliases == NULL)
     557        {
     558          (void) safe_logger (0, 0, NULL);
     559          aud__exit(FIL__, __LINE__, EXIT_FAILURE);
     560        }
     561    }
     562
     563  if ((sepnum == 1) && (sep > 0) && (i > (sep + 1)))
     564    {
     565      newalias                  = SH_ALLOC (sizeof(alias_t));
     566      newalias->alias           = SH_ALLOC (sep+1);
     567      newalias->hostname        = SH_ALLOC (sl_strlen(str)-sep);
     568
     569      /* truncate */
     570      sl_strlcpy(newalias->alias,  &str[0],        sep+1);
     571      sh_tolower(newalias->alias);
     572
     573      /* truncate */
     574      sl_strlcpy(newalias->hostname,  &str[sep+1], sl_strlen(str)-sep);
     575      sh_tolower(newalias->hostname);
     576
     577      testalias = (alias_t *) zAVLSearch (all_aliases, newalias->alias);
     578
     579      if (testalias != NULL)
     580        {
     581          /* keep the alias but replace the hostname with the new one */
     582          SH_FREE(testalias->hostname);
     583          siz_str = strlen (newalias->hostname) + 1;
     584          testalias->hostname = SH_ALLOC (siz_str);
     585          sl_strlcpy(testalias->hostname, newalias->hostname, siz_str);
     586         
     587          free_alias(newalias);
     588          SL_RETURN( 0, _("sh_xfer_register_alias"));
     589        }
     590      else
     591        {
     592          if (0 == zAVLInsert (all_aliases, newalias))
     593            {
     594              sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_AREG,
     595                              newalias->alias,
     596                              newalias->hostname);
     597              SL_RETURN( 0, _("sh_xfer_register_alias"));
     598            }
     599        }
     600    }
     601  SL_RETURN (-1, _("sh_xfer_register_alias"));
    492602}
    493603
     
    10531163client_t * search_register(sh_conn_t * conn, int pos)
    10541164{
     1165  alias_t  * this_alias;
    10551166  client_t * this_client;
    10561167  char       peer_ip[SH_IP_BUF];
     
    10861197        {
    10871198          sl_strlcpy(peer_name, peer_ip, MAXHOSTNAMELEN + 1);
     1199        }
     1200      else
     1201        {
     1202          this_alias = zAVLSearch(all_aliases, peer_name);
     1203          if (this_alias)
     1204            {
     1205              sl_strlcpy(peer_name, this_alias->hostname, MAXHOSTNAMELEN + 1);
     1206            }
    10881207        }
    10891208
     
    33753494            sh_xfer_mark_dead ();
    33763495
     3496            /* free the aliases list */
     3497            zAVLFreeTree (all_aliases, free_alias);
     3498            all_aliases = NULL;
     3499
    33773500            reset_count_dev_console();
    33783501            reset_count_dev_time();
  • trunk/test/testrun_2g.sh

    r551 r577  
    204204        UUID=$(uuidgen)
    205205        mv ./file.delta file.${SH_LOCALHOST}.${UUID}
    206         cp file.${SH_LOCALHOST}.${UUID} "./file.${ALTHOST}.${UUID}"
     206        if [ "x${SH_LOCALHOST}" != "x${ALTHOST}" ]
     207        then
     208            cp file.${SH_LOCALHOST}.${UUID} "./file.${ALTHOST}.${UUID}"
     209        fi
    207210       
    208211        #
     
    223226        fi
    224227
     228        NHOSTS=1
     229       
    225230        ./yulectl -c "DELTA:${UUID}" ${SH_LOCALHOST}
    226231        if [ $? -ne 0 ]; then
     
    229234            return 1
    230235        fi
    231         ./yulectl -c "DELTA:${UUID}" ${ALTHOST}
    232         if [ $? -ne 0 ]; then
    233             [ -z "$verbose" ] || log_msg_fail "yulectl (2)";
    234             kill $PROC_S; kill $PROC_Y;
    235             return 1
    236         fi
     236
     237        if [ "x${SH_LOCALHOST}" != "x${ALTHOST}" ]
     238        then
     239            ./yulectl -c "DELTA:${UUID}" ${ALTHOST}
     240            NHOSTS=2
     241            if [ $? -ne 0 ]; then
     242                [ -z "$verbose" ] || log_msg_fail "yulectl (2)";
     243                kill $PROC_S; kill $PROC_Y;
     244                return 1
     245            fi
     246        fi
     247       
    237248        NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
    238         if [ $NR -ne 2 ]; then
     249        if [ $NR -ne $NHOSTS ]; then
    239250            [ -z "$verbose" ] || log_msg_fail "yulectl (3)";
    240251            [ -z "$verbose" ] || ./yulectl -c LIST
     
    249260        done
    250261        #
    251         NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
     262        NR=$( ./yulectl -c LISTALL | grep ${UUID} | grep SENT | grep -v grep | wc -l )
     263        # NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
    252264        if [ $NR -ne 1 ]; then
    253265            [ -z "$verbose" ] || log_msg_fail "yulectl (4)";
     
    330342        else
    331343            mv ./file.delta file.${SH_LOCALHOST}.${UUID}
    332             cp file.${SH_LOCALHOST}.${UUID} "./file.${ALTHOST}.${UUID}"
     344            if [ "x${SH_LOCALHOST}" != "x${ALTHOST}" ]
     345            then
     346                cp file.${SH_LOCALHOST}.${UUID} "./file.${ALTHOST}.${UUID}"
     347            fi
    333348        fi
    334349        [ -z "$verbose" ] || log_msg_ok    "... DeltaDB copied as file.${SH_LOCALHOST}.${UUID} ...";
     
    351366        fi
    352367
     368        NHOSTS=1
     369       
    353370        ./yulectl -c "DELTA:${UUID}" ${SH_LOCALHOST}
    354371        if [ $? -ne 0 ]; then
     
    357374            return 1
    358375        fi
    359         ./yulectl -c "DELTA:${UUID}" ${ALTHOST}
    360         if [ $? -ne 0 ]; then
    361             [ -z "$verbose" ] || log_msg_fail "yulectl (2)";
    362             kill $PROC_S; kill $PROC_Y;
    363             return 1
    364         fi
     376       
     377        if [ "x${SH_LOCALHOST}" != "x${ALTHOST}" ]
     378        then
     379            ./yulectl -c "DELTA:${UUID}" ${ALTHOST}
     380            NHOSTS=2
     381            if [ $? -ne 0 ]; then
     382                [ -z "$verbose" ] || log_msg_fail "yulectl (2)";
     383                kill $PROC_S; kill $PROC_Y;
     384                return 1
     385            fi
     386        fi
     387       
    365388        NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
    366         if [ $NR -ne 2 ]; then
     389        if [ $NR -ne $NHOSTS ]; then
    367390            [ -z "$verbose" ] || log_msg_fail "yulectl (3)";
    368391            [ -z "$verbose" ] || ./yulectl -c LIST
     
    378401        done
    379402        #
    380         NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
     403        NR=$( ./yulectl -c LISTALL | grep ${UUID} | grep SENT | grep -v grep | wc -l )
    381404        if [ $NR -ne 1 ]; then
    382             [ -z "$verbose" ] || log_msg_fail "yulectl (4)";
     405            [ -z "$verbose" ] || log_msg_fail "yulectl (4): ${UUID}";
    383406            [ -z "$verbose" ] || ./yulectl -c LISTALL
    384             kill $PROC_S; kill $PROC_Y;
    385             return 1
    386         fi
    387         [ -z "$verbose" ] || OLINE=$( ./yulectl -c LIST | grep ${UUID} )
     407            [ -z "$verbose" ] || echo "(now just LIST)"
     408            [ -z "$verbose" ] || ./yulectl -c LIST
     409            kill $PROC_S; kill $PROC_Y;
     410            return 1
     411        fi
     412        [ -z "$verbose" ] || OLINE=$( ./yulectl -c LISTALL | grep ${UUID} )
    388413        [ -z "$verbose" ] || echo "${OLINE}"
    389414
     
    607632        chmod 644 ./file.${SH_LOCALHOST}
    608633
    609         cp    ./testrc_2       "./rc.${ALTHOST}"
    610         cp    ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
    611         chmod 644 ./rc.${ALTHOST}
    612         chmod 644 ./file.${ALTHOST}
     634        if [ "x${SH_LOCALHOST}" != "x${ALTHOST}" ]
     635        then
     636            cp    ./testrc_2       "./rc.${ALTHOST}"
     637            cp    ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
     638            chmod 644 ./rc.${ALTHOST}
     639            chmod 644 ./file.${ALTHOST}
     640        fi
    613641}
    614642
Note: See TracChangeset for help on using the changeset viewer.