Пример #1
0
static void test_config_file_read_invalid_values(void)
{
	int ret = 0;
	struct configuration config;

	diag("Config file read invalid values");

	ret = config_file_read(fixture("config2"), &config);
	ok(ret == -EINVAL &&
		config.conf_file.tor_port == 0,
		"TorPort 65536 returns -EINVAL");

	memset(&config, 0x0, sizeof(config));
	ret = config_file_read(fixture("config3"), &config);
	ok(ret == -EINVAL &&
		config.conf_file.tor_port == 0,
		"TorPort 0 returns -EINVAL");

	memset(&config, 0x0, sizeof(config));
	ret = config_file_read(fixture("config4"), &config);
	ok(ret == 0 &&
		config.conf_file.tor_address == NULL,
		"TorAddress invalid IPv4 returns -1");

	memset(&config, 0x0, sizeof(config));
	ret = config_file_read(fixture("config5"), &config);
	ok(ret == 0 &&
		config.conf_file.tor_address == NULL,
		"TorAddress invalid IPv6 returns -1");

	memset(&config, 0x0, sizeof(config));
	ret = config_file_read(fixture("config6"), &config);
	ok(ret == -EINVAL &&
		config.conf_file.onion_mask == 0,
		"OnionAdrRange invalid range returns -EINVAL");

	memset(&config, 0x0, sizeof(config));
	ret = config_file_read(fixture("config7"), &config);
	ok(ret == -EINVAL &&
		config.conf_file.onion_base == 0,
		"OnionAdrRange invalid IPv4 address returns -EINVAL");

	memset(&config, 0x0, sizeof(config));
	ret = config_file_read(fixture("config8"), &config);
	ok(ret == -EINVAL &&
		config.conf_file.onion_base == 0,
		"OnionAdrRange invalid IPv6 address returns -EINVAL");

	memset(&config, 0x0, sizeof(config));
#if (defined(__LP64__))
	ret = config_file_read(fixture("config9_64"), &config);
#else
	ret = config_file_read(fixture("config9_32"), &config);
#endif
	ok(ret == -EINVAL &&
		config.conf_file.onion_base == 0,
		"OnionAdrRange invalid mask returns -EINVAL");
}
Пример #2
0
void parse_config(char *configfile,struct mfshell_user_options *opts)
{
    FILE            *fp;

    char            **argv = NULL;              // create our own argv
    int             argc;                       // create one own argc
    int             new_items = 0;

    fp = fopen(configfile,"r");
    if(fp == NULL) return;

    // getopt_long() expect at least argc >= 1 and argv[0] != NULL
    argv = (char**)calloc(1,sizeof(char*));
    argv[0] = strdup("mediafire-shell");
    argc = 1;

    new_items = config_file_read(fp, &argc, &argv);
    fprintf(stderr,"argc = %d\n", argc);

    parse_argv(argc, argv, opts);

    if(new_items > 0)
    {
        string_array_free(argv);
    }
    else
    {
        free(argv[0]);
        free(argv);
    }

    return;
}
Пример #3
0
struct dm_config_tree *config_file_open_and_read(const char *config_file,
						 config_source_t source)
{
	struct dm_config_tree *cft;
	struct stat info;

	if (!(cft = config_open(source, config_file, 0))) {
		log_error("config_tree allocation failed");
		return NULL;
	}

	/* Is there a config file? */
	if (stat(config_file, &info) == -1) {
		/* Profile file must be present! */
		if (errno == ENOENT && (source != CONFIG_PROFILE))
			return cft;
		log_sys_error("stat", config_file);
		goto bad;
	}

	log_very_verbose("Loading config file: %s", config_file);
	if (!config_file_read(cft)) {
		log_error("Failed to load config file %s", config_file);
		goto bad;
	}

	return cft;
bad:
	config_destroy(cft);
	return NULL;
}
Пример #4
0
/*
 * Initialize torsocks configuration from a given conf file or the default one.
 */
