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