diff --git a/ChangeLog b/ChangeLog index 3200dc0..fd9c391 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-04-29 Omar Polo + + * parse.y (servopt): added ``alias'' option to define hostname aliases for a server + 2021-04-28 Omar Polo * gmid.c (main): pidfile support with `-P pidfile' diff --git a/gmid.1 b/gmid.1 index 0e08e2f..332eed1 100644 --- a/gmid.1 +++ b/gmid.1 @@ -192,6 +192,10 @@ or a name including a wildcards, .Pp Followed by a block of options that is enclosed in curly brackets: .Bl -tag -width Ds +.It Ic alias Ar name +Specify an additional alias +.Ar name +for this server. .It Ic auto Ic index Ar bool If no index file is found, automatically generate a directory listing. It's disabled by default. @@ -282,7 +286,7 @@ A .Ic location section may include most of the server configuration rules except -.Ic cert , Ic env , Ic key , Ic root , Ic location , +.Ic alias , cert , Ic env , Ic key , Ic root , Ic location , .Ic entrypoint No and Ic cgi . .It Ic root Pa directory Specify the root directory for this server. diff --git a/gmid.c b/gmid.c index 30ffaa1..0af53f3 100644 --- a/gmid.c +++ b/gmid.c @@ -245,6 +245,7 @@ free_config(void) struct vhost *h, *th; struct location *l, *tl; struct envlist *e, *te; + struct alist *a, *ta; int v; v = conf.verbose; @@ -273,6 +274,11 @@ free_config(void) free(e); } + TAILQ_FOREACH_SAFE(a, &h->aliases, aliases, ta) { + free(a->alias); + free(a); + } + TAILQ_REMOVE(&hosts, h, vhosts); free(h); } diff --git a/gmid.h b/gmid.h index f29c210..5eec8af 100644 --- a/gmid.h +++ b/gmid.h @@ -80,6 +80,12 @@ struct envlist { TAILQ_ENTRY(envlist) envs; }; +TAILQ_HEAD(aliashead, alist); +struct alist { + char *alias; + TAILQ_ENTRY(alist) aliases; +}; + extern TAILQ_HEAD(vhosthead, vhost) hosts; struct vhost { const char *domain; @@ -98,6 +104,7 @@ struct vhost { struct lochead locations; struct envhead env; + struct aliashead aliases; }; struct etm { /* extension to mime */ diff --git a/lex.l b/lex.l index e4b5e6d..1aa87f2 100644 --- a/lex.l +++ b/lex.l @@ -51,6 +51,7 @@ off yylval.num = 0; return TBOOL; on yylval.num = 1; return TBOOL; +alias return TALIAS; auto return TAUTO; block return TBLOCK; ca return TCA; diff --git a/parse.y b/parse.y index cc9c998..d675a82 100644 --- a/parse.y +++ b/parse.y @@ -60,7 +60,7 @@ void advance_loc(void); %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE %token TCHROOT TUSER TSERVER TPREFORK %token TLOCATION TCERT TKEY TROOT TCGI TENV TLANG TLOG TINDEX TAUTO -%token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA +%token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA TALIAS %token TERR %token TSTRING @@ -119,7 +119,17 @@ servopts : /* empty */ | servopts servopt ; -servopt : TCERT TSTRING { host->cert = ensure_absolute_path($2); } +servopt : TALIAS TSTRING { + struct alist *a; + + a = xcalloc(1, sizeof(*a)); + a->alias = $2; + if (TAILQ_EMPTY(&host->aliases)) + TAILQ_INSERT_HEAD(&host->aliases, a, aliases); + else + TAILQ_INSERT_TAIL(&host->aliases, a, aliases); + } + | TCERT TSTRING { host->cert = ensure_absolute_path($2); } | TCGI TSTRING { /* drop the starting '/', if any */ if (*$2 == '/') diff --git a/server.c b/server.c index 5812c66..86c8d08 100644 --- a/server.c +++ b/server.c @@ -391,6 +391,7 @@ handle_handshake(int fd, short ev, void *d) { struct client *c = d; struct vhost *h; + struct alist *a; const char *servname; const char *parse_err = "unknown error"; @@ -417,9 +418,14 @@ handle_handshake(int fd, short ev, void *d) TAILQ_FOREACH(h, &hosts, vhosts) { if (matches(h->domain, c->domain)) - break; + goto found; + TAILQ_FOREACH(a, &h->aliases, aliases) { + if (matches(a->alias, c->domain)) + goto found; + } } +found: log_debug(c, "handshake: SNI: \"%s\"; decoded: \"%s\"; matched: \"%s\"", servname != NULL ? servname : "(null)", c->domain,