diff options
| -rw-r--r-- | config.c | 11 | ||||
| -rw-r--r-- | config.h | 4 | ||||
| -rw-r--r-- | pullreqd.c | 9 | 
3 files changed, 14 insertions, 10 deletions
| @@ -2,6 +2,7 @@  #include <stdint.h>  #include <stdlib.h>  #include <string.h> +#include <syslog.h>  #include "config.h"  char *read_file(const char *filename, long *size) { @@ -152,6 +153,16 @@ config *parse_config(const char *filename) {  		/* Is the config option valid? */  		if (opt->name != NULL) {  			config_val val = parse_option_value(opt, value); +			if (opt->offset == offsetof(config, port)) { +				const int port = strtol(val.str, NULL, 0); +				if (port <= 0 || port > 65535) { +					syslog(LOG_ERR, "Invalid port %d. (Valid port must be between 1, and 65535.)", port); +					cleanup_config(cfg); +					free(line); +					free(buf); +					return NULL; +				} +			}  			set_config_opt(cfg, opt->type, opt->offset, val);  		} @@ -21,7 +21,7 @@ struct config {  	char *git_root;		/* Root of git server. */  	char *sock_type;	/* Type of socket. */  	char *sock;		/* Socket address. */ -	int port;		/* Listen port. */ +	char *port;		/* Listen port. */  	int merge_type;		/* Merge type. */  	char *pr_root;		/* Root of pull requests. */  	char *key_path;		/* Path to maintainer authentication key file. */ @@ -44,7 +44,7 @@ static const config_opt config_opts[] = {  	{"git-root", "Root of git server (can also be a url).", TYPE_STRING, offsetof(config, git_root)},  	{"socket-type", "Socket type to use (options: unix, network. default: network).", TYPE_STRING, offsetof(config, sock_type)},  	{"socket", "Path, IP address, or domain name of socket.", TYPE_STRING, offsetof(config, sock)}, -	{"port", "Port to listen on (network socket only).", TYPE_INT, offsetof(config, port)}, +	{"port", "Port to listen on (network socket only).", TYPE_STRING, offsetof(config, port)},  	{"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", TYPE_INT, offsetof(config, merge_type)},  	{"pr-root", "Directory to store pull requests in.", TYPE_STRING, offsetof(config, pr_root)},  	{"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", TYPE_STRING, offsetof(config, key_path)}, @@ -109,15 +109,8 @@ int init_socket(config *cfg) {  		sock_addr.sa_un.sun_family = sock_type;  		memcpy(sock_addr.sa_un.sun_path, cfg->sock, path_length+1);  	} else { -		if (cfg->port <= 0 || cfg->port > 65535) { -			syslog(LOG_ERR, "Invalid port %d. (Valid port must be between 1, and 65535.)", cfg->port); -			return -1; -		}  		struct addrinfo hints, *ainfo_root, *ainfo; -		const size_t size = snprintf(NULL, 0, "%d", cfg->port) + 1; -		char *port_str = malloc(size); -		sprintf(port_str, "%d", cfg->port);  		memset(&hints, 0, sizeof(hints));  		hints.ai_family = AF_UNSPEC; @@ -125,7 +118,7 @@ int init_socket(config *cfg) {  		/*hints.ai_protocol = IPPROTO_SCTP;*/  		hints.ai_flags = AI_PASSIVE; -		const int gai_ret = getaddrinfo(cfg->sock, port_str, &hints, &ainfo_root); +		const int gai_ret = getaddrinfo(cfg->sock, cfg->port, &hints, &ainfo_root);  		/* Did getaddrinfo fail? */  		if (gai_ret) {  			syslog(LOG_ERR, "getaddrinfo() failed for hostname %s. Reason: %s", cfg->sock, gai_strerror(gai_ret)); | 
