[1] | 1 | /* SAMHAIN file system integrity testing */
|
---|
| 2 | /* Copyright (C) 1999, 2000, 2001, 2002 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 <stdlib.h>
|
---|
| 23 | #include <string.h>
|
---|
| 24 | #include <stdio.h>
|
---|
| 25 | #include <sys/types.h>
|
---|
| 26 | #include <sys/stat.h>
|
---|
| 27 | #include <unistd.h>
|
---|
[444] | 28 | #include <ctype.h>
|
---|
[1] | 29 |
|
---|
| 30 | #ifdef MAJOR_IN_MKDEV
|
---|
| 31 | #include <sys/mkdev.h>
|
---|
| 32 | #else
|
---|
| 33 | #ifdef MAJOR_IN_SYSMACROS
|
---|
| 34 | #include <sys/sysmacros.h>
|
---|
| 35 | #endif
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 | #ifdef HAVE_MEMORY_H
|
---|
| 39 | #include <memory.h>
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
[481] | 42 |
|
---|
[1] | 43 | #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
|
---|
| 44 |
|
---|
[481] | 45 | #include "samhain.h"
|
---|
| 46 | #include "sh_utils.h"
|
---|
| 47 | #include "sh_unix.h"
|
---|
| 48 | #include "sh_dbIO_int.h"
|
---|
| 49 | #include "sh_dbIO.h"
|
---|
[1] | 50 | #include "sh_hash.h"
|
---|
| 51 | #include "sh_error.h"
|
---|
| 52 | #include "sh_tiger.h"
|
---|
| 53 | #include "sh_gpg.h"
|
---|
| 54 | #include "sh_unix.h"
|
---|
| 55 | #include "sh_files.h"
|
---|
| 56 | #include "sh_ignore.h"
|
---|
[149] | 57 | #include "sh_pthread.h"
|
---|
[1] | 58 |
|
---|
| 59 | #if defined(SH_WITH_CLIENT)
|
---|
[481] | 60 | #include "sh_xfer.h"
|
---|
[1] | 61 | #endif
|
---|
| 62 |
|
---|
[105] | 63 |
|
---|
| 64 | #define SH_KEY_NULL _("000000000000000000000000000000000000000000000000")
|
---|
| 65 |
|
---|
| 66 |
|
---|
[1] | 67 | #undef FIL__
|
---|
| 68 | #define FIL__ _("sh_hash.c")
|
---|
| 69 |
|
---|
[481] | 70 | SH_MUTEX_INIT(mutex_hash,PTHREAD_MUTEX_INITIALIZER);
|
---|
[149] | 71 |
|
---|
[1] | 72 | static char * all_items (file_type * theFile, char * fileHash, int is_new);
|
---|
| 73 |
|
---|
[481] | 74 | static const char *policy[] = {
|
---|
| 75 | N_("[]"),
|
---|
| 76 | N_("[ReadOnly]"),
|
---|
| 77 | N_("[LogFiles]"),
|
---|
| 78 | N_("[GrowingLogs]"),
|
---|
| 79 | N_("[IgnoreNone]"),
|
---|
| 80 | N_("[IgnoreAll]"),
|
---|
| 81 | N_("[Attributes]"),
|
---|
| 82 | N_("[User0]"),
|
---|
| 83 | N_("[User1]"),
|
---|
| 84 | N_("[User2]"),
|
---|
| 85 | N_("[User3]"),
|
---|
| 86 | N_("[User4]"),
|
---|
| 87 | N_("[Prelink]"),
|
---|
| 88 | NULL
|
---|
| 89 | };
|
---|
[1] | 90 |
|
---|
[481] | 91 | static int report_checkflags = S_FALSE;
|
---|
| 92 | int set_report_checkflags(const char * c)
|
---|
[1] | 93 | {
|
---|
[481] | 94 | return sh_util_flagval(c, &report_checkflags);
|
---|
[1] | 95 | }
|
---|
[481] | 96 | int get_report_checkflags()
|
---|
[1] | 97 | {
|
---|
[481] | 98 | return report_checkflags;
|
---|
[1] | 99 | }
|
---|
| 100 |
|
---|
[34] | 101 |
|
---|
[1] | 102 |
|
---|
[356] | 103 | const char * sh_hash_getpolicy(int class)
|
---|
| 104 | {
|
---|
| 105 | if (class > 0 && class < SH_ERR_T_DIR)
|
---|
| 106 | return _(policy[class]);
|
---|
| 107 | return _("[indef]");
|
---|
| 108 | }
|
---|
[1] | 109 |
|
---|
| 110 | /**********************************
|
---|
| 111 | *
|
---|
| 112 | * hash table functions
|
---|
| 113 | *
|
---|
| 114 | **********************************
|
---|
| 115 | */
|
---|
| 116 |
|
---|
| 117 | #include "sh_hash.h"
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | /**************************************************************
|
---|
| 121 | *
|
---|
| 122 | * create a file_type from a sh_file_t
|
---|
| 123 | *
|
---|
| 124 | **************************************************************/
|
---|
[481] | 125 | file_type * sh_hash_create_ft (const sh_file_t * p, char * fileHash)
|
---|
[1] | 126 | {
|
---|
| 127 | file_type * theFile;
|
---|
| 128 |
|
---|
| 129 | SL_ENTER(_("sh_hash_create_ft"));
|
---|
| 130 |
|
---|
| 131 | theFile = SH_ALLOC(sizeof(file_type));
|
---|
| 132 |
|
---|
| 133 | sl_strlcpy(theFile->c_mode, p->theFile.c_mode, 11);
|
---|
| 134 | theFile->mode = p->theFile.mode;
|
---|
[10] | 135 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[149] | 136 | sl_strlcpy(theFile->c_attributes, p->theFile.c_attributes, ATTRBUF_SIZE);
|
---|
[1] | 137 | theFile->attributes = p->theFile.attributes;
|
---|
| 138 | #endif
|
---|
| 139 |
|
---|
| 140 | sl_strlcpy(theFile->fullpath, p->fullpath, PATH_MAX);
|
---|
[167] | 141 | if (p->linkpath != NULL /* && theFile->c_mode[0] == 'l' */)
|
---|
[1] | 142 | {
|
---|
[167] | 143 | theFile->link_path = sh_util_strdup(p->linkpath);
|
---|
[1] | 144 | }
|
---|
| 145 | else
|
---|
| 146 | {
|
---|
[167] | 147 | theFile->link_path = NULL;
|
---|
[1] | 148 | }
|
---|
| 149 | sl_strlcpy(fileHash, p->theFile.checksum, KEY_LEN+1);
|
---|
| 150 |
|
---|
| 151 | theFile->mtime = p->theFile.mtime;
|
---|
| 152 | theFile->ctime = p->theFile.ctime;
|
---|
| 153 | theFile->atime = p->theFile.atime;
|
---|
| 154 |
|
---|
| 155 | theFile->size = p->theFile.size;
|
---|
| 156 |
|
---|
| 157 | sl_strlcpy(theFile->c_group, p->theFile.c_group, GROUP_MAX+2);
|
---|
| 158 | theFile->group = p->theFile.group;
|
---|
| 159 | sl_strlcpy(theFile->c_owner, p->theFile.c_owner, USER_MAX+2);
|
---|
| 160 | theFile->owner = p->theFile.owner;
|
---|
| 161 |
|
---|
| 162 | theFile->ino = p->theFile.ino;
|
---|
| 163 | theFile->rdev = p->theFile.rdev;
|
---|
| 164 | theFile->dev = p->theFile.dev;
|
---|
| 165 | theFile->hardlinks = p->theFile.hardlinks;
|
---|
[481] | 166 | theFile->check_flags = p->theFile.checkflags;
|
---|
[1] | 167 |
|
---|
[68] | 168 | if (p->attr_string)
|
---|
| 169 | theFile->attr_string = sh_util_strdup(p->attr_string);
|
---|
| 170 | else
|
---|
| 171 | theFile->attr_string = NULL;
|
---|
| 172 |
|
---|
[1] | 173 | SL_RETURN((theFile), _("sh_hash_create_ft"));
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[305] | 176 | struct two_sh_file_t {
|
---|
| 177 | sh_file_t * prev;
|
---|
| 178 | sh_file_t * this;
|
---|
| 179 | };
|
---|
| 180 |
|
---|
[294] | 181 | static sh_file_t * hashsearch (const char * s);
|
---|
[305] | 182 | static int hashsearch_prev (const char * s, struct two_sh_file_t * a, int * index);
|
---|
[1] | 183 |
|
---|
[481] | 184 |
|
---|
| 185 | /**************************************************************
|
---|
| 186 | *
|
---|
| 187 | * >>>> The internal database <<<
|
---|
| 188 | *
|
---|
| 189 | **************************************************************/
|
---|
| 190 |
|
---|
[1] | 191 | static sh_file_t * tab[TABSIZE];
|
---|
| 192 |
|
---|
[481] | 193 | sh_file_t ** get_default_data_table()
|
---|
| 194 | {
|
---|
| 195 | return tab;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[1] | 198 | /**************************************************************
|
---|
| 199 | *
|
---|
| 200 | * compute hash function
|
---|
| 201 | *
|
---|
| 202 | **************************************************************/
|
---|
[8] | 203 |
|
---|
[294] | 204 | static int hashfunc(const char *s)
|
---|
[1] | 205 | {
|
---|
[18] | 206 | unsigned int n = 0;
|
---|
[1] | 207 |
|
---|
| 208 | for ( ; *s; s++)
|
---|
| 209 | n = 31 * n + *s;
|
---|
[18] | 210 |
|
---|
| 211 | return n & (TABSIZE - 1); /* % TABSIZE */;
|
---|
[1] | 212 | }
|
---|
| 213 |
|
---|
[8] | 214 |
|
---|
[1] | 215 | int hashreport_missing( char *fullpath, int level)
|
---|
| 216 | {
|
---|
| 217 | sh_file_t * p;
|
---|
| 218 | char * tmp;
|
---|
| 219 | char fileHash[KEY_LEN + 1];
|
---|
| 220 | file_type * theFile;
|
---|
| 221 | char * str;
|
---|
[133] | 222 | char hashbuf[KEYBUF_SIZE];
|
---|
[367] | 223 | volatile int retval;
|
---|
[1] | 224 |
|
---|
| 225 | /* -------- find the entry for the file ---------------- */
|
---|
| 226 |
|
---|
[149] | 227 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 228 |
|
---|
[170] | 229 | retval = 0;
|
---|
| 230 |
|
---|
[1] | 231 | if (sl_strlen(fullpath) <= MAX_PATH_STORE)
|
---|
| 232 | p = hashsearch(fullpath);
|
---|
| 233 | else
|
---|
| 234 | p = hashsearch( sh_tiger_hash(fullpath,
|
---|
| 235 | TIGER_DATA,
|
---|
[133] | 236 | sl_strlen(fullpath),
|
---|
| 237 | hashbuf, sizeof(hashbuf))
|
---|
[1] | 238 | );
|
---|
| 239 | if (p == NULL)
|
---|
[149] | 240 | {
|
---|
| 241 | retval = -1;
|
---|
| 242 | goto unlock_and_return;
|
---|
| 243 | }
|
---|
[1] | 244 |
|
---|
| 245 | theFile = sh_hash_create_ft (p, fileHash);
|
---|
| 246 | str = all_items(theFile, fileHash, 0);
|
---|
| 247 | tmp = sh_util_safe_name(fullpath);
|
---|
[367] | 248 |
|
---|
| 249 | SH_MUTEX_LOCK(mutex_thread_nolog);
|
---|
[488] | 250 | if (!sh_global_check_silent)
|
---|
| 251 | sh_error_handle (level, FIL__, __LINE__, 0,
|
---|
| 252 | MSG_FI_MISS2, tmp, str);
|
---|
[367] | 253 | SH_MUTEX_UNLOCK(mutex_thread_nolog);
|
---|
[405] | 254 | ++sh.statistics.files_report;
|
---|
[362] | 255 |
|
---|
[1] | 256 | SH_FREE(tmp);
|
---|
| 257 | SH_FREE(str);
|
---|
[167] | 258 | if (theFile->attr_string) SH_FREE(theFile->attr_string);
|
---|
| 259 | if (theFile->link_path) SH_FREE(theFile->link_path);
|
---|
[1] | 260 | SH_FREE(theFile);
|
---|
[149] | 261 |
|
---|
| 262 | unlock_and_return:
|
---|
[153] | 263 | ; /* 'label at end of compound statement */
|
---|
[149] | 264 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[305] | 265 |
|
---|
[458] | 266 | /* remove here to avoid second message from hash_unvisited */
|
---|
| 267 | if (retval == 0)
|
---|
| 268 | sh_hash_remove (fullpath);
|
---|
| 269 |
|
---|
[149] | 270 | return retval;
|
---|
[1] | 271 | }
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | /**************************************************************
|
---|
| 275 | *
|
---|
| 276 | * search for files not visited, and check whether they exist
|
---|
| 277 | *
|
---|
| 278 | **************************************************************/
|
---|
[294] | 279 | static sh_file_t * delete_db_entry(sh_file_t *p)
|
---|
| 280 | {
|
---|
| 281 | if (p->fullpath)
|
---|
| 282 | {
|
---|
| 283 | SH_FREE(p->fullpath);
|
---|
| 284 | p->fullpath = NULL;
|
---|
| 285 | }
|
---|
| 286 | if (p->linkpath)
|
---|
| 287 | {
|
---|
[481] | 288 | SH_FREE(p->linkpath);
|
---|
[294] | 289 | p->linkpath = NULL;
|
---|
| 290 | }
|
---|
| 291 | if (p->attr_string)
|
---|
| 292 | {
|
---|
| 293 | SH_FREE(p->attr_string);
|
---|
| 294 | p->attr_string = NULL;
|
---|
| 295 | }
|
---|
| 296 | SH_FREE(p);
|
---|
| 297 | return NULL;
|
---|
| 298 | }
|
---|
| 299 |
|
---|
[1] | 300 | static void hash_unvisited (int j,
|
---|
| 301 | sh_file_t *prev, sh_file_t *p, ShErrLevel level)
|
---|
| 302 | {
|
---|
| 303 | struct stat buf;
|
---|
| 304 | int i;
|
---|
| 305 | char * tmp;
|
---|
| 306 | char * ptr;
|
---|
| 307 | char fileHash[KEY_LEN + 1];
|
---|
| 308 | file_type * theFile;
|
---|
| 309 | char * str;
|
---|
| 310 |
|
---|
| 311 | SL_ENTER(_("hash_unvisited"));
|
---|
| 312 |
|
---|
| 313 | if (p->next != NULL)
|
---|
| 314 | hash_unvisited (j, p, p->next, level);
|
---|
| 315 |
|
---|
| 316 | if (p->fullpath == NULL)
|
---|
| 317 | {
|
---|
| 318 | SL_RET0(_("hash_unvisited"));
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[114] | 321 | /* Not a fully qualified path, i.e. some info stored by some module
|
---|
[1] | 322 | */
|
---|
[114] | 323 | if (p->fullpath[0] != '/')
|
---|
[1] | 324 | {
|
---|
| 325 | SL_RET0(_("hash_unvisited"));
|
---|
| 326 | }
|
---|
[458] | 327 |
|
---|
[114] | 328 | /* visited flag not set: not seen;
|
---|
| 329 | * checked flag set: not seen (i.e. missing), and already checked
|
---|
| 330 | * reported flag not set: not reported yet
|
---|
| 331 | * allignore flag not set: not under IgnoreAll
|
---|
[1] | 332 | *
|
---|
| 333 | * Files/directories under IgnoreAll are noticed as missing already
|
---|
| 334 | * during the file check.
|
---|
| 335 | */
|
---|
[114] | 336 | if (((!SH_FFLAG_VISITED_SET(p->fflags)) || SH_FFLAG_CHECKED_SET(p->fflags))
|
---|
| 337 | && (!SH_FFLAG_REPORTED_SET(p->fflags))
|
---|
[481] | 338 | /* && (!SH_FFLAG_ALLIGNORE_SET(p->fflags)) */)
|
---|
[1] | 339 | {
|
---|
| 340 | i = retry_lstat(FIL__, __LINE__, p->fullpath, &buf);
|
---|
[458] | 341 |
|
---|
[457] | 342 | /* if file does not exist
|
---|
[1] | 343 | */
|
---|
| 344 | if (0 != i)
|
---|
| 345 | {
|
---|
[34] | 346 | ptr = sh_util_dirname (p->fullpath);
|
---|
[1] | 347 | if (ptr)
|
---|
| 348 | {
|
---|
| 349 | /* If any of the parent directories is under IgnoreAll
|
---|
| 350 | */
|
---|
[481] | 351 | if ((0 != sh_files_is_allignore(ptr)) || SH_FFLAG_ALLIGNORE_SET(p->fflags))
|
---|
[1] | 352 | level = ShDFLevel[SH_LEVEL_ALLIGNORE];
|
---|
| 353 | SH_FREE(ptr);
|
---|
| 354 | }
|
---|
[114] | 355 |
|
---|
| 356 | /* Only report if !SH_FFLAG_CHECKED_SET
|
---|
| 357 | */
|
---|
| 358 | if (!SH_FFLAG_CHECKED_SET(p->fflags))
|
---|
[1] | 359 | {
|
---|
| 360 | if (S_FALSE == sh_ignore_chk_del(p->fullpath))
|
---|
| 361 | {
|
---|
| 362 | tmp = sh_util_safe_name(p->fullpath);
|
---|
| 363 |
|
---|
| 364 | theFile = sh_hash_create_ft (p, fileHash);
|
---|
| 365 | str = all_items(theFile, fileHash, 0);
|
---|
[488] | 366 | if (!sh_global_check_silent)
|
---|
| 367 | sh_error_handle (level, FIL__, __LINE__, 0,
|
---|
| 368 | MSG_FI_MISS2, tmp, str);
|
---|
[405] | 369 | ++sh.statistics.files_report;
|
---|
[1] | 370 | SH_FREE(str);
|
---|
[167] | 371 | if (theFile->attr_string) SH_FREE(theFile->attr_string);
|
---|
| 372 | if (theFile->link_path) SH_FREE(theFile->link_path);
|
---|
[1] | 373 | SH_FREE(theFile);
|
---|
| 374 |
|
---|
| 375 | SH_FREE(tmp);
|
---|
| 376 | }
|
---|
| 377 | }
|
---|
| 378 |
|
---|
[77] | 379 | /* We rewrite the db on update, thus we need to keep this
|
---|
[1] | 380 | * if the user does not want to purge it from the db.
|
---|
| 381 | */
|
---|
| 382 |
|
---|
[77] | 383 | if ((sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE) ||
|
---|
| 384 | (S_TRUE == sh.flag.update && S_TRUE == sh_util_ask_update(p->fullpath)))
|
---|
[1] | 385 | {
|
---|
| 386 | /* Remove the old entry
|
---|
| 387 | */
|
---|
| 388 | if (prev == p)
|
---|
| 389 | tab[j] = p->next;
|
---|
| 390 | else
|
---|
| 391 | prev->next = p->next;
|
---|
[294] | 392 |
|
---|
[383] | 393 | delete_db_entry(p);
|
---|
[294] | 394 |
|
---|
[1] | 395 | SL_RET0(_("hash_unvisited"));
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
| 399 |
|
---|
[114] | 400 | else if (SH_FFLAG_VISITED_SET(p->fflags) && SH_FFLAG_REPORTED_SET(p->fflags)
|
---|
| 401 | && (!SH_FFLAG_ALLIGNORE_SET(p->fflags)))
|
---|
[1] | 402 | {
|
---|
| 403 | if (S_FALSE == sh_ignore_chk_new(p->fullpath))
|
---|
| 404 | {
|
---|
| 405 | tmp = sh_util_safe_name(p->fullpath);
|
---|
| 406 |
|
---|
| 407 | theFile = sh_hash_create_ft (p, fileHash);
|
---|
| 408 | str = all_items(theFile, fileHash, 0);
|
---|
[488] | 409 | if (!sh_global_check_silent)
|
---|
| 410 | sh_error_handle (level, FIL__, __LINE__, 0,
|
---|
| 411 | MSG_FI_MISS2, tmp, str);
|
---|
[405] | 412 | ++sh.statistics.files_report;
|
---|
[1] | 413 | SH_FREE(str);
|
---|
[68] | 414 | if (theFile->attr_string)
|
---|
| 415 | SH_FREE(theFile->attr_string);
|
---|
[1] | 416 | SH_FREE(theFile);
|
---|
| 417 |
|
---|
| 418 | SH_FREE(tmp);
|
---|
| 419 | }
|
---|
| 420 |
|
---|
[114] | 421 | CLEAR_SH_FFLAG_REPORTED(p->fflags);
|
---|
[1] | 422 | }
|
---|
| 423 |
|
---|
| 424 | if (sh.flag.reportonce == S_FALSE)
|
---|
[114] | 425 | CLEAR_SH_FFLAG_REPORTED(p->fflags);
|
---|
[1] | 426 |
|
---|
[114] | 427 | CLEAR_SH_FFLAG_VISITED(p->fflags);
|
---|
| 428 | CLEAR_SH_FFLAG_CHECKED(p->fflags);
|
---|
[458] | 429 | SET_SH_FFLAG_ENOENT(p->fflags);
|
---|
[114] | 430 |
|
---|
[1] | 431 | SL_RET0(_("hash_unvisited"));
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 |
|
---|
[305] | 435 |
|
---|
[1] | 436 | /*********************************************************************
|
---|
| 437 | *
|
---|
| 438 | * Search for files in the database that have been deleted from disk.
|
---|
| 439 | *
|
---|
| 440 | *********************************************************************/
|
---|
| 441 | void sh_hash_unvisited (ShErrLevel level)
|
---|
| 442 | {
|
---|
| 443 | int i;
|
---|
| 444 |
|
---|
| 445 | SL_ENTER(_("sh_hash_unvisited"));
|
---|
[149] | 446 |
|
---|
| 447 | SH_MUTEX_LOCK(mutex_hash);
|
---|
[1] | 448 | for (i = 0; i < TABSIZE; ++i)
|
---|
| 449 | {
|
---|
| 450 | if (tab[i] != NULL)
|
---|
| 451 | hash_unvisited (i, tab[i], tab[i], level);
|
---|
| 452 | }
|
---|
[149] | 453 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 454 |
|
---|
[1] | 455 | SL_RET0(_("hash_unvisited"));
|
---|
| 456 | }
|
---|
| 457 |
|
---|
[294] | 458 | /*********************************************************************
|
---|
| 459 | *
|
---|
[305] | 460 | * Remove a single file from the database.
|
---|
| 461 | *
|
---|
| 462 | *********************************************************************/
|
---|
[481] | 463 | void sh_hash_remove_unconditional (const char * path)
|
---|
[305] | 464 | {
|
---|
| 465 | struct two_sh_file_t entries;
|
---|
| 466 | int index;
|
---|
| 467 |
|
---|
[481] | 468 | SL_ENTER(_("sh_hash_remove_unconditional"));
|
---|
[305] | 469 |
|
---|
| 470 | SH_MUTEX_LOCK(mutex_hash);
|
---|
[481] | 471 | if (0 == hashsearch_prev (path, &entries, &index))
|
---|
| 472 | {
|
---|
| 473 | sh_file_t * p = entries.this;
|
---|
| 474 |
|
---|
| 475 | /* Remove the old entry
|
---|
| 476 | */
|
---|
| 477 | if (entries.prev == p)
|
---|
| 478 | tab[index] = p->next;
|
---|
| 479 | else
|
---|
| 480 | entries.prev->next = p->next;
|
---|
| 481 |
|
---|
| 482 | delete_db_entry(p);
|
---|
| 483 | }
|
---|
| 484 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[305] | 485 |
|
---|
[481] | 486 | SL_RET0(_("sh_hash_remove_unconditional"));
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | void sh_hash_remove (const char * path)
|
---|
| 490 | {
|
---|
| 491 | SL_ENTER(_("sh_hash_remove"));
|
---|
| 492 |
|
---|
[305] | 493 | if ((sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE) ||
|
---|
| 494 | (S_TRUE == sh.flag.update && S_TRUE == sh_util_ask_update(path)))
|
---|
| 495 | {
|
---|
[481] | 496 | sh_hash_remove_unconditional (path);
|
---|
[305] | 497 | }
|
---|
| 498 | SL_RET0(_("sh_hash_remove"));
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 |
|
---|
| 502 | /*********************************************************************
|
---|
| 503 | *
|
---|
[294] | 504 | * Search for unvisited entries in the database, custom error handler.
|
---|
| 505 | *
|
---|
| 506 | *********************************************************************/
|
---|
| 507 | void sh_hash_unvisited_custom (char prefix, void(*handler)(const char * key))
|
---|
| 508 | {
|
---|
| 509 | int i;
|
---|
| 510 | sh_file_t *p = NULL;
|
---|
| 511 | sh_file_t *prev = NULL;
|
---|
| 512 | sh_file_t *next = NULL;
|
---|
[1] | 513 |
|
---|
[294] | 514 | SL_ENTER(_("sh_hash_unvisited_custom"));
|
---|
| 515 |
|
---|
| 516 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 517 | for (i = 0; i < TABSIZE; ++i)
|
---|
| 518 | {
|
---|
| 519 | if (tab[i] != NULL)
|
---|
| 520 | {
|
---|
| 521 | p = tab[i]; prev = p;
|
---|
| 522 |
|
---|
| 523 | do
|
---|
| 524 | {
|
---|
| 525 | next = p->next;
|
---|
| 526 |
|
---|
| 527 | if (p->fullpath &&
|
---|
| 528 | prefix == p->fullpath[0])
|
---|
| 529 | {
|
---|
| 530 | if ((!SH_FFLAG_VISITED_SET(p->fflags))
|
---|
| 531 | && (!SH_FFLAG_REPORTED_SET(p->fflags)))
|
---|
| 532 | {
|
---|
| 533 | handler(p->fullpath);
|
---|
| 534 |
|
---|
| 535 | if (!SH_FFLAG_CHECKED_SET(p->fflags))
|
---|
| 536 | {
|
---|
| 537 | /* delete */
|
---|
| 538 | if (tab[i] == p)
|
---|
| 539 | {
|
---|
| 540 | tab[i] = p->next;
|
---|
| 541 | prev = tab[i];
|
---|
| 542 | next = prev;
|
---|
| 543 | }
|
---|
| 544 | else
|
---|
| 545 | {
|
---|
| 546 | prev->next = p->next;
|
---|
| 547 | next = prev->next;
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | p = delete_db_entry(p);
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
| 553 | if (p)
|
---|
| 554 | {
|
---|
| 555 | CLEAR_SH_FFLAG_VISITED(p->fflags);
|
---|
| 556 | CLEAR_SH_FFLAG_CHECKED(p->fflags);
|
---|
| 557 | }
|
---|
| 558 | }
|
---|
| 559 | if (p)
|
---|
| 560 | prev = p;
|
---|
| 561 | p = next;
|
---|
| 562 | }
|
---|
| 563 | while (p);
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 567 |
|
---|
| 568 | SL_RET0(_("hash_unvisited_custom"));
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 |
|
---|
[1] | 572 | /**********************************************************************
|
---|
| 573 | *
|
---|
| 574 | * delete hash array
|
---|
| 575 | *
|
---|
| 576 | **********************************************************************/
|
---|
| 577 | static void hash_kill (sh_file_t *p)
|
---|
| 578 | {
|
---|
| 579 | SL_ENTER(_("hash_kill"));
|
---|
| 580 |
|
---|
| 581 | if (p == NULL)
|
---|
| 582 | SL_RET0(_("hash_kill"));
|
---|
| 583 |
|
---|
| 584 | if (p->next != NULL)
|
---|
| 585 | hash_kill (p->next);
|
---|
| 586 |
|
---|
| 587 | if (p->fullpath)
|
---|
| 588 | {
|
---|
| 589 | SH_FREE(p->fullpath);
|
---|
| 590 | p->fullpath = NULL;
|
---|
| 591 | }
|
---|
| 592 | if (p->linkpath)
|
---|
| 593 | {
|
---|
[481] | 594 | SH_FREE(p->linkpath);
|
---|
[1] | 595 | p->linkpath = NULL;
|
---|
| 596 | }
|
---|
[68] | 597 | if (p->attr_string)
|
---|
| 598 | {
|
---|
| 599 | SH_FREE(p->attr_string);
|
---|
| 600 | p->attr_string = NULL;
|
---|
| 601 | }
|
---|
[1] | 602 | SH_FREE(p);
|
---|
| 603 | p = NULL;
|
---|
| 604 | SL_RET0(_("hash_kill"));
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 |
|
---|
| 608 | /***********************************************************************
|
---|
| 609 | *
|
---|
| 610 | * get info out of hash array
|
---|
| 611 | *
|
---|
| 612 | ***********************************************************************/
|
---|
[294] | 613 | static sh_file_t * hashsearch (const char * s)
|
---|
[1] | 614 | {
|
---|
| 615 | sh_file_t * p;
|
---|
| 616 |
|
---|
| 617 | SL_ENTER(_("hashsearch"));
|
---|
| 618 |
|
---|
[8] | 619 | if (s)
|
---|
| 620 | {
|
---|
| 621 | for (p = tab[hashfunc(s)]; p; p = p->next)
|
---|
| 622 | if ((p->fullpath != NULL) && (0 == strcmp(s, p->fullpath)))
|
---|
| 623 | SL_RETURN( p, _("hashsearch"));
|
---|
| 624 | }
|
---|
[1] | 625 | SL_RETURN( NULL, _("hashsearch"));
|
---|
| 626 | }
|
---|
| 627 |
|
---|
[305] | 628 | static int hashsearch_prev (const char * s, struct two_sh_file_t * a, int * index)
|
---|
| 629 | {
|
---|
| 630 | sh_file_t * this;
|
---|
| 631 | sh_file_t * prev = NULL;
|
---|
[1] | 632 |
|
---|
[305] | 633 | SL_ENTER(_("hashsearch_prev"));
|
---|
| 634 |
|
---|
| 635 | if (s)
|
---|
| 636 | {
|
---|
| 637 | *index = hashfunc(s);
|
---|
[481] | 638 | this = tab[*index];
|
---|
| 639 | prev = this;
|
---|
[305] | 640 |
|
---|
| 641 | if (this)
|
---|
| 642 | {
|
---|
| 643 | do {
|
---|
| 644 | if ((this->fullpath != NULL) && (0 == strcmp(s, this->fullpath)))
|
---|
| 645 | {
|
---|
| 646 | a->prev = prev;
|
---|
[481] | 647 | a->this = this;
|
---|
[305] | 648 | SL_RETURN( 0, _("hashsearch_prev"));
|
---|
| 649 | }
|
---|
| 650 | prev = this;
|
---|
| 651 | this = this->next;
|
---|
| 652 | } while(this);
|
---|
| 653 | }
|
---|
| 654 | }
|
---|
| 655 | SL_RETURN( -1, _("hashsearch"));
|
---|
| 656 | }
|
---|
| 657 |
|
---|
| 658 |
|
---|
[1] | 659 | /***********************************************************************
|
---|
| 660 | *
|
---|
| 661 | * insert into hash array
|
---|
| 662 | *
|
---|
| 663 | ***********************************************************************/
|
---|
[481] | 664 | void hashinsert (sh_file_t * mtab[TABSIZE], sh_file_t * s)
|
---|
[1] | 665 | {
|
---|
| 666 | sh_file_t * p;
|
---|
[3] | 667 | sh_file_t * q;
|
---|
[1] | 668 | int key;
|
---|
| 669 |
|
---|
| 670 | SL_ENTER(_("hashinsert"));
|
---|
| 671 |
|
---|
| 672 | key = hashfunc(s->fullpath);
|
---|
| 673 |
|
---|
[481] | 674 | if (mtab[key] == NULL)
|
---|
[1] | 675 | {
|
---|
[481] | 676 | mtab[key] = s;
|
---|
| 677 | mtab[key]->next = NULL;
|
---|
[1] | 678 | SL_RET0(_("hashinsert"));
|
---|
| 679 | }
|
---|
| 680 | else
|
---|
| 681 | {
|
---|
[481] | 682 | p = mtab[key];
|
---|
[1] | 683 | while (1)
|
---|
| 684 | {
|
---|
[481] | 685 | if (p && p->fullpath && 0 == strcmp(s->fullpath, p->fullpath))
|
---|
[1] | 686 | {
|
---|
[3] | 687 | q = p->next;
|
---|
| 688 | SH_FREE(p->fullpath);
|
---|
[481] | 689 | if(p->linkpath) SH_FREE(p->linkpath);
|
---|
| 690 | if(p->attr_string) SH_FREE(p->attr_string);
|
---|
[3] | 691 | memcpy(p, s, sizeof(sh_file_t));
|
---|
| 692 | p->next = q;
|
---|
[481] | 693 | SH_FREE(s); s = NULL;
|
---|
[1] | 694 | SL_RET0(_("hashinsert"));
|
---|
| 695 | }
|
---|
[383] | 696 | else if (p && p->next == NULL)
|
---|
| 697 | {
|
---|
| 698 | p->next = s;
|
---|
| 699 | p->next->next = NULL;
|
---|
| 700 | SL_RET0(_("hashinsert"));
|
---|
| 701 | }
|
---|
| 702 | if (p)
|
---|
| 703 | p = p->next;
|
---|
| 704 | else /* cannot really happen, but llvm/clang does not know */
|
---|
| 705 | break;
|
---|
[1] | 706 | }
|
---|
| 707 | }
|
---|
| 708 | /* notreached */
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 |
|
---|
| 712 |
|
---|
| 713 | /******************************************************************
|
---|
| 714 | *
|
---|
| 715 | * ------- Check functions -------
|
---|
| 716 | *
|
---|
| 717 | ******************************************************************/
|
---|
| 718 |
|
---|
| 719 | static int IsInit = 0;
|
---|
| 720 |
|
---|
[481] | 721 | void sh_hash_set_initialized()
|
---|
[1] | 722 | {
|
---|
[481] | 723 | IsInit = 1;
|
---|
| 724 | return;
|
---|
[1] | 725 | }
|
---|
| 726 |
|
---|
[481] | 727 | int sh_hash_get_initialized()
|
---|
[1] | 728 | {
|
---|
[481] | 729 | return IsInit;
|
---|
[1] | 730 | }
|
---|
| 731 |
|
---|
| 732 |
|
---|
| 733 | /******************************************************************
|
---|
| 734 | *
|
---|
| 735 | * Initialize
|
---|
| 736 | *
|
---|
| 737 | ******************************************************************/
|
---|
| 738 | void sh_hash_init ()
|
---|
| 739 | {
|
---|
[199] | 740 | volatile int retval = 0;
|
---|
| 741 | volatile int exitval = EXIT_SUCCESS;
|
---|
[185] | 742 |
|
---|
[1] | 743 | SL_ENTER(_("sh_hash_init"));
|
---|
| 744 |
|
---|
[463] | 745 | if ( sh.flag.checkSum == SH_CHECK_INIT )
|
---|
| 746 | {
|
---|
| 747 | dlog(1, FIL__, __LINE__,
|
---|
| 748 | _("Attempt to load the baseline database during initialisation. This is an internal error, please report it to the developer.\n"));
|
---|
| 749 | SH_ABORT;
|
---|
| 750 | aud_exit (FIL__, __LINE__, EXIT_FAILURE);
|
---|
| 751 | }
|
---|
| 752 |
|
---|
[149] | 753 | SH_MUTEX_LOCK(mutex_hash);
|
---|
[1] | 754 |
|
---|
[149] | 755 | if (IsInit == 1)
|
---|
| 756 | {
|
---|
| 757 | goto unlock_and_return;
|
---|
| 758 | }
|
---|
[1] | 759 |
|
---|
[149] | 760 | /* Initialization completed.
|
---|
| 761 | */
|
---|
[481] | 762 | retval = sh_dbIO_load_db(tab);
|
---|
[149] | 763 |
|
---|
[481] | 764 | if (0 == retval)
|
---|
| 765 | IsInit = 1;
|
---|
| 766 | else
|
---|
| 767 | exitval = EXIT_FAILURE;
|
---|
[1] | 768 |
|
---|
[149] | 769 | unlock_and_return:
|
---|
[153] | 770 | ; /* 'label at end of compound statement */
|
---|
[149] | 771 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[185] | 772 | if (retval == 0)
|
---|
| 773 | {
|
---|
| 774 | SL_RET0(_("sh_hash_init"));
|
---|
| 775 | }
|
---|
[481] | 776 | sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EXIT_ABORT1, sh.prg_name);
|
---|
[185] | 777 | aud_exit (FIL__, __LINE__, exitval);
|
---|
[1] | 778 | }
|
---|
[481] | 779 |
|
---|
| 780 | void sh_hash_init_and_checksum()
|
---|
| 781 | {
|
---|
| 782 | TPT((0, FIL__, __LINE__, _("msg=<Get checksum of the database.>\n")))
|
---|
| 783 | if (sh.flag.checkSum == SH_CHECK_CHECK)
|
---|
| 784 | {
|
---|
| 785 | if (0 != sl_strcmp(file_path('D', 'R'), _("REQ_FROM_SERVER")))
|
---|
| 786 | {
|
---|
| 787 | char hashbuf[KEYBUF_SIZE];
|
---|
| 788 | (void) sl_strlcpy(sh.data.hash,
|
---|
| 789 | sh_tiger_hash (file_path('D', 'R'),
|
---|
| 790 | TIGER_FILE, TIGER_NOLIM,
|
---|
| 791 | hashbuf, sizeof(hashbuf)),
|
---|
| 792 | KEY_LEN+1);
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | /* this eventually fetches the file from server to get checksum
|
---|
| 796 | */
|
---|
| 797 | sh_hash_init ();
|
---|
| 798 | }
|
---|
| 799 | return;
|
---|
| 800 | }
|
---|
[1] | 801 |
|
---|
| 802 | /*****************************************************************
|
---|
| 803 | *
|
---|
| 804 | * delete hash array
|
---|
| 805 | *
|
---|
| 806 | *****************************************************************/
|
---|
| 807 | void sh_hash_hashdelete ()
|
---|
| 808 | {
|
---|
| 809 | int i;
|
---|
| 810 |
|
---|
| 811 | SL_ENTER(_("sh_hash_hashdelete"));
|
---|
| 812 |
|
---|
[320] | 813 | /* need deadlock detection here if called from exit handler
|
---|
| 814 | */
|
---|
| 815 | SH_MUTEX_TRYLOCK(mutex_hash);
|
---|
| 816 |
|
---|
[1] | 817 | if (IsInit == 0)
|
---|
[149] | 818 | goto unlock_and_exit;
|
---|
| 819 |
|
---|
[1] | 820 | for (i = 0; i < TABSIZE; ++i)
|
---|
| 821 | if (tab[i] != NULL)
|
---|
| 822 | {
|
---|
| 823 | hash_kill (tab[i]);
|
---|
| 824 | tab[i] = NULL;
|
---|
| 825 | }
|
---|
| 826 | IsInit = 0;
|
---|
[149] | 827 |
|
---|
| 828 | unlock_and_exit:
|
---|
[153] | 829 | ; /* 'label at end of compound statement */
|
---|
[371] | 830 | SH_MUTEX_TRYLOCK_UNLOCK(mutex_hash);
|
---|
[320] | 831 |
|
---|
[1] | 832 | SL_RET0(_("sh_hash_hashdelete"));
|
---|
| 833 | }
|
---|
| 834 |
|
---|
[205] | 835 | static int sh_loosedircheck = S_FALSE;
|
---|
[1] | 836 |
|
---|
[205] | 837 | int sh_hash_loosedircheck(const char * str)
|
---|
| 838 | {
|
---|
| 839 | return sh_util_flagval(str, &sh_loosedircheck);
|
---|
| 840 | }
|
---|
| 841 |
|
---|
| 842 |
|
---|
[1] | 843 |
|
---|
| 844 |
|
---|
| 845 | /*********************************************************************
|
---|
| 846 | *
|
---|
| 847 | * Check whether a file is present in the database.
|
---|
| 848 | *
|
---|
| 849 | *********************************************************************/
|
---|
[294] | 850 | static sh_file_t * sh_hash_have_it_int (const char * newname)
|
---|
[1] | 851 | {
|
---|
| 852 | sh_file_t * p;
|
---|
[133] | 853 | char hashbuf[KEYBUF_SIZE];
|
---|
[1] | 854 |
|
---|
[115] | 855 | SL_ENTER(_("sh_hash_have_it_int"));
|
---|
[1] | 856 |
|
---|
| 857 | if (newname == NULL)
|
---|
[115] | 858 | SL_RETURN( (NULL), _("sh_hash_have_it_int"));
|
---|
[1] | 859 |
|
---|
| 860 | if (sl_strlen(newname) <= MAX_PATH_STORE)
|
---|
| 861 | p = hashsearch(newname);
|
---|
| 862 | else
|
---|
[133] | 863 | p = hashsearch ( sh_tiger_hash(newname, TIGER_DATA, sl_strlen(newname),
|
---|
| 864 | hashbuf, sizeof(hashbuf)) );
|
---|
[1] | 865 | if (p == NULL)
|
---|
[115] | 866 | SL_RETURN( (NULL), _("sh_hash_have_it_int"));
|
---|
[149] | 867 |
|
---|
[115] | 868 | SL_RETURN( (p), _("sh_hash_have_it_int"));
|
---|
[1] | 869 | }
|
---|
| 870 |
|
---|
[294] | 871 | int sh_hash_have_it (const char * newname)
|
---|
[1] | 872 | {
|
---|
[149] | 873 | sh_file_t * p;
|
---|
[170] | 874 | int retval;
|
---|
[1] | 875 |
|
---|
[149] | 876 | if (IsInit != 1)
|
---|
| 877 | sh_hash_init();
|
---|
| 878 |
|
---|
| 879 | SH_MUTEX_LOCK(mutex_hash);
|
---|
[170] | 880 |
|
---|
| 881 | retval = 0;
|
---|
| 882 |
|
---|
[149] | 883 | p = sh_hash_have_it_int (newname);
|
---|
| 884 |
|
---|
| 885 | if (!p)
|
---|
| 886 | retval = (-1);
|
---|
| 887 | else if ((!SH_FFLAG_ALLIGNORE_SET(p->fflags)) &&
|
---|
| 888 | (p->modi_mask & MODI_CHK) != 0 &&
|
---|
| 889 | (p->modi_mask & MODI_MOD) != 0)
|
---|
| 890 | retval = 1;
|
---|
| 891 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 892 |
|
---|
| 893 | return retval;
|
---|
[1] | 894 | }
|
---|
| 895 |
|
---|
[294] | 896 | int sh_hash_get_it (const char * newname, file_type * tmpFile, char * fileHash)
|
---|
[1] | 897 | {
|
---|
[149] | 898 | sh_file_t * p;
|
---|
[170] | 899 | int retval;
|
---|
[68] | 900 |
|
---|
[149] | 901 | if (IsInit != 1)
|
---|
| 902 | sh_hash_init();
|
---|
| 903 |
|
---|
[167] | 904 | tmpFile->link_path = NULL;
|
---|
| 905 | tmpFile->attr_string = NULL;
|
---|
| 906 |
|
---|
[149] | 907 | SH_MUTEX_LOCK(mutex_hash);
|
---|
[170] | 908 |
|
---|
| 909 | retval = (-1);
|
---|
| 910 |
|
---|
[149] | 911 | p = sh_hash_have_it_int (newname);
|
---|
| 912 | if (p)
|
---|
| 913 | {
|
---|
[167] | 914 | sl_strlcpy(tmpFile->fullpath, p->fullpath, PATH_MAX);
|
---|
| 915 | if (p->linkpath)
|
---|
| 916 | tmpFile->link_path = sh_util_strdup (p->linkpath);
|
---|
[149] | 917 | tmpFile->size = p->theFile.size;
|
---|
| 918 | tmpFile->mtime = p->theFile.mtime;
|
---|
| 919 | tmpFile->ctime = p->theFile.ctime;
|
---|
[294] | 920 | tmpFile->atime = p->theFile.atime;
|
---|
| 921 |
|
---|
| 922 | if (NULL != fileHash)
|
---|
| 923 | sl_strlcpy(fileHash, p->theFile.checksum, KEY_LEN+1);
|
---|
| 924 |
|
---|
[149] | 925 | tmpFile->attr_string = NULL;
|
---|
| 926 | retval = 0;
|
---|
| 927 | }
|
---|
| 928 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 929 |
|
---|
| 930 | return retval;
|
---|
[1] | 931 | }
|
---|
| 932 |
|
---|
[115] | 933 | int sh_hash_getflags (char * filename)
|
---|
| 934 | {
|
---|
[149] | 935 | sh_file_t * p;
|
---|
[463] | 936 | int retval = 0;
|
---|
[149] | 937 |
|
---|
[463] | 938 | if ( sh.flag.checkSum != SH_CHECK_INIT )
|
---|
| 939 | {
|
---|
| 940 | if (IsInit != 1)
|
---|
| 941 | sh_hash_init();
|
---|
| 942 |
|
---|
| 943 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 944 | p = sh_hash_have_it_int (filename);
|
---|
| 945 | if (p)
|
---|
| 946 | retval = p->fflags;
|
---|
| 947 | else
|
---|
| 948 | retval = -1;
|
---|
| 949 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 950 | }
|
---|
[149] | 951 | return retval;
|
---|
[115] | 952 | }
|
---|
| 953 |
|
---|
| 954 | int sh_hash_setflags (char * filename, int flags)
|
---|
| 955 | {
|
---|
[149] | 956 | sh_file_t * p;
|
---|
[463] | 957 | int retval = 0;
|
---|
[149] | 958 |
|
---|
[463] | 959 | if ( sh.flag.checkSum != SH_CHECK_INIT )
|
---|
[149] | 960 | {
|
---|
[463] | 961 | if (IsInit != 1)
|
---|
| 962 | sh_hash_init();
|
---|
| 963 |
|
---|
| 964 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 965 | p = sh_hash_have_it_int (filename);
|
---|
| 966 | if (p)
|
---|
| 967 | {
|
---|
| 968 | p->fflags = flags;
|
---|
| 969 | retval = 0;
|
---|
| 970 | }
|
---|
| 971 | else
|
---|
| 972 | retval = -1;
|
---|
| 973 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[149] | 974 | }
|
---|
| 975 | return retval;
|
---|
[115] | 976 | }
|
---|
| 977 |
|
---|
| 978 | /* needs lock to be threadsafe
|
---|
| 979 | */
|
---|
[458] | 980 | void sh_hash_set_flag (char * filename, int flag_to_set)
|
---|
[115] | 981 | {
|
---|
[149] | 982 | sh_file_t * p;
|
---|
[115] | 983 |
|
---|
[463] | 984 | if ( sh.flag.checkSum != SH_CHECK_INIT )
|
---|
[115] | 985 | {
|
---|
[463] | 986 | if (IsInit != 1)
|
---|
| 987 | sh_hash_init();
|
---|
| 988 |
|
---|
| 989 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 990 | p = sh_hash_have_it_int (filename);
|
---|
| 991 | if (p)
|
---|
| 992 | {
|
---|
| 993 | p->fflags |= flag_to_set;
|
---|
| 994 | }
|
---|
| 995 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[115] | 996 | }
|
---|
| 997 | return;
|
---|
| 998 | }
|
---|
| 999 |
|
---|
[458] | 1000 | /* needs lock to be threadsafe
|
---|
| 1001 | */
|
---|
| 1002 | void sh_hash_clear_flag (char * filename, int flag_to_clear)
|
---|
| 1003 | {
|
---|
| 1004 | sh_file_t * p;
|
---|
| 1005 |
|
---|
[463] | 1006 | if ( sh.flag.checkSum != SH_CHECK_INIT )
|
---|
[458] | 1007 | {
|
---|
[463] | 1008 | if (IsInit != 1)
|
---|
| 1009 | sh_hash_init();
|
---|
| 1010 |
|
---|
| 1011 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 1012 | p = sh_hash_have_it_int (filename);
|
---|
| 1013 | if (p)
|
---|
| 1014 | {
|
---|
| 1015 | p->fflags &= ~flag_to_clear;
|
---|
| 1016 | }
|
---|
| 1017 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[458] | 1018 | }
|
---|
| 1019 | return;
|
---|
| 1020 | }
|
---|
| 1021 |
|
---|
| 1022 |
|
---|
[1] | 1023 | /*****************************************************************
|
---|
| 1024 | *
|
---|
| 1025 | * Set a file's status to 'visited'. This is required for
|
---|
| 1026 | * files that should be ignored, and may be present in the
|
---|
| 1027 | * database, but not on disk.
|
---|
| 1028 | *
|
---|
| 1029 | *****************************************************************/
|
---|
| 1030 | static int sh_hash_set_visited_int (char * newname, int flag)
|
---|
| 1031 | {
|
---|
| 1032 | sh_file_t * p;
|
---|
[133] | 1033 | char hashbuf[KEYBUF_SIZE];
|
---|
[170] | 1034 | int retval;
|
---|
[1] | 1035 |
|
---|
| 1036 | SL_ENTER(_("sh_hash_set_visited_int"));
|
---|
| 1037 |
|
---|
| 1038 | if (newname == NULL)
|
---|
| 1039 | SL_RETURN((-1), _("sh_hash_set_visited_int"));
|
---|
[149] | 1040 |
|
---|
[1] | 1041 | if (IsInit != 1)
|
---|
| 1042 | sh_hash_init();
|
---|
| 1043 |
|
---|
[149] | 1044 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 1045 |
|
---|
[1] | 1046 | if (sl_strlen(newname) <= MAX_PATH_STORE)
|
---|
| 1047 | p = hashsearch(newname);
|
---|
| 1048 | else
|
---|
[133] | 1049 | p = hashsearch (sh_tiger_hash(newname, TIGER_DATA, sl_strlen(newname),
|
---|
| 1050 | hashbuf, sizeof(hashbuf)));
|
---|
[1] | 1051 |
|
---|
[149] | 1052 | if (p)
|
---|
[1] | 1053 | {
|
---|
[149] | 1054 | if (flag == SH_FFLAG_CHECKED)
|
---|
| 1055 | {
|
---|
| 1056 | CLEAR_SH_FFLAG_REPORTED(p->fflags);
|
---|
| 1057 | CLEAR_SH_FFLAG_VISITED(p->fflags);
|
---|
| 1058 | SET_SH_FFLAG_CHECKED(p->fflags);
|
---|
| 1059 | }
|
---|
[114] | 1060 | else
|
---|
[149] | 1061 | {
|
---|
| 1062 | SET_SH_FFLAG_VISITED(p->fflags);
|
---|
| 1063 | CLEAR_SH_FFLAG_CHECKED(p->fflags);
|
---|
| 1064 | if (flag == SH_FFLAG_REPORTED)
|
---|
| 1065 | SET_SH_FFLAG_REPORTED(p->fflags);
|
---|
| 1066 | else
|
---|
| 1067 | CLEAR_SH_FFLAG_REPORTED(p->fflags);
|
---|
| 1068 | }
|
---|
| 1069 | retval = 0;
|
---|
[1] | 1070 | }
|
---|
[170] | 1071 | else
|
---|
| 1072 | retval = -1;
|
---|
[149] | 1073 |
|
---|
| 1074 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 1075 | SL_RETURN((retval), _("sh_hash_set_visited_int"));
|
---|
[1] | 1076 | }
|
---|
| 1077 |
|
---|
| 1078 |
|
---|
| 1079 | /* cause the record to be deleted without a 'missing' message
|
---|
| 1080 | */
|
---|
| 1081 | int sh_hash_set_missing (char * newname)
|
---|
| 1082 | {
|
---|
| 1083 | int i;
|
---|
[294] | 1084 | SL_ENTER(_("sh_hash_set_missing"));
|
---|
[305] | 1085 |
|
---|
[114] | 1086 | i = sh_hash_set_visited_int(newname, SH_FFLAG_CHECKED);
|
---|
[305] | 1087 |
|
---|
| 1088 | if (sh.flag.checkSum != SH_CHECK_INIT) {
|
---|
| 1089 | sh_hash_remove(newname);
|
---|
| 1090 | }
|
---|
| 1091 |
|
---|
[294] | 1092 | SL_RETURN(i, _("sh_hash_set_missing"));
|
---|
[1] | 1093 | }
|
---|
| 1094 |
|
---|
[114] | 1095 | /* mark the file as visited and reported
|
---|
| 1096 | */
|
---|
[1] | 1097 | int sh_hash_set_visited (char * newname)
|
---|
| 1098 | {
|
---|
| 1099 | int i;
|
---|
| 1100 | SL_ENTER(_("sh_hash_set_visited"));
|
---|
[114] | 1101 | i = sh_hash_set_visited_int(newname, SH_FFLAG_REPORTED);
|
---|
[1] | 1102 | SL_RETURN(i, _("sh_hash_set_visited"));
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
[114] | 1105 | /* mark the file as visited and NOT reported
|
---|
| 1106 | * used to avoid deletion of file from internal database
|
---|
| 1107 | */
|
---|
[1] | 1108 | int sh_hash_set_visited_true (char * newname)
|
---|
| 1109 | {
|
---|
| 1110 | int i;
|
---|
| 1111 | SL_ENTER(_("sh_hash_set_visited_true"));
|
---|
[114] | 1112 | i = sh_hash_set_visited_int(newname, 0);
|
---|
[1] | 1113 | SL_RETURN(i, _("sh_hash_set_visited_true"));
|
---|
| 1114 | }
|
---|
| 1115 |
|
---|
| 1116 |
|
---|
| 1117 | /******************************************************************
|
---|
| 1118 | *
|
---|
| 1119 | * Data entry for arbitrary data into database
|
---|
| 1120 | *
|
---|
| 1121 | ******************************************************************/
|
---|
| 1122 |
|
---|
[294] | 1123 | void sh_hash_push2db (const char * key, struct store2db * save)
|
---|
[1] | 1124 | {
|
---|
| 1125 | int i = 0;
|
---|
| 1126 | char * p;
|
---|
[137] | 1127 | char i2h[2];
|
---|
[227] | 1128 | file_type * tmpFile = SH_ALLOC(sizeof(file_type));
|
---|
[1] | 1129 |
|
---|
[294] | 1130 | int size = save->size;
|
---|
| 1131 | unsigned char * str = save->str;
|
---|
| 1132 |
|
---|
| 1133 |
|
---|
[227] | 1134 | tmpFile->attr_string = NULL;
|
---|
| 1135 | tmpFile->link_path = NULL;
|
---|
[68] | 1136 |
|
---|
[227] | 1137 | sl_strlcpy(tmpFile->fullpath, key, PATH_MAX);
|
---|
[294] | 1138 | tmpFile->size = save->val0;
|
---|
| 1139 | tmpFile->mtime = save->val1;
|
---|
| 1140 | tmpFile->ctime = save->val2;
|
---|
| 1141 | tmpFile->atime = save->val3;
|
---|
[1] | 1142 |
|
---|
[227] | 1143 | tmpFile->mode = 0;
|
---|
| 1144 | tmpFile->owner = 0;
|
---|
| 1145 | tmpFile->group = 0;
|
---|
| 1146 | sl_strlcpy(tmpFile->c_owner, _("root"), 5);
|
---|
| 1147 | sl_strlcpy(tmpFile->c_group, _("root"), 5);
|
---|
[1] | 1148 |
|
---|
[481] | 1149 | tmpFile->check_flags = 0;
|
---|
| 1150 |
|
---|
[1] | 1151 | if ((str != NULL) && (size < (PATH_MAX/2)-1))
|
---|
| 1152 | {
|
---|
[227] | 1153 | tmpFile->c_mode[0] = 'l';
|
---|
| 1154 | tmpFile->c_mode[1] = 'r'; tmpFile->c_mode[2] = 'w';
|
---|
| 1155 | tmpFile->c_mode[3] = 'x'; tmpFile->c_mode[4] = 'r';
|
---|
| 1156 | tmpFile->c_mode[5] = 'w'; tmpFile->c_mode[6] = 'x';
|
---|
| 1157 | tmpFile->c_mode[7] = 'r'; tmpFile->c_mode[8] = 'w';
|
---|
| 1158 | tmpFile->c_mode[9] = 'x'; tmpFile->c_mode[10] = '\0';
|
---|
| 1159 | tmpFile->link_path = SH_ALLOC((size * 2) + 2);
|
---|
[1] | 1160 | for (i = 0; i < size; ++i)
|
---|
| 1161 | {
|
---|
[137] | 1162 | p = sh_util_charhex (str[i],i2h);
|
---|
[227] | 1163 | tmpFile->link_path[2*i] = p[0];
|
---|
| 1164 | tmpFile->link_path[2*i+1] = p[1];
|
---|
| 1165 | tmpFile->link_path[2*i+2] = '\0';
|
---|
[1] | 1166 | }
|
---|
| 1167 | }
|
---|
| 1168 | else
|
---|
| 1169 | {
|
---|
[93] | 1170 | for (i = 0; i < 10; ++i)
|
---|
[227] | 1171 | tmpFile->c_mode[i] = '-';
|
---|
| 1172 | tmpFile->c_mode[10] = '\0';
|
---|
| 1173 | tmpFile->link_path = sh_util_strdup("-");
|
---|
[1] | 1174 | }
|
---|
| 1175 |
|
---|
[294] | 1176 | if (sh.flag.checkSum == SH_CHECK_INIT)
|
---|
[481] | 1177 | sh_dbIO_data_write (tmpFile,
|
---|
| 1178 | (save->checksum[0] == '\0') ? SH_KEY_NULL : save->checksum);
|
---|
[1] | 1179 | else
|
---|
[294] | 1180 | sh_hash_pushdata_memory (tmpFile,
|
---|
| 1181 | (save->checksum[0] == '\0') ? SH_KEY_NULL : save->checksum);
|
---|
[1] | 1182 |
|
---|
[227] | 1183 | if (tmpFile->link_path) SH_FREE(tmpFile->link_path);
|
---|
| 1184 | SH_FREE(tmpFile);
|
---|
[1] | 1185 | return;
|
---|
| 1186 | }
|
---|
| 1187 |
|
---|
| 1188 | extern int sh_util_hextobinary (char * binary, char * hex, int bytes);
|
---|
| 1189 |
|
---|
[294] | 1190 | char * sh_hash_db2pop (const char * key, struct store2db * save)
|
---|
[1] | 1191 | {
|
---|
| 1192 | size_t len;
|
---|
| 1193 | char * p;
|
---|
| 1194 | int i;
|
---|
[167] | 1195 | char * retval = NULL;
|
---|
[294] | 1196 | char fileHash[KEY_LEN+1];
|
---|
[227] | 1197 | file_type * tmpFile = SH_ALLOC(sizeof(file_type));
|
---|
[167] | 1198 |
|
---|
[294] | 1199 | save->size = 0;
|
---|
[1] | 1200 |
|
---|
[294] | 1201 | if (0 == sh_hash_get_it (key, tmpFile, fileHash))
|
---|
[1] | 1202 | {
|
---|
[294] | 1203 | save->val0 = tmpFile->size;
|
---|
| 1204 | save->val1 = tmpFile->mtime;
|
---|
| 1205 | save->val2 = tmpFile->ctime;
|
---|
| 1206 | save->val3 = tmpFile->atime;
|
---|
[1] | 1207 |
|
---|
[294] | 1208 | sl_strlcpy(save->checksum, fileHash, KEY_LEN+1);
|
---|
| 1209 |
|
---|
[227] | 1210 | if (tmpFile->link_path && tmpFile->link_path[0] != '-')
|
---|
[1] | 1211 | {
|
---|
[227] | 1212 | len = strlen(tmpFile->link_path);
|
---|
[1] | 1213 |
|
---|
| 1214 | p = SH_ALLOC((len/2)+1);
|
---|
[227] | 1215 | i = sh_util_hextobinary (p, tmpFile->link_path, len);
|
---|
[1] | 1216 |
|
---|
| 1217 | if (i == 0)
|
---|
| 1218 | {
|
---|
[294] | 1219 | save->size = (len/2);
|
---|
| 1220 | p[save->size] = '\0';
|
---|
[167] | 1221 | retval = p;
|
---|
[1] | 1222 | }
|
---|
| 1223 | else
|
---|
| 1224 | {
|
---|
| 1225 | SH_FREE(p);
|
---|
[294] | 1226 | save->size = 0;
|
---|
[1] | 1227 | }
|
---|
| 1228 | }
|
---|
| 1229 | else
|
---|
| 1230 | {
|
---|
[294] | 1231 | save->size = 0;
|
---|
[1] | 1232 | }
|
---|
| 1233 | }
|
---|
| 1234 | else
|
---|
| 1235 | {
|
---|
[294] | 1236 | save->size = -1;
|
---|
| 1237 | save->val0 = 0;
|
---|
| 1238 | save->val1 = 0;
|
---|
| 1239 | save->val2 = 0;
|
---|
| 1240 | save->val3 = 0;
|
---|
[1] | 1241 | }
|
---|
[227] | 1242 | if (tmpFile->link_path) SH_FREE(tmpFile->link_path);
|
---|
| 1243 | SH_FREE(tmpFile);
|
---|
[167] | 1244 | return retval;
|
---|
[1] | 1245 | }
|
---|
| 1246 |
|
---|
| 1247 |
|
---|
| 1248 |
|
---|
| 1249 |
|
---|
| 1250 | /******************************************************************
|
---|
| 1251 | *
|
---|
| 1252 | * Data entry in hash table
|
---|
| 1253 | *
|
---|
| 1254 | ******************************************************************/
|
---|
| 1255 | sh_file_t * sh_hash_push_int (file_type * buf, char * fileHash)
|
---|
| 1256 | {
|
---|
| 1257 | sh_file_t * fp;
|
---|
| 1258 | sh_filestore_t p;
|
---|
[34] | 1259 |
|
---|
| 1260 | size_t len;
|
---|
[1] | 1261 | char * fullpath;
|
---|
| 1262 | char * linkpath;
|
---|
[68] | 1263 | char * attr_string = NULL;
|
---|
[133] | 1264 | char hashbuf[KEYBUF_SIZE];
|
---|
[1] | 1265 |
|
---|
| 1266 | SL_ENTER(_("sh_hash_push_int"));
|
---|
| 1267 |
|
---|
| 1268 | fp = SH_ALLOC(sizeof(sh_file_t));
|
---|
| 1269 |
|
---|
| 1270 | p.mark = REC_MAGIC;
|
---|
[68] | 1271 | if (buf->attr_string)
|
---|
| 1272 | p.mark |= REC_FLAGS_ATTR;
|
---|
[1] | 1273 | sl_strlcpy(p.c_mode, buf->c_mode, 11);
|
---|
| 1274 | sl_strlcpy(p.c_group, buf->c_group, GROUP_MAX+1);
|
---|
| 1275 | sl_strlcpy(p.c_owner, buf->c_owner, USER_MAX+1);
|
---|
| 1276 | sl_strlcpy(p.checksum, fileHash, KEY_LEN+1);
|
---|
[10] | 1277 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 1278 | sl_strlcpy(p.c_attributes, buf->c_attributes, 13);
|
---|
| 1279 | #endif
|
---|
| 1280 |
|
---|
[10] | 1281 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 1282 | p.attributes = (UINT32) buf->attributes;
|
---|
| 1283 | #endif
|
---|
| 1284 | p.linkmode = (UINT32) buf->linkmode;
|
---|
| 1285 | p.hardlinks = (UINT32) buf->hardlinks;
|
---|
[40] | 1286 | p.dev = (UINT64) buf->dev;
|
---|
| 1287 | p.rdev = (UINT64) buf->rdev;
|
---|
[1] | 1288 | p.mode = (UINT32) buf->mode;
|
---|
| 1289 | p.ino = (UINT32) buf->ino;
|
---|
| 1290 | p.size = (UINT64) buf->size;
|
---|
| 1291 | p.mtime = (UINT64) buf->mtime;
|
---|
| 1292 | p.atime = (UINT64) buf->atime;
|
---|
| 1293 | p.ctime = (UINT64) buf->ctime;
|
---|
| 1294 | p.owner = (UINT32) buf->owner;
|
---|
| 1295 | p.group = (UINT32) buf->group;
|
---|
| 1296 |
|
---|
[481] | 1297 | p.checkflags = (UINT32) buf->check_flags;
|
---|
| 1298 |
|
---|
[1] | 1299 | memcpy( &(*fp).theFile, &p, sizeof(sh_filestore_t) );
|
---|
[115] | 1300 | fp->fflags = 0; /* init fflags */
|
---|
[1] | 1301 | fp->modi_mask = 0L;
|
---|
| 1302 |
|
---|
[68] | 1303 | if (buf->attr_string)
|
---|
| 1304 | attr_string = sh_util_strdup(buf->attr_string);
|
---|
| 1305 | fp->attr_string = attr_string;
|
---|
| 1306 |
|
---|
[34] | 1307 | len = sl_strlen(buf->fullpath);
|
---|
| 1308 | if (len <= MAX_PATH_STORE)
|
---|
[1] | 1309 | {
|
---|
[34] | 1310 | fullpath = SH_ALLOC(len+1);
|
---|
| 1311 | sl_strlcpy(fullpath, buf->fullpath, len+1);
|
---|
[1] | 1312 | }
|
---|
| 1313 | else
|
---|
| 1314 | {
|
---|
| 1315 | fullpath = SH_ALLOC(KEY_LEN + 1);
|
---|
| 1316 | sl_strlcpy(fullpath,
|
---|
[133] | 1317 | sh_tiger_hash (buf->fullpath, TIGER_DATA, len,
|
---|
| 1318 | hashbuf, sizeof(hashbuf)),
|
---|
[1] | 1319 | KEY_LEN+1);
|
---|
| 1320 | }
|
---|
| 1321 | fp->fullpath = fullpath;
|
---|
| 1322 |
|
---|
[167] | 1323 | if (buf->link_path)
|
---|
[1] | 1324 | {
|
---|
[167] | 1325 | len = sl_strlen(buf->link_path);
|
---|
[34] | 1326 | if (len <= MAX_PATH_STORE)
|
---|
[1] | 1327 | {
|
---|
[34] | 1328 | linkpath = SH_ALLOC(len+1);
|
---|
[167] | 1329 | sl_strlcpy(linkpath, buf->link_path, len+1);
|
---|
[1] | 1330 | }
|
---|
| 1331 | else
|
---|
| 1332 | {
|
---|
| 1333 | linkpath = SH_ALLOC(KEY_LEN + 1);
|
---|
| 1334 | sl_strlcpy(linkpath,
|
---|
[167] | 1335 | sh_tiger_hash (buf->link_path, TIGER_DATA, len,
|
---|
[133] | 1336 | hashbuf, sizeof(hashbuf)),
|
---|
[1] | 1337 | KEY_LEN+1);
|
---|
| 1338 | }
|
---|
| 1339 | fp->linkpath = linkpath;
|
---|
| 1340 | }
|
---|
| 1341 | else
|
---|
| 1342 | fp->linkpath = NULL;
|
---|
| 1343 |
|
---|
| 1344 | SL_RETURN( fp, _("sh_hash_push_int"));
|
---|
| 1345 | }
|
---|
| 1346 |
|
---|
| 1347 | #ifdef HAVE_INTTYPES_H
|
---|
| 1348 | #include <inttypes.h>
|
---|
| 1349 | #else
|
---|
| 1350 | #ifdef HAVE_STDINT_H
|
---|
| 1351 | #include <stdint.h>
|
---|
| 1352 | #endif
|
---|
| 1353 | #endif
|
---|
| 1354 |
|
---|
[40] | 1355 | #ifndef PRIu64
|
---|
| 1356 | #ifdef HAVE_LONG_32
|
---|
| 1357 | #define PRIu64 "llu"
|
---|
| 1358 | #else
|
---|
| 1359 | #define PRIu64 "lu"
|
---|
[1] | 1360 | #endif
|
---|
[40] | 1361 | #endif
|
---|
[1] | 1362 |
|
---|
| 1363 | char * sh_hash_size_format()
|
---|
| 1364 | {
|
---|
| 1365 | static char form_rval[81];
|
---|
| 1366 |
|
---|
| 1367 | SL_ENTER(_("sh_hash_size_format"));
|
---|
| 1368 |
|
---|
| 1369 |
|
---|
| 1370 | #ifdef SH_USE_XML
|
---|
| 1371 | sl_snprintf(form_rval, 80, _("%s%s%s%s%s"),
|
---|
[40] | 1372 | _("size_old=\"%"), PRIu64, _("\" size_new=\"%"), PRIu64, "\" ");
|
---|
[1] | 1373 | #else
|
---|
| 1374 | sl_snprintf(form_rval, 80, _("%s%s%s%s%s"),
|
---|
[40] | 1375 | _("size_old=<%"), PRIu64, _(">, size_new=<%"), PRIu64, ">, ");
|
---|
[1] | 1376 | #endif
|
---|
| 1377 |
|
---|
| 1378 | SL_RETURN( form_rval, _("sh_hash_size_format"));
|
---|
| 1379 | }
|
---|
| 1380 |
|
---|
| 1381 |
|
---|
| 1382 | #ifdef SH_USE_XML
|
---|
| 1383 | static char * all_items (file_type * theFile, char * fileHash, int is_new)
|
---|
| 1384 | {
|
---|
| 1385 | char timstr1c[32];
|
---|
| 1386 | char timstr1a[32];
|
---|
| 1387 | char timstr1m[32];
|
---|
| 1388 |
|
---|
| 1389 | char * tmp_lnk;
|
---|
| 1390 | char * format;
|
---|
| 1391 |
|
---|
[170] | 1392 | char * tmp = SH_ALLOC(SH_MSG_BUF);
|
---|
| 1393 | char * msg = SH_ALLOC(SH_MSG_BUF);
|
---|
[1] | 1394 |
|
---|
| 1395 | tmp[0] = '\0';
|
---|
| 1396 | msg[0] = '\0';
|
---|
| 1397 |
|
---|
[481] | 1398 | if (report_checkflags != S_FALSE)
|
---|
| 1399 | {
|
---|
| 1400 | if (is_new)
|
---|
| 1401 | format = _("checkflags_new=\"0%lo\" ");
|
---|
| 1402 | else
|
---|
| 1403 | format = _("checkflags_old=\"0%lo\" ");
|
---|
| 1404 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
| 1405 | (unsigned long) theFile->check_flags);
|
---|
| 1406 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
| 1407 | }
|
---|
[1] | 1408 |
|
---|
[10] | 1409 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 1410 | if (is_new)
|
---|
| 1411 | format = _("mode_new=\"%s\" attr_new=\"%s\" imode_new=\"%ld\" iattr_new=\"%ld\" ");
|
---|
| 1412 | else
|
---|
| 1413 | format = _("mode_old=\"%s\" attr_old=\"%s\" imode_old=\"%ld\" iattr_old=\"%ld\" ");
|
---|
[170] | 1414 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1415 | theFile->c_mode,
|
---|
| 1416 | theFile->c_attributes,
|
---|
| 1417 | (long) theFile->mode,
|
---|
| 1418 | (long) theFile->attributes
|
---|
| 1419 | );
|
---|
| 1420 | #else
|
---|
| 1421 | if (is_new)
|
---|
| 1422 | format = _("mode_new=\"%s\" imode_new=\"%ld\" ");
|
---|
| 1423 | else
|
---|
| 1424 | format = _("mode_old=\"%s\" imode_old=\"%ld\" ");
|
---|
| 1425 |
|
---|
[170] | 1426 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1427 | theFile->c_mode,
|
---|
| 1428 | (long) theFile->mode
|
---|
| 1429 | );
|
---|
| 1430 | #endif
|
---|
[170] | 1431 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1432 |
|
---|
| 1433 | if (is_new)
|
---|
[40] | 1434 | format = _("hardlinks_new=\"%lu\" ");
|
---|
[1] | 1435 | else
|
---|
[40] | 1436 | format = _("hardlinks_old=\"%lu\" ");
|
---|
[170] | 1437 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1438 | (unsigned long) theFile->hardlinks);
|
---|
[170] | 1439 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1440 |
|
---|
| 1441 |
|
---|
| 1442 | if (is_new)
|
---|
[40] | 1443 | format = _("idevice_new=\"%lu\" ");
|
---|
[1] | 1444 | else
|
---|
[40] | 1445 | format = _("idevice_old=\"%lu\" ");
|
---|
[170] | 1446 | sl_snprintf(tmp, SH_MSG_BUF, format, (unsigned long) theFile->rdev);
|
---|
| 1447 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1448 |
|
---|
| 1449 |
|
---|
| 1450 | if (is_new)
|
---|
[40] | 1451 | format = _("inode_new=\"%lu\" ");
|
---|
[1] | 1452 | else
|
---|
[40] | 1453 | format = _("inode_old=\"%lu\" ");
|
---|
[170] | 1454 | sl_snprintf(tmp, SH_MSG_BUF, format, (unsigned long) theFile->ino);
|
---|
| 1455 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1456 |
|
---|
[40] | 1457 | /*
|
---|
| 1458 | * also report device for prelude
|
---|
| 1459 | */
|
---|
[181] | 1460 | #if defined(HAVE_LIBPRELUDE)
|
---|
[40] | 1461 | if (is_new)
|
---|
| 1462 | format = _("dev_new=\"%lu,%lu\" ");
|
---|
| 1463 | else
|
---|
| 1464 | format = _("dev_old=\"%lu,%lu\" ");
|
---|
[170] | 1465 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[40] | 1466 | (unsigned long) major(theFile->dev),
|
---|
| 1467 | (unsigned long) minor(theFile->dev));
|
---|
[170] | 1468 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[40] | 1469 | #endif
|
---|
[1] | 1470 |
|
---|
[40] | 1471 |
|
---|
[1] | 1472 | if (is_new)
|
---|
| 1473 | format = _("owner_new=\"%s\" iowner_new=\"%ld\" ");
|
---|
| 1474 | else
|
---|
| 1475 | format = _("owner_old=\"%s\" iowner_old=\"%ld\" ");
|
---|
[170] | 1476 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1477 | theFile->c_owner, (long) theFile->owner);
|
---|
[170] | 1478 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1479 |
|
---|
| 1480 |
|
---|
| 1481 | if (is_new)
|
---|
| 1482 | format = _("group_new=\"%s\" igroup_new=\"%ld\" ");
|
---|
| 1483 | else
|
---|
| 1484 | format = _("group_old=\"%s\" igroup_old=\"%ld\" ");
|
---|
[170] | 1485 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1486 | theFile->c_group, (long) theFile->group);
|
---|
[170] | 1487 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1488 |
|
---|
| 1489 |
|
---|
| 1490 | if (is_new)
|
---|
[170] | 1491 | sl_snprintf(tmp, SH_MSG_BUF, sh_hash_size_format(),
|
---|
[1] | 1492 | (UINT64) 0, (UINT64) theFile->size);
|
---|
| 1493 | else
|
---|
[170] | 1494 | sl_snprintf(tmp, SH_MSG_BUF, sh_hash_size_format(),
|
---|
[1] | 1495 | (UINT64) theFile->size, (UINT64) 0);
|
---|
[170] | 1496 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1497 |
|
---|
| 1498 |
|
---|
[132] | 1499 | (void) sh_unix_gmttime (theFile->ctime, timstr1c, sizeof(timstr1c));
|
---|
[1] | 1500 | if (is_new)
|
---|
[170] | 1501 | sl_snprintf(tmp, SH_MSG_BUF, _("ctime_new=\"%s\" "), timstr1c);
|
---|
[1] | 1502 | else
|
---|
[170] | 1503 | sl_snprintf(tmp, SH_MSG_BUF, _("ctime_old=\"%s\" "), timstr1c);
|
---|
| 1504 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1505 |
|
---|
[132] | 1506 | (void) sh_unix_gmttime (theFile->atime, timstr1a, sizeof(timstr1a));
|
---|
[1] | 1507 | if (is_new)
|
---|
[170] | 1508 | sl_snprintf(tmp, SH_MSG_BUF, _("atime_new=\"%s\" "), timstr1a);
|
---|
[1] | 1509 | else
|
---|
[170] | 1510 | sl_snprintf(tmp, SH_MSG_BUF, _("atime_old=\"%s\" "), timstr1a);
|
---|
| 1511 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1512 |
|
---|
[132] | 1513 | (void) sh_unix_gmttime (theFile->mtime, timstr1m, sizeof(timstr1m));
|
---|
[1] | 1514 | if (is_new)
|
---|
[170] | 1515 | sl_snprintf(tmp, SH_MSG_BUF, _("mtime_new=\"%s\" "), timstr1m);
|
---|
[1] | 1516 | else
|
---|
[170] | 1517 | sl_snprintf(tmp, SH_MSG_BUF, _("mtime_old=\"%s\" "), timstr1m);
|
---|
| 1518 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1519 |
|
---|
| 1520 | if (is_new)
|
---|
[170] | 1521 | sl_snprintf(tmp, SH_MSG_BUF, _("chksum_new=\"%s\" "), fileHash);
|
---|
[1] | 1522 | else
|
---|
[170] | 1523 | sl_snprintf(tmp, SH_MSG_BUF, _("chksum_old=\"%s\" "), fileHash);
|
---|
| 1524 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1525 |
|
---|
[169] | 1526 | if (theFile->c_mode[0] == 'l' ||
|
---|
| 1527 | (theFile->link_path != NULL && theFile->link_path[0] != '-'))
|
---|
[1] | 1528 | {
|
---|
[167] | 1529 | tmp_lnk = sh_util_safe_name(theFile->link_path);
|
---|
[1] | 1530 | if (tmp_lnk)
|
---|
| 1531 | {
|
---|
| 1532 | if (is_new)
|
---|
[170] | 1533 | sl_snprintf(tmp, SH_MSG_BUF, _("link_new=\"%s\" "), tmp_lnk);
|
---|
[1] | 1534 | else
|
---|
[170] | 1535 | sl_snprintf(tmp, SH_MSG_BUF, _("link_old=\"%s\" "), tmp_lnk);
|
---|
[1] | 1536 | SH_FREE(tmp_lnk);
|
---|
[170] | 1537 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1538 | }
|
---|
| 1539 | }
|
---|
[68] | 1540 |
|
---|
| 1541 | if (theFile->attr_string)
|
---|
| 1542 | {
|
---|
| 1543 | tmp_lnk = sh_util_safe_name(theFile->attr_string);
|
---|
| 1544 | if (tmp_lnk)
|
---|
| 1545 | {
|
---|
| 1546 | if (is_new)
|
---|
[170] | 1547 | sl_snprintf(tmp, SH_MSG_BUF, _("acl_new=\"%s\" "), tmp_lnk);
|
---|
[68] | 1548 | else
|
---|
[170] | 1549 | sl_snprintf(tmp, SH_MSG_BUF, _("acl_old=\"%s\" "), tmp_lnk);
|
---|
[68] | 1550 | SH_FREE(tmp_lnk);
|
---|
[170] | 1551 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[68] | 1552 | }
|
---|
| 1553 | }
|
---|
| 1554 |
|
---|
[1] | 1555 |
|
---|
| 1556 | SH_FREE(tmp);
|
---|
| 1557 | return (msg);
|
---|
| 1558 | }
|
---|
| 1559 | #else
|
---|
| 1560 | static char * all_items (file_type * theFile, char * fileHash, int is_new)
|
---|
| 1561 | {
|
---|
| 1562 | char timstr1c[32];
|
---|
| 1563 | char timstr1a[32];
|
---|
| 1564 | char timstr1m[32];
|
---|
| 1565 |
|
---|
| 1566 | char * tmp_lnk;
|
---|
| 1567 | char * format;
|
---|
| 1568 |
|
---|
[170] | 1569 | char * tmp = SH_ALLOC(SH_MSG_BUF);
|
---|
| 1570 | char * msg = SH_ALLOC(SH_MSG_BUF);
|
---|
[1] | 1571 |
|
---|
| 1572 | tmp[0] = '\0';
|
---|
| 1573 | msg[0] = '\0';
|
---|
| 1574 |
|
---|
[481] | 1575 | if (report_checkflags == S_TRUE)
|
---|
| 1576 | {
|
---|
| 1577 | if (is_new)
|
---|
| 1578 | format = _("checkflags_new=<0%lo> ");
|
---|
| 1579 | else
|
---|
| 1580 | format = _("checkflags_old=<0%lo> ");
|
---|
| 1581 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
| 1582 | (unsigned long) theFile->check_flags);
|
---|
| 1583 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
| 1584 | }
|
---|
[1] | 1585 |
|
---|
[481] | 1586 |
|
---|
[10] | 1587 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 1588 | if (is_new)
|
---|
| 1589 | format = _("mode_new=<%s>, attr_new=<%s>, imode_new=<%ld>, iattr_new=<%ld>, ");
|
---|
| 1590 | else
|
---|
| 1591 | format = _("mode_old=<%s>, attr_old=<%s>, imode_old=<%ld>, iattr_old=<%ld>, ");
|
---|
[170] | 1592 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1593 | theFile->c_mode,
|
---|
| 1594 | theFile->c_attributes,
|
---|
| 1595 | (long) theFile->mode,
|
---|
| 1596 | (long) theFile->attributes
|
---|
| 1597 | );
|
---|
| 1598 | #else
|
---|
| 1599 | if (is_new)
|
---|
| 1600 | format = _("mode_new=<%s>, imode_new=<%ld>, ");
|
---|
| 1601 | else
|
---|
| 1602 | format = _("mode_old=<%s>, imode_old=<%ld>, ");
|
---|
| 1603 |
|
---|
[170] | 1604 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1605 | theFile->c_mode,
|
---|
| 1606 | (long) theFile->mode
|
---|
| 1607 | );
|
---|
| 1608 | #endif
|
---|
[170] | 1609 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1610 |
|
---|
| 1611 | if (is_new)
|
---|
[40] | 1612 | format = _("hardlinks_new=<%lu>, ");
|
---|
[1] | 1613 | else
|
---|
[40] | 1614 | format = _("hardlinks_old=<%lu>, ");
|
---|
[170] | 1615 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1616 | (unsigned long) theFile->hardlinks);
|
---|
[170] | 1617 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1618 |
|
---|
| 1619 |
|
---|
| 1620 | if (is_new)
|
---|
[40] | 1621 | format = _("idevice_new=<%lu>, ");
|
---|
[1] | 1622 | else
|
---|
[40] | 1623 | format = _("idevice_old=<%lu>, ");
|
---|
[170] | 1624 | sl_snprintf(tmp, SH_MSG_BUF, format, (unsigned long) theFile->rdev);
|
---|
| 1625 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1626 |
|
---|
| 1627 |
|
---|
| 1628 | if (is_new)
|
---|
[40] | 1629 | format = _("inode_new=<%lu>, ");
|
---|
[1] | 1630 | else
|
---|
[40] | 1631 | format = _("inode_old=<%lu>, ");
|
---|
[170] | 1632 | sl_snprintf(tmp, SH_MSG_BUF, format, (unsigned long) theFile->ino);
|
---|
| 1633 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1634 |
|
---|
| 1635 |
|
---|
[40] | 1636 | /*
|
---|
| 1637 | * also report device for prelude
|
---|
| 1638 | */
|
---|
[181] | 1639 | #if defined(HAVE_LIBPRELUDE)
|
---|
[1] | 1640 | if (is_new)
|
---|
[40] | 1641 | format = _("dev_new=<%lu,%lu>, ");
|
---|
| 1642 | else
|
---|
| 1643 | format = _("dev_old=<%lu,%lu>, ");
|
---|
[170] | 1644 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[40] | 1645 | (unsigned long) major(theFile->dev),
|
---|
| 1646 | (unsigned long) minor(theFile->dev));
|
---|
[170] | 1647 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[40] | 1648 | #endif
|
---|
| 1649 |
|
---|
| 1650 | if (is_new)
|
---|
[1] | 1651 | format = _("owner_new=<%s>, iowner_new=<%ld>, ");
|
---|
| 1652 | else
|
---|
| 1653 | format = _("owner_old=<%s>, iowner_old=<%ld>, ");
|
---|
[170] | 1654 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1655 | theFile->c_owner, (long) theFile->owner);
|
---|
[170] | 1656 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1657 |
|
---|
| 1658 |
|
---|
| 1659 | if (is_new)
|
---|
| 1660 | format = _("group_new=<%s>, igroup_new=<%ld>, ");
|
---|
| 1661 | else
|
---|
| 1662 | format = _("group_old=<%s>, igroup_old=<%ld>, ");
|
---|
[170] | 1663 | sl_snprintf(tmp, SH_MSG_BUF, format,
|
---|
[1] | 1664 | theFile->c_group, (long) theFile->group);
|
---|
[170] | 1665 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1666 |
|
---|
| 1667 |
|
---|
| 1668 | if (is_new)
|
---|
[170] | 1669 | sl_snprintf(tmp, SH_MSG_BUF, sh_hash_size_format(),
|
---|
[1] | 1670 | (UINT64) 0, (UINT64) theFile->size);
|
---|
| 1671 | else
|
---|
[170] | 1672 | sl_snprintf(tmp, SH_MSG_BUF, sh_hash_size_format(),
|
---|
[1] | 1673 | (UINT64) theFile->size, (UINT64) 0);
|
---|
[170] | 1674 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1675 |
|
---|
| 1676 |
|
---|
[132] | 1677 | (void) sh_unix_gmttime (theFile->ctime, timstr1c, sizeof(timstr1c));
|
---|
[1] | 1678 | if (is_new)
|
---|
[170] | 1679 | sl_snprintf(tmp, SH_MSG_BUF, _("ctime_new=<%s>, "), timstr1c);
|
---|
[1] | 1680 | else
|
---|
[170] | 1681 | sl_snprintf(tmp, SH_MSG_BUF, _("ctime_old=<%s>, "), timstr1c);
|
---|
| 1682 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1683 |
|
---|
[132] | 1684 | (void) sh_unix_gmttime (theFile->atime, timstr1a, sizeof(timstr1a));
|
---|
[1] | 1685 | if (is_new)
|
---|
[170] | 1686 | sl_snprintf(tmp, SH_MSG_BUF, _("atime_new=<%s>, "), timstr1a);
|
---|
[1] | 1687 | else
|
---|
[170] | 1688 | sl_snprintf(tmp, SH_MSG_BUF, _("atime_old=<%s>, "), timstr1a);
|
---|
| 1689 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1690 |
|
---|
[132] | 1691 | (void) sh_unix_gmttime (theFile->mtime, timstr1m, sizeof(timstr1m));
|
---|
[1] | 1692 | if (is_new)
|
---|
[170] | 1693 | sl_snprintf(tmp, SH_MSG_BUF, _("mtime_new=<%s>, "), timstr1m);
|
---|
[1] | 1694 | else
|
---|
[170] | 1695 | sl_snprintf(tmp, SH_MSG_BUF, _("mtime_old=<%s>, "), timstr1m);
|
---|
| 1696 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1697 |
|
---|
| 1698 | if (is_new)
|
---|
[170] | 1699 | sl_snprintf(tmp, SH_MSG_BUF, _("chksum_new=<%s>"), fileHash);
|
---|
[1] | 1700 | else
|
---|
[170] | 1701 | sl_snprintf(tmp, SH_MSG_BUF, _("chksum_old=<%s>"), fileHash);
|
---|
| 1702 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1703 |
|
---|
[169] | 1704 | if (theFile->c_mode[0] == 'l' ||
|
---|
| 1705 | (theFile->link_path != NULL && theFile->link_path[0] != '-'))
|
---|
[1] | 1706 | {
|
---|
[167] | 1707 | tmp_lnk = sh_util_safe_name(theFile->link_path);
|
---|
[1] | 1708 | if (tmp_lnk)
|
---|
| 1709 | {
|
---|
| 1710 | if (is_new)
|
---|
[170] | 1711 | sl_snprintf(tmp, SH_MSG_BUF, _(", link_new=<%s> "), tmp_lnk);
|
---|
[1] | 1712 | else
|
---|
[170] | 1713 | sl_snprintf(tmp, SH_MSG_BUF, _(", link_old=<%s> "), tmp_lnk);
|
---|
[1] | 1714 | SH_FREE(tmp_lnk);
|
---|
[170] | 1715 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[1] | 1716 | }
|
---|
| 1717 | }
|
---|
| 1718 |
|
---|
[68] | 1719 | if (theFile->attr_string)
|
---|
| 1720 | {
|
---|
| 1721 | tmp_lnk = sh_util_safe_name(theFile->attr_string);
|
---|
| 1722 | if (tmp_lnk)
|
---|
| 1723 | {
|
---|
| 1724 | if (is_new)
|
---|
[170] | 1725 | sl_snprintf(tmp, SH_MSG_BUF, _(", acl_new=<%s> "), tmp_lnk);
|
---|
[68] | 1726 | else
|
---|
[170] | 1727 | sl_snprintf(tmp, SH_MSG_BUF, _(", acl_old=<%s> "), tmp_lnk);
|
---|
[68] | 1728 | SH_FREE(tmp_lnk);
|
---|
[170] | 1729 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[68] | 1730 | }
|
---|
| 1731 | }
|
---|
| 1732 |
|
---|
[1] | 1733 | SH_FREE(tmp);
|
---|
| 1734 | return (msg);
|
---|
| 1735 | }
|
---|
| 1736 | #endif
|
---|
| 1737 |
|
---|
| 1738 | void sh_hash_pushdata_memory (file_type * theFile, char * fileHash)
|
---|
| 1739 | {
|
---|
| 1740 | sh_file_t * p;
|
---|
| 1741 |
|
---|
| 1742 | SL_ENTER(_("sh_hash_pushdata_memory"));
|
---|
| 1743 |
|
---|
| 1744 | p = sh_hash_push_int(theFile, fileHash);
|
---|
| 1745 | if (p)
|
---|
| 1746 | {
|
---|
[149] | 1747 | SH_MUTEX_LOCK(mutex_hash);
|
---|
[481] | 1748 | hashinsert (tab, p);
|
---|
| 1749 | p->modi_mask = theFile->check_flags;
|
---|
[149] | 1750 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
[1] | 1751 | }
|
---|
| 1752 |
|
---|
| 1753 | SL_RET0(_("sh_hash_pushdata_memory"));
|
---|
| 1754 | }
|
---|
| 1755 |
|
---|
[481] | 1756 | int sh_hash_is_null_file(file_type * theFile)
|
---|
| 1757 | {
|
---|
| 1758 | if (theFile->hardlinks == SH_DEADFILE && theFile->mode == 0 &&
|
---|
| 1759 | theFile->ino == 0 && theFile->ctime == 0)
|
---|
| 1760 | {
|
---|
| 1761 | return S_TRUE;
|
---|
| 1762 | }
|
---|
| 1763 | return S_FALSE;
|
---|
| 1764 | }
|
---|
[1] | 1765 |
|
---|
[481] | 1766 | int sh_hash_is_null_record(sh_filestore_t * theFile)
|
---|
| 1767 | {
|
---|
| 1768 | if (theFile->hardlinks == SH_DEADFILE && theFile->mode == 0 &&
|
---|
| 1769 | theFile->ino == 0 && theFile->ctime == 0)
|
---|
| 1770 | {
|
---|
| 1771 | return S_TRUE;
|
---|
| 1772 | }
|
---|
| 1773 | return S_FALSE;
|
---|
| 1774 | }
|
---|
| 1775 |
|
---|
| 1776 | void sh_hash_insert_null(char * str)
|
---|
| 1777 | {
|
---|
| 1778 | file_type theFile = { 0, 0, {'\0'}, 0, 0, 0, 0, 0,
|
---|
| 1779 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
| 1780 | 0, {'\0'},
|
---|
| 1781 | #endif
|
---|
| 1782 | {'\0'}, 0, {'\0'}, 0, {'\0'},
|
---|
| 1783 | 0, 0, 0, 0, 0, 0, 0, NULL, 0, {'\0'}, 0, NULL
|
---|
| 1784 | }; /* clang compiler bails out on standard conforming init with just {0} */
|
---|
| 1785 | char fileHash[KEY_LEN+1];
|
---|
| 1786 | char hashbuf[KEYBUF_SIZE];
|
---|
| 1787 |
|
---|
| 1788 | sl_strlcpy(fileHash, SH_KEY_NULL, sizeof(fileHash));
|
---|
| 1789 | theFile.hardlinks = SH_DEADFILE;
|
---|
| 1790 |
|
---|
| 1791 | if (sl_strlen(str) < PATH_MAX)
|
---|
| 1792 | sl_strlcpy(theFile.fullpath, str, PATH_MAX);
|
---|
| 1793 | else
|
---|
| 1794 | sl_strlcpy(theFile.fullpath,
|
---|
| 1795 | sh_tiger_hash(str, TIGER_DATA, sl_strlen(str),
|
---|
| 1796 | hashbuf, sizeof(hashbuf)),
|
---|
| 1797 | PATH_MAX);
|
---|
| 1798 |
|
---|
| 1799 | sh_hash_pushdata_memory(&theFile, fileHash);
|
---|
| 1800 | return;
|
---|
| 1801 | }
|
---|
| 1802 |
|
---|
| 1803 | static int handle_notfound(int log_severity, int class,
|
---|
| 1804 | file_type * theFile, char * fileHash)
|
---|
| 1805 | {
|
---|
| 1806 | sh_file_t * p;
|
---|
| 1807 | int retval = 0;
|
---|
| 1808 |
|
---|
| 1809 | if (S_FALSE == sh_ignore_chk_new(theFile->fullpath))
|
---|
| 1810 | {
|
---|
| 1811 | char * tmp = sh_util_safe_name(theFile->fullpath);
|
---|
| 1812 | char * str;
|
---|
| 1813 |
|
---|
| 1814 | sh_files_fixup_mask(class, &(theFile->check_flags));
|
---|
| 1815 | str = all_items (theFile, fileHash, 1);
|
---|
| 1816 |
|
---|
[488] | 1817 | if (!sh_global_check_silent)
|
---|
| 1818 | sh_error_handle (log_severity, FIL__, __LINE__, 0,
|
---|
| 1819 | MSG_FI_ADD2,
|
---|
| 1820 | tmp, str);
|
---|
[481] | 1821 | ++sh.statistics.files_report;
|
---|
| 1822 | SH_FREE(str);
|
---|
| 1823 | SH_FREE(tmp);
|
---|
| 1824 | }
|
---|
| 1825 |
|
---|
| 1826 | if (sh.flag.reportonce == S_TRUE)
|
---|
| 1827 | SET_SH_FFLAG_REPORTED(theFile->file_reported);
|
---|
| 1828 |
|
---|
| 1829 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 1830 | {
|
---|
| 1831 | p = sh_hash_push_int(theFile, fileHash);
|
---|
| 1832 | if (p)
|
---|
| 1833 | {
|
---|
| 1834 | hashinsert (tab, p);
|
---|
| 1835 | p->modi_mask = theFile->check_flags;
|
---|
| 1836 | p->theFile.checkflags = p->modi_mask;
|
---|
| 1837 | }
|
---|
| 1838 | }
|
---|
| 1839 |
|
---|
| 1840 | else if (S_TRUE == sh.flag.update)
|
---|
| 1841 | {
|
---|
| 1842 | if (S_TRUE == sh_util_ask_update (theFile->fullpath))
|
---|
| 1843 | {
|
---|
| 1844 | p = sh_hash_push_int(theFile, fileHash);
|
---|
| 1845 | if (p)
|
---|
| 1846 | {
|
---|
| 1847 | hashinsert (tab, p);
|
---|
| 1848 | p->modi_mask = theFile->check_flags;
|
---|
| 1849 | p->theFile.checkflags = p->modi_mask;
|
---|
| 1850 | }
|
---|
| 1851 | }
|
---|
| 1852 | else
|
---|
| 1853 | retval = 1;
|
---|
| 1854 | }
|
---|
| 1855 | return retval;
|
---|
| 1856 | }
|
---|
| 1857 |
|
---|
[1] | 1858 | /*****************************************************************
|
---|
| 1859 | *
|
---|
| 1860 | * Compare a file with the database status.
|
---|
| 1861 | *
|
---|
| 1862 | *****************************************************************/
|
---|
| 1863 | int sh_hash_compdata (int class, file_type * theFile, char * fileHash,
|
---|
| 1864 | char * policy_override, int severity_override)
|
---|
| 1865 | {
|
---|
| 1866 | char * msg;
|
---|
| 1867 | sh_file_t * p;
|
---|
| 1868 | char * tmp;
|
---|
| 1869 | char * tmp_path;
|
---|
| 1870 | char * tmp_lnk;
|
---|
| 1871 | char * tmp_lnk_old;
|
---|
| 1872 |
|
---|
| 1873 | char timstr1c[32];
|
---|
| 1874 | char timstr2c[32];
|
---|
| 1875 | char timstr1a[32];
|
---|
| 1876 | char timstr2a[32];
|
---|
| 1877 | char timstr1m[32];
|
---|
| 1878 | char timstr2m[32];
|
---|
| 1879 | char linkHash[KEY_LEN+1];
|
---|
[169] | 1880 | char * linkComp;
|
---|
[1] | 1881 | int maxcomp;
|
---|
| 1882 |
|
---|
| 1883 | char change_code[16];
|
---|
| 1884 | int i;
|
---|
| 1885 |
|
---|
[170] | 1886 | unsigned long modi_mask;
|
---|
[1] | 1887 |
|
---|
| 1888 | char log_policy[32];
|
---|
[153] | 1889 | volatile int log_severity;
|
---|
[133] | 1890 | char hashbuf[KEYBUF_SIZE];
|
---|
[481] | 1891 | struct {
|
---|
| 1892 | unsigned long oldflags;
|
---|
| 1893 | unsigned long newflags;
|
---|
| 1894 | } cf_report;
|
---|
[1] | 1895 |
|
---|
[170] | 1896 | int retval;
|
---|
[149] | 1897 |
|
---|
[1] | 1898 | SL_ENTER(_("sh_hash_compdata"));
|
---|
| 1899 |
|
---|
| 1900 | if (IsInit != 1) sh_hash_init();
|
---|
| 1901 |
|
---|
| 1902 | if (severity_override < 0)
|
---|
| 1903 | log_severity = ShDFLevel[class];
|
---|
| 1904 | else
|
---|
| 1905 | log_severity = severity_override;
|
---|
| 1906 |
|
---|
| 1907 | if (policy_override != NULL)
|
---|
| 1908 | sl_strlcpy (log_policy, policy_override, 32);
|
---|
| 1909 |
|
---|
| 1910 | /* -------- find the entry for the file ---------------- */
|
---|
| 1911 |
|
---|
[149] | 1912 | SH_MUTEX_LOCK(mutex_hash);
|
---|
| 1913 |
|
---|
[170] | 1914 | modi_mask = 0;
|
---|
| 1915 | retval = 0;
|
---|
| 1916 |
|
---|
[1] | 1917 | if (sl_strlen(theFile->fullpath) <= MAX_PATH_STORE)
|
---|
| 1918 | p = hashsearch(theFile->fullpath);
|
---|
| 1919 | else
|
---|
| 1920 | p = hashsearch( sh_tiger_hash(theFile->fullpath,
|
---|
| 1921 | TIGER_DATA,
|
---|
[133] | 1922 | sl_strlen(theFile->fullpath),
|
---|
| 1923 | hashbuf, sizeof(hashbuf))
|
---|
[1] | 1924 | );
|
---|
| 1925 |
|
---|
| 1926 |
|
---|
| 1927 | /* --------- Not found in database. ------------
|
---|
| 1928 | */
|
---|
| 1929 |
|
---|
| 1930 | if (p == NULL)
|
---|
| 1931 | {
|
---|
[481] | 1932 | retval = handle_notfound(log_severity, class, theFile, fileHash);
|
---|
[149] | 1933 | goto unlock_and_return;
|
---|
[1] | 1934 | }
|
---|
| 1935 |
|
---|
[425] | 1936 | /* --------- Skip if we don't want to report changes. ------------
|
---|
| 1937 | */
|
---|
| 1938 |
|
---|
| 1939 | if (S_TRUE == sh_ignore_chk_mod(theFile->fullpath))
|
---|
| 1940 | {
|
---|
[481] | 1941 | MODI_SET(theFile->check_flags, MODI_NOCHECK);
|
---|
| 1942 | p->modi_mask = theFile->check_flags;
|
---|
| 1943 | p->theFile.checkflags = p->modi_mask;
|
---|
[425] | 1944 | goto unlock_and_return;
|
---|
| 1945 | }
|
---|
| 1946 |
|
---|
[481] | 1947 | cf_report.oldflags = p->theFile.checkflags;
|
---|
| 1948 | cf_report.newflags = theFile->check_flags;
|
---|
[149] | 1949 |
|
---|
[481] | 1950 | p->modi_mask = theFile->check_flags;
|
---|
| 1951 | p->theFile.checkflags = p->modi_mask;
|
---|
| 1952 |
|
---|
[1] | 1953 | /* initialize change_code */
|
---|
| 1954 | for (i = 0; i < 15; ++i)
|
---|
| 1955 | change_code[i] = '-';
|
---|
| 1956 | change_code[15] = '\0';
|
---|
| 1957 |
|
---|
| 1958 | TPT ((0, FIL__, __LINE__, _("file=<%s>, cs_old=<%s>, cs_new=<%s>\n"),
|
---|
| 1959 | theFile->fullpath, fileHash, p->theFile.checksum));
|
---|
| 1960 |
|
---|
[474] | 1961 | if ( (fileHash != NULL) &&
|
---|
[19] | 1962 | (strncmp (fileHash, p->theFile.checksum, KEY_LEN) != 0) &&
|
---|
[481] | 1963 | (theFile->check_flags & MODI_CHK) != 0)
|
---|
[1] | 1964 | {
|
---|
[481] | 1965 | if ((theFile->check_flags & MODI_SGROW) == 0)
|
---|
[19] | 1966 | {
|
---|
| 1967 | modi_mask |= MODI_CHK;
|
---|
| 1968 | change_code[0] = 'C';
|
---|
| 1969 | TPT ((0, FIL__, __LINE__, _("mod=<checksum>")));
|
---|
| 1970 | }
|
---|
| 1971 | else
|
---|
| 1972 | {
|
---|
[425] | 1973 | if (0 != strncmp (&fileHash[KEY_LEN + 1], p->theFile.checksum, KEY_LEN))
|
---|
[19] | 1974 | {
|
---|
[425] | 1975 | if (S_FALSE == sh_check_rotated_log (theFile->fullpath, (UINT64) p->theFile.size,
|
---|
[481] | 1976 | (UINT64) p->theFile.ino, p->theFile.checksum,
|
---|
| 1977 | p->theFile.checkflags))
|
---|
[425] | 1978 | {
|
---|
| 1979 | modi_mask |= MODI_CHK;
|
---|
| 1980 | change_code[0] = 'C';
|
---|
| 1981 | TPT ((0, FIL__, __LINE__, _("mod=<checksum>")));
|
---|
| 1982 | }
|
---|
| 1983 | else
|
---|
| 1984 | {
|
---|
| 1985 | /* logfile has been rotated */
|
---|
| 1986 | p->theFile.size = theFile->size;
|
---|
| 1987 | p->theFile.ino = theFile->ino;
|
---|
| 1988 | sl_strlcpy(p->theFile.checksum, fileHash, KEY_LEN+1);
|
---|
| 1989 | }
|
---|
[19] | 1990 | }
|
---|
| 1991 | else
|
---|
| 1992 | {
|
---|
| 1993 | p->theFile.size = theFile->size;
|
---|
| 1994 | sl_strlcpy(p->theFile.checksum, fileHash, KEY_LEN+1);
|
---|
| 1995 | }
|
---|
| 1996 | }
|
---|
[1] | 1997 | }
|
---|
| 1998 |
|
---|
| 1999 | if (p->theFile.c_mode[0] == 'l')
|
---|
| 2000 | {
|
---|
[169] | 2001 | if (!(theFile->link_path) &&
|
---|
[481] | 2002 | (theFile->check_flags & MODI_LNK) != 0)
|
---|
[1] | 2003 | {
|
---|
[169] | 2004 | linkComp = NULL;
|
---|
[93] | 2005 | modi_mask |= MODI_LNK;
|
---|
| 2006 | change_code[1] = 'L';
|
---|
| 2007 | TPT ((0, FIL__, __LINE__, _("mod=<link>")));
|
---|
[169] | 2008 | }
|
---|
| 2009 | else
|
---|
| 2010 | {
|
---|
| 2011 | if (sl_strlen(theFile->link_path) >= MAX_PATH_STORE)
|
---|
| 2012 | {
|
---|
| 2013 | sl_strlcpy(linkHash,
|
---|
| 2014 | sh_tiger_hash(theFile->link_path,
|
---|
| 2015 | TIGER_DATA,
|
---|
| 2016 | sl_strlen(theFile->link_path),
|
---|
| 2017 | hashbuf, sizeof(hashbuf)),
|
---|
| 2018 | MAX_PATH_STORE+1);
|
---|
| 2019 | linkComp = linkHash;
|
---|
| 2020 | maxcomp = KEY_LEN;
|
---|
| 2021 | }
|
---|
| 2022 | else
|
---|
| 2023 | {
|
---|
| 2024 | linkComp = theFile->link_path;
|
---|
| 2025 | maxcomp = MAX_PATH_STORE;
|
---|
| 2026 | }
|
---|
| 2027 |
|
---|
| 2028 | if ( sl_strncmp (linkComp, p->linkpath, maxcomp) != 0 &&
|
---|
[481] | 2029 | (theFile->check_flags & MODI_LNK) != 0)
|
---|
[169] | 2030 | {
|
---|
| 2031 | modi_mask |= MODI_LNK;
|
---|
| 2032 | change_code[1] = 'L';
|
---|
| 2033 | TPT ((0, FIL__, __LINE__, _("mod=<link>")));
|
---|
| 2034 | }
|
---|
| 2035 | }
|
---|
[1] | 2036 | }
|
---|
| 2037 |
|
---|
| 2038 | if (p->theFile.c_mode[0] == 'c' || p->theFile.c_mode[0] == 'b')
|
---|
| 2039 | {
|
---|
| 2040 | if ( ( major(theFile->rdev) != major((dev_t)p->theFile.rdev) ||
|
---|
| 2041 | minor(theFile->rdev) != minor((dev_t)p->theFile.rdev) ) &&
|
---|
[481] | 2042 | (theFile->check_flags & MODI_RDEV) != 0)
|
---|
[1] | 2043 | {
|
---|
| 2044 | modi_mask |= MODI_RDEV;
|
---|
| 2045 | change_code[2] = 'D';
|
---|
| 2046 | TPT ((0, FIL__, __LINE__, _("mod=<rdev>")));
|
---|
| 2047 | }
|
---|
| 2048 | }
|
---|
| 2049 |
|
---|
| 2050 | /* cast to UINT32 in case ino_t is not 32bit
|
---|
| 2051 | */
|
---|
| 2052 | if ( (UINT32) theFile->ino != (UINT32) p->theFile.ino &&
|
---|
[481] | 2053 | (theFile->check_flags & MODI_INO) != 0)
|
---|
[1] | 2054 | {
|
---|
| 2055 | modi_mask |= MODI_INO;
|
---|
| 2056 | change_code[3] = 'I';
|
---|
| 2057 | TPT ((0, FIL__, __LINE__, _("mod=<inode>")));
|
---|
| 2058 | }
|
---|
| 2059 |
|
---|
| 2060 | if ( theFile->hardlinks != (nlink_t) p->theFile.hardlinks &&
|
---|
[481] | 2061 | (theFile->check_flags & MODI_HLN) != 0)
|
---|
[1] | 2062 | {
|
---|
| 2063 | modi_mask |= MODI_HLN;
|
---|
| 2064 | change_code[4] = 'H';
|
---|
| 2065 | TPT ((0, FIL__, __LINE__, _("mod=<hardlink>")));
|
---|
| 2066 | }
|
---|
| 2067 |
|
---|
| 2068 |
|
---|
| 2069 | if ( ( (theFile->mode != p->theFile.mode)
|
---|
[68] | 2070 | #if defined(USE_ACL) || defined(USE_XATTR)
|
---|
| 2071 | || ( (sh_unix_check_selinux|sh_unix_check_acl) &&
|
---|
| 2072 | (
|
---|
| 2073 | (theFile->attr_string == NULL && p->attr_string != NULL) ||
|
---|
| 2074 | (theFile->attr_string != NULL && p->attr_string == NULL) ||
|
---|
| 2075 | (theFile->attr_string != NULL && 0 != strcmp(theFile->attr_string, p->attr_string))
|
---|
| 2076 | )
|
---|
| 2077 | )
|
---|
| 2078 | #endif
|
---|
[10] | 2079 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 2080 | || (theFile->attributes != p->theFile.attributes)
|
---|
| 2081 | #endif
|
---|
[68] | 2082 | )
|
---|
[481] | 2083 | && (theFile->check_flags & MODI_MOD) != 0)
|
---|
[1] | 2084 | {
|
---|
| 2085 | modi_mask |= MODI_MOD;
|
---|
| 2086 | change_code[5] = 'M';
|
---|
| 2087 | TPT ((0, FIL__, __LINE__, _("mod=<mode>")));
|
---|
| 2088 | /*
|
---|
| 2089 | * report link path if switch link/no link
|
---|
| 2090 | */
|
---|
[481] | 2091 | if ((theFile->check_flags & MODI_LNK) != 0 &&
|
---|
[1] | 2092 | (theFile->c_mode[0] != p->theFile.c_mode[0]) &&
|
---|
| 2093 | (theFile->c_mode[0] == 'l' || p->theFile.c_mode[0] == 'l'))
|
---|
| 2094 | {
|
---|
| 2095 | modi_mask |= MODI_LNK;
|
---|
| 2096 | change_code[1] = 'L';
|
---|
| 2097 | TPT ((0, FIL__, __LINE__, _("mod=<link>")));
|
---|
| 2098 | }
|
---|
| 2099 | }
|
---|
| 2100 |
|
---|
| 2101 | if ( theFile->owner != (uid_t) p->theFile.owner &&
|
---|
[481] | 2102 | (theFile->check_flags & MODI_USR) != 0)
|
---|
[1] | 2103 | {
|
---|
| 2104 | modi_mask |= MODI_USR;
|
---|
| 2105 | change_code[6] = 'U';
|
---|
| 2106 | TPT ((0, FIL__, __LINE__, _("mod=<user>")));
|
---|
| 2107 | }
|
---|
| 2108 |
|
---|
| 2109 | if ( theFile->group != (gid_t) p->theFile.group &&
|
---|
[481] | 2110 | (theFile->check_flags & MODI_GRP) != 0)
|
---|
[1] | 2111 | {
|
---|
| 2112 | modi_mask |= MODI_GRP;
|
---|
| 2113 | change_code[7] = 'G';
|
---|
| 2114 | TPT ((0, FIL__, __LINE__, _("mod=<group>")));
|
---|
| 2115 | }
|
---|
| 2116 |
|
---|
| 2117 |
|
---|
| 2118 | if ( theFile->mtime != (time_t) p->theFile.mtime &&
|
---|
[481] | 2119 | (theFile->check_flags & MODI_MTM) != 0)
|
---|
[1] | 2120 | {
|
---|
| 2121 | modi_mask |= MODI_MTM;
|
---|
| 2122 | change_code[8] = 'T';
|
---|
| 2123 | TPT ((0, FIL__, __LINE__, _("mod=<mtime>")));
|
---|
| 2124 | }
|
---|
| 2125 |
|
---|
[481] | 2126 | if ( (theFile->check_flags & MODI_ATM) != 0 &&
|
---|
[68] | 2127 | theFile->atime != (time_t) p->theFile.atime)
|
---|
[1] | 2128 | {
|
---|
| 2129 | modi_mask |= MODI_ATM;
|
---|
| 2130 | change_code[8] = 'T';
|
---|
| 2131 | TPT ((0, FIL__, __LINE__, _("mod=<atime>")));
|
---|
| 2132 | }
|
---|
| 2133 |
|
---|
| 2134 |
|
---|
| 2135 | /* Resetting the access time will set a new ctime. Thus, either we ignore
|
---|
| 2136 | * the access time or the ctime for NOIGNORE
|
---|
| 2137 | */
|
---|
| 2138 | if ( theFile->ctime != (time_t) p->theFile.ctime &&
|
---|
[481] | 2139 | (theFile->check_flags & MODI_CTM) != 0)
|
---|
[1] | 2140 | {
|
---|
| 2141 | modi_mask |= MODI_CTM;
|
---|
| 2142 | change_code[8] = 'T';
|
---|
| 2143 | TPT ((0, FIL__, __LINE__, _("mod=<ctime>")));
|
---|
| 2144 | }
|
---|
| 2145 |
|
---|
| 2146 | if ( theFile->size != (off_t) p->theFile.size &&
|
---|
[481] | 2147 | (theFile->check_flags & MODI_SIZ) != 0)
|
---|
[1] | 2148 | {
|
---|
[481] | 2149 | if ((theFile->check_flags & MODI_SGROW) == 0 ||
|
---|
[19] | 2150 | theFile->size < (off_t) p->theFile.size)
|
---|
[1] | 2151 | {
|
---|
| 2152 | modi_mask |= MODI_SIZ;
|
---|
| 2153 | change_code[9] = 'S';
|
---|
| 2154 | TPT ((0, FIL__, __LINE__, _("mod=<size>")));
|
---|
[19] | 2155 | }
|
---|
[1] | 2156 | }
|
---|
| 2157 | change_code[10] = '\0';
|
---|
| 2158 |
|
---|
[205] | 2159 | /* --- Directories special case ---
|
---|
| 2160 | */
|
---|
| 2161 | if (p->theFile.c_mode[0] == 'd' &&
|
---|
| 2162 | 0 == (modi_mask & ~(MODI_SIZ|MODI_ATM|MODI_CTM|MODI_MTM)) &&
|
---|
| 2163 | sh_loosedircheck == S_TRUE)
|
---|
| 2164 | {
|
---|
| 2165 | modi_mask = 0;
|
---|
| 2166 | }
|
---|
| 2167 |
|
---|
[1] | 2168 | /* --- Report full details. ---
|
---|
| 2169 | */
|
---|
| 2170 | if (modi_mask != 0 && sh.flag.fulldetail == S_TRUE)
|
---|
| 2171 | {
|
---|
[481] | 2172 | if ((theFile->check_flags & MODI_ATM) == 0)
|
---|
[1] | 2173 | modi_mask = MASK_READONLY_;
|
---|
| 2174 | else
|
---|
| 2175 | modi_mask = MASK_NOIGNORE_;
|
---|
| 2176 | }
|
---|
| 2177 |
|
---|
| 2178 | /* --- Report on modified files. ---
|
---|
| 2179 | */
|
---|
[114] | 2180 | if (modi_mask != 0 && (!SH_FFLAG_REPORTED_SET(p->fflags)))
|
---|
[1] | 2181 | {
|
---|
[170] | 2182 | tmp = SH_ALLOC(SH_MSG_BUF);
|
---|
| 2183 | msg = SH_ALLOC(SH_MSG_BUF);
|
---|
[1] | 2184 | msg[0] = '\0';
|
---|
| 2185 |
|
---|
[481] | 2186 | sh_files_fixup_mask(class, &(cf_report.newflags));
|
---|
| 2187 |
|
---|
| 2188 | if ( (report_checkflags != S_FALSE) && (cf_report.oldflags != cf_report.newflags))
|
---|
| 2189 | {
|
---|
| 2190 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
| 2191 | #ifdef SH_USE_XML
|
---|
| 2192 | _("checkflags_old=\"0%lo\" checkflags_new=\"0%lo\" "),
|
---|
| 2193 | #else
|
---|
| 2194 | _("checkflags_old=<0%lo>, checkflags_new=<0%lo>, "),
|
---|
| 2195 | #endif
|
---|
| 2196 | cf_report.oldflags, cf_report.newflags);
|
---|
| 2197 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
| 2198 | }
|
---|
| 2199 |
|
---|
[1] | 2200 | if ( ((modi_mask & MODI_MOD) != 0)
|
---|
[181] | 2201 | #if defined(HAVE_LIBPRELUDE)
|
---|
[68] | 2202 | || ((modi_mask & MODI_USR) != 0)
|
---|
| 2203 | || ((modi_mask & MODI_GRP) != 0)
|
---|
[1] | 2204 | #endif
|
---|
| 2205 | )
|
---|
| 2206 | {
|
---|
[10] | 2207 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[170] | 2208 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2209 | #ifdef SH_USE_XML
|
---|
| 2210 | _("mode_old=\"%s\" mode_new=\"%s\" attr_old=\"%s\" attr_new=\"%s\" imode_old=\"%ld\" imode_new=\"%ld\" iattr_old=\"%ld\" iattr_new=\"%ld\" "),
|
---|
| 2211 | #else
|
---|
| 2212 | _("mode_old=<%s>, mode_new=<%s>, attr_old=<%s>, attr_new=<%s>, "),
|
---|
| 2213 | #endif
|
---|
| 2214 | p->theFile.c_mode, theFile->c_mode,
|
---|
| 2215 | p->theFile.c_attributes, theFile->c_attributes
|
---|
| 2216 | #ifdef SH_USE_XML
|
---|
| 2217 | , (long) p->theFile.mode, (long) theFile->mode,
|
---|
| 2218 | (long) p->theFile.attributes,
|
---|
| 2219 | (long) theFile->attributes
|
---|
| 2220 | #endif
|
---|
| 2221 | );
|
---|
| 2222 | #else
|
---|
| 2223 | #ifdef SH_USE_XML
|
---|
[170] | 2224 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2225 | _("mode_old=\"%s\" mode_new=\"%s\" imode_old=\"%ld\" imode_new=\"%ld\" "),
|
---|
[68] | 2226 | p->theFile.c_mode, theFile->c_mode,
|
---|
| 2227 | (long) p->theFile.mode, (long) theFile->mode);
|
---|
[1] | 2228 | #else
|
---|
[170] | 2229 | sl_snprintf(tmp, SH_MSG_BUF, _("mode_old=<%s>, mode_new=<%s>, "),
|
---|
[68] | 2230 | p->theFile.c_mode, theFile->c_mode);
|
---|
[1] | 2231 | #endif
|
---|
[68] | 2232 | #endif
|
---|
[170] | 2233 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[68] | 2234 |
|
---|
| 2235 | #if defined(USE_ACL) || defined(USE_XATTR)
|
---|
| 2236 | if (theFile->attr_string != NULL || p->attr_string != NULL)
|
---|
| 2237 | {
|
---|
[170] | 2238 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2239 | #ifdef SH_USE_XML
|
---|
[68] | 2240 | _("acl_old=\"%s\" acl_new=\"%s\" "),
|
---|
| 2241 | #else
|
---|
| 2242 | _("acl_old=<%s>, acl_new=<%s>, "),
|
---|
[1] | 2243 | #endif
|
---|
[68] | 2244 | (p->attr_string) ? p->attr_string : _("none"),
|
---|
| 2245 | (theFile->attr_string) ? theFile->attr_string : _("none"));
|
---|
| 2246 |
|
---|
[170] | 2247 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[68] | 2248 | }
|
---|
[1] | 2249 | #endif
|
---|
[68] | 2250 |
|
---|
[1] | 2251 | if ((modi_mask & MODI_MOD) != 0)
|
---|
| 2252 | {
|
---|
| 2253 | /*
|
---|
| 2254 | * We postpone update if sh.flag.update == S_TRUE because
|
---|
| 2255 | * in interactive mode the user may not accept the change.
|
---|
| 2256 | */
|
---|
| 2257 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2258 | {
|
---|
| 2259 | sl_strlcpy(p->theFile.c_mode, theFile->c_mode, 11);
|
---|
| 2260 | p->theFile.mode = theFile->mode;
|
---|
[10] | 2261 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 2262 | sl_strlcpy(p->theFile.c_attributes,theFile->c_attributes,16);
|
---|
| 2263 | p->theFile.attributes = theFile->attributes;
|
---|
| 2264 | #endif
|
---|
[68] | 2265 | #if defined(USE_ACL) || defined(USE_XATTR)
|
---|
| 2266 | if (p->attr_string == NULL && theFile->attr_string != NULL)
|
---|
| 2267 | { p->attr_string = sh_util_strdup (theFile->attr_string); }
|
---|
| 2268 | else if (p->attr_string != NULL && theFile->attr_string == NULL)
|
---|
| 2269 | { SH_FREE(p->attr_string); p->attr_string = NULL; }
|
---|
| 2270 | else if (theFile->attr_string != NULL && p->attr_string != NULL)
|
---|
| 2271 | {
|
---|
| 2272 | if (0 != strcmp(theFile->attr_string, p->attr_string))
|
---|
| 2273 | {
|
---|
| 2274 | SH_FREE(p->attr_string);
|
---|
| 2275 | p->attr_string = sh_util_strdup (theFile->attr_string);
|
---|
| 2276 | }
|
---|
| 2277 | }
|
---|
| 2278 | #endif
|
---|
[1] | 2279 | }
|
---|
| 2280 | }
|
---|
[481] | 2281 |
|
---|
[1] | 2282 | }
|
---|
| 2283 |
|
---|
| 2284 | if ((modi_mask & MODI_HLN) != 0)
|
---|
| 2285 | {
|
---|
[170] | 2286 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2287 | #ifdef SH_USE_XML
|
---|
[40] | 2288 | _("hardlinks_old=\"%lu\" hardlinks_new=\"%lu\" "),
|
---|
[1] | 2289 | #else
|
---|
[40] | 2290 | _("hardlinks_old=<%lu>, hardlinks_new=<%lu>, "),
|
---|
[1] | 2291 | #endif
|
---|
| 2292 | (unsigned long) p->theFile.hardlinks,
|
---|
| 2293 | (unsigned long) theFile->hardlinks);
|
---|
[170] | 2294 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2295 |
|
---|
[1] | 2296 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2297 | p->theFile.hardlinks = theFile->hardlinks;
|
---|
| 2298 | }
|
---|
| 2299 |
|
---|
| 2300 | if ((modi_mask & MODI_RDEV) != 0)
|
---|
| 2301 | {
|
---|
[170] | 2302 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2303 | #ifdef SH_USE_XML
|
---|
[40] | 2304 | _("device_old=\"%lu,%lu\" device_new=\"%lu,%lu\" idevice_old=\"%lu\" idevice_new=\"%lu\" "),
|
---|
[1] | 2305 | #else
|
---|
[40] | 2306 | _("device_old=<%lu,%lu>, device_new=<%lu,%lu>, "),
|
---|
[1] | 2307 | #endif
|
---|
| 2308 | (unsigned long) major(p->theFile.rdev),
|
---|
| 2309 | (unsigned long) minor(p->theFile.rdev),
|
---|
| 2310 | (unsigned long) major(theFile->rdev),
|
---|
| 2311 | (unsigned long) minor(theFile->rdev)
|
---|
| 2312 | #ifdef SH_USE_XML
|
---|
| 2313 | , (unsigned long) p->theFile.rdev,
|
---|
| 2314 | (unsigned long) theFile->rdev
|
---|
| 2315 | #endif
|
---|
| 2316 | );
|
---|
[170] | 2317 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2318 |
|
---|
[1] | 2319 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2320 | p->theFile.rdev = theFile->rdev;
|
---|
| 2321 | }
|
---|
| 2322 |
|
---|
| 2323 | if ((modi_mask & MODI_INO) != 0)
|
---|
| 2324 | {
|
---|
[170] | 2325 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2326 | #ifdef SH_USE_XML
|
---|
[40] | 2327 | _("inode_old=\"%lu\" inode_new=\"%lu\" "),
|
---|
[1] | 2328 | #else
|
---|
[40] | 2329 | _("inode_old=<%lu>, inode_new=<%lu>, "),
|
---|
[1] | 2330 | #endif
|
---|
| 2331 | (unsigned long) p->theFile.ino,
|
---|
| 2332 | (unsigned long) theFile->ino);
|
---|
[170] | 2333 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2334 |
|
---|
[1] | 2335 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
[40] | 2336 | {
|
---|
| 2337 | p->theFile.ino = theFile->ino;
|
---|
| 2338 | p->theFile.dev = theFile->dev;
|
---|
| 2339 | }
|
---|
[1] | 2340 | }
|
---|
| 2341 |
|
---|
[40] | 2342 |
|
---|
| 2343 | /*
|
---|
| 2344 | * also report device for prelude
|
---|
| 2345 | */
|
---|
[181] | 2346 | #if defined(HAVE_LIBPRELUDE)
|
---|
[40] | 2347 | if ((modi_mask & MODI_INO) != 0)
|
---|
| 2348 | {
|
---|
[170] | 2349 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[40] | 2350 | #ifdef SH_USE_XML
|
---|
| 2351 | _("dev_old=\"%lu,%lu\" dev_new=\"%lu,%lu\" "),
|
---|
| 2352 | #else
|
---|
| 2353 | _("dev_old=<%lu,%lu>, dev_new=<%lu,%lu>, "),
|
---|
| 2354 | #endif
|
---|
| 2355 | (unsigned long) major(p->theFile.dev),
|
---|
| 2356 | (unsigned long) minor(p->theFile.dev),
|
---|
| 2357 | (unsigned long) major(theFile->dev),
|
---|
| 2358 | (unsigned long) minor(theFile->dev)
|
---|
| 2359 | );
|
---|
[170] | 2360 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2361 |
|
---|
[40] | 2362 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2363 | p->theFile.dev = theFile->dev;
|
---|
| 2364 | }
|
---|
| 2365 | #endif
|
---|
| 2366 |
|
---|
[1] | 2367 | if ( ((modi_mask & MODI_USR) != 0)
|
---|
[181] | 2368 | #if defined(HAVE_LIBPRELUDE)
|
---|
[1] | 2369 | || ((modi_mask & MODI_MOD) != 0)
|
---|
| 2370 | #endif
|
---|
| 2371 | )
|
---|
| 2372 | {
|
---|
| 2373 | #ifdef SH_USE_XML
|
---|
[170] | 2374 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[40] | 2375 | _("owner_old=\"%s\" owner_new=\"%s\" iowner_old=\"%ld\" iowner_new=\"%ld\" "),
|
---|
[1] | 2376 | #else
|
---|
[170] | 2377 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[40] | 2378 | _("owner_old=<%s>, owner_new=<%s>, iowner_old=<%ld>, iowner_new=<%ld>, "),
|
---|
[1] | 2379 | #endif
|
---|
[40] | 2380 | p->theFile.c_owner, theFile->c_owner,
|
---|
| 2381 | (long) p->theFile.owner, (long) theFile->owner
|
---|
[1] | 2382 | );
|
---|
[170] | 2383 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2384 |
|
---|
[1] | 2385 | if ((modi_mask & MODI_USR) != 0) {
|
---|
| 2386 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2387 | {
|
---|
| 2388 | sl_strlcpy(p->theFile.c_owner, theFile->c_owner, USER_MAX+2);
|
---|
| 2389 | p->theFile.owner = theFile->owner;
|
---|
| 2390 | }
|
---|
| 2391 | }
|
---|
| 2392 | }
|
---|
| 2393 |
|
---|
| 2394 | if ( ((modi_mask & MODI_GRP) != 0)
|
---|
[181] | 2395 | #if defined(HAVE_LIBPRELUDE)
|
---|
[1] | 2396 | || ((modi_mask & MODI_MOD) != 0)
|
---|
| 2397 | #endif
|
---|
| 2398 | )
|
---|
| 2399 | {
|
---|
| 2400 | #ifdef SH_USE_XML
|
---|
[170] | 2401 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[40] | 2402 | _("group_old=\"%s\" group_new=\"%s\" igroup_old=\"%ld\" igroup_new=\"%ld\" "),
|
---|
[1] | 2403 | p->theFile.c_group, theFile->c_group,
|
---|
| 2404 | (long) p->theFile.group, (long) theFile->group);
|
---|
| 2405 | #else
|
---|
[170] | 2406 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[40] | 2407 | _("group_old=<%s>, group_new=<%s>, igroup_old=<%ld>, igroup_new=<%ld>, "),
|
---|
| 2408 | p->theFile.c_group, theFile->c_group,
|
---|
| 2409 | (long) p->theFile.group, (long) theFile->group);
|
---|
[1] | 2410 | #endif
|
---|
| 2411 |
|
---|
[170] | 2412 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2413 |
|
---|
[1] | 2414 | if ((modi_mask & MODI_GRP) != 0) {
|
---|
| 2415 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2416 | {
|
---|
| 2417 | sl_strlcpy(p->theFile.c_group, theFile->c_group, GROUP_MAX+2);
|
---|
| 2418 | p->theFile.group = theFile->group;
|
---|
| 2419 | }
|
---|
| 2420 | }
|
---|
| 2421 | }
|
---|
| 2422 |
|
---|
| 2423 | if ((modi_mask & MODI_SIZ) != 0)
|
---|
| 2424 | {
|
---|
[170] | 2425 | sl_snprintf(tmp, SH_MSG_BUF, sh_hash_size_format(),
|
---|
[1] | 2426 | (UINT64) p->theFile.size,
|
---|
| 2427 | (UINT64) theFile->size);
|
---|
[170] | 2428 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2429 |
|
---|
[1] | 2430 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2431 | p->theFile.size = theFile->size;
|
---|
| 2432 | }
|
---|
| 2433 |
|
---|
| 2434 | if ((modi_mask & MODI_CTM) != 0)
|
---|
| 2435 | {
|
---|
[132] | 2436 | (void) sh_unix_gmttime (p->theFile.ctime, timstr1c, sizeof(timstr1c));
|
---|
| 2437 | (void) sh_unix_gmttime (theFile->ctime, timstr2c, sizeof(timstr2c));
|
---|
[1] | 2438 | #ifdef SH_USE_XML
|
---|
[170] | 2439 | sl_snprintf(tmp, SH_MSG_BUF, _("ctime_old=\"%s\" ctime_new=\"%s\" "),
|
---|
[1] | 2440 | timstr1c, timstr2c);
|
---|
| 2441 | #else
|
---|
[170] | 2442 | sl_snprintf(tmp, SH_MSG_BUF, _("ctime_old=<%s>, ctime_new=<%s>, "),
|
---|
[1] | 2443 | timstr1c, timstr2c);
|
---|
| 2444 | #endif
|
---|
[170] | 2445 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2446 |
|
---|
[1] | 2447 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2448 | p->theFile.ctime = theFile->ctime;
|
---|
| 2449 | }
|
---|
| 2450 |
|
---|
| 2451 | if ((modi_mask & MODI_ATM) != 0)
|
---|
| 2452 | {
|
---|
[132] | 2453 | (void) sh_unix_gmttime (p->theFile.atime, timstr1a, sizeof(timstr1a));
|
---|
| 2454 | (void) sh_unix_gmttime (theFile->atime, timstr2a, sizeof(timstr2a));
|
---|
[1] | 2455 | #ifdef SH_USE_XML
|
---|
[170] | 2456 | sl_snprintf(tmp, SH_MSG_BUF, _("atime_old=\"%s\" atime_new=\"%s\" "),
|
---|
[1] | 2457 | timstr1a, timstr2a);
|
---|
| 2458 | #else
|
---|
[170] | 2459 | sl_snprintf(tmp, SH_MSG_BUF, _("atime_old=<%s>, atime_new=<%s>, "),
|
---|
[1] | 2460 | timstr1a, timstr2a);
|
---|
| 2461 | #endif
|
---|
[170] | 2462 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2463 |
|
---|
[1] | 2464 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2465 | p->theFile.atime = theFile->atime;
|
---|
| 2466 | }
|
---|
| 2467 |
|
---|
| 2468 | if ((modi_mask & MODI_MTM) != 0)
|
---|
| 2469 | {
|
---|
[132] | 2470 | (void) sh_unix_gmttime (p->theFile.mtime, timstr1m, sizeof(timstr1m));
|
---|
| 2471 | (void) sh_unix_gmttime (theFile->mtime, timstr2m, sizeof(timstr2m));
|
---|
[1] | 2472 | #ifdef SH_USE_XML
|
---|
[170] | 2473 | sl_snprintf(tmp, SH_MSG_BUF, _("mtime_old=\"%s\" mtime_new=\"%s\" "),
|
---|
[1] | 2474 | timstr1m, timstr2m);
|
---|
| 2475 | #else
|
---|
[170] | 2476 | sl_snprintf(tmp, SH_MSG_BUF, _("mtime_old=<%s>, mtime_new=<%s>, "),
|
---|
[1] | 2477 | timstr1m, timstr2m);
|
---|
| 2478 | #endif
|
---|
[170] | 2479 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2480 |
|
---|
[1] | 2481 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2482 | p->theFile.mtime = theFile->mtime;
|
---|
| 2483 | }
|
---|
| 2484 |
|
---|
| 2485 |
|
---|
| 2486 | if ((modi_mask & MODI_CHK) != 0)
|
---|
| 2487 | {
|
---|
[170] | 2488 | sl_snprintf(tmp, SH_MSG_BUF,
|
---|
[1] | 2489 | #ifdef SH_USE_XML
|
---|
| 2490 | _("chksum_old=\"%s\" chksum_new=\"%s\" "),
|
---|
| 2491 | #else
|
---|
| 2492 | _("chksum_old=<%s>, chksum_new=<%s>, "),
|
---|
| 2493 | #endif
|
---|
| 2494 | p->theFile.checksum, fileHash);
|
---|
[170] | 2495 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2496 |
|
---|
[1] | 2497 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
[107] | 2498 | {
|
---|
| 2499 | sl_strlcpy(p->theFile.checksum, fileHash, KEY_LEN+1);
|
---|
[481] | 2500 | if ((theFile->check_flags & MODI_SGROW) != 0)
|
---|
[107] | 2501 | p->theFile.size = theFile->size;
|
---|
| 2502 | }
|
---|
[481] | 2503 |
|
---|
| 2504 |
|
---|
[169] | 2505 | if (theFile->c_mode[0] != 'l' && theFile->link_path &&
|
---|
| 2506 | strlen(theFile->link_path) > 2)
|
---|
| 2507 | modi_mask |= MODI_LNK;
|
---|
[1] | 2508 | }
|
---|
| 2509 |
|
---|
| 2510 |
|
---|
[169] | 2511 | if ((modi_mask & MODI_LNK) != 0 /* && theFile->c_mode[0] == 'l' */)
|
---|
[1] | 2512 | {
|
---|
[169] | 2513 | if (theFile->link_path)
|
---|
| 2514 | tmp_lnk = sh_util_safe_name(theFile->link_path);
|
---|
| 2515 | else
|
---|
| 2516 | tmp_lnk = sh_util_strdup("-");
|
---|
| 2517 | if (p->linkpath)
|
---|
| 2518 | tmp_lnk_old = sh_util_safe_name(p->linkpath);
|
---|
| 2519 | else
|
---|
| 2520 | tmp_lnk_old = sh_util_strdup("-");
|
---|
[1] | 2521 | #ifdef SH_USE_XML
|
---|
[170] | 2522 | sl_snprintf(tmp, SH_MSG_BUF, _("link_old=\"%s\" link_new=\"%s\" "),
|
---|
[1] | 2523 | tmp_lnk_old, tmp_lnk);
|
---|
| 2524 | #else
|
---|
[294] | 2525 | sl_snprintf(tmp, SH_MSG_BUF, _("link_old=<%s>, link_new=<%s>, "),
|
---|
[1] | 2526 | tmp_lnk_old, tmp_lnk);
|
---|
| 2527 | #endif
|
---|
| 2528 | SH_FREE(tmp_lnk);
|
---|
| 2529 | SH_FREE(tmp_lnk_old);
|
---|
[170] | 2530 | sl_strlcat(msg, tmp, SH_MSG_BUF);
|
---|
[481] | 2531 |
|
---|
[1] | 2532 | if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE)
|
---|
| 2533 | {
|
---|
[481] | 2534 | if (p->linkpath != NULL)
|
---|
[1] | 2535 | SH_FREE(p->linkpath);
|
---|
[481] | 2536 | if (!(theFile->link_path))
|
---|
| 2537 | p->linkpath = sh_util_strdup("-");
|
---|
[149] | 2538 | else
|
---|
[167] | 2539 | p->linkpath = sh_util_strdup(theFile->link_path);
|
---|
[1] | 2540 | }
|
---|
| 2541 | }
|
---|
| 2542 |
|
---|
[481] | 2543 | if (MODI_AUDIT_ENABLED(theFile->check_flags))
|
---|
[294] | 2544 | {
|
---|
| 2545 | char result[256];
|
---|
[488] | 2546 |
|
---|
| 2547 | sh_error_handle (SH_ERR_INFO, FIL__, __LINE__,
|
---|
| 2548 | 0, MSG_E_SUBGPATH,
|
---|
| 2549 | _("Fetching audit record"),
|
---|
| 2550 | _("sh_hash"), theFile->fullpath );
|
---|
[1] | 2551 |
|
---|
[488] | 2552 | if (NULL != sh_audit_fetch (theFile->fullpath, theFile->mtime, theFile->ctime, result, sizeof(result)))
|
---|
[294] | 2553 | {
|
---|
| 2554 | #ifdef SH_USE_XML
|
---|
| 2555 | sl_strlcat(msg, _("obj=\""), SH_MSG_BUF);
|
---|
| 2556 | #else
|
---|
| 2557 | sl_strlcat(msg, _("obj=<"), SH_MSG_BUF);
|
---|
| 2558 | #endif
|
---|
| 2559 |
|
---|
| 2560 | sl_strlcat(msg, result, SH_MSG_BUF);
|
---|
| 2561 |
|
---|
| 2562 | #ifdef SH_USE_XML
|
---|
| 2563 | sl_strlcat(msg, _("\" "), SH_MSG_BUF);
|
---|
| 2564 | #else
|
---|
| 2565 | sl_strlcat(msg, _(">"), SH_MSG_BUF);
|
---|
| 2566 | #endif
|
---|
| 2567 | }
|
---|
| 2568 | }
|
---|
| 2569 |
|
---|
[481] | 2570 | /****************************************************
|
---|
| 2571 | *
|
---|
| 2572 | * REPORT on file change
|
---|
| 2573 | *
|
---|
| 2574 | ****************************************************/
|
---|
[1] | 2575 | tmp_path = sh_util_safe_name(theFile->fullpath);
|
---|
[488] | 2576 | if (!sh_global_check_silent)
|
---|
| 2577 | sh_error_handle(log_severity, FIL__, __LINE__,
|
---|
| 2578 | (long) modi_mask, MSG_FI_CHAN,
|
---|
| 2579 | (policy_override == NULL) ? _(policy[class]):log_policy,
|
---|
| 2580 | change_code, tmp_path, msg);
|
---|
[405] | 2581 | ++sh.statistics.files_report;
|
---|
[1] | 2582 |
|
---|
| 2583 | SH_FREE(tmp_path);
|
---|
| 2584 | SH_FREE(tmp);
|
---|
| 2585 | SH_FREE(msg);
|
---|
| 2586 |
|
---|
| 2587 | if (S_TRUE == sh.flag.update)
|
---|
| 2588 | {
|
---|
| 2589 | if (S_FALSE == sh_util_ask_update(theFile->fullpath))
|
---|
| 2590 | {
|
---|
| 2591 | /* user does not want to update, thus we replace
|
---|
| 2592 | * with data from the baseline database
|
---|
| 2593 | */
|
---|
| 2594 | sl_strlcpy(theFile->c_mode, p->theFile.c_mode, 11);
|
---|
| 2595 | theFile->mode = p->theFile.mode;
|
---|
[10] | 2596 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 2597 | sl_strlcpy(theFile->c_attributes, p->theFile.c_attributes, 16);
|
---|
| 2598 | theFile->attributes = p->theFile.attributes;
|
---|
| 2599 | #endif
|
---|
[68] | 2600 | #if defined(USE_ACL) || defined(USE_XATTR)
|
---|
| 2601 | if (theFile->attr_string == NULL && p->attr_string != NULL)
|
---|
| 2602 | { theFile->attr_string = sh_util_strdup (p->attr_string); }
|
---|
| 2603 | else if (theFile->attr_string != NULL && p->attr_string == NULL)
|
---|
| 2604 | { SH_FREE(theFile->attr_string); theFile->attr_string = NULL; }
|
---|
| 2605 | else if (theFile->attr_string != NULL && p->attr_string != NULL)
|
---|
| 2606 | {
|
---|
| 2607 | if (0 != strcmp(theFile->attr_string, p->attr_string))
|
---|
| 2608 | {
|
---|
| 2609 | SH_FREE(theFile->attr_string);
|
---|
| 2610 | theFile->attr_string = sh_util_strdup (p->attr_string);
|
---|
| 2611 | }
|
---|
| 2612 | }
|
---|
| 2613 | #endif
|
---|
[1] | 2614 |
|
---|
| 2615 | if (theFile->c_mode[0] == 'l') /* c_mode is already copied */
|
---|
| 2616 | {
|
---|
[167] | 2617 | if (theFile->link_path)
|
---|
| 2618 | SH_FREE(theFile->link_path);
|
---|
| 2619 | if (p->linkpath)
|
---|
| 2620 | theFile->link_path = sh_util_strdup(p->linkpath);
|
---|
| 2621 | else
|
---|
| 2622 | theFile->link_path = sh_util_strdup("-");
|
---|
[1] | 2623 | }
|
---|
| 2624 | else
|
---|
| 2625 | {
|
---|
[167] | 2626 | if (theFile->link_path)
|
---|
| 2627 | SH_FREE(theFile->link_path);
|
---|
[481] | 2628 | if (p->linkpath)
|
---|
[167] | 2629 | theFile->link_path = sh_util_strdup(p->linkpath);
|
---|
| 2630 | else
|
---|
| 2631 | theFile->link_path = NULL;
|
---|
[1] | 2632 | }
|
---|
| 2633 |
|
---|
| 2634 | sl_strlcpy(fileHash, p->theFile.checksum, KEY_LEN+1);
|
---|
| 2635 |
|
---|
| 2636 | theFile->mtime = p->theFile.mtime;
|
---|
| 2637 | theFile->ctime = p->theFile.ctime;
|
---|
| 2638 | theFile->atime = p->theFile.atime;
|
---|
| 2639 |
|
---|
| 2640 | theFile->size = p->theFile.size;
|
---|
| 2641 |
|
---|
| 2642 | sl_strlcpy(theFile->c_group, p->theFile.c_group, GROUP_MAX+2);
|
---|
| 2643 | theFile->group = p->theFile.group;
|
---|
| 2644 | sl_strlcpy(theFile->c_owner, p->theFile.c_owner, USER_MAX+2);
|
---|
| 2645 | theFile->owner = p->theFile.owner;
|
---|
| 2646 |
|
---|
| 2647 | theFile->ino = p->theFile.ino;
|
---|
| 2648 | theFile->rdev = p->theFile.rdev;
|
---|
| 2649 | theFile->dev = p->theFile.dev;
|
---|
| 2650 | theFile->hardlinks = p->theFile.hardlinks;
|
---|
| 2651 |
|
---|
[114] | 2652 | SET_SH_FFLAG_VISITED(p->fflags);
|
---|
| 2653 | CLEAR_SH_FFLAG_CHECKED(p->fflags);
|
---|
[149] | 2654 | retval = 1;
|
---|
| 2655 | goto unlock_and_return;
|
---|
[1] | 2656 | }
|
---|
[77] | 2657 | else /* if (sh.flag.reportonce == S_TRUE) */
|
---|
[1] | 2658 | {
|
---|
| 2659 | /* we replace the data in the in-memory copy of the
|
---|
| 2660 | * baseline database, because otherwise we would get
|
---|
| 2661 | * another warning if the suidcheck runs
|
---|
| 2662 | */
|
---|
| 2663 | sl_strlcpy(p->theFile.c_mode, theFile->c_mode, 11);
|
---|
| 2664 | p->theFile.mode = theFile->mode;
|
---|
[10] | 2665 | #if defined(__linux__) || defined(HAVE_STAT_FLAGS)
|
---|
[1] | 2666 | sl_strlcpy(p->theFile.c_attributes, theFile->c_attributes, 16);
|
---|
| 2667 | p->theFile.attributes = theFile->attributes;
|
---|
| 2668 | #endif
|
---|
[68] | 2669 | #if defined(USE_ACL) || defined(USE_XATTR)
|
---|
| 2670 | if (p->attr_string == NULL && theFile->attr_string != NULL)
|
---|
| 2671 | { p->attr_string = sh_util_strdup (theFile->attr_string); }
|
---|
| 2672 | else if (p->attr_string != NULL && theFile->attr_string == NULL)
|
---|
| 2673 | { SH_FREE(p->attr_string); p->attr_string = NULL; }
|
---|
| 2674 | else if (theFile->attr_string != NULL && p->attr_string != NULL)
|
---|
| 2675 | {
|
---|
| 2676 | if (0 != strcmp(theFile->attr_string, p->attr_string))
|
---|
| 2677 | {
|
---|
| 2678 | SH_FREE(p->attr_string);
|
---|
| 2679 | p->attr_string = sh_util_strdup (theFile->attr_string);
|
---|
| 2680 | }
|
---|
| 2681 | }
|
---|
| 2682 | #endif
|
---|
[1] | 2683 |
|
---|
[167] | 2684 | if (theFile->c_mode[0] == 'l' || theFile->link_path)
|
---|
[1] | 2685 | {
|
---|
[481] | 2686 | if (p->linkpath != NULL)
|
---|
[1] | 2687 | SH_FREE(p->linkpath);
|
---|
[167] | 2688 | p->linkpath = sh_util_strdup(theFile->link_path);
|
---|
[1] | 2689 | }
|
---|
| 2690 | else
|
---|
| 2691 | {
|
---|
[481] | 2692 | if (p->linkpath != NULL)
|
---|
[167] | 2693 | SH_FREE(p->linkpath);
|
---|
[481] | 2694 | p->linkpath = sh_util_strdup("-");
|
---|
[1] | 2695 | }
|
---|
| 2696 |
|
---|
| 2697 | sl_strlcpy(p->theFile.checksum, fileHash, KEY_LEN+1);
|
---|
| 2698 |
|
---|
| 2699 | p->theFile.mtime = theFile->mtime;
|
---|
| 2700 | p->theFile.ctime = theFile->ctime;
|
---|
| 2701 | p->theFile.atime = theFile->atime;
|
---|
| 2702 |
|
---|
| 2703 | p->theFile.size = theFile->size;
|
---|
| 2704 |
|
---|
| 2705 | sl_strlcpy(p->theFile.c_group, theFile->c_group, GROUP_MAX+2);
|
---|
| 2706 | p->theFile.group = theFile->group;
|
---|
| 2707 | sl_strlcpy(p->theFile.c_owner, theFile->c_owner, USER_MAX+2);
|
---|
| 2708 | p->theFile.owner = theFile->owner;
|
---|
| 2709 |
|
---|
| 2710 | p->theFile.ino = theFile->ino;
|
---|
| 2711 | p->theFile.rdev = theFile->rdev;
|
---|
| 2712 | p->theFile.dev = theFile->dev;
|
---|
| 2713 | p->theFile.hardlinks = theFile->hardlinks;
|
---|
| 2714 | }
|
---|
| 2715 | }
|
---|
| 2716 | }
|
---|
| 2717 |
|
---|
[114] | 2718 | SET_SH_FFLAG_VISITED(p->fflags);
|
---|
| 2719 | CLEAR_SH_FFLAG_CHECKED(p->fflags);
|
---|
[1] | 2720 |
|
---|
[149] | 2721 | unlock_and_return:
|
---|
[153] | 2722 | ; /* 'label at end of compound statement */
|
---|
[149] | 2723 | SH_MUTEX_UNLOCK(mutex_hash);
|
---|
| 2724 | SL_RETURN(retval, _("sh_hash_compdata"));
|
---|
[1] | 2725 | }
|
---|
| 2726 |
|
---|
| 2727 | int hash_full_tree ()
|
---|
| 2728 | {
|
---|
| 2729 | sh_file_t * p;
|
---|
| 2730 | int i;
|
---|
| 2731 |
|
---|
[457] | 2732 | SL_ENTER(_("hash_full_tree"));
|
---|
[1] | 2733 |
|
---|
| 2734 | if (IsInit != 1)
|
---|
[457] | 2735 | SL_RETURN(0, _("hash_full_tree"));
|
---|
[1] | 2736 |
|
---|
[149] | 2737 | SH_MUTEX_LOCK_UNSAFE(mutex_hash);
|
---|
[1] | 2738 | for (i = 0; i < TABSIZE; ++i)
|
---|
| 2739 | {
|
---|
| 2740 | for (p = tab[i]; p; p = p->next)
|
---|
[114] | 2741 | CLEAR_SH_FFLAG_ALLIGNORE(p->fflags);
|
---|
[1] | 2742 | }
|
---|
[149] | 2743 | SH_MUTEX_UNLOCK_UNSAFE(mutex_hash);
|
---|
[457] | 2744 | SL_RETURN (0, _("hash_full_tree"));
|
---|
[1] | 2745 | }
|
---|
| 2746 |
|
---|
[457] | 2747 | #if !defined(SH_CUTEST)
|
---|
| 2748 | static
|
---|
| 2749 | #endif
|
---|
| 2750 | int hash_remove_tree_test(char * s, char * fullpath, size_t len_s)
|
---|
| 2751 | {
|
---|
| 2752 | size_t len_p;
|
---|
| 2753 | char * test;
|
---|
[1] | 2754 |
|
---|
[457] | 2755 | len_p = strlen(fullpath);
|
---|
| 2756 |
|
---|
| 2757 | if (len_p >= len_s)
|
---|
| 2758 | {
|
---|
| 2759 | if (0 == strncmp(s, fullpath, len_s))
|
---|
| 2760 | {
|
---|
| 2761 | if (len_p > len_s)
|
---|
| 2762 | {
|
---|
| 2763 | /* continue if not inside directory;
|
---|
| 2764 | * len_s > 1 because everything is inside '/'
|
---|
| 2765 | */
|
---|
| 2766 | if ((len_s > 1) && (fullpath[len_s] != '/'))
|
---|
| 2767 | return S_FALSE;
|
---|
| 2768 |
|
---|
| 2769 | test = sh_files_find_mostspecific_dir(fullpath);
|
---|
| 2770 |
|
---|
| 2771 | if (test && 0 != strcmp(test, s)) {
|
---|
| 2772 | /* There is a more specific directory, continue */
|
---|
| 2773 | return S_FALSE;
|
---|
| 2774 | }
|
---|
| 2775 |
|
---|
| 2776 | if (NULL == sh_files_findfile(fullpath)) {
|
---|
| 2777 | /* SET_SH_FFLAG_ALLIGNORE(p->fflags); */
|
---|
| 2778 | return S_TRUE;
|
---|
| 2779 | }
|
---|
| 2780 | }
|
---|
| 2781 | else /* len_p == len */
|
---|
| 2782 | {
|
---|
| 2783 | /* it is 's' itself, mark and continue
|
---|
| 2784 | * unless there is a policy for the inode itself
|
---|
| 2785 | */
|
---|
| 2786 | if (NULL == sh_files_findfile(fullpath)) {
|
---|
| 2787 | /* SET_SH_FFLAG_ALLIGNORE(p->fflags); */
|
---|
| 2788 | return S_TRUE;
|
---|
| 2789 | }
|
---|
| 2790 | else {
|
---|
| 2791 | return S_FALSE;
|
---|
| 2792 | }
|
---|
| 2793 | }
|
---|
| 2794 |
|
---|
| 2795 | } /* if path is in tree */
|
---|
| 2796 | } /* if path is possibly in tree */
|
---|
| 2797 | return S_FALSE;
|
---|
| 2798 | }
|
---|
| 2799 |
|
---|
| 2800 |
|
---|
[1] | 2801 | int hash_remove_tree (char * s)
|
---|
| 2802 | {
|
---|
[8] | 2803 | sh_file_t * p;
|
---|
[457] | 2804 | size_t len_s;
|
---|
[8] | 2805 | unsigned int i;
|
---|
[1] | 2806 |
|
---|
| 2807 | SL_ENTER(_("hash_remove_tree"));
|
---|
| 2808 |
|
---|
[8] | 2809 | if (!s || *s == '\0')
|
---|
[1] | 2810 | SL_RETURN ((-1), _("hash_remove_tree"));
|
---|
| 2811 |
|
---|
[457] | 2812 | len_s = sl_strlen(s);
|
---|
[8] | 2813 |
|
---|
[1] | 2814 | if (IsInit != 1)
|
---|
| 2815 | sh_hash_init();
|
---|
| 2816 |
|
---|
[149] | 2817 | SH_MUTEX_LOCK_UNSAFE(mutex_hash);
|
---|
[1] | 2818 | for (i = 0; i < TABSIZE; ++i)
|
---|
| 2819 | {
|
---|
| 2820 | for (p = tab[i]; p; p = p->next)
|
---|
| 2821 | {
|
---|
[457] | 2822 | if (p->fullpath)
|
---|
| 2823 | {
|
---|
| 2824 | /* if (0 == strncmp(s, p->fullpath, len_s)) *//* old */
|
---|
[481] | 2825 | if (S_TRUE == hash_remove_tree_test(s, p->fullpath, len_s)) {
|
---|
[457] | 2826 | SET_SH_FFLAG_ALLIGNORE(p->fflags);
|
---|
[481] | 2827 | MODI_SET(p->theFile.checkflags, MODI_ALLIGNORE);
|
---|
| 2828 | }
|
---|
[457] | 2829 | } /* if path is not null */
|
---|
| 2830 |
|
---|
[1] | 2831 | }
|
---|
| 2832 | }
|
---|
[149] | 2833 | SH_MUTEX_UNLOCK_UNSAFE(mutex_hash);
|
---|
[1] | 2834 | SL_RETURN ((0), _("hash_remove_tree"));
|
---|
| 2835 | }
|
---|
| 2836 |
|
---|
| 2837 | #if TIME_WITH_SYS_TIME
|
---|
| 2838 | #include <sys/time.h>
|
---|
| 2839 | #include <time.h>
|
---|
| 2840 | #else
|
---|
| 2841 | #if HAVE_SYS_TIME_H
|
---|
| 2842 | #include <sys/time.h>
|
---|
| 2843 | #else
|
---|
| 2844 | #include <time.h>
|
---|
| 2845 | #endif
|
---|
| 2846 | #endif
|
---|
| 2847 |
|
---|
[169] | 2848 | static int ListFullDetail = S_FALSE;
|
---|
[1] | 2849 | static int ListWithDelimiter = S_FALSE;
|
---|
[169] | 2850 | static char * ListFile = NULL;
|
---|
[1] | 2851 |
|
---|
[169] | 2852 | int set_list_file (const char * c)
|
---|
| 2853 | {
|
---|
| 2854 | ListFile = sh_util_strdup(c);
|
---|
| 2855 | return 0;
|
---|
| 2856 | }
|
---|
[481] | 2857 | char * get_list_file()
|
---|
| 2858 | {
|
---|
| 2859 | return ListFile;
|
---|
| 2860 | }
|
---|
[169] | 2861 |
|
---|
[20] | 2862 | int set_full_detail (const char * c)
|
---|
[1] | 2863 | {
|
---|
[149] | 2864 | (void) c;
|
---|
[1] | 2865 | ListFullDetail = S_TRUE;
|
---|
[149] | 2866 | return 0;
|
---|
[1] | 2867 | }
|
---|
| 2868 |
|
---|
[20] | 2869 | int set_list_delimited (const char * c)
|
---|
[1] | 2870 | {
|
---|
[149] | 2871 | (void) c;
|
---|
[1] | 2872 | ListFullDetail = S_TRUE;
|
---|
| 2873 | ListWithDelimiter = S_TRUE;
|
---|
[149] | 2874 | return 0;
|
---|
[1] | 2875 | }
|
---|
[76] | 2876 |
|
---|
[149] | 2877 | /* Always quote the string, except if it is empty. Quote quotes by
|
---|
[76] | 2878 | * doubling them.
|
---|
| 2879 | */
|
---|
| 2880 | char * csv_escape(const char * str)
|
---|
| 2881 | {
|
---|
| 2882 | const char * p = str;
|
---|
| 2883 | const char * q;
|
---|
| 2884 |
|
---|
| 2885 | size_t size = 0;
|
---|
| 2886 | size_t flag_quote = 0;
|
---|
[362] | 2887 |
|
---|
[76] | 2888 | char * new;
|
---|
| 2889 | char * pnew;
|
---|
| 2890 |
|
---|
| 2891 | if (p)
|
---|
| 2892 | {
|
---|
| 2893 |
|
---|
| 2894 | while (*p)
|
---|
| 2895 | {
|
---|
[362] | 2896 | if (*p == '"')
|
---|
[76] | 2897 | ++flag_quote;
|
---|
| 2898 |
|
---|
| 2899 | ++size; ++p;
|
---|
| 2900 | }
|
---|
| 2901 |
|
---|
| 2902 | if (sl_ok_adds(size, flag_quote))
|
---|
| 2903 | size += flag_quote; /* double each quote */
|
---|
| 2904 | else
|
---|
| 2905 | return NULL;
|
---|
| 2906 |
|
---|
| 2907 | if (sl_ok_adds(size, 3))
|
---|
| 2908 | size += 3; /* two quotes and terminating null */
|
---|
| 2909 | else
|
---|
| 2910 | return NULL;
|
---|
| 2911 |
|
---|
| 2912 | new = SH_ALLOC(size);
|
---|
| 2913 |
|
---|
| 2914 | if (flag_quote != 0)
|
---|
| 2915 | {
|
---|
| 2916 | new[0] = '"';
|
---|
| 2917 | pnew = &new[1];
|
---|
| 2918 | q = str;
|
---|
| 2919 | while (*q)
|
---|
| 2920 | {
|
---|
| 2921 | *pnew = *q;
|
---|
| 2922 | if (*pnew == '"')
|
---|
| 2923 | {
|
---|
| 2924 | ++pnew; *pnew = '"';
|
---|
| 2925 | }
|
---|
| 2926 | ++pnew; ++q;
|
---|
| 2927 | }
|
---|
| 2928 | *pnew = '"'; ++pnew;
|
---|
| 2929 | *pnew = '\0';
|
---|
| 2930 | }
|
---|
| 2931 | else
|
---|
| 2932 | {
|
---|
| 2933 | if (size > 3)
|
---|
| 2934 | {
|
---|
| 2935 | new[0] = '"';
|
---|
| 2936 | sl_strlcpy (&new[1], str, size-1);
|
---|
| 2937 | new[size-2] = '"';
|
---|
| 2938 | new[size-1] = '\0';
|
---|
| 2939 | }
|
---|
| 2940 | else
|
---|
| 2941 | {
|
---|
| 2942 | new[0] = '\0';
|
---|
| 2943 | }
|
---|
| 2944 | }
|
---|
| 2945 |
|
---|
| 2946 | return new;
|
---|
| 2947 | }
|
---|
| 2948 | return NULL;
|
---|
| 2949 | }
|
---|
| 2950 |
|
---|
[444] | 2951 | int isHexKey(char * s)
|
---|
| 2952 | {
|
---|
| 2953 | int i;
|
---|
| 2954 |
|
---|
| 2955 | for (i = 0; i < KEY_LEN; ++i)
|
---|
| 2956 | {
|
---|
| 2957 | if (*s)
|
---|
| 2958 | {
|
---|
| 2959 | if ((*s >= '0' && *s <= '9') ||
|
---|
| 2960 | (*s >= 'A' && *s <= 'F') ||
|
---|
| 2961 | (*s >= 'a' && *s <= 'f'))
|
---|
| 2962 | {
|
---|
| 2963 | ++s;
|
---|
| 2964 | continue;
|
---|
| 2965 | }
|
---|
| 2966 | }
|
---|
| 2967 | return S_FALSE;
|
---|
| 2968 | }
|
---|
| 2969 | return S_TRUE;
|
---|
| 2970 | }
|
---|
| 2971 |
|
---|
| 2972 | #include "sh_checksum.h"
|
---|
[76] | 2973 |
|
---|
[444] | 2974 | static char * KEYBUFtolower (char * s, char * result)
|
---|
| 2975 | {
|
---|
| 2976 | char * r = result;
|
---|
| 2977 | if (s)
|
---|
| 2978 | {
|
---|
| 2979 | for (; *s; ++s)
|
---|
| 2980 | {
|
---|
| 2981 | *r = tolower((unsigned char) *s); ++r;
|
---|
| 2982 | }
|
---|
| 2983 | *r = '\0';
|
---|
| 2984 | }
|
---|
| 2985 | return result;
|
---|
| 2986 | }
|
---|
| 2987 |
|
---|
[1] | 2988 | void sh_hash_list_db_entry_full_detail (sh_file_t * p)
|
---|
| 2989 | {
|
---|
| 2990 | char * tmp;
|
---|
[76] | 2991 | char * esc;
|
---|
[1] | 2992 | char str[81];
|
---|
[444] | 2993 | char hexdigest[SHA256_DIGEST_STRING_LENGTH];
|
---|
| 2994 | char keybuffer[KEYBUF_SIZE];
|
---|
[1] | 2995 |
|
---|
| 2996 | if (ListWithDelimiter == S_TRUE)
|
---|
| 2997 | {
|
---|
[40] | 2998 | printf(_("%7ld, %7ld, %10s, %5d, %12s, %5d, %3d, %-8s, %5d, %-8s, %5d, "),
|
---|
| 2999 | (unsigned long) p->theFile.ino, (unsigned long) p->theFile.dev,
|
---|
[1] | 3000 | p->theFile.c_mode, (int) p->theFile.mode,
|
---|
| 3001 | p->theFile.c_attributes, (int) p->theFile.attributes,
|
---|
| 3002 | (int) p->theFile.hardlinks,
|
---|
| 3003 | p->theFile.c_owner, (int) p->theFile.owner,
|
---|
| 3004 | p->theFile.c_group, (int) p->theFile.group);
|
---|
| 3005 | }
|
---|
| 3006 | else
|
---|
| 3007 | {
|
---|
[40] | 3008 | printf(_("%7ld %7ld %10s %5d %12s %5d %3d %-8s %5d %-8s %5d "),
|
---|
| 3009 | (unsigned long) p->theFile.ino, (unsigned long) p->theFile.dev,
|
---|
[1] | 3010 | p->theFile.c_mode, (int) p->theFile.mode,
|
---|
| 3011 | p->theFile.c_attributes, (int) p->theFile.attributes,
|
---|
| 3012 | (int) p->theFile.hardlinks,
|
---|
| 3013 | p->theFile.c_owner, (int) p->theFile.owner,
|
---|
| 3014 | p->theFile.c_group, (int) p->theFile.group);
|
---|
| 3015 | }
|
---|
| 3016 |
|
---|
| 3017 | if ('c' == p->theFile.c_mode[0] || 'b' == p->theFile.c_mode[0])
|
---|
[132] | 3018 | sl_snprintf(str, sizeof(str), "%"PRIu64, p->theFile.rdev);
|
---|
[1] | 3019 | else
|
---|
[132] | 3020 | sl_snprintf(str, sizeof(str), "%"PRIu64, p->theFile.size);
|
---|
[1] | 3021 |
|
---|
| 3022 | printf( _(" %8s"), str);
|
---|
| 3023 | if (ListWithDelimiter == S_TRUE)
|
---|
| 3024 | putchar(',');
|
---|
| 3025 |
|
---|
[132] | 3026 | printf( _(" %s"), sh_unix_gmttime (p->theFile.ctime, str, sizeof(str)));
|
---|
[1] | 3027 | if (ListWithDelimiter == S_TRUE)
|
---|
| 3028 | putchar(',');
|
---|
[132] | 3029 | printf( _(" %s"), sh_unix_gmttime (p->theFile.mtime, str, sizeof(str)));
|
---|
[1] | 3030 | if (ListWithDelimiter == S_TRUE)
|
---|
| 3031 | putchar(',');
|
---|
[132] | 3032 | printf( _(" %s"), sh_unix_gmttime (p->theFile.atime, str, sizeof(str)));
|
---|
[1] | 3033 | if (ListWithDelimiter == S_TRUE)
|
---|
| 3034 | putchar(',');
|
---|
[444] | 3035 |
|
---|
| 3036 | if (isHexKey(p->theFile.checksum))
|
---|
| 3037 | printf( _(" %s"), KEYBUFtolower(p->theFile.checksum, keybuffer));
|
---|
| 3038 | else
|
---|
| 3039 | printf( _(" %s"), SHA256_Base2Hex(p->theFile.checksum, hexdigest));
|
---|
[1] | 3040 | if (ListWithDelimiter == S_TRUE)
|
---|
| 3041 | putchar(',');
|
---|
| 3042 |
|
---|
| 3043 | tmp = sh_util_safe_name(p->fullpath);
|
---|
[76] | 3044 | if (ListWithDelimiter != S_TRUE)
|
---|
| 3045 | {
|
---|
| 3046 | printf( _(" %s"), tmp);
|
---|
| 3047 | }
|
---|
| 3048 | else
|
---|
| 3049 | {
|
---|
| 3050 | esc = csv_escape(tmp);
|
---|
| 3051 | printf( _(" %s,"), (esc != NULL) ? esc : _("(null)"));
|
---|
| 3052 | if (esc)
|
---|
| 3053 | SH_FREE(esc);
|
---|
| 3054 | }
|
---|
[1] | 3055 | SH_FREE(tmp);
|
---|
| 3056 |
|
---|
| 3057 | if ('l' == p->theFile.c_mode[0])
|
---|
| 3058 | {
|
---|
| 3059 | tmp = sh_util_safe_name(p->linkpath);
|
---|
[76] | 3060 | if (ListWithDelimiter != S_TRUE)
|
---|
| 3061 | {
|
---|
| 3062 | printf(_(" -> %s"), tmp);
|
---|
| 3063 | }
|
---|
[1] | 3064 | else
|
---|
[76] | 3065 | {
|
---|
| 3066 | esc = csv_escape(tmp);
|
---|
| 3067 | printf( _(" %s,"), (esc != NULL) ? esc : _("(null)"));
|
---|
| 3068 | if (esc)
|
---|
| 3069 | SH_FREE(esc);
|
---|
| 3070 | }
|
---|
[1] | 3071 | SH_FREE(tmp);
|
---|
| 3072 | }
|
---|
[68] | 3073 |
|
---|
| 3074 | if (p->attr_string)
|
---|
| 3075 | {
|
---|
| 3076 | tmp = sh_util_safe_name(p->attr_string);
|
---|
[76] | 3077 | if (ListWithDelimiter != S_TRUE)
|
---|
| 3078 | {
|
---|
| 3079 | printf(_(" %s"), tmp);
|
---|
| 3080 | }
|
---|
| 3081 | else
|
---|
| 3082 | {
|
---|
| 3083 | esc = csv_escape(tmp);
|
---|
| 3084 | printf( _(" %s"), (esc != NULL) ? esc : _("(null)"));
|
---|
| 3085 | if (esc)
|
---|
| 3086 | SH_FREE(esc);
|
---|
| 3087 | }
|
---|
[68] | 3088 | SH_FREE(tmp);
|
---|
| 3089 | }
|
---|
[1] | 3090 | else
|
---|
[68] | 3091 | {
|
---|
| 3092 | if (ListWithDelimiter == S_TRUE)
|
---|
[210] | 3093 | printf("%s",_(" no_attr"));
|
---|
[68] | 3094 | }
|
---|
| 3095 | putchar('\n');
|
---|
[1] | 3096 |
|
---|
| 3097 | return;
|
---|
| 3098 | }
|
---|
| 3099 |
|
---|
| 3100 | void sh_hash_list_db_entry (sh_file_t * p)
|
---|
| 3101 | {
|
---|
| 3102 | char nowtime[128];
|
---|
| 3103 | char thetime[128];
|
---|
| 3104 | char * tmp;
|
---|
| 3105 | time_t now = time(NULL);
|
---|
| 3106 | time_t then = (time_t) p->theFile.mtime;
|
---|
[481] | 3107 | struct tm * time_ptr;
|
---|
[1] | 3108 |
|
---|
[131] | 3109 | #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GMTIME_R)
|
---|
| 3110 | struct tm time_tm;
|
---|
[481] | 3111 | #endif
|
---|
[131] | 3112 |
|
---|
[481] | 3113 | if (ListFullDetail != S_FALSE)
|
---|
| 3114 | {
|
---|
| 3115 | sh_hash_list_db_entry_full_detail (p);
|
---|
| 3116 | return;
|
---|
| 3117 | }
|
---|
| 3118 |
|
---|
| 3119 | #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GMTIME_R)
|
---|
[131] | 3120 | time_ptr = gmtime_r(&then, &time_tm);
|
---|
[481] | 3121 | if (!time_ptr)
|
---|
| 3122 | return;
|
---|
[131] | 3123 | strftime(thetime, 127, _("%b %d %Y"), time_ptr);
|
---|
| 3124 | time_ptr = gmtime_r(&now, &time_tm);
|
---|
[481] | 3125 | if (!time_ptr)
|
---|
| 3126 | return;
|
---|
[131] | 3127 | strftime(nowtime, 127, _("%b %d %Y"), time_ptr);
|
---|
| 3128 | if (0 == strncmp(&nowtime[7], &thetime[7], 4))
|
---|
| 3129 | {
|
---|
| 3130 | time_ptr = gmtime_r(&then, &time_tm);
|
---|
[481] | 3131 | if (!time_ptr)
|
---|
| 3132 | return;
|
---|
[131] | 3133 | strftime(thetime, 127, _("%b %d %H:%M"), time_ptr);
|
---|
| 3134 | }
|
---|
| 3135 | #else
|
---|
[481] | 3136 | time_ptr = gmtime(&then);
|
---|
| 3137 | if (!time_ptr)
|
---|
| 3138 | return;
|
---|
| 3139 | strftime(thetime, 127, _("%b %d %Y"), time_ptr);
|
---|
| 3140 | time_ptr = gmtime(&now);
|
---|
| 3141 | if (!time_ptr)
|
---|
| 3142 | return;
|
---|
| 3143 | strftime(nowtime, 127, _("%b %d %Y"), time_ptr);
|
---|
[1] | 3144 | if (0 == strncmp(&nowtime[7], &thetime[7], 4))
|
---|
[481] | 3145 | {
|
---|
| 3146 | time_ptr = gmtime(&then);
|
---|
| 3147 | if (!time_ptr)
|
---|
| 3148 | return;
|
---|
| 3149 | strftime(thetime, 127, _("%b %d %H:%M"), time_ptr);
|
---|
| 3150 | }
|
---|
[131] | 3151 | #endif
|
---|
[1] | 3152 |
|
---|
| 3153 | tmp = sh_util_safe_name(p->fullpath);
|
---|
| 3154 | if ('c' == p->theFile.c_mode[0] || 'b' == p->theFile.c_mode[0])
|
---|
| 3155 | printf(_("%10s %3d %-8s %-8s %3d,%4d %s %s"),
|
---|
| 3156 | p->theFile.c_mode, (int) p->theFile.hardlinks,
|
---|
| 3157 | p->theFile.c_owner, p->theFile.c_group,
|
---|
| 3158 | (int) major((dev_t)p->theFile.rdev),
|
---|
| 3159 | (int) minor((dev_t)p->theFile.rdev),
|
---|
| 3160 | thetime,
|
---|
| 3161 | tmp);
|
---|
| 3162 | else
|
---|
| 3163 | printf(_("%10s %3d %-8s %-8s %8ld %s %s"),
|
---|
| 3164 | p->theFile.c_mode, (int) p->theFile.hardlinks,
|
---|
| 3165 | p->theFile.c_owner, p->theFile.c_group, (long) p->theFile.size,
|
---|
| 3166 | thetime,
|
---|
| 3167 | tmp);
|
---|
| 3168 | SH_FREE(tmp);
|
---|
| 3169 |
|
---|
| 3170 | if ('l' == p->theFile.c_mode[0])
|
---|
| 3171 | {
|
---|
| 3172 | tmp = sh_util_safe_name(p->linkpath);
|
---|
| 3173 | printf(_(" -> %s\n"), tmp);
|
---|
| 3174 | SH_FREE(tmp);
|
---|
| 3175 | }
|
---|
| 3176 | else
|
---|
| 3177 | printf("\n");
|
---|
| 3178 |
|
---|
| 3179 | return;
|
---|
| 3180 | }
|
---|
| 3181 |
|
---|
[169] | 3182 | #ifdef HAVE_LIBZ
|
---|
| 3183 | #include <zlib.h>
|
---|
| 3184 | #endif
|
---|
| 3185 |
|
---|
| 3186 | int sh_hash_printcontent(char * linkpath)
|
---|
| 3187 | {
|
---|
| 3188 | #ifdef HAVE_LIBZ
|
---|
| 3189 | unsigned char * decoded;
|
---|
| 3190 | unsigned char * decompressed = NULL;
|
---|
| 3191 | size_t dlen;
|
---|
| 3192 | unsigned long clen;
|
---|
| 3193 | unsigned long clen_o;
|
---|
| 3194 | int res;
|
---|
| 3195 |
|
---|
| 3196 | if (linkpath && *linkpath != '-')
|
---|
| 3197 | {
|
---|
| 3198 | dlen = sh_util_base64_dec_alloc (&decoded,
|
---|
| 3199 | (unsigned char *)linkpath,
|
---|
| 3200 | strlen(linkpath));
|
---|
[170] | 3201 |
|
---|
[169] | 3202 | clen = dlen * 2 + 1;
|
---|
[170] | 3203 |
|
---|
[169] | 3204 | do {
|
---|
| 3205 | if (decompressed)
|
---|
| 3206 | SH_FREE(decompressed);
|
---|
| 3207 | clen += dlen; clen_o = clen;
|
---|
| 3208 | decompressed = SH_ALLOC(clen);
|
---|
| 3209 | res = uncompress(decompressed, &clen, decoded, dlen);
|
---|
| 3210 | if (res == Z_MEM_ERROR)
|
---|
[210] | 3211 | { fprintf(stderr, "%s",_("Error: Not enough memory\n")); return -1; }
|
---|
[169] | 3212 | if (res == Z_DATA_ERROR)
|
---|
[210] | 3213 | { fprintf(stderr, "%s",_("Error: Data corrupt or incomplete\n")); return -1; }
|
---|
[169] | 3214 | } while (res == Z_BUF_ERROR || clen == clen_o);
|
---|
[170] | 3215 |
|
---|
[169] | 3216 | decompressed[clen] = '\0';
|
---|
| 3217 | fputs( (char*) decompressed, stdout);
|
---|
[227] | 3218 | SH_FREE(decompressed);
|
---|
[169] | 3219 | return 0;
|
---|
| 3220 | }
|
---|
| 3221 | #else
|
---|
| 3222 | (void) linkpath;
|
---|
| 3223 | #endif
|
---|
[210] | 3224 | fprintf(stderr, "%s",_("Error: No data available\n"));
|
---|
[169] | 3225 | return -1;
|
---|
| 3226 | }
|
---|
| 3227 |
|
---|
[1] | 3228 | /* if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE) */
|
---|
| 3229 | #endif
|
---|