From 3c4afef1d419a0058265834efe6d60e8bf421924 Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Wed, 22 May 2019 01:25:43 +0200 Subject: [PATCH] Disable gopher+ compatibility by default and add a `-+' option to enable it. --- geomyidae.8 | 15 ++++++++++----- main.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/geomyidae.8 b/geomyidae.8 index bcb86b6..26589e0 100644 --- a/geomyidae.8 +++ b/geomyidae.8 @@ -11,6 +11,7 @@ .Sh SYNOPSIS .Nm .Bk -words +.Op Fl + .Op Fl 4 .Op Fl 6 .Op Fl c @@ -84,6 +85,10 @@ source archive. geomyidae options and default settings: .Bl -tag -width Ds . +.It Fl + +Enable compatibility layer for gopher(1) client requesting gopher+ +metadata by default (see QUIRK). +. .It Fl 4 Only use IPv4. . @@ -341,11 +346,11 @@ surprises depending on how a script is written. See the CGI file (included in the geomyidae source archive) for further elaboration. .Pp QUIRK: The original gopher client tried to be too intelligent. It is using -gopher+ when you request some resource. When "search" is just the value "+", -"!", "$" or empty, geomyidae will display a gopher+ redirect instead of invoking the -script. Be careful to design your search script so the user is unlikely to -enter those values. The designers of gopher+ did not think of classic gopher -to survive. It survived gopher+. +gopher+ when you request some resource. When -+ option is used and "search" +start with value "+", "!", "$" or empty, geomyidae will display a gopher+ +redirect instead of invoking the script. Be careful to design your search +script so the user is unlikely to enter those values. The designers of +gopher+ did not think of classic gopher to survive. It survived gopher+. .Pp Additionally to the above arguments several environment variables are set. .Pp diff --git a/main.c b/main.c index 379d9f9..e554c90 100644 --- a/main.c +++ b/main.c @@ -116,7 +116,7 @@ logentry(char *host, char *port, char *qry, char *status) void handlerequest(int sock, char *base, char *ohost, char *port, char *clienth, - char *clientp, int nocgi) + char *clientp, int nocgi, int dogpcompat) { struct stat dir; char recvc[1025], recvb[1025], path[1025], *args, *sear, *c; @@ -153,7 +153,8 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth, * mode. DO NOT ADD ANY OTHER GOPHER+ SUPPORT. GOPHER+ IS * CRAP. */ - if (*sear == '+' || *sear == '$' || *sear == '!' || *sear == '\0') { + if (dogpcompat && (*sear == '+' || *sear == '$' || + *sear == '!' || *sear == '\0')) { dprintf(sock, "+-2\r\n"); dprintf(sock, "+INFO: 1gopher+\t\t%s\t%s\r\n", ohost, port); @@ -397,8 +398,8 @@ main(int argc, char *argv[]) struct addrinfo hints; struct sockaddr_storage clt; socklen_t cltlen; - int sock, dofork, inetf, usechroot, nocgi, errno_save, nbindips, i, j, - nlfdret, *lfdret, listfd, maxlfd; + int sock, dofork, inetf, usechroot, nocgi, dogpcompat, errno_save, + nbindips, i, j, nlfdret, *lfdret, listfd, maxlfd; char *port, *base, clienth[NI_MAXHOST], clientp[NI_MAXSERV]; char *user, *group, **bindips, *ohost, *sport, *p; struct passwd *us; @@ -419,8 +420,12 @@ main(int argc, char *argv[]) inetf = AF_UNSPEC; usechroot = 0; nocgi = 0; + dogpcompat = 0; ARGBEGIN { + case '+': + dogpcompat = 1; + break; case '4': inetf = AF_INET; break; @@ -703,7 +708,7 @@ main(int argc, char *argv[]) #endif /* __OpenBSD__ */ handlerequest(sock, base, ohost, sport, clienth, - clientp, nocgi); + clientp, nocgi, dogpcompat); waitforpendingbytes(sock); -- 2.21.0