Commit Diff
Diff:
8e8b2e252c37a1e633c33ac923ab78c3f1e8ab31
cc8c2901ad544d336374887451dc8c85a5ae1264
Commit:
cc8c2901ad544d336374887451dc8c85a5ae1264
Tree:
46f42e9929fd44cf9bf94a9a2b6a81de2f72a517
Author:
Omar Polo <op@omarpolo.com>
Date:
Thu Apr 29 18:23:35 2021 UTC
Message:
added ``alias'' option to define hostname aliases for a server
commit - 8e8b2e252c37a1e633c33ac923ab78c3f1e8ab31
commit + cc8c2901ad544d336374887451dc8c85a5ae1264
blob - 3200dc0bf628e78f072234290d017e22ef799655
blob + fd9c39132abca70abee5a57a670e913e6b831021
--- ChangeLog
+++ ChangeLog
@@ -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'
blob - 0e08e2ff01dc1070bc6f1db9d6a186fef39ebd2b
blob + 332eed1f0e0dada5abcdbedbb040169aeafb0d8c
--- gmid.1
+++ gmid.1
@@ -192,6 +192,10 @@ Followed by a block of options that is enclosed in cur
.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 @@ except
.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.
blob - 30ffaa12cc982ecf17be00e213fce5d1324eb90b
blob + 0af53f3f5eb37e5466caec6042d9b2127bd9e760
--- gmid.c
+++ 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;
@@ -271,6 +272,11 @@ free_config(void)
free(e->name);
free(e->value);
free(e);
+ }
+
+ TAILQ_FOREACH_SAFE(a, &h->aliases, aliases, ta) {
+ free(a->alias);
+ free(a);
}
TAILQ_REMOVE(&hosts, h, vhosts);
blob - f29c210e0fa6286fb4f050d78ac5a712650d2c70
blob + 5eec8af079d3151b5a57d86bb012bcc24acafeed
--- gmid.h
+++ gmid.h
@@ -80,6 +80,12 @@ extern TAILQ_HEAD(vhosthead, vhost) hosts;
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 */
blob - e4b5e6d6b14d9c8f435da0e5c5bff3188e6807b1
blob + 1aa87f2f23f40994f19f6cf4cc5450e93a758105
--- lex.l
+++ lex.l
@@ -51,6 +51,7 @@ auto return TAUTO;
off yylval.num = 0; return TBOOL;
on yylval.num = 1; return TBOOL;
+alias return TALIAS;
auto return TAUTO;
block return TBLOCK;
ca return TCA;
blob - cc9c99868be28cf14097905ff591a7635922a607
blob + d675a822fd6b1b733bd035416cf29649bd6296d7
--- parse.y
+++ 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 <str> TSTRING
@@ -119,7 +119,17 @@ servopt : TCERT TSTRING { host->cert = ensure_absolu
| 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 == '/')
blob - 5812c664765b7d7901c186f84883de6a2f97539e
blob + 86c8d0886707548054ba07f1a8004df3328bcee7
--- server.c
+++ 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,
Omar Polo