static void init_config(void)
{
	int ret;
	const char *filename = NULL;

	if (!is_suid) {
		filename = getenv("TORSOCKS_CONF_FILE");
	}

	ret  = config_file_read(filename, &tsocks_config);
	if (ret < 0) {
		/*
		 * Failing to get the configuration means torsocks can not function
		 * properly so stops everything.
		 */
		clean_exit(EXIT_FAILURE);
	}

	/*
	 * Setup configuration from config file. Use defaults if some attributes
	 * are missing.
	 */
	if (!tsocks_config.conf_file.tor_address) {
		tsocks_config.conf_file.tor_address = strdup(DEFAULT_TOR_ADDRESS);
		if (!tsocks_config.conf_file.tor_address) {
			/* Most likely ENOMEM thus we can't continue. */
			clean_exit(EXIT_FAILURE);
		}
	}
	if (tsocks_config.conf_file.tor_port == 0) {
		tsocks_config.conf_file.tor_port = DEFAULT_TOR_PORT;
	}
	if (tsocks_config.conf_file.tor_domain == 0) {
		tsocks_config.conf_file.tor_domain = DEFAULT_TOR_DOMAIN;
	}
	if (tsocks_config.conf_file.onion_base == 0) {
		tsocks_config.conf_file.onion_base = inet_addr(DEFAULT_ONION_ADDR_RANGE);
		tsocks_config.conf_file.onion_mask = atoi(DEFAULT_ONION_ADDR_MASK);
	}

	/* Create the Tor SOCKS5 connection address. */
	ret = connection_addr_set(tsocks_config.conf_file.tor_domain,
			tsocks_config.conf_file.tor_address,
			tsocks_config.conf_file.tor_port, &tsocks_config.socks5_addr);
	if (ret < 0) {
		/*
		 * Without a valid connection address object to Tor well torsocks can't
		 * work properly at all so abort everything.
		 */
		clean_exit(EXIT_FAILURE);
	}

	/* Handle possible env. variables. */
	read_env();
}
Пример #5
0
int
secure_read ()
{
    int rc;

    secure_data_encrypted = 0;

    rc = config_file_read (secure_config_file);

    return rc;
}
Пример #6
0
struct volume_group *text_vg_import_fd(struct format_instance *fid,
				       const char *file,
				       int single_device,
				       struct device *dev,
				       off_t offset, uint32_t size,
				       off_t offset2, uint32_t size2,
				       checksum_fn_t checksum_fn,
				       uint32_t checksum,
				       time_t *when, char **desc)
{
	struct volume_group *vg = NULL;
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;

	_init_text_import();

	*desc = NULL;
	*when = 0;

	if (!(cft = config_open(CONFIG_FILE, file, 0)))
		return_NULL;

	if ((!dev && !config_file_read(cft)) ||
	    (dev && !config_file_read_fd(cft, dev, offset, size,
					 offset2, size2, checksum_fn, checksum))) {
		log_error("Couldn't read volume group metadata.");
		goto out;
	}

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vg = (*vsn)->read_vg(fid, cft, single_device)))
			goto_out;

		(*vsn)->read_desc(vg->vgmem, cft, when, desc);
		break;
	}

      out:
	config_destroy(cft);
	return vg;
}
Пример #7
0
static void test_config_file_read_empty(void)
{
	int ret = 0;
	struct configuration config;
	char buf[DEFAULT_DOMAIN_NAME_SIZE];

	diag("Config file read empty");

	ret = config_file_read(fixture("config1"), &config);
	inet_ntop(AF_INET, &config.conf_file.onion_base, buf, sizeof(buf));
	ok(ret == 0 &&
		config.conf_file.tor_port == 0 &&
		config.conf_file.tor_address == NULL &&
		strcmp(buf, "0.0.0.0") == 0 &&
		config.conf_file.onion_mask == 0,
		"Read empty config file");
}
Пример #8
0
static void test_config_file_read_valid(void)
{
	int ret = 0;
	struct configuration config;
	char buf[DEFAULT_DOMAIN_NAME_SIZE];

	diag("Config file read valid");

	ret = config_file_read(fixture("config0"), &config);
	inet_ntop(AF_INET, &config.conf_file.onion_base, buf, sizeof(buf));
	ok(ret == 0 &&
		config.conf_file.tor_port == DEFAULT_TOR_PORT &&
		strcmp(config.conf_file.tor_address, DEFAULT_TOR_ADDRESS) == 0 &&
		strcmp(buf, DEFAULT_ONION_ADDR_RANGE) == 0 &&
		config.conf_file.onion_mask == strtoul(DEFAULT_ONION_ADDR_MASK, NULL, 0),
		"Read valid config file");
}
Пример #9
0
void config_file_to_opt(const char *filename){
  dynamic_array_t *a;

  if((a=config_file_read(filename))==NULL){
    return;
  }
  
  /* Set options according to config file but only if they are not 
   * Masked (overriden on the command line)
   */

  options(
    dynamic_array_get_count(a),
    dynamic_array_get_vector(a),
    OPT_USE_MASK|OPT_FILE|OPT_ERR
  );

  dynamic_array_destroy(a, DESTROY_STR);

  return;
}
Пример #10
0
const char *text_vgname_import(const struct format_type *fmt,
			       struct device *dev,
			       off_t offset, uint32_t size,
			       off_t offset2, uint32_t size2,
			       checksum_fn_t checksum_fn, uint32_t checksum,
			       struct id *vgid, uint64_t *vgstatus,
			       char **creation_host)
{
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;
	const char *vgname = NULL;

	_init_text_import();

	if (!(cft = config_open(CONFIG_FILE, NULL, 0)))
		return_NULL;

	if ((!dev && !config_file_read(cft)) ||
	    (dev && !config_file_read_fd(cft, dev, offset, size,
					 offset2, size2, checksum_fn, checksum)))
		goto_out;

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vgname = (*vsn)->read_vgname(fmt, cft, vgid, vgstatus,
						   creation_host)))
			goto_out;

		break;
	}

      out:
	config_destroy(cft);
	return vgname;
}
Пример #11
0
int
plugin_config_read ()
{
    return config_file_read (plugin_config_file);
}
Пример #12
0
int main (int argc, char *argv[])
{
	GtkWidget	*main_window;
	GOptionContext	*context;
	GError		*option_error;
	gchar		*config_file_name, *dir;
	gboolean	show_version = FALSE;

	GOptionEntry options[] =
	{
		{
			"version",
			'v',
			0,
			G_OPTION_ARG_NONE,
			&show_version,
			_("Show version information"),
			NULL
		},
		{NULL}
	};

#ifdef WITH_HILDON
	HildonProgram   *hildon_program;
#endif

#ifdef ENABLE_NLS
	bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (PACKAGE, "UTF-8");
	textdomain (PACKAGE);
  
	gtk_set_locale();
#endif

	/* Parse command line options */
	context = g_option_context_new (NULL);
	g_option_context_set_summary(context,
			_("Carry out simple and scientific calculations"));
#ifdef ENABLE_NLS
	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
#else
	g_option_context_add_main_entries (context, options, NULL);
#endif
	g_option_context_add_group (context, gtk_get_option_group (TRUE));

	if (!g_option_context_parse (context, &argc, &argv, &option_error))
	{
		if (option_error)
			g_print ("%s\n", option_error->message);

		return EXIT_FAILURE;
	}

	g_option_context_free (context);

	if(show_version == TRUE)
	{
		g_print(_("%s v%s, (c) 2002-2010 Simon Floery\n"),
			PACKAGE, VERSION);
		return EXIT_SUCCESS;
	}


	gtk_init (&argc, &argv);

	/* at first, get config file */
	dir = g_build_filename (g_get_user_config_dir (), PACKAGE, NULL);
	g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
	config_file_name = g_build_filename (dir, CONFIG_FILE_NAME, NULL);
	g_free(dir);

	prefs = config_file_read (config_file_name);
	
	constant = config_file_get_constants();
	user_function = config_file_get_user_functions();
	g_free (config_file_name);

	current_status.notation = prefs.def_notation;

#ifdef WITH_HILDON
	gtkbuilder_register_widget (HILDON_TYPE_WINDOW, gtkbuilder_hildon_window_new, gtkbuilder_standard_build_children, NULL);
	hildon_program = HILDON_PROGRAM(hildon_program_get_instance());
#endif

	/* at first get the main frame */
	
	/* sth like ui_launch_up_ui for splitting into first time wizard? */
	main_window = ui_main_window_create();
#ifdef WITH_HILDON
	hildon_program_add_window(hildon_program, HILDON_WINDOW(main_window));
	g_set_application_name(PACKAGE_NAME);
	create_hildon_menu(HILDON_WINDOW(main_window));
#endif	

	/* set the window title */
#ifndef WITH_DEFCALC
	gtk_window_set_title ((GtkWindow *)main_window, PACKAGE_NAME);
#else
	gtk_window_set_title ((GtkWindow *)main_window, "Calculator");
#endif

	/* set the window's icon */
#ifndef WITH_DEFCALC
	gtk_window_set_default_icon_name (PACKAGE);
#else
	gtk_window_set_default_icon_name ("utilities-calculator");
#endif

	/* usually, only Shift, CTRL and ALT modifiers are paid attention to by 
	 * accelerator code. add MOD2 (NUMLOCK allover the world?) to the list. 
	 * We have to do this for a working keypad.
	 */

	gtk_accelerator_set_default_mod_mask (gtk_accelerator_get_default_mod_mask () | GDK_MOD2_MASK); 
				  
	/* prepare calc_basic */

	main_alg = alg_init (0);
	rpn_init (prefs.stack_size, 0);
		
	/* apply changes */
	apply_preferences (prefs);

	memory.data = NULL;
	memory.len = 0;

	/* see function key_snooper for details */
	gtk_key_snooper_install (key_snooper, NULL);

	gtk_window_resize ((GtkWindow *)main_window, 1, 1);
	
	/* gtk_widget_show main window as late as possible */
	gtk_widget_show (main_window);

	gtk_main ();

	/* save changes to file */
	dir = g_build_filename (g_get_user_config_dir (), PACKAGE, NULL);
	g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
	config_file_name = g_build_filename (dir, CONFIG_FILE_NAME, NULL);
	g_free(dir);

	config_file_write (config_file_name, prefs, constant, user_function);
	g_free (config_file_name);

	return EXIT_SUCCESS;
}
Пример #13
0
/*
 * Find out vgname on a given device.
 */
