Changeset 169 for trunk/src/sh_prelude.c
- Timestamp:
- Apr 13, 2008, 9:59:55 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_prelude.c
r131 r169 85 85 #define SH_NEED_PWD_GRP 1 86 86 #include "sh_static.h" 87 87 char * sh_util_strdup (const char * str) SH_GNUC_MALLOC; 88 88 /* 89 89 * When SH_USE_XML is set, value are formated using name="value". … … 651 651 #endif 652 652 653 #ifdef SH_USE_PORTCHECK 654 { MSG_PORT_MISS, N_("Service closed"), IDMEF_IMPACT_TYPE_OTHER }, 655 { MSG_PORT_NEW, N_("Service opened"), IDMEF_IMPACT_TYPE_OTHER }, 656 { MSG_PORT_RESTART, N_("Service restarted"), IDMEF_IMPACT_TYPE_OTHER }, 657 { MSG_PORT_NEWPORT, N_("Service restarted"), IDMEF_IMPACT_TYPE_OTHER }, 658 #endif 659 653 660 #ifdef SH_USE_SUIDCHK 654 661 { MSG_SUID_POLICY, N_("SUID/SGID File Detected"), IDMEF_IMPACT_TYPE_FILE }, … … 684 691 685 692 693 #ifdef SH_USE_PORTCHECK 694 static int get_service_info(char *msg, idmef_alert_t *alert) 695 { 696 int ret; 697 long port; 698 char *ptr, *new, *tmp, *ip, *srv, *end; 699 prelude_string_t *str; 700 idmef_address_t *address; 701 idmef_node_t *node; 702 idmef_service_t *service; 703 idmef_source_t *source = idmef_alert_get_next_source(alert, NULL); 704 705 new = sh_util_strdup(msg); 706 707 ptr = strstr(new, _("port: ")); 708 if ( ! ptr ) { 709 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 710 _("malformed Samhain port check message"), _("get_service_info")); 711 SH_FREE( new ); 712 return -1; 713 } 714 715 ptr += 6; /* skip 'port: ', position on first byte of interface */ 716 tmp = strchr(ptr, ':'); 717 if ( ! tmp ) { 718 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 719 _("malformed Samhain port check message (no port)"), _("get_service_info")); 720 SH_FREE( new ); 721 return -1; 722 } 723 *tmp = '\0'; 724 725 ip = strdup(ptr); 726 if ( ip ) { 727 if ( ! source ) { 728 ret = idmef_alert_new_source(alert, &source, IDMEF_LIST_APPEND); 729 if ( ret < 0 ) { 730 free(ip); 731 SH_FREE( new ); 732 return ret; 733 } 734 } 735 736 ret = idmef_source_new_node(source, &node); 737 if ( ret < 0 ) { 738 free(ip); 739 SH_FREE( new ); 740 return ret; 741 } 742 743 ret = idmef_node_new_address(node, &address, IDMEF_LIST_APPEND); 744 if ( ret < 0 ) { 745 free(ip); 746 SH_FREE( new ); 747 return ret; 748 } 749 750 ret = idmef_address_new_address(address, &str); 751 if ( ret < 0 ) { 752 free(ip); 753 SH_FREE( new ); 754 return ret; 755 } 756 757 prelude_string_set_nodup(str, ip); 758 } 759 760 ptr = tmp; 761 ++ptr; 762 tmp = strchr(ptr, '/'); 763 if ( ! tmp ) { 764 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 765 _("malformed Samhain port check message (no protocol)"), _("get_service_info")); 766 SH_FREE( new ); 767 return -1; 768 } 769 *tmp = '\0'; 770 771 port = strtol(ptr, &end, 0); 772 if ( *ptr && *end == '\0' && port >= 0 && port < 65536) { 773 774 if ( ! source ) { 775 ret = idmef_alert_new_source(alert, &source, IDMEF_LIST_APPEND); 776 if ( ret < 0 ) { 777 free(srv); 778 SH_FREE( new ); 779 return ret; 780 } 781 } 782 783 ret = idmef_source_new_service(source, &service); 784 if ( ret < 0 ) { 785 free(srv); 786 SH_FREE( new ); 787 return ret; 788 } 789 790 idmef_service_set_port(service, port); 791 } 792 793 ptr = tmp; 794 ++ptr; 795 ptr = strchr(ptr, '('); 796 if ( ! ptr ) { 797 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 798 _("malformed Samhain port check message (no service)"), _("get_service_info")); 799 SH_FREE( new ); 800 return -1; 801 } 802 ++ptr; 803 tmp = strchr(ptr, ')'); 804 if ( ! tmp ) { 805 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 806 _("malformed Samhain port check message (service not closed)"), _("get_service_info")); 807 SH_FREE( new ); 808 return -1; 809 } 810 *tmp = '\0'; 811 812 srv = strdup(ptr); 813 if ( srv ) { 814 if ( ! source ) { 815 ret = idmef_alert_new_source(alert, &source, IDMEF_LIST_APPEND); 816 if ( ret < 0 ) { 817 free(srv); 818 SH_FREE( new ); 819 return ret; 820 } 821 } 822 823 if ( ! service ) { 824 ret = idmef_source_new_service(source, &service); 825 if ( ret < 0 ) { 826 free(srv); 827 SH_FREE( new ); 828 return ret; 829 } 830 } 831 832 ret = idmef_service_new_ident(service, &str); 833 if ( ret < 0 ) { 834 free(srv); 835 SH_FREE( new ); 836 return ret; 837 } 838 839 prelude_string_set_nodup(str, srv); 840 } 841 842 SH_FREE( new ); 843 844 return 0; 845 } 846 #endif 686 847 687 848 static int get_login_info(char *msg, idmef_alert_t *alert) … … 902 1063 goto err; 903 1064 1065 #ifdef SH_USE_PORTCHECK 1066 if (msgid == MSG_PORT_MISS || msgid == MSG_PORT_NEW || msgid == MSG_PORT_RESTART || msgid == MSG_PORT_NEWPORT) { 1067 ret = get_service_info(message, alert); 1068 if ( ret < 0 ) 1069 goto err; 1070 } 1071 #endif 1072 904 1073 map_policy_to_class(message, msgid, impact, str); 905 1074
Note:
See TracChangeset
for help on using the changeset viewer.