- Timestamp:
- Aug 3, 2014, 4:29:51 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docs/Changelog
r456 r457 10 10 overflow check (the required buffer length information for the check 11 11 wasn't provided) 12 * Fixed incorrect logic in setting the ALLIGNORE flag (more specific 13 directory / file directives were ignored) 12 14 13 15 3.1.1 (01-0-2014): -
trunk/include/sh_files.h
r415 r457 31 31 }; 32 32 33 /* Check whether a file is in the config 34 */ 35 char * sh_files_findfile(const char * path); 36 37 /* Find the most specific directory in the config 38 */ 39 char * sh_files_find_mostspecific_dir(const char * path); 33 40 34 41 /* free a directory listing -
trunk/include/zAVLTree.h
r452 r457 74 74 extern void *zAVLNext (zAVLCursor *avlcursor); 75 75 76 extern char * zAVL_string_get (zAVLTree * tree, c har * key);76 extern char * zAVL_string_get (zAVLTree * tree, const char * key); 77 77 /* uses strdup to insert a copy */ 78 78 extern int zAVL_string_set (zAVLTree ** tree, const char * key); -
trunk/src/sh_files.c
r440 r457 521 521 } 522 522 523 static zAVLTree * fileTree = NULL; 524 static zAVLTree * dirTree = NULL; 525 526 static void clear_lists() 527 { 528 if (fileTree) { 529 zAVL_string_reset(fileTree); 530 fileTree = NULL; 531 } 532 if (dirTree) { 533 zAVL_string_reset(dirTree); 534 dirTree = NULL; 535 } 536 return; 537 } 538 539 static void add_to_filelist(zAVLTree * tree) 540 { 541 dirstack_t * ptr; 542 zAVLCursor avlcursor; 543 544 SL_ENTER(_("add_to_filelist")); 545 546 SH_MUTEX_LOCK(mutex_zfiles); 547 for (ptr = (dirstack_t *) zAVLFirst(&avlcursor, tree); ptr; 548 ptr = (dirstack_t *) zAVLNext(&avlcursor)) 549 zAVL_string_set (&fileTree, ptr->name); 550 SH_MUTEX_UNLOCK(mutex_zfiles); 551 SL_RET0(_("add_to_filelist")); 552 } 553 static void add_to_dirlist(zAVLTree * tree) 554 { 555 dirstack_t * ptr; 556 zAVLCursor avlcursor; 557 558 SL_ENTER(_("add_to_dirlist")); 559 560 SH_MUTEX_LOCK(mutex_zfiles); 561 for (ptr = (dirstack_t *) zAVLFirst(&avlcursor, tree); ptr; 562 ptr = (dirstack_t *) zAVLNext(&avlcursor)) 563 zAVL_string_set (&dirTree, ptr->name); 564 SH_MUTEX_UNLOCK(mutex_zfiles); 565 SL_RET0(_("add_to_dirlist")); 566 } 567 char * sh_files_findfile(const char * path) 568 { 569 return zAVL_string_get (fileTree, path); 570 } 571 static char * intern_find_morespecific_dir(zAVLTree * tree, 572 const char * path, size_t * len) 573 { 574 dirstack_t * ptr; 575 zAVLCursor avlcursor; 576 size_t l_path = strlen(path); 577 size_t l_name; 578 char * candidate = NULL; 579 size_t l_candidate = 0; 580 581 if (NULL == tree) 582 return NULL; 583 584 SH_MUTEX_LOCK(mutex_zfiles); 585 for (ptr = (dirstack_t *) zAVLFirst(&avlcursor, tree); ptr; 586 ptr = (dirstack_t *) zAVLNext(&avlcursor)) 587 { 588 l_name = strlen(ptr->name); 589 if (l_name <= l_path) 590 { 591 if (0 == strncmp(ptr->name, path, l_name)) 592 { 593 if ((l_name == l_path) || (path[l_name] == '/')) 594 { 595 if (!candidate || (l_candidate < l_name)) 596 { 597 candidate = ptr->name; 598 l_candidate = l_name; 599 *len = l_candidate; 600 } 601 } 602 } 603 } 604 } 605 SH_MUTEX_UNLOCK(mutex_zfiles); 606 return candidate; 607 } 608 char * sh_files_find_mostspecific_dir(const char * path) 609 { 610 size_t l_one = 0; 611 size_t l_two = 0; 612 char * one; 613 char * two; 614 615 one = intern_find_morespecific_dir(zdirListOne, path, &l_one); 616 two = intern_find_morespecific_dir(zdirListTwo, path, &l_two); 617 618 if (l_one > l_two) return one; 619 else return two; 620 } 621 523 622 int sh_files_delfilestack () 524 623 { … … 547 646 ptr->rdepth = MaxRecursionLevel; 548 647 } 549 if (ptr->rdepth == (-1) && sh.flag.checkSum != SH_CHECK_INIT) 648 649 if ( (ptr->rdepth == (-1)) && 650 (ptr->class == SH_LEVEL_ALLIGNORE) && 651 (sh.flag.checkSum != SH_CHECK_INIT)) 550 652 hash_remove_tree (ptr->name); 551 653 } … … 559 661 SH_MUTEX_RECURSIVE_INIT(mutex_zdirs); 560 662 SH_MUTEX_RECURSIVE_LOCK(mutex_zdirs); 663 clear_lists(); 664 add_to_dirlist(zdirListOne); 665 add_to_dirlist(zdirListTwo); 666 add_to_filelist(zfileList); 561 667 sh_files_setrec_int(zdirListOne); 562 668 ret = sh_files_setrec_int(zdirListTwo); … … 3014 3120 #include "CuTest.h" 3015 3121 3122 void Test_file_lists (CuTest *tc) 3123 { 3124 #if (defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)) 3125 3126 extern int hash_remove_tree_test(char * s, char * fullpath, size_t len_s); 3127 3128 char * test; 3129 int ret; 3130 3131 sh_files_pushfile_ro("/usr/test"); 3132 sh_files_pushfile_ro("/usr/bin/test"); 3133 sh_files_pushfile_ro("/usr/bin/foo/test"); 3134 3135 sh_files_pushdir_ro("/usr"); 3136 sh_files_pushdir_attr("/usr/bin"); 3137 sh_files_pushdir_ro("/usr/bin/foo"); 3138 3139 add_to_dirlist(zdirListOne); 3140 add_to_dirlist(zdirListTwo); 3141 add_to_filelist(zfileList); 3142 3143 test = sh_files_findfile("/usr/tes"); 3144 CuAssertTrue(tc, test == NULL); 3145 test = sh_files_findfile("/usr/test"); 3146 CuAssertPtrNotNull(tc, test); 3147 test = sh_files_findfile("/usr/testi"); 3148 CuAssertTrue(tc, test == NULL); 3149 test = sh_files_findfile("/test"); 3150 CuAssertTrue(tc, test == NULL); 3151 3152 test = sh_files_find_mostspecific_dir("/usr/bin/foo/test"); 3153 CuAssertStrEquals(tc, "/usr/bin/foo", test); 3154 test = sh_files_find_mostspecific_dir("/usr/bin/test"); 3155 CuAssertStrEquals(tc, "/usr/bin", test); 3156 test = sh_files_find_mostspecific_dir("/usr/test"); 3157 CuAssertStrEquals(tc, "/usr", test); 3158 test = sh_files_find_mostspecific_dir("/test"); 3159 CuAssertTrue(tc, test == NULL); 3160 test = sh_files_find_mostspecific_dir("/usr/foo/test"); 3161 CuAssertStrEquals(tc, "/usr", test); 3162 3163 test = sh_files_find_mostspecific_dir("/usr/bin"); 3164 CuAssertStrEquals(tc, "/usr/bin", test); 3165 3166 ret = hash_remove_tree_test("/usr", "/usr/test", strlen("/usr")); 3167 CuAssertIntEquals(tc, S_FALSE, ret); 3168 ret = hash_remove_tree_test("/usr", "/usr/testi", strlen("/usr")); 3169 CuAssertIntEquals(tc, S_TRUE, ret); 3170 ret = hash_remove_tree_test("/usr", "/usr/tes", strlen("/usr")); 3171 CuAssertIntEquals(tc, S_TRUE, ret); 3172 3173 ret = hash_remove_tree_test("/usr/bin", "/usr/test", strlen("/usr/bin")); 3174 CuAssertIntEquals(tc, S_FALSE, ret); 3175 ret = hash_remove_tree_test("/usr/bin", "/usr/testi", strlen("/usr/bin")); 3176 CuAssertIntEquals(tc, S_FALSE, ret); 3177 ret = hash_remove_tree_test("/usr/bin", "/usr/tes", strlen("/usr/bin")); 3178 CuAssertIntEquals(tc, S_FALSE, ret); 3179 3180 ret = hash_remove_tree_test("/usr/bin", "/usr/bin/test", strlen("/usr/bin")); 3181 CuAssertIntEquals(tc, S_FALSE, ret); 3182 ret = hash_remove_tree_test("/usr/bin", "/usr/bin/testi", strlen("/usr/bin")); 3183 CuAssertIntEquals(tc, S_TRUE, ret); 3184 ret = hash_remove_tree_test("/usr/bin", "/usr/bin/tes", strlen("/usr/bin")); 3185 CuAssertIntEquals(tc, S_TRUE, ret); 3186 3187 ret = hash_remove_tree_test("/usr/bin", "/usr/bin", strlen("/usr/bin")); 3188 CuAssertIntEquals(tc, S_TRUE, ret); 3189 ret = hash_remove_tree_test("/usr", "/usr", strlen("/usr")); 3190 CuAssertIntEquals(tc, S_TRUE, ret); 3191 ret = hash_remove_tree_test("/usr", "/usrbin", strlen("/usr")); 3192 CuAssertIntEquals(tc, S_FALSE, ret); 3193 ret = hash_remove_tree_test("/", "/usrbin", strlen("/")); 3194 CuAssertIntEquals(tc, S_TRUE, ret); 3195 ret = hash_remove_tree_test("/", "/usr", strlen("/")); 3196 CuAssertIntEquals(tc, S_FALSE, ret); 3197 3198 #else 3199 (void) tc; /* fix compiler warning */ 3200 return; 3201 #endif 3202 } 3203 3016 3204 void Test_file_dequote (CuTest *tc) 3017 3205 { -
trunk/src/sh_hash.c
r444 r457 537 537 SL_RET0(_("hash_unvisited")); 538 538 } 539 539 #if 0 540 if (!strcmp(p->fullpath, "/var/lib/synaptic")) 541 { 542 fprintf(stderr, "FIXME: Check for missing files %s\n", p->fullpath); 543 if (SH_FFLAG_VISITED_SET(p->fflags)) fprintf(stderr, "FIXME: visited\n"); 544 if (SH_FFLAG_CHECKED_SET(p->fflags)) fprintf(stderr, "FIXME: checked\n"); 545 if (SH_FFLAG_REPORTED_SET(p->fflags)) fprintf(stderr, "FIXME: reported\n"); 546 if (SH_FFLAG_ALLIGNORE_SET(p->fflags)) fprintf(stderr, "FIXME: allignore\n"); 547 } 548 #endif 540 549 /* visited flag not set: not seen; 541 550 * checked flag set: not seen (i.e. missing), and already checked … … 551 560 { 552 561 i = retry_lstat(FIL__, __LINE__, p->fullpath, &buf); 553 554 /* if file does not exist 562 #if 0 563 if (!strcmp(p->fullpath, "/var/lib/synaptic")) 564 fprintf(stderr, "FIXME: Check for missing files %s (%d)\n", p->fullpath, i); 565 #endif 566 /* if file does not exist 555 567 */ 556 568 if (0 != i) … … 3817 3829 int i; 3818 3830 3819 SL_ENTER(_(" sh_hash_compdata"));3831 SL_ENTER(_("hash_full_tree")); 3820 3832 3821 3833 if (IsInit != 1) 3822 SL_RETURN(0, _(" sh_hash_compdata"));3834 SL_RETURN(0, _("hash_full_tree")); 3823 3835 3824 3836 SH_MUTEX_LOCK_UNSAFE(mutex_hash); … … 3829 3841 } 3830 3842 SH_MUTEX_UNLOCK_UNSAFE(mutex_hash); 3831 SL_RETURN (0, _(" sh_hash_compdata"));3843 SL_RETURN (0, _("hash_full_tree")); 3832 3844 } 3833 3845 3846 #if !defined(SH_CUTEST) 3847 static 3848 #endif 3849 int hash_remove_tree_test(char * s, char * fullpath, size_t len_s) 3850 { 3851 size_t len_p; 3852 char * test; 3853 3854 len_p = strlen(fullpath); 3855 3856 if (len_p >= len_s) 3857 { 3858 if (0 == strncmp(s, fullpath, len_s)) 3859 { 3860 if (len_p > len_s) 3861 { 3862 /* continue if not inside directory; 3863 * len_s > 1 because everything is inside '/' 3864 */ 3865 if ((len_s > 1) && (fullpath[len_s] != '/')) 3866 return S_FALSE; 3867 3868 test = sh_files_find_mostspecific_dir(fullpath); 3869 3870 if (test && 0 != strcmp(test, s)) { 3871 /* There is a more specific directory, continue */ 3872 return S_FALSE; 3873 } 3874 3875 if (NULL == sh_files_findfile(fullpath)) { 3876 /* SET_SH_FFLAG_ALLIGNORE(p->fflags); */ 3877 return S_TRUE; 3878 } 3879 } 3880 else /* len_p == len */ 3881 { 3882 /* it is 's' itself, mark and continue 3883 * unless there is a policy for the inode itself 3884 */ 3885 if (NULL == sh_files_findfile(fullpath)) { 3886 /* SET_SH_FFLAG_ALLIGNORE(p->fflags); */ 3887 return S_TRUE; 3888 } 3889 else { 3890 return S_FALSE; 3891 } 3892 } 3893 3894 } /* if path is in tree */ 3895 } /* if path is possibly in tree */ 3896 return S_FALSE; 3897 } 3898 3834 3899 3835 3900 int hash_remove_tree (char * s) 3836 3901 { 3837 3902 sh_file_t * p; 3838 size_t len ;3903 size_t len_s; 3839 3904 unsigned int i; 3840 3905 … … 3844 3909 SL_RETURN ((-1), _("hash_remove_tree")); 3845 3910 3846 len = sl_strlen(s);3911 len_s = sl_strlen(s); 3847 3912 3848 3913 if (IsInit != 1) … … 3854 3919 for (p = tab[i]; p; p = p->next) 3855 3920 { 3856 if (p->fullpath && 0 == strncmp(s, p->fullpath, len)) 3857 { 3858 SET_SH_FFLAG_ALLIGNORE(p->fflags); 3859 } 3921 if (p->fullpath) 3922 { 3923 /* if (0 == strncmp(s, p->fullpath, len_s)) *//* old */ 3924 if (S_TRUE == hash_remove_tree_test(s, p->fullpath, len_s)) 3925 SET_SH_FFLAG_ALLIGNORE(p->fflags); 3926 } /* if path is not null */ 3927 3860 3928 } 3861 3929 } -
trunk/src/zAVLTree.c
r452 r457 70 70 return -1; 71 71 } 72 char * zAVL_string_get (zAVLTree * tree, c har * key)72 char * zAVL_string_get (zAVLTree * tree, const char * key) 73 73 { 74 74 /* zAVLSearch() checks for NULL tree
Note:
See TracChangeset
for help on using the changeset viewer.