Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

909 lines
29 KiB

  1. Sub PrintOutMode(stringtoprint)
  2. 'check if /Q quiet flag was set
  3. if Not gRunMode and 1 then
  4. WScript.StdOut.WriteLine stringtoprint
  5. end if
  6. End Sub
  7. Sub PrintCustomError(strtoprint, whichstyleflag)
  8. 'if build flag is set /b then print build style
  9. if gRunMode and 2 then
  10. if whichstyleflag = 1 then
  11. WScript.StdErr.WriteLine "BUILDMSG: XML Manifest error:" + sourceFile + ":" + strtoprint
  12. else
  13. WScript.StdErr.WriteLine "BUILDMSG: XML ManifestChk Error:" + strtoprint
  14. end if
  15. else
  16. if whichstyleflag = 1 then
  17. 'print normal output style
  18. PrintOutMode vbTab + "XML Manifest error:" + sourceFile + ":" + strtoprint
  19. else
  20. PrintOutMode "XML ManifestChk Error:" + strtoprint
  21. end if
  22. end if
  23. End Sub
  24. Sub PrintXMLError(byRef pXmlParseError)
  25. PrintOutMode vbTab + "XML Error Info: "
  26. PrintOutMode vbTab + " line: " + CStr(pXmlParseError.line)
  27. PrintOutMode vbTab + " linepos: " + CStr(pXmlParseError.linepos)
  28. PrintOutMode vbTab + " url: " + pXmlParseError.url
  29. PrintOutMode vbTab + " errCode: " + Hex(pXmlParseError.errorCode)
  30. PrintOutMode vbTab + " srcText: " + pXmlParseError.srcText
  31. if Hex(pXmlParseError.errorCode) = "800C0006" then
  32. PrintOutMode vbTab + " reason: " + "File not found."
  33. else
  34. PrintOutMode vbTab + " reason: " + pXmlParseError.reason
  35. end if
  36. End Sub
  37. Sub PrintErrorDuringBuildProcess( byRef pXmlParseError )
  38. Dim sFileUrl
  39. if pXmlParseError.url = "" then
  40. sFileUrl = sourceFile
  41. else
  42. sFileUrl = pXmlParseError.url
  43. end if
  44. WScript.StdErr.Write "NMAKE : error XML" + Hex(pXmlParseError.errorCode) + ": " + sFileUrl
  45. if Hex(pXmlParseError.errorCode) = "800C0006" then
  46. WScript.StdErr.WriteLine "(" + CStr(pXmlParseError.line) + ") : " + "File not found."
  47. else
  48. WScript.StdErr.WriteLine "(" + CStr(pXmlParseError.line) + ") : " + pXmlParseError.reason
  49. end if
  50. End Sub
  51. Sub PrintSchemaError( byRef pErrObj )
  52. if Hex(pErrObj.Number) = "800C0006" then
  53. PrintOutMode vbTab + "Schema Error Info: " + Hex(pErrObj.Number) + vbCrLf + vbTab + "File:" + schemaname + " ( not found )"
  54. else
  55. PrintOutMode vbTab + "Schema Error Info: " + Hex(pErrObj.Number) + vbCrLf + vbTab + pErrobj.Description + vbCrLf + vbTab + "Error with:" + schemaname
  56. end if
  57. End Sub
  58. Sub PrintSchemaErrorDuringBuildProcess( byRef pErrObj )
  59. Dim sFileSource
  60. sFileSource = schemaname
  61. if Hex(pErrObj.Number) = "800C0006" then
  62. WScript.StdErr.Write "NMAKE : error XMLSchema" + Hex(pErrObj.Number) + ": " + sFileSource
  63. WScript.StdErr.WriteLine "( file not found )"
  64. else
  65. WScript.StdErr.Write "NMAKE : error XMLSchema" + Hex(pErrObj.Number) + ": " + sFileSource
  66. WScript.StdErr.WriteLine "(" + pErrObj.Description + ")"
  67. end if
  68. End Sub
  69. Sub PrintUsage()
  70. WScript.StdOut.WriteLine vbTab + vbCrLf
  71. WScript.StdOut.WriteLine "Validates Fusion Win32 Manifest files using a schema."
  72. WScript.StdOut.WriteLine vbTab + vbCrLf
  73. WScript.StdOut.WriteLine "Usage:"
  74. WScript.StdOut.WriteLine vbTab + "cscript manifestchk.vbs /S:[drive:][path]schema_filename /M:[drive:][path]xml_manifest_filename /T:type [/Q]"
  75. WScript.StdOut.WriteLine vbTab + "/S: Specify schema filename used to validate manifest"
  76. WScript.StdOut.WriteLine vbTab + "/M: Specify manifest filename to validate"
  77. WScript.StdOut.WriteLine vbTab + "/T: Specify manifest type value"
  78. WScript.StdOut.WriteLine vbTab + "/Q Quiet mode - suppresses output to console"
  79. WScript.StdOut.WriteLine vbTab + vbCrLf
  80. WScript.StdOut.WriteLine vbTab + " Valid manifest type values are: "
  81. WScript.StdOut.WriteLine vbTab + " AM for Assembly or Application Manifest"
  82. WScript.StdOut.WriteLine vbTab + " PC for Publisher Configuration"
  83. WScript.StdOut.WriteLine vbTab + " AC for Application Configuration"
  84. WScript.StdOut.WriteLine vbTab + vbCrLf
  85. WScript.StdOut.WriteLine vbTab + " The tool without /Q displays details of first encountered error"
  86. WScript.StdOut.WriteLine vbTab + " (if errors are present in manifest), and displays Pass or Fail"
  87. WScript.StdOut.WriteLine vbTab + " of the validation result. The application returns 0 for Pass,"
  88. WScript.StdOut.WriteLine vbTab + " 1 for Fail, and returns 2 for bad command line argument."
  89. End Sub
  90. Function ChkProcessor(byRef rootdocobj, byRef strerr)
  91. Dim retVal
  92. Dim procArchChkList
  93. retVal = True
  94. set procArchChkList = rootdocobj.selectNodes("//assembly/*// @processorArchitecture[nodeType() = '2']")
  95. rootlen = 0
  96. rootlen = procArchChkList.length
  97. if rootlen > 0 then
  98. For counter = 0 To rootlen-1 Step 1
  99. MyVar = UCase (CStr(procArchChkList.item(counter).text))
  100. Select Case MyVar
  101. Case "X86" retVal = True
  102. Case "IA64" retVal = True
  103. Case "*" retVal = True
  104. Case Else strerr = "Attribute processorArchitecture contains invalid value: " + MyVar
  105. retVal = False
  106. End Select
  107. Next
  108. end if
  109. ChkProcessor = retVal
  110. End Function
  111. Function Chklanguage(byRef rootdocobj, byRef strerr)
  112. Dim retVal
  113. Dim languageChkList
  114. retVal = True
  115. set languageChkList = rootdocobj.selectNodes("//assembly/*// @language[nodeType() = '2']")
  116. rootlen = 0
  117. rootlen = languageChkList.length
  118. if rootlen > 0 then
  119. For counter = 0 To rootlen-1 Step 1
  120. MyVar = UCase (CStr(languageChkList.item(counter).text))
  121. if MyVar = "*" then
  122. retVal = True
  123. else
  124. 'then check by length and format
  125. LenMyVar = Len(MyVar)
  126. IF LenMyVar > 5 then
  127. strerr = "Attribute language contains invalid value: length too long:" + MyVar
  128. retVal = False
  129. elseif LenMyVar = 5 then
  130. if RegExpTest("[A-Za-z][A-Za-z]-[A-Za-z][A-Za-z]", MyVar) then
  131. retVal = True
  132. else
  133. strerr = "Attribute language contains invalid value: incorrect format(ie. en-us):" + MyVar
  134. retVal = False
  135. end if
  136. elseif LenMyVar = 2 then
  137. if RegExpTest("[A-Za-z][A-Za-z]", MyVar) then
  138. retVal = True
  139. else
  140. strerr = "Attribute language contains invalid value:" + MyVar
  141. retVal = False
  142. end if
  143. else
  144. strerr = "Attribute language contains invalid value:" + MyVar
  145. retVal = False
  146. End If
  147. end if
  148. Next
  149. end if
  150. Chklanguage = retVal
  151. End Function
  152. Function ChkAllversion(byRef rootdocobj, byRef strerr)
  153. Dim retVal
  154. Dim versionChkList
  155. Dim MyVar
  156. Dim strVersionErr
  157. Dim strValFound
  158. retVal = True
  159. strVersionErr = "Attribute version contains invalid value:"
  160. Dim versionregexp
  161. versionregexp = "^[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}$"
  162. 'create a string array of the two element levels to search the version attribute
  163. 'the first element searches the manifest at the assembly/assemblyIdentity level
  164. 'and the second searches for the version attribute starting from the:
  165. 'assembly/dependency level and all its child elements
  166. Dim arrayofelementstosearch
  167. arrayofelementstosearch = Array("/assembly/assemblyIdentity/ @version[nodeType() = '2']", _
  168. "/assembly/dependency/*// @version[nodeType() = '2']")
  169. 'Now loop through earch array string item and do the search and validation check
  170. 'note: the array is zero based
  171. For i = 0 To 1 Step 1
  172. 'First check version at the /assembly/assemblyIdentity level
  173. set versionChkList = rootdocobj.selectNodes(arrayofelementstosearch(i))
  174. if versionChkList.length > 0 then
  175. For counter = 0 To versionChkList.length-1 Step 1
  176. MyVar = UCase (CStr(versionChkList.item(counter).text))
  177. if RegExpTest(versionregexp, MyVar) then
  178. retVal = True
  179. else
  180. strerr = strVersionErr + MyVar
  181. retVal = False
  182. Exit For
  183. end if
  184. Next
  185. if retVal = False then
  186. Exit For
  187. end if
  188. end if
  189. Next
  190. ChkAllversion = retVal
  191. End Function
  192. Function ChkAllGuidtypes(byRef rootdocobj, byRef strerr)
  193. Dim retVal
  194. Dim guidtypeChkList
  195. Dim strVersionErr
  196. Dim strValFound
  197. Dim MyVar
  198. Dim MyVarRegExpIndex
  199. retVal = True
  200. strVersionErr = " attribute contains invalid value:"
  201. Dim strpreelementtosearch
  202. Dim strpostelementtosearch
  203. Dim strFullelementAttributetosearch
  204. strpreelementtosearch = "/assembly/file/*// @"
  205. strpostelementtosearch = "[nodeType() = '2']"
  206. 'needed 4 different regexpressions to test for 4 acceptable formats
  207. 'created an array of these
  208. 'the format validations in the guidregexpr array are indexed as follows:
  209. ' 0 = "{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}"
  210. ' 1 = "{AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}"
  211. ' 2 = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
  212. ' 3 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  213. Dim guidregexpr
  214. guidregexpr = Array("^\{[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}\}", _
  215. "^\{[A-Fa-f0-9]{32}\}", _
  216. "^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}", _
  217. "^[A-Fa-f0-9]{32}")
  218. Dim arrAttribsToChk
  219. Dim numberofarrAttribsToChk
  220. numberofarrAttribsToChk = 3 'because VBScipt doesnt have a way to dynamically get the size of an array you must keep track yourself
  221. arrAttribsToChk = Array("clsid", "tlbid", "iid")
  222. 'Now loop through earch arrAttribsToChk string attribute and do the search and validation check
  223. For i = 0 To numberofarrAttribsToChk-1 Step 1
  224. 'First check guid attribute at the /assembly/file level so build full string
  225. strFullelementAttributetosearch = strpreelementtosearch + arrAttribsToChk(i) + strpostelementtosearch
  226. set guidtypeChkList = rootdocobj.selectNodes(strFullelementAttributetosearch)
  227. if guidtypeChkList.length > 0 then
  228. For counter = 0 To guidtypeChkList.length-1 Step 1
  229. 'Extract the text value from the attribute
  230. MyVar = UCase (CStr(guidtypeChkList.item(counter).text))
  231. 'Based on length, determine which regular expression string to use
  232. if Len(MyVar) = 38 then 'must use guidregexpr(0)
  233. MyVarRegExpIndex = 0
  234. elseif Len(MyVar) = 34 then 'must use guidregexpr(1)
  235. MyVarRegExpIndex = 1
  236. elseif Len(MyVar) = 36 then 'must use guidregexpr(2)
  237. MyVarRegExpIndex = 2
  238. elseif Len(MyVar) = 32 then 'must use guidregexpr(3)
  239. MyVarRegExpIndex = 3
  240. else
  241. retVal = False
  242. strerr = arrAttribsToChk(i) + strVersionErr + MyVar
  243. Exit For
  244. end if
  245. 'Do actual regular expression validation search
  246. if RegExpTest(guidregexpr(MyVarRegExpIndex), MyVar) then
  247. retVal = True
  248. else
  249. retVal = False
  250. strerr = arrAttribsToChk(i) + strVersionErr + MyVar
  251. Exit For
  252. end if
  253. Next
  254. end if
  255. If retVal = False then
  256. Exit For
  257. End if
  258. Next
  259. ChkAllGuidtypes = retVal
  260. End Function
  261. Function ChkthreadingModel(byRef rootdocobj, byRef strerr)
  262. Dim retVal
  263. Dim threadingModelChkList
  264. retVal = True
  265. set threadingModelChkList = rootdocobj.selectNodes("//assembly/*// @threadingModel[nodeType() = '2']")
  266. rootlen = 0
  267. rootlen = threadingModelChkList.length
  268. if rootlen > 0 then
  269. For counter = 0 To rootlen-1 Step 1
  270. MyVar = UCase (CStr(threadingModelChkList.item(counter).text))
  271. Select Case MyVar
  272. Case UCase ("Apartment") retVal = True
  273. Case UCase ("Free") retVal = True
  274. Case UCase ("Single") retVal = True
  275. Case UCase ("Both") retVal = True
  276. Case UCase ("Neutral") retVal = True
  277. Case Else strerr = "Attribute threadingModel contains invalid value: " + MyVar
  278. retVal = False
  279. End Select
  280. Next
  281. end if
  282. ChkthreadingModel = retVal
  283. End Function
  284. Function RegExpTest(patrn, strng)
  285. Dim regEx, Match, Matches ' Create variable.
  286. Set regEx = New RegExp ' Create a regular expression.
  287. regEx.Pattern = patrn ' Set pattern.
  288. regEx.IgnoreCase = True ' Set case insensitivity.
  289. regEx.Global = True ' Set global applicability.
  290. Set Matches = regEx.Execute(strng) ' Execute search.
  291. RetStr = "TTL Matches: " & CStr(Matches.Count) & vbCRLF
  292. For Each Match in Matches ' Iterate Matches collection.
  293. RetStr = RetStr & "Match found at position "
  294. RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
  295. RetStr = RetStr & Match.Value & "'." & vbCRLF
  296. Next
  297. if Matches.Count = 1 then
  298. RegExpTest = True
  299. else
  300. RegExpTest = False
  301. end if
  302. End Function
  303. Function IsMSXML3Installed()
  304. Dim retVal
  305. Dim XmlDoc
  306. Dim strFailed
  307. retVal = True
  308. strFailed = "MSXML version 3.0 not installed. Please install to run Manifestchk validator."
  309. On Error resume next
  310. set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
  311. if Err.Number <> 0 then
  312. If Err.Number = 429 then
  313. PrintCustomError strFailed, 2
  314. else
  315. strFailed = Hex(Err.Number) + ": " + Err.Description
  316. PrintCustomError strFailed, 2
  317. end if
  318. retVal = False
  319. end if
  320. IsMSXML3Installed = retVal
  321. End Function
  322. Function IsValidCommandLine()
  323. Dim objArgs
  324. Dim retVal
  325. Dim retValT
  326. Dim nOnlyAllowFirstTimeReadFlag
  327. 'nOnlyAllowFirstTimeReadFlag values: Manifest = 0x01 Schema = 0x02 Quiet = 0x04 InBuildProcess = 0x08 ManifestType = 0x16
  328. nOnlyAllowFirstTimeReadFlag = 0
  329. retVal = True
  330. Set objArgs = WScript.Arguments
  331. if objArgs.Count < 2 then
  332. retVal = False
  333. IsValidCommandLine = retVal
  334. Exit function
  335. end if
  336. For I = 0 to objArgs.Count - 1
  337. if Len(objArgs(I)) >= 2 then
  338. if Mid(objArgs(I),1,1)="/" then
  339. Select Case UCase(Mid(objArgs(I),2,1))
  340. Case "?"
  341. retVal = False
  342. IsValidCommandLine = retVal
  343. Exit function
  344. Case "Q"
  345. if Len(objArgs(I)) = 2 then
  346. if 4 and nOnlyAllowFirstTimeReadFlag then
  347. retVal = False
  348. IsValidCommandLine = retVal
  349. Exit function
  350. else
  351. gRunMode = gRunMode + 1
  352. nOnlyAllowFirstTimeReadFlag = nOnlyAllowFirstTimeReadFlag + 4
  353. end if
  354. else
  355. retVal = False
  356. IsValidCommandLine = retVal
  357. Exit function
  358. end if
  359. Case "B"
  360. if Len(objArgs(I)) = 2 then
  361. if 8 and nOnlyAllowFirstTimeReadFlag then
  362. retVal = False
  363. IsValidCommandLine = retVal
  364. Exit function
  365. else
  366. gRunMode = gRunMode + 2
  367. nOnlyAllowFirstTimeReadFlag = nOnlyAllowFirstTimeReadFlag + 8
  368. end if
  369. else
  370. retVal = False
  371. IsValidCommandLine = retVal
  372. Exit function
  373. end if
  374. Case "M"
  375. if Mid(objArgs(I),3,1)=":" then
  376. if Len(objArgs(I)) > 3 then
  377. if 1 and nOnlyAllowFirstTimeReadFlag then
  378. retVal = False
  379. IsValidCommandLine = retVal
  380. Exit function
  381. else
  382. sourceFile = Mid(objArgs(I),4)
  383. nOnlyAllowFirstTimeReadFlag = nOnlyAllowFirstTimeReadFlag + 1
  384. end if
  385. else
  386. retVal = False
  387. IsValidCommandLine = retVal
  388. Exit function
  389. end if
  390. else
  391. retVal = False
  392. IsValidCommandLine = retVal
  393. Exit function
  394. end if
  395. Case "S"
  396. if Mid(objArgs(I),3,1)=":" then
  397. if Len(objArgs(I)) > 3 then
  398. if 2 and nOnlyAllowFirstTimeReadFlag then
  399. retVal = False
  400. IsValidCommandLine = retVal
  401. Exit function
  402. else
  403. schemaname = Mid(objArgs(I),4)
  404. nOnlyAllowFirstTimeReadFlag = nOnlyAllowFirstTimeReadFlag + 2
  405. end if
  406. else
  407. retVal = False
  408. IsValidCommandLine = retVal
  409. Exit function
  410. end if
  411. else
  412. retVal = False
  413. IsValidCommandLine = retVal
  414. Exit function
  415. end if
  416. Case "T"
  417. if Mid(objArgs(I),3,1)=":" then
  418. if Len(objArgs(I)) > 3 then
  419. if 16 and nOnlyAllowFirstTimeReadFlag then
  420. retVal = False
  421. IsValidCommandLine = retVal
  422. Exit function
  423. else
  424. TVar = UCase (CStr(Mid(objArgs(I),4)))
  425. Select Case TVar
  426. Case "AM"
  427. gRunMode = gRunMode + 8
  428. retValT = True
  429. Case "PC"
  430. gRunMode = gRunMode + 16
  431. retValT = True
  432. Case "AC"
  433. gRunMode = gRunMode + 32
  434. retValT = True
  435. Case Else strerr = "Argument 'type' contains invalid value: " + TVar
  436. retValT = False
  437. End Select
  438. if retValT = False then
  439. retVal = False
  440. IsValidCommandLine = retVal
  441. Exit function
  442. End if
  443. nOnlyAllowFirstTimeReadFlag = nOnlyAllowFirstTimeReadFlag + 16
  444. end if
  445. else
  446. retVal = False
  447. IsValidCommandLine = retVal
  448. Exit function
  449. end if
  450. else
  451. retVal = False
  452. IsValidCommandLine = retVal
  453. Exit function
  454. end if
  455. Case Else
  456. retVal = False
  457. IsValidCommandLine = retVal
  458. Exit function
  459. End Select
  460. else
  461. retVal = False
  462. IsValidCommandLine = retVal
  463. Exit function
  464. end if
  465. else
  466. retVal = False
  467. IsValidCommandLine = retVal
  468. Exit function
  469. end if
  470. Next
  471. 'now check to make sure at minimum a manifest, schema, and manifest type was set
  472. Dim bschema_manifest_set
  473. bschema_manifest_set = False
  474. if 1 and nOnlyAllowFirstTimeReadFlag then
  475. if 2 and nOnlyAllowFirstTimeReadFlag then
  476. if 16 and nOnlyAllowFirstTimeReadFlag then
  477. bschema_manifest_set = True
  478. else
  479. retVal = False
  480. end if
  481. else
  482. retVal = False
  483. end if
  484. else
  485. retVal = False
  486. end if
  487. IsValidCommandLine = retVal
  488. End Function
  489. Function IsWellFormedXML(sourceFile)
  490. Dim XmlDoc
  491. Dim bRet
  492. Dim pXmlParseError
  493. Dim retVal
  494. Dim strPassed
  495. Dim strFailed
  496. strPassed = "Well Formed XML Validation: PASSED"
  497. strFailed = "Well Formed XML Validation: FAILED"
  498. retVal = True
  499. set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
  500. XmlDoc.async = False
  501. XmlDoc.validateOnParse = False
  502. XmlDoc.resolveExternals = False
  503. bRet = XmlDoc.load(sourceFile)
  504. if not bRet then
  505. PrintOutMode strFailed
  506. set pXmlParseError = XmlDoc.parseError
  507. if gRunMode and 2 then
  508. PrintErrorDuringBuildProcess(pXmlParseError)
  509. else
  510. PrintXMLError(pXmlParseError)
  511. end if
  512. retVal = False
  513. else
  514. PrintOutMode strPassed
  515. end if
  516. set XmlDoc = Nothing
  517. IsWellFormedXML = retVal
  518. End Function
  519. Function IsValidAgainstSchema(sourceFile, schemaname)
  520. Dim XmlDoc
  521. Dim bRet
  522. Dim pXmlParseError
  523. Dim retVal
  524. Dim SchemaCacheObj
  525. Dim objXMLDOMSchemaCollection
  526. Dim strPassed
  527. Dim strFailed
  528. strPassed = "XML Schema Validation: PASSED"
  529. strFailed = "XML Schema Validation: FAILED"
  530. retVal = True
  531. set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
  532. XmlDoc.async = False
  533. XmlDoc.validateOnParse = True
  534. XmlDoc.resolveExternals = False
  535. set SchemaCacheObj = CreateObject("Msxml2.XMLSchemaCache.3.0")
  536. On Error Resume Next
  537. SchemaCacheObj.add "urn:schemas-microsoft-com:asm.v1", schemaname
  538. if Err.Number <> 0 then
  539. PrintOutMode strFailed
  540. if gRunMode and 2 then
  541. PrintSchemaErrorDuringBuildProcess(Err)
  542. else
  543. PrintSchemaError(Err)
  544. end if
  545. set SchemaCacheObj = Nothing
  546. set XmlDoc = Nothing
  547. retVal = False
  548. IsValidAgainstSchema = retVal
  549. Exit Function
  550. end if
  551. XmlDoc.schemas = SchemaCacheObj
  552. bRet = XmlDoc.load(sourceFile)
  553. if not bRet then
  554. PrintOutMode strFailed
  555. set pXmlParseError = XmlDoc.parseError
  556. if gRunMode and 2 then
  557. PrintErrorDuringBuildProcess(pXmlParseError)
  558. else
  559. PrintXMLError(pXmlParseError)
  560. end if
  561. retVal = False
  562. else
  563. PrintOutMode strPassed
  564. end if
  565. set SchemaCacheObj = Nothing
  566. set pXmlParseError = Nothing
  567. set XmlDoc = Nothing
  568. IsValidAgainstSchema = retVal
  569. End Function
  570. Function ChkAssemblyID(byRef rootdocobj, byRef strerr)
  571. 'this function validates a special check for Ref Context Assembly Identity: Type=win32-policy
  572. Dim retVal
  573. Dim AssemblyID
  574. Dim strSelectNode
  575. retVal = True
  576. strSelectNode = "//assembly/dependency/dependentAssembly/assemblyIdentity/*// @version[nodeType() = '2']"
  577. set AssemblyID = rootdocobj.selectNodes(strSelectNode)
  578. rootlen = 0
  579. rootlen = AssemblyID.length
  580. if rootlen > 0 then
  581. For counter = 0 To rootlen-1 Step 1
  582. MyVar = CStr(AssemblyID.item(counter).text)
  583. Select Case MyVar
  584. Case "win32-policy" retVal = True
  585. Case Else strerr = "Attribute type contains invalid value: " + MyVar
  586. retVal = False
  587. End Select
  588. Next
  589. else
  590. retVal = False
  591. end if
  592. ChkAssemblyID = retVal
  593. End Function
  594. Function ChkAssemblyIDNoversion(byRef rootdocobj, chkType)
  595. 'this function validates that no Version attribute is present at the below strSelectNode string elements.
  596. Dim retVal
  597. Dim AssemblyIDNoversion
  598. Dim strSelectNode
  599. retVal = True
  600. if chkType = "p" then
  601. strSelectNode = "//assembly/dependency/dependentAssembly/*// @version[nodeType() = '2']"
  602. else
  603. strSelectNode = "//configuration/windows/assemblyBinding/dependentAssembly/*// @version[nodeType() = '2']"
  604. end if
  605. set AssemblyIDNoversion = rootdocobj.selectNodes(strSelectNode)
  606. rootlen = 0
  607. rootlen = AssemblyIDNoversion.length
  608. if rootlen > 0 then
  609. WScript.Echo "strSelectNode:" & strSelectNode
  610. retVal = False
  611. end if
  612. ChkAssemblyIDNoversion = retVal
  613. End Function
  614. Function ChkCFGversion(byRef rootdocobj, byRef strerr, chkType)
  615. Dim retVal
  616. Dim versionChkList
  617. Dim MyVar
  618. Dim strVersionErr
  619. Dim strValFound
  620. retVal = True
  621. strVersionErr = "Attribute version contains invalid value:"
  622. Dim versionregexp
  623. versionregexp = "^[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}$"
  624. 'create a string array of the two element levels to search the version attribute
  625. 'the first element searches the manifest at the assembly/assemblyIdentity level
  626. 'and the second searches for the version attribute starting from the:
  627. 'assembly/dependency level and all its child elements
  628. Dim arrayofelementstosearch
  629. if chkType = "p" then
  630. 'check as publisher policy
  631. arrayofelementstosearch = Array("/assembly/dependency/dependentAssembly/*// @oldVersion[nodeType() = '2']", _
  632. "/assembly/dependency/dependentAssembly/*// @newVersion[nodeType() = '2']")
  633. else
  634. 'check as application policy
  635. arrayofelementstosearch = Array("/configuration/windows/assemblyBinding/dependentAssembly/*// @oldVersion[nodeType() = '2']", _
  636. "/configuration/windows/assemblyBinding/dependentAssembly/*// @newVersion[nodeType() = '2']")
  637. end if
  638. 'Now loop through earch array string item and do the search and validation check
  639. 'note: the array is zero based
  640. For i = 0 To 1 Step 1
  641. 'First check version at the /assembly/assemblyIdentity level
  642. set versionChkList = rootdocobj.selectNodes(arrayofelementstosearch(i))
  643. if versionChkList.length > 0 then
  644. For counter = 0 To versionChkList.length-1 Step 1
  645. MyVar = UCase (CStr(versionChkList.item(counter).text))
  646. if RegExpTest(versionregexp, MyVar) then
  647. retVal = True
  648. else
  649. if i = 0 then
  650. strVersionErr = "Attribute oldVersion contains invalid value:"
  651. else
  652. strVersionErr = "Attribute newVersion contains invalid value:"
  653. end if
  654. strerr = strVersionErr + MyVar
  655. retVal = False
  656. Exit For
  657. end if
  658. Next
  659. if retVal = False then
  660. Exit For
  661. end if
  662. end if
  663. Next
  664. ChkCFGversion = retVal
  665. End Function
  666. Function ChkCustomCfg(byRef rootdocobj, byRef strerr, chkType)
  667. Dim retVal
  668. retVal = True
  669. if Not ChkAssemblyIDNoversion(rootdocobj, chkType) then
  670. strerr = "assemblyidentity should not contain version attribute at this level"
  671. retVal = False
  672. end if
  673. if Not ChkCFGversion(rootdocobj, strerr, chkType) then
  674. retVal = False
  675. end if
  676. ChkCustomCfg = retVal
  677. End Function
  678. Function CustomChk(sourceFile)
  679. Dim root
  680. Dim XmlDoc
  681. Dim retVal
  682. retVal = True
  683. Dim strPassed
  684. Dim strFailed
  685. Dim strErrOut
  686. strPassed = "XML Last Validation: PASSED"
  687. strFailed = "XML Last Validation: FAILED"
  688. set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
  689. XmlDoc.validateOnParse = False
  690. XmlDoc.resolveExternals = False
  691. XmlDoc.async = False
  692. XmlDoc.load(sourceFile)
  693. set root = XmlDoc.documentElement
  694. Do
  695. 'validate processorArchitecture attribute
  696. if Not ChkProcessor(root, strErrOut) then
  697. retVal = False
  698. Exit Do
  699. end if
  700. 'validate threadingModel attribute
  701. if Not ChkthreadingModel(root, strErrOut) then
  702. retVal = False
  703. Exit Do
  704. end if
  705. 'validate language attribute
  706. if Not Chklanguage(root, strErrOut) then
  707. retVal = False
  708. Exit Do
  709. end if
  710. 'validate version attribute
  711. if Not ChkAllversion(root, strErrOut) then
  712. retVal = False
  713. Exit Do
  714. end if
  715. 'validate AllGuidtype attribute
  716. if Not ChkAllGuidtypes(root, strErrOut) then
  717. retVal = False
  718. Exit Do
  719. end if
  720. 'validate custom check for Publisher Configuration
  721. if 16 and gRunMode then
  722. if Not ChkCustomCfg(root, strErrOut,"p") then
  723. retVal = False
  724. Exit Do
  725. end if
  726. end if
  727. 'validate custom check for Application Configuration
  728. if 32 and gRunMode then
  729. if Not ChkCustomCfg(root, strErrOut,"a") then
  730. retVal = False
  731. Exit Do
  732. end if
  733. end if
  734. Exit Do
  735. Loop
  736. if retVal then
  737. PrintOutMode strPassed
  738. else
  739. PrintOutMode strFailed
  740. PrintCustomError strErrOut, 1
  741. end if
  742. set XmlDoc = Nothing
  743. CustomChk = retVal
  744. End Function
  745. 'global run code starts here
  746. 'global vars
  747. Dim sourceFile
  748. Dim schemaname
  749. 'mainRetVal is returned value that cscript.exe returns
  750. 'value 0 = validation passed with no errors, 1 = error in validation process, 2 = commandline arg error
  751. Dim mainRetVal
  752. 'gRunMode - flag that determines whether to run in quiet mode, if in build process, and manifest Type to check
  753. 'value 1 - means run quiet, value 2 means in build process, value
  754. Dim gRunMode
  755. 'Initialize variables
  756. sourceFile = ""
  757. schemaname = ""
  758. gRunMode = 0
  759. mainRetVal = 0
  760. Do
  761. 'First Check just for valid commandline
  762. If Not IsValidCommandLine() then
  763. PrintUsage()
  764. mainRetVal = 2
  765. Exit Do
  766. End If
  767. 'Check to make sure MSXML version 3 is installed on machine
  768. If Not IsMSXML3Installed() then
  769. mainRetVal = 1
  770. Exit Do
  771. End If
  772. 'Now First pass is to check just for Well Formed XML
  773. If Not IsWellFormedXML(sourceFile) then
  774. mainRetVal = 1
  775. Exit Do
  776. End If
  777. 'Second... pass checks against schema for correct Win32 Fusion structure
  778. If Not IsValidAgainstSchema(sourceFile,schemaname) then
  779. mainRetVal = 1
  780. Exit Do
  781. End If
  782. 'Last... add custom validation to check for various values that the schema could not handle
  783. If Not CustomChk(sourceFile) then
  784. mainRetVal = 1
  785. Exit Do
  786. End If
  787. Exit Do
  788. Loop
  789. 'WScript.Echo "gRunMode: " + CStr(gRunMode)
  790. 'WScript.Echo "mainRetVal: " + CStr(mainRetVal)
  791. WScript.Quit mainRetVal