commit 85dff1f9c3b18256f0f2cceb802c3c7f2961bc58 from: Omar Polo date: Mon Jan 11 12:08:50 2021 UTC fix remote_user for CGI and add -6 flag to enable ipv6 commit - 33756bd2353b645a2c046a0807103c309d6d7215 commit + 85dff1f9c3b18256f0f2cceb802c3c7f2961bc58 blob - a36853f7fa086a398c3df98f865536ccd4b0e706 blob + 9f61b0aff0dab0178a16b36866f391fb13affdb5 --- ChangeLog +++ ChangeLog @@ -1,3 +1,7 @@ +2021-01-11 Omar Polo + + * gmid.c (main): ipv6 disabled by default and -6 flag to enable it + 2021-01-10 Omar Polo * gmid.c (logs): log also the port of the client blob - 3e9e46128e3aec385c67204bdd22394472211019 blob + 51404f0154370f3b3d14825214890a69d5a62e2d --- README.md +++ README.md @@ -6,7 +6,7 @@ # SYNOPSIS **gmid** -\[**-fh**] +\[**-6fh**] \[**-c** *cert.pem*] \[**-d** *docs*] \[**-k** *key.pem*] @@ -51,6 +51,10 @@ file inside that directory. The options are as follows: +**-6** + +> Enable IPv6. + **-c** *cert.pem* > The certificate to use, by default is blob - 12fa78247ffdb69d151e04621c442b41315fb271 blob + f14d0aaff13a268a3261ec1e593e9ada3143277b --- gmid.1 +++ gmid.1 @@ -20,7 +20,7 @@ .Sh SYNOPSIS .Nm .Bk -words -.Op Fl fh +.Op Fl 6fh .Op Fl c Ar cert.pem .Op Fl d Ar docs .Op Fl k Ar key.pem @@ -64,6 +64,8 @@ file inside that directory. .Pp The options are as follows: .Bl -tag -width 12m +.It Fl 6 +Enable IPv6. .It Fl c Ar cert.pem The certificate to use, by default is .Pa cert.pem . blob - e858c7b34fd054f3efd92755a6f5bd61b94a186a blob + 7ce51016b7c168bced42344cd7df1ae268ea133d --- gmid.c +++ gmid.c @@ -348,8 +348,9 @@ start_cgi(const char *spath, const char *relpath, cons case 0: { /* child */ char *ex, *requri, *portno; - char addr[INET_ADDRSTRLEN]; + char addr[NI_MAXHOST]; char *argv[] = { NULL, NULL, NULL }; + int ec; close(p[0]); if (dup2(p[1], 1) == -1) @@ -358,6 +359,13 @@ start_cgi(const char *spath, const char *relpath, cons if (inet_ntop(c->af, &c->addr, addr, sizeof(addr)) == NULL) goto childerr; + ec = getnameinfo((struct sockaddr*)&c->addr, sizeof(c->addr), + addr, sizeof(addr), + NULL, 0, + NI_NUMERICHOST | NI_NUMERICSERV); + if (ec != 0) + goto childerr; + if (asprintf(&portno, "%d", port) == -1) goto childerr; @@ -853,7 +861,7 @@ main(int argc, char **argv) const char *cert = "cert.pem", *key = "key.pem"; struct tls *ctx = NULL; struct tls_config *conf; - int sock4, sock6, ch; + int sock4, sock6, enable_ipv6, ch; connected_clients = 0; if ((dir = absolutify_path("docs")) == NULL) @@ -862,9 +870,14 @@ main(int argc, char **argv) cgi = NULL; port = 1965; foreground = 0; - - while ((ch = getopt(argc, argv, "c:d:fhk:p:x:")) != -1) { + enable_ipv6 = 0; + + while ((ch = getopt(argc, argv, "6c:d:fhk:p:x:")) != -1) { switch (ch) { + case '6': + enable_ipv6 = 1; + break; + case 'c': cert = optarg; break; @@ -946,7 +959,10 @@ main(int argc, char **argv) errx(1, "tls_configure: %s", tls_error(ctx)); sock4 = make_socket(port, AF_INET); - sock6 = make_socket(port, AF_INET6); + if (enable_ipv6) + sock6 = make_socket(port, AF_INET6); + else + sock6 = -1; if ((dirfd = open(dir, O_RDONLY | O_DIRECTORY)) == -1) err(1, "open: %s", dir);