Esempio n. 1
0
void run_28_bit_record_tests(int mode, const char *mode_desc)
{
    const char *filename = "MaxMind-DB-test-mixed-28.mmdb";
    const char *path = test_database_path(filename);
    MMDB_s *mmdb = open_ok(path, mode, mode_desc);
    free((void *)path);

    const uint32_t tests[7][5] = {
        { 0,   1,   MMDB_RECORD_TYPE_SEARCH_NODE, 242,
          MMDB_RECORD_TYPE_EMPTY },
        { 80,  81,  MMDB_RECORD_TYPE_SEARCH_NODE, 197,
          MMDB_RECORD_TYPE_SEARCH_NODE, },
        { 96,  97,  MMDB_RECORD_TYPE_SEARCH_NODE, 242,
          MMDB_RECORD_TYPE_EMPTY, },
        { 103, 242, MMDB_RECORD_TYPE_EMPTY,       104,
          MMDB_RECORD_TYPE_SEARCH_NODE, },
        { 127, 242, MMDB_RECORD_TYPE_EMPTY,       315,
          MMDB_RECORD_TYPE_DATA, },
        { 132, 329, MMDB_RECORD_TYPE_DATA,       242,
          MMDB_RECORD_TYPE_EMPTY, },
        { 241, 96,  MMDB_RECORD_TYPE_SEARCH_NODE, 242,
          MMDB_RECORD_TYPE_EMPTY, }
    };
    run_read_node_tests(mmdb, tests, 7, 28);

    MMDB_close(mmdb);
    free(mmdb);
}
Esempio n. 2
0
static void geoip2_compat_internal_close(MMDB_s* mmdb)
{
  if(mmdb->file_content) {
    MMDB_close(mmdb);
  }
  mmdb->file_content = NULL;
}
Esempio n. 3
0
List maxmind_bindings::call_maxmind(std::vector < std::string > ip_addresses, const char* file,
                                    std::vector < std::string > fields){
  
  //Open file
  MMDB_s geo_file;
  int result;
  result = MMDB_open(file, 0, &geo_file);
  if(result != MMDB_SUCCESS){
    throw std::range_error("The geolocation database could not be opened");
  }
  
  //Create references and holding
  std::vector < std::string >& ip_ref = ip_addresses;
  int input_size = ip_addresses.size();
  IntegerVector rownames(input_size);
  rownames = Rcpp::seq(1,input_size);
  
  List output = lookup(ip_ref, &geo_file, fields);
  output.attr("class") = "data.frame";
  output.attr("names") = fields;
  output.attr("row.names") = rownames;
  
  //Close and return
  MMDB_close(&geo_file);
  return output;
}
// close gets called by varnish when then the treads destroyed
void close_mmdb(void *mmdb_handle)
{
    // don't do anything if the db didn't open correctly.
    if (mmdb_handle == NULL) {
        return;
    }
    MMDB_s *handle = (MMDB_s *)mmdb_handle;
    MMDB_close(handle);
}
Esempio n. 5
0
F_NONNULL
static void geoip2_destroy(geoip2_t* db) {
    MMDB_close(&db->mmdb);
    free(db->map_name);
    free(db->pathname);
    for(unsigned i = 0; i < OFFSET_CACHE_SIZE; i++)
        free(db->offset_cache[i]);
    free(db);
}
Esempio n. 6
0
static PyObject *Reader_close(PyObject *self, PyObject *UNUSED(args))
{
    Reader_obj *mmdb_obj = (Reader_obj *)self;

    if (NULL != mmdb_obj->mmdb) {
        MMDB_close(mmdb_obj->mmdb);
        free(mmdb_obj->mmdb);
        mmdb_obj->mmdb = NULL;
    }

    Py_RETURN_NONE;
}
Esempio n. 7
0
vmod_geoip2__fini(struct vmod_geoip2_geoip2 **vpp)
{
	struct vmod_geoip2_geoip2 *vp;

	if (!*vpp)
		return;

	vp = *vpp;
	*vpp = NULL;
	CHECK_OBJ_NOTNULL(vp, VMOD_GEOIP2_MAGIC);
	MMDB_close(&vp->mmdb);
	FREE_OBJ(vp);
}
static void
ngx_http_geoip2_cleanup(void *data)
{
    ngx_http_geoip2_conf_t  *gcf = data;
    ngx_uint_t              i;
    ngx_http_geoip2_db_t    *database;

    if (gcf->databases != NULL) {
        database = gcf->databases->elts;

        for (i = 0; i < gcf->databases->nelts; i++) {
            MMDB_close(&database[i].mmdb);
        }

        ngx_array_destroy(gcf->databases);
    }
}
Esempio n. 9
0
void run_tests(int mode, const char *mode_desc)
{
    const char *file = "MaxMind-DB-test-ipv4-24.mmdb";
    const char *path = test_database_path(file);
    MMDB_s *mmdb = open_ok(path, mode, mode_desc);

    // All of the remaining tests require an open mmdb
    if (NULL == mmdb) {
        diag("could not open %s - skipping remaining tests", path);
        return;
    }
    free((void *)path);

    test_metadata(mmdb, mode_desc);
    test_metadata_as_data_entry_list(mmdb, mode_desc);

    MMDB_close(mmdb);
    free(mmdb);
}
Esempio n. 10
0
void test_simple_structure(int mode, const char *mode_desc)
{
    const char *filename = "MaxMind-DB-test-decoder.mmdb";
    const char *path = test_database_path(filename);
    MMDB_s *mmdb = open_ok(path, mode, mode_desc);
    free((void *)path);

    const char *ip = "1.1.1.1";
    MMDB_lookup_result_s result =
        lookup_string_ok(mmdb, ip, filename, mode_desc);

    {
        MMDB_entry_data_s entry_data;
        const char *lookup_path[] = { "array", "0", NULL };
        int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
        test_array_0_result(status, entry_data, "MMDB_aget_value");

        status = MMDB_get_value(&result.entry, &entry_data, "array", "0", NULL);
        test_array_0_result(status, entry_data, "MMDB_get_value");

        status = call_vget_value(&result.entry, &entry_data, "array", "0", NULL);
        test_array_0_result(status, entry_data, "MMDB_vget_value");
    }

    {
        MMDB_entry_data_s entry_data;
        const char *lookup_path[] = { "array", "2", NULL };
        int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
        test_array_2_result(status, entry_data, "MMDB_aget_value");

        status = MMDB_get_value(&result.entry, &entry_data, "array", "2", NULL);
        test_array_2_result(status, entry_data, "MMDB_get_value");

        status = call_vget_value(&result.entry, &entry_data, "array", "2", NULL);
        test_array_2_result(status, entry_data, "MMDB_vget_value");
    }

    MMDB_close(mmdb);
    free(mmdb);
}
Esempio n. 11
0
int main(void)
{
	int gai_error, mmdb_error;
	MMDB_s mmdb;
	char *ip = "8.8.8.8";
	int status = MMDB_open("/home/lannister/Documentos/GeoLite2-City.mmdb", MMDB_MODE_MMAP, &mmdb);

	if (MMDB_SUCCESS != status) { 
		printf("Fail WTF"); 
	}

	MMDB_lookup_result_s result = MMDB_lookup_string(&mmdb, ip, &gai_error, &mmdb_error);

	if (MMDB_SUCCESS != mmdb_error) { 
		printf("Fail WTF2"); 
	}

	int exit_code = 0;
	char *country = NULL;

	MMDB_entry_data_s entry_data;

	status = MMDB_get_value(&result.entry, &entry_data,"city","names","es", NULL);
	if (entry_data.has_data) { 
		country =  strndup(entry_data.utf8_string, entry_data.data_size);
		printf("%s\n", country);
	}else{
		printf("No city");
	}

	status = MMDB_get_value(&result.entry, &entry_data,"country","names","es", NULL);
	if (entry_data.has_data) { 
		country =  strndup(entry_data.utf8_string, entry_data.data_size);
		printf("%s\n", country);
	}

	MMDB_close(&mmdb);
 return 0;
}
Esempio n. 12
0
void geoip2_close_db(void)
{
	MMDB_close(&mmdb);
}
Esempio n. 13
0
void geoip2_destroy_pv(void)
{
	MMDB_close(&_handle_GeoIP);
}
Esempio n. 14
0
// ------------------------------------------------------------------------------------------------
DbHnd::~DbHnd()
{
    // We don't need the database handle anymore
    MMDB_close(&mDb);
}
Esempio n. 15
0
void OnGeoipCommand()
{
	const auto cmd = CMD_ARGV(1);

	if (!strcmp(cmd, "version"))
	{
		if (!HandleDB.filename)
		{
			MF_PrintSrvConsole("\n  Database is not loaded.\n");
			return;
		}

		const auto meta_dump = "\n"
			"  Database metadata\n"
			"    Node count:    %i\n"
			"    Record size:   %i bits\n"
			"    IP version:    IPv%i\n"
			"    Binary format: %i.%i\n"
			"    Build epoch:   %llu (%s)\n"
			"    Type:          %s\n"
			"    Languages:     ";

		char date[40];
		strftime(date, sizeof date, "%Y-%m-%d %H:%M:%S UTC", gmtime(reinterpret_cast<const time_t *>(&HandleDB.metadata.build_epoch)));

		fprintf(stdout, meta_dump,
				HandleDB.metadata.node_count,
				HandleDB.metadata.record_size,
				HandleDB.metadata.ip_version,
				HandleDB.metadata.binary_format_major_version,
				HandleDB.metadata.binary_format_minor_version,
				HandleDB.metadata.build_epoch,
				date,
				HandleDB.metadata.database_type);

		for (size_t i = 0; i < HandleDB.metadata.languages.count; ++i)
		{
			fprintf(stdout, "%s", HandleDB.metadata.languages.names[i]);

			if (i < HandleDB.metadata.languages.count - 1)
			{
				fprintf(stdout, " ");
			}
		}

		fprintf(stdout, "\n");
		fprintf(stdout, "    Description:\n");

		for (size_t i = 0; i < HandleDB.metadata.description.count; ++i)
		{
			fprintf(stdout, "      %s:   %s\n",
					HandleDB.metadata.description.descriptions[i]->language,
					HandleDB.metadata.description.descriptions[i]->description);
		}
		fprintf(stdout, "\n");
	}
	else if (!strcmp(cmd, "dump"))
	{
		if (!HandleDB.filename)
		{
			MF_PrintSrvConsole("\n  Database is not loaded.\n\n");
			return;
		}

		const auto num_args = CMD_ARGC();

		if (num_args < 3)
		{
			MF_PrintSrvConsole("\n  An IP address must be provided.\n\n");
			return;
		}

		const auto ip = stripPort(const_cast<char *>(CMD_ARGV(2)));

		auto gai_error = 0;
		auto mmdb_error = 0;

		auto result = MMDB_lookup_string(&HandleDB, ip, &gai_error, &mmdb_error);

		if (gai_error != 0 || mmdb_error != MMDB_SUCCESS || !result.found_entry)
		{
			MF_PrintSrvConsole("\n  Either look up failed or no found result.\n\n");
			return;
		}

		MMDB_entry_data_list_s *entry_data_list = nullptr;
		int status;

		if ((status = MMDB_get_entry_data_list(&result.entry, &entry_data_list)) != MMDB_SUCCESS || entry_data_list == nullptr)
		{
			MF_PrintSrvConsole("\n  Could not retrieve data list - %s.\n\n", MMDB_strerror(status));
			return;
		}

		const char *file = nullptr;
		FILE *fp = nullptr;

		if (num_args > 3)
		{
			file = CMD_ARGV(3);
			fp = fopen(MF_BuildPathname("%s", file), "w");
		}

		if (!fp)
		{
			file = nullptr;
			fp = stdout;
		}

		fprintf(fp, "\n");
		MMDB_dump_entry_data_list(fp, entry_data_list, 2);
		fprintf(fp, "\n");

		if (file)
		{
			fclose(fp);
		}

		MMDB_free_entry_data_list(entry_data_list);
	}
	else if (!strcmp(cmd, "reload"))
	{
		const auto isDatabaseLoaded = HandleDB.filename != nullptr;

		if (isDatabaseLoaded)
		{
			MMDB_close(&HandleDB);
		}

		if (loadDatabase() && !NativesRegistered)
		{
			MF_AddNatives(GeoipNatives);

			NativesRegistered = true;
		}
	}
	else
	{
		MF_PrintSrvConsole("\n");
		MF_PrintSrvConsole("  Usage: geoip <command> [argument]\n");
		MF_PrintSrvConsole("  Commands:\n");
		MF_PrintSrvConsole("     version                 - display geoip database metadata\n");
		MF_PrintSrvConsole("     reload                  - reload geoip database\n");
		MF_PrintSrvConsole("     dump <ip> [output file] - dump all data from an IP address formatted in a JSON-ish fashion.\n");
		MF_PrintSrvConsole("                               An output file is mod-based and if not provided, it will print in the console.\n");
		MF_PrintSrvConsole("\n");
	}
}
Esempio n. 16
0
void OnAmxxDetach()
{
	MMDB_close(&HandleDB);

	LangList.clear();
}
void clean_up_mmdb_memory(value this_mmdb)
{
  MMDB_close((MMDB_s*)Data_custom_val(this_mmdb));
}
Esempio n. 18
0
void test_mmdb(MMDB_s * mmdb)
{
    char *ipstr;
    char *(*ip_string)[2] = mmdb->depth == 32 ? ip4_string : ip6_string;
    for (int i = 0; (ipstr = ip_string[i][0]); i++) {
        in_addrX ipnum;
        MMDB_root_entry_s root = {.entry.mmdb = mmdb };
        ip_to_num(mmdb, ipstr, &ipnum);
        int err =
            mmdb->depth == 32 ? MMDB_lookup_by_ipnum(ipnum.v4.s_addr, &root)
            : MMDB_lookup_by_ipnum_128(ipnum.v6, &root);
        ok(err == MMDB_SUCCESS, "Search for %s SUCCESSFUL", ipstr);
        ok(root.entry.offset == 0, "No entries found for %s good", ipstr);
        ipstr = ip_string[i][1];
        ip_to_num(mmdb, ipstr, &ipnum);
        err = mmdb->depth == 32 ? MMDB_lookup_by_ipnum(ipnum.v4.s_addr, &root)
            : MMDB_lookup_by_ipnum_128(ipnum.v6, &root);
        ok(err == MMDB_SUCCESS, "Search for %s SUCCESSFUL", ipstr);
        ok(root.entry.offset > 0, "Found something %s good", ipstr);
        MMDB_return_s country;
        MMDB_get_value(&root.entry, &country, "country", NULL);
        ok(country.offset > 0, "Found country hash for %s", ipstr);
        if (country.offset) {
            MMDB_entry_s country_hash = {.mmdb = mmdb,.offset = country.offset
            };
            MMDB_return_s result;
            MMDB_get_value(&country_hash, &result, "iso_code", NULL);
            ok(result.offset > 0, "Found country code for %s", ipstr);
            if (result.offset > 0) {
                ok(MMDB_strcmp_result(mmdb, &result, "US") == 0,
                   "Country code is US for %s", ipstr);
            }
            MMDB_get_value(&country_hash, &result, "names", "ascii", NULL);
            if (result.offset > 0) {
                ok(MMDB_strcmp_result(mmdb, &result, "United States") == 0,
                   "Country name ascii match United States for %s", ipstr);
            }
            MMDB_get_value(&country_hash, &result, "names", "de", NULL);
            if (result.offset > 0) {
                ok(MMDB_strcmp_result(mmdb, &result, "USA") == 0,
                   "Country name de is USA for %s", ipstr);
            }
            MMDB_get_value(&country_hash, &result, "names", "es", NULL);
            if (result.offset > 0) {
                ok(MMDB_strcmp_result(mmdb, &result, "Estados Unidos") == 0,
                   "Country name es is Estados Unidos for %s", ipstr);
            }
            MMDB_get_value(&country_hash, &result, "names", "whatever", NULL);
            ok(result.offset == 0,
               "Country name whatever is not found for %s", ipstr);

            MMDB_return_s military, cellular, flt, dbl;

            MMDB_get_value(&root.entry, &military, "traits", "is_military",
                           NULL);
            ok(military.offset != 0, "traits/is_military _is_ found for %s",
               ipstr);

            ok(military.type == MMDB_DTYPE_BOOLEAN,
               "is_military.type _is_ MMDB_DTYPE_BOOLEAN for %s", ipstr);

            ok(military.uinteger == 0, "traits/is_military _is_ 0");

            MMDB_get_value(&root.entry, &cellular, "traits", "cellular", NULL);
            ok(cellular.offset != 0, "traits/cellular _is_ found for %s",
               ipstr);

            ok(cellular.type == MMDB_DTYPE_BOOLEAN,
               "cellular.type _is_ MMDB_DTYPE_BOOLEAN for %s", ipstr);

            ok(cellular.uinteger == 1, "traits/is_cellular _is_ 1");

            MMDB_get_value(&root.entry, &flt, "test_data", "max", "float_t",
                           NULL);
            ok(flt.offset != 0, "test_data/max/float_t _is_ found for %s",
               ipstr);

            ok(flt.type == MMDB_DTYPE_IEEE754_FLOAT,
               "flt.type _is_ MMDB_DTYPE_IEEE754_FLOAT for %s", ipstr);

            ok(!dbl_cmp(flt.float_value, 9999.99),
               "test_data/max/float_t _is_ nearly 9999.99");

            MMDB_get_value(&root.entry, &dbl, "test_data", "max", "double_t",
                           NULL);
            ok(dbl.offset != 0, "test_data/max/double_t _is_ found for %s",
               ipstr);

            ok(dbl.type == MMDB_DTYPE_IEEE754_DOUBLE,
               "dbl.type _is_ MMDB_DTYPE_IEEE754_DOUBLE for %s", ipstr);

            ok(!dbl_cmp(dbl.double_value, 999999999.9999),
               "test_data/max/double_t _is_ nearly 999999999.9999");

            {
                double expect[] =
                    { 0.000000, 0.000000, 1.000000, 0.100000, 0.123000,
          10.000000, 7.990000, 1000000000.000000, -1.000000, -0.100000,
          -0.123000, -10.000000, -7.990000, -1000000000.000000 };
                int cnt = sizeof(expect) / sizeof(double);

                MMDB_return_s got;
                MMDB_get_value(&root.entry, &dbl, "test_data", "tst",
                               "array_ieee754_double_t", NULL);
                ok(dbl.offset > 0, "Found it");

                if (dbl.offset > 0) {
                    MMDB_entry_s dbl_array = {.mmdb = mmdb,.offset = dbl.offset
                    };
                    for (int i = 0; i < cnt; i++) {
                        char idx[256];
                        snprintf(idx, sizeof(idx), "%d", i);
                        MMDB_get_value(&dbl_array, &got, idx, NULL);
                        ok(got.offset != 0, "Found something");
                        ok(got.type == MMDB_DTYPE_IEEE754_DOUBLE,
                           "type ok (is %d)", got.type);
                        ok(!dbl_cmp(got.double_value, expect[i]),
                           "test_data/max/double_t _is_ nearly %f", expect[i]);
                    }

                    check_illegal_index(&dbl_array, -1);
                    check_illegal_index(&dbl_array, cnt);
                }
            }
        }
    }
}

