Esempio n. 1
0
static int load_module(xml_node *config) {

	xml_node *params, *profile=NULL, *settings;
	char *key, *value = NULL;
	unsigned int i = 0;
	//char module_api_name[256];
	char loadplan[1024];
	FILE* cfg_stream;

	LNOTICE("Loaded %s", module_name);

	load_module_xml_config();

	/* READ CONFIG */
	profile = module_xml_config;

	/* reset profile */
	profile_size = 0;

	while (profile) {

		profile = xml_get("profile", profile, 1);

		memset(&profile_socket[i], 0, sizeof(profile_socket_t));

		if (profile == NULL)
			break;

		if (!profile->attr[4] || strncmp(profile->attr[4], "enable", 6)) {
			goto nextprofile;
		}

		/* if not equals "true" */
		if (!profile->attr[5] || strncmp(profile->attr[5], "true", 4)) {
			goto nextprofile;
		}

		/* set values */
		profile_socket[profile_size].name = strdup(profile->attr[1]);
		profile_socket[profile_size].description = strdup(profile->attr[3]);
		profile_socket[profile_size].serial = atoi(profile->attr[7]);
		profile_socket[profile_size].protocol = PROTO_SIP; //we extract SIP and send as SIP packet
		profile_socket[profile_size].port = TZSP_PORT;
		profile_socket[profile_size].host = TZSP_HOST;
		
		/* SETTINGS */
		settings = xml_get("settings", profile, 1);

		if (settings != NULL) {

			params = settings;

			while (params) {

				params = xml_get("param", params, 1);
				if (params == NULL)
					break;

				if (params->attr[0] != NULL) {

					/* bad parser */
					if (strncmp(params->attr[0], "name", 4)) {
						LERR("bad keys in the config");
						goto nextparam;
					}

					key = params->attr[1];

					if (params->attr[2] && params->attr[3] && !strncmp(params->attr[2], "value", 5)) {
						value = params->attr[3];
					} else {
						value = params->child->value;
					}

					if (key == NULL || value == NULL) {
						LERR("bad values in the config");
						goto nextparam;

					}

					if (!strncmp(key, "host", 4))
						profile_socket[profile_size].host = strdup(value);
					else if (!strncmp(key, "port", 4))
						profile_socket[profile_size].port = strdup(value);
					else if (!strncmp(key, "protocol-type", 13))
						profile_socket[profile_size].protocol = atoi(value);						
					else if (!strncmp(key, "capture-plan", 12))
						profile_socket[profile_size].capture_plan = strdup(value);
				}

				nextparam: params = params->next;

			}
		}
		
		profile_size++;

		nextprofile: profile = profile->next;
	}

	/* free */		
		
	free_module_xml_config();

#if UV_VERSION_MAJOR == 0
    loop = uv_loop_new();
#else               
    loop = malloc(sizeof *loop);
    uv_loop_init(loop);
#endif

	for (i = 0; i < profile_size; i++) {

		if(profile_socket[i].capture_plan != NULL)
		{

			snprintf(loadplan, sizeof(loadplan), "%s/%s", global_capture_plan_path, profile_socket[i].capture_plan);
			cfg_stream=fopen (loadplan, "r");

			if (cfg_stream==0){
			   fprintf(stderr, "ERROR: loading config file(%s): %s\n", loadplan, strerror(errno));
			}

			yyin=cfg_stream;
			if ((yyparse()!=0)||(cfg_errors)){
			          fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
			}

			profile_socket[i].action = main_ct.idx;
		}

		// start thread
		if (init_socket(i)) {
			LERR("couldn't init tzsp");
			return -1;
		}

		//pthread_create(&call_thread, NULL, proto_collect, arg);

	}
	
	uv_async_init(loop, &async_handle, _async_callback);
	uv_thread_create(&runthread, _run_uv_loop, loop);

	return 0;
}
Esempio n. 2
0
static int load_module(xml_node *config) {
	xml_node *params, *profile, *settings;
	char *key, *value = NULL;

	LNOTICE("Loaded %s", module_name);

	load_module_xml_config();
	/* READ CONFIG */
	profile = module_xml_config;

	/* reset profile */
	profile_size = 0;

	while (profile) {

		profile = xml_get("profile", profile, 1);

		if (profile == NULL)
			break;

		if (!profile->attr[4] || strncmp(profile->attr[4], "enable", 6)) {
			goto nextprofile;
		}

		/* if not equals "true" */
		if (!profile->attr[5] || strncmp(profile->attr[5], "true", 4)) {
			goto nextprofile;
		}

		/* set values */
		profile_protocol[profile_size].name = strdup(profile->attr[1]);
		profile_protocol[profile_size].description = strdup(profile->attr[3]);
		profile_protocol[profile_size].serial = atoi(profile->attr[7]);

		/* SETTINGS */
		settings = xml_get("settings", profile, 1);

		if (settings != NULL) {

			params = settings;

			while (params) {

				params = xml_get("param", params, 1);
				if (params == NULL)
					break;

				if (params->attr[0] != NULL) {

					/* bad parser */
					if (strncmp(params->attr[0], "name", 4)) {
						LERR("bad keys in the config");
						goto nextparam;
					}

					key = params->attr[1];

					if (params->attr[2] && params->attr[3] && !strncmp(params->attr[2], "value", 5)) {
						value = params->attr[3];
					} else {
						value = params->child->value;
					}

					if (key == NULL || value == NULL) {
						LERR("bad values in the config");
						goto nextparam;

					}

					/*
					if (!strncmp(key, "ignore", 6))
						profile_protocol[profile_size].ignore = strdup(value);
					else if (!strncmp(key, "dialog-type", 11))
						profile_protocol[profile_size].dialog_type = atoi(value);
					else if (!strncmp(key, "dialog-timeout", 14))
						profile_protocol[profile_size].dialog_timeout = atoi(value);
						*/

				}

				nextparam: params = params->next;

			}
		}

		profile_size++;

		nextprofile: profile = profile->next;
	}

	/* free it */
	free_module_xml_config();


	return 0;
}
Esempio n. 3
0
static int load_module(xml_node *config) {

	char errbuf[PCAP_ERRBUF_SIZE];
	xml_node *params, *profile=NULL, *settings;
	char *key, *value = NULL;
	unsigned int i = 0;
	char loadplan[1024];
        FILE* cfg_stream;

	LNOTICE("Loaded %s", module_name);

	load_module_xml_config();

	/* READ CONFIG */
	profile = module_xml_config;

	/* reset profile */
	profile_size = 0;

	memset(sniffer_proto, 0, sizeof sniffer_proto);
	        
	
	//global_scripts_path


	while (profile) {

		profile = xml_get("profile", profile, 1);

		if (profile == NULL)
			break;

		if (!profile->attr[4] || strncmp(profile->attr[4], "enable", 6)) {
			goto nextprofile;
		}

		/* if not equals "true" */
		if (!profile->attr[5] || strncmp(profile->attr[5], "true", 4)) {
			goto nextprofile;
		}

		if(profile_size == MAX_SOCKETS) {
			break;
		}

		memset(&profile_socket[profile_size], 0, sizeof(profile_socket_t));

		/* set values */
		profile_socket[profile_size].name = strdup(profile->attr[1]);
		profile_socket[profile_size].description = strdup(profile->attr[3]);
		profile_socket[profile_size].serial = atoi(profile->attr[7]);
		profile_socket[profile_size].capture_plan = NULL;
		profile_socket[profile_size].capture_filter = NULL;
		profile_socket[profile_size].action = -1;
		profile_socket[profile_size].ring_buffer = 12;
		profile_socket[profile_size].snap_len = 3200;
		profile_socket[profile_size].promisc = 1;
		profile_socket[profile_size].timeout = 100;
		profile_socket[profile_size].full_packet = 0;
		profile_socket[profile_size].reasm = 0;         		                
		profile_socket[profile_size].erspan = 0;

		/* SETTINGS */
		settings = xml_get("settings", profile, 1);

		if (settings != NULL) {

			params = settings;

			while (params) {

				params = xml_get("param", params, 1);
				if (params == NULL)
					break;

				if (params->attr[0] != NULL) {

					/* bad parser */
					if (strncmp(params->attr[0], "name", 4)) {
						LERR("bad keys in the config");
						goto nextparam;
					}

					key = params->attr[1];

					if (params->attr[2] && params->attr[3] && !strncmp(params->attr[2], "value", 5)) {
						value = params->attr[3];
					} else {
						value = params->child->value;
					}

					if (key == NULL || value == NULL) {
						LERR("bad values in the config");
						goto nextparam;
					}


					if (!usefile && !strncmp(key, "dev", 3))
						profile_socket[profile_size].device = strdup(value);
					else if (!strncmp(key, "reasm", 5) && !strncmp(value, "true", 4))
						profile_socket[profile_size].reasm = +1;
                                        else if (!strncmp(key, "ipv4fragments", 13) && !strncmp(value, "true", 4))
						ipv4fragments = 1;
                                        else if (!strncmp(key, "ipv6fragments", 13) && !strncmp(value, "true", 4))
						ipv6fragments = 1;
                                        else if(!strncmp(key, "tcpdefrag", 9) && !strncmp(value, "true", 4))
                                                profile_socket[profile_size].reasm +=2;                                                    						
					else if (!strncmp(key, "ring-buffer", 11))					        
						profile_socket[profile_size].ring_buffer = atoi(value);		
					else if (!strncmp(key, "full-packet",11) && !strncmp(value, "true", 4))					        
						profile_socket[profile_size].full_packet = 1;												
					else if (!strncmp(key, "timeout", 7))					        
						profile_socket[profile_size].timeout = atoi(value);												
					else if (!strncmp(key, "snap-len", 8))					        
						profile_socket[profile_size].snap_len = atoi(value);												
					else if (!strncmp(key, "promisc", 7) && !strncmp(value, "true", 4))
						profile_socket[profile_size].promisc = 1;
					else if (!strncmp(key, "filter", 6))
						profile_socket[profile_size].filter = strdup(value);
					else if (!strncmp(key, "capture-plan", 12))
						profile_socket[profile_size].capture_plan = strdup(value);
                                        else if (!strncmp(key, "capture-filter", 14))
						profile_socket[profile_size].capture_filter = strdup(value);
					else if(!strncmp(key, "debug", 5) && !strncmp(value, "true", 4))
                                                debug_socket_pcap_enable = 1;	
					else if (!strncmp(key, "erspan", 6) && !strncmp(value, "true", 4))
						profile_socket[profile_size].erspan = 1;
				}

				nextparam: params = params->next;

			}
		}

		profile_size++;

		nextprofile: profile = profile->next;
	}

	/* free */
	free_module_xml_config();

	for (i = 0; i < profile_size; i++) {

		unsigned int *arg = malloc(sizeof(arg));		

		*arg = i;
		
		/* DEV || FILE */
		if (!usefile) {
			if (!profile_socket[i].device)
				profile_socket[i].device = pcap_lookupdev(errbuf);
			if (!profile_socket[i].device) {
				perror(errbuf);
				exit(-1);
			}
		}
		
		// start thread
		if (!init_socket(i)) {
			LERR("couldn't init pcap");
			return -1;
		}

		 /* REASM */
                if (profile_socket[i].reasm == 1 || profile_socket[i].reasm == 3) {
                        reasm[i] = reasm_ip_new();
                        reasm_ip_set_timeout(reasm[i], 30000000);
                }
                else reasm[i] = NULL;

                /* TCPREASM */
                if (profile_socket[i].reasm == 2 || profile_socket[i].reasm == 3) {
                        tcpreasm[i] = tcpreasm_ip_new ();
                        tcpreasm_ip_set_timeout(tcpreasm[i], 30000000);
                }
                else tcpreasm[i] = NULL;

		if(profile_socket[i].capture_plan != NULL)
		{

			snprintf(loadplan, sizeof(loadplan), "%s/%s", global_capture_plan_path, profile_socket[i].capture_plan);

						cfg_stream=fopen (loadplan, "r");
			if (cfg_stream==0){
			   fprintf(stderr, "ERROR: loading config file(%s): %s\n", loadplan, strerror(errno));
			}

			yyin=cfg_stream;
			if ((yyparse()!=0)||(cfg_errors)){
			          fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
			          //goto error;
			}

			profile_socket[i].action = main_ct.idx;
			
		}

		pthread_create(&call_thread[i], NULL, proto_collect, arg);		
	}

	return 0;
}
Esempio n. 4
0
static int load_module(xml_node *config) {
	xml_node *params, *profile, *settings, *condition, *action;
	char *key, *value = NULL;
	unsigned int i = 0;
	char module_api_name[256];

	LNOTICE("Loaded %s", module_name);

	load_module_xml_config();
	/* READ CONFIG */
	profile = module_xml_config;

	/* reset profile */
	profile_size = 0;

	while (profile) {

		profile = xml_get("profile", profile, 1);

		if (profile == NULL)
			break;

		if(!profile->attr[4] || strncmp(profile->attr[4], "enable", 6)) {
			goto nextprofile;
		}

		/* if not equals "true" */
		if(!profile->attr[5] || strncmp(profile->attr[5], "true", 4)) {
			goto nextprofile;
		}

		/* set values */
		profile_transport[profile_size].name = strdup(profile->attr[1]);
		profile_transport[profile_size].description = strdup(profile->attr[3]);
		profile_transport[profile_size].serial = atoi(profile->attr[7]);
		profile_transport[profile_size].statistic_pipe = NULL;
		profile_transport[profile_size].flag = 1;

		/* SETTINGS */
		settings = xml_get("settings", profile, 1);

		if (settings != NULL) {

			params = settings;

			while (params) {

				params = xml_get("param", params, 1);
				if (params == NULL) break;

				if (params->attr[0] != NULL) {

					/* bad parser */
					if (strncmp(params->attr[0], "name", 4)) {
						LERR("bad keys in the config");
						goto nextparam;
					}

					key = params->attr[1];

					if(params->attr[2] && params->attr[3] && !strncmp(params->attr[2], "value", 5)) {
							value = params->attr[3];
					}
					else {
						value = params->child->value;
					}

					if (key == NULL || value == NULL) {
						LERR("bad values in the config");
						goto nextparam;

					}

					if(!strncmp(key, "capture-host", 10)) profile_transport[profile_size].capt_host = strdup(value);
					else if(!strncmp(key, "capture-port", 13)) profile_transport[profile_size].capt_port = strdup(value);
					else if(!strncmp(key, "capture-proto", 14)) profile_transport[profile_size].capt_proto = strdup(value);
					else if(!strncmp(key, "capture-password", 17)) profile_transport[profile_size].capt_password = strdup(value);
					else if(!strncmp(key, "capture-id", 11)) profile_transport[profile_size].capt_id = atoi(value);
					else if(!strncmp(key, "payload-compression", 19) && !strncmp(value, "true", 5)) profile_transport[profile_size].compression = 1;
					else if(!strncmp(key, "version", 7)) profile_transport[profile_size].version = atoi(value);
					else if(!strncmp(key, "payload-send", 12) && !strncmp(value, "false", 5)) profile_transport[profile_size].flag = 0;


					//if (!strncmp(key, "ignore", 6))
					//	profile_transport[profile_size].ignore = value;
				}

				nextparam:
					params = params->next;

			}
		}


		/* STATS */

		condition = xml_get("statistic", profile, 1);

		while (condition) {

			condition = xml_get("condition", condition, 1);

			if (condition == NULL)	break;

			if (condition->attr[0] != NULL && condition->attr[2] != NULL) {

						/* bad parser */
						if (strncmp(condition->attr[0], "field", 5) || strncmp(condition->attr[2], "expression", 10)) {
							LERR("bad keys in the config");
							goto nextstatistic;
						}

						key = condition->attr[1];
						value = condition->attr[3];

						if (key == NULL || value == NULL) {
							LERR("bad values in the config");
							goto nextstatistic;
						}

						action = condition->child;
						if (action && !strncmp(action->key, "action", 6)) {
							for (i = 0; action->attr[i]; i++) {
								if (!strncmp(action->attr[i], "application", 4)) {
									profile_transport[profile_size].statistic_pipe = strdup(action->attr[i + 1]);
								}
								else if (!strncmp(action->attr[i], "profile", 7)) {
									profile_transport[profile_size].statistic_profile = strdup(action->attr[i + 1]);
								}
							}
						}
			}

			nextstatistic: condition = condition->next;
		}

		profile_size++;

		nextprofile:
			profile = profile->next;
	}

	/* free it */
	free_module_xml_config();

	for (i = 0; i < profile_size; i++) {

#ifndef USE_ZLIB
			if(profile_transport[i].compression) {
				printf("The captagent has not compiled with zlib. Please reconfigure with --enable-compression\n");
				LERR("The captagent has not compiled with zlib. Please reconfigure with --enable-compression");
			}
#endif /* USE_ZLIB */

			/*TLS || SSL*/
			if(!strncmp(profile_transport[i].capt_proto, "ssl", 3)) {

#ifdef USE_SSL
				profile_transport[i].usessl = 1;
				/* init SSL library */
				if(sslInit == 0) {
					SSL_library_init();
					sslInit = 1;
				}
#else
				printf("The captagent has not compiled with ssl support. Please reconfigure with --enable-ssl\n");
				LERR("The captagent has not compiled with ssl support. Please reconfigure with --enable-ssl");

#endif /* end USE_SSL */
			}

			if(!profile_transport[i].usessl) {
				if(init_jsonsocket_blocking(i)) {
					LERR("capture: couldn't init socket");
				}
			}

#ifdef USE_SSL
			else {
				if(initSSL(i)) {
					LERR("capture: couldn't init SSL socket");
				}
			}
#endif /* use SSL */

			if(profile_transport[i].statistic_pipe) {
				snprintf(module_api_name, 256, "%s_bind_api", profile_transport[i].statistic_pipe);
				//stats_bind_api = (bind_statistic_module_api_t) find_export(module_api_name, 1, 0);
				//stats_bind_api(&profile_transport[i].stats_api);
			}
	}

	sigPipe();

	return 0;
}