4.2 NWDir Object

This is the top level of the NWDir UCX Component. This Directory component can enumerate all objects under a context in a given tree. A sub object of this component represents an NDS object. It does the following:

4.2.1 Object Diagram

Describes the hierarchy of various objects in NWDir object

4.2.2 FullName property

Provides/sets the full name of the context.

Syntax

object.FullName

Type

String.

Attributes

Read-write.

Remarks

By default refers to the tree and context for the server on which the script is running. The FullName syntax is

"NDS:\\ACME-Tree\TopContext\SubContext"

Example

This example lists all the objects under the given context.

On Error Resume Next
Set nwdir = CreateObject("UCX:NWDIR")
’Enter the NDS context of the server
nwdir.FullName = "NDS\\ACMECorporation\Sales\New York"
’Enter your login name and password
If (NOT nwdir.login ("Test User", "Test Password")) Then
          Print "Login Failure"
Else
    Print "Login Success"
    Print "Current FullName: " &nwdir.FullName
    Print "Current ShortName: " &nwdir.ShortName
    Print "Current User: " &nwdir.LoginName
    Print "Current Entry Object: " &nwdir.Entry.ShortName
    Print "objects under current context are"
      For each entry in nwdir.Entries
        Print entry.ShortName
      Next
Endif
’Logout
nwdir.Logout() 

4.2.3 ShortName property

Gives the short name of the current context.

Syntax

object.ShortName

Type

String.

Attributes

Read-only.

Remarks

The short name is commonly used where you want to see only the name of the object relative to its parent, instead of its full name.

Example

This example gives the short name of the current context.

Set dirObj = CreateObject("UCX:NWDIR")
’Enter your username and password
dirObj.Login("user", "password")
Print "Current ShortName: " &dirobj.ShortName 

4.2.4 PrefServer property

Provides/sets the preferred Novell eDirectory server to which the component establishes the connection.

Syntax

object.PrefServer

Type

Read-Write.

Attributes

String.

Remarks

If this value is not set, the component connects to the nearest server in the tree. By default, the value is set to "".

Example

This example uses the preferred server to connect to eDirectory and lists all the objects.

Sub Test_PrefServer
    set nwdir=createobject("UCX:NWDIR")
    nwdir.fullname="NDS:\\treename\context"
    nwdir.prefserver="164.99.150.91"
    For Each entry In nwdir.entries
        Print entry.shortname
    Next
End Sub

4.2.5 LoginName property

text goes here

Syntax

object.LoginName

Type

Read-only.

Attributes

String.

Remarks

By default the value is NULL string.

Example

This example returns the name of the user logged into NDS.

Set dirObj = CreateObject ("UCX:NWDIR")
’Enter the NDS context of the server
dirObj.FullName = "NDS\\ACMECorporation\Sales\New York"
’Enter the username and password
dirObj.Login("user", "password")
Print "Current User: " &dirObj.LoginName

4.2.6 Entries property

Returns the collection of entries at the context specified by FullName property.

Syntax

object.Entries

Type

NWEntries.

Attributes

Read-only.

Example

This example lists all the objects under the given context.

Set nwdir = CreateObject("UCX:NWDIR")
’enter the nds context of the server
nwdir.FullName = "NDS\\ACMECorporation\Sales\New York"
’enter the username and password
If (NOT nwdir.Login("Test User", "Test Password")) Then
          Print "Login Failure"
Else
    Print "Login Success"
    Print "Current FullName: " &nwdir.FullName
    Print "Current ShortName: " &nwdir.ShortName
    Print "Current User: " &nwdir.LoginName
    Print "Current Entry Object: " &nwdir.Entry.ShortName
    ’Print the name of all the objects under this context
    ’Print objects under current context are: "
    For each entry in nwdir.Entries
        Print entry.ShortName
    Next
Endif
’Logout
nwdir.Logout()          

4.2.7 Entry property

Returns the entry object representing the FullName.

Syntax

