source: trunk/src/sh_dbCheck.c

Last change on this file was 481, checked in by katerina, 6 years ago

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File size: 3.6 KB
Line 
1/* SAMHAIN file system integrity testing                                   */
2/* Copyright (C) 2015 Rainer Wichmann                                      */
3/*                                                                         */
4/*  This program is free software; you can redistribute it                 */
5/*  and/or modify                                                          */
6/*  it under the terms of the GNU General Public License as                */
7/*  published by                                                           */
8/*  the Free Software Foundation; either version 2 of the License, or      */
9/*  (at your option) any later version.                                    */
10/*                                                                         */
11/*  This program is distributed in the hope that it will be useful,        */
12/*  but WITHOUT ANY WARRANTY; without even the implied warranty of         */
13/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
14/*  GNU General Public License for more details.                           */
15/*                                                                         */
16/*  You should have received a copy of the GNU General Public License      */
17/*  along with this program; if not, write to the Free Software            */
18/*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
19
20#include "config_xor.h"
21
22#include <string.h>
23
24#include "samhain.h"
25#include "sh_unix.h"
26#include "sh_utils.h"
27#include "sh_hash.h"
28#include "sh_files.h"
29#include "sh_tiger.h"
30
31#include "sh_dbIO.h"
32#include "sh_dbIO_int.h"
33#include "sh_pthread.h"
34
35#undef  FIL__
36#define FIL__  _("sh_dbCheck.c")
37
38#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
39
40static void file_verify(sh_file_t * p)
41{
42  int reported = 0;
43  unsigned long check_flags;
44  char * dir_name;
45  char * file_name;
46
47  if (p->next != NULL)
48    file_verify(p->next);
49  if (p->fullpath == NULL || p->fullpath[0] != '/')
50    return;
51
52  check_flags = p->theFile.checkflags;
53
54  if (!MODI_INITIALIZED(check_flags)) {
55    MODI_SET(check_flags, MODI_INIT|MASK_READONLY_);
56    sh_tiger_get_mask_hashtype(&check_flags);
57  }
58
59  dir_name   = sh_util_dirname(p->fullpath);
60  file_name  = sh_util_basename(p->fullpath);
61
62  if (SH_FILE_UNKNOWN == sh_files_filecheck (SH_LEVEL_READONLY, check_flags,
63                                             dir_name, file_name,
64                                             &reported, 0))
65    ++sh.statistics.files_report;
66
67  SH_FREE(dir_name);
68  SH_FREE(file_name);
69  return;
70}
71
72static void dbCheck_setup()
73{
74  sh_hash_set_initialized();
75  sh.flag.isdaemon = S_FALSE; 
76  sh.flag.loop     = S_FALSE;
77  sh.flag.update   = S_FALSE;
78  sh.flag.checkSum = SH_CHECK_CHECK;
79 
80  sh.statistics.files_report  = 0;
81  ShDFLevel[SH_ERR_T_FILE]    = SH_ERR_SEVERE;
82  ShDFLevel[SH_ERR_T_RO]      = SH_ERR_SEVERE;
83  ShDFLevel[SH_ERR_T_NAME]    = SH_ERR_SEVERE;
84
85  return;
86}
87#include <stddef.h>
88int sh_dbCheck_verify (const char * db_file)
89{
90  unsigned int i;
91  sh_file_t ** mtab = get_default_data_table();
92 
93  sh_error_only_stderr (S_TRUE);
94  sh_error_setprint(_("none"));
95
96  /* for sh.effective.home in open_tmp() */
97  sh_unix_getUser (); 
98
99  if (sh_dbIO_load_db_file(mtab, db_file) < 0)
100    aud_exit (FIL__, __LINE__, EXIT_FAILURE);
101
102  dbCheck_setup();
103
104  /* Don't lock because:
105   * (a) we are single-treaded, thus it's not required
106   * (b) it will lead to deadlocking
107   */
108  for (i = 0; i < TABSIZE; ++i)
109    {
110      if (mtab[i] != NULL) 
111        file_verify(mtab[i]);
112    }
113 
114  sh_hash_unvisited (SH_ERR_INFO);
115 
116  if (0 != sh.statistics.files_report)
117    aud_exit (FIL__, __LINE__, EXIT_FAILURE);
118  aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
119  return 0;
120}
121
122#endif
Note: See TracBrowser for help on using the repository browser.