Check-in [5396b2b79c]
Overview
SHA1:5396b2b79c63a20642099279fd11654dbbd6061b
Date: 2011-03-06 02:10:58
User: rmiller
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.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2011-03-06
17:18
[697a450bd4] This has been verified to work, at least on a quick test. Need to test more thoroughly. Good for a beta release, anyway. (user: rmiller, tags: trunk)
02:10
[5396b2b79c] 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. (user: rmiller, tags: trunk)
01:57
[9a13922db2] 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. (user: rmiller, tags: trunk)
Changes

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

   809    809    *   global variables.  It may cause the program to abort with a failure
   810    810    *   if the configuration is unreadable or unparsable.  Due to this fact,
   811    811    *   it should only be called during start-up and not from the main loop.
   812    812    *
   813    813    */
   814    814   void parse_config(void) {
   815    815   
   816         -	config_t *config = NULL;
          816  +	config_t cf, *config;
   817    817   	config_setting_t *config_setting = NULL;
   818    818   	struct ce *config_entry = NULL;
   819    819   	int result = 0;
   820    820   	int i = 0;
   821    821   	const char *facstr = NULL;
   822    822   	
          823  +	config = &cf;
   823    824   	config_init(config);
   824    825   	result = config_read_file(config, "test.config");
   825    826   	if (result == CONFIG_FALSE) {
   826    827   		if (config_error_type(config) == CONFIG_ERR_PARSE) {
   827    828   			fprintf (stderr, "Error parsing config file %s, line %d: %s\n",
   828    829   				config_error_file(config),
   829    830   				config_error_line(config),
................................................................................
   856    857   
   857    858   	if (packet_cache_len < 0) {
   858    859   		packet_cache_len = USE_CACHE_DEF_LEN;
   859    860   		fprintf(stderr, "config size TTL negative - using default");
   860    861   	}
   861    862   #endif
   862    863   
   863         -	config_lookup_string(config, "log.facility", &facstr);
          864  +	result = config_lookup_string(config, "log.facility", &facstr);
   864    865   	i = 0;
   865         -	while (&facenum[i] != NULL) {
   866         -		if (strcasecmp(facenum[i].string, facstr) == 0) {
   867         -			conf.log_facility = facenum[i].num;
   868         -			break;
   869         -		} else {
   870         -			i++;
          866  +	if (result == CONFIG_TRUE) {
          867  +		while (&facenum[i] != NULL) {
          868  +			if (strcasecmp(facenum[i].string, facstr) == 0) {
          869  +				conf.log_facility = facenum[i].num;
          870  +				break;
          871  +			} else {
          872  +				i++;
          873  +			}
   871    874   		}
   872    875   	}
   873    876   	
   874    877   	config_lookup_int(config, "config.queueno", &conf.queueno);
   875    878   	
   876    879   	if (conf.queueno < 0) {
   877    880   		conf.queueno = 1;
   878    881   		fprintf(stderr, "queueno negative - using default");
   879    882   	}
   880    883   
   881    884   	config_setting = config_lookup(config, "blacklistbl");
   882         -	parse_config_bl_list(config_setting, 1);
          885  +	if (config_setting != NULL) {
          886  +		parse_config_bl_list(config_setting, 1);
          887  +	}
   883    888   	config_setting = config_lookup(config, "whitelistbl");
   884         -	parse_config_bl_list(config_setting, 2);
          889  +	if (config_setting != NULL) {
          890  +		parse_config_bl_list(config_setting, 2);
          891  +	}
   885    892   	config_setting = config_lookup(config, "blacklist");
   886         -	parse_config_bl_list(config_setting, 3);
          893  +	if (config_setting != NULL) {
          894  +		parse_config_bl_list(config_setting, 3);
          895  +	}
   887    896   	config_setting = config_lookup(config, "whitelist");
   888         -	parse_config_bl_list(config_setting, 4);
   889         -	
          897  +	if (config_setting != NULL) {
          898  +		parse_config_bl_list(config_setting, 4);
          899  +	}
   890    900   }
   891    901   
   892    902   parse_config_bl_list(config_setting_t *c, int type) {
   893    903   
   894    904   	struct config_entry *ce, *tmp;
   895    905   	int i = 0, len = 0;
   896    906   	char *setting;