object.Entry

Type

NWEntry.

Attributes

Read-only.

Remarks

This property is typically used to get and set field values on the entry at the root of the subtree indicated by the FullName property of the NWDir Object.This property can also be used as a convenience to point to an entry in the tree.

Example

This example lists all the objects under the given context.

Set nwdir = CreateObject("UCX:NWDIR")
’enter the NDS context of the server
nwdir.FullName = "NDS:\\ACMECorporation\Sales\New York"
’enter the username and password
If (NOT nwdir.Login ("Test User", "Test Password")) Then
          Print "Login Failure"
Else
    Print "Login Success"
    Print "Current FullName: " &nwdir.FullName
    Print "Current ShortName: " &nwdir.ShortName
    Print "Current User: " &nwdir.LoginName
    Print "Current Entry Object: " &nwdir.Entry.ShortName
    ’print the name of all the objects under this context
    For each entry in nwdir.Entries
        Print entry.ShortName
    Next
Endif
’Logout
nwdir.Logout()

4.2.8 Layouts property

Returns the collection of layouts of NDS.

Syntax

object.Layouts

Type

NWLayoutDescriptions.

Attributes

Read-only.

Example

This example lists all the NDS layouts.

Set dirObj = CreateObject("UCX:NWDIR")
’enter the username and password
dirObj.Login("user","password")
For each layout in nwdir.Layouts
    Print layout.Name
Next

4.2.9 FieldTypes property

Returns a collection of all the field types (NDS Syntax) of the specified NDS tree.

Syntax

object.FieldTypes

Type

NWFieldTypes.

Attributes

Read-only.

Example

This example lists the details of each NDS field type.

Set dirObj = CreateObject("UCX:NWDIR")
’enter the username and password
dirObj.Login("user", "password")
For each FieldType in dirobj.FieldTypes
    Print FieldType.Name
    Print FieldType.SyntaxName
    Print FieldType.Type
    Print FieldType.Removable
    Print FieldType.SingleValued
    Print FieldType.SyntaxType
Next
 

4.2.10 Filter property

Returns filter object.

Syntax

object.Filter

Type

NWFilter.

Attributes

Read-only.

Remarks

This property returns an empty search filter object. The search conditions have to be added using the properties and methods of NWFilter.After that, this object has to be passed as a parameter to the search method.

See Also Section A.13, Filter/Search Scope Constants and Section A.23, Operator Constants.

Example

This example sets the filter for a search on an NDS object.

Set dirObj = CreateObject("UCX:NWDIR")
’enter the username and password
dirObj.Login("user","password")
Set Filter1 = dirobj.Filter
Filter1.addexpression FTOK_APPROX, "CN", "User3"
Filter1.addexpression FTOK_END
Print "Filter Expression" & Filter1.Value
Set Entries = dirobj.Search(Filter1)
For each Entry in dirobj.Entries
    Print Entry.FullName
Next

4.2.11 Login method

Logs in to the specified User account in NDS.

Syntax

object.Login(
  UserName As String,
  [Password As String])

Parameters

UserName

The login name.

Password

The password for the specified username.

Return Values

Boolean.

Remarks

Returns TRUE if login is successful, otherwise returns FALSE and throws exception.

If NWDir component is instantiated inside a Web script or a NSP page, then the component detects the user and performs automatic authentication.

In case the account has expired and the user has grace logins then this method logs into NDS using grace logins and returns TRUE and also sets the Err.Number (-223).

Example

This example gives the default tree and context, performs a login and logs the user out of NDS.

Set dirObj = CreateObject("UCX:NWDIR")
’Enter the NDS context of the server
dirObj.FullName =  "NDS:\\Acmecorporation\sales\Newyork"
Print "Current FullName: "&dirObj.FullName
’Log in to the server
Status = dirObj.Login("Username","password")
Print "The Login status is" &Status
’Logout
dirObj.Logout()

4.2.12 Logout method

Logs out from NDS.

