[mapserver-commits] r8822 - branches/branch-5-2/mapserver

svn at osgeo.org svn at osgeo.org
Wed Mar 25 20:47:01 EDT 2009


Author: sdlime
Date: 2009-03-25 20:47:01 -0400 (Wed, 25 Mar 2009)
New Revision: 8822

Modified:
   branches/branch-5-2/mapserver/mapserv.c
   branches/branch-5-2/mapserver/mapserver.h
   branches/branch-5-2/mapserver/maptemplate.c
Log:
RFC56 support.

Modified: branches/branch-5-2/mapserver/mapserv.c
===================================================================
--- branches/branch-5-2/mapserver/mapserv.c	2009-03-25 14:26:21 UTC (rev 8821)
+++ branches/branch-5-2/mapserver/mapserv.c	2009-03-26 00:47:01 UTC (rev 8822)
@@ -41,9 +41,8 @@
 
 MS_CVSID("$Id$")
 
+mapservObj *mapserv;
 
-mapservObj* mapserv;
-
 int writeLog(int show_error)
 {
   FILE *stream;
@@ -199,8 +198,21 @@
   } else {
     if(getenv(mapserv->request->ParamValues[i])) /* an environment references the actual file to use */
       map = msLoadMap(getenv(mapserv->request->ParamValues[i]), NULL);
-    else
-      map = msLoadMap(mapserv->request->ParamValues[i], NULL);
+    else {
+      /* by here we know the request isn't for something in an environment variable */
+      if(getenv("MS_MAP_NO_PATH")) {
+        msSetError(MS_WEBERR, "Mapfile not found in environment variables and this server is not configured for full paths.", "loadMap()");
+	writeError();
+      }
+
+      if(getenv("MS_MAP_PATTERN") && msEvalRegex(getenv("MS_MAP_PATTERN"), mapserv->request->ParamValues[i]) != MS_TRUE) {
+        msSetError(MS_WEBERR, "Parameter 'map' value fails to validate.", "loadMap()");
+        writeError();
+      }
+
+      /* ok to try to load now */
+      map = msLoadMap(mapserv->request->ParamValues[i], NULL);      
+    }
   }
 
   if(!map) writeError();
@@ -1194,7 +1206,7 @@
     /* -------------------------------------------------------------------- */
     mapserv = msAllocMapServObj();
     mapserv->sendheaders = sendheaders; /* override the default if necessary (via command line -nh switch) */
-
+    
     mapserv->request->ParamNames = (char **) malloc(MS_MAX_CGI_PARAMS*sizeof(char*));
     mapserv->request->ParamValues = (char **) malloc(MS_MAX_CGI_PARAMS*sizeof(char*));
     if(mapserv->request->ParamNames==NULL || mapserv->request->ParamValues==NULL) {

Modified: branches/branch-5-2/mapserver/mapserver.h
===================================================================
--- branches/branch-5-2/mapserver/mapserver.h	2009-03-25 14:26:21 UTC (rev 8821)
+++ branches/branch-5-2/mapserver/mapserver.h	2009-03-26 00:47:01 UTC (rev 8822)
@@ -151,8 +151,10 @@
 /* General defines, not wrapable */
 #ifndef SWIG
 #define MS_DEFAULT_MAPFILE_PATTERN "\\.map$"
-#define MS_TEMPLATE_EXPR "\\.(jsp|asp|cfm|xml|wml|html|htm|shtml|phtml|php|svg|kml|gml|js|tmpl)$"
 
+#define MS_TEMPLATE_MAGIC_STRING "MapServer Template"
+#define MS_TEMPLATE_EXPR "\\.(xml|wml|html|htm|svg|kml|gml|js|tmpl)$"
+
 #define MS_INDEX_EXTENSION ".qix"
 #define MS_QUERY_EXTENSION ".qy"
 

Modified: branches/branch-5-2/mapserver/maptemplate.c
===================================================================
--- branches/branch-5-2/mapserver/maptemplate.c	2009-03-25 14:26:21 UTC (rev 8821)
+++ branches/branch-5-2/mapserver/maptemplate.c	2009-03-26 00:47:01 UTC (rev 8822)
@@ -1054,11 +1054,28 @@
 
     if(!src) return(MS_SUCCESS); /* don't process the tag, could be something else so return MS_SUCCESS */
 
+    if(msEvalRegex(MS_TEMPLATE_EXPR, src) != MS_TRUE) {
+      msSetError(MS_WEBERR, "Malformed template name (%s).", "processIncludeTag()", src);
+      return MS_FAILURE;
+    }
+
     if((includeStream = fopen(msBuildPath(path, mapserv->map->mappath, src), "r")) == NULL) {
       msSetError(MS_IOERR, src, "processIncludeTag()");
       return MS_FAILURE;
     } 
-    
+
+    /* examine 1st line, must contain a magic string to continue */
+    if(fgets(buffer, MS_BUFFER_LENGTH, includeStream) != NULL) {
+      if(!msCaseFindSubstring(buffer, MS_TEMPLATE_MAGIC_STRING)) {
+	fclose(includeStream);
+	msSetError(MS_WEBERR, "Missing magic string, this doesn't look like a MapServer template.", "processIncludeTag()");
+	return MS_FAILURE;
+      }
+    } else { /* empty template, just return */
+      fclose(includeStream);
+      return MS_SUCCESS;
+    }
+
     while(fgets(buffer, MS_BUFFER_LENGTH, includeStream) != NULL)
       content = msStringConcatenate(content, buffer);
 
@@ -3413,26 +3430,30 @@
   int   nCurrentSize = 0;
   int   nExpandBuffer = 0;
 
-  ms_regex_t re; /* compiled regular expression to be matched */ 
   char szPath[MS_MAXPATHLEN];
 
-  if(ms_regcomp(&re, MS_TEMPLATE_EXPR, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) {
-    msSetError(MS_REGEXERR, NULL, "msReturnPage()");
-    return MS_FAILURE;
-  }
-
-  if(ms_regexec(&re, html, 0, NULL, 0) != 0) { /* no match */
-    ms_regfree(&re);
+  if(msEvalRegex(MS_TEMPLATE_EXPR, html) != MS_TRUE) {
     msSetError(MS_WEBERR, "Malformed template name (%s).", "msReturnPage()", html);
     return MS_FAILURE;
   }
-  ms_regfree(&re);
 
   if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, html), "r")) == NULL) {
     msSetError(MS_IOERR, html, "msReturnPage()");
     return MS_FAILURE;
   } 
 
+  /* examine 1st line, must contain a magic string to continue */
+  if(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) {
+    if(!msCaseFindSubstring(line, MS_TEMPLATE_MAGIC_STRING)) {
+      fclose(stream);
+      msSetError(MS_WEBERR, "Missing magic string, this doesn't look like a MapServer template.", "msReturnPage()");
+      return MS_FAILURE; 
+    }
+  } else { /* file is empty, technically not a error */
+    fclose(stream);
+    return MS_SUCCESS;
+  }
+
   if(papszBuffer) {
     if((*papszBuffer) == NULL) {
       (*papszBuffer) = (char *)malloc(MS_TEMPLATE_BUFFER);



More information about the mapserver-commits mailing list