fix remote_user for CGI and add -6 flag to enable ipv6

This commit is contained in:
Omar Polo 2021-01-11 12:08:50 +00:00
parent 33756bd235
commit 85dff1f9c3
4 changed files with 32 additions and 6 deletions

View File

@ -1,3 +1,7 @@
2021-01-11 Omar Polo <op@omarpolo.com>
* gmid.c (main): ipv6 disabled by default and -6 flag to enable it
2021-01-10 Omar Polo <op@omarpolo.com>
* gmid.c (logs): log also the port of the client

View File

@ -6,7 +6,7 @@
# SYNOPSIS
**gmid**
\[**-fh**]
\[**-6fh**]
\[**-c**&nbsp;*cert.pem*]
\[**-d**&nbsp;*docs*]
\[**-k**&nbsp;*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

4
gmid.1
View File

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

24
gmid.c
View File

@ -348,8 +348,9 @@ start_cgi(const char *spath, const char *relpath, const char *query,
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, const char *query,
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;
enable_ipv6 = 0;
while ((ch = getopt(argc, argv, "c:d:fhk:p:x:")) != -1) {
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);