diff options
-rw-r--r-- | fcgi.c | 14 | ||||
-rw-r--r-- | ge.c | 12 | ||||
-rw-r--r-- | gmid.c | 11 | ||||
-rw-r--r-- | gmid.h | 2 | ||||
-rw-r--r-- | server.c | 11 |
5 files changed, 19 insertions, 31 deletions
@@ -343,26 +343,18 @@ fcgi_error(struct bufferevent *bev, short err, void *d) void fcgi_req(struct client *c) { - char addr[NI_MAXHOST], buf[22]; + char buf[22]; char *qs; - int e; time_t tim; struct tm tminfo; struct envlist *p; - e = getnameinfo((struct sockaddr*)&c->raddr, c->raddrlen, - addr, sizeof(addr), - NULL, 0, - NI_NUMERICHOST); - if (e != 0) - fatalx("getnameinfo failed: %s", gai_strerror(e)); - fcgi_begin_request(c->cgibev); fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1"); fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path); fcgi_send_param(c->cgibev, "QUERY_STRING", c->iri.query); - fcgi_send_param(c->cgibev, "REMOTE_ADDR", addr); - fcgi_send_param(c->cgibev, "REMOTE_HOST", addr); + fcgi_send_param(c->cgibev, "REMOTE_ADDR", c->rhost); + fcgi_send_param(c->cgibev, "REMOTE_HOST", c->rhost); fcgi_send_param(c->cgibev, "REQUEST_METHOD", ""); fcgi_send_param(c->cgibev, "SERVER_NAME", c->iri.host); fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI"); @@ -42,16 +42,8 @@ static const struct option opts[] = { void log_request(struct client *c, char *meta, size_t l) { - char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN]; + char b[GEMINI_URL_LEN]; const char *t; - int ec; - - ec = getnameinfo((struct sockaddr*)&c->raddr, c->raddrlen, - hbuf, sizeof(hbuf), - sbuf, sizeof(sbuf), - NI_NUMERICHOST | NI_NUMERICSERV); - if (ec != 0) - fatalx("getnameinfo: %s", gai_strerror(ec)); if (c->iri.schema != NULL) { /* serialize the IRI */ @@ -81,7 +73,7 @@ log_request(struct client *c, char *meta, size_t l) if ((t = memchr(meta, '\r', l)) == NULL) t = meta + l; - fprintf(stderr, "%s:%s GET %s %.*s\n", hbuf, sbuf, b, + fprintf(stderr, "%s:%s GET %s %.*s\n", c->rhost, c->rserv, b, (int)(t-meta), meta); } @@ -84,18 +84,11 @@ void log_request(struct client *c, char *meta, size_t l) { struct conf *conf = c->conf; - char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN]; + char b[GEMINI_URL_LEN]; char *fmted; const char *t; int ec; - ec = getnameinfo((struct sockaddr*)&c->raddr, c->raddrlen, - hbuf, sizeof(hbuf), - sbuf, sizeof(sbuf), - NI_NUMERICHOST | NI_NUMERICSERV); - if (ec != 0) - fatalx("getnameinfo: %s", gai_strerror(ec)); - if (c->iri.schema != NULL) { /* serialize the IRI */ strlcpy(b, c->iri.schema, sizeof(b)); @@ -124,7 +117,7 @@ log_request(struct client *c, char *meta, size_t l) if ((t = memchr(meta, '\r', l)) == NULL) t = meta + l; - ec = asprintf(&fmted, "%s:%s GET %s %.*s", hbuf, sbuf, b, + ec = asprintf(&fmted, "%s:%s GET %s %.*s", c->rhost, c->rserv, b, (int)(t-meta), meta); if (ec == -1) fatal("asprintf"); @@ -281,6 +281,8 @@ struct client { size_t reqlen; struct iri iri; char domain[DOMAIN_NAME_LEN]; + char rhost[NI_MAXHOST]; + char rserv[NI_MAXSERV]; struct bufferevent *bev; @@ -1343,7 +1343,7 @@ do_accept(int sock, short et, void *d) struct sockaddr_storage raddr; struct sockaddr *sraddr; socklen_t len; - int fd; + int e, fd; sraddr = (struct sockaddr *)&raddr; len = sizeof(raddr); @@ -1365,6 +1365,15 @@ do_accept(int sock, short et, void *d) memcpy(&c->raddr, &raddr, sizeof(raddr)); c->raddrlen = len; + e = getnameinfo(sraddr, len, c->rhost, sizeof(c->rhost), + c->rserv, sizeof(c->rserv), NI_NUMERICHOST | NI_NUMERICSERV); + if (e != 0) { + log_warnx("getnameinfo failed: %s", gai_strerror(e)); + close(c->fd); + free(c); + return; + } + if (tls_accept_socket(addr->ctx, &c->ctx, fd) == -1) { log_warnx("failed to accept socket: %s", tls_error(c->ctx)); close(c->fd); |