Changeset 167
- Timestamp:
- Mar 15, 2008, 12:38:20 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile.in
r162 r167 117 117 rijndael-boxes-fst.h sh_socket.h sh_ignore.h sh_prelude.h \ 118 118 sh_mounts.h sh_userfiles.h sh_static.h sh_prelink.h \ 119 sh_processcheck.h sh_portcheck.h sh_pthread.h 119 sh_processcheck.h sh_portcheck.h sh_pthread.h sh_string.h 120 120 121 121 … … 151 151 $(srcsrc)/sh_portcheck.c \ 152 152 $(srcsrc)/sh_processcheck.c $(srcsrc)/sh_prelude_old.c \ 153 $(srcsrc)/sh_pthread.c 153 $(srcsrc)/sh_pthread.c $(srcsrc)/sh_string.c 154 154 155 155 OBJECTS = sh_files.o sh_tiger0.o sh_tiger2.o sh_tiger2_64.o \ … … 165 165 sh_mounts.o sh_userfiles.o sh_prelink.o sh_static.o \ 166 166 sh_processcheck.o sh_portcheck.o sh_prelude_old.o \ 167 sh_pthread.o 167 sh_pthread.o sh_string.o 168 168 169 169 KERN = kern_head.h kern_head.c … … 1642 1642 sh_getopt.o: $(srcsrc)/sh_getopt.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_getopt.h $(srcinc)/sh_files.h $(srcinc)/sh_utils.h $(srcinc)/sh_mail.h $(srcinc)/sh_forward.h $(srcinc)/sh_hash.h $(srcinc)/sh_extern.h 1643 1643 sh_readconf.o: $(srcsrc)/sh_readconf.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_database.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_files.h $(srcinc)/sh_mail.h $(srcinc)/sh_calls.h $(srcinc)/sh_tiger.h $(srcinc)/sh_forward.h $(srcinc)/sh_modules.h $(srcinc)/sh_gpg.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/sh_prelink.h $(srcinc)/sh_extern.h $(srcinc)/sh_database.h $(srcinc)/sh_prelude.h 1644 sh_tiger0.o: $(srcsrc)/sh_tiger0.c Makefile config_xor.h $(srcinc)/sh_tiger.h $(srcinc)/sh_unix.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_pthread.h 1644 sh_tiger0.o: $(srcsrc)/sh_tiger0.c Makefile config_xor.h $(srcinc)/sh_tiger.h $(srcinc)/sh_unix.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_pthread.h $(srcinc)/sh_string.h 1645 1645 sh_tiger1.o: $(srcsrc)/sh_tiger1.c Makefile config_xor.h 1646 1646 sh_tiger2.o: $(srcsrc)/sh_tiger2.c Makefile config_xor.h … … 1680 1680 exepack_mkdata.o: $(srcsrc)/exepack_mkdata.c Makefile config.h $(srcinc)/minilzo.h 1681 1681 minilzo.o: $(srcsrc)/minilzo.c Makefile $(srcinc)/minilzo.h 1682 slib.o: $(srcsrc)/slib.c Makefile config_xor.h $(srcinc)/slib.h $(srcinc)/sh_calls.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_ mem.h1682 slib.o: $(srcsrc)/slib.c Makefile config_xor.h $(srcinc)/slib.h $(srcinc)/sh_calls.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_string.h $(srcinc)/sh_mem.h 1683 1683 rijndael-alg-fst.o: $(srcsrc)/rijndael-alg-fst.c Makefile config_xor.h $(srcinc)/rijndael-alg-fst.h $(srcinc)/rijndael-boxes-fst.h 1684 1684 rijndael-api-fst.o: $(srcsrc)/rijndael-api-fst.c Makefile config_xor.h $(srcinc)/rijndael-alg-fst.h $(srcinc)/rijndael-api-fst.h … … 1698 1698 sh_portcheck.o: $(srcsrc)/sh_portcheck.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_mem.h $(srcinc)/sh_calls.h $(srcinc)/sh_utils.h $(srcinc)/sh_modules.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/CuTest.h 1699 1699 sh_pthread.o: $(srcsrc)/sh_pthread.c Makefile config_xor.h $(srcinc)/sh_pthread.h $(srcinc)/sh_calls.h $(srcinc)/sh_modules.h 1700 sh_string.o: $(srcsrc)/sh_string.c Makefile $(srcinc)/sh_string.h $(srcinc)/sh_mem.h -
trunk/depend.dep
r162 r167 8 8 sh_getopt.o: $(srcsrc)/sh_getopt.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_getopt.h $(srcinc)/sh_files.h $(srcinc)/sh_utils.h $(srcinc)/sh_mail.h $(srcinc)/sh_forward.h $(srcinc)/sh_hash.h $(srcinc)/sh_extern.h 9 9 sh_readconf.o: $(srcsrc)/sh_readconf.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_database.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_files.h $(srcinc)/sh_mail.h $(srcinc)/sh_calls.h $(srcinc)/sh_tiger.h $(srcinc)/sh_forward.h $(srcinc)/sh_modules.h $(srcinc)/sh_gpg.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/sh_prelink.h $(srcinc)/sh_extern.h $(srcinc)/sh_database.h $(srcinc)/sh_prelude.h 10 sh_tiger0.o: $(srcsrc)/sh_tiger0.c Makefile config_xor.h $(srcinc)/sh_tiger.h $(srcinc)/sh_unix.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_pthread.h 10 sh_tiger0.o: $(srcsrc)/sh_tiger0.c Makefile config_xor.h $(srcinc)/sh_tiger.h $(srcinc)/sh_unix.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_pthread.h $(srcinc)/sh_string.h 11 11 sh_tiger1.o: $(srcsrc)/sh_tiger1.c Makefile config_xor.h 12 12 sh_tiger2.o: $(srcsrc)/sh_tiger2.c Makefile config_xor.h … … 46 46 exepack_mkdata.o: $(srcsrc)/exepack_mkdata.c Makefile config.h $(srcinc)/minilzo.h 47 47 minilzo.o: $(srcsrc)/minilzo.c Makefile $(srcinc)/minilzo.h 48 slib.o: $(srcsrc)/slib.c Makefile config_xor.h $(srcinc)/slib.h $(srcinc)/sh_calls.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_ mem.h48 slib.o: $(srcsrc)/slib.c Makefile config_xor.h $(srcinc)/slib.h $(srcinc)/sh_calls.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_string.h $(srcinc)/sh_mem.h 49 49 rijndael-alg-fst.o: $(srcsrc)/rijndael-alg-fst.c Makefile config_xor.h $(srcinc)/rijndael-alg-fst.h $(srcinc)/rijndael-boxes-fst.h 50 50 rijndael-api-fst.o: $(srcsrc)/rijndael-api-fst.c Makefile config_xor.h $(srcinc)/rijndael-alg-fst.h $(srcinc)/rijndael-api-fst.h … … 63 63 sh_pthread.o: $(srcsrc)/sh_pthread.c Makefile config_xor.h $(srcinc)/sh_pthread.h $(srcinc)/sh_calls.h $(srcinc)/sh_modules.h 64 64 kern_head.o: $(srcsrc)/kern_head.c Makefile config.h $(srcinc)/kern_head.h $(srcinc)/kern_head.h 65 sh_string.o: $(srcsrc)/sh_string.c Makefile $(srcinc)/sh_string.h $(srcinc)/sh_mem.h -
trunk/depend.sum
r162 r167 1 2613935365 1 3237390887 -
trunk/docs/Changelog
r164 r167 1 1 2.4.4: 2 * fill content if MODI_TXT, base64 encode and add as link_path 3 in sh_unix.c; add to report in sh_hash.c; needs listing option 2 4 * testsuite: add test for gpg fingerprint option 3 5 * sh_extern.c: add 'CloseCommand' for syntactic sugar, 4 6 add in testsuite 7 8 2.4.3a: 9 * fix compile error cause by open() with O_CREAT and no third argument 10 (reported by J.-S. Eon) 5 11 6 12 2.4.3: -
trunk/include/sh_unix.h
r156 r167 90 90 /* use prelink */ 91 91 #define MODI_PREL (1 << 13) 92 /* get content */ 93 #define MODI_TXT (1 << 14) 94 95 #define SH_TXT_MAX 9200 92 96 93 97 #define MASK_ALLIGNORE_ 0 … … 140 144 time_t ctime; 141 145 142 char linkpath[PATH_MAX];146 char * link_path; 143 147 mode_t linkmode; 144 148 char link_c_mode[11]; -
trunk/include/sh_utils.h
r149 r167 190 190 char * sh_util_basename(const char * fullpath); 191 191 192 /* required size (including terminating NULL) for string of strlen l 193 */ 194 #define SH_B64_SIZ(l) (1 + ((((l) + 2) / 3) * 4)) 195 196 /* return len of encoded string 197 */ 198 size_t sh_util_base64_enc (unsigned char * out, const unsigned char * instr, 199 size_t lin); 200 201 /* return allocated encoded string in out, return its len 202 */ 203 size_t sh_util_base64_enc_alloc (char **out, const char *in, size_t inlen); 204 205 /* return len of decoded string 206 */ 207 size_t sh_util_base64_dec (unsigned char *out, const unsigned char *in, size_t lin); 208 209 /* return allocated decoded string in out, return its len 210 */ 211 size_t sh_util_base64_dec_alloc (unsigned char **out, const unsigned char *in, size_t lin); 212 192 213 #endif -
trunk/include/slib.h
r156 r167 23 23 #include <unistd.h> 24 24 #endif 25 26 #include "sh_string.h" 25 27 26 28 /**************** … … 333 335 SL_TICKET sl_open_rdwr_trunc (const char * fname, int priviledge_mode); 334 336 337 /* Initialize the content sh_string. 338 */ 339 int sl_init_content (SL_TICKET ticket, size_t size); 340 341 /* Get the (pointer to) the content sh_string. 342 */ 343 sh_string * sl_get_content (SL_TICKET ticket); 344 335 345 /* Close file. 336 346 */ -
trunk/src/cutest_sh_utils.c
r157 r167 128 128 } 129 129 130 void Test_sh_util_base64_enc_ok (CuTest *tc) { 131 unsigned char out[64]; 132 unsigned char ou2[64]; 133 int ret; 134 unsigned char inp0[64] = ""; 135 unsigned char inp1[64] = "A"; 136 unsigned char inp2[64] = "AB"; 137 unsigned char inp3[64] = "ABC"; 138 unsigned char inp4[64] = "ABCD"; 139 140 ret = sh_util_base64_enc (out, inp0, strlen((char*)inp0)); 141 CuAssertIntEquals(tc, ret, 0); 142 CuAssertStrEquals(tc, "", (char*)out); 143 ret = sh_util_base64_dec (ou2, out, strlen((char*)out)); 144 CuAssertIntEquals(tc, ret, 0); 145 CuAssertStrEquals(tc, (char*)inp0, (char*)ou2); 146 147 ret = sh_util_base64_enc (out, inp1, strlen((char*)inp1)); 148 CuAssertIntEquals(tc, ret, 4); 149 CuAssertStrEquals(tc, "QQ??", (char*)out); 150 ret = sh_util_base64_dec (ou2, out, strlen((char*)out)); 151 CuAssertStrEquals(tc, (char*)inp1, (char*)ou2); 152 CuAssertIntEquals(tc, 1, ret); 153 154 ret = sh_util_base64_enc (out, inp2, strlen((char*)inp2)); 155 CuAssertIntEquals(tc, ret, 4); 156 CuAssertStrEquals(tc, "QUI?", (char*)out); 157 ret = sh_util_base64_dec (ou2, out, strlen((char*)out)); 158 CuAssertStrEquals(tc, (char*)inp2, (char*)ou2); 159 CuAssertIntEquals(tc, 2, ret); 160 161 ret = sh_util_base64_enc (out, inp3, strlen((char*)inp3)); 162 CuAssertIntEquals(tc, ret, 4); 163 CuAssertStrEquals(tc, "QUJD", (char*)out); 164 ret = sh_util_base64_dec (ou2, out, strlen((char*)out)); 165 CuAssertStrEquals(tc, (char*)inp3, (char*)ou2); 166 CuAssertIntEquals(tc, 3, ret); 167 168 ret = sh_util_base64_enc (out, inp4, strlen((char*)inp4)); 169 CuAssertIntEquals(tc, ret, 8); 170 CuAssertStrEquals(tc, "QUJDRA??", (char*)out); 171 ret = sh_util_base64_dec (ou2, out, strlen((char*)out)); 172 CuAssertStrEquals(tc, (char*)inp4, (char*)ou2); 173 CuAssertIntEquals(tc, 4, ret); 174 175 176 return; 177 } 178 130 179 void Test_sh_util_dirname_ok (CuTest *tc) { 131 180 char * ret = 0; -
trunk/src/sh_files.c
r137 r167 616 616 if (0 == strncmp(myword, _("PRE"), 3)) 617 617 sh_files_set_mask (mask, MODI_PREL, act); 618 /* get content */ 619 if (0 == strncmp(myword, _("TXT"), 3)) 620 sh_files_set_mask (mask, MODI_TXT, act); 618 621 619 622 } … … 1570 1573 sl_strlcpy (theFile.fullpath, iname, PATH_MAX); 1571 1574 theFile.attr_string = NULL; 1575 theFile.link_path = NULL; 1572 1576 1573 1577 (void) relativeName; … … 1579 1583 { 1580 1584 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1585 if (theFile.link_path) SH_FREE(theFile.link_path); 1581 1586 SL_RETURN((0), _("sh_files_checkdir")); 1582 1587 } … … 1586 1591 SH_FREE(tmpname); 1587 1592 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1588 SL_RETURN((-1), _("sh_files_checkdir")); 1593 if (theFile.link_path) SH_FREE(theFile.link_path); 1594 SL_RETURN((-1), _("sh_files_checkdir")); 1589 1595 } 1590 1596 … … 1596 1602 SH_FREE(tmpname); 1597 1603 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1604 if (theFile.link_path) SH_FREE(theFile.link_path); 1598 1605 SL_RETURN((-1), _("sh_files_checkdir")); 1599 1606 } … … 1618 1625 1619 1626 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1627 if (theFile.link_path) SH_FREE(theFile.link_path); 1620 1628 SL_RETURN((-1), _("sh_files_checkdir")); 1621 1629 } … … 1676 1684 { 1677 1685 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1686 if (theFile.link_path) SH_FREE(theFile.link_path); 1678 1687 SL_RETURN((0), _("sh_files_checkdir")); 1679 1688 } … … 1871 1880 { 1872 1881 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1882 if (theFile.link_path) SH_FREE(theFile.link_path); 1873 1883 SL_RETURN((0), _("sh_files_checkdir")); 1874 1884 } … … 1918 1928 1919 1929 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1930 if (theFile.link_path) SH_FREE(theFile.link_path); 1920 1931 SH_FREE(tmpname); 1921 1932 … … 2016 2027 theFile.file_reported = (*reported); 2017 2028 theFile.attr_string = NULL; 2029 theFile.link_path = NULL; 2018 2030 2019 2031 TPT(( 0, FIL__, __LINE__, _("msg=<checking file: %s>\n"), fullpath)); … … 2030 2042 if (class == SH_LEVEL_ALLIGNORE && sh.flag.checkSum != SH_CHECK_INIT) 2031 2043 sh_hash_set_visited_true (fullpath); 2032 if (theFile.attr_string) 2033 SH_FREE(theFile.attr_string);2044 if (theFile.attr_string) SH_FREE(theFile.attr_string); 2045 if (theFile.link_path) SH_FREE(theFile.link_path); 2034 2046 SL_RETURN(SH_FILE_UNKNOWN, _("sh_files_filecheck")); 2035 2047 } … … 2109 2121 2110 2122 if (theFile.attr_string) SH_FREE(theFile.attr_string); 2123 if (theFile.link_path) SH_FREE(theFile.link_path); 2111 2124 2112 2125 switch (theFile.c_mode[0]) -
trunk/src/sh_hash.c
r162 r167 363 363 364 364 sl_strlcpy(theFile->fullpath, p->fullpath, PATH_MAX); 365 if (p->linkpath != NULL && theFile->c_mode[0] == 'l')366 { 367 sl_strlcpy(theFile->linkpath, p->linkpath, PATH_MAX);365 if (p->linkpath != NULL /* && theFile->c_mode[0] == 'l' */) 366 { 367 theFile->link_path = sh_util_strdup(p->linkpath); 368 368 } 369 369 else 370 370 { 371 theFile->linkpath[0] = '-'; 372 theFile->linkpath[1] = '\0'; 371 theFile->link_path = NULL; 373 372 } 374 373 sl_strlcpy(fileHash, p->theFile.checksum, KEY_LEN+1); … … 454 453 SH_FREE(tmp); 455 454 SH_FREE(str); 456 if (theFile->attr_string) 457 SH_FREE(theFile->attr_string);455 if (theFile->attr_string) SH_FREE(theFile->attr_string); 456 if (theFile->link_path) SH_FREE(theFile->link_path); 458 457 SH_FREE(theFile); 459 458 … … 541 540 MSG_FI_MISS2, tmp, str); 542 541 SH_FREE(str); 543 if (theFile->attr_string) 544 SH_FREE(theFile->attr_string);542 if (theFile->attr_string) SH_FREE(theFile->attr_string); 543 if (theFile->link_path) SH_FREE(theFile->link_path); 545 544 SH_FREE(theFile); 546 545 … … 1009 1008 else 1010 1009 { 1011 len = sl_strlen(tmp)+1; 1012 linkpath = SH_ALLOC(len); 1013 (void) sl_strlcpy (linkpath, tmp, len); 1014 if (len > 1 && linkpath[len-2] == '\n') 1015 linkpath[len-2] = '\0'; 1010 len = sl_strlen(tmp); 1011 linkpath = sh_util_strdup_l(tmp, len); 1012 if (len > 0 && linkpath[len-1] == '\n') 1013 linkpath[len-1] = '\0'; 1016 1014 } 1017 1015 … … 1614 1612 } 1615 1613 1616 if (buf != NULL && buf->c_mode[0] == 'l' && buf->linkpath != NULL)1614 if (buf != NULL /* && buf->c_mode[0] == 'l' */ && buf->link_path != NULL) 1617 1615 { 1618 1616 1619 old_len = sl_strlen(buf->link path);1617 old_len = sl_strlen(buf->link_path); 1620 1618 #if defined(SH_STEALTH) 1621 sh_do_encode(buf->linkpath, old_len); 1622 #endif 1623 tmp = quote_string(buf->linkpath, old_len); 1619 if (buf->c_mode[0] == 'l') 1620 sh_do_encode(buf->link_path, old_len); 1621 #endif 1622 tmp = quote_string(buf->link_path, old_len); 1624 1623 tmp_len = sl_strlen(tmp); 1625 1624 #if defined(SH_STEALTH) 1626 sh_do_decode(buf->linkpath, old_len); 1625 if (buf->c_mode[0] == 'l') 1626 sh_do_decode(buf->link_path, old_len); 1627 1627 #endif 1628 1628 1629 1629 if (tmp && tmp_len <= MAX_PATH_STORE) 1630 1630 { 1631 sl_strlcpy(linkpath, buf->link path, MAX_PATH_STORE+1);1631 sl_strlcpy(linkpath, buf->link_path, MAX_PATH_STORE+1); 1632 1632 } 1633 1633 else … … 1635 1635 char hashbuf[KEYBUF_SIZE]; 1636 1636 sl_strlcpy(linkpath, 1637 sh_tiger_hash (buf->link path,1637 sh_tiger_hash (buf->link_path, 1638 1638 TIGER_DATA, old_len, 1639 1639 hashbuf, sizeof(hashbuf)), … … 1644 1644 path_len = sl_strlen(linkpath); 1645 1645 #if defined(SH_STEALTH) 1646 sh_do_encode(linkpath, path_len); 1646 if (buf->c_mode[0] == 'l') 1647 sh_do_encode(linkpath, path_len); 1647 1648 #endif 1648 1649 tmp = quote_string(linkpath, path_len); … … 1873 1874 f = sh_hash_create_ft (p, fileHash); 1874 1875 sh_hash_pushdata_int (f, fileHash); 1875 if (f->attr_string) 1876 SH_FREE(f->attr_string);1876 if (f->attr_string) SH_FREE(f->attr_string); 1877 if (f->link_path) SH_FREE(f->link_path); 1877 1878 SH_FREE(f); 1878 1879 } … … 1948 1949 sh_hash_init(); 1949 1950 1951 tmpFile->link_path = NULL; 1952 tmpFile->attr_string = NULL; 1953 1950 1954 SH_MUTEX_LOCK(mutex_hash); 1951 1955 p = sh_hash_have_it_int (newname); 1952 1956 if (p) 1953 1957 { 1954 sl_strlcpy(tmpFile->fullpath, p->fullpath, PATH_MAX); 1955 sl_strlcpy(tmpFile->linkpath, p->linkpath, PATH_MAX); 1958 sl_strlcpy(tmpFile->fullpath, p->fullpath, PATH_MAX); 1959 if (p->linkpath) 1960 tmpFile->link_path = sh_util_strdup (p->linkpath); 1956 1961 tmpFile->size = p->theFile.size; 1957 1962 tmpFile->mtime = p->theFile.mtime; … … 2121 2126 2122 2127 tmpFile.attr_string = NULL; 2128 tmpFile.link_path = NULL; 2123 2129 2124 2130 sl_strlcpy(tmpFile.fullpath, key, PATH_MAX); … … 2141 2147 tmpFile.c_mode[5] = 'w'; tmpFile.c_mode[6] = 'x'; 2142 2148 tmpFile.c_mode[7] = 'r'; tmpFile.c_mode[8] = 'w'; 2143 tmpFile.c_mode[9] = 'x'; tmpFile.c_mode[10] = '\0'; 2149 tmpFile.c_mode[9] = 'x'; tmpFile.c_mode[10] = '\0'; 2150 tmpFile.link_path = SH_ALLOC((size * 2) + 2); 2144 2151 for (i = 0; i < size; ++i) 2145 2152 { 2146 2153 p = sh_util_charhex (str[i],i2h); 2147 tmpFile.link path[2*i] = p[0];2148 tmpFile.link path[2*i+1] = p[1];2149 tmpFile.link path[2*i+2] = '\0';2154 tmpFile.link_path[2*i] = p[0]; 2155 tmpFile.link_path[2*i+1] = p[1]; 2156 tmpFile.link_path[2*i+2] = '\0'; 2150 2157 } 2151 2158 } … … 2154 2161 for (i = 0; i < 10; ++i) 2155 2162 tmpFile.c_mode[i] = '-'; 2156 tmpFile.c_mode[10] = '\0'; 2157 tmpFile.linkpath[0] = '-'; 2158 tmpFile.linkpath[1] = '\0'; 2163 tmpFile.c_mode[10] = '\0'; 2164 tmpFile.link_path = sh_util_strdup("-"); 2159 2165 } 2160 2166 … … 2165 2171 sh_hash_pushdata (&tmpFile, SH_KEY_NULL); 2166 2172 2173 if (tmpFile.link_path) SH_FREE(tmpFile.link_path); 2167 2174 return; 2168 2175 } … … 2178 2185 char * p; 2179 2186 int i; 2180 2187 char * retval = NULL; 2188 2181 2189 *size = 0; 2182 2190 … … 2187 2195 *val3 = tmpFile.ctime; 2188 2196 2189 if (tmpFile.link path[0] != '-')2190 { 2191 len = strlen(tmpFile.link path);2197 if (tmpFile.link_path && tmpFile.link_path[0] != '-') 2198 { 2199 len = strlen(tmpFile.link_path); 2192 2200 2193 2201 p = SH_ALLOC((len/2)+1); 2194 i = sh_util_hextobinary (p, tmpFile.link path, len);2202 i = sh_util_hextobinary (p, tmpFile.link_path, len); 2195 2203 2196 2204 if (i == 0) … … 2198 2206 *size = (len/2); 2199 2207 p[*size] = '\0'; 2200 ret urnp;2208 retval = p; 2201 2209 } 2202 2210 else … … 2204 2212 SH_FREE(p); 2205 2213 *size = 0; 2206 return NULL;2207 2214 } 2208 2215 } … … 2210 2217 { 2211 2218 *size = 0; 2212 return NULL;2213 2219 } 2214 2220 } … … 2219 2225 *val2 = 0; 2220 2226 *val3 = 0; 2221 return NULL; 2222 } 2227 } 2228 if (tmpFile.link_path) SH_FREE(tmpFile.link_path); 2229 return retval; 2223 2230 } 2224 2231 … … 2297 2304 fp->fullpath = fullpath; 2298 2305 2299 if (buf-> c_mode[0] == 'l')2306 if (buf->link_path) 2300 2307 { 2301 len = sl_strlen(buf->link path);2308 len = sl_strlen(buf->link_path); 2302 2309 if (len <= MAX_PATH_STORE) 2303 2310 { 2304 2311 linkpath = SH_ALLOC(len+1); 2305 sl_strlcpy(linkpath, buf->link path, len+1);2312 sl_strlcpy(linkpath, buf->link_path, len+1); 2306 2313 } 2307 2314 else … … 2309 2316 linkpath = SH_ALLOC(KEY_LEN + 1); 2310 2317 sl_strlcpy(linkpath, 2311 sh_tiger_hash (buf->link path, TIGER_DATA, len,2318 sh_tiger_hash (buf->link_path, TIGER_DATA, len, 2312 2319 hashbuf, sizeof(hashbuf)), 2313 2320 KEY_LEN+1); … … 2490 2497 sl_strlcat(msg, tmp, SH_BUFSIZE); 2491 2498 2492 if (theFile->c_mode[0] == 'l' )2493 { 2494 tmp_lnk = sh_util_safe_name(theFile->link path);2499 if (theFile->c_mode[0] == 'l' || theFile->link_path != NULL) 2500 { 2501 tmp_lnk = sh_util_safe_name(theFile->link_path); 2495 2502 if (tmp_lnk) 2496 2503 { … … 2656 2663 sl_strlcat(msg, tmp, SH_BUFSIZE); 2657 2664 2658 if (theFile->c_mode[0] == 'l' )2659 { 2660 tmp_lnk = sh_util_safe_name(theFile->link path);2665 if (theFile->c_mode[0] == 'l' || theFile->link_path != NULL) 2666 { 2667 tmp_lnk = sh_util_safe_name(theFile->link_path); 2661 2668 if (tmp_lnk) 2662 2669 { … … 2862 2869 if (p->theFile.c_mode[0] == 'l') 2863 2870 { 2864 if (sl_strlen(theFile->link path) >= MAX_PATH_STORE)2871 if (sl_strlen(theFile->link_path) >= MAX_PATH_STORE) 2865 2872 { 2866 2873 sl_strlcpy(linkHash, 2867 sh_tiger_hash(theFile->link path,2874 sh_tiger_hash(theFile->link_path, 2868 2875 TIGER_DATA, 2869 sl_strlen(theFile->link path),2876 sl_strlen(theFile->link_path), 2870 2877 hashbuf, sizeof(hashbuf)), 2871 2878 MAX_PATH_STORE+1); … … 2874 2881 else 2875 2882 { 2876 sl_strlcpy(linkHash, theFile->link path, KEY_LEN + 1);2883 sl_strlcpy(linkHash, theFile->link_path, KEY_LEN + 1); 2877 2884 maxcomp = KEY_LEN; 2878 2885 } … … 3347 3354 if ((modi_mask & MODI_LNK) != 0 && theFile->c_mode[0] == 'l') 3348 3355 { 3349 tmp_lnk = sh_util_safe_name(theFile->link path);3356 tmp_lnk = sh_util_safe_name(theFile->link_path); 3350 3357 tmp_lnk_old = sh_util_safe_name(p->linkpath); 3351 3358 #ifdef SH_USE_XML … … 3364 3371 if (p->linkpath != NULL && p->linkpath != notalink) 3365 3372 SH_FREE(p->linkpath); 3366 if (theFile->linkpath[0] == '-' && theFile->linkpath[1] == '\0') 3373 if (!(theFile->link_path) || 3374 (theFile->link_path[0] == '-' && theFile->link_path[1] == '\0')) 3367 3375 p->linkpath = (char *)notalink; 3368 3376 else 3369 p->linkpath = sh_util_strdup(theFile->link path);3377 p->linkpath = sh_util_strdup(theFile->link_path); 3370 3378 } 3371 3379 #endif … … 3417 3425 if (theFile->c_mode[0] == 'l') /* c_mode is already copied */ 3418 3426 { 3419 sl_strlcpy(theFile->linkpath, p->linkpath, PATH_MAX); 3427 if (theFile->link_path) 3428 SH_FREE(theFile->link_path); 3429 if (p->linkpath) 3430 theFile->link_path = sh_util_strdup(p->linkpath); 3431 else 3432 theFile->link_path = sh_util_strdup("-"); 3420 3433 } 3421 3434 else 3422 3435 { 3423 theFile->linkpath[0] = '-'; 3424 theFile->linkpath[1] = '\0'; 3436 if (theFile->link_path) 3437 SH_FREE(theFile->link_path); 3438 if (p->linkpath && p->linkpath != notalink) 3439 theFile->link_path = sh_util_strdup(p->linkpath); 3440 else 3441 theFile->link_path = NULL; 3425 3442 } 3426 3443 … … 3475 3492 #endif 3476 3493 3477 if (theFile->c_mode[0] == 'l' )3494 if (theFile->c_mode[0] == 'l' || theFile->link_path) 3478 3495 { 3479 3496 if (p->linkpath != NULL && p->linkpath != notalink) 3480 3497 SH_FREE(p->linkpath); 3481 p->linkpath = sh_util_strdup(theFile->link path);3498 p->linkpath = sh_util_strdup(theFile->link_path); 3482 3499 } 3483 3500 else 3484 3501 { 3485 3502 if (p->linkpath != NULL && p->linkpath != notalink) { 3486 p->linkpath[0] = '-'; 3487 p->linkpath[1] = '\0'; 3488 } else { 3489 p->linkpath = (char *)notalink; 3490 } 3503 SH_FREE(p->linkpath); 3504 } 3505 p->linkpath = (char *)notalink; 3491 3506 } 3492 3507 -
trunk/src/sh_kern.c
r162 r167 915 915 CLEAR_SH_FFLAG_REPORTED(theFile.file_reported); 916 916 theFile.attr_string = NULL; 917 theFile.link_path = NULL; 917 918 918 919 status = sh_unix_getinfo (ShDFLevel[SH_ERR_T_RO], … … 928 929 tmp); 929 930 SH_FREE(tmp); 930 return;931 goto out; 931 932 } 932 933 … … 940 941 } 941 942 943 out: 944 if (theFile.attr_string) SH_FREE(theFile.attr_string); 945 if (theFile.link_path) SH_FREE(theFile.link_path); 942 946 return; 943 947 } -
trunk/src/sh_suidchk.c
r166 r167 1032 1032 CLEAR_SH_FFLAG_REPORTED(theFile.file_reported); 1033 1033 theFile.attr_string = NULL; 1034 theFile.link_path = NULL; 1034 1035 1035 1036 status = sh_unix_getinfo (ShDFLevel[SH_ERR_T_RO], … … 1161 1162 } 1162 1163 SH_FREE(tmp); 1163 if (theFile.attr_string) 1164 SH_FREE(theFile.attr_string);1164 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1165 if (theFile.link_path) SH_FREE(theFile.link_path); 1165 1166 } 1166 1167 } -
trunk/src/sh_tiger0.c
r151 r167 25 25 #include "sh_utils.h" 26 26 #include "sh_pthread.h" 27 #include "sh_string.h" 27 28 28 29 #define PRIV_MAX 32768 … … 114 115 { 115 116 SL_TICKET fd; 117 sh_string * content = NULL; 116 118 int i, j, tt; 117 119 int count = 0; … … 159 161 if (what > TIGER_FILE) 160 162 { 161 fd = what; 163 fd = what; 164 content = sl_get_content(fd); 162 165 TPT((0,FIL__, __LINE__, _("msg=<TIGER_FD>, fd=<%ld>\n"), fd)); 163 166 } … … 247 250 SL_RETURN( NULL, _("sh_tiger_hash_val")); 248 251 } 252 253 if (content) 254 sh_string_cat_lchar(content, (char*)buffer, count); 249 255 250 256 bcount += count; … … 843 849 uid_t euid; 844 850 UINT64 bcount = 0; 851 sh_string * content; 845 852 846 853 unsigned long pages_read; … … 867 874 868 875 pages_read = 0; 876 877 content = sl_get_content(fd); 869 878 870 879 /* Iterate over full file contents. */ … … 902 911 return -1; 903 912 } 913 914 if (content) 915 sh_string_cat_lchar(content, buffer, n); 904 916 905 917 bcount += n; … … 1360 1372 uid_t euid; 1361 1373 UINT64 bcount = 0; 1374 sh_string * content; 1362 1375 1363 1376 unsigned long pages_read; … … 1386 1399 1387 1400 pages_read = 0; 1401 1402 content = sl_get_content(fd); 1388 1403 1389 1404 while (1 == 1) { … … 1422 1437 return -1; 1423 1438 } 1439 1440 if (content) 1441 sh_string_cat_lchar(content, buffer, n); 1424 1442 1425 1443 bcount += n; -
trunk/src/sh_unix.c
r162 r167 3062 3062 3063 3063 /* return */ 3064 if (tmpFile.link_path) SH_FREE(tmpFile.link_path); 3064 3065 SL_RETURN( 0, _("sh_unix_checksum_size")); 3065 3066 } 3066 3067 3067 3068 out: 3069 if (tmpFile.link_path) SH_FREE(tmpFile.link_path); 3068 3070 sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1); 3069 3071 SL_RETURN( -1, _("sh_unix_checksum_size")); … … 3279 3281 int fd; 3280 3282 int fstat_return; 3281 3283 sh_string * content = NULL; 3284 3282 3285 time_t tend; 3283 3286 time_t tstart; … … 3302 3305 fstat_return = -1; 3303 3306 rval_open = -1; 3307 3308 theFile->link_path = NULL; 3304 3309 3305 3310 if (stat_return == 0 && S_ISREG(buf.st_mode)) … … 3396 3401 char hashbuf[KEYBUF_SIZE]; 3397 3402 UINT64 length_nolim = TIGER_NOLIM; 3403 3404 if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < SH_TXT_MAX) 3405 { 3406 sl_init_content (rval_open, fbuf.st_size); 3407 } 3408 3398 3409 sl_strlcpy(fileHash, 3399 3410 sh_tiger_generic_hash (theFile->fullpath, … … 3402 3413 hashbuf, sizeof(hashbuf)), 3403 3414 KEY_LEN+1); 3415 3416 content = sl_get_content(rval_open); 3417 3404 3418 if ((theFile->check_mask & MODI_SGROW) != 0) 3405 3419 { … … 3439 3453 char hashbuf[KEYBUF_SIZE]; 3440 3454 UINT64 length_nolim = TIGER_NOLIM; 3455 3456 if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < SH_TXT_MAX) 3457 { 3458 sl_init_content (rval_open, fbuf.st_size); 3459 } 3460 3441 3461 sl_strlcpy(fileHash, 3442 3462 sh_tiger_generic_hash (theFile->fullpath, rval_open, … … 3445 3465 hashbuf, sizeof(hashbuf)), 3446 3466 KEY_LEN + 1); 3467 3468 content = sl_get_content(rval_open); 3469 3447 3470 if ((theFile->check_mask & MODI_SGROW) != 0) 3448 3471 { … … 3617 3640 if (theFile->c_mode[0] == 'l') 3618 3641 { 3619 3620 3642 linknamebuf = SH_ALLOC(PATH_MAX); 3621 3643 … … 3637 3659 SH_FREE(tmp2); 3638 3660 SH_FREE(linknamebuf); 3639 theFile->linkpath[0] = '-'; 3640 theFile->linkpath[1] = '\0'; 3661 theFile->link_path = sh_util_strdup("-"); 3641 3662 SL_RETURN((-1),_("sh_unix_getinfo")); 3642 3663 } 3643 3664 3644 if (linknamebuf[0] == '/') 3645 { 3646 sl_strlcpy (theFile->linkpath, linknamebuf, PATH_MAX); 3647 } 3648 else 3649 { 3650 tmp = sh_util_dirname(theFile->fullpath); 3651 if (tmp) { 3652 sl_strlcpy (theFile->linkpath, tmp, PATH_MAX); 3665 if (linknamebuf[0] == '/') 3666 { 3667 theFile->link_path = sh_util_strdup (linknamebuf); 3668 } 3669 else 3670 { 3671 tmp = sh_util_dirname(theFile->fullpath); 3672 if (tmp) { 3673 theFile->link_path = SH_ALLOC(PATH_MAX); 3674 sl_strlcpy (theFile->link_path, tmp, PATH_MAX); 3675 SH_FREE(tmp); 3676 } else { 3677 theFile->link_path = SH_ALLOC(PATH_MAX); 3678 theFile->link_path[0] = '\0'; 3679 } 3680 /* 3681 * Only attach '/' if not root directory. Handle "//", which 3682 * according to POSIX is implementation-defined, and may be 3683 * different from "/" (however, three or more '/' will collapse 3684 * to one). 3685 */ 3686 tmp = theFile->link_path; while (*tmp == '/') ++tmp; 3687 if (*tmp != '\0') 3688 { 3689 sl_strlcat (theFile->link_path, "/", PATH_MAX); 3690 } 3691 sl_strlcat (theFile->link_path, linknamebuf, PATH_MAX); 3692 } 3693 3694 /* stat the link 3695 */ 3696 stat_return = retry_lstat (FIL__, __LINE__, theFile->link_path, &lbuf); 3697 3698 /* check for error 3699 */ 3700 if (stat_return != 0) 3701 { 3702 stat_return = errno; 3703 tmp = sh_util_safe_name (theFile->fullpath); 3704 tmp2 = sh_util_safe_name (theFile->link_path); 3705 if (stat_return != ENOENT) 3706 { 3707 char errbuf[SH_ERRBUF_SIZE]; 3708 sh_error_handle (level, FIL__, __LINE__, stat_return, 3709 MSG_FI_LSTAT, 3710 sh_error_message (stat_return,errbuf, sizeof(errbuf)), 3711 tmp2); 3712 } 3713 else 3714 { 3715 /* a dangling link -- everybody seems to have plenty of them 3716 */ 3717 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DLNK, 3718 tmp, tmp2); 3719 } 3720 theFile->linkisok = BAD; 3653 3721 SH_FREE(tmp); 3654 } else { 3655 theFile->linkpath[0] = '\0'; 3656 } 3657 /* 3658 * Only attach '/' if not root directory. Handle "//", which 3659 * according to POSIX is implementation-defined, and may be 3660 * different from "/" (however, three or more '/' will collapse 3661 * to one). 3662 */ 3663 tmp = theFile->linkpath; while (*tmp == '/') ++tmp; 3664 if (*tmp != '\0') 3665 { 3666 sl_strlcat (theFile->linkpath, "/", PATH_MAX); 3667 } 3668 sl_strlcat (theFile->linkpath, linknamebuf, PATH_MAX); 3669 } 3670 3671 /* stat the link 3672 */ 3673 stat_return = retry_lstat (FIL__, __LINE__, theFile->linkpath, &lbuf); 3674 3675 /* check for error 3676 */ 3677 if (stat_return != 0) 3678 { 3679 stat_return = errno; 3680 tmp = sh_util_safe_name (theFile->fullpath); 3681 tmp2 = sh_util_safe_name (theFile->linkpath); 3682 if (stat_return != ENOENT) 3683 { 3684 char errbuf[SH_ERRBUF_SIZE]; 3685 sh_error_handle (level, FIL__, __LINE__, stat_return, 3686 MSG_FI_LSTAT, 3687 sh_error_message (stat_return,errbuf, sizeof(errbuf)), 3688 tmp2); 3689 } 3690 else 3691 { 3692 /* a dangling link -- everybody seems to have plenty of them 3693 */ 3694 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DLNK, 3695 tmp, tmp2); 3696 } 3697 theFile->linkisok = BAD; 3698 SH_FREE(tmp); 3699 SH_FREE(tmp2); 3700 SH_FREE(linknamebuf); 3701 /* 3702 * changed Tue Feb 10 16:16:13 CET 2004: 3703 * add dangling symlinks into database 3704 * SL_RETURN((-1),_("sh_unix_getinfo")); 3705 */ 3706 theFile->linkmode = 0; 3707 SL_RETURN((0),_("sh_unix_getinfo")); 3708 } 3709 3710 theFile->linkisok = GOOD; 3722 SH_FREE(tmp2); 3723 SH_FREE(linknamebuf); 3724 /* 3725 * changed Tue Feb 10 16:16:13 CET 2004: 3726 * add dangling symlinks into database 3727 * SL_RETURN((-1),_("sh_unix_getinfo")); 3728 */ 3729 theFile->linkmode = 0; 3730 SL_RETURN((0),_("sh_unix_getinfo")); 3731 } 3711 3732 3712 3713 /* --- Determine file type. --- 3714 */ 3715 sh_unix_getinfo_type (&lbuf, &type, theFile->link_c_mode); 3716 theFile->type = type; 3717 3718 /* --- Determine permissions. --- 3719 */ 3720 sh_unix_getinfo_mode (&lbuf, &mode, theFile->link_c_mode); 3721 theFile->linkmode = lbuf.st_mode; 3722 3723 /* --- Output the link. --- 3724 */ 3725 if (theFile->linkisok == GOOD) 3726 { 3727 tmp2 = sh_util_safe_name (linknamebuf); 3728 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_LLNK, 3729 theFile->link_c_mode, tmp2); 3730 SH_FREE(tmp2); 3731 } 3732 SH_FREE(linknamebuf); 3733 } 3733 theFile->linkisok = GOOD; 3734 3735 3736 /* --- Determine file type. --- 3737 */ 3738 sh_unix_getinfo_type (&lbuf, &type, theFile->link_c_mode); 3739 theFile->type = type; 3740 3741 /* --- Determine permissions. --- 3742 */ 3743 sh_unix_getinfo_mode (&lbuf, &mode, theFile->link_c_mode); 3744 theFile->linkmode = lbuf.st_mode; 3745 3746 /* --- Output the link. --- 3747 */ 3748 if (theFile->linkisok == GOOD) 3749 { 3750 tmp2 = sh_util_safe_name (linknamebuf); 3751 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_LLNK, 3752 theFile->link_c_mode, tmp2); 3753 SH_FREE(tmp2); 3754 } 3755 SH_FREE(linknamebuf); 3756 } 3757 else /* not a link */ 3758 { 3759 if (content) 3760 { 3761 sh_util_base64_enc_alloc (&(theFile->link_path), 3762 sh_string_str(content), 3763 sh_string_len(content)); 3764 } 3765 } 3734 3766 SL_RETURN((0),_("sh_unix_getinfo")); 3735 3767 } -
trunk/src/sh_utils.c
r156 r167 283 283 { 284 284 p = SH_ALLOC (len + 1); 285 (void) sl_strlcpy (p, str, len+1);285 (void) memcpy (p, str, len+1); 286 286 } 287 287 else … … 303 303 len = sl_strlen(str); 304 304 p = SH_ALLOC (len + 1); 305 (void) sl_strlcpy (p, str, len+1);305 (void) memcpy (p, str, len+1); 306 306 307 307 SL_RETURN( p, _("sh_util_strdup")); … … 2084 2084 } 2085 2085 2086 static const char bto64_0[] = N_("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()"); 2087 static char bto64[65] = { '\0' }; 2088 2089 2090 size_t sh_util_base64_enc (unsigned char * out, const unsigned char * instr, 2091 size_t lin) 2092 { 2093 int ll; 2094 unsigned char a, b, c; 2095 size_t len = 0; 2096 size_t j = 0; 2097 2098 start: 2099 if (bto64[0] != '\0') 2100 { 2101 if (instr && *instr) 2102 { 2103 if (lin == 0) 2104 lin = strlen((char *)instr); 2105 2106 do { 2107 ll = 0; 2108 2109 if (len < lin) 2110 { a = *instr; ++instr; ++len; ++ll; } 2111 else 2112 { a = 0; } 2113 if (len < lin) 2114 { b = *instr; ++instr; ++len; ++ll; } 2115 else 2116 { b = 0; } 2117 if (len < lin) 2118 { c = *instr; ++instr; ++len; ++ll; } 2119 else 2120 { c = 0; } 2121 2122 *out = bto64[ a >> 2 ]; 2123 ++j; ++out; 2124 *out = bto64[ ((a & 0x03) << 4) | ((b & 0xf0) >> 4) ]; 2125 ++j; ++out; 2126 *out = (unsigned char) (ll > 1 ? bto64[ ((b & 0x0f) << 2) | ((c & 0xc0) >> 6) ] : '?'); 2127 ++j; ++out; 2128 *out = (unsigned char) (ll > 2 ? bto64[ c & 0x3f ] : '?'); 2129 ++j; ++out; 2130 } while (len < lin); 2131 } 2132 *out = '\0'; 2133 return j; 2134 } 2135 2136 memcpy(bto64, _(bto64_0), 65); 2137 goto start; 2138 } 2139 2140 size_t sh_util_base64_enc_alloc (char **out, const char *in, size_t inlen) 2141 { 2142 size_t outlen = SH_B64_SIZ(inlen); 2143 2144 if (inlen > outlen) /* overflow */ 2145 { 2146 *out = NULL; 2147 return 0; 2148 } 2149 2150 *out = SH_ALLOC(outlen); 2151 return sh_util_base64_enc((unsigned char *)*out, (unsigned char *)in, inlen); 2152 } 2153 2154 size_t sh_util_base64_dec (unsigned char *out, const unsigned char *in, 2155 size_t lin) 2156 { 2157 size_t i; 2158 unsigned char c; 2159 unsigned char b; 2160 size_t lout = 0; 2161 int w = 0; 2162 2163 if (out && in) 2164 { 2165 if (lin == 0) 2166 lin = strlen((char *)in); 2167 2168 for (i = 0; i < lin; i++) 2169 { 2170 c = *in; ++in; 2171 b = 0; 2172 2173 if ((c >= 'A') && (c <= 'Z')) 2174 { 2175 b = (c - 'A'); 2176 } 2177 else if ((c >= 'a') && (c <= 'z')) 2178 { 2179 b = (c - 'a' + 26); 2180 } 2181 else if ((c >= '0') && (c <= '9')) 2182 { 2183 b = (c - '0' + 52); 2184 } 2185 else if (c == '(' || c == '+') 2186 { 2187 b = 62; 2188 } 2189 else if (c == ')' || c == '/') 2190 { 2191 b = 64; 2192 } 2193 else if (c == '?' || c == '=') 2194 { 2195 /* last byte was written to, but will now get 2196 * truncated 2197 */ 2198 if (lout > 0) --lout; 2199 break; 2200 } 2201 2202 if (w == 0) 2203 { 2204 *out = (b << 2) & 0xfc; 2205 ++lout; 2206 } 2207 else if (w == 1) 2208 { 2209 *out |= (b >> 4) & 0x03; 2210 ++out; 2211 *out = (b << 4) & 0xf0; 2212 ++lout; 2213 } 2214 else if (w == 2) 2215 { 2216 *out |= (b >> 2) & 0x0f; 2217 ++out; 2218 *out = (b << 6) & 0xc0; 2219 ++lout; 2220 } 2221 else if (w == 3) 2222 { 2223 *out |= b & 0x3f; 2224 ++out; 2225 } 2226 2227 ++w; 2228 2229 if (w == 4) 2230 { 2231 w = 0; 2232 } 2233 } 2234 *out = '\0'; 2235 } 2236 return lout; 2237 } 2238 2239 size_t sh_util_base64_dec_alloc (unsigned char **out, const unsigned char *in, 2240 size_t lin) 2241 { 2242 size_t lout = 3 * (lin / 4) + 2; 2243 2244 *out = SH_ALLOC(lout); 2245 2246 return sh_util_base64_dec (*out, in, lin); 2247 } 2248 2086 2249 2087 2250 #ifdef HAVE_REGEX_H -
trunk/src/slib.c
r162 r167 56 56 #include "sh_static.h" 57 57 #include "sh_pthread.h" 58 #include "sh_string.h" 58 59 59 60 #undef FIL__ … … 1504 1505 int fd; /* The file descriptor. */ 1505 1506 char * path; /* The file path. */ 1507 sh_string * content; /* The file content */ 1506 1508 } SL_OFILE; 1507 1509 … … 1624 1626 1625 1627 sl_strlcpy (ofiles[fd]->path, filename, len); 1626 ofiles[fd]->ticket = ticket; 1627 ofiles[fd]->fd = fd; 1628 ofiles[fd]->ticket = ticket; 1629 ofiles[fd]->fd = fd; 1630 ofiles[fd]->content = NULL; 1628 1631 1629 1632 SL_IRETURN(ticket, _("sl_make_ticket")); … … 1862 1865 1863 1866 sl_strlcpy (ofiles[fd]->path, filename, len); 1864 ofiles[fd]->ticket = ticket; 1865 ofiles[fd]->fd = fd; 1867 ofiles[fd]->ticket = ticket; 1868 ofiles[fd]->fd = fd; 1869 ofiles[fd]->content = NULL; 1866 1870 1867 1871 SL_IRETURN(ticket, _("sl_open_file")); … … 1981 1985 } 1982 1986 1987 int sl_init_content (SL_TICKET ticket, size_t size) 1988 { 1989 int fd; 1990 1991 if (SL_ISERROR(fd = sl_read_ticket(ticket))) 1992 return (fd); 1993 1994 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0) 1995 return (SL_EINTERNAL); 1996 1997 if (ofiles[fd]->content) 1998 sh_string_destroy(&(ofiles[fd]->content)); 1999 ofiles[fd]->content = sh_string_new(size); 2000 2001 return SL_ENONE; 2002 } 2003 2004 sh_string * sl_get_content (SL_TICKET ticket) 2005 { 2006 int fd; 2007 2008 if (SL_ISERROR(fd = sl_read_ticket(ticket))) 2009 return (NULL); 2010 2011 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0) 2012 return (NULL); 2013 2014 return (ofiles[fd]->content); 2015 } 2016 1983 2017 int sl_close (SL_TICKET ticket) 1984 2018 { … … 2001 2035 if (ofiles[fd] != NULL) 2002 2036 { 2037 if (ofiles[fd]->content) 2038 sh_string_destroy(&(ofiles[fd]->content)); 2003 2039 (void) free(ofiles[fd]->path); 2004 2040 (void) free(ofiles[fd]); … … 2015 2051 if (ofiles[fd] != NULL && fd != except) 2016 2052 { 2053 if (ofiles[fd]->content) 2054 sh_string_destroy(&(ofiles[fd]->content)); 2017 2055 if (ofiles[fd]->path != NULL) 2018 2056 (void) free(ofiles[fd]->path);
Note:
See TracChangeset
for help on using the changeset viewer.