Syntax

object.Logout()

Parameters

None.

Return Values

Boolean. Returns TRUE, if successful else returns FALSE.

Example

This example gives the default tree and context, performs a login and logs the user out of NDS.

Set dirObj = CreateObject("UCX:NWDIR")
’Enter the NDS context of the server
dirObj.FullName =  "NDS:\\Acmecorporation\sales\Newyork"
Print "Current FullName: "&dirObj.FullName
Status = dirObj.Login("Username","password")
Print "The Login status is" &Status
dirObj.Logout()

4.2.13 Search method

Searches the directory services using the search filter.

Syntax

object.Search(
  Filter As NWFilter)

Parameters

NWFilter

The filter set for the search.

Return Values

NWEntries.

Remarks

Return value is a collection of NWEntry objects. See also Section A.13, Filter/Search Scope Constants and Section A.23, Operator Constants.

Example

The following example illustrates how to search NDS using the Search filter.

’List all the users starting with the word User3
 Set nwdir = CreateObject("UCX:NWDIR")
 nwdir.Login ("User", "Password")
 Set Filter1 = nwdir.Filter
’Search entire subtree and dereference the alias objects
 Filter1.Scope = SEARCH_SUBTREE
 Filter1.DerefAlias = FALSE
 Filter1.AddExpression FTOK_APPROX, "CN", "User3"
 Filter1.AddExpression FTOK_END
 Print "Filter Expression " & Filter1.Value
 Print "Default Search Context: " &Filter1.SearchContext
 Set Entries = nwdir.Search(Filter1)
 For each entry in Entries
   Print Entry.FullName
 Next

4.2.14 FindEntry method

Returns an entry object corresponding to the given full name.

Syntax

object.FindEntry(
  FullName As String)

Parameters

FullName

Full name of the Object to be searched.

Return Values

NWEntry.

Remarks

If there is no entry corresponding to the given full name, then returns NULL and throws an exception.

Example

This example creates a new entry, tests for that Entry Object and deletes it.

Set nwdir=CreateObject("UCX:NWDIR")
’Enter the username and the password
nwdir.Login ("username", "password")
Set entries = nwdir.Entries
Print "Total number of entries: "&Entries.Count
Entries.Reset()
while Entries.HasMoreElements()
    Set Entry = Entries.Next()
    Print Entry.ShortName
Wend
’Create a new User object
Set newEntry=Entries.Add("TestUser","User")
’Set the mandatory fields and create the entry
newEntry.SetFieldValue "Surname", "Test Surname"
newEntry.Update()
’Confirm the creation of test user
Entries.Reset()
Set TestUser=Entries.Element ("TestUser")
Print " The new user is"&TestUser.FullName
’Finds the entry and displays the related information
’Enter the fullname of the entry
Set Entry=Nwdir.FindEntry("Nds:\\Acmecorporation\Testuser")
’Get the partition in which this entry reside
Set partition = Entry.GetPartitionRoot()
Print " The partition is" &partition.Shortname
’Set the objects's password
Entry.SetPassword ("password")
’Verify the new password
If (Entry.VerifyPassword("password")) Then 
   Print "Password Verification Success"
Else
    Print "Password Verification Failed"
End If
’Delete the test user
Status = Entries.RemoveElement("TestUser")
Print "The deletion status is" &Status

4.2.15 GetRights method

Returns the summary of the subject's rights with respect to the object, ObjectName or an attribute of an object.

Syntax

object.GetRights(
  SubjectName As String,
  ObjectName As String,
  AttrName As String)

Parameters

SubjectName

Name of the Subject.

ObjectName

Name of the Object.

AttrName

The attribute name.

Return Values

String.

Remarks

The return value is in the form, [ff..]. The return string contains characters where each character represents a particular right. These characters appear in the order mentioned below. If the object doesn't have a particular right, then a blank will appear in that position.

Following are the possible values and their meanings:

