From d57dc1f9239e6fb8feab69be05440bd3d3c61c85 Mon Sep 17 00:00:00 2001 From: trasz Date: Tue, 25 Mar 2014 12:14:48 +0000 Subject: MFC r261759: Make it possible to redefine portal-group "default". Sponsored by: The FreeBSD Foundation --- usr.sbin/ctld/ctld.h | 3 +++ usr.sbin/ctld/parse.y | 26 +++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h index 188645e..a4b1e4e 100644 --- a/usr.sbin/ctld/ctld.h +++ b/usr.sbin/ctld/ctld.h @@ -146,6 +146,9 @@ struct conf { uint16_t conf_last_portal_group_tag; struct pidfh *conf_pidfh; + + bool conf_default_pg_defined; + bool conf_default_ag_defined; }; #define CONN_SESSION_TYPE_NONE 0 diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y index d3d8330..bed1b5c 100644 --- a/usr.sbin/ctld/parse.y +++ b/usr.sbin/ctld/parse.y @@ -224,7 +224,17 @@ portal_group: PORTAL_GROUP portal_group_name portal_group_name: STR { - portal_group = portal_group_new(conf, $1); + /* + * Make it possible to redefine default + * portal-group. but only once. + */ + if (strcmp($1, "default") == 0 && + conf->conf_default_pg_defined == false) { + portal_group = portal_group_find(conf, $1); + conf->conf_default_pg_defined = true; + } else { + portal_group = portal_group_new(conf, $1); + } free($1); if (portal_group == NULL) return (1); @@ -703,6 +713,7 @@ conf_new_from_file(const char *path) conf = conf_new(); ag = auth_group_new(conf, "no-authentication"); + assert(ag != NULL); ag->ag_type = AG_TYPE_NO_AUTHENTICATION; /* @@ -710,11 +721,11 @@ conf_new_from_file(const char *path) * any entries and thus will always deny access. */ ag = auth_group_new(conf, "no-access"); + assert(ag != NULL); ag->ag_type = AG_TYPE_CHAP; pg = portal_group_new(conf, "default"); - portal_group_add_listen(pg, "0.0.0.0:3260", false); - portal_group_add_listen(pg, "[::]:3260", false); + assert(pg != NULL); yyin = fopen(path, "r"); if (yyin == NULL) { @@ -736,6 +747,15 @@ conf_new_from_file(const char *path) return (NULL); } + if (conf->conf_default_pg_defined == false) { + log_debugx("portal-group \"default\" not defined; " + "going with defaults"); + pg = portal_group_find(conf, "default"); + assert(pg != NULL); + portal_group_add_listen(pg, "0.0.0.0:3260", false); + portal_group_add_listen(pg, "[::]:3260", false); + } + error = conf_verify(conf); if (error != 0) { conf_delete(conf); -- cgit v1.1