int main(void)
{
    char *fnames[] =
        { "./data/v4-24.mmdb", "./data/v4-28.mmdb", "./data/v4-32.mmdb",
        "./data/v6-24.mmdb", "./data/v6-28.mmdb", "./data/v6-32.mmdb", NULL
    };

    char *fname;
    for (char **ptr = fnames; (fname = *ptr++);) {
        struct stat sstat;
        int err = stat(fname, &sstat);
        ok(err == 0, "%s exists", fname);

        MMDB_s *mmdb_m = MMDB_open(fname, MMDB_MODE_MEMORY_CACHE);
        ok(mmdb_m != NULL, "MMDB_open successful ( MMDB_MODE_MEMORY_CACHE )");
        if (mmdb_m) {
            test_mmdb(mmdb_m);
            MMDB_close(mmdb_m);
        }

        MMDB_s *mmdb_s = MMDB_open(fname, MMDB_MODE_STANDARD);
        ok(mmdb_s != NULL, "MMDB_open successful ( MMDB_MODE_STANDARD )");
        if (mmdb_s) {
            test_mmdb(mmdb_s);
            MMDB_close(mmdb_s);
        }
    }
    done_testing();
}
Esempio n. 19
0
	void ShutDown( void ) {
		MMDB_close( handle );
		delete handle;
		handle = nullptr;
	}