If attrname passed to the method is "[Entry Rights]", then return values are as follows:

B-DS_ENTRY_BROWSE
A-DS_ENTRY_ADD
D-DS_ENTRY_DELETE
R-DS_ENTRY_RENAME
S-DS_ENTRY_SUPERVISOR

Example: [BA RS]

If attrname passed to the method is "[SMS Rights]" then return values are these:

S-DS_SMS_SCAN
B-DS_SMS_BACKUP
R-DS_SMS_RESTORE
C-DS_SMS_RENAME
D-DS_SMS_DELETE
A-DS_SMS_ADMIN 

Example: [S R DA]

For other attributes, the following values are returned:

C-DS_ATTR_COMPARE
R-DS_ATTR_READ
W-DS_TTR_WRITE
A-DS_ATTR_SELF
S-DS_ATTTR_SUPERVISOR

Example: [CR AS]

Example

This example shows how to get the rights User on the Testuser.

Set nwdir=CreateObject("UCX:NWDIR")
’enter the username and password
nwdir.Login ("User","password")
’Get the rights of User on test user
’Enter the Full name of the User and the  test user
rights=nwdir.GetRights ("NDS:\\ACMEcorporation\Sales\User",
"NDS:\\ACMEcorporation\Sales\TestUser","[Entry Rights]")
Print "User's right on TestUser: "&rights

4.2.16 AddSecurity method

Adds the SecFrom object to the security equivalence list of SecTo.

Syntax

object.AddSecurity(
  SecTo As String,
  SecFrom As String)

Parameters

SecTo

The destination object whose security equivalence list is added to.

SecFrom

The source object.

Return Values

Boolean.

Example

This example shows how to add TestUser1 into the security equivalence list of TestUser.

Set nwdir=CreateObject("UCX:NWDIR")
’Enter the username and password
nwdir.Login ("User", "password")
’Adds test user1 to security equivalence of test user
’Enter the full name of the source and the destination entries
If(nwdir.AddSecurity("NDS:\\Acmecorporation\Sales\TestUser1"
 "NDS:\\Acmecorporation\Sales\TestUser")) Then
    Print "TestUser1 has the security equivalence to TestUser"
Else 
    Print "Failed to add TestUser1 into the security
           equivalence list of TestUser"
End If    

4.2.17 RemoveSecurity method

Removes the security equivalence from SecTo object.

Syntax

object.RemoveSecurity(
  SecTo As String, SecFrom As String)

Parameters

SecTo

The destination object whose security equivalence list is added to.

SecFrom

The source object.

Return Values

Boolean.

Example

This example shows how to remove TestUser1 from the security equivalence list of Testuser.

Set nwdir=CreateObject("UCX:NWDIR")
’Enter the user name and password
nwdir.Login ("User", "password")
’Removes test user1 from security equivalence of test user
’Enter the full name of the source and the destination entries
If (nwdir.RemoveSecurity
("NDS:\\Acmecorporation\Sales\TestUser1","NDS:\\Acmecorporat
ion\Sales\\TestUser")) Then
 Print "TestUser1 is removed"
Else
 Print "Failed to remove TestUser1 from the security
 equivalence of TestUser"
End If

4.2.18 MoveEntry method

Changes the object's position in the tree.

Syntax

object.MoveEntry(
  OldFullName As String,
  NewFullName As String)

Parameters

OldFullName

The old full name of the object.

NewFullName

The new full name of the object.

Return Values

Boolean.

Example

This example shows how to move an entry, TestUser1 to another context.

Set nwdir=CreateObject("UCX:NWDIR")
’Enter the username and password
nwdir.Login ("User","password")
’Enter the full name of source and the destination
res=nwdir.MoveEntry ("NDS:\\ACMECorporation\Sales\TestUser1", "NDS:\\ACMECorporation\Sales\NewYork\TestUser1")
If (res) Then
    Print "Testuser1 is successfully moved"
Else
    Print "Failed to move TestUser1"
End If