Introduction
Introduction Statistics Contact Development Disclaimer Help
Make CGI environment more conformant to RFC3875. - geomyidae - a small C-based …
git clone git://git.codemadness.org/geomyidae
Log
Files
Refs
README
LICENSE
---
commit 4db13c5e462c939ad71bc0d1bf0cdbe117770d54
parent 06a070824c9fcbc590986c1931ca6266463a613f
Author: Christoph Lohmann <[email protected]>
Date: Fri, 6 Jun 2025 21:23:02 +0200
Make CGI environment more conformant to RFC3875.
Diffstat:
M handlr.c | 10 ++++++++++
M ind.c | 62 +++++++++++++++--------------…
2 files changed, 40 insertions(+), 32 deletions(-)
---
diff --git a/handlr.c b/handlr.c
@@ -139,6 +139,12 @@ handlebin(int sock, char *file, char *port, char *base, ch…
}
}
+/*
+ * See RFC3875 5 NPH Scripts
+ *
+ * In gopher, with no header parsing, this allows bi-directional
+ * long-running communications. One example would be raw HTTP emulation.
+ */
void
handlecgi(int sock, char *file, char *port, char *base, char *args,
char *sear, char *ohost, char *chost, char *bhost, int istls,
@@ -188,6 +194,10 @@ handlecgi(int sock, char *file, char *port, char *base, ch…
}
}
+/*
+ * This is RFC3875 NPH Scripts
+ * plus parsing of GPH syntax for easier gophermap portability.
+ */
void
handledcgi(int sock, char *file, char *port, char *base, char *args,
char *sear, char *ohost, char *chost, char *bhost, int istls,
diff --git a/ind.c b/ind.c
@@ -539,53 +539,52 @@ setcgienviron(char *file, char *path, char *port, char *b…
char *sear, char *ohost, char *chost, char *bhost, int istls,
char *sel, char *traverse)
{
- /*
- * TODO: Clean environment from possible unsafe environment variables.
- * But then it is the responsibility of the script writer.
- */
- unsetenv("AUTH_TYPE");
+ /* RFC3875 4.1.1 */
+ setenv("AUTH_TYPE", "", 1);
+ /* RFC3875 4.1.2 */
unsetenv("CONTENT_LENGTH");
+ /* RFC3875 4.1.3 */
unsetenv("CONTENT_TYPE");
+ /* RFC3875 4.1.4 */
setenv("GATEWAY_INTERFACE", "CGI/1.1", 1);
- /* TODO: Separate, if run like rest.dcgi. */
- setenv("SCRIPT_NAME", path+strlen(base), 1);
- setenv("SCRIPT_FILENAME", path, 1);
-
- setenv("QUERY_STRING", args, 1);
- setenv("SELECTOR", sel, 1);
- setenv("REQUEST", sel, 1);
+ /* RFC3875 4.1.5 */
setenv("PATH_INFO", traverse, 1);
-
+ /* RFC3875 4.1.6 */
+ setenv("PATH_TRANSLATED", traverse, 1);
+ /* RFC3875 4.1.7 */
+ setenv("QUERY_STRING", args, 1);
+ /* RFC3875 4.1.8 */
setenv("REMOTE_ADDR", chost, 1);
- /*
- * Don't do a reverse lookup on every call. Only do when needed, in
- * the script. The RFC allows us to set the IP to the value.
- */
+ /* RFC3875 4.1.9 */
setenv("REMOTE_HOST", chost, 1);
- /* Please do not implement identd here. */
+ /* RFC3875 4.1.10 */
unsetenv("REMOTE_IDENT");
+ /* RFC3875 4.1.11 */
unsetenv("REMOTE_USER");
- /* Make PHP happy. */
- setenv("REDIRECT_STATUS", "", 1);
- /*
- * Only GET is possible in gopher. POST emulation would be really
- * ugly.
- */
+ /* RFC3875 4.1.12 */
setenv("REQUEST_METHOD", "GET", 1);
+ /* RFC3875 4.1.13 */
+ setenv("SCRIPT_NAME", path+strlen(base), 1);
+ /* RFC3875 4.1.14 */
setenv("SERVER_NAME", ohost, 1);
+ /* RFC3875 4.1.15 */
setenv("SERVER_PORT", port, 1);
- setenv("SERVER_LISTEN_NAME", bhost, 1);
- if (istls) {
- setenv("SERVER_PROTOCOL", "gophers/1.0", 1);
- } else {
- setenv("SERVER_PROTOCOL", "gopher/1.0", 1);
- }
+ /* RFC3875 4.1.16 */
+ setenv("SERVER_PROTOCOL", "gopher/1.0", 1);
+ /* RFC3875 4.1.17 */
setenv("SERVER_SOFTWARE", "geomyidae", 1);
- setenv("X_GOPHER_SEARCH", sear, 1);
+ /* GOPHER-specific variables */
+ setenv("GOPHER_SELECTOR", sel, 1);
+ setenv("GOPHER_REQUEST", sel, 1);
+ setenv("GOPHER_SEARCH", sear, 1);
/* legacy compatibility */
setenv("SEARCHREQUEST", sear, 1);
+ setenv("SCRIPT_FILENAME", path, 1);
+ /* Make PHP happy. */
+ setenv("REDIRECT_STATUS", "", 1);
+ setenv("SERVER_LISTEN_NAME", bhost, 1);
if (istls) {
setenv("GOPHERS", "on", 1);
setenv("HTTPS", "on", 1);
@@ -593,7 +592,6 @@ setcgienviron(char *file, char *path, char *port, char *bas…
unsetenv("GOPHERS");
unsetenv("HTTPS");
}
-
}
char *
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.