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

<!--
******************************************************************
'
' scrldap.wsf
'
' Purpose: test UMI LDAP functionality
'
' Parameters: none
'
' Returns: 0 - success
' 1 - failure
'
'*****************************************************************
-->
<job id="UMI LDAP Test">
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
<script language="VBScript">
on error resume next
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
scriptHelper.logFile = "c:\temp\umildap.txt"
scriptHelper.loggingLevel = 3
scriptHelper.testName = "UMI LDAP"
scriptHelper.testStart
dim locator
dim computerName
computerName = "nw01t1"
username = "nw01t1domnb\administrator"
password = "nw01t1domnb"
if WScript.arguments.Count > 0 then computerName = WScript.Arguments (0)
if WScript.arguments.Count > 1 then username = WScript.Arguments (1)
if WScript.arguments.Count > 2 then password = WScript.Arguments (2)
TestBindings
'TestClasses
TestAttributes
'TestSearch
'TestSecurity
'TestExtensions
'TestUsers
'TestGroups
'TestComputers
scriptHelper.testComplete
if scriptHelper.statusOK then
WScript.Echo "PASS"
WScript.Quit 0
else
WScript.Echo "FAIL"
WScript.Quit 1
end if
'****************************************************************
'*
'* TestBindings
'* ============
'*
'* Test of moniker-based binding to objects and explicit
'* locator connections with search preferences.
'*
'****************************************************************
Sub TestBindings ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing binding via monikers...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
' Bind to namespace using UMI path
set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to bind to umi://" & computerName & "/LDAP"
else
scriptHelper.writeToLog "Succesful binding to umi://" & computerName & "/LDAP", 2
end if
'Bind to single object using UMI path
'set user = GetObject("umi:///winnt/computer=" & computerName & "/user=guest")
'if err <> 0 then
' scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName & "/user=guest"
'else
' scriptHelper.writeToLog "Successful binding to umi:///winnt/computer=" & computerName & "/user=guest", 2
'end if
' Bind to single object using native path
'set user = GetObject("umiwinnt:///" & computerName & "/guest,User")
'if err <> 0 then
' scriptHelper.writeErrorToLog err, "Failed to bind to umiwinnt:///" & computerName & "/guest,User"
'else
' scriptHelper.writeToLog "Successful binding to umiwinnt:///" & computerName & "/guest,User", 2
'end if
' Bind using a umi server path
' Bind using a native server path
' Bind using connection properties
set locator = CreateObject("WbemScripting.SWbemLocatorEx")
' set context = CreateObject("WbemScripting.SWbemNamedValueSet")
' context.Add
set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to connect to umi://" & computerName & "/LDAP"
else
scriptHelper.writeToLog "Successful binding to umi//" & computerName & "/LDAP", 2
end if
End Sub
'****************************************************************
'*
'* TestClasses
'* ===========
'*
'* Test of class manipulation.
'*
'****************************************************************
Sub TestClasses ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing classes...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
' Bind to namespace using UMI path
set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to bind to umi://" & computerName & "/LDAP"
else
scriptHelper.writeToLog "Succesful binding to umi://" & computerName & "/LDAP", 2
end if
for each c in conn.SubclassesOf
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get class"
else
DisplayClass c
DisplayInstances conn, c.Path_.Class
end if
next
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate classes"
End Sub
'****************************************************************
'*
'* TestAttributes
'* ==============
'*
'* Test of attribute manipulation.
'*
'****************************************************************
Sub TestAttributes ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing attributes...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
set conn = locator.Open ("umi://" & computerName & "/LDAP",, username, password)
set ou = conn.Get(".OU=AjayTest")
scriptHelper.writeToLog "Getting an org unit", 2
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get user"
else
scriptHelper.writeToLog "Succesfully retrieved ou", 2
end if
' Attribute enumeration
set props = ou.Properties_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
DisplayProperties props
' Single attribute retrieval by name
value = ou.whenChanged
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get ou.whenChanged"
else
scriptHelper.writeToLog "OU.whenChanged is <" & value & ">", 2
end if
' System properties
set props = ou.SystemProperties_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get system properties"
DisplayProperties props
' Attribute modification
ou.wwwHomePage = "http://www.microsoft.com"
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to set ou.wwwHomePage"
user.Put_
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to put ou"
else
scriptHelper.writeToLog "OU put successfuly", 2
end if
' Casting attributes to multivalues
' Object-valued attributes
' Multivalued attribute modification
' Refreshing the cache
ou.Refresh_
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to refresh ou"
else
scriptHelper.writeToLog "ou refreshed successfuly: " & ou.wwwHomePage, 2
end if
' Refreshing specific items in the cache
ou.wwwHomePage = "blah"
user.Refresh_ Array("wwwHomePage")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to refresh specific ou properties"
else
scriptHelper.writeToLog "Specific ou properties refreshed successfuly: " & ou.wwwHomePage, 2
end if
' Property Count
count = ou.Properties_.Count
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to count properties"
else
scriptHelper.writeToLog "Number of properties is: " & count, 2
end if
' Schemaless attributes
' Parent traversal
parent = ou.Path_.Parent
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get parent"
else
scriptHelper.writeToLog "Parent is : " & parent, 2
end if
set parentObject = GetObject(parent)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to open parent"
else
scriptHelper.writeToLog "Parent opened OK", 2
end if
End Sub
'****************************************************************
'*
'* TestSearch
'* ==========
'*
'* Test of queries
'*
'****************************************************************
Sub TestSearch ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing Search...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
'Search preferences
'Search result traversal
End Sub
'****************************************************************
'*
'* TestSecurity
'* ============
'*
'* Test of security
'*
'****************************************************************
Sub TestSecurity ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing Security...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
'Get SD with flags
'Display ACLs and ACEs
'Change something
'Commit
End Sub
'****************************************************************
'*
'* TestExtensions
'* ==============
'*
'* Test of extension interfaces
'*
'****************************************************************
Sub TestExtensions ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing Extensions...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
'Late-bound property access
End Sub
'****************************************************************
'*
'* TestUsers
'* =========
'*
'* Test of users
'*
'****************************************************************
Sub TestUsers ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing Users...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
'Listing users on a computer
'Listing users in a domain
'Adding a user
'Setting a user password
'Setting user flags
'Moving a user
'Renaming a user
'Copying a user
End Sub
'****************************************************************
'*
'* TestGroups
'* ==========
'*
'* Test of groups
'*
'****************************************************************
Sub TestGroups ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing Groups...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
'Listing groups on a computer
'Listing groups in a domain
'Listing members of a group
'Adding a user to a group
'Removing a user from a group
End Sub
'****************************************************************
'*
'* TestComputers
'* =============
'*
'* Test of computers
'*
'****************************************************************
Sub TestComputers ()
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing Computers...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
'Listing computers in a domain
'Creating a computer account
'Deleting a computer account
End Sub
'****************************************************************
'*
'* StrFromCIMType
'* ==============
'*
'* Utility function to return string form of CIM type
'*
'****************************************************************
function StrFromCIMType (cimType)
on error resume next
StrFromCIMType = "?"
Select Case cimType
Case wbemCimtypeString StrFromCIMType = "String"
Case wbemCimtypeIllegal StrFromCIMType = "Illegal"
Case wbemCimtypeSint8 StrFromCIMType = "Sint8"
Case wbemCimtypeUint8 StrFromCIMType = "Uint8"
Case wbemCimtypeSint16 StrFromCIMType = "Sint16"
Case wbemCimtypeUint16 StrFromCIMType = "Uint16"
Case wbemCimtypeSint32 StrFromCIMType = "Sint32"
Case wbemCimtypeUint32 StrFromCIMType = "Uint32"
Case wbemCimtypeSint64 StrFromCIMType = "Sint64"
Case wbemCimtypeUint64 StrFromCIMType = "Uint64"
Case wbemCimtypeReal32 StrFromCIMType = "Real32"
Case wbemCimtypeReal64 StrFromCIMType = "Real64"
Case wbemCimtypeBoolean StrFromCIMType = "Boolean"
Case wbemCimtypeDatetime StrFromCIMType = "Datetime"
Case wbemCimtypeReference StrFromCIMType = "Reference"
Case wbemCimtypeChar16 StrFromCIMType = "Char16"
Case wbemCimtypeObject StrFromCIMType = "Object"
Case wbemCimtypeIUnknown StrFromCIMType = "IUnknown"
End Select
end function
Sub DisplayClass (c)
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "***************************", 2
className = c.Path_.Class
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get classname"
else
scriptHelper.writeToLog "Class:" & className, 2
end if
superclassName = c.Derivation_(0)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get superclass"
else
scriptHelper.writeToLog "Superclass:" & superclassName, 2
end if
' Properties
set props = c.Properties_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
DisplayProperties props
scriptHelper.writeToLog "***************************", 2
scriptHelper.writeToLog "", 2
End Sub
Sub DisplayInstance (i)
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "***************************", 2
path = i.SystemProperties_("__URL")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get path"
else
scriptHelper.writeToLog "Path:" & className, 2
end if
nativepath = i.SystemProperties_("__PATH")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get native path"
else
scriptHelper.writeToLog "Native Path:" & nativepath, 2
end if
' Properties
set props = i.Properties_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
DisplayProperties props
scriptHelper.writeToLog "***************************", 2
scriptHelper.writeToLog "", 2
End Sub
Sub DisplayProperties (props)
on error resume next
for each p in props
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get property " & p.Name
else
value = "<NULL>"
v = p.Value
arrayStr = ""
if p.IsArray then
arrayStr = "[]"
if Not(IsNull(v)) then
value = "{"
for i = LBound(v) to UBound(v)
if IsObject(v(i)) OR (p.CIMType = wbemCimtypeIUnknown) then
value = value & "<object>"
else
value = value & v(i)
end if
if i < UBound(v) then value = value & ","
next
value = value & "}"
end if
elseif Not(IsNull(v)) then
if IsObject(v) OR (p.CIMType = wbemCimtypeIUnknown) then
value = "<object>"
else
value = v
end if
end if
scriptHelper.writeToLog " " & p.Name & "(" & StrFromCIMType(p.CIMType) & ")" _
& arrayStr & ": " & value, 2
end if
err.clear
next
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate properties"
End Sub
'****************************************************************
'*
'* DisplayInstances
'* ================
'*
'* Enumerate and display instances
'*
'****************************************************************
Sub DisplayInstances (conn,className)
on error resume next
scriptHelper.writeToLog "", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog ">> Testing instances of " & className & "...", 2
scriptHelper.writeToLog "**********************************", 2
scriptHelper.writeToLog "", 2
for each i in conn.InstancesOf (className)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get instance"
else
DisplayInstance i
end if
next
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate instances"
End Sub
</script>
</job>