1e3521c5e1b20bf843a22a397e0e4662141dc4de max Mon Oct 12 01:06:04 2015 -0700 trying to make hgLogin work as a non-root htdocs, refs #16187 diff --git src/lib/cheapcgi.c src/lib/cheapcgi.c index f0cd3f4..c1d5df2 100644 --- src/lib/cheapcgi.c +++ src/lib/cheapcgi.c @@ -1,27 +1,28 @@ /* Routines for getting variables passed in from web page * forms via CGI. * * This file is copyright 2002 Jim Kent, but license is hereby * granted for all use - public, private or commercial. */ #include "common.h" #include "hash.h" #include "cheapcgi.h" #include "portable.h" #include "linefile.h" #include "errAbort.h" +#include "filePath.h" #ifndef GBROWSE #include "mime.h" #endif /* GBROWSE */ #include <signal.h> /* These three variables hold the parsed version of cgi variables. */ static char *inputString = NULL; static unsigned long inputSize; static struct hash *inputHash = NULL; static struct cgiVar *inputList = NULL; static boolean haveCookiesHash = FALSE; static struct hash *cookieHash = NULL; static struct cgiVar *cookieList = NULL; @@ -64,30 +65,46 @@ char *cgiRequestContentLength() /* Return HTTP REQUEST CONTENT_LENGTH if available*/ { return getenv("CONTENT_LENGTH"); } char *cgiScriptName() /* Return name of script so libs can do context-sensitive stuff. */ { char *scriptName = getenv("SCRIPT_NAME"); if (scriptName == NULL) scriptName = "cgiSpoofedScript"; return scriptName; } +char *cgiScriptDirUrl() +/* Return the absolute cgi-bin directory on this webserver. + * This is not the local directory but the <path> part after the server + * in external URLs to this webserver. + * e.g. if CGI is called http://localhost/subdir/cgi-bin/cgiTest + * then returned value is /subdir/ + * return value must be free'd. */ +{ +char* cgiPath = cloneString(cgiScriptName()); +char dir[PATH_LEN]; +splitPath(cgiPath, dir, NULL, NULL); +char* dirStr = needMem(PATH_LEN); +safecpy(dirStr, PATH_LEN, dir); +return dirStr; +} + char *cgiServerName() /* Return name of server, better to use cgiServerNamePort() for actual URL construction */ { return getenv("SERVER_NAME"); } char *cgiServerPort() /* Return port number of server, default 80 if not found */ { char *port = getenv("SERVER_PORT"); if (port) return port; else return "80";