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.

597 lines
16 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' scrldap.wsf
  5. '
  6. ' Purpose: test UMI LDAP functionality
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="UMI LDAP Test">
  16. <reference object="WbemScripting.SWbemLocator" version="1.2"/>
  17. <script language="VBScript">
  18. on error resume next
  19. set scriptHelper = CreateObject("WMIScriptHelper.WSC")
  20. scriptHelper.logFile = "c:\temp\umildap.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "UMI LDAP"
  23. scriptHelper.testStart
  24. dim locator
  25. dim computerName
  26. computerName = "nw01t1"
  27. username = "nw01t1domnb\administrator"
  28. password = "nw01t1domnb"
  29. if WScript.arguments.Count > 0 then computerName = WScript.Arguments (0)
  30. if WScript.arguments.Count > 1 then username = WScript.Arguments (1)
  31. if WScript.arguments.Count > 2 then password = WScript.Arguments (2)
  32. TestBindings
  33. 'TestClasses
  34. TestAttributes
  35. 'TestSearch
  36. 'TestSecurity
  37. 'TestExtensions
  38. 'TestUsers
  39. 'TestGroups
  40. 'TestComputers
  41. scriptHelper.testComplete
  42. if scriptHelper.statusOK then
  43. WScript.Echo "PASS"
  44. WScript.Quit 0
  45. else
  46. WScript.Echo "FAIL"
  47. WScript.Quit 1
  48. end if
  49. '****************************************************************
  50. '*
  51. '* TestBindings
  52. '* ============
  53. '*
  54. '* Test of moniker-based binding to objects and explicit
  55. '* locator connections with search preferences.
  56. '*
  57. '****************************************************************
  58. Sub TestBindings ()
  59. on error resume next
  60. scriptHelper.writeToLog "", 2
  61. scriptHelper.writeToLog "**********************************", 2
  62. scriptHelper.writeToLog ">> Testing binding via monikers...", 2
  63. scriptHelper.writeToLog "**********************************", 2
  64. scriptHelper.writeToLog "", 2
  65. ' Bind to namespace using UMI path
  66. set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
  67. if err <> 0 then
  68. scriptHelper.writeErrorToLog err, "Failed to bind to umi://" & computerName & "/LDAP"
  69. else
  70. scriptHelper.writeToLog "Succesful binding to umi://" & computerName & "/LDAP", 2
  71. end if
  72. 'Bind to single object using UMI path
  73. 'set user = GetObject("umi:///winnt/computer=" & computerName & "/user=guest")
  74. 'if err <> 0 then
  75. ' scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName & "/user=guest"
  76. 'else
  77. ' scriptHelper.writeToLog "Successful binding to umi:///winnt/computer=" & computerName & "/user=guest", 2
  78. 'end if
  79. ' Bind to single object using native path
  80. 'set user = GetObject("umiwinnt:///" & computerName & "/guest,User")
  81. 'if err <> 0 then
  82. ' scriptHelper.writeErrorToLog err, "Failed to bind to umiwinnt:///" & computerName & "/guest,User"
  83. 'else
  84. ' scriptHelper.writeToLog "Successful binding to umiwinnt:///" & computerName & "/guest,User", 2
  85. 'end if
  86. ' Bind using a umi server path
  87. ' Bind using a native server path
  88. ' Bind using connection properties
  89. set locator = CreateObject("WbemScripting.SWbemLocatorEx")
  90. ' set context = CreateObject("WbemScripting.SWbemNamedValueSet")
  91. ' context.Add
  92. set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
  93. if err <> 0 then
  94. scriptHelper.writeErrorToLog err, "Failed to connect to umi://" & computerName & "/LDAP"
  95. else
  96. scriptHelper.writeToLog "Successful binding to umi//" & computerName & "/LDAP", 2
  97. end if
  98. End Sub
  99. '****************************************************************
  100. '*
  101. '* TestClasses
  102. '* ===========
  103. '*
  104. '* Test of class manipulation.
  105. '*
  106. '****************************************************************
  107. Sub TestClasses ()
  108. on error resume next
  109. scriptHelper.writeToLog "", 2
  110. scriptHelper.writeToLog "**********************************", 2
  111. scriptHelper.writeToLog ">> Testing classes...", 2
  112. scriptHelper.writeToLog "**********************************", 2
  113. scriptHelper.writeToLog "", 2
  114. ' Bind to namespace using UMI path
  115. set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
  116. if err <> 0 then
  117. scriptHelper.writeErrorToLog err, "Failed to bind to umi://" & computerName & "/LDAP"
  118. else
  119. scriptHelper.writeToLog "Succesful binding to umi://" & computerName & "/LDAP", 2
  120. end if
  121. for each c in conn.SubclassesOf
  122. if err <> 0 then
  123. scriptHelper.writeErrorToLog err, "Failed to get class"
  124. else
  125. DisplayClass c
  126. DisplayInstances conn, c.Path_.Class
  127. end if
  128. next
  129. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate classes"
  130. End Sub
  131. '****************************************************************
  132. '*
  133. '* TestAttributes
  134. '* ==============
  135. '*
  136. '* Test of attribute manipulation.
  137. '*
  138. '****************************************************************
  139. Sub TestAttributes ()
  140. on error resume next
  141. scriptHelper.writeToLog "", 2
  142. scriptHelper.writeToLog "**********************************", 2
  143. scriptHelper.writeToLog ">> Testing attributes...", 2
  144. scriptHelper.writeToLog "**********************************", 2
  145. scriptHelper.writeToLog "", 2
  146. set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
  147. set ou = conn.Get(".OU=AjayTest")
  148. scriptHelper.writeToLog "Getting an org unit", 2
  149. if err <> 0 then
  150. scriptHelper.writeErrorToLog err, "Failed to get user"
  151. else
  152. scriptHelper.writeToLog "Succesfully retrieved ou", 2
  153. end if
  154. ' Attribute enumeration
  155. set props = ou.Properties_
  156. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
  157. DisplayProperties props
  158. ' Single attribute retrieval by name
  159. value = ou.whenChanged
  160. if err <> 0 then
  161. scriptHelper.writeErrorToLog err, "Failed to get ou.whenChanged"
  162. else
  163. scriptHelper.writeToLog "OU.whenChanged is <" & value & ">", 2
  164. end if
  165. ' System properties
  166. set props = ou.SystemProperties_
  167. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get system properties"
  168. DisplayProperties props
  169. ' Attribute modification
  170. ou.wwwHomePage = "http://www.microsoft.com"
  171. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to set ou.wwwHomePage"
  172. user.Put_
  173. if err <> 0 then
  174. scriptHelper.writeErrorToLog err, "Failed to put ou"
  175. else
  176. scriptHelper.writeToLog "OU put successfuly", 2
  177. end if
  178. ' Casting attributes to multivalues
  179. ' Object-valued attributes
  180. ' Multivalued attribute modification
  181. ' Refreshing the cache
  182. ou.Refresh_
  183. if err <> 0 then
  184. scriptHelper.writeErrorToLog err, "Failed to refresh ou"
  185. else
  186. scriptHelper.writeToLog "ou refreshed successfuly: " & ou.wwwHomePage, 2
  187. end if
  188. ' Refreshing specific items in the cache
  189. ou.wwwHomePage = "blah"
  190. user.Refresh_ Array("wwwHomePage")
  191. if err <> 0 then
  192. scriptHelper.writeErrorToLog err, "Failed to refresh specific ou properties"
  193. else
  194. scriptHelper.writeToLog "Specific ou properties refreshed successfuly: " & ou.wwwHomePage, 2
  195. end if
  196. ' Property Count
  197. count = ou.Properties_.Count
  198. if err <> 0 then
  199. scriptHelper.writeErrorToLog err, "Failed to count properties"
  200. else
  201. scriptHelper.writeToLog "Number of properties is: " & count, 2
  202. end if
  203. ' Schemaless attributes
  204. ' Parent traversal
  205. parent = ou.Path_.Parent
  206. if err <> 0 then
  207. scriptHelper.writeErrorToLog err, "Failed to get parent"
  208. else
  209. scriptHelper.writeToLog "Parent is : " & parent, 2
  210. end if
  211. set parentObject = GetObject(parent)
  212. if err <> 0 then
  213. scriptHelper.writeErrorToLog err, "Failed to open parent"
  214. else
  215. scriptHelper.writeToLog "Parent opened OK", 2
  216. end if
  217. End Sub
  218. '****************************************************************
  219. '*
  220. '* TestSearch
  221. '* ==========
  222. '*
  223. '* Test of queries
  224. '*
  225. '****************************************************************
  226. Sub TestSearch ()
  227. on error resume next
  228. scriptHelper.writeToLog "", 2
  229. scriptHelper.writeToLog "**********************************", 2
  230. scriptHelper.writeToLog ">> Testing Search...", 2
  231. scriptHelper.writeToLog "**********************************", 2
  232. scriptHelper.writeToLog "", 2
  233. 'Search preferences
  234. 'Search result traversal
  235. End Sub
  236. '****************************************************************
  237. '*
  238. '* TestSecurity
  239. '* ============
  240. '*
  241. '* Test of security
  242. '*
  243. '****************************************************************
  244. Sub TestSecurity ()
  245. on error resume next
  246. scriptHelper.writeToLog "", 2
  247. scriptHelper.writeToLog "**********************************", 2
  248. scriptHelper.writeToLog ">> Testing Security...", 2
  249. scriptHelper.writeToLog "**********************************", 2
  250. scriptHelper.writeToLog "", 2
  251. 'Get SD with flags
  252. 'Display ACLs and ACEs
  253. 'Change something
  254. 'Commit
  255. End Sub
  256. '****************************************************************
  257. '*
  258. '* TestExtensions
  259. '* ==============
  260. '*
  261. '* Test of extension interfaces
  262. '*
  263. '****************************************************************
  264. Sub TestExtensions ()
  265. on error resume next
  266. scriptHelper.writeToLog "", 2
  267. scriptHelper.writeToLog "**********************************", 2
  268. scriptHelper.writeToLog ">> Testing Extensions...", 2
  269. scriptHelper.writeToLog "**********************************", 2
  270. scriptHelper.writeToLog "", 2
  271. 'Late-bound property access
  272. End Sub
  273. '****************************************************************
  274. '*
  275. '* TestUsers
  276. '* =========
  277. '*
  278. '* Test of users
  279. '*
  280. '****************************************************************
  281. Sub TestUsers ()
  282. on error resume next
  283. scriptHelper.writeToLog "", 2
  284. scriptHelper.writeToLog "**********************************", 2
  285. scriptHelper.writeToLog ">> Testing Users...", 2
  286. scriptHelper.writeToLog "**********************************", 2
  287. scriptHelper.writeToLog "", 2
  288. 'Listing users on a computer
  289. 'Listing users in a domain
  290. 'Adding a user
  291. 'Setting a user password
  292. 'Setting user flags
  293. 'Moving a user
  294. 'Renaming a user
  295. 'Copying a user
  296. End Sub
  297. '****************************************************************
  298. '*
  299. '* TestGroups
  300. '* ==========
  301. '*
  302. '* Test of groups
  303. '*
  304. '****************************************************************
  305. Sub TestGroups ()
  306. on error resume next
  307. scriptHelper.writeToLog "", 2
  308. scriptHelper.writeToLog "**********************************", 2
  309. scriptHelper.writeToLog ">> Testing Groups...", 2
  310. scriptHelper.writeToLog "**********************************", 2
  311. scriptHelper.writeToLog "", 2
  312. 'Listing groups on a computer
  313. 'Listing groups in a domain
  314. 'Listing members of a group
  315. 'Adding a user to a group
  316. 'Removing a user from a group
  317. End Sub
  318. '****************************************************************
  319. '*
  320. '* TestComputers
  321. '* =============
  322. '*
  323. '* Test of computers
  324. '*
  325. '****************************************************************
  326. Sub TestComputers ()
  327. on error resume next
  328. scriptHelper.writeToLog "", 2
  329. scriptHelper.writeToLog "**********************************", 2
  330. scriptHelper.writeToLog ">> Testing Computers...", 2
  331. scriptHelper.writeToLog "**********************************", 2
  332. scriptHelper.writeToLog "", 2
  333. 'Listing computers in a domain
  334. 'Creating a computer account
  335. 'Deleting a computer account
  336. End Sub
  337. '****************************************************************
  338. '*
  339. '* StrFromCIMType
  340. '* ==============
  341. '*
  342. '* Utility function to return string form of CIM type
  343. '*
  344. '****************************************************************
  345. function StrFromCIMType (cimType)
  346. on error resume next
  347. StrFromCIMType = "?"
  348. Select Case cimType
  349. Case wbemCimtypeString StrFromCIMType = "String"
  350. Case wbemCimtypeIllegal StrFromCIMType = "Illegal"
  351. Case wbemCimtypeSint8 StrFromCIMType = "Sint8"
  352. Case wbemCimtypeUint8 StrFromCIMType = "Uint8"
  353. Case wbemCimtypeSint16 StrFromCIMType = "Sint16"
  354. Case wbemCimtypeUint16 StrFromCIMType = "Uint16"
  355. Case wbemCimtypeSint32 StrFromCIMType = "Sint32"
  356. Case wbemCimtypeUint32 StrFromCIMType = "Uint32"
  357. Case wbemCimtypeSint64 StrFromCIMType = "Sint64"
  358. Case wbemCimtypeUint64 StrFromCIMType = "Uint64"
  359. Case wbemCimtypeReal32 StrFromCIMType = "Real32"
  360. Case wbemCimtypeReal64 StrFromCIMType = "Real64"
  361. Case wbemCimtypeBoolean StrFromCIMType = "Boolean"
  362. Case wbemCimtypeDatetime StrFromCIMType = "Datetime"
  363. Case wbemCimtypeReference StrFromCIMType = "Reference"
  364. Case wbemCimtypeChar16 StrFromCIMType = "Char16"
  365. Case wbemCimtypeObject StrFromCIMType = "Object"
  366. Case wbemCimtypeIUnknown StrFromCIMType = "IUnknown"
  367. End Select
  368. end function
  369. Sub DisplayClass (c)
  370. on error resume next
  371. scriptHelper.writeToLog "", 2
  372. scriptHelper.writeToLog "***************************", 2
  373. className = c.Path_.Class
  374. if err <> 0 then
  375. scriptHelper.writeErrorToLog err, "Failed to get classname"
  376. else
  377. scriptHelper.writeToLog "Class:" & className, 2
  378. end if
  379. superclassName = c.Derivation_(0)
  380. if err <> 0 then
  381. scriptHelper.writeErrorToLog err, "Failed to get superclass"
  382. else
  383. scriptHelper.writeToLog "Superclass:" & superclassName, 2
  384. end if
  385. ' Properties
  386. set props = c.Properties_
  387. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
  388. DisplayProperties props
  389. scriptHelper.writeToLog "***************************", 2
  390. scriptHelper.writeToLog "", 2
  391. End Sub
  392. Sub DisplayInstance (i)
  393. on error resume next
  394. scriptHelper.writeToLog "", 2
  395. scriptHelper.writeToLog "***************************", 2
  396. path = i.SystemProperties_("__URL")
  397. if err <> 0 then
  398. scriptHelper.writeErrorToLog err, "Failed to get path"
  399. else
  400. scriptHelper.writeToLog "Path:" & className, 2
  401. end if
  402. nativepath = i.SystemProperties_("__PATH")
  403. if err <> 0 then
  404. scriptHelper.writeErrorToLog err, "Failed to get native path"
  405. else
  406. scriptHelper.writeToLog "Native Path:" & nativepath, 2
  407. end if
  408. ' Properties
  409. set props = i.Properties_
  410. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
  411. DisplayProperties props
  412. scriptHelper.writeToLog "***************************", 2
  413. scriptHelper.writeToLog "", 2
  414. End Sub
  415. Sub DisplayProperties (props)
  416. on error resume next
  417. for each p in props
  418. if err <> 0 then
  419. scriptHelper.writeErrorToLog err, "Failed to get property " & p.Name
  420. else
  421. value = "<NULL>"
  422. v = p.Value
  423. arrayStr = ""
  424. if p.IsArray then
  425. arrayStr = "[]"
  426. if Not(IsNull(v)) then
  427. value = "{"
  428. for i = LBound(v) to UBound(v)
  429. if IsObject(v(i)) OR (p.CIMType = wbemCimtypeIUnknown) then
  430. value = value & "<object>"
  431. else
  432. value = value & v(i)
  433. end if
  434. if i < UBound(v) then value = value & ","
  435. next
  436. value = value & "}"
  437. end if
  438. elseif Not(IsNull(v)) then
  439. if IsObject(v) OR (p.CIMType = wbemCimtypeIUnknown) then
  440. value = "<object>"
  441. else
  442. value = v
  443. end if
  444. end if
  445. scriptHelper.writeToLog " " & p.Name & "(" & StrFromCIMType(p.CIMType) & ")" _
  446. & arrayStr & ": " & value, 2
  447. end if
  448. err.clear
  449. next
  450. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate properties"
  451. End Sub
  452. '****************************************************************
  453. '*
  454. '* DisplayInstances
  455. '* ================
  456. '*
  457. '* Enumerate and display instances
  458. '*
  459. '****************************************************************
  460. Sub DisplayInstances (conn,className)
  461. on error resume next
  462. scriptHelper.writeToLog "", 2
  463. scriptHelper.writeToLog "**********************************", 2
  464. scriptHelper.writeToLog ">> Testing instances of " & className & "...", 2
  465. scriptHelper.writeToLog "**********************************", 2
  466. scriptHelper.writeToLog "", 2
  467. for each i in conn.InstancesOf (className)
  468. if err <> 0 then
  469. scriptHelper.writeErrorToLog err, "Failed to get instance"
  470. else
  471. DisplayInstance i
  472. end if
  473. next
  474. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate instances"
  475. End Sub
  476. </script>
  477. </job>