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