Changeset 452


Ignore:
Timestamp:
Jun 26, 2014, 8:01:54 PM (10 years ago)
Author:
katerina
Message:

Fix for ticket #353 (multiple exclusions for SUID check).

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.in

    r448 r452  
    17431743sh_utmp.o: $(srcsrc)/sh_utmp.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_utmp.h $(srcinc)/sh_pthread.h $(srcinc)/sh_inotify.h
    17441744sh_kern.o: $(srcsrc)/sh_kern.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_kern.h sh_ks_xor.h $(srcinc)/sh_unix.h $(srcinc)/sh_hash.h
    1745 sh_suidchk.o: $(srcsrc)/sh_suidchk.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_suidchk.h $(srcinc)/sh_hash.h $(srcinc)/sh_unix.h $(srcinc)/sh_files.h $(srcinc)/sh_schedule.h $(srcinc)/sh_calls.h
     1745sh_suidchk.o: $(srcsrc)/sh_suidchk.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_suidchk.h $(srcinc)/sh_hash.h $(srcinc)/sh_unix.h $(srcinc)/sh_files.h $(srcinc)/sh_schedule.h $(srcinc)/sh_calls.h $(srcinc)/zAVLTree.h
    17461746sh_srp.o: $(srcsrc)/sh_srp.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_tiger.h $(srcinc)/sh_mem.h $(srcinc)/sh_utils.h $(srcinc)/sh_srp.h $(srcinc)/bignum.h $(srcinc)/CuTest.h
    17471747sh_fifo.o: $(srcsrc)/sh_fifo.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_mem.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_fifo.h
  • trunk/depend.dep

    r448 r452  
    2121sh_utmp.o: $(srcsrc)/sh_utmp.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_utmp.h $(srcinc)/sh_pthread.h $(srcinc)/sh_inotify.h
    2222sh_kern.o: $(srcsrc)/sh_kern.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_kern.h sh_ks_xor.h $(srcinc)/sh_unix.h $(srcinc)/sh_hash.h
    23 sh_suidchk.o: $(srcsrc)/sh_suidchk.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_suidchk.h $(srcinc)/sh_hash.h $(srcinc)/sh_unix.h $(srcinc)/sh_files.h $(srcinc)/sh_schedule.h $(srcinc)/sh_calls.h
     23sh_suidchk.o: $(srcsrc)/sh_suidchk.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_modules.h $(srcinc)/sh_suidchk.h $(srcinc)/sh_hash.h $(srcinc)/sh_unix.h $(srcinc)/sh_files.h $(srcinc)/sh_schedule.h $(srcinc)/sh_calls.h $(srcinc)/zAVLTree.h
    2424sh_srp.o: $(srcsrc)/sh_srp.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_tiger.h $(srcinc)/sh_mem.h $(srcinc)/sh_utils.h $(srcinc)/sh_srp.h $(srcinc)/bignum.h $(srcinc)/CuTest.h
    2525sh_fifo.o: $(srcsrc)/sh_fifo.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_mem.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_fifo.h
  • trunk/depend.sum

    r448 r452  
    1 3861086825
     13192621362
  • trunk/include/zAVLTree.h

    r363 r452  
    7474extern void *zAVLNext (zAVLCursor *avlcursor);
    7575
     76extern char * zAVL_string_get (zAVLTree * tree, char * key);
     77/* uses strdup to insert a copy */
     78extern int zAVL_string_set (zAVLTree ** tree, const char * key);
     79extern void zAVL_string_reset (zAVLTree * tree);
     80
    7681#endif
  • trunk/src/cutest_zAVLTree.c

    r366 r452  
    3737  int result;
    3838  int counter = 0;
     39
     40  char * str;
    3941
    4042  struct ztest z1 = { "abc"  , 1 };
     
    483485  CuAssertTrue (tc, iz8.iname == 0);
    484486
     487  ztest_tree = NULL;
     488  str = strdup("foo");
     489  result = zAVL_string_set(&ztest_tree, str);
     490  CuAssertTrue(tc, 0 == result);
     491  CuAssertPtrNotNull(tc, ztest_tree);
     492  CuAssertStrEquals(tc, "foo", zAVL_string_get(ztest_tree, "foo"));
     493
     494  str = strdup("bar");
     495  result = zAVL_string_set(&ztest_tree, str);
     496  CuAssertTrue(tc, 0 == result);
     497  CuAssertStrEquals(tc, "foo", zAVL_string_get(ztest_tree, "foo"));
     498  CuAssertStrEquals(tc, "bar", zAVL_string_get(ztest_tree, "bar"));
     499
     500  str = strdup("balloon");
     501  result = zAVL_string_set(&ztest_tree, str);
     502  CuAssertTrue(tc, 0 == result);
     503  CuAssertStrEquals(tc, "foo", zAVL_string_get(ztest_tree, "foo"));
     504  CuAssertStrEquals(tc, "bar", zAVL_string_get(ztest_tree, "bar"));
     505  CuAssertStrEquals(tc, "balloon", zAVL_string_get(ztest_tree, "balloon"));
     506
     507  str = zAVL_string_get(ztest_tree, "foobar");
     508  CuAssertTrue(tc, str == NULL);
     509  str = zAVL_string_get(ztest_tree, "");
     510  CuAssertTrue(tc, str == NULL);
     511  str = zAVL_string_get(ztest_tree, NULL);
     512  CuAssertTrue(tc, str == NULL);
     513
     514  zAVL_string_reset(ztest_tree);
     515  str = zAVL_string_get(ztest_tree, "foo");
     516  CuAssertTrue(tc, str == NULL);
     517  str = zAVL_string_get(ztest_tree, "bar");
     518  CuAssertTrue(tc, str == NULL);
     519  str = zAVL_string_get(ztest_tree, "balloon");
     520  CuAssertTrue(tc, str == NULL);
    485521
    486522}
  • trunk/src/sh_suidchk.c

    r440 r452  
    8282#include "sh_schedule.h"
    8383#include "sh_calls.h"
     84#include "zAVLTree.h"
    8485
    8586
     
    146147static int     ShSuidchkQDelete  = S_FALSE;
    147148static int     ShSuidchkSeverity = SH_ERR_SEVERE;
    148 static char *  ShSuidchkExclude  = NULL;
    149 static size_t  ExcludeLen        = 0;
    150149
    151150static time_t  FileLimNow        = 0;
     
    155154
    156155static sh_schedule_t * ShSuidchkSched = NULL;
     156
     157
     158static zAVLTree *  ShSuidchkExclude  = NULL;
     159static void sh_suid_exclude_free()
     160{
     161  zAVL_string_reset(ShSuidchkExclude);
     162  ShSuidchkExclude  = NULL;
     163  return;
     164}
     165static int sh_suid_exclude_add(const char * str)
     166{
     167  size_t len;
     168  int    ret;
     169  char * key = sh_util_strdup(str);
     170
     171  len = sl_strlen (key);
     172  if (len && key[len-1] == '/')
     173    {
     174      key[len-1] = '\0';
     175    }
     176  ret = zAVL_string_set(&ShSuidchkExclude, key);
     177  SH_FREE(key);
     178  return ret;
     179}
     180
    157181
    158182static char *
     
    179203  ShSuidchkSeverity = SH_ERR_SEVERE;
    180204  if (ShSuidchkExclude != NULL)
    181     SH_FREE(ShSuidchkExclude);
    182   ShSuidchkExclude  = NULL;
    183   ExcludeLen        = 0;
     205    sh_suid_exclude_free(ShSuidchkExclude);
    184206
    185207  FileLimNow        = 0;
     
    11361158        if (tlen >= 6 && 0 == strcmp(&tmp[tlen-6], _("/.gvfs")))
    11371159          elevel = SH_ERR_NOTICE;
     1160        else if (tlen >= 5 && 0 == strcmp(&((mnt->mnt_dir)[tlen-5]), _("/gvfs")))
     1161          elevel = SH_ERR_NOTICE;
    11381162
    11391163        /* If we are scanning a temporary directory where dirs and files
     
    11561180        if (/*@-usedef@*/S_ISDIR(buf.st_mode)/*@+usedef@*/ &&
    11571181            (ShSuidchkExclude == NULL ||
    1158              0 != strcmp(tmpcat, ShSuidchkExclude)))
     1182             NULL == zAVL_string_get(ShSuidchkExclude, tmpcat)))
    11591183          {
    11601184            /* fs is a STATIC string or NULL
     
    15291553int sh_suidchk_set_exclude (const char * c)
    15301554{
     1555  int ret = 0;
    15311556  SL_ENTER(_("sh_suidchk_set_exclude"));
    15321557
     
    15391564    {
    15401565      if (ShSuidchkExclude != NULL)
    1541         SH_FREE(ShSuidchkExclude);
    1542       ShSuidchkExclude = NULL;
     1566        sh_suid_exclude_free();
    15431567      SL_RETURN(0, _("sh_suidchk_set_exclude"));
    15441568    }
    15451569
    1546   if (ShSuidchkExclude != NULL)
    1547     SH_FREE(ShSuidchkExclude);
    1548 
    1549   ShSuidchkExclude = sh_util_strdup (c);
    1550   ExcludeLen       = sl_strlen (ShSuidchkExclude);
    1551   if (ShSuidchkExclude && ShSuidchkExclude[ExcludeLen-1] == '/')
    1552     {
    1553       ShSuidchkExclude[ExcludeLen-1] = '\0';
    1554       ExcludeLen--;
    1555     }
    1556   SL_RETURN(0, _("sh_suidchk_set_exclude"));
     1570  ret = sh_suid_exclude_add(c);
     1571
     1572  SL_RETURN(ret, _("sh_suidchk_set_exclude"));
    15571573}
    15581574
  • trunk/src/zAVLTree.c

    r383 r452  
    3333#include "zAVLTree.h"
    3434
     35/* Interface for handling "string only" items rw 2014-06-26
     36 */
     37static zAVLKey zstring_key (void const * arg)
     38{
     39  return (zAVLKey) arg;
     40}
     41static void zfree_string (void * inptr)
     42{
     43  char * str = (char *) inptr;
     44  str[0] = '\0';
     45  free (str);
     46  return;
     47}
     48void zAVL_string_reset (zAVLTree * tree)
     49{
     50  if (tree)
     51    zAVLFreeTree (tree, zfree_string);
     52  return;
     53}
     54int zAVL_string_set (zAVLTree ** tree, const char * key)
     55{
     56  if (tree && key)
     57    {
     58      zAVLTree * itree = (*tree);
     59      if (!itree)
     60        {
     61          itree = zAVLAllocTree (zstring_key, zAVL_KEY_STRING);
     62          if (!itree)
     63            {
     64              return -1;
     65            }
     66        }
     67      *tree = itree;
     68      return zAVLInsert (itree, strdup(key));
     69    }
     70  return -1;
     71}
     72char * zAVL_string_get (zAVLTree * tree, char * key)
     73{
     74  /* zAVLSearch() checks for NULL tree
     75   */
     76  if (key)
     77    {
     78      return ((char *) zAVLSearch (tree, key));
     79    }
     80  return NULL;
     81}
     82
     83
    3584/* Wed Nov 23 17:57:42 CET 2005 rw: introduce third argument in
    3685 * zAVLCloseSearchNode() to avoid redundant strcmp
     
    86135  zAVLTree *rc;
    87136
    88   rc = malloc(sizeof(zAVLTree));
     137  rc = calloc(1, sizeof(zAVLTree));
    89138  if (rc == NULL)
    90139    return NULL;
     
    130179  int       ok;
    131180
    132   newnode = malloc(sizeof(zAVLNode));
     181  newnode = calloc(1, sizeof(zAVLNode));
    133182  if (newnode == NULL)
    134183    return -1;
Note: See TracChangeset for help on using the changeset viewer.