[1] | 1 | /* SAMHAIN file system integrity testing */
|
---|
| 2 | /* Copyright (C) 2003 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 | #ifndef NULL
|
---|
| 23 | #if !defined(__cplusplus)
|
---|
| 24 | #define NULL ((void*)0)
|
---|
| 25 | #else
|
---|
| 26 | #define NULL (0)
|
---|
| 27 | #endif
|
---|
| 28 | #endif
|
---|
| 29 |
|
---|
| 30 | #ifdef HAVE_REGEX_H
|
---|
| 31 | #include <sys/types.h>
|
---|
| 32 | #include <regex.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include "samhain.h"
|
---|
| 36 | #include "sh_mem.h"
|
---|
| 37 | #include "sh_error.h"
|
---|
| 38 |
|
---|
| 39 | #define FIL__ _("sh_ignore.c")
|
---|
| 40 |
|
---|
| 41 | struct sh_ignore_list {
|
---|
| 42 | #ifdef HAVE_REGEX_H
|
---|
| 43 | regex_t preg;
|
---|
| 44 | #else
|
---|
| 45 | char * path;
|
---|
| 46 | #endif
|
---|
| 47 | struct sh_ignore_list * next;
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | static struct sh_ignore_list * sh_del_ign = NULL;
|
---|
| 52 | static struct sh_ignore_list * sh_new_ign = NULL;
|
---|
| 53 |
|
---|
| 54 | static struct sh_ignore_list * sh_ignore_add_int(struct sh_ignore_list * list,
|
---|
[22] | 55 | const char * addpath)
|
---|
[1] | 56 | {
|
---|
| 57 | struct sh_ignore_list * new;
|
---|
| 58 | #ifdef HAVE_REGEX_H
|
---|
| 59 | int status = -1;
|
---|
| 60 | char * errbuf;
|
---|
| 61 | #else
|
---|
| 62 | size_t size;
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
| 65 | SL_ENTER(_("sh_ignore_add"));
|
---|
| 66 |
|
---|
| 67 | if (addpath == NULL)
|
---|
| 68 | {
|
---|
| 69 | SL_RETURN(list, _("sh_ignore_add"));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | new = SH_ALLOC(sizeof(struct sh_ignore_list));
|
---|
| 73 |
|
---|
| 74 | #ifdef HAVE_REGEX_H
|
---|
| 75 | status = regcomp(&(new->preg), addpath, REG_NOSUB|REG_EXTENDED);
|
---|
| 76 | if (status != 0)
|
---|
| 77 | {
|
---|
| 78 | errbuf = SH_ALLOC(BUFSIZ+2);
|
---|
| 79 | (void) regerror(status, &(new->preg), errbuf, BUFSIZ);
|
---|
| 80 | errbuf[BUFSIZ] = '\0';
|
---|
| 81 | sh_error_handle ((-1), FIL__, __LINE__, status, MSG_E_REGEX,
|
---|
| 82 | errbuf, addpath);
|
---|
| 83 | SH_FREE(errbuf);
|
---|
| 84 | SH_FREE(new);
|
---|
| 85 | SL_RETURN(list, _("sh_ignore_add"));
|
---|
| 86 | }
|
---|
| 87 | #else
|
---|
| 88 | size = sl_strlen(addpath);
|
---|
| 89 | new->path = SH_ALLOC(size + 1);
|
---|
| 90 | sl_strlcpy(new->path, addpath, size+1);
|
---|
| 91 | #endif
|
---|
| 92 |
|
---|
| 93 | new->next = list;
|
---|
| 94 |
|
---|
| 95 | SL_RETURN(new, _("sh_ignore_add"));
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[22] | 98 | int sh_ignore_add_del (const char * addpath)
|
---|
[1] | 99 | {
|
---|
| 100 | if ((addpath == NULL) || (addpath[0] != '/'))
|
---|
| 101 | {
|
---|
| 102 | return -1;
|
---|
| 103 | }
|
---|
| 104 | sh_del_ign = sh_ignore_add_int (sh_del_ign, addpath);
|
---|
| 105 | return 0;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[22] | 108 | int sh_ignore_add_new (const char * addpath)
|
---|
[1] | 109 | {
|
---|
| 110 | if ((addpath == NULL) || (addpath[0] != '/'))
|
---|
| 111 | {
|
---|
| 112 | return -1;
|
---|
| 113 | }
|
---|
| 114 | sh_new_ign = sh_ignore_add_int (sh_new_ign, addpath);
|
---|
| 115 | return 0;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | static int sh_ignore_chk_int (struct sh_ignore_list * list,
|
---|
| 119 | const char * chkpath)
|
---|
| 120 | {
|
---|
| 121 | struct sh_ignore_list * new = list;
|
---|
| 122 |
|
---|
| 123 | SL_ENTER(_("sh_ignore_chk"));
|
---|
| 124 |
|
---|
| 125 | if (chkpath == NULL)
|
---|
| 126 | {
|
---|
| 127 | SL_RETURN(S_FALSE, _("sh_ignore_add"));
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | while (new)
|
---|
| 131 | {
|
---|
| 132 | #ifdef HAVE_REGEX_H
|
---|
| 133 | if (0 == regexec(&(new->preg), chkpath, 0, NULL, 0))
|
---|
| 134 | {
|
---|
| 135 | SL_RETURN(S_TRUE, _("sh_ignore_add"));
|
---|
| 136 | }
|
---|
| 137 | #else
|
---|
| 138 | if (0 == sl_strcmp(new->path, chkpath))
|
---|
| 139 | {
|
---|
| 140 | SL_RETURN(S_TRUE, _("sh_ignore_add"));
|
---|
| 141 | }
|
---|
| 142 | #endif
|
---|
| 143 | new = new->next;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | SL_RETURN(S_FALSE, _("sh_ignore_add"));
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | int sh_ignore_chk_new (const char * chkpath)
|
---|
| 150 | {
|
---|
| 151 | return (sh_ignore_chk_int(sh_new_ign, chkpath));
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | int sh_ignore_chk_del (const char * chkpath)
|
---|
| 155 | {
|
---|
| 156 | return (sh_ignore_chk_int(sh_del_ign, chkpath));
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[170] | 159 | int sh_ignore_clean (void)
|
---|
[1] | 160 | {
|
---|
| 161 | struct sh_ignore_list * new;
|
---|
| 162 |
|
---|
| 163 | new = sh_new_ign;
|
---|
| 164 |
|
---|
| 165 | while (new)
|
---|
| 166 | {
|
---|
| 167 | sh_new_ign = new->next;
|
---|
| 168 | #ifdef HAVE_REGEX_H
|
---|
| 169 | regfree (&(new->preg));
|
---|
| 170 | #else
|
---|
| 171 | SH_FREE(new->path);
|
---|
| 172 | #endif
|
---|
| 173 | SH_FREE(new);
|
---|
| 174 | new = sh_new_ign;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | new = sh_del_ign;
|
---|
| 178 |
|
---|
| 179 | while (new)
|
---|
| 180 | {
|
---|
| 181 | sh_del_ign = new->next;
|
---|
| 182 | #ifdef HAVE_REGEX_H
|
---|
| 183 | regfree (&(new->preg));
|
---|
| 184 | #else
|
---|
| 185 | SH_FREE(new->path);
|
---|
| 186 | #endif
|
---|
| 187 | SH_FREE(new);
|
---|
| 188 | new = sh_del_ign;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | return 0;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 |
|
---|