Changeset 40 for trunk/src/sh_prelude.c
- Timestamp:
- May 31, 2006, 9:38:30 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_prelude.c
r37 r40 39 39 #include <string.h> 40 40 #include <sys/types.h> 41 #include <sys/stat.h>42 41 43 42 #if TIME_WITH_SYS_TIME … … 56 55 #endif 57 56 58 #ifdef MAJOR_IN_MKDEV59 # include <sys/mkdev.h>60 #else61 # ifdef MAJOR_IN_SYSMACROS62 # include <sys/sysmacros.h>63 # endif64 #endif65 66 57 #include <unistd.h> 67 58 #include <syslog.h> 68 59 #include <pwd.h> 69 #include <grp.h>70 60 71 61 int sh_argc_store; … … 412 402 if ( ptr ) { 413 403 ret = idmef_file_new_name(file, &str); 414 if ( ret < 0 ) 415 return; 416 417 prelude_string_set_dup(str, ptr + 1); 404 if ( ret == 0 ) { 405 prelude_string_set_dup(str, ptr + 1); 406 } 418 407 } 419 408 } … … 428 417 if ( ptr ) { 429 418 ret = idmef_time_from_samhain(&time, ptr); 430 if ( ret < 0 ) { 431 free(ptr); 432 return; 433 } 434 435 idmef_file_set_modify_time(file, time); 419 if ( ret == 0 ) { 420 idmef_file_set_modify_time(file, time); 421 } 436 422 free(ptr); 437 423 } … … 440 426 if ( ptr ) { 441 427 ret = idmef_time_from_samhain(&time, ptr); 442 if ( ret < 0 ) { 443 free(ptr); 444 return; 445 } 446 447 idmef_file_set_create_time(file, time); 428 if ( ret == 0 ) { 429 idmef_file_set_create_time(file, time); 430 } 448 431 free(ptr); 449 432 } … … 451 434 ptr = get_value(msg, _("inode"), suffix); 452 435 if ( ptr ) { 453 struct stat st;454 455 ret = lstat(prelude_string_get_string(idmef_file_get_path(file)), &st);456 if ( ret < 0 ) {457 free(ptr);458 return;459 }460 461 436 ret = idmef_file_new_inode(file, &inode); 462 if ( ret < 0 ) { 463 free(ptr); 464 return; 465 } 466 467 idmef_inode_set_major_device(inode, major(st.st_dev)); 468 idmef_inode_set_minor_device(inode, minor(st.st_dev)); 469 idmef_inode_set_number(inode, strtoul(ptr, NULL, 10)); 437 if ( ret == 0 ) { 438 char * dev = get_value(msg, _("dev"), suffix); 439 if (dev) { 440 char * q = strchr(dev, ','); 441 if (*q) { 442 *q = '\0'; ++q; 443 idmef_inode_set_major_device(inode, strtoul(dev, NULL, 0)); 444 idmef_inode_set_minor_device(inode, strtoul( q, NULL, 0)); 445 } 446 free(dev); 447 } 448 idmef_inode_set_number(inode, strtoul(ptr, NULL, 10)); 449 } 470 450 free(ptr); 471 451 } … … 475 455 ret = idmef_file_new_checksum(file, &checksum, IDMEF_LIST_APPEND); 476 456 if ( ret < 0 ) { 477 478 return;457 free(ptr); 458 goto get_mode; 479 459 } 480 460 … … 482 462 483 463 if (hashtype == 0) 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 return;464 idmef_checksum_set_algorithm(checksum, IDMEF_CHECKSUM_ALGORITHM_TIGER); 465 466 else if (hashtype == 1) 467 idmef_checksum_set_algorithm(checksum, IDMEF_CHECKSUM_ALGORITHM_SHA1); 468 469 else if (hashtype == 2) 470 idmef_checksum_set_algorithm(checksum, IDMEF_CHECKSUM_ALGORITHM_MD5); 471 472 else 473 idmef_checksum_set_algorithm(checksum, IDMEF_CHECKSUM_ALGORITHM_TIGER); 474 475 476 ret = idmef_checksum_new_value(checksum, &str); 477 if ( ret < 0 ) { 478 free(ptr); 479 goto get_mode; 500 480 } 501 481 502 482 /* will be freed on destroy() 503 483 */ 504 prelude_string_set_nodup(str, ptr); 505 } 484 prelude_string_set_nodup(str, ptr); 485 } 486 487 get_mode: 506 488 507 489 mode = get_value(msg, _("mode"), suffix); … … 510 492 ret = idmef_file_new_file_access(file, &access, IDMEF_LIST_APPEND); 511 493 if ( ret < 0 ) 512 goto mode_free;494 goto get_owner; 513 495 514 496 /* flawfinder: ignore *//* is part of name, not access() */ 515 497 ret = idmef_file_access_new_user_id(access, &userid); 516 498 if ( ret < 0 ) 517 goto mode_free;499 goto get_owner; 518 500 idmef_user_id_set_type(userid, IDMEF_USER_ID_TYPE_OTHER_PRIVS); 519 501 … … 521 503 get_access_info ( access, mode, 7, 9 ); 522 504 } 505 506 get_owner: 523 507 524 508 ptr = get_value(msg, _("owner"), suffix); 525 509 if ( ptr ) { 526 struct passwd *pw;510 char * uid; 527 511 528 512 /* flawfinder: ignore *//* is part of name, not access() */ … … 530 514 if ( ret < 0 ) { 531 515 free(ptr); 532 goto mode_free;516 goto get_group; 533 517 } 534 518 … … 537 521 if ( ret < 0 ) { 538 522 free(ptr); 539 goto mode_free;523 goto get_group; 540 524 } 541 525 idmef_user_id_set_type(userid, IDMEF_USER_ID_TYPE_USER_PRIVS); … … 544 528 if ( ret < 0 ) { 545 529 free(ptr); 546 goto mode_free;530 goto get_group; 547 531 } 548 532 prelude_string_set_nodup(str, ptr); 549 533 550 pw = getpwnam(ptr);551 if ( ! pw)552 goto mode_free;553 554 idmef_user_id_set_number(userid, pw->pw_uid);534 uid = get_value(msg, _("iowner"), suffix); 535 if ( ! uid ) 536 goto get_group; 537 538 idmef_user_id_set_number(userid, strtoul(uid, NULL, 0)); 555 539 556 540 if ( mode ) { … … 558 542 get_access_info ( access, mode, 1, 3 ); 559 543 } 560 } 544 545 free(uid); 546 } 547 548 get_group: 561 549 562 550 ptr = get_value(msg, _("group"), suffix); 563 551 if ( ptr ) { 564 struct group *gr;552 char *gid; 565 553 566 554 /* flawfinder: ignore *//* is part of name, not access() */ … … 587 575 prelude_string_set_nodup(str, ptr); 588 576 589 g r = getgrnam(ptr);590 if ( ! g r)577 gid = get_value(msg, _("igroup"), suffix); 578 if ( ! gid ) 591 579 goto mode_free; 592 580 593 idmef_user_id_set_number(userid, gr->gr_gid);581 idmef_user_id_set_number(userid, strtoul(gid, NULL, 0)); 594 582 595 583 if ( mode ) { 596 584 get_access_info ( access, mode, 4, 6 ); /* flawfinder: ignore */ 597 585 } 586 587 free(gid); 598 588 } 599 589
Note:
See TracChangeset
for help on using the changeset viewer.