2.3 Authentication and Connection Tasks

To access all but the public available eDirectory information, applications must establish a connection and authenticate to eDirectory. This section provides instructions on accessing eDirectory information that is available from the connection, authenticating to eDirectory, retrieving the server address of the connection.

2.3.1 Accessing eDirectory Ping Information

  1. Allocate a request buffer of type Buf_T by calling NWDSAllocBuf.

  2. Call NWDSReadNDSInfo. Pass the requestedFields parameter an OR of DSPING flags for which information is needed (see Section 5.19, eDirectory Ping Flags).

  3. Call NWDSGetNDSInfo to retrieve information returned about any single field. Pass in the result buffer returned from NWDSReadNDSInfo for the resultBuffer parameter, a single flag for the requestedField parameter, and a pointer to memory of the appropriate size for the data parameter.

NOTE:For NWDSGetNDSInfo, fields can be called in any order, and the information can be retrieved so long as the buffer has not been reused or freed. A particular field can even be retrieved multiple times.

2.3.2 Authenticating to eDirectory

Most client workstations log in to the network when they are booted making it unnecessary for many client applications to perform this task. See Section 1.8, Authentication of Client Applications.

If you want your application to have full responsibility for accessing the network, or if you are writing an NLM that must access eDirectory or another NLM on a different server, you can control the authentication process by following these steps.

  1. Initialize an eDirectory context by calling NWDSCreateContextHandle.

  2. If needed, call NWDSSetContext to change context values.

    For information about changing your context, see Section 1.1, Context Handles and Modifying the Context of the Context Handle.

  3. Log in to eDirectory by calling NWDSLogin.

  4. Open a new connection by calling either NWDSOpenConnToNDSServer, NWCCOpenConnByName, or NWCCOpenConnByRef.

  5. Authenticate and license the new connection by calling NWDSAuthenticateConn.

NOTE:The process of authenticating to eDirectory is the same for client applications and NLMs. The only difference is that NLMs do not inherit the credentials of the computer they are running on.

Although an NLM has administrator rights to the local file system directory, it is not authenticated to eDirectory as “admin”; it is authenticated as “public”. If you want to do anything with eDirectory other than read public information, you must log in. The authentication credentials are stored on the thread group level and are accessible only by the OS.

2.3.3 Establishing Identities to Multiple eDirectory Trees—NLM Platform

NLMs establish identities to multiple eDirectory trees by manipulating the DCK_TREE_NAME key and by managing the current user in the thread group structure. NLMs must manage the current user associated with each thread group.

To establish identities to two eDirectory trees, follow these steps. They are separated into three procedures: logging in User 1 to Tree 1, logging in User 2 to Tree 2, and switching between users.

User 1 to Tree 1

To log in User 1 to Tree 1, follow these steps.

  1. Call NWDSSetCurrentUser with the userHandle parameter set to zero (0) to clear the user information in the thread group structure.

  2. Call NWDSCreateContextHandle.

  3. Call NWDSSetContext with DCK_TREE_NAME as the value for the key parameter and point the value parameter to the name of Tree 1.

    These instructions call this the context handle for User 1.

  4. Call NWDSLogin with the context handle for User 1, the eDirectory name for User 1, and User 1's password.

  5. Call NWDSGetCurrentUser and save the information to use for User 1 in Tree 1.

User 2 to Tree 2

To log in User 2 to Tree 2, follow these steps.

  1. Call NWDSSetCurrentUser with the userHandle parameter set to zero (0) to clear the user information in the thread group structure.

  2. Call NWDSCreateContextHandle.

  3. Call NWDSSetContext with DCK_TREE_NAME as the value for the key parameter and point the value parameter to the name of Tree 2.

    These instructions call this the context handle for User 2.

  4. Call NWDSLogin with the context handle for User 2, the eDirectory name for User 2, and User 2's password.

  5. Call NWDSGetCurrentUser and save the information to use for User 2 in Tree 2.

Switching Between Trees

With two users authenticated to two eDirectory trees, you can switch between them by following these steps.

  1. Call NWDSSetCurrentUser with the userHandle parameter set to the value for User 1.

  2. Use the context handle that you set up for User 1 in Tree 1 and call the eDirectory functions to perform work in Tree 1.

  3. To switch to User 2 in Tree 2, call NWDSSetCurrentUser with the userHandle parameter set to the value for User 2.

  4. Use the context handle that you set up for User 2 in Tree 2 and call the eDirectory functions to perform work in Tree 2.

2.3.4 Establishing Identities to Multiple eDirectory Trees—Client Platforms

Applications for Windows 95, Windows 98, and Windows NT establish identities to multiple eDirectory trees by manipulating the DCK_TREE_NAME key. To establish an identity to two eDirectory tree, follow these steps. They are divided into three tasks: logging User 1 in to Tree 1, logging User 2 in to Tree 2, and switching between users.

User 1 to Tree 1

To log User 1 in to Tree 1, follow these steps.

  1. Call NWDSCreateContextHandle to create a context handle.

  2. Call NWDSSetContext with DCK_TREE_NAME as the value for the key parameter and point the value parameter to Tree 1.

    These instructions call this the context handle for User 1.

  3. Call NWDSLogin with the context handle for User 1, the eDirectory name for User 1, and User 1's password.

User 2 to Tree 2

To log in User 2 to Tree 2, follow these steps.

  1. Call NWDSCreateContextHandle to create a context handle.

  2. Call NWDSSetContext with DCK_TREE_NAME as the value for the key parameter and point the value parameter to Tree 2.

    These instructions call this the context handle for User 2.

  3. Call NWDSLogin with the context handle for User 2, the eDirectory name for User 2, and User 2's password.

Switching between Trees

With two users authenticated to two eDirectory trees, you can switch between them by following these steps.

  1. To perform work on Tree 1, call eDirectory functions with the context handle for User 1.

  2. To perform work on Tree 2, call eDirectory functions with the context handle for User 2.

2.3.5 Retrieving Addresses of a Connected Server

To determine the network addresses for a server associated with a connection, follow these steps:

  1. Allocate a result buffer by calling NWDSAllocBuf. This buffer does not need to be initialized since it is a result buffer.

  2. Call NWDSGetServerAddresses2.

  3. Call NWDSComputeAttrValSize to find the size of the address data in the buffer.

  4. Allocate a contiguous block of memory the size of the attribute value, and set a void pointer to point to that block.

  5. Call NWDSGetAttrVal, passing in the pointer to the allocated memory.

  6. When NWDSGetAttrVal returns, typecast the pointer to be a pointer to Net_Address_T, and retrieve the information.

  7. Before retrieving the next address, free the allocated memory. (Addresses can be different sizes.)

  8. Loop to Step 3 until all addresses have been removed from the result buffer.

  9. Free the result buffer by calling NWDSFreeBuf.

When all addresses have been retrieved, free the result buffer pointer to netAddresses.

See Also: