Skip to content

Commit b128dac

Browse files
authored
Use CPLSetConfigOption/CPLGetConfigOption for some CGI/FastCGI-related env vars. (#6304)
Push a few high-value env vars into CPL config and then reference that instead of the env (mostly for IIS/FastCGI).
1 parent 3c1a5c6 commit b128dac

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

maphttp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "mapthread.h"
4040
#include "mapows.h"
4141

42-
42+
#include "cpl_conv.h"
4343

4444
#include <time.h>
4545
#ifndef _WIN32
@@ -471,7 +471,7 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests,
471471
* If set then the value is the full path to the ca-bundle.crt file
472472
* e.g. CURL_CA_BUNDLE=/usr/local/share/curl/curl-ca-bundle.crt
473473
*/
474-
pszCurlCABundle = getenv("CURL_CA_BUNDLE");
474+
pszCurlCABundle = CPLGetConfigOption("CURL_CA_BUNDLE", NULL);
475475

476476
if (debug) {
477477
msDebug("HTTP: Starting to prepare HTTP requests.\n");

mapserv.c

+11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "mapio.h"
4444
#include "maptime.h"
4545

46+
#include "cpl_conv.h"
47+
4648
#ifndef WIN32
4749
#include <signal.h>
4850
#endif
@@ -162,6 +164,15 @@ int main(int argc, char *argv[])
162164
if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING)
163165
msGettimeofday(&execstarttime, NULL);
164166

167+
/* push high-value ENV vars into the CPL global config - primarily for IIS/FastCGI */
168+
const char* const apszEnvVars[] = {
169+
"CURL_CA_BUNDLE", "MS_MAPFILE", "MS_MAP_NO_PATH", "MS_MAP_PATTERN",
170+
NULL /* guard */ };
171+
for( int i = 0; apszEnvVars[i] != NULL; ++i ) {
172+
const char* value = getenv(apszEnvVars[i]);
173+
if(value) CPLSetConfigOption(apszEnvVars[i], value);
174+
}
175+
165176
/* -------------------------------------------------------------------- */
166177
/* Process arguments. In normal use as a cgi-bin there are no */
167178
/* commandline switches, but we provide a few for test/debug */

mapserv.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "maptile.h"
4242

4343
#include "cgiutil.h"
44+
4445
/*
4546
** Defines
4647
*/

mapservutil.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "maptime.h"
3434
#include "mapows.h"
3535

36+
#include "cpl_conv.h"
37+
3638
/*
3739
** Enumerated types, keep the query modes in sequence and at the end of the enumeration (mode enumeration is in maptemplate.h).
3840
*/
@@ -197,12 +199,15 @@ mapObj *msCGILoadMap(mapservObj *mapserv)
197199
int i, j;
198200
mapObj *map = NULL;
199201

202+
const char *ms_mapfile = CPLGetConfigOption("MS_MAPFILE", NULL);
203+
const char *ms_map_no_path = CPLGetConfigOption("MS_MAP_NO_PATH", NULL);
204+
const char *ms_map_pattern = CPLGetConfigOption("MS_MAP_PATTERN", NULL);
205+
200206
for(i=0; i<mapserv->request->NumParams; i++) /* find the mapfile parameter first */
201207
if(strcasecmp(mapserv->request->ParamNames[i], "map") == 0) break;
202208

203209
if(i == mapserv->request->NumParams) {
204-
char *ms_mapfile = getenv("MS_MAPFILE");
205-
if(ms_mapfile) {
210+
if(ms_mapfile != NULL) {
206211
map = msLoadMap(ms_mapfile,NULL);
207212
} else {
208213
msSetError(MS_WEBERR, "CGI variable \"map\" is not set.", "msCGILoadMap()"); /* no default, outta here */
@@ -213,12 +218,12 @@ mapObj *msCGILoadMap(mapservObj *mapserv)
213218
map = msLoadMap(getenv(mapserv->request->ParamValues[i]), NULL);
214219
else {
215220
/* by here we know the request isn't for something in an environment variable */
216-
if(getenv("MS_MAP_NO_PATH")) {
221+
if(ms_map_no_path != NULL) {
217222
msSetError(MS_WEBERR, "Mapfile not found in environment variables and this server is not configured for full paths.", "msCGILoadMap()");
218223
return NULL;
219224
}
220225

221-
if(getenv("MS_MAP_PATTERN") && msEvalRegex(getenv("MS_MAP_PATTERN"), mapserv->request->ParamValues[i]) != MS_TRUE) {
226+
if(ms_map_pattern != NULL && msEvalRegex(ms_map_pattern, mapserv->request->ParamValues[i]) != MS_TRUE) {
222227
msSetError(MS_WEBERR, "Parameter 'map' value fails to validate.", "msCGILoadMap()");
223228
return NULL;
224229
}

0 commit comments

Comments
 (0)