added ``alias'' option to define hostname aliases for a server

This commit is contained in:
Omar Polo 2021-04-29 18:23:35 +00:00
parent 8e8b2e252c
commit cc8c2901ad
7 changed files with 42 additions and 4 deletions

View File

@ -1,3 +1,7 @@
2021-04-29 Omar Polo <op@omarpolo.com>
* parse.y (servopt): added ``alias'' option to define hostname aliases for a server
2021-04-28 Omar Polo <op@omarpolo.com>
* gmid.c (main): pidfile support with `-P pidfile'

6
gmid.1
View File

@ -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.

6
gmid.c
View File

@ -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);
}

7
gmid.h
View File

@ -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 */

1
lex.l
View File

@ -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;

14
parse.y
View File

@ -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 <str> 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 == '/')

View File

@ -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,