Ejemplo n.º 1
0
void set_default_mark_change(int linenr, char *cmd, char *par)
{
    char *re;

    if ((re = find_next_par(par)) == NULL)		/* format: cs_re:color:regular expression */
        config_error_exit(linenr, "Scheme entry malformed: scheme name or regular expression missing.\n");

    add_pars_per_file(re, NULL, -1, -1, config_yes_no(par), -1, -1, NULL);
}
Ejemplo n.º 2
0
void set_show_subwindow_id(int linenr, char *cmd, char *par)
{
    show_subwindow_id = config_yes_no(par);
}
Ejemplo n.º 3
0
void set_bright(int linenr, char *cmd, char *par)
{
    bright_colors = config_yes_no(par);
}
Ejemplo n.º 4
0
void load_config(const char *config, config_t *pconfig)
{
	char *dummy = strdup(config);

	char *cur_dir_dummy = dirname(dummy);
	char *cur_dir = realpath(cur_dir_dummy, NULL);

        int linenr = 0;
        FILE *fh = fopen(config, "r");
        if (!fh)
                error_exit("error opening configuration file '%s'", config);

	/* set defaults */
	pconfig -> max_number_of_mem_pools = 14;
	pconfig -> max_number_of_disk_pools = 128;
	pconfig -> min_store_on_disk_n = 5;

	pconfig -> bitcount_estimator = BCE_SHANNON;

	pconfig -> listen_adapter    = "0.0.0.0";
	pconfig -> listen_port       = DEFAULT_BROKER_PORT;
	pconfig -> listen_queue_size = 64;
	pconfig -> disable_nagle     = false;
	pconfig -> enable_keepalive  = true;

	pconfig -> reset_counters_interval    = 60;
	pconfig -> statistics_interval        = 300;
	pconfig -> ping_interval              = 601;
	pconfig -> kernelpool_filled_interval = 3600;

	pconfig -> stats_file = NULL;

	pconfig -> communication_timeout              = 15.0;
	pconfig -> communication_session_timeout      = 3600.0; /* 0 for no timeout */
	pconfig -> default_sleep_time_when_pools_full = 10;
	pconfig -> default_sleep_when_pools_empty     = 16;
	pconfig -> default_max_sleep_when_pools_empty = 60;
	pconfig -> when_pools_full_allow_submit_interval = 15;
	pconfig -> max_open_files = 1024;

	pconfig -> default_max_bits_per_interval = 16000000;

	pconfig -> ignore_rngtest_fips140 = false;
	pconfig -> ignore_rngtest_scc = false;
	pconfig -> scc_threshold = 0.2;

	pconfig -> allow_event_entropy_addition = true;
	pconfig -> add_entropy_even_if_all_full = false;
	pconfig -> allow_prng = false;

	pconfig -> user_map = new std::string("usermap.txt");

	pconfig -> pool_size_bytes = DEFAULT_POOL_SIZE_BITS / 8;

	pconfig -> prng_seed_file = NULL;

	pconfig -> max_get_put_size = 1249;

	pconfig -> ht = H_SHA512;
	pconfig -> st = S_BLOWFISH;

	pconfig -> rs = RS_CRYPTOPP;

	pconfig -> stream_cipher = "blowfish";
	pconfig -> mac_hasher = "md5";
	pconfig -> hash_hasher = "sha512";

	pconfig -> webserver_interface = "0.0.0.0";
	pconfig -> webserver_port = -1;

	pconfig -> graph_font = strdup(FONT);

	pconfig -> default_max_get_bps = 4096;

        for(;;)
        {
		double parvald;
		int parval;
                char read_buffer[4096], *lf, *par;
                char *cmd = fgets(read_buffer, sizeof read_buffer, fh), *is;
                if (!cmd)
                        break;
                linenr++;

                if (read_buffer[0] == '#' || read_buffer[0] == ';')
                        continue;

		while(*cmd == ' ') cmd++;

                lf = strchr(read_buffer, '\n');
                if (lf) *lf = 0x00;

		if (strlen(cmd) == 0)
			continue;

                is = strchr(read_buffer, '=');
                if (!is)
                        error_exit("invalid line at line %d: '=' missing", linenr);

                *is = 0x00;
                par = is + 1;
		while(*par == ' ') par++;
		parval = atoi(par);
		parvald = atof(par);

		is--;
		while(*is == ' ') { *is = 0x00 ; is--; }

		if (strcmp(cmd, "max_number_of_mem_pools") == 0)
			pconfig -> max_number_of_mem_pools = parval;
		else if (strcmp(cmd, "max_number_of_disk_pools") == 0)
			pconfig -> max_number_of_disk_pools = parval;
		else if (strcmp(cmd, "min_store_on_disk_n") == 0)
			pconfig -> min_store_on_disk_n = parval;
		else if (strcmp(cmd, "listen_adapter") == 0)
			pconfig -> listen_adapter = strdup(par);
		else if (strcmp(cmd, "graph_font") == 0)
			pconfig -> graph_font = strdup(par);
		else if (strcmp(cmd, "users") == 0)
		{
			char *p_file = static_cast<char *>(malloc(strlen(cur_dir) + strlen(par) + 1 + 1));
			if (par[0] == '/')
				strcpy(p_file, par);
			else
				sprintf(p_file, "%s/%s", cur_dir, par);
			dolog(LOG_INFO, "Load users from %s", p_file);
			delete pconfig -> user_map;
			pconfig -> user_map = new std::string(p_file);
			free(p_file);
		}
		else if (strcmp(cmd, "bitcount_estimator") == 0)
		{
			if (strcmp(par, "shannon") == 0)
				pconfig -> bitcount_estimator = BCE_SHANNON;
			else if (strcmp(par, "compression") == 0)
				pconfig -> bitcount_estimator = BCE_COMPRESSION;
			else
				error_exit("bitcount_estimator of type '%s' is not known", par);
		}
		else if (strcmp(cmd, "random_source") == 0)
		{
			if (strcmp(par, "cryptopp") == 0)
				pconfig -> rs = RS_CRYPTOPP;
			else if (strcmp(par, "dev_random") == 0)
				pconfig -> rs = RS_DEV_RANDOM;
			else if (strcmp(par, "dev_urandom") == 0)
				pconfig -> rs = RS_DEV_URANDOM;
			else
				error_exit("random_source of type '%s' is not known", par);
		}
		else if (strcmp(cmd, "listen_port") == 0)
			pconfig -> listen_port = parval;
		else if (strcmp(cmd, "listen_queue_size") == 0)
			pconfig -> listen_queue_size = parval;
		else if (strcmp(cmd, "default_max_get_bps") == 0)
			pconfig -> default_max_get_bps = parval;
		else if (strcmp(cmd, "max_open_files") == 0)
			pconfig -> max_open_files = parval;
		else if (strcmp(cmd, "webserver_interface") == 0)
			pconfig -> webserver_interface = par;
		else if (strcmp(cmd, "webserver_port") == 0)
			pconfig -> webserver_port = parval;
		else if (strcmp(cmd, "disable_nagle") == 0)
			pconfig -> disable_nagle = config_yes_no(par);
		else if (strcmp(cmd, "enable_keepalive") == 0)
			pconfig -> enable_keepalive = config_yes_no(par);
		else if (strcmp(cmd, "reset_counters_interval") == 0)
			pconfig -> reset_counters_interval = parval;
		else if (strcmp(cmd, "statistics_interval") == 0)
			pconfig -> statistics_interval = parval;
		else if (strcmp(cmd, "ping_interval") == 0)
			pconfig -> ping_interval = parval;
		else if (strcmp(cmd, "pool_size_in_bytes") == 0)
			pconfig -> pool_size_bytes = parval;
		else if (strcmp(cmd, "max_get_put_size") == 0)
			pconfig -> max_get_put_size = parval;
		else if (strcmp(cmd, "kernelpool_filled_interval") == 0)
			pconfig -> kernelpool_filled_interval = parval;
		else if (strcmp(cmd, "stats_file") == 0)
			pconfig -> stats_file = strdup(par);
		else if (strcmp(cmd, "stream_cipher") == 0)
			pconfig -> stream_cipher = par;
		else if (strcmp(cmd, "mac_hasher") == 0)
			pconfig -> mac_hasher = par;
		else if (strcmp(cmd, "hash_hasher") == 0)
			pconfig -> hash_hasher = par;
		else if (strcmp(cmd, "prng_seed_file") == 0)
		{
			char *p_file = static_cast<char *>(malloc(strlen(VAR_DIR) + strlen(par) + 1 + 1));
			if (par[0] == '/')
				strcpy(p_file, par);
			else
				sprintf(p_file, VAR_DIR "/%s", par);
			dolog(LOG_INFO, "Will load PRNG seed from %s", p_file);
			pconfig -> prng_seed_file = p_file;
		}
		else if (strcmp(cmd, "communication_timeout") == 0)
			pconfig -> communication_timeout = parvald;
		else if (strcmp(cmd, "communication_session_timeout") == 0)
			pconfig -> communication_session_timeout = parvald;
		else if (strcmp(cmd, "default_sleep_time_when_pools_full") == 0)
			pconfig -> default_sleep_time_when_pools_full = parval;
		else if (strcmp(cmd, "default_sleep_when_pools_empty") == 0)
			pconfig -> default_sleep_when_pools_empty = parval;
		else if (strcmp(cmd, "default_max_sleep_when_pools_empty") == 0)
			pconfig -> default_max_sleep_when_pools_empty = parval;
		else if (strcmp(cmd, "default_max_bits_per_interval") == 0)
			pconfig -> default_max_bits_per_interval = parval;
		else if (strcmp(cmd, "ignore_rngtest_fips140") == 0)
			pconfig -> ignore_rngtest_fips140 = config_yes_no(par);
		else if (strcmp(cmd, "ignore_rngtest_scc") == 0)
			pconfig -> ignore_rngtest_scc = config_yes_no(par);
		else if (strcmp(cmd, "allow_event_entropy_addition") == 0)
			pconfig -> allow_event_entropy_addition = config_yes_no(par);
		else if (strcmp(cmd, "add_entropy_even_if_all_full") == 0)
			pconfig -> add_entropy_even_if_all_full = config_yes_no(par);
		else if (strcmp(cmd, "allow_prng") == 0)
			pconfig -> allow_prng = config_yes_no(par);
		else if (strcmp(cmd, "scc_threshold") == 0)
			pconfig -> scc_threshold = parvald;
		else if (strcmp(cmd, "when_pools_full_allow_submit_interval") == 0)
			pconfig -> when_pools_full_allow_submit_interval = parval;
		else if (strcmp(cmd, "hash_type") == 0)
		{
			if (strcmp(par, "sha512") == 0)
				pconfig -> ht = H_SHA512;
			else if (strcmp(par, "md5") == 0)
				pconfig -> ht = H_MD5;
			else if (strcmp(par, "ripemd160") == 0)
				pconfig -> ht = H_RIPEMD160;
			else if (strcmp(par, "whirlpool") == 0)
				pconfig -> ht = H_WHIRLPOOL;
			else
				error_exit("Hash type '%s' not understood", par);
		}
		else if (strcmp(cmd, "stirrer_type") == 0)
		{
			if (strcmp(par, "blowfish") == 0)
				pconfig -> st = S_BLOWFISH;
			else if (strcmp(par, "aes") == 0)
				pconfig -> st = S_AES;
			else if (strcmp(par, "3des") == 0)
				pconfig -> st = S_3DES;
			else if (strcmp(par, "camellia") == 0)
				pconfig -> st = S_CAMELLIA;
			else
				error_exit("Stirrer type '%s' not understood", par);
		}
		else
			error_exit("%s=%s not understood", cmd, par);
	}

	dolog(LOG_DEBUG, "read %d configuration file lines", linenr);

	fclose(fh);

	free(dummy);
	free(cur_dir);
}
Ejemplo n.º 5
0
void set_show_severity_facility(int linenr, char *cmd, char *par)
{
    show_severity_facility = config_yes_no(par);
}
Ejemplo n.º 6
0
void set_posix_tail(int linenr, char *cmd, char *par)
{
    posix_tail = config_yes_no(par);
}
Ejemplo n.º 7
0
void set_scrollback_show_winnrs(int linenr, char *cmd, char *par)
{
    default_sb_showwinnr = config_yes_no(par);
}
Ejemplo n.º 8
0
void set_abbreviate_filesize(int linenr, char *cmd, char *par)
{
    afs = config_yes_no(par);
}
Ejemplo n.º 9
0
void set_statusline_above_data(int linenr, char *cmd, char *par)
{
    statusline_above_data = config_yes_no(par);
}
Ejemplo n.º 10
0
void set_follow_filename(int linenr, char *cmd, char *par)
{
    default_follow_filename = config_yes_no(par);
}
Ejemplo n.º 11
0
void set_close_closed_windows(int linenr, char *cmd, char *par)
{
    do_not_close_closed_windows = !config_yes_no(par);
}
Ejemplo n.º 12
0
void set_suppress_empty_lines(int linenr, char *cmd, char *par)
{
    suppress_empty_lines = config_yes_no(par);
}
Ejemplo n.º 13
0
void set_gnu_tail(int linenr, char *cmd, char *par)
{
    gnu_tail = config_yes_no(par);
}
Ejemplo n.º 14
0
void set_scrollback_search_new_window(int linenr, char *cmd, char *par)
{
    scrollback_search_new_window = config_yes_no(par);
}
Ejemplo n.º 15
0
void set_markerline_timestamp(int linenr, char *cmd, char *par)
{
    timestamp_in_markerline = config_yes_no(par);
}
Ejemplo n.º 16
0
void set_caret_notation(int linenr, char *cmd, char *par)
{
    caret_notation = config_yes_no(par);
}
Ejemplo n.º 17
0
void set_allow_8bit(int linenr, char *cmd, char *par)
{
    allow_8bit = config_yes_no(par);
}
Ejemplo n.º 18
0
void set_global_mark_change(int linenr, char *cmd, char *par)
{
    global_marker_of_other_window = config_yes_no(par);
}
Ejemplo n.º 19
0
void set_dsblwm(int linenr, char *cmd, char *par)
{
    no_linewrap = 1 - config_yes_no(par);
}
Ejemplo n.º 20
0
void set_reuse_searchstring(int linenr, char *cmd, char *par)
{
    reuse_searchstring = config_yes_no(par);
}
Ejemplo n.º 21
0
void set_warn_closed(int linenr, char *cmd, char *par)
{
    warn_closed = config_yes_no(par);
}
Ejemplo n.º 22
0
void set_resolv_ip_addresses(int linenr, char *cmd, char *par)
{
    resolv_ip_addresses = config_yes_no(par);
}
Ejemplo n.º 23
0
void set_basename(int linenr, char *cmd, char *par)
{
    filename_only = config_yes_no(par);
}
Ejemplo n.º 24
0
void set_scrollback_no_colors(int linenr, char *cmd, char *par)
{
    scrollback_no_colors = config_yes_no(par);
}
Ejemplo n.º 25
0
void load_config(const char *config, config_t *pconfig)
{
	char *dummy = strdup(config);
	int linenr = 0;
	FILE *fh = fopen(config, "r");
	if (!fh) {
		printf("error opening configuration file '%s'", config);
		exit(1);
	}

	// set defaults
	pconfig->serial_line = "/dev/tty01";
	pconfig->baudrate = 57600;
#ifdef HAVE_GPIO
	pconfig->gpio_device = "gpio1";
	pconfig->gpio_pin = 16;
#endif
	pconfig->daemonize = -1;
	pconfig->debug = 0;
	pconfig->samples = 60;
	pconfig->user = "******";
	pconfig->chroot = "/var/empty";
	pconfig->datalog = "/srv/weatherd";
	pconfig->graphite = NULL;

	for(;;) {
		double parvald;
		int parval;
		char read_buffer[4096], *lf, *par;
		char *cmd = fgets(read_buffer, sizeof(read_buffer), fh), *is;
		if (!cmd) {
			break;
		}
		linenr++;

		if (read_buffer[0] == '#' || read_buffer[0] == ';') {
			continue;
		}

		while(*cmd == ' ') cmd++;

		lf = strchr(read_buffer, '\n');
		if (lf) *lf = 0x00;

		if (strlen(cmd) == 0) {
			continue;
		}

		is = strchr(read_buffer, '=');
		if (!is) {
			printf("invalid line at line %d: '=' missing", linenr);
			exit(1);
		}

		*is = 0x00;
		par = is + 1;

		while(*par == ' ') par++;
		parval = atoi(par);
		parvald = atof(par);

		is--;
		while(*is == ' ') { *is = 0x00 ; is--; }

		if (strcmp(cmd, "serial_line") == 0) {
			pconfig->serial_line = strdup(par);
		} else if (strcmp(cmd, "baudrate") == 0) {
			pconfig->baudrate = parval;
#ifdef HAVE_GPIO
		} else if (strcmp(cmd, "gpio_device") == 0) {
			pconfig->gpio_device = strdup(par);
		} else if (strcmp(cmd, "gpio_pin") == 0 ) {
			pconfig->gpio_pin = parval;
#endif
		} else if (strcmp(cmd, "daemonize") == 0) {
			pconfig->daemonize = config_yes_no(par);
		} else if (strcmp(cmd, "debug") == 0) {
			pconfig->debug = config_yes_no(par);
		} else if (strcmp(cmd, "user") == 0) {
			pconfig->user = strdup(par);
		} else if (strcmp(cmd, "chroot") == 0) {
			pconfig->chroot = strdup(par);
		} else if (strcmp(cmd, "samples") == 0) {
			pconfig->samples = parval;
		} else if (strcmp(cmd, "datalog") == 0) {
			pconfig->datalog = strdup(par);
		} else if (strcmp(cmd, "graphite") == 0) {
			continue;
		} else {
			printf("%s=%s not understood\n", cmd, par);
			exit(1);
		}
	}

	fclose(fh);

	free(dummy);
}