Check-in [5396b2b79c]
Overview
Comment:This fixes a few segfaults with an empty config file. It's, of course, *useless* with an empty config file, but that's for testing at a later time.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5396b2b79c63a20642099279fd11654dbbd6061b
User & Date: rmiller on 2011-03-06 02:10:58
Other Links: manifest | tags
Context
2011-03-06
17:18
This has been verified to work, at least on a quick test. Need to test more thoroughly. Good for a beta release, anyway. check-in: 697a450bd4 user: rmiller tags: trunk
02:10
This fixes a few segfaults with an empty config file. It's, of course, *useless* with an empty config file, but that's for testing at a later time. check-in: 5396b2b79c user: rmiller tags: trunk
01:57
it compiles and links properly. I don't guarantee ANYTHING else. This is a very major change - I have removed dotconf and am replacing with libconfig. Also did some cleanup along with it. Some parts are messy. I hope it's functional. check-in: 9a13922db2 user: rmiller tags: trunk
Changes

Modified packetbl.c from [de1fe284bf] to [9a2b349279].

809
810
811
812
813
814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
 *   global variables.  It may cause the program to abort with a failure
 *   if the configuration is unreadable or unparsable.  Due to this fact,
 *   it should only be called during start-up and not from the main loop.
 *
 */
void parse_config(void) {

	config_t *config = NULL;
	config_setting_t *config_setting = NULL;
	struct ce *config_entry = NULL;
	int result = 0;
	int i = 0;
	const char *facstr = NULL;
	

	config_init(config);
	result = config_read_file(config, "test.config");
	if (result == CONFIG_FALSE) {
		if (config_error_type(config) == CONFIG_ERR_PARSE) {
			fprintf (stderr, "Error parsing config file %s, line %d: %s\n",
				config_error_file(config),
				config_error_line(config),







|






>







809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
 *   global variables.  It may cause the program to abort with a failure
 *   if the configuration is unreadable or unparsable.  Due to this fact,
 *   it should only be called during start-up and not from the main loop.
 *
 */
void parse_config(void) {

	config_t cf, *config;
	config_setting_t *config_setting = NULL;
	struct ce *config_entry = NULL;
	int result = 0;
	int i = 0;
	const char *facstr = NULL;
	
	config = &cf;
	config_init(config);
	result = config_read_file(config, "test.config");
	if (result == CONFIG_FALSE) {
		if (config_error_type(config) == CONFIG_ERR_PARSE) {
			fprintf (stderr, "Error parsing config file %s, line %d: %s\n",
				config_error_file(config),
				config_error_line(config),
856
857
858
859
860
861
862
863
864

865
866
867
868
869
870

871
872
873
874
875
876
877
878
879
880
881

882

883

884

885

886

887

888
889
890
891
892
893
894
895
896

	if (packet_cache_len < 0) {
		packet_cache_len = USE_CACHE_DEF_LEN;
		fprintf(stderr, "config size TTL negative - using default");
	}
#endif

	config_lookup_string(config, "log.facility", &facstr);
	i = 0;

	while (&facenum[i] != NULL) {
		if (strcasecmp(facenum[i].string, facstr) == 0) {
			conf.log_facility = facenum[i].num;
			break;
		} else {
			i++;

		}
	}
	
	config_lookup_int(config, "config.queueno", &conf.queueno);
	
	if (conf.queueno < 0) {
		conf.queueno = 1;
		fprintf(stderr, "queueno negative - using default");
	}

	config_setting = config_lookup(config, "blacklistbl");

	parse_config_bl_list(config_setting, 1);

	config_setting = config_lookup(config, "whitelistbl");

	parse_config_bl_list(config_setting, 2);

	config_setting = config_lookup(config, "blacklist");

	parse_config_bl_list(config_setting, 3);

	config_setting = config_lookup(config, "whitelist");

	parse_config_bl_list(config_setting, 4);
	
}

parse_config_bl_list(config_setting_t *c, int type) {

	struct config_entry *ce, *tmp;
	int i = 0, len = 0;
	char *setting;







|

>
|
|
|
|
|
|
>











>
|
>

>
|
>

>
|
>

>
|
|







857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906

	if (packet_cache_len < 0) {
		packet_cache_len = USE_CACHE_DEF_LEN;
		fprintf(stderr, "config size TTL negative - using default");
	}
#endif

	result = config_lookup_string(config, "log.facility", &facstr);
	i = 0;
	if (result == CONFIG_TRUE) {
		while (&facenum[i] != NULL) {
			if (strcasecmp(facenum[i].string, facstr) == 0) {
				conf.log_facility = facenum[i].num;
				break;
			} else {
				i++;
			}
		}
	}
	
	config_lookup_int(config, "config.queueno", &conf.queueno);
	
	if (conf.queueno < 0) {
		conf.queueno = 1;
		fprintf(stderr, "queueno negative - using default");
	}

	config_setting = config_lookup(config, "blacklistbl");
	if (config_setting != NULL) {
		parse_config_bl_list(config_setting, 1);
	}
	config_setting = config_lookup(config, "whitelistbl");
	if (config_setting != NULL) {
		parse_config_bl_list(config_setting, 2);
	}
	config_setting = config_lookup(config, "blacklist");
	if (config_setting != NULL) {
		parse_config_bl_list(config_setting, 3);
	}
	config_setting = config_lookup(config, "whitelist");
	if (config_setting != NULL) {
		parse_config_bl_list(config_setting, 4);
	}
}

parse_config_bl_list(config_setting_t *c, int type) {

	struct config_entry *ce, *tmp;
	int i = 0, len = 0;
	char *setting;