int text_read_metadata_summary(const struct format_type *fmt,
		       struct device *dev, dev_io_reason_t reason,
		       off_t offset, uint32_t size,
		       off_t offset2, uint32_t size2,
		       checksum_fn_t checksum_fn,
		       int checksum_only,
		       struct lvmcache_vgsummary *vgsummary)
{
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;
	int r = 0;

	_init_text_import();

	if (!(cft = config_open(CONFIG_FILE_SPECIAL, NULL, 0)))
		return_0;

	if (dev) {
		log_debug_metadata("Reading metadata summary from %s at %llu size %d (+%d)",
				   dev_name(dev), (unsigned long long)offset,
				   size, size2);

		if (!config_file_read_fd(cft, dev, reason, offset, size,
					 offset2, size2, checksum_fn,
					 vgsummary->mda_checksum,
					 checksum_only, 1)) {
			/* FIXME: handle errors */
			log_error("Couldn't read volume group metadata from %s.", dev_name(dev));
			goto out;
		}
	} else {
		if (!config_file_read(cft)) {
			log_error("Couldn't read volume group metadata from file.");
			goto out;
		}
	}

	if (checksum_only) {
		/* Checksum matches already-cached content - no need to reparse. */
		log_debug_metadata("Skipped parsing metadata on %s", dev_name(dev));
		r = 1;
		goto out;
	}

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(*vsn)->read_vgsummary(fmt, cft, vgsummary))
			goto_out;

		r = 1;
		break;
	}

      out:
	config_destroy(cft);
	return r;
}
Пример #14
0
struct volume_group *text_read_metadata(struct format_instance *fid,
				       const char *file,
				       struct cached_vg_fmtdata **vg_fmtdata,
				       unsigned *use_previous_vg,
				       struct device *dev, int primary_mda,
				       off_t offset, uint32_t size,
				       off_t offset2, uint32_t size2,
				       checksum_fn_t checksum_fn,
				       uint32_t checksum,
				       time_t *when, char **desc)
{
	struct volume_group *vg = NULL;
	struct dm_config_tree *cft;
	struct text_vg_version_ops **vsn;
	int skip_parse;

	/*
	 * This struct holds the checksum and size of the VG metadata
	 * that was read from a previous device.  When we read the VG
	 * metadata from this device, we can skip parsing it into a
	 * cft (saving time) if the checksum of the metadata buffer
	 * we read from this device matches the size/checksum saved in
	 * the mda_header/rlocn struct on this device, and matches the
	 * size/checksum from the previous device.
	 */
	if (vg_fmtdata && !*vg_fmtdata &&
	    !(*vg_fmtdata = dm_pool_zalloc(fid->mem, sizeof(**vg_fmtdata)))) {
		log_error("Failed to allocate VG fmtdata for text format.");
		return NULL;
	}

	_init_text_import();

	*desc = NULL;
	*when = 0;

	if (!(cft = config_open(CONFIG_FILE_SPECIAL, file, 0)))
		return_NULL;

	/* Does the metadata match the already-cached VG? */
	skip_parse = vg_fmtdata && 
		     ((*vg_fmtdata)->cached_mda_checksum == checksum) &&
		     ((*vg_fmtdata)->cached_mda_size == (size + size2));


	if (dev) {
		log_debug_metadata("Reading metadata from %s at %llu size %d (+%d)",
				   dev_name(dev), (unsigned long long)offset,
				   size, size2);

		if (!config_file_read_fd(cft, dev, MDA_CONTENT_REASON(primary_mda), offset, size,
					 offset2, size2, checksum_fn, checksum,
					 skip_parse, 1)) {
			/* FIXME: handle errors */
			log_error("Couldn't read volume group metadata from %s.", dev_name(dev));
			goto out;
		}
	} else {
		if (!config_file_read(cft)) {
			log_error("Couldn't read volume group metadata from file.");
			goto out;
		}
	}

	if (skip_parse) {
		if (use_previous_vg)
			*use_previous_vg = 1;
		log_debug_metadata("Skipped parsing metadata on %s", dev_name(dev));
		goto out;
	}

	/*
	 * Find a set of version functions that can read this file
	 */
	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
		if (!(*vsn)->check_version(cft))
			continue;

		if (!(vg = (*vsn)->read_vg(fid, cft, 0)))
			goto_out;

		(*vsn)->read_desc(vg->vgmem, cft, when, desc);
		break;
	}

	if (vg && vg_fmtdata && *vg_fmtdata) {
		(*vg_fmtdata)->cached_mda_size = (size + size2);
		(*vg_fmtdata)->cached_mda_checksum = checksum;
	}

	if (use_previous_vg)
		*use_previous_vg = 0;

      out:
	config_destroy(cft);
	return vg;
}