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.

454 lines
12 KiB

  1. <HTML>
  2. <HEAD>
  3. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
  4. <TITLE>WMI Scripting Sample - Security Descriptor Viewer</TITLE>
  5. <LINK REL="STYLESHEET" HREF="sdstyle.css">
  6. <OBJECT id=locator CLASSID="CLSID:BF37162F-9E73-48ed-B009-92E2F732252F"></OBJECT>
  7. <SCRIPT language=VBScript>
  8. dim sd
  9. dim saclAceArray ()
  10. dim daclAceArray ()
  11. Sub window_onload
  12. ' Test code to fake up an SD - remove this with a real SD when
  13. ' it's all working
  14. set sacl = CreateObject("AccessControlList")
  15. set dacl = CreateObject("AccessControlList")
  16. set sd = CreateObject("SecurityDescriptor")
  17. sd.SystemAcl = sacl
  18. sd.DiscretionaryAcl = dacl
  19. End Sub
  20. Sub DisplaySD (sd)
  21. on error resume next
  22. sdRevision.innerText = sd.Revision
  23. sdOwner.innerText = sd.Owner
  24. sdOwnerDefaulted.innerText = sd.OwnerDefaulted
  25. sdGroup.innerText = sd.Group
  26. sdGroupDefaulted.innerText = sd.GroupDefaulted
  27. sdDaclDefaulted.innerText = sd.DaclDefaulted
  28. sdSaclDefaulted.innerText = sd.SaclDefaulted
  29. DisplayAcl sd.DiscretionaryAcl, true
  30. DisplayAcl sd.SystemAcl, false
  31. End Sub
  32. Sub DisplayAcl (acl, bIsDacl)
  33. on error resume next
  34. if bIsDacl then
  35. daclAclRevision.innerText = acl.AclRevision
  36. daclAceCount.innerText = acl.AceCount
  37. DisplayAces acl, daclAces, bIsDacl
  38. else
  39. saclAclRevision.innerText = acl.AclRevision
  40. saclAceCount.innerText = acl.AceCount
  41. DisplayAces acl, saclAces, bIsDacl
  42. end if
  43. End Sub
  44. Sub DisplayAces (acl, aclAceTable, bIsDacl)
  45. on error resume next
  46. ClearAceInfo aclAceTable, bIsDacl
  47. for each ace in acl
  48. DisplayAce ace, aclAceTable, bIsDacl
  49. next
  50. End Sub
  51. Sub DisplayAce (ace, aclAceTable, bIsDacl)
  52. on error resume next
  53. set newRow = aclAceTable.insertRow (-1)
  54. newRow.insertCell (-1).innerText = Hex(ace.AccessMask)
  55. newRow.insertCell (-1).innerText = ace.AceType
  56. newRow.insertCell (-1).innerText = ace.AceFlags
  57. newRow.insertCell (-1).innerText = ace.Flags
  58. newRow.insertCell (-1).innerText = ace.ObjectType
  59. newRow.insertCell (-1).innerText = ace.InheritedObjectType
  60. newRow.insertCell (-1).innerText = ace.Trustee
  61. ' Add a delete button
  62. set newCell = newRow.insertCell (-1)
  63. if bIsDacl then
  64. newCell.innerHTML = _
  65. "<SPAN CLASS=HotText2 onmouseover=""this.style.cursor='hand'"" onmouseout=""this.style.cursor='auto'"" onclick='DeleteAce(this.parentElement.parentElement, true)'>Delete</SPAN>"
  66. else
  67. newCell.innerHTML = _
  68. "<SPAN CLASS=HotText2 onmouseover=""this.style.cursor='hand'"" onmouseout=""this.style.cursor='auto'"" onclick='DeleteAce(this.parentElement.parentElement, false)'>Delete</SPAN>"
  69. end if
  70. ' Add a modify button
  71. set newCell = newRow.insertCell (-1)
  72. if bIsDacl then
  73. newCell.innerHTML = _
  74. "<SPAN CLASS=HotText2 onmouseover=""this.style.cursor='hand'"" onmouseout=""this.style.cursor='auto'"" onclick='ModifyAce(this.parentElement.parentElement, true)'>Modify</SPAN>"
  75. else
  76. newCell.innerHTML = _
  77. "<SPAN CLASS=HotText2 onmouseover=""this.style.cursor='hand'"" onmouseout=""this.style.cursor='auto'"" onclick='ModifyAce(this.parentElement.parentElement, false)'>Modify</SPAN>"
  78. end if
  79. ' Remember our ACE in case we need to delete or modify it
  80. if bIsDacl then
  81. if IsNull(daclAceArray) then
  82. daclAceArray = Array (0)
  83. set daclAceArray(0) = ace
  84. else
  85. bound = aclAceTable.rows.length - 1
  86. Redim Preserve daclAceArray (bound)
  87. set daclAceArray (bound) = ace
  88. end if
  89. else
  90. if IsNull(saclAceArray) then
  91. saclAceArray = Array (0)
  92. set saclAceArray(0) = ace
  93. else
  94. bound = aclAceTable.rows.length - 1
  95. Redim Preserve saclAceArray (bound)
  96. set saclAceArray (bound) = ace
  97. end if
  98. end if
  99. End Sub
  100. Sub RefreshAce (row, ace)
  101. row.cells(0).innerText = Hex(ace.AccessMask)
  102. row.cells(1).innerText = ace.AceType
  103. row.cells(2).innerText = ace.AceFlags
  104. row.cells(3).innerText = ace.Flags
  105. row.cells(4).innerText = ace.ObjectType
  106. row.cells(5).innerText = ace.InheritedObjectType
  107. row.cells(6).innerText = ace.Trustee
  108. End Sub
  109. Sub DeleteAce (row, bIsDacl)
  110. if bIsDacl then
  111. set ace = daclAceArray (row.rowIndex - 1)
  112. else
  113. set ace = saclAceArray (row.rowIndex - 1)
  114. end if
  115. row.removeNode true
  116. if err <> 0 then
  117. alert "Error!"
  118. else
  119. if bIsDacl then
  120. sd.DiscretionaryAcl.RemoveAce (ace)
  121. else
  122. sd.SystemAcl.RemoveAce (ace)
  123. end if
  124. end if
  125. End Sub
  126. Sub ClearSDInfo
  127. on error resume next
  128. sdRevision.innerText = ""
  129. sdOwner.innerText = ""
  130. sdOwnerDefaulted.innerText = ""
  131. sdGroup.innerText = ""
  132. sdGroupDefaulted.innerText = ""
  133. sdDaclDefaulted.innerText = ""
  134. sdSaclDefaulted.innerText = ""
  135. ClearAclInfo true
  136. ClearAclInfo false
  137. End Sub
  138. Sub ClearAclInfo (bIsDacl)
  139. on error resume next
  140. if bIsDacl then
  141. daclAclRevision.innerText = ""
  142. daclAceCount.innerText = ""
  143. ClearAceInfo daclAces, bIsDacl
  144. else
  145. saclAclRevision.innerText = ""
  146. saclAceCount.innerText = ""
  147. ClearAceInfo saclAces, bIsDacl
  148. end if
  149. End Sub
  150. Sub ClearAceInfo (aceTable, bIsDacl)
  151. on error resume next
  152. numRows = aceTable.rows.length
  153. if numRows > 0 then
  154. for i = 0 to (numRows-1)
  155. aceTable.deleteRow i
  156. next
  157. end if
  158. if bIsDacl then
  159. if Not(IsNull(daclAceArray)) then set daclAceArray = null
  160. else
  161. if Not(IsNull(saclAceArray)) then set saclAceArray = null
  162. end if
  163. End Sub
  164. '***************************************************************
  165. ' Handles the onclick event for the Security Descriptor hot text
  166. '***************************************************************
  167. Sub getSD_onclick
  168. on error resume next
  169. ' Show that we're busy
  170. getSD.style.cursor = "wait"
  171. ClearSDInfo
  172. window.defaultStatus = "Retrieving value..."
  173. ' Attempt to open the required object
  174. ' set obj = locator.Open (objectPath.value, user.value, password.value)
  175. ' Temporary hack
  176. err.clear
  177. set ldap = locator.Open (objectPath.value, user.value, password.value)
  178. if err then
  179. window.alert ("Error opening ldap: 0x" & Hex(err.Number) & " : " & err.Description)
  180. end if
  181. Set c = CreateObject("WbemScripting.SWbemNamedValueSet")
  182. c.Add "INCLUDE_OWNER", true
  183. c.Add "INCLUDE_GROUP", true
  184. c.Add "INCLUDE_DACL", true
  185. c.Add "INCLUDE_SACL", true
  186. set obj = ldap.Get (".CN=Users", &H40000, c)
  187. if err <> 0 then
  188. window.alert ("Error retrieving object: 0x" & Hex(err.Number) & " : " & err.Description)
  189. else
  190. ' Try and get the specified Security Descriptor property
  191. set sd = obj.GetSecurityDescriptor_
  192. if err <> 0 then
  193. window.alert ("Could not get Security Descriptor: 0x" & Hex(err.Number) & " : " & err.Description)
  194. else
  195. DisplaySD sd
  196. end if
  197. end if
  198. getSD.style.cursor = "auto"
  199. End sub
  200. Sub objectPathDiv_onmouseover
  201. window.status = "Path to the object whose Security Descriptor is to be displayed"
  202. End Sub
  203. Sub objectPathDiv_onmouseout
  204. window.status = ""
  205. End Sub
  206. Sub nameDiv_onmouseover
  207. window.status = "Name of the Security Descriptor property to retrieve, or the default (__SD) if not specified"
  208. End Sub
  209. Sub nameDiv_onmouseout
  210. window.status = ""
  211. End Sub
  212. Sub userPasswordDiv_onmouseover
  213. window.status = "Explicit user credentials (if required)"
  214. End Sub
  215. Sub userPasswordDiv_onmouseout
  216. window.status = ""
  217. End Sub
  218. Sub getDiv_onmouseover
  219. window.status = "Retrieve and display the specified security descriptor"
  220. getSD.style.color = "Green"
  221. getSD.style.fontWeight = "bolder"
  222. getSD.style.cursor = "hand"
  223. End Sub
  224. Sub getDiv_onmouseout
  225. window.status = ""
  226. getSD.style.color = "SaddleBrown"
  227. getSD.style.fontWeight = "lighter"
  228. getSD.style.cursor = "auto"
  229. End Sub
  230. Sub AddAce (bIsDacl)
  231. on error resume next
  232. set ace = window.showModalDialog ("sdaddace.htm",, _
  233. "help:no;resizable:yes;status:no;dialogWidth:18cm;dialogHeight:15cm")
  234. if IsObject(ace) then
  235. if bIsDacl then
  236. sd.DiscretionaryAcl.AddAce ace
  237. else
  238. sd.SystemAcl.AddAce ace
  239. end if
  240. if err <> 0 then
  241. alert Err.Description & ": 0x" & Hex(Err.number)
  242. else
  243. if bIsDacl then
  244. DisplayAce ace, daclAces, true
  245. else
  246. DisplayAce ace, saclAces, false
  247. end if
  248. end if
  249. end if
  250. End Sub
  251. Sub ModifyAce (row, bIsDacl)
  252. if bIsDacl then
  253. set ace = daclAceArray (row.rowIndex - 1)
  254. else
  255. set ace = saclAceArray (row.rowIndex - 1)
  256. end if
  257. if window.showModalDialog ("sdaddace.htm", ace, _
  258. "help:no;resizable:yes;status:no;dialogWidth:18cm;dialogHeight:15cm") then
  259. RefreshAce row, ace
  260. end if
  261. End Sub
  262. Sub saclAddAce_onmouseover
  263. saclAddAce.style.color = "Green"
  264. saclAddAce.style.fontWeight = "bolder"
  265. saclAddAce.style.cursor = "hand"
  266. End Sub
  267. Sub saclAddAce_onmouseout
  268. saclAddAce.style.color = "SaddleBrown"
  269. saclAddAce.style.fontWeight = "lighter"
  270. saclAddAce.style.cursor = "auto"
  271. End Sub
  272. Sub daclAddAce_onmouseover
  273. daclAddAce.style.color = "Green"
  274. daclAddAce.style.fontWeight = "bolder"
  275. daclAddAce.style.cursor = "hand"
  276. End Sub
  277. Sub daclAddAce_onmouseout
  278. daclAddAce.style.color = "SaddleBrown"
  279. daclAddAce.style.fontWeight = "lighter"
  280. daclAddAce.style.cursor = "auto"
  281. End Sub
  282. </SCRIPT>
  283. </HEAD>
  284. <BODY>
  285. <H1>WMI Scripting Sample - Security Descriptor Viewer</H1>
  286. <P>
  287. <HR>
  288. <P></P>
  289. <SPAN id=objectPathDiv>
  290. <P class=ObjectPath>Object Path: <INPUT id=objectPath style="WIDTH: 548px; HEIGHT: 22px" size=78
  291. name=text1 value=umi://nw01t1/ldap>&nbsp;</P>
  292. </SPAN>
  293. <SPAN id=userPasswordDiv>
  294. <P class=ObjectPath>User:&nbsp;<INPUT id=user value=nw01t1domnb\administrator>
  295. &nbsp; Password: <INPUT type=password id=password value=nw01t1domnb>&nbsp;
  296. </SPAN>
  297. <SPAN id=nameDiv></P></SPAN>
  298. <P>
  299. <SPAN id=getDiv><P class=HotText id=getSD align=center>Get the Security Descriptor</P></SPAN>
  300. <P></P>
  301. <P>
  302. <HR>
  303. <P></P>
  304. <H2>Security Descriptor information</H2>
  305. <P>
  306. <TABLE CLASS=data cellSpacing=1 cellPadding=1 width="75%" >
  307. <COLGROUP CLASS=data>
  308. <COLGROUP CLASS=valueCol>
  309. <TR>
  310. <TD>Revision</TD>
  311. <TD id=sdRevision></TD></TR>
  312. <TR>
  313. <TD>Control</TD>
  314. <TD id=sdControl></TD></TR>
  315. <TR>
  316. <TD>Owner</TD>
  317. <TD id=sdOwner></TD></TR>
  318. <TR>
  319. <TD>OwnerDefaulted</TD>
  320. <TD id=sdOwnerDefaulted></TD></TR>
  321. <TR>
  322. <TD>Group</TD>
  323. <TD id=sdGroup></TD></TR>
  324. <TR>
  325. <TD>GroupDefaulted</TD>
  326. <TD id=sdGroupDefaulted></TD></TR>
  327. <TR>
  328. <TD>DaclDefaulted</TD>
  329. <TD id=sdDaclDefaulted></TD></TR>
  330. <TR>
  331. <TD>SaclDefaulted</TD>
  332. <TD id=sdSaclDefaulted></TD></TR></TABLE></P>
  333. <H2>
  334. <HR>
  335. </H2>
  336. <H2>System ACL information</H2>
  337. <P>
  338. <TABLE CLASS=data cellSpacing=1 cellPadding=1 width="75%">
  339. <COLGROUP CLASS=data>
  340. <COLGROUP CLASS=valueCol>
  341. <TR>
  342. <TD>AclRevision</TD>
  343. <TD id=saclAclRevision></TD></TR>
  344. <TR>
  345. <TD>AceCount</TD>
  346. <TD id=saclAceCount></TD></TR></TABLE></P>
  347. <H3>ACEs</H3>
  348. <TABLE CLASS=data cellSpacing=1 cellPadding=1 width="85%" border=1 style="WIDTH: 85%">
  349. <THEAD>
  350. <TR>
  351. <TH>AccessMask</TH>
  352. <TH>AceType</TH>
  353. <TH>AceFlags</TH>
  354. <TH>Flags</TH>
  355. <TH>ObjectType</TH>
  356. <TH>InheritedObjectType</TH>
  357. <TH>Trustee</TH>
  358. <TH><SPAN CLASS=HotText2 onmouseover="me.style.cursor='hand'"
  359. onmouseout="me.style.cursor='auto'" onclick="AddAce(false)">Add</SPAN></TH></TR>
  360. </THEAD>
  361. <TBODY id=saclAces></TBODY>
  362. </TABLE>
  363. <H2>
  364. <HR>
  365. </H2>
  366. <H2>Discretionary ACL Information</H2>
  367. <P>
  368. <TABLE CLASS=data cellSpacing=1 cellPadding=1 width="75%">
  369. <COLGROUP CLASS=data></COLGROUP>
  370. <COLGROUP CLASS=valueCol></COLGROUP>
  371. <TR>
  372. <TD>AclRevision</TD>
  373. <TD id=daclAclRevision></TD></TR>
  374. <TR>
  375. <TD>AceCount</TD>
  376. <TD id=daclAceCount></TD></TR></TABLE></P>
  377. <H3>ACEs</H3>
  378. <TABLE CLASS=data cellSpacing=1 cellPadding=1 width="85%" border=1 style="WIDTH: 85%">
  379. <THEAD>
  380. <TR>
  381. <TH>AccessMask</TH>
  382. <TH>AceType</TH>
  383. <TH>AceFlags</TH>
  384. <TH>Flags</TH>
  385. <TH>ObjectType</TH>
  386. <TH>InheritedObjectType</TH>
  387. <TH>Trustee</TH>
  388. <TH><SPAN CLASS=HotText2 onmouseover="me.style.cursor='hand'"
  389. onmouseout="me.style.cursor='auto'" onclick="AddAce(true)">Add</SPAN></TH></TR>
  390. </THEAD>
  391. <TBODY id=daclAces></TBODY>
  392. </TABLE>
  393. </BODY>
  394. </HTML>