- Timestamp:
- Jan 8, 2009, 10:08:45 PM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_cat.c
r192 r206 135 135 #ifdef SH_USE_PORTCHECK 136 136 { MSG_PORT_MISS, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServiceMissing] %s\"")}, 137 { MSG_PORT_NEW, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServiceNew] %s\" path=\"%s\" userid=\"%s\"")},138 { MSG_PORT_RESTART,SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServiceRestarted] %s\" path=\"%s\" userid=\"%s\"")},139 { MSG_PORT_NEWPORT,SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServicePortSwitch] %s\" path=\"%s\" userid=\"%s\"")},137 { MSG_PORT_NEW, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServiceNew] %s\" path=\"%s\" pid=\"%lu\" userid=\"%s\"")}, 138 { MSG_PORT_RESTART,SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServiceRestarted] %s\" path=\"%s\" pid=\"%lu\" userid=\"%s\"")}, 139 { MSG_PORT_NEWPORT,SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [ServicePortSwitch] %s\" path=\"%s\" pid=\"%lu\" userid=\"%s\"")}, 140 140 #endif 141 141 … … 464 464 #ifdef SH_USE_PORTCHECK 465 465 { MSG_PORT_MISS, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServiceMissing] %s>")}, 466 { MSG_PORT_NEW, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServiceNew] %s> path=<%s> userid=<%s>")},467 { MSG_PORT_RESTART,SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServiceRestarted] %s> path=<%s> userid=<%s>")},468 { MSG_PORT_NEWPORT,SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServicePortSwitch] %s> path=<%s> userid=<%s>")},466 { MSG_PORT_NEW, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServiceNew] %s> path=<%s> pid=<%lu> userid=<%s>")}, 467 { MSG_PORT_RESTART,SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServiceRestarted] %s> path=<%s> pid=<%lu> userid=<%s>")}, 468 { MSG_PORT_NEWPORT,SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [ServicePortSwitch] %s> path=<%s> pid=<%lu> userid=<%s>")}, 469 469 #endif 470 470 -
trunk/src/sh_port2proc.c
r199 r206 311 311 /* returns the command and fills the 'user' array 312 312 */ 313 char * sh_port2proc_query(int proto, struct in_addr * saddr, int sport, 313 char * sh_port2proc_query(int proto, struct in_addr * saddr, int sport, unsigned long * pid, 314 314 char * user, size_t userlen) 315 315 { … … 320 320 else 321 321 fd = fopen("/proc/net/udp", "r"); 322 323 *pid = 0; 322 324 323 325 if (fd) … … 345 347 { 346 348 fclose(fd); 349 *pid = (unsigned long) new->pid; 347 350 if (new->path) 348 351 { … … 363 366 } 364 367 err_out: 365 sl_strlcpy(user, " 0", userlen);368 sl_strlcpy(user, "-", userlen); 366 369 return sh_util_strdup("-"); 367 370 } … … 750 753 751 754 char * sh_port2proc_query(int proto, struct in_addr * saddr, int sport, 752 char * user, size_t userlen)755 unsigned long * pid, char * user, size_t userlen) 753 756 { 754 757 int n, hash; … … 756 759 struct in_addr * haddr; 757 760 struct sock * s; 761 762 *pid = 0; 758 763 759 764 for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) { … … 796 801 struct sock_store try; 797 802 803 *pid = xf->xf_pid; 804 798 805 try.pid = xf->xf_pid; 799 806 try.path = NULL; … … 862 869 863 870 char * sh_port2proc_query(int proto, struct in_addr * saddr, int sport, 864 char * user, size_t userlen)871 unsigned long * pid, char * user, size_t userlen) 865 872 { 866 873 (void) proto; … … 868 875 (void) sport; 869 876 877 *pid = 0; 878 870 879 sl_strlcpy(user, "-", userlen); 871 880 return sh_util_strdup("-"); -
trunk/src/sh_portcheck.c
r180 r206 137 137 138 138 extern char * sh_port2proc_query(int proto, struct in_addr * saddr, int sport, 139 char * user, size_t userlen);139 unsigned long * pid, char * user, size_t userlen); 140 140 extern int sh_port2proc_prepare(); 141 141 … … 515 515 { 516 516 char * path; 517 unsigned long qpid; 517 518 char user[USER_MAX]; 518 519 … … 523 524 inet_ntoa(haddr), port, SH_PROTO_STR(proto), service); 524 525 #else 525 path = sh_port2proc_query(proto, &haddr, port, user, sizeof(user));526 path = sh_port2proc_query(proto, &haddr, port, &qpid, user, sizeof(user)); 526 527 SH_MUTEX_LOCK(mutex_thread_nolog); 527 528 sh_error_handle(sh_portchk_severity, FIL__, __LINE__, 0, 528 MSG_PORT_NEW, errbuf, path, user);529 MSG_PORT_NEW, errbuf, path, qpid, user); 529 530 SH_MUTEX_UNLOCK(mutex_thread_nolog); 530 531 SH_FREE(path); … … 538 539 { 539 540 char * path; 541 unsigned long qpid; 540 542 char user[USER_MAX]; 541 543 … … 545 547 fprintf(stderr, _("service: %s\n"), errbuf); 546 548 #else 547 path = sh_port2proc_query(proto, &haddr, port, user, sizeof(user));549 path = sh_port2proc_query(proto, &haddr, port, &qpid, user, sizeof(user)); 548 550 SH_MUTEX_LOCK(mutex_thread_nolog); 549 551 sh_error_handle(sh_portchk_severity, FIL__, __LINE__, 0, 550 MSG_PORT_RESTART, errbuf, path, user);552 MSG_PORT_RESTART, errbuf, path, qpid, user); 551 553 SH_MUTEX_UNLOCK(mutex_thread_nolog); 552 554 SH_FREE(path); … … 558 560 { 559 561 char * path; 562 unsigned long qpid; 560 563 char user[USER_MAX]; 561 564 … … 565 568 fprintf(stderr, _("service: %s\n"), errbuf); 566 569 #else 567 path = sh_port2proc_query(proto, &haddr, port, user, sizeof(user));570 path = sh_port2proc_query(proto, &haddr, port, &qpid, user, sizeof(user)); 568 571 SH_MUTEX_LOCK(mutex_thread_nolog); 569 572 sh_error_handle(sh_portchk_severity, FIL__, __LINE__, 0, 570 MSG_PORT_NEWPORT, errbuf, path, user);573 MSG_PORT_NEWPORT, errbuf, path, qpid, user); 571 574 SH_MUTEX_UNLOCK(mutex_thread_nolog); 572 575 SH_FREE(path); … … 585 588 { 586 589 char * path; 590 unsigned long qpid; 587 591 char user[USER_MAX]; 588 592 … … 593 597 inet_ntoa(haddr), port, SH_PROTO_STR(proto), check_services(port, proto)); 594 598 #else 595 path = sh_port2proc_query(proto, &haddr, port, user, sizeof(user));599 path = sh_port2proc_query(proto, &haddr, port, &qpid, user, sizeof(user)); 596 600 SH_MUTEX_LOCK(mutex_thread_nolog); 597 601 sh_error_handle(sh_portchk_severity, FIL__, __LINE__, 0, 598 MSG_PORT_NEW, errbuf, path, user);602 MSG_PORT_NEW, errbuf, path, qpid, user); 599 603 SH_MUTEX_UNLOCK(mutex_thread_nolog); 600 604 SH_FREE(path); … … 608 612 { 609 613 char * path; 614 unsigned long qpid; 610 615 char user[USER_MAX]; 611 616 … … 615 620 fprintf(stderr, _("port : %s\n"), errbuf); 616 621 #else 617 path = sh_port2proc_query(proto, &haddr, port, user, sizeof(user));622 path = sh_port2proc_query(proto, &haddr, port, &qpid, user, sizeof(user)); 618 623 SH_MUTEX_LOCK(mutex_thread_nolog); 619 624 sh_error_handle(sh_portchk_severity, FIL__, __LINE__, 0, 620 MSG_PORT_RESTART, errbuf, path, user);625 MSG_PORT_RESTART, errbuf, path, qpid, user); 621 626 SH_MUTEX_UNLOCK(mutex_thread_nolog); 622 627 SH_FREE(path); -
trunk/src/sh_prelude.c
r181 r206 696 696 int ret; 697 697 long port; 698 char *ptr, *new, *tmp, *ip, *srv, * end;698 char *ptr, *new, *tmp, *ip, *srv, *protocol, *end; 699 699 prelude_string_t *str; 700 700 idmef_address_t *address; … … 704 704 idmef_service_t *service; 705 705 idmef_source_t *source = idmef_alert_get_next_source(alert, NULL); 706 struct passwd *pw; 707 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 708 struct passwd pwd; 709 char buffer[SH_PWBUF_SIZE]; 710 #endif 706 711 707 712 new = sh_util_strdup(msg); … … 778 783 if ( *ptr && *end == '\0' && port >= 0 && port < 65536) { 779 784 785 char * tmpw; 786 780 787 if ( ! source ) { 781 788 ret = idmef_alert_new_source(alert, &source, IDMEF_LIST_APPEND); 782 789 if ( ret < 0 ) { 783 free(srv);784 790 SH_FREE( new ); 785 791 return ret; … … 789 795 ret = idmef_source_new_service(source, &service); 790 796 if ( ret < 0 ) { 791 free(srv);792 797 SH_FREE( new ); 793 798 return ret; … … 795 800 796 801 idmef_service_set_port(service, port); 802 803 ret = idmef_service_new_protocol(service, &str); 804 if ( ret < 0 ) { 805 SH_FREE( new ); 806 return ret; 807 } 808 809 ++tmp; 810 if (*tmp) { 811 char * tmpw = tmp; 812 char tmpw_store; 813 while (*tmpw && !isblank((int) *tmpw)) ++tmpw; 814 tmpw_store = *tmpw; *tmpw = '\0'; 815 protocol = strdup(tmp); 816 *tmpw = tmpw_store; 817 prelude_string_set_nodup(str, protocol); 818 } 819 797 820 } 798 821 … … 850 873 SH_FREE( new ); 851 874 852 ptr = get_value(msg, _("user "), NULL);875 ptr = get_value(msg, _("userid"), NULL); 853 876 854 877 if ( ptr ) { 855 878 879 idmef_user_id_t * user_id; 880 856 881 ret = idmef_source_new_user(source, &user); 857 882 if ( ret < 0 ) { … … 860 885 } 861 886 862 ret = idmef_user_new_ident(user, &str); 863 if ( ret < 0 ) { 864 free(ptr); 865 return ret; 866 } 887 idmef_user_set_category(user, IDMEF_USER_CATEGORY_APPLICATION); 888 889 ret = idmef_user_new_user_id(user, &user_id, IDMEF_LIST_APPEND); 890 if ( ret < 0 ) { 891 free(ptr); 892 return ret; 893 } 894 895 idmef_user_id_set_type(user_id, IDMEF_USER_ID_TYPE_CURRENT_USER); 896 897 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 898 sh_getpwnam_r(ptr, &pwd, buffer, sizeof(buffer), &pw); 899 #else 900 pw = sh_getpwnam(ptr); 901 #endif 902 if ( pw ) 903 idmef_user_id_set_number(user_id, pw->pw_uid); 904 905 ret = idmef_user_id_new_name(user_id, &str); 906 if ( ret < 0 ) { 907 free(ptr); 908 return ret; 909 } 867 910 prelude_string_set_nodup(str, ptr); 911 868 912 } 869 913 870 914 ptr = get_value(msg, _("path"), NULL); 915 tmp = get_value(msg, _("pid"), NULL); 871 916 872 917 if ( ptr ) { … … 889 934 prelude_string_set_nodup(str, ptr); 890 935 891 ptr = strrchr(ptr, '/');892 if ( ptr) {936 937 if ( NULL != strrchr(ptr, '/') ) { 893 938 ret = idmef_process_new_name(process, &str); 894 939 if ( ret == 0 ) { 940 ptr = strrchr(ptr, '/'); 895 941 prelude_string_set_dup(str, ptr + 1); 896 942 } 897 } 898 } 943 } else { 944 ret = idmef_process_new_name(process, &str); 945 if ( ret == 0 ) { 946 prelude_string_set_dup(str, ptr); 947 } 948 } 949 950 idmef_process_set_pid(process, strtoul(tmp, NULL, 0)); 951 } 952 953 if (tmp) 954 free(tmp); 899 955 900 956 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.