Changeset 543 for trunk


Ignore:
Timestamp:
Feb 17, 2019, 2:27:24 PM (6 years ago)
Author:
katerina
Message:

Fix for ticket #434 (option to init for alternative root fs).

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/sh_dbIO.h

    r481 r543  
    5959int sh_dbIO_list_filter (const char * c);
    6060
     61/* alternative rootfs */
     62
     63int sh_dbIO_init_rootfs (const char * rootfs);
     64size_t sh_dbIO_get_rootfs_len();
     65char * sh_dbIO_rootfs_prepend(char * path);
     66char * sh_dbIO_rootfs_strip(char * path);
     67char * sh_dbIO_rootfs_strip_link(char * path);
     68
    6169#endif
  • trunk/src/sh_dbIO.c

    r541 r543  
    385385      path[len-2] = '\0';
    386386  }
     387  return path;
     388}
     389
     390/******************************************************************
     391 *
     392 * Use different init rootfs (patch by Kemal H.)
     393 *
     394 ******************************************************************/
     395
     396static char * sh_dbIO_rootfs = NULL;
     397static size_t sh_dbIO_rootfs_len = 0;
     398
     399int sh_dbIO_init_rootfs (const char * rootfs)
     400{
     401  if (NULL == sh_dbIO_rootfs)
     402    {
     403      sh_dbIO_rootfs     = sh_util_strdup (rootfs);
     404      sh_dbIO_rootfs_len = sl_strlen(sh_dbIO_rootfs);
     405      return 0;
     406    }
     407  return -1;
     408}
     409
     410size_t sh_dbIO_get_rootfs_len()
     411{
     412  return sh_dbIO_rootfs_len;
     413}
     414
     415/* Prepend rootfs when reading from config file ('path' must be allocated with sufficient space).
     416 */
     417char * sh_dbIO_rootfs_prepend(char * path)
     418{
     419  if (0 == sh_dbIO_rootfs_len)
     420    return path;
     421 
     422  memmove (path + sh_dbIO_rootfs_len, path, sl_strlen(path) + 1);
     423  memcpy  (path, sh_dbIO_rootfs, sh_dbIO_rootfs_len);
     424
     425  return path;
     426}
     427
     428
     429/* Strip rootfs when writing to database file.
     430 */
     431char * sh_dbIO_rootfs_strip(char * path)
     432{
     433  if (sh_dbIO_rootfs_len == 0)
     434    {
     435      return path;
     436    }
     437  else
     438    {
     439      size_t len = sl_strlen(path);
     440
     441      memmove (path, path + sh_dbIO_rootfs_len, len + 1 - sh_dbIO_rootfs_len);
     442      if(path[0] != '/')
     443        {
     444          path[0]='/';
     445          path[1]='\0';
     446        }
     447    }
     448
     449  return path;
     450}
     451
     452char * sh_dbIO_rootfs_strip_link(char * path)
     453{
     454  if (sh_dbIO_rootfs_len == 0)
     455    return path;
     456  if (strstr(path, sh_dbIO_rootfs) == path)
     457    {
     458      size_t len = sl_strlen(path);
     459
     460      memmove (path, path + sh_dbIO_rootfs_len, len + 1 - sh_dbIO_rootfs_len);
     461    }
    387462  return path;
    388463}
  • trunk/src/sh_files.c

    r539 r543  
    215215{
    216216  char  * p;
    217 
     217 
    218218  if (!str_s || *str_s == '\0')
    219219    return NULL;
    220220
    221221  *len = sl_strlen(str_s);
    222 
     222  if (sh.flag.checkSum == SH_CHECK_INIT)
     223    {
     224      size_t addspace = sh_dbIO_get_rootfs_len();
     225      if (addspace != 0 && S_TRUE == sl_ok_adds (*len, addspace))
     226        *len += addspace;
     227    }
     228 
    223229  if ( (str_s[0] == '"'  && str_s[*len-1] == '"' ) ||
    224230       (str_s[0] == '\'' && str_s[*len-1] == '\'') )
     
    14211427    SL_RETURN((-1), _("sh_files_pushfile"));
    14221428
     1429  if (sh.flag.checkSum == SH_CHECK_INIT)
     1430    p = sh_dbIO_rootfs_prepend(p);
     1431     
    14231432  if (len >= PATH_MAX)
    14241433    {
     
    18551864    }
    18561865
     1866  if (sh.flag.checkSum == SH_CHECK_INIT)
     1867    tail = sh_dbIO_rootfs_prepend(tail);
     1868
    18571869  len = sl_strlen(tail);
    18581870
     
    27632775        MODI_SET(theFile->check_flags, MODI_NOCHECK);
    27642776      sh_tiger_get_mask_hashtype(&(theFile->check_flags));
     2777
     2778      sh_dbIO_rootfs_strip(theFile->fullpath);
     2779      if (theFile->link_path)
     2780        sh_dbIO_rootfs_strip_link(theFile->link_path);
    27652781      sh_dbIO_data_write (theFile, fileHash);
    27662782    }
  • trunk/src/sh_getopt.c

    r539 r543  
    291291    HAS_ARG_YES,
    292292    sh_dbCreate},
     293  { N_("init-rootfs"), 
     294    '-',
     295    N_("Build database based on another rootfs"), 
     296    HAS_ARG_YES,
     297    sh_dbIO_init_rootfs},
    293298  { N_("wait-on-check"), 
    294299    'w',
  • trunk/src/sh_suidchk.c

    r517 r543  
    13031303                    /* Running init. Report on files detected.
    13041304                     */
     1305                    sh_dbIO_rootfs_strip(theFile->fullpath);
    13051306                    sh_dbIO_data_write (theFile, fileHash); /* no call to sh_error_handle */
    13061307                    SH_MUTEX_LOCK(mutex_thread_nolog);
Note: See TracChangeset for help on using the changeset viewer.