Ejemplo n.º 1
0
static switch_status_t do_config(switch_bool_t reload)
{
	/* Load up blacklists */
	switch_xml_t xml, cfg, lists, list;
	switch_hash_index_t *hi = NULL;
	
	if (!(xml = switch_xml_open_cfg("mod_blacklist.conf", &cfg, NULL))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load configuration section\n");
		return SWITCH_STATUS_FALSE;
	}
	
	switch_mutex_lock(globals.lists_mutex);
	
	/* Destroy any active lists */
	while ((hi = switch_core_hash_first_iter( globals.lists, hi))) {
		const void *key;
		void *val;
		switch_core_hash_this(hi, &key, NULL, &val);
		blacklist_free((blacklist_t*)val);
		switch_core_hash_delete(globals.lists, (const char*)key);
	}
	
	if ((lists = switch_xml_child(cfg, "lists"))) {
		for (list = switch_xml_child(lists, "list"); list; list = list->next) {
			const char *name = switch_xml_attr_soft(list, "name");
			const char *filename = switch_xml_attr_soft(list, "filename");

			if (zstr(name)) {
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "list has no name\n");
				continue;
			}
			if (zstr(filename)) {
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "list [%s] has no filename\n", name);
				continue;
			}

			load_list(name, filename);
		}
	}
	
	switch_mutex_unlock(globals.lists_mutex);
	
	if (xml) {
		switch_xml_free(xml);
		xml = NULL;
	}

	return SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 2
0
void server_free(server_t *server) {
  if (!server) {
    return;
  }
  
  linking_list_entry_t *ll_entry = server->linking_list;
  
  while (ll_entry) {
    linking_list_entry_t *next = ll_entry->next;
    //printf("free(%x,ll_entry)\n", (u_int)ll_entry);
    free(ll_entry);
    ll_entry = next;
  }
  
  blacklist_free(server->blacklist);
  
  //printf("free(%x,server)\n", (u_int)server);
  free(server);
}
Ejemplo n.º 3
0
void server_update(server_t *server, blacklist_t *blacklist, linking_token_t *linking_tokens) {
  blacklist_free(server->blacklist);
  server->blacklist = malloc(sizeof(blacklist_t));
  //printf("malloc(%x,blacklist)\n", (u_int)server->blacklist);

  blacklist_cpy(server->blacklist, blacklist);

  linking_token_t *linking_token = linking_tokens;
  
  while (linking_token) {
    linking_list_entry_t *ll_entry = malloc(sizeof(linking_list_entry_t));
    //printf("malloc(%x,ll_entry)\n", (u_int)ll_entry);
    
    ll_entry->time_period = linking_token->time_period;
    memcpy(ll_entry->trapdoor, linking_token->trapdoor, DIGEST_SIZE);
    memcpy(ll_entry->nymble, linking_token->nymble_ticket->nymble, DIGEST_SIZE);
    ll_entry->next       = server->linking_list;
    server->linking_list = ll_entry;

    linking_token = linking_token->next;
  }
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	char errbuf[PCAP_ERRBUF_SIZE];
	char *dev;
	struct iface_config *ifc;
	int optind;
	int i;


	bzero(&cfg, sizeof(cfg));

	/* Default configuration */
//	cfg.ratelimit = 0;
	cfg.hashsize = 1;
//	cfg.quiet = 0;
	cfg.promisc_flag = 1;
//	cfg.ratelimit = 0;
//	cfg.sqlite_file = NULL;
//	cfg.uname = NULL;
	cfg.shm_data.size = DEFAULT_SHM_LOG_SIZE;
	cfg.shm_data.name = DEFAULT_SHM_LOG_NAME;
#if HAVE_LIBSQLITE3
	cfg.sqlite_table = PACKAGE;
#endif
	log_open(PACKAGE_NAME);
	argp_parse(&argp, argc, argv, 0, &optind, 0);

	if (!cfg.hostname) {
		cfg.hostname_len = sysconf(_SC_HOST_NAME_MAX);
		cfg.hostname = (char *)calloc(cfg.hostname_len, sizeof(char));
		gethostname(cfg.hostname, cfg.hostname_len);
	}

	daemonize();
	save_pid();

	libevent_init();


	if (cfg.ratelimit > 0)
		log_msg(LOG_DEBUG, "Ratelimiting duplicate entries to 1 per %d seconds", cfg.ratelimit);
	else if (cfg.ratelimit == -1)
		log_msg(LOG_DEBUG, "Duplicate entries supressed indefinitely");
	else
		log_msg(LOG_DEBUG, "Duplicate entries ratelimiting disabled");

	if (cfg.promisc_flag)
		log_msg(LOG_DEBUG, "PROMISC mode enabled");
	else
		log_msg(LOG_DEBUG, "PROMISC mode disabled");

	if (argc > optind) {
		for (i = optind; i < argc; i++)
			add_iface(argv[i]);
	} else {
		dev = pcap_lookupdev(errbuf);
		if (dev != NULL)
			add_iface(dev);
	}

	if (!cfg.interfaces)
		log_msg(LOG_ERR, "No suitable interfaces found!");

	if (cfg.uname)
		drop_root(cfg.uname);

	output_flatfile_init();
	output_sqlite_init();
	output_shm_init();

	/* main loop */
#if HAVE_LIBEVENT2
	event_base_dispatch(cfg.eb);
#else
	event_dispatch();
#endif

	output_shm_close();
	output_sqlite_close();
	output_flatfile_close();

	for (ifc = cfg.interfaces; ifc != NULL; ifc = del_iface(ifc));


	libevent_close();
	log_close();

	del_pid();
	blacklist_free();

	free(cfg.hostname);

	return 0;
}