Esempio n. 20
0
void test_nested_structure(int mode, const char *mode_desc)
{
    const char *filename = "MaxMind-DB-test-nested.mmdb";
    const char *path = test_database_path(filename);
    MMDB_s *mmdb = open_ok(path, mode, mode_desc);
    free((void *)path);

    const char *ip = "1.1.1.1";
    MMDB_lookup_result_s result =
        lookup_string_ok(mmdb, ip, filename, mode_desc);

    {
        MMDB_entry_data_s entry_data;
        const char *lookup_path[] =
        { "map1", "map2", "array", "0", "map3", "a", NULL };
        int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
        test_complex_map_a_result(status, entry_data, "MMDB_aget_value");

        status = MMDB_get_value(&result.entry, &entry_data,
                                "map1", "map2", "array", "0", "map3", "a", NULL);
        test_complex_map_a_result(status, entry_data, "MMDB_get_value");

        status = call_vget_value(&result.entry, &entry_data,
                                 "map1", "map2", "array", "0", "map3", "a",
                                 NULL);
        test_complex_map_a_result(status, entry_data, "MMDB_vget_value");
    }

    {
        MMDB_entry_data_s entry_data;
        const char *lookup_path[] =
        { "map1", "map2", "array", "0", "map3", "c", NULL };
        int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
        test_complex_map_c_result(status, entry_data, "MMDB_aget_value");

        status = MMDB_get_value(&result.entry, &entry_data,
                                "map1", "map2", "array", "0", "map3", "c", NULL);
        test_complex_map_c_result(status, entry_data, "MMDB_get_value");

        status = call_vget_value(&result.entry, &entry_data,
                                 "map1", "map2", "array", "0", "map3", "c",
                                 NULL);
        test_complex_map_c_result(status, entry_data, "MMDB_vget_value");
    }

    {
        MMDB_entry_data_s entry_data;
        const char *lookup_path[] =
        { "map1", "map42", "array", "0", "map3", "c", NULL };
        int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
        test_no_result(status, entry_data, "MMDB_aget_value",
                       "map1{map42}{array}[0]{map3}{c}");

        status = MMDB_get_value(&result.entry, &entry_data,
                                "map1", "map42", "array", "0", "map3", "c",
                                NULL);
        test_no_result(status, entry_data, "MMDB_get_value",
                       "map1{map42}{array}[0]{map3}{c}");

        status = call_vget_value(&result.entry, &entry_data,
                                 "map1", "map42", "array", "0", "map3", "c",
                                 NULL);
        test_no_result(status, entry_data, "MMDB_vget_value",
                       "map1{map42}{array}[0]{map3}{c}");
    }

    {
        MMDB_entry_data_s entry_data;
        const char *lookup_path[] =
        { "map1", "map2", "array", "9", "map3", "c", NULL };
        int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
        test_no_result(status, entry_data, "MMDB_aget_value",
                       "map1{map42}{array}[9]{map3}{c}");

        status = MMDB_get_value(&result.entry, &entry_data,
                                "map1", "map2", "array", "9", "map3", "c",
                                NULL);
        test_no_result(status, entry_data, "MMDB_get_value",
                       "map1{map42}{array}[9]{map3}{c}");

        status = call_vget_value(&result.entry, &entry_data,
                                 "map1", "map2", "array", "9", "map3", "c",
                                 NULL);
        test_no_result(status, entry_data, "MMDB_vget_value",
                       "map1{map42}{array}[9]{map3}{c}");
    }

    MMDB_close(mmdb);
    free(mmdb);
}
Esempio n. 21
0
void Sig_Handler( _SaganSigArgs *args )
{

    sigset_t signal_set;
    int sig;
    sbool orig_perfmon_value = 0;

#ifdef HAVE_LIBPCAP
    sbool orig_plog_value = 0;
#endif

    for(;;)
        {
            /* wait for any and all signals */
            sigfillset( &signal_set );
            sigwait( &signal_set, &sig );


            switch( sig )
                {
                    /* exit */
                case SIGQUIT:
                case SIGINT:
                case SIGTERM:
                case SIGSEGV:
                case SIGABRT:

                    Sagan_Log(S_NORMAL, "\n\n[Received signal %d. Sagan version %s shutting down]-------\n", sig, VERSION);
                    Sagan_Statistics();

#if defined(HAVE_DNET_H) || defined(HAVE_DUMBNET_H)
                    if ( sagan_unified2_flag )
                        {
                            Unified2CleanExit();
                        }
#endif

#ifdef HAVE_LIBMAXMINDDB

                    MMDB_close(&config->geoip2);

#endif

                    fflush(config->sagan_alert_stream);
                    fclose(config->sagan_alert_stream);             /* Close Sagan alert file */

                    fflush(config->sagan_log_stream);               /* Close the sagan.log */
                    fclose(config->sagan_log_stream);

                    if ( config->perfmonitor_flag )
                        {
                            Sagan_Perfmonitor_Close();
                        }

                    Remove_Lock_File();
                    exit(0);
                    break;

                case SIGHUP:

                    config->sagan_reload = 1;				/* Only this thread can alter this */

                    pthread_mutex_lock(&SaganReloadMutex);

                    Sagan_Log(S_NORMAL, "[Reloading Sagan version %s.]-------", VERSION);

                    /*
                    * Close and re-open log files.  This is for logrotate and such
                    * 04/14/2015 - Champ Clark III ([email protected])
                    */

                    Sagan_Open_Log_File(REOPEN, ALL_LOGS);

                    /******************/
                    /* Reset counters */
                    /******************/

                    counters->refcount=0;
                    counters->classcount=0;
                    counters->rulecount=0;
                    counters->ruletotal=0;
                    counters->genmapcount=0;
                    counters->flowbit_track_count=0;

                    memset(rulestruct, 0, sizeof(_Rule_Struct));
                    memset(classstruct, 0, sizeof(_Class_Struct));
                    memset(generator, 0, sizeof(_Sagan_Processor_Generator));
                    memset(flowbit, 0, sizeof(_Sagan_Flowbit));


                    /**********************************/
                    /* Disabled and reset processors. */
                    /**********************************/

                    /* Note: Processors that run as there own thread (perfmon, plog) cannot be
                     * loaded via SIGHUP.  They must be loaded at run time.  Once they are loaded,
                     * they can be disabled/re-enabled. */

                    /* Single Threaded processors */

                    if ( config->perfmonitor_flag == 1 && orig_perfmon_value == 0 )
                        {
                            Sagan_Perfmonitor_Close();
                            orig_perfmon_value = 1;
                        }

                    config->perfmonitor_flag = 0;

#ifdef HAVE_LIBPCAP

                    if ( config->plog_flag )
                        {
                            orig_plog_value = 1;
                        }

                    config->plog_flag = 0;
#endif

                    /* Multi Threaded processors */

                    config->blacklist_flag = 0;

                    if ( config->blacklist_flag )
                        {
                            free(SaganBlacklist);
                        }

                    config->blacklist_flag = 0;

                    if ( config->brointel_flag )
                        {
                            free(Sagan_BroIntel_Intel_Addr);
                            free(Sagan_BroIntel_Intel_Domain);
                            free(Sagan_BroIntel_Intel_File_Hash);
                            free(Sagan_BroIntel_Intel_URL);
                            free(Sagan_BroIntel_Intel_Software);
                            free(Sagan_BroIntel_Intel_Email);
                            free(Sagan_BroIntel_Intel_User_Name);
                            free(Sagan_BroIntel_Intel_File_Name);
                            free(Sagan_BroIntel_Intel_Cert_Hash);

                            counters->brointel_addr_count = 0;
                            counters->brointel_domain_count = 0;
                            counters->brointel_file_hash_count = 0;
                            counters->brointel_url_count = 0;
                            counters->brointel_software_count = 0;
                            counters->brointel_email_count = 0;
                            counters->brointel_user_name_count = 0;
                            counters->brointel_file_name_count = 0;
                            counters->brointel_cert_hash_count = 0;
                            counters->brointel_dups = 0;
                        }

                    config->brointel_flag = 0;

                    if ( config->sagan_track_clients_flag )
                        {
                            free(SaganTrackClients);
                            fclose(config->sagan_track_client_file);
                        }

                    config->sagan_track_clients_flag = 0;
                    counters->track_clients_client_count = 0;
                    counters->track_clients_down = 0;

                    /* Output formats */

                    config->sagan_ext_flag = 0;

#ifdef WITH_SYSLOG
                    config->sagan_syslog_flag = 0;
#endif


#ifdef HAVE_LIBESMTP
                    config->sagan_esmtp_flag = 0;
#endif

#ifdef WITH_SNORTSAM
                    config->sagan_fwsam_flag = 0;
#endif

                    /* Non-output / Processors */

                    if ( config->sagan_droplist_flag )
                        {
                            config->sagan_droplist_flag = 0;
                            free(SaganIgnorelist);
                        }

                    /************************************************************/
                    /* Re-load primary configuration (rules/classifictions/etc) */
                    /************************************************************/

                    Load_Config();	/* <- RELOAD */

                    /************************************************************/
                    /* Re-load primary configuration (rules/classifictions/etc) */
                    /************************************************************/

                    if ( config->perfmonitor_flag == 1 )
                        {
                            if ( orig_perfmon_value == 1 )
                                {
                                    Sagan_Perfmonitor_Open();
                                }
                            else
                                {
                                    Sagan_Log(S_WARN, "** 'perfmonitor' must be loaded at runtime! NOT loading 'perfmonitor'!");
                                    config->perfmonitor_flag = 0;
                                }
                        }


#ifdef HAVE_LIBPCAP

                    if ( config->plog_flag == 1 )
                        {
                            if ( orig_plog_value == 1 )
                                {
                                    config->plog_flag = 1;
                                }
                            else
                                {
                                    Sagan_Log(S_WARN, "** 'plog' must be loaded at runtime! NOT loading 'plog'!");
                                    config->plog_flag = 0;
                                }
                        }
#endif

                    /* Load Blacklist data */

                    if ( config->blacklist_flag )
                        {
                            counters->blacklist_count=0;
                            Sagan_Blacklist_Init();
                            Sagan_Blacklist_Load();
                        }

                    if ( config->brointel_flag )
                        {
                            Sagan_BroIntel_Init();
                            Sagan_BroIntel_Load_File();
                        }

                    if ( config->sagan_track_clients_flag )
                        {
                            Sagan_Load_Tracking_Cache();
                            Sagan_Log(S_NORMAL, "Reset Sagan Track Client.");
                        }


                    /* Non output / processors */

                    if ( config->sagan_droplist_flag )
                        {
                            Load_Ignore_List();
                            Sagan_Log(S_NORMAL, "Loaded %d ignore/drop list item(s).", counters->droplist_count);
                        }

#ifdef HAVE_LIBMAXMINDDB
                    Sagan_Log(S_NORMAL, "Reloading GeoIP2 data.");
                    Sagan_Open_GeoIP2_Database();
#endif

#ifdef HAVE_LIBLOGNORM
                    Sagan_Liblognorm_Load();
#endif


                    pthread_cond_signal(&SaganReloadCond);
                    pthread_mutex_unlock(&SaganReloadMutex);

                    config->sagan_reload = 0;

                    Sagan_Log(S_NORMAL, "Configuration reloaded.");
                    break;

                    /* Signals to ignore */
                case 17:		/* Child process has exited. */
                case 28:		/* Terminal 'resize'/alarm. */
                    break;

                case SIGUSR1:
                    Sagan_Statistics();
                    break;

                default:
                    Sagan_Log(S_NORMAL, "[Received signal %d. Sagan doesn't know how to deal with]", sig);
                }
        }
}