Added default-user-config and default-group-config configuration options.

These allow setting a configuration file that will be loaded if a
user-specific or group-specific configuration file isn't found.
This commit is contained in:
Nikos Mavrogiannopoulos
2014-05-14 13:17:45 +02:00
parent 3f9a215f53
commit 788560b9ce
5 changed files with 35 additions and 5 deletions

View File

@@ -197,6 +197,10 @@ run-as-group = daemon
# The name of the tun device
device = vpns
# Whether the generated IPs will be predictable, i.e., IP stays the
# same for the same user when possible.
predictable-ips = true
# The default domain to be advertised
default-domain = example.com
@@ -261,6 +265,12 @@ route = 192.168.5.0/255.255.255.0
#config-per-user = /etc/ocserv/config-per-user/
#config-per-group = /etc/ocserv/config-per-group/
# When config-per-xxx is specified and there is no group or user that
# matches, then utilize the following configuration.
#default-user-config = /etc/ocserv/defaults/user.conf
#default-group-config = /etc/ocserv/defaults/group.conf
# The system command to use to setup a route. %R will be replaced with the
# route/mask and %D with the (tun) device.
#

View File

@@ -125,6 +125,8 @@ static struct cfg_options available_options[] = {
{ .name = "route-del-cmd", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "config-per-user", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "config-per-group", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "default-user-config", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "default-group-config", .type = OPTION_STRING, .mandatory = 0 },
};
static const tOptionValue* get_option(const char* name, unsigned * mand)
@@ -512,6 +514,9 @@ unsigned force_cert_auth;
READ_STRING("config-per-user", config->per_user_dir);
READ_STRING("config-per-group", config->per_group_dir);
READ_STRING("default-user-config", config->default_user_conf);
READ_STRING("default-group-config", config->default_group_conf);
optionUnloadNested(pov);
}

View File

@@ -138,7 +138,7 @@ int handle_script_exit(main_server_st *s, struct proc_st *proc, int code)
}
static int read_additional_config_file(main_server_st * s, struct proc_st *proc,
const char *file, const char *type)
const char *file, const char *fallback, const char *type)
{
int ret;
@@ -150,8 +150,16 @@ static int read_additional_config_file(main_server_st * s, struct proc_st *proc,
if (ret < 0)
return ERR_READ_CONFIG;
} else {
mslog(s, proc, LOG_DEBUG, "No %s configuration for '%s'", type,
proc->username);
if (fallback != NULL) {
mslog(s, proc, LOG_DEBUG, "Loading default %s configuration '%s'", type, fallback);
ret = parse_group_cfg_file(s, proc, fallback);
if (ret < 0)
return ERR_READ_CONFIG;
} else {
mslog(s, proc, LOG_DEBUG, "No %s configuration for '%s'", type,
proc->username);
}
}
return 0;
@@ -169,7 +177,7 @@ static int read_additional_config(struct main_server_st *s,
snprintf(file, sizeof(file), "%s/%s", s->config->per_group_dir,
proc->groupname);
ret = read_additional_config_file(s, proc, file, "group");
ret = read_additional_config_file(s, proc, file, s->config->default_group_conf, "group");
if (ret < 0)
return ret;
}
@@ -178,7 +186,7 @@ static int read_additional_config(struct main_server_st *s,
snprintf(file, sizeof(file), "%s/%s", s->config->per_user_dir,
proc->username);
ret = read_additional_config_file(s, proc, file, "user");
ret = read_additional_config_file(s, proc, file, s->config->default_user_conf, "user");
if (ret < 0)
return ret;
}

View File

@@ -359,6 +359,11 @@ route = 192.168.5.0/255.255.255.0
#config-per-user = /etc/ocserv/config-per-user/
#config-per-group = /etc/ocserv/config-per-group/
# When config-per-xxx is specified and there is no group or user that
# matches, then utilize the following configuration.
#default-user-config = /etc/ocserv/defaults/user.conf
#default-group-config = /etc/ocserv/defaults/group.conf
# The system command to use to setup a route. %R will be replaced with the
# route/mask and %D with the (tun) device.
#

View File

@@ -262,6 +262,8 @@ struct cfg_st {
/* additional configuration files */
char *per_group_dir;
char *per_user_dir;
char *default_group_conf;
char *default_user_conf;
/* the tun network */
struct vpn_st network;