Exemplo n.º 1
0
int
setup(struct config_t *config, int argc, char **argv)
{
	char *home, *cfgfile = NULL;
	
	config_init(config);
	
	/* parse arguments */
	if (parse_args(config, argc, argv) != 0)
		return SETUP_ERROR;
	
	/* if the user did not supply an alternate config file,
	 * check if the default config file exists */
	if (!config->filename) {
		if ((home = getenv("HOME"))) {
			cfgfile = malloc(strlen(home) + sizeof(CONFIG_FILE) + 2);
			if (!cfgfile) {
				warn("malloc failed for $HOME + " CONFIG_FILE);
				return SETUP_ERROR;
			}
			stpcpy(stpcpy(stpcpy(cfgfile, home), "/"), CONFIG_FILE);
			if (access(cfgfile, F_OK) == 0) {
				/* file exists - keep malloc'ed data */
				config->filename = cfgfile;
			} else {
				/* file does not exist - free data */
				errno = 0;
				free(cfgfile);
				cfgfile = NULL;
			}
		}
	}
	
	/* parse config file - if provided or default exists */
	if (config->filename && parse_conf(config, config->filename) != 0)
		return SETUP_ERROR;
	
	/* put defaults for each undefined variable */
	config_finalize(config);
	
	/* check mandatory/conflicting settings */
	if (config_validate(config) != 0)
		return SETUP_ERROR;
	
	return SETUP_OK;
}
Exemplo n.º 2
0
int main(int argc, const char ** argv)
{
	int res = 1;
	config_t config;
	rule_info_t rule;
	DEHT * deht = NULL;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <prefix>\n", argv[0]);
		goto cleanup0;
	}

	if (config_load(&config, argv[1]) != INI_STATUS_OK) {
		/* error message printed by config_load */
		goto cleanup0;
	}
	if (rule_init(&rule, config.rule_pattern, config.lexicon_file) != RULE_STATUS_OK) {
		/* error message printed by rule_init */
		goto cleanup1;
	}

	deht = 	create_empty_DEHT(config.prefix, my_hash_func, my_valid_func,
		config.num_of_buckets, config.bucket_size, 8, config.hash_name);
	if (deht == NULL) {
		/* error message printed by create_empty_DEHT */
		goto cleanup2;
	}

	if (rainbow_generate_seed_table(&config) != RAINBOW_STATUS_OK) {
		/* error message printed by rainbow_generate_seed_table */
		goto cleanup3;
	}

	res = generate_all_chains(&config, &rule, deht);

cleanup3:
	close_DEHT_files(deht);
cleanup2:
	rule_finalize(&rule);
cleanup1:
	config_finalize(&config);
cleanup0:
	return res;
}