[sr-dev] [tracker] Task opened: tls module 'config' param can point to directory

sip-router admin at sip-router.org
Sat Oct 2 18:50:56 CEST 2010


THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below. 

User who did this - Juha Heinanen (jh) 

Attached to Project - sip-router
Summary - tls module 'config' param can point to directory
Task Type - Improvement
Category - tls
Status - Assigned
Assigned To - Andrei Pelinescu-Onciul
Operating System - All
Severity - Medium
Priority - Normal
Reported Version - Development
Due in Version - Undecided
Due Date - Undecided
Details - i modified tls/tls_config.c tls_load_config() function so that it checks if file pointed to by 'config' module param is a directory.  if it is, tls_load_config() copies all regular files of that directory to a tmp file and then passes that tmp file to cfg_parser.  that way config parser can stay as is.
 
reason for this improvement is that it is easier from management point of view to add/remove files when peers come and go rather than edit a monolithic single config file.  modified tls_load_config() is below.  feel free to implement same functionality in some other way.  i don't care how it is done as long as the feature is available.  if adopted, i'll update README accordingly.

-- juha

------------------------------------------------------------------------------------------------------------------


/*
 * Create configuration structures from configuration file
 */
tls_domains_cfg_t* tls_load_config(str* filename)
{
	cfg_parser_t* parser;
	str empty;
	struct stat file_status;
	char tmp_name[13] = "configXXXXXX";
	str filename_str;
	DIR *dir;
	struct dirent *ent;
	int out_fd, in_fd, filename_is_directory;
	char *file_path, ch;

	parser = NULL;
	memset(&file_status, 0, sizeof(struct stat));
	dir = (DIR *)NULL;
	in_fd = out_fd = filename_is_directory = 0;
	file_path = (char *)0;

	if ((cfg = tls_new_cfg()) == NULL) goto error;

	if (stat(filename->s, &file_status) != 0) {
	    LOG(L_ERR, "cannot stat config file %s\n", filename->s);
	    goto error;
	}
	if (S_ISDIR(file_status.st_mode)) {
	    filename_is_directory = 1;
	    dir = opendir(filename->s);
	    if (dir == NULL) {
		LOG(L_ERR, "cannot open directory file %s\n", filename->s);
		goto error;
	    }
	    out_fd = mkstemp(&(tmp_name[0]));
	    if (out_fd == -1) {
		LOG(L_ERR, "cannot make tmp file %s\n", &(tmp_name[0]));
		goto error;
	    }
	    while ((ent = readdir(dir)) != NULL) {
		file_path = pkg_malloc(filename->len + 1 + 256);
		memcpy(file_path, filename->s, filename->len);
		file_path[filename->len] = '/';
		strcpy(file_path + filename->len + 1, ent->d_name);
		if (stat(file_path, &file_status) != 0) {
		    LOG(L_ERR, "cannot get status of config file %s\n",
			file_path);
		    goto error;
		}
		if (S_ISREG(file_status.st_mode)) {
		    in_fd = open(file_path, O_RDONLY);
		    if (in_fd == -1) {
			LOG(L_ERR, "cannot open config file %s\n",
			    file_path);
			goto error;
		    }
		    pkg_free(file_path);
		    while (read(in_fd, &ch, 1)) {
			write(out_fd, &ch, 1);
		    }
		    close(in_fd);
		    in_fd = 0;
		    ch = '\n';
		    write(out_fd, &ch, 1);
		}
	    }
	    closedir(dir);
	    close(out_fd);
	    dir = (DIR *)NULL;
	    out_fd = 0;
	}

	empty.s = 0;
	empty.len = 0;
	if (filename_is_directory) {
	    filename_str.s = &(tmp_name[0]);
	    filename_str.len = strlen(&(tmp_name[0]));
	    if ((parser = cfg_parser_init(&empty, &filename_str)) == NULL) {
		ERR("tls: Error while initializing configuration file parser.\n");
		unlink(&(tmp_name[0]));
		goto error;
	    }
	    unlink(&(tmp_name[0]));
	} else {
		if ((parser = cfg_parser_init(&empty, filename)) == NULL) {
		    ERR("tls: Error while initializing configuration file parser.\n");
		    goto error;
		}		
	}

	cfg_section_parser(parser, parse_domain, NULL);
	if (sr_cfg_parse(parser)) goto error;
	cfg_parser_close(parser);
	return cfg;

 error:
	if (dir) closedir(dir);
	if (out_fd > 0) {
	    close(out_fd);
	    unlink(&(tmp_name[0]));
	}
	if (file_path) pkg_free(file_path);
	if (parser) cfg_parser_close(parser);
	if (cfg) tls_free_cfg(cfg);
	return 0;
}


More information can be found at the following URL:
http://sip-router.org/tracker/index.php?do=details&task_id=89

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.



More information about the sr-dev mailing list