Changeset 264
- Timestamp:
- Dec 14, 2009, 8:54:23 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile.in
r262 r264 1660 1660 1661 1661 samhain.o: $(srcsrc)/samhain.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_files.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_unix.h $(srcinc)/sh_getopt.h $(srcinc)/sh_readconf.h $(srcinc)/sh_hash.h $(srcinc)/sh_nmail.h $(srcinc)/sh_tiger.h $(srcinc)/sh_gpg.h $(srcinc)/sh_mem.h $(srcinc)/sh_forward.h $(srcinc)/sh_tools.h $(srcinc)/sh_hash.h $(srcinc)/sh_extern.h $(srcinc)/sh_modules.h $(srcinc)/sh_ignore.h $(srcinc)/sh_prelink.h sh_MK.h $(srcinc)/sh_schedule.h 1662 sh_unix.o: $(srcsrc)/sh_unix.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_mem.h $(srcinc)/sh_hash.h $(srcinc)/sh_tools.h $(srcinc)/sh_tiger.h $(srcinc)/sh_prelink.h $(srcinc)/sh_pthread.h $(srcinc)/sh_static.h $(srcinc)/sh_prelude.h $(srcinc)/ sh_ignore.h1662 sh_unix.o: $(srcsrc)/sh_unix.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_mem.h $(srcinc)/sh_hash.h $(srcinc)/sh_tools.h $(srcinc)/sh_tiger.h $(srcinc)/sh_prelink.h $(srcinc)/sh_pthread.h $(srcinc)/sh_static.h $(srcinc)/sh_prelude.h $(srcinc)/zAVLTree.h $(srcinc)/sh_ignore.h 1663 1663 sh_utils.o: $(srcsrc)/sh_utils.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_tiger.h $(srcinc)/sh_entropy.h $(srcinc)/sh_pthread.h 1664 1664 sh_error.o: $(srcsrc)/sh_error.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_cat.h $(srcinc)/sh_database.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_tiger.h $(srcinc)/sh_nmail.h $(srcinc)/sh_forward.h $(srcinc)/sh_prelude.h $(srcinc)/sh_pthread.h $(srcinc)/sh_tools.h $(srcinc)/sh_extern.h -
trunk/depend.dep
r262 r264 2 2 # DO NOT DELETE THIS LINE 3 3 samhain.o: $(srcsrc)/samhain.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_files.h $(srcinc)/sh_utils.h $(srcinc)/sh_error.h $(srcinc)/sh_unix.h $(srcinc)/sh_getopt.h $(srcinc)/sh_readconf.h $(srcinc)/sh_hash.h $(srcinc)/sh_nmail.h $(srcinc)/sh_tiger.h $(srcinc)/sh_gpg.h $(srcinc)/sh_mem.h $(srcinc)/sh_forward.h $(srcinc)/sh_tools.h $(srcinc)/sh_hash.h $(srcinc)/sh_extern.h $(srcinc)/sh_modules.h $(srcinc)/sh_ignore.h $(srcinc)/sh_prelink.h sh_MK.h $(srcinc)/sh_schedule.h 4 sh_unix.o: $(srcsrc)/sh_unix.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_mem.h $(srcinc)/sh_hash.h $(srcinc)/sh_tools.h $(srcinc)/sh_tiger.h $(srcinc)/sh_prelink.h $(srcinc)/sh_pthread.h $(srcinc)/sh_static.h $(srcinc)/sh_prelude.h $(srcinc)/ sh_ignore.h4 sh_unix.o: $(srcsrc)/sh_unix.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_mem.h $(srcinc)/sh_hash.h $(srcinc)/sh_tools.h $(srcinc)/sh_tiger.h $(srcinc)/sh_prelink.h $(srcinc)/sh_pthread.h $(srcinc)/sh_static.h $(srcinc)/sh_prelude.h $(srcinc)/zAVLTree.h $(srcinc)/sh_ignore.h 5 5 sh_utils.o: $(srcsrc)/sh_utils.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_tiger.h $(srcinc)/sh_entropy.h $(srcinc)/sh_pthread.h 6 6 sh_error.o: $(srcsrc)/sh_error.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_cat.h $(srcinc)/sh_database.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_tiger.h $(srcinc)/sh_nmail.h $(srcinc)/sh_forward.h $(srcinc)/sh_prelude.h $(srcinc)/sh_pthread.h $(srcinc)/sh_tools.h $(srcinc)/sh_extern.h -
trunk/depend.sum
r262 r264 1 2976518268 1 188553029 -
trunk/include/sh_unix.h
r197 r264 156 156 extern int sh_unix_check_acl; 157 157 158 /* destroy userid cache 159 */ 160 void sh_userid_destroy (); 161 158 162 /* --- run a command, securely --- 159 163 */ -
trunk/src/samhain.c
r256 r264 2168 2168 continue; 2169 2169 2170 /* reset cache 2171 */ 2172 sh_userid_destroy(); 2173 2170 2174 /* go to sleep 2171 2175 */ -
trunk/src/sh_forward.c
r262 r264 5380 5380 tchkold = tcurrent; 5381 5381 client_time_check(/* all_clients */); 5382 /* reset cache */ 5383 sh_userid_destroy(); 5382 5384 } 5383 5385 -
trunk/src/sh_socket.c
r252 r264 384 384 sl_strlcat(sh_sockname, _(".sock"), size); 385 385 } 386 386 387 387 388 pf_unix_fd = socket (PF_UNIX, SOCK_STREAM, 0); -
trunk/src/sh_unix.c
r263 r264 1499 1499 #endif 1500 1500 int test; 1501 struct sigaction act, oldact;1502 1501 int status; 1502 struct sigaction act; 1503 #if !defined(SH_PROFILE) 1504 struct sigaction oldact; 1505 #endif 1503 1506 1504 1507 sigset_t set_proc; … … 2480 2483 struct passwd * tempres; 2481 2484 int status = 0; 2485 2482 2486 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWUID_R) 2483 2487 struct passwd pwd; … … 2524 2528 } 2525 2529 2526 SH_MUTEX_STATIC(mutex_getUIDname, PTHREAD_MUTEX_INITIALIZER); 2527 2530 /* ------------------- Caching ----------------*/ 2531 #include "zAVLTree.h" 2532 2533 #define CACHE_GID 0 2534 #define CACHE_UID 1 2535 2536 struct user_id { 2537 char * name; 2538 uid_t id; 2539 struct user_id * next; 2540 }; 2541 2542 static struct user_id * uid_list = NULL; 2543 static struct user_id * gid_list = NULL; 2544 2545 SH_MUTEX_STATIC(mutex_cache, PTHREAD_MUTEX_INITIALIZER); 2546 2547 static void sh_userid_free(struct user_id * item) 2548 { 2549 while (item) 2550 { 2551 struct user_id * user = item; 2552 item = item->next; 2553 2554 SH_FREE(user->name); 2555 SH_FREE(user); 2556 } 2557 return; 2558 } 2559 2560 void sh_userid_destroy () 2561 { 2562 struct user_id * tmp_uid; 2563 struct user_id * tmp_gid; 2564 2565 SH_MUTEX_LOCK_UNSAFE(mutex_cache); 2566 tmp_gid = gid_list; 2567 gid_list = NULL; 2568 tmp_uid = uid_list; 2569 uid_list = NULL; 2570 SH_MUTEX_UNLOCK_UNSAFE(mutex_cache); 2571 2572 sh_userid_free(tmp_uid); 2573 sh_userid_free(tmp_gid); 2574 return; 2575 } 2576 2577 static void sh_userid_additem(struct user_id * list, struct user_id * item) 2578 { 2579 while (list && list->next) 2580 list = list->next; 2581 list->next = item; 2582 return; 2583 } 2584 2585 static void sh_userid_add(uid_t id, char * username, int which) 2586 { 2587 size_t len; 2588 struct user_id * user = SH_ALLOC(sizeof(struct user_id)); 2589 2590 if (username) 2591 len = strlen(username) + 1; 2592 else 2593 len = 1; 2594 2595 user->name = SH_ALLOC(len); 2596 user->id = id; 2597 if (username) 2598 sl_strlcpy(user->name, username, len); 2599 else 2600 user->name[0] = '\0'; 2601 user->next = NULL; 2602 2603 SH_MUTEX_LOCK(mutex_cache); 2604 if (which == CACHE_UID) 2605 { 2606 if (!uid_list) 2607 uid_list = user; 2608 else 2609 sh_userid_additem(uid_list, user); 2610 } 2611 else 2612 { 2613 if (!gid_list) 2614 gid_list = user; 2615 else 2616 sh_userid_additem(gid_list, user); 2617 } 2618 SH_MUTEX_UNLOCK(mutex_cache); 2619 2620 return; 2621 } 2622 2623 static char * sh_userid_search(struct user_id * list, uid_t id) 2624 { 2625 while (list) 2626 { 2627 if (list->id == id) 2628 return list->name; 2629 list = list->next; 2630 } 2631 return NULL; 2632 } 2633 2634 static char * sh_userid_get (uid_t id, int which, char * out, size_t len) 2635 { 2636 char * user = NULL; 2637 2638 SH_MUTEX_LOCK_UNSAFE(mutex_cache); 2639 if (which == CACHE_UID) 2640 user = sh_userid_search(uid_list, id); 2641 else 2642 user = sh_userid_search(gid_list, id); 2643 if (user) 2644 { 2645 sl_strlcpy(out, user, len); 2646 user = out; 2647 } 2648 SH_MUTEX_UNLOCK_UNSAFE(mutex_cache); 2649 2650 return user; 2651 } 2652 2653 /* --------- end caching code --------- */ 2654 2528 2655 char * sh_unix_getUIDname (int level, uid_t uid, char * out, size_t len) 2529 2656 { … … 2534 2661 #endif 2535 2662 int status = 0; 2536 static uid_t old_uid;2537 static char name[32] = { '\0' };2538 2663 char errbuf[SH_ERRBUF_SIZE]; 2664 char * tmp; 2539 2665 2540 2666 SL_ENTER(_("sh_unix_getUIDname")); 2541 2667 2542 if ((uid == old_uid) && (name[0] != '\0')) { 2543 out[0] = '\0'; 2544 SH_MUTEX_LOCK_UNSAFE(mutex_getUIDname); 2545 if ((uid == old_uid) && (name[0] != '\0')) { 2546 sl_strlcpy(out, name, len); 2547 } 2548 SH_MUTEX_UNLOCK_UNSAFE(mutex_getUIDname); 2549 if (out[0] != '\0') 2550 SL_RETURN( out, _("sh_unix_getUIDname")); 2551 } 2668 tmp = sh_userid_get(uid, CACHE_UID, out, len); 2669 2670 if (tmp) 2671 { 2672 if (tmp[0] != '\0') 2673 { 2674 SL_RETURN( out, _("sh_unix_getUIDname")); 2675 } 2676 else 2677 { 2678 SL_RETURN( NULL, _("sh_unix_getUIDname")); 2679 } 2680 } 2552 2681 2553 2682 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWUID_R) … … 2560 2689 #endif 2561 2690 2562 if (tempres == NULL) { 2563 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL, 2564 sh_error_message(status, errbuf, sizeof(errbuf)), 2565 _("getpwuid"), (long) uid, _("completely missing")); 2691 if (tempres == NULL) 2692 { 2693 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL, 2694 sh_error_message(status, errbuf, sizeof(errbuf)), 2695 _("getpwuid"), (long) uid, _("completely missing")); 2566 2696 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2567 SH_FREE(buffer); 2568 #endif 2569 SL_RETURN( NULL, _("sh_unix_getUIDname")); 2570 } 2571 2572 2573 if (tempres->pw_name != NULL) { 2574 SH_MUTEX_LOCK_UNSAFE(mutex_getUIDname); 2575 sl_strlcpy(name, tempres->pw_name, sizeof(name)); 2576 old_uid = uid; 2577 sl_strlcpy(out, name, len); 2578 SH_MUTEX_UNLOCK_UNSAFE(mutex_getUIDname); 2697 SH_FREE(buffer); 2698 #endif 2699 sh_userid_add(uid, NULL, CACHE_UID); 2700 SL_RETURN( NULL, _("sh_unix_getUIDname")); 2701 } 2702 2703 2704 if (tempres->pw_name != NULL) 2705 { 2706 2707 sl_strlcpy(out, tempres->pw_name, len); 2708 sh_userid_add(uid, out, CACHE_UID); 2709 2579 2710 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2580 SH_FREE(buffer); 2581 #endif 2582 SL_RETURN( out, _("sh_unix_getUIDname")); 2583 } else { 2584 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL, 2585 sh_error_message(status, errbuf, sizeof(errbuf)), 2586 _("getpwuid"), (long) uid, _("pw_user")); 2711 SH_FREE(buffer); 2712 #endif 2713 2714 SL_RETURN( out, _("sh_unix_getUIDname")); 2715 } 2716 else 2717 { 2718 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL, 2719 sh_error_message(status, errbuf, sizeof(errbuf)), 2720 _("getpwuid"), (long) uid, _("pw_user")); 2587 2721 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2588 SH_FREE(buffer); 2589 #endif 2590 SL_RETURN( NULL, _("sh_unix_getUIDname")); 2591 } 2592 } 2593 2594 SH_MUTEX_STATIC(mutex_getGIDname, PTHREAD_MUTEX_INITIALIZER); 2722 SH_FREE(buffer); 2723 #endif 2724 SL_RETURN( NULL, _("sh_unix_getUIDname")); 2725 } 2726 /* notreached */ 2727 } 2595 2728 2596 2729 char * sh_unix_getGIDname (int level, gid_t gid, char * out, size_t len) … … 2598 2731 struct group * tempres; 2599 2732 int status = 0; 2600 static gid_t old_gid; 2601 static char name[32] = { '\0' }; 2733 2602 2734 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2603 2735 struct group grp; … … 2605 2737 #endif 2606 2738 char errbuf[SH_ERRBUF_SIZE]; 2739 char * tmp; 2607 2740 2608 2609 2741 SL_ENTER(_("sh_unix_getGIDname")); 2610 2742 2611 if ((gid == old_gid) && (name[0] != '\0')) { 2612 out[0] = '\0'; 2613 SH_MUTEX_LOCK_UNSAFE(mutex_getGIDname); 2614 if ((gid == old_gid) && (name[0] != '\0')) { 2615 sl_strlcpy(out, name, len); 2616 } 2617 SH_MUTEX_UNLOCK_UNSAFE(mutex_getGIDname); 2618 if (out[0] != '\0') 2619 SL_RETURN( out, _("sh_unix_getGIDname")); 2620 } 2743 tmp = sh_userid_get((uid_t)gid, CACHE_GID, out, len); 2744 2745 if (tmp) 2746 { 2747 if (tmp[0] != '\0') 2748 { 2749 SL_RETURN( out, _("sh_unix_getGIDname")); 2750 } 2751 else 2752 { 2753 SL_RETURN( NULL, _("sh_unix_getGIDname")); 2754 } 2755 } 2621 2756 2622 2757 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) … … 2629 2764 #endif 2630 2765 2631 if (tempres == NULL) { 2632 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL, 2633 sh_error_message(status, errbuf, sizeof(errbuf)), 2634 _("getgrgid"), (long) gid, _("completely missing")); 2766 if (tempres == NULL) 2767 { 2768 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL, 2769 sh_error_message(status, errbuf, sizeof(errbuf)), 2770 _("getgrgid"), (long) gid, _("completely missing")); 2635 2771 2636 2772 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2637 SH_FREE(buffer); 2638 #endif 2639 SL_RETURN( NULL, _("sh_unix_getGIDname")); 2640 } 2641 2642 if (tempres->gr_name != NULL) { 2643 SH_MUTEX_LOCK_UNSAFE(mutex_getGIDname); 2644 sl_strlcpy(name, tempres->gr_name, sizeof(name)); 2645 old_gid = gid; 2646 sl_strlcpy(out, name, len); 2647 SH_MUTEX_UNLOCK_UNSAFE(mutex_getGIDname); 2773 SH_FREE(buffer); 2774 #endif 2775 2776 sh_userid_add(gid, NULL, CACHE_GID); 2777 SL_RETURN( NULL, _("sh_unix_getGIDname")); 2778 } 2779 2780 if (tempres->gr_name != NULL) 2781 { 2782 2783 sl_strlcpy(out, tempres->gr_name, len); 2784 sh_userid_add((uid_t)gid, out, CACHE_GID); 2785 2648 2786 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2649 SH_FREE(buffer); 2650 #endif 2651 SL_RETURN( out, _("sh_unix_getGIDname")); 2652 } else { 2653 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL, 2654 sh_error_message(status, errbuf, sizeof(errbuf)), 2655 _("getgrgid"), (long) gid, _("gr_name")); 2787 SH_FREE(buffer); 2788 #endif 2789 2790 SL_RETURN( out, _("sh_unix_getGIDname")); 2791 } 2792 else 2793 { 2794 sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL, 2795 sh_error_message(status, errbuf, sizeof(errbuf)), 2796 _("getgrgid"), (long) gid, _("gr_name")); 2797 2656 2798 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 2657 SH_FREE(buffer); 2658 #endif 2659 SL_RETURN( NULL, _("sh_unix_getGIDname")); 2660 } 2799 SH_FREE(buffer); 2800 #endif 2801 2802 SL_RETURN( NULL, _("sh_unix_getGIDname")); 2803 } 2804 /* notreached */ 2661 2805 } 2662 2806
Note:
See TracChangeset
for help on using the changeset viewer.