Validate Windows service name
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 4 Jul 2011 20:05:26 +0000 (20:05 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 4 Jul 2011 20:05:26 +0000 (20:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1142784 13f79535-47bb-0310-9956-ffa450edef68

res/tomcat.nsi

index 0b21ee3..ba28a49 100644 (file)
@@ -546,8 +546,52 @@ Function pageConfigurationLeave
     ${NSD_GetText} $CtlTomcatAdminPassword $TomcatAdminPassword
     ${NSD_GetText} $CtlTomcatAdminRoles $TomcatAdminRoles
   ${EndIf}
+  
+  Push $TomcatServiceName
+  Call validateServiceName
+  Pop $0
+  
+  IntCmp $0 1 exit
+  MessageBox MB_ICONEXCLAMATION|MB_OK 'The Service Name may not contain a space or any of the following characters: <>:"/\:|?*'
+  Abort "Config not right"
+  exit:
 FunctionEnd
 
+; Validates that a service name does not use any of the invalid
+; characters: <>:"/\:|?*
+; Note that space is also not permitted although it will be once
+; Tomcat is using Daemon 1.0.6 or later
+;
+; Put the proposed service name on the stack
+; If the name is valid, a 1 will be left on the stack
+; If the name is invalid, a 0 will be left on the stack
+Function validateServiceName
+  Pop $0
+  StrLen $1 $0
+  StrCpy $3 '<>:"/\:|?* '
+  StrLen $4 $3
+  
+  loopInput:
+    IntOp $1 $1 - 1
+    IntCmp $1 -1 valid
+    loopTestChars:
+      IntOp $4 $4 - 1
+      IntCmp $4 -1 loopTestCharsDone
+      StrCpy $2 $0 1 $1
+      StrCpy $5 $3 1 $4
+      StrCmp $2 $5 invalid loopTestChars
+    loopTestCharsDone:
+    StrLen $4 $3
+    Goto loopInput
+
+  invalid:
+  Push 0
+  Goto exit
+  
+  valid:
+  Push 1
+  exit:
+FunctionEnd
 
 ;--------------------------------
 ;Descriptions