- Timestamp:
- May 4, 2010, 10:28:11 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_error.c
r272 r283 841 841 #ifdef SH_WITH_SERVER 842 842 static char inet_peer[SH_MINIBUF] = { '\0' }; 843 #ifdef HAVE_LIBPRELUDE 844 static char inet_peer_ip[SH_IP_BUF] = { '\0' }; 845 846 void sh_error_set_peer_ip(const char * str) 847 { 848 if (str == NULL) 849 inet_peer_ip[0] = '\0'; 850 else 851 sl_strlcpy(inet_peer_ip, str, sizeof(inet_peer_ip)); 852 } 853 #endif 843 854 844 855 void sh_error_set_peer(const char * str) … … 847 858 inet_peer[0] = '\0'; 848 859 else 849 sl_strlcpy(inet_peer, str, SH_MINIBUF);860 sl_strlcpy(inet_peer, str, sizeof(inet_peer)); 850 861 } 851 862 #endif … … 880 891 int class_inet = clt_class; /* initialize from global */ 881 892 char local_inet_peer[SH_MINIBUF]; 893 #ifdef HAVE_LIBPRELUDE 894 char local_inet_peer_ip[SH_IP_BUF]; 895 #endif 882 896 #endif 883 897 … … 924 938 if ((msg_id == MSG_TCP_MSG) && (inet_peer[0] != '\0')) 925 939 { 926 sl_strlcpy(local_inet_peer, inet_peer, SH_MINIBUF);940 sl_strlcpy(local_inet_peer, inet_peer, sizeof(local_inet_peer)); 927 941 sh_error_set_peer(NULL); 928 942 } 929 943 else 930 944 local_inet_peer[0] = '\0'; 945 946 #ifdef HAVE_LIBPRELUDE 947 if ((msg_id == MSG_TCP_MSG) && (inet_peer_ip[0] != '\0')) 948 { 949 sl_strlcpy(local_inet_peer_ip, inet_peer_ip, sizeof(local_inet_peer_ip)); 950 sh_error_set_peer_ip(NULL); 951 } 952 else 953 local_inet_peer_ip[0] = '\0'; 954 #endif 931 955 932 956 clt_class = (-1); /* reset global */ … … 1263 1287 * Reports first error after failure. Always tries. 1264 1288 */ 1265 (void) sh_prelude_alert (severity, (int) class, lmsg->msg, 1266 lmsg->status, msg_id); 1267 1289 #if defined(HAVE_LIBPRELUDE) && defined(SH_WITH_SERVER) 1290 (void) sh_prelude_alert (severity, (int) class, 1291 lmsg->msg, lmsg->status, msg_id, 1292 local_inet_peer_ip); 1293 #else 1294 (void) sh_prelude_alert (severity, (int) class, 1295 lmsg->msg, lmsg->status, msg_id, 1296 NULL); 1297 #endif 1268 1298 prelude_block = 0; 1269 1299 } … … 1301 1331 (void) sh_log_file (lmsg->msg, NULL); 1302 1332 else 1303 1333 (void) sh_log_file (lmsg->msg, local_inet_peer); 1304 1334 } 1305 1335 #else -
trunk/src/sh_forward.c
r270 r283 3661 3661 /* push client name to error routine 3662 3662 */ 3663 #if defined(SH_WITH_SERVER) && defined(HAVE_LIBPRELUDE) 3664 sh_error_set_peer_ip( inet_ntoa (*(struct in_addr *) &(conn->addr_peer.sin_addr)) ); 3665 #endif 3663 3666 sh_error_set_peer(sh_strip_domain (conn->peer)); 3664 3667 sh_error_handle(clt_sev, FIL__, __LINE__, 0, MSG_TCP_MSG, … … 3666 3669 ptok); 3667 3670 sh_error_set_peer(NULL); 3668 3671 #if defined(SH_WITH_SERVER) && defined(HAVE_LIBPRELUDE) 3672 sh_error_set_peer_ip(NULL); 3673 #endif 3674 3669 3675 TPT((0, FIL__, __LINE__, _("msg=<%s>\n"), ptok)); 3670 3676 SH_FREE(ptok); -
trunk/src/sh_prelude.c
r227 r283 219 219 { 220 220 char *ret = NULL; 221 221 #if defined(SH_WITH_SERVER) 222 int delim_start_count = 0; 223 int found = 0; 224 #endif 225 222 226 ptr = strchr(ptr, delim_start); 223 227 if ( ! ptr ) … … 225 229 226 230 ret = ++ptr; 227 231 #if defined(SH_WITH_SERVER) 232 while ((*ptr != '\0') && (!found)){ 233 if (*ptr == delim_end) { 234 if (delim_start_count == 0) 235 found = 1; 236 delim_start_count--; 237 } 238 else if (*ptr == delim_start) 239 delim_start_count++; 240 ptr++; 241 } 242 ptr = (found) ? ptr-1 : NULL ; 243 #else 228 244 ptr = strchr(ptr, delim_end); 245 #endif 229 246 if ( ! ptr ) 230 247 return NULL; … … 555 572 556 573 free(uid); 574 /* Don't free(ptr) because of prelude_string_set_nodup(str, ptr) */ 557 575 } 558 576 … … 597 615 598 616 free(gid); 617 /* Don't free(ptr) because of prelude_string_set_nodup(str, ptr) */ 599 618 } 600 619 … … 683 702 return -1; 684 703 } 685 704 705 #if defined(SH_WITH_SERVER) 706 /* when using yule, theres a msg=<... msg=<...> >*/ 707 do { 708 msg = ptr; 709 ptr = get_value(msg, _("msg"), NULL); 710 if ( ! ptr ) { 711 ptr = msg; 712 break; 713 } else { 714 free(msg); 715 } 716 } while (1); 717 #endif 718 686 719 ret = prelude_string_cat(out, ptr); 687 720 free(ptr); … … 1115 1148 1116 1149 1150 static int node_set_address(idmef_node_t *node, const char *addr) 1151 { 1152 int ret; 1153 prelude_string_t *prelude_str; 1154 idmef_address_t *idmef_addr; 1155 1156 ret = prelude_string_new(&prelude_str); 1157 if ( ret < 0 ) 1158 goto err; 1159 1160 ret = prelude_string_set_ref(prelude_str, addr); 1161 if ( ret < 0 ) 1162 goto err; 1163 1164 ret = idmef_address_new(&idmef_addr); 1165 if ( ret < 0 ) 1166 goto err; 1167 1168 idmef_address_set_category(idmef_addr, IDMEF_ADDRESS_CATEGORY_IPV4_ADDR); 1169 idmef_address_set_address(idmef_addr, prelude_str); 1170 idmef_node_set_address(node, idmef_addr, 0); 1171 1172 return 0; 1173 err: 1174 return -1; 1175 } 1176 1177 1178 1117 1179 static int samhain_alert_prelude(int priority, int sh_class, 1118 char *message, unsigned long msgid )1180 char *message, unsigned long msgid, char * inet_peer_ip) 1119 1181 { 1120 1182 int ret; … … 1129 1191 idmef_confidence_t *confidence; 1130 1192 prelude_string_t *str; 1193 #if defined(SH_WITH_SERVER) 1194 idmef_node_t *node; 1195 #endif 1131 1196 1132 1197 if ( !client || sh_class == STAMP) … … 1162 1227 1163 1228 idmef_target_set_decoy(target, IDMEF_TARGET_DECOY_NO); 1164 1229 1230 #if defined(SH_WITH_SERVER) 1231 if ( inet_peer_ip != NULL){ 1232 ret = idmef_target_new_node(target, &node); 1233 1234 ret = node_set_address(node, inet_peer_ip); 1235 if ( ret < 0 ) 1236 goto err; 1237 1238 idmef_target_set_node(target, idmef_node_ref(node)); 1239 } 1240 else 1165 1241 if ( idmef_analyzer_get_node(prelude_client_get_analyzer(client)) ) { 1166 1242 idmef_node_ref(idmef_analyzer_get_node(prelude_client_get_analyzer(client))); 1167 1243 idmef_target_set_node(target, idmef_analyzer_get_node(prelude_client_get_analyzer(client))); 1168 1244 } 1169 1245 #else 1246 if ( idmef_analyzer_get_node(prelude_client_get_analyzer(client)) ) { 1247 idmef_node_ref(idmef_analyzer_get_node(prelude_client_get_analyzer(client))); 1248 idmef_target_set_node(target, idmef_analyzer_get_node(prelude_client_get_analyzer(client))); 1249 } 1250 #endif 1170 1251 if ( strstr(message, _("path=")) ) { 1171 1252 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE) … … 1248 1329 1249 1330 1250 int sh_prelude_alert(int priority, int sh_class, char *message, long msgflags, unsigned long msgid )1331 int sh_prelude_alert(int priority, int sh_class, char *message, long msgflags, unsigned long msgid, char *inet_peer_ip) 1251 1332 { 1252 1333 int ret; … … 1257 1338 return -1; 1258 1339 1259 ret = samhain_alert_prelude(priority, sh_class, message, msgid );1340 ret = samhain_alert_prelude(priority, sh_class, message, msgid, inet_peer_ip); 1260 1341 if ( ret < 0 ) { 1261 1342 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
Note:
See TracChangeset
for help on using the changeset viewer.