Changeset 167 for trunk/src


Ignore:
Timestamp:
Mar 15, 2008, 12:38:20 PM (17 years ago)
Author:
katerina
Message:

First parts of changes for MODI_TXT

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_utils.c

    r157 r167  
    128128}
    129129
     130void 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
    130179void Test_sh_util_dirname_ok (CuTest *tc) {
    131180  char * ret = 0;
  • trunk/src/sh_files.c

    r137 r167  
    616616        if (0 == strncmp(myword, _("PRE"), 3))
    617617          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);
    618621       
    619622      }
     
    15701573  sl_strlcpy (theFile.fullpath, iname, PATH_MAX);
    15711574  theFile.attr_string = NULL;
     1575  theFile.link_path   = NULL;
    15721576
    15731577  (void) relativeName;
     
    15791583    {
    15801584      if (theFile.attr_string) SH_FREE(theFile.attr_string);
     1585      if (theFile.link_path)   SH_FREE(theFile.link_path);
    15811586      SL_RETURN((0), _("sh_files_checkdir"));
    15821587    }
     
    15861591      SH_FREE(tmpname);
    15871592      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"));
    15891595    }
    15901596
     
    15961602      SH_FREE(tmpname);
    15971603      if (theFile.attr_string) SH_FREE(theFile.attr_string);
     1604      if (theFile.link_path)   SH_FREE(theFile.link_path);
    15981605      SL_RETURN((-1), _("sh_files_checkdir"));
    15991606    }
     
    16181625
    16191626      if (theFile.attr_string) SH_FREE(theFile.attr_string);
     1627      if (theFile.link_path)   SH_FREE(theFile.link_path);
    16201628      SL_RETURN((-1), _("sh_files_checkdir"));
    16211629    }
     
    16761684      {
    16771685        if (theFile.attr_string) SH_FREE(theFile.attr_string);
     1686        if (theFile.link_path)   SH_FREE(theFile.link_path);
    16781687        SL_RETURN((0), _("sh_files_checkdir"));
    16791688      }
     
    18711880      {
    18721881        if (theFile.attr_string) SH_FREE(theFile.attr_string);
     1882        if (theFile.link_path)   SH_FREE(theFile.link_path);
    18731883        SL_RETURN((0), _("sh_files_checkdir"));
    18741884      }
     
    19181928
    19191929  if (theFile.attr_string) SH_FREE(theFile.attr_string);
     1930  if (theFile.link_path)   SH_FREE(theFile.link_path);
    19201931  SH_FREE(tmpname);
    19211932
     
    20162027  theFile.file_reported = (*reported);
    20172028  theFile.attr_string   = NULL;
     2029  theFile.link_path     = NULL;
    20182030
    20192031  TPT(( 0, FIL__, __LINE__, _("msg=<checking file: %s>\n"),  fullpath));
     
    20302042      if (class == SH_LEVEL_ALLIGNORE && sh.flag.checkSum != SH_CHECK_INIT)
    20312043        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);
    20342046      SL_RETURN(SH_FILE_UNKNOWN, _("sh_files_filecheck"));
    20352047    }
     
    21092121
    21102122  if (theFile.attr_string) SH_FREE(theFile.attr_string);
     2123  if (theFile.link_path)   SH_FREE(theFile.link_path);
    21112124
    21122125  switch (theFile.c_mode[0])
  • trunk/src/sh_hash.c

    r162 r167  
    363363
    364364  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);
    368368    }
    369369  else
    370370    {
    371       theFile->linkpath[0] = '-';
    372       theFile->linkpath[1] = '\0';
     371      theFile->link_path = NULL;
    373372    }
    374373  sl_strlcpy(fileHash, p->theFile.checksum, KEY_LEN+1);
     
    454453  SH_FREE(tmp);
    455454  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);
    458457  SH_FREE(theFile);
    459458
     
    541540                                   MSG_FI_MISS2, tmp, str);
    542541                  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);
    545544                  SH_FREE(theFile);
    546545
     
    10091008  else
    10101009    {
    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';
    10161014    }
    10171015
     
    16141612  }
    16151613
    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)
    16171615    { 
    16181616
    1619       old_len = sl_strlen(buf->linkpath);
     1617      old_len = sl_strlen(buf->link_path);
    16201618#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);
    16241623      tmp_len = sl_strlen(tmp);
    16251624#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);
    16271627#endif
    16281628
    16291629      if (tmp && tmp_len <= MAX_PATH_STORE)
    16301630        {
    1631           sl_strlcpy(linkpath, buf->linkpath, MAX_PATH_STORE+1); 
     1631          sl_strlcpy(linkpath, buf->link_path, MAX_PATH_STORE+1); 
    16321632        }
    16331633      else
     
    16351635          char hashbuf[KEYBUF_SIZE];
    16361636          sl_strlcpy(linkpath,
    1637                      sh_tiger_hash (buf->linkpath,
     1637                     sh_tiger_hash (buf->link_path,
    16381638                                    TIGER_DATA, old_len,
    16391639                                    hashbuf, sizeof(hashbuf)),
     
    16441644      path_len = sl_strlen(linkpath);
    16451645#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);
    16471648#endif
    16481649      tmp = quote_string(linkpath, path_len);
     
    18731874          f = sh_hash_create_ft (p, fileHash);
    18741875          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);
    18771878          SH_FREE(f);
    18781879        }
     
    19481949    sh_hash_init();
    19491950
     1951  tmpFile->link_path   = NULL;
     1952  tmpFile->attr_string = NULL;
     1953
    19501954  SH_MUTEX_LOCK(mutex_hash);
    19511955  p = sh_hash_have_it_int (newname);
    19521956  if (p)
    19531957    {
    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);
    19561961      tmpFile->size  = p->theFile.size;
    19571962      tmpFile->mtime = p->theFile.mtime;
     
    21212126
    21222127  tmpFile.attr_string = NULL;
     2128  tmpFile.link_path   = NULL;
    21232129
    21242130  sl_strlcpy(tmpFile.fullpath, key, PATH_MAX);
     
    21412147      tmpFile.c_mode[5] = 'w'; tmpFile.c_mode[6]  = 'x';
    21422148      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);
    21442151      for (i = 0; i < size; ++i)
    21452152        {
    21462153          p = sh_util_charhex (str[i],i2h);
    2147           tmpFile.linkpath[2*i]   = p[0];
    2148           tmpFile.linkpath[2*i+1] = p[1];
    2149           tmpFile.linkpath[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';
    21502157        }
    21512158    }
     
    21542161      for (i = 0; i < 10; ++i)
    21552162        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("-");
    21592165    }
    21602166
     
    21652171    sh_hash_pushdata (&tmpFile, SH_KEY_NULL);
    21662172
     2173  if (tmpFile.link_path) SH_FREE(tmpFile.link_path);
    21672174  return;
    21682175}
     
    21782185  char      * p;
    21792186  int         i;
    2180 
     2187  char      * retval = NULL;
     2188 
    21812189  *size = 0;
    21822190
     
    21872195      *val3 = tmpFile.ctime;
    21882196
    2189       if (tmpFile.linkpath[0] != '-')
    2190         {
    2191           len = strlen(tmpFile.linkpath);
     2197      if (tmpFile.link_path && tmpFile.link_path[0] != '-')
     2198        {
     2199          len = strlen(tmpFile.link_path);
    21922200
    21932201          p = SH_ALLOC((len/2)+1);
    2194           i = sh_util_hextobinary (p, tmpFile.linkpath, len);
     2202          i = sh_util_hextobinary (p, tmpFile.link_path, len);
    21952203
    21962204          if (i == 0)
     
    21982206              *size = (len/2);
    21992207              p[*size] = '\0';
    2200               return p;
     2208              retval = p;
    22012209            }
    22022210          else
     
    22042212              SH_FREE(p);
    22052213              *size = 0;
    2206               return NULL;
    22072214            }
    22082215        }
     
    22102217        {
    22112218          *size = 0;
    2212           return NULL;
    22132219        }
    22142220    }
     
    22192225      *val2 =  0;
    22202226      *val3 =  0;
    2221       return NULL;
    2222     }
     2227    }
     2228  if (tmpFile.link_path) SH_FREE(tmpFile.link_path);
     2229  return retval;
    22232230}
    22242231
     
    22972304  fp->fullpath  = fullpath;
    22982305
    2299   if (buf->c_mode[0] == 'l')
     2306  if (buf->link_path)
    23002307    { 
    2301       len = sl_strlen(buf->linkpath);
     2308      len = sl_strlen(buf->link_path);
    23022309      if (len <= MAX_PATH_STORE)
    23032310        {
    23042311          linkpath = SH_ALLOC(len+1);
    2305           sl_strlcpy(linkpath, buf->linkpath, len+1);
     2312          sl_strlcpy(linkpath, buf->link_path, len+1);
    23062313        }
    23072314      else
     
    23092316          linkpath = SH_ALLOC(KEY_LEN + 1);
    23102317          sl_strlcpy(linkpath,
    2311                      sh_tiger_hash (buf->linkpath, TIGER_DATA, len,
     2318                     sh_tiger_hash (buf->link_path, TIGER_DATA, len,
    23122319                                    hashbuf, sizeof(hashbuf)),
    23132320                     KEY_LEN+1);
     
    24902497  sl_strlcat(msg, tmp, SH_BUFSIZE);
    24912498
    2492   if (theFile->c_mode[0] == 'l')
    2493     {
    2494       tmp_lnk     = sh_util_safe_name(theFile->linkpath);
     2499  if (theFile->c_mode[0] == 'l' || theFile->link_path != NULL)
     2500    {
     2501      tmp_lnk     = sh_util_safe_name(theFile->link_path);
    24952502      if (tmp_lnk)
    24962503        {
     
    26562663  sl_strlcat(msg, tmp, SH_BUFSIZE);
    26572664
    2658   if (theFile->c_mode[0] == 'l')
    2659     {
    2660       tmp_lnk     = sh_util_safe_name(theFile->linkpath);
     2665  if (theFile->c_mode[0] == 'l' || theFile->link_path != NULL)
     2666    {
     2667      tmp_lnk     = sh_util_safe_name(theFile->link_path);
    26612668      if (tmp_lnk)
    26622669        {
     
    28622869  if (p->theFile.c_mode[0] == 'l')
    28632870    {
    2864       if (sl_strlen(theFile->linkpath) >= MAX_PATH_STORE)
     2871      if (sl_strlen(theFile->link_path) >= MAX_PATH_STORE)
    28652872        {
    28662873          sl_strlcpy(linkHash,
    2867                      sh_tiger_hash(theFile->linkpath,
     2874                     sh_tiger_hash(theFile->link_path,
    28682875                                   TIGER_DATA,
    2869                                    sl_strlen(theFile->linkpath),
     2876                                   sl_strlen(theFile->link_path),
    28702877                                   hashbuf, sizeof(hashbuf)),
    28712878                     MAX_PATH_STORE+1);
     
    28742881      else
    28752882        {
    2876           sl_strlcpy(linkHash, theFile->linkpath, KEY_LEN + 1);
     2883          sl_strlcpy(linkHash, theFile->link_path, KEY_LEN + 1);
    28772884          maxcomp = KEY_LEN;
    28782885        }
     
    33473354      if ((modi_mask & MODI_LNK) != 0 && theFile->c_mode[0] == 'l')
    33483355        {
    3349           tmp_lnk     = sh_util_safe_name(theFile->linkpath);
     3356          tmp_lnk     = sh_util_safe_name(theFile->link_path);
    33503357          tmp_lnk_old = sh_util_safe_name(p->linkpath);
    33513358#ifdef SH_USE_XML
     
    33643371              if (p->linkpath != NULL && p->linkpath != notalink)
    33653372                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'))
    33673375                p->linkpath = (char *)notalink;
    33683376              else
    3369                 p->linkpath = sh_util_strdup(theFile->linkpath);
     3377                p->linkpath = sh_util_strdup(theFile->link_path);
    33703378            }
    33713379#endif
     
    34173425              if (theFile->c_mode[0] == 'l') /* c_mode is already copied */
    34183426                {
    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("-");
    34203433                }
    34213434              else
    34223435                {
    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;
    34253442                }
    34263443             
     
    34753492#endif
    34763493             
    3477               if (theFile->c_mode[0] == 'l')
     3494              if (theFile->c_mode[0] == 'l' || theFile->link_path)
    34783495                {
    34793496                  if (p->linkpath != NULL && p->linkpath != notalink)
    34803497                    SH_FREE(p->linkpath);
    3481                   p->linkpath = sh_util_strdup(theFile->linkpath);
     3498                  p->linkpath = sh_util_strdup(theFile->link_path);
    34823499                }
    34833500              else
    34843501                {
    34853502                  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;
    34913506                }
    34923507             
  • trunk/src/sh_kern.c

    r162 r167  
    915915  CLEAR_SH_FFLAG_REPORTED(theFile.file_reported);
    916916  theFile.attr_string = NULL;
     917  theFile.link_path   = NULL;
    917918 
    918919  status = sh_unix_getinfo (ShDFLevel[SH_ERR_T_RO],
     
    928929                       tmp);
    929930      SH_FREE(tmp);
    930       return;
     931      goto out;
    931932    }
    932933
     
    940941    }
    941942
     943 out:
     944  if (theFile.attr_string) SH_FREE(theFile.attr_string);
     945  if (theFile.link_path)   SH_FREE(theFile.link_path);
    942946  return;
    943947}
  • trunk/src/sh_suidchk.c

    r166 r167  
    10321032            CLEAR_SH_FFLAG_REPORTED(theFile.file_reported);
    10331033            theFile.attr_string = NULL;
     1034            theFile.link_path   = NULL;
    10341035           
    10351036            status = sh_unix_getinfo (ShDFLevel[SH_ERR_T_RO],
     
    11611162              }
    11621163            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);
    11651166          }
    11661167      }
  • trunk/src/sh_tiger0.c

    r151 r167  
    2525#include "sh_utils.h"
    2626#include "sh_pthread.h"
     27#include "sh_string.h"
    2728
    2829#define PRIV_MAX  32768
     
    114115{
    115116  SL_TICKET  fd;
     117  sh_string * content = NULL;
    116118  int  i, j, tt;
    117119  int  count = 0;
     
    159161      if (what > TIGER_FILE)
    160162        {
    161           fd = what;
     163          fd      = what;
     164          content = sl_get_content(fd);
    162165          TPT((0,FIL__, __LINE__, _("msg=<TIGER_FD>, fd=<%ld>\n"), fd));
    163166        }
     
    247250            SL_RETURN( NULL, _("sh_tiger_hash_val"));
    248251          }
     252
     253        if (content)
     254          sh_string_cat_lchar(content, (char*)buffer, count);
    249255
    250256        bcount += count;
     
    843849  uid_t   euid;
    844850  UINT64  bcount = 0;
     851  sh_string * content;
    845852
    846853  unsigned long pages_read;
     
    867874
    868875  pages_read = 0;
     876
     877  content = sl_get_content(fd);
    869878
    870879  /* Iterate over full file contents.  */
     
    902911          return -1;
    903912        }
     913
     914      if (content)
     915        sh_string_cat_lchar(content, buffer, n);
    904916
    905917      bcount += n;
     
    13601372  uid_t  euid;
    13611373  UINT64 bcount = 0;
     1374  sh_string * content;
    13621375
    13631376  unsigned long pages_read;
     
    13861399
    13871400  pages_read = 0;
     1401
     1402  content = sl_get_content(fd);
    13881403
    13891404  while (1 == 1) {
     
    14221437          return -1;
    14231438        }
     1439
     1440      if (content)
     1441        sh_string_cat_lchar(content, buffer, n);
    14241442
    14251443      bcount += n;
  • trunk/src/sh_unix.c

    r162 r167  
    30623062     
    30633063       /* return */
     3064      if (tmpFile.link_path)   SH_FREE(tmpFile.link_path);
    30643065      SL_RETURN( 0, _("sh_unix_checksum_size"));
    30653066    }
    30663067
    30673068 out:
     3069  if (tmpFile.link_path)   SH_FREE(tmpFile.link_path);
    30683070  sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
    30693071  SL_RETURN( -1, _("sh_unix_checksum_size"));
     
    32793281  int           fd;
    32803282  int           fstat_return;
    3281 
     3283  sh_string   * content = NULL;
     3284     
    32823285  time_t        tend;
    32833286  time_t        tstart;
     
    33023305  fstat_return = -1;
    33033306  rval_open    = -1;
     3307
     3308  theFile->link_path = NULL;
    33043309
    33053310  if (stat_return == 0 && S_ISREG(buf.st_mode))
     
    33963401              char hashbuf[KEYBUF_SIZE];
    33973402              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
    33983409              sl_strlcpy(fileHash,
    33993410                         sh_tiger_generic_hash (theFile->fullpath,
     
    34023413                                                hashbuf, sizeof(hashbuf)),
    34033414                         KEY_LEN+1);
     3415
     3416              content = sl_get_content(rval_open);
     3417
    34043418              if ((theFile->check_mask & MODI_SGROW) != 0)
    34053419                {
     
    34393453              char hashbuf[KEYBUF_SIZE];
    34403454              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
    34413461              sl_strlcpy(fileHash,
    34423462                         sh_tiger_generic_hash (theFile->fullpath, rval_open,
     
    34453465                                                hashbuf, sizeof(hashbuf)),
    34463466                         KEY_LEN + 1);
     3467
     3468              content = sl_get_content(rval_open);
     3469
    34473470              if ((theFile->check_mask & MODI_SGROW) != 0)
    34483471                {
     
    36173640  if (theFile->c_mode[0] == 'l')
    36183641    {
    3619 
    36203642      linknamebuf = SH_ALLOC(PATH_MAX);
    36213643
     
    36373659          SH_FREE(tmp2);
    36383660          SH_FREE(linknamebuf);
    3639           theFile->linkpath[0] = '-';
    3640           theFile->linkpath[1] = '\0';
     3661          theFile->link_path = sh_util_strdup("-");
    36413662          SL_RETURN((-1),_("sh_unix_getinfo"));
    36423663        }
    36433664
    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;
    36533721          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        }
    37113732     
    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    }
    37343766  SL_RETURN((0),_("sh_unix_getinfo"));
    37353767}
  • trunk/src/sh_utils.c

    r156 r167  
    283283    {
    284284      p   = SH_ALLOC (len + 1);
    285       (void) sl_strlcpy (p, str, len+1);
     285      (void) memcpy (p, str, len+1);
    286286    }
    287287  else
     
    303303  len = sl_strlen(str);
    304304  p   = SH_ALLOC (len + 1);
    305   (void) sl_strlcpy (p, str, len+1);
     305  (void) memcpy (p, str, len+1);
    306306
    307307  SL_RETURN( p, _("sh_util_strdup"));
     
    20842084}
    20852085
     2086static const char bto64_0[] = N_("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()");
     2087static char bto64[65] = { '\0' };
     2088
     2089 
     2090size_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
     2140size_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
     2154size_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
     2239size_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
    20862249
    20872250#ifdef HAVE_REGEX_H
  • trunk/src/slib.c

    r162 r167  
    5656#include "sh_static.h"
    5757#include "sh_pthread.h"
     58#include "sh_string.h"
    5859
    5960#undef  FIL__
     
    15041505  int fd;               /* The file descriptor. */
    15051506  char * path;          /* The file path.       */
     1507  sh_string * content;  /* The file content     */
    15061508} SL_OFILE;
    15071509
     
    16241626
    16251627  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;
    16281631
    16291632  SL_IRETURN(ticket, _("sl_make_ticket"));
     
    18621865
    18631866  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;
    18661870
    18671871  SL_IRETURN(ticket, _("sl_open_file"));
     
    19811985}
    19821986
     1987int 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
     2004sh_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
    19832017int sl_close (SL_TICKET ticket)
    19842018{
     
    20012035  if (ofiles[fd] != NULL)
    20022036    {
     2037      if (ofiles[fd]->content)
     2038        sh_string_destroy(&(ofiles[fd]->content));
    20032039      (void) free(ofiles[fd]->path);
    20042040      (void) free(ofiles[fd]);
     
    20152051      if (ofiles[fd] != NULL && fd != except)
    20162052        {
     2053          if (ofiles[fd]->content)
     2054            sh_string_destroy(&(ofiles[fd]->content));
    20172055          if (ofiles[fd]->path != NULL)
    20182056            (void) free(ofiles[fd]->path);
Note: See TracChangeset for help on using the changeset viewer.