Exemplo n.º 1
0
/*
 * read initiator name from supplied filename
 */
int
isns_read_initiatorname(const char *filename)
{
	FILE	*fp;
	char	*name, *pos;

	if ((fp = fopen(filename, "r")) == NULL) {
		perror(filename);
		return -1;
	}

	while ((pos = parser_get_next_line(fp)) != NULL) {
		pos[strcspn(pos, "#")] = '\0';

		if (!(name = parser_get_next_word(&pos)))
			continue;
		if (strcmp(name, "InitiatorName"))
			continue;
		if (pos[0] == '=')
			pos++;
		if (!strncmp(pos, "iqn.", 4))
			isns_assign_string(&isns_config.ic_source_name, pos);
	}

	fclose(fp);
	return 0;
}
Exemplo n.º 2
0
int
parser_split_line(char *line, unsigned int argsmax, char **argv)
{
	unsigned int	argc = 0;
	char		*s;

	while (argc < argsmax && (s = parser_get_next_word(&line)))
		argv[argc++] = strdup(s);
	return argc;
}
Exemplo n.º 3
0
/*
 * Read the iSNS configuration file
 */
int
isns_read_config(const char *filename)
{
	FILE	*fp;
	char	*name, *pos;

	__isns_config_defaults();

	if ((fp = fopen(filename, "r")) == NULL) {
		perror(filename);
		return -1;
	}

	while ((pos = parser_get_next_line(fp)) != NULL) {
		pos[strcspn(pos, "#")] = '\0';

		if (!(name = parser_get_next_word(&pos)))
			continue;

		isns_config_set(name, pos);
	}

	fclose(fp);

	/* Massage the config file */
	if (isns_config.ic_security < 0) {
		/* By default, we will enable authentication
		 * whenever we find our private key, and
		 * the server's public key. */
		if (access(isns_config.ic_auth_key_file, R_OK) == 0
		 && access(isns_config.ic_server_key_file, R_OK) == 0)
			isns_config.ic_security = 1;
		else
			isns_config.ic_security = 0;
	}

	return 0;
}