Index: src/cgi.c ================================================================== --- src/cgi.c +++ src/cgi.c @@ -949,17 +949,34 @@ const char *zType; int len; const char *zRequestUri = cgi_parameter("REQUEST_URI",0); const char *zScriptName = cgi_parameter("SCRIPT_NAME",0); const char *zPathInfo = cgi_parameter("PATH_INFO",0); +#ifdef _WIN32 + const char *zServerSoftware = cgi_parameter("SERVER_SOFTWARE",0); +#endif #ifdef FOSSIL_ENABLE_JSON json_main_bootstrap(); #endif g.isHTTP = 1; cgi_destination(CGI_BODY); if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME"); +#ifdef _WIN32 + /* The Microsoft IIS web server does not define REQUEST_URI, instead it uses + ** PATH_INFO for virtually the same purpose. Define REQUEST_URI the same as + ** PATH_INFO and redefine PATH_INFO with SCRIPT_NAME removed from the + ** beginning. */ + if( zServerSoftware && strstr(zServerSoftware, "Microsoft-IIS") ){ + int i, j; + cgi_set_parameter("REQUEST_URI", zPathInfo); + for(i=0; zPathInfo[i]==zScriptName[i] && zPathInfo[i]; i++){} + for(j=i; zPathInfo[j] && zPathInfo[j]!='?'; j++){} + zPathInfo = mprintf("%.*s", j-i, zPathInfo+i); + cgi_replace_parameter("PATH_INFO", zPathInfo); + } +#endif if( zRequestUri==0 ){ const char *z = zPathInfo; if( zPathInfo==0 ){ malformed_request("missing PATH_INFO and/or REQUEST_URI"); } @@ -1113,15 +1130,16 @@ } } /* If no match is found and the name begins with an upper-case ** letter, then check to see if there is an environment variable - ** with the given name. + ** with the given name. Handle environment variables with empty values + ** the same as non-existent environment variables. */ if( zName && fossil_isupper(zName[0]) ){ const char *zValue = fossil_getenv(zName); - if( zValue ){ + if( zValue && zValue[0] ){ cgi_set_parameter_nocopy(zName, zValue, 0); CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue)); return zValue; } } Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -1994,21 +1994,26 @@ char **azRedirect = 0; /* List of repositories to redirect to */ int nRedirect = 0; /* Number of entries in azRedirect */ Glob *pFileGlob = 0; /* Pattern for files */ int allowRepoList = 0; /* Allow lists of repository files */ Blob config, line, key, value, value2; - if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){ - zFile = g.argv[2]; - }else{ - zFile = g.argv[1]; - } + /* Initialize the CGI environment. */ g.httpOut = stdout; g.httpIn = stdin; fossil_binary_mode(g.httpOut); fossil_binary_mode(g.httpIn); g.cgiOutput = 1; fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT); + /* Read and parse the CGI control file. */ + if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){ + zFile = g.argv[2]; + }else if( g.argc>=2 ){ + zFile = g.argv[1]; + }else{ + cgi_panic("No CGI control file specified"); + } + /* Read and parse the CGI control file. */ blob_read_from_file(&config, zFile, ExtFILE); while( blob_line(&config, &line) ){ if( !blob_token(&line, &key) ) continue; if( blob_buffer(&key)[0]=='#' ) continue; if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){