commit 61bbe97771c2c1f6246fc5cdfa14cf572cbf5630 from: Omar Polo via: Thomas Adam date: Thu Nov 16 00:48:08 2023 UTC gotwebd: merge host() and get_addrs(); use * instead of "" for any addr ok plus tweaks stsp@ commit - 08f1c78e511357d5bd17bf80440ee6e6c00a5d3f commit + 61bbe97771c2c1f6246fc5cdfa14cf572cbf5630 blob - f37bcb65b0a961df4a1dda281bf7726a20fe121e blob + ceff3ccc3774187d7c67e2047b1d3cb47319b9ec --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -49,7 +49,6 @@ #define GOTWEBD_MAXNAME 64 #define GOTWEBD_MAXPORT 6 #define GOTWEBD_NUMPROC 3 -#define GOTWEBD_MAXIFACE 16 #define GOTWEBD_REPO_CACHESIZE 4 /* GOTWEB DEFAULTS */ blob - f72e765bc60988b95712cf43aaae9a2b96def4d6 blob + 74506e9f84000e48e25740c5309fe004c24455cd --- gotwebd/parse.y +++ gotwebd/parse.y @@ -100,8 +100,6 @@ int get_addrs(const char *, struct server *, in_port int addr_dup_check(struct addresslist *, struct address *, const char *, const char *); int add_addr(struct server *, struct address *); -int host(const char *, struct server *, - int, in_port_t, const char *); typedef struct { union { @@ -124,6 +122,7 @@ typedef struct { %type fcgiport %token NUMBER %type boolean +%type listen_addr %% @@ -175,6 +174,10 @@ boolean : STRING { } $$ = $1; } + ; + +listen_addr : '*' { $$ = NULL; } + | STRING ; fcgiport : PORT NUMBER { @@ -343,7 +346,7 @@ serveropts1 : REPOS_PATH STRING { } free($2); } - | LISTEN ON STRING fcgiport { + | LISTEN ON listen_addr fcgiport { if (get_addrs($3, new_srv, $4) == -1) { yyerror("could not get addrs"); YYERROR; @@ -1021,42 +1024,42 @@ getservice(const char *n) } int -host(const char *s, struct server *new_srv, int max, - in_port_t port, const char *ifname) +get_addrs(const char *s, struct server *new_srv, in_port_t port) { struct addrinfo hints, *res0, *res; - int error, cnt = 0; + int n, error; struct sockaddr_in *sain; struct sockaddr_in6 *sin6; struct address *h; + char portstr[32]; + n = snprintf(portstr, sizeof(portstr), "%d", port); + if (n < 0 || (size_t)n >= sizeof(portstr)) + fatalx("snprintf: port numbr too long: %d", port); + memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; /* DUMMY */ - hints.ai_flags = AI_ADDRCONFIG; - error = getaddrinfo(s, NULL, &hints, &res0); - if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME) - return (0); + hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + error = getaddrinfo(s, portstr, &hints, &res0); if (error) { log_warnx("%s: could not parse \"%s\": %s", __func__, s, gai_strerror(error)); return (-1); } - for (res = res0; res && cnt < max; res = res->ai_next) { - if (res->ai_family != AF_INET && - res->ai_family != AF_INET6) - continue; + for (res = res0; res; res = res->ai_next) { if ((h = calloc(1, sizeof(*h))) == NULL) fatal(__func__); if (port) h->port = port; - if (ifname != NULL) { - if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >= + if (s == NULL) { + strlcpy(h->ifname, "*", sizeof(h->ifname)); + } else { + if (strlcpy(h->ifname, s, sizeof(h->ifname)) >= sizeof(h->ifname)) { - log_warnx("%s: interface name truncated", - __func__); + log_warnx("%s: address truncated", __func__); freeaddrinfo(res0); free(h); return (-1); @@ -1078,35 +1081,8 @@ host(const char *s, struct server *new_srv, int max, if (add_addr(new_srv, h)) return -1; - cnt++; } - if (cnt == max && res) { - log_warnx("%s: %s resolves to more than %d hosts", __func__, - s, max); - } freeaddrinfo(res0); - return (cnt); -} - -int -get_addrs(const char *addr, struct server *new_srv, in_port_t port) -{ - if (strcmp("", addr) == 0) { - if (host("127.0.0.1", new_srv, 1, port, "127.0.0.1") <= 0) { - yyerror("invalid listen ip: %s", - "127.0.0.1"); - return (-1); - } - if (host("::1", new_srv, 1, port, "::1") <= 0) { - yyerror("invalid listen ip: %s", "::1"); - return (-1); - } - } else { - if (host(addr, new_srv, GOTWEBD_MAXIFACE, port, addr) <= 0) { - yyerror("invalid listen ip: %s", addr); - return (-1); - } - } return (0); }