Previous in Contents Next in Contents

Listing the Basic Configuration of an LDAP Service Instance

In this example, the basic properties of an LDAP service instance are listed. In each example, the process is similar:

  1. Create an instance of the ldapcfg coclass and fetch a pointer to the Ildapcfg interface.

  2. Connect (or Attach) to a local or remote machine's LDAP service module using the AttachToXXXXXMachine() method. The ldapcfg coclass uses a special DCOM object behind the scenes to do the actual communication with other LDAP services on other machines through DCOM calls.

  3. Once connected, the configuration for a particular LDAP service instance is loaded and the properties are listed.

The configuration information essentially is read-only for accounts that are not members of the Microsoft® Windows NT® administrators group.

The example is shown in the following programming languages:

It should be noted that these examples would have to be modified to work in a given network environment.

C++

This example uses the COM support found in the Microsoft® Visual C++® 5.0 compiler. If you are unfamiliar with this set of features, you can get a quick overview in the programming language overview that is provided in this guide.

The primary method calls to the ldapcfg COM object are in bold type to make reading the example a bit easier.

This example demonstrates some of the functionality of the ldapcfg object, such as getting the server state and listing many of the configuration properties. The properties are listed in the same groupings as found in the LDAP properties in the Microsoft Management Console (MMC). This dialog box can be activated when the "properties" option is selected for the LDAP service under the Membership Server instance. It is sometimes useful to compare the output of this example to the values found under the MMC.

Although the code may appear quite long at first glance, it simply gets the server state for the specified LDAP service instance and then lists the configuration properties you would find in the MMC.

#include <iostream.h>
#import "d:\\Microsoft Site Server\\bin\\P&M\\ladmin2.dll" no_namespace

main()
{
   CoInitialize(NULL);
   IldapcfgPtr LDAP = new IldapcfgPtr(_uuidof(ldapcfg));

   ///////////////////////////////////////////////////////
   // That was the hard part.  We now have a pointer
   //  to the Ildapcfg interface.  
  //////////////////////////////////////////////////////////

   //  Local Machine ?
   //LDAP->AttachToLocalMachine();

   // Remote Machine ?
   _bstr_t bszRemoteHost = "Server1";
   _variant_t RemoteHost = new _variant_t(bszRemoteHost);
   try{
   LDAP->AttachToRemoteMachine(RemoteHost);
   }
   catch( _com_error er ) {
      cout << "Failed to attach to remote host:" << endl;
      cout << er.Description() << endl;
      exit(0);
   }


   //  Load the config information for the given 
   //  Instance ID 
   //  Variable:  Instance
   LONG Instance = 1;
   _variant_t Inst = new _variant_t((long)Instance,VT_I4);
   LDAP->LoadConfig(Inst);

/////////////////////////////////////////////////
//////  Get the Server State for this Instance
/////////////////////////////////////////////////

   _variant_t ServerState;

   try{ LDAP->GetServerState(Inst,&ServerState);}
   catch(_com_error er )
   {
      cout << "Error getting Server State" << endl;
      cout << er.Description() << endl;
      cout << "This is bad...exiting..." << endl;
      exit(0);
   }

   cout << "Server State is : " << _bstr_t(ServerState)  << endl;
   cout << endl;


//////////////////////////////////////////////////////////////
///////// print out the config here
//////////////////////////////////////////////////////////////
   
   cout << "General LDAP Config Info" << endl;

   cout << "Type:    "   << _bstr_t( LDAP->DBType      ) << endl;
   cout << "Source:  "   << _bstr_t( LDAP->DBSource   ) << endl;
   cout << "DB Name: "   << _bstr_t( LDAP->DBName      ) << endl;
   cout << "Username:"  << _bstr_t( LDAP->DBUsername ) << endl;
   cout << "Password:"  << _bstr_t( LDAP->DBPassword ) << endl;
   cout << endl;

   cout << "Network Config Info" << endl;

   try{cout << "Port:         " << _bstr_t(LDAP->Port      )
 <<endl;}catch(...){cout << endl;}
   try{cout << "SecurePort:   " << _bstr_t(LDAP->SecurePort)
 <<endl;}catch(...){cout << endl;}
   try{cout << "IP Addr:      " << _bstr_t(LDAP->IP        )
 <<endl;}catch(...){cout << endl;}
   try{cout << "Host DNS Name:" << _bstr_t(LDAP->DNSName   )
 <<endl;}catch(...){cout << endl;}
   try{cout << "SSL Enabled?  " << _bstr_t(LDAP->EnableSSL )
 <<endl;}catch(...){cout << endl;}


   try{cout << "ReadOnlyMode?     " << _bstr_t(LDAP->ReadOnlyMode     )
 <<endl;}catch(...){}
   try{cout << "MaxPageSize:      " << _bstr_t(LDAP->MaxPageSize      )
 <<endl;}catch(...){}
   try{cout << "MaxResultSet:     " << _bstr_t(LDAP->MaxResultSet     )
 <<endl;}catch(...){}
   try{cout << "MaxQueryTime:     " << _bstr_t(LDAP->MaxQueryTime     )
 <<endl;}catch(...){}
   try{cout << "MaxConnection:    " << _bstr_t(LDAP->MaxConnection    )
 <<endl;}catch(...){}
   try{cout << "ConnectionTimeout:" << _bstr_t(LDAP->ConnectionTimeout)
 <<endl;}catch(...){}
   try{cout << "Authorization:    " << _bstr_t(LDAP->Authorization    )
 <<endl;}catch(...){}
   try{cout << "Enable Replicate?:" << _bstr_t(LDAP->EnableReplicate  )
 <<endl;}catch(...){}
   try{cout << "Enable Log?:      " << _bstr_t(LDAP->EnableLog        )
 <<endl;}catch(...){}
   try{cout << "Enable Dynamic?:  " << _bstr_t(LDAP->EnableDynamic    )
 <<endl;}catch(...){}

   
   ////////////////////////////////
   //  Directory Properties Set
   ////////////////////////////////

   _variant_t Realm     = new _variant_t();
   _variant_t DnPrefix  = new _variant_t();
   _variant_t IsSQL     = new _variant_t();
   _variant_t ExtSec    = new _variant_t();
   _variant_t Partitions= new _variant_t();

   try {
   LDAP->GetDirectoryProperties (
                           Inst,
                           &Realm,
                           &DnPrefix,
                           &IsSQL,
                           &ExtSec,
                           &Partitions
                           );
   }
   catch( _com_error er ) 
   {
      cout << "Error calling GetDirectoryProperties:" << endl;
      cout << endl;
      exit(0);
   }

   cout << "Realm:    " << _bstr_t(Realm   ) << endl;
   cout << "DnPrefix: " << _bstr_t(DnPrefix) << endl;
   cout << "IsSQL?    " << _bstr_t(IsSQL   ) << endl;
   cout << "ExtSec?   " << _bstr_t(ExtSec  ) << endl;
   try{
      cout << "Partitions: " << _bstr_t(Partitions) << endl;
   }
   catch(_com_error e )
   {
      cout << "Error in Partitions parameter " << endl;
   }

   return 1;
}

VBScript

This example lists almost the same information that can be viewed using the Microsoft Management Console dialog box for LDAP properties. Under the MMC, the dialog box appears under Personalization & Membership -> LDAP. Right-click and select properties for the LDAP service instance. If you run this script, the same information is listed in the same groupings where possible.

The code may appear quite long at first glance, but really is nothing more than a "laundry list" of the LDAP service instance properties.

The example runs using the Windows Scripting Host. To execute this code, paste it into a file with the extension.vbs and run cscript.exe <name>.vbs.

Inst = 1  ‘ LDAP Service Instance # 1
call ldap.loadconfig(Inst)
call ShowLDAPProps(Inst, ldap)

‘  Here’s the subroutine that builds the dialog popup
Sub ShowLDAPProps( Inst, LDAPObj )
‘  we’ll use this to create a popup dialog
set wshshll = wscript.createobject("Wscript.Shell")

Str = "Hello.  Here's the data" & vbcrlf
Str = Str & "Instance ID: 1" & vbcrlf
Str = Str & "*** General Properties ***" & vbcrlf
Str = Str & "Server Name: " & LDAPObj.DNSName & vbcrlf
Str = Str & "IP Address: " & LDAPObj.IP & vbcrlf
Str = Str & "TCP Port: " & LDAPObj.Port & "  "
Str = Str & "SSL Port: " & LDAPObj.SecurePort & vbcrlf
Str = Str & "Connections------------------------" & vbcrlf
Str = Str & "Max Connections:    " & LDAPObj.MaxConnection & vbcrlf
Str = Str & "Connection Timeout: " & LDAPObj.ConnectionTimeout & vbcrlf
Str = Str & "Read-Only: " & LDAPObj.ReadOnlyMode & vbcrlf
Str = Str & "Searches---------------------------" & vbcrlf

Str = Str & "Limit Search to Initial Substring: "

If LDAPObj.EnableAllSub Then  ' flip logic...
 Str = Str & "False" & vbcrlf
Else
 Str = Str & "True" & vbcrlf
End If

Str = Str & "Max Query Size:  " & LDAPObj.MaxQueryTime & " millisec" & vbcrlf
Str = Str & "Max Page Size:   " & LDAPObj.MaxPageSize & " entries" & vbcrlf
Str = Str & "Max Result Set: "
if LDAPObj.MaxResultSet = 0 Then
  Str = Str & "(unlimited)" & vbcrlf
Else
  Str = Str & "Limited to : " & LDAPObj.MaxResultSet & " entries" &vbcrlf
End If 

Str = Str & "*** Root Database ***" & vbcrlf
If LDAPObj.DBType = 1 Then
 Str = Str & "SQL Server Database: " & vbcrlf
 Str = Str & "Computer Name: " & LDAPObj.DBSource & vbcrlf
 Str = Str & "Database Name: " & LDAPObj.DBName & vbcrlf
 Str = Str & "Username:      " & LDAPObj.DBUsername & vbcrlf
 Str = Str & "Password:      " & LDAPObj.DBPassword & vbcrlf
Else
 Str = Str & "Access Database --- " & vbcrlf
 Str = Str & "File Name: " & LDAPObj.DBSource & vbcrlf
End If


Str = Str & "*** Dynamic Directory ***" & vbcrlf
Str = Str & "Enable Dynamic Directory? " & LDAPObj.EnableDynamic & vbcrlf
If LDAPObj.EnableDynamic Then
  Str = Str & "Minimum Client Time to Live: " & LDAPObj.MinTTL & " seconds" & vbcrlf
  Str = Str & "Maximum Dynmaic entries: " & LDAPObj.MaxDynamObj & " entries " & vbcrlf
Else
  Str = Str & "-- disabled --" & vbcrlf
End If

Str = Str & "Enable NetMeeting 1.0 Support? " & LDAPObj.EnableRTPerson & vbcrlf
Str = Str & "Enable Dynamic data replication? " & LDAPObj.EnableReplicate & vbcrlf
If LDAPObj.EnableReplicate Then
 Str = Str & "fix later"
End If

Str = Str & "*** Directory Properties ***" & vbcrlf

call LDAPObj.GetDirectoryProperties(Inst,Realm,DnPrefix,IsSQL,SecExt,Partitions)

Str = Str & "Root distinguished name (DN) o=" & Realm & vbcrlf
Str = Str & "DN Prefix: " & DnPrefix & vbcrlf
If IsSQL Then
 Str = Str & "SecExt: " & SecExt & vbcrlf
 Str = Str & "Available Partitions: " & vbcrlf
 For Each i in Partitions
  Str = Str & i & vbcrlf
 Next
End If

Str = Str & "*** Membership Directory Security ***" & vbcrlf
Auth = LDAPObj.Authorization
Str = Str & "Password Authentication Method-------------" & vbcrlf
If Auth and 1 Then
 Str = Str & "Anonymous Access " & vbcrlf
End If
If Auth and 2 Then
 Str = Str & "Clear Text/Basic Auth" & vbcrlf
End If
If Auth and 4 Then
 Str = Str & "DPA Auth (Membership 1.0 compat) " & vbcrlf
End If
Str = Str & "--------------------------------------------" & vbcrlf
Str = Str & "Secure Communications-----------------------" & vbcrlf
Str = Str & "SSL Enabled?  " & LDAPObj.EnableSSL & vbcrlf
Str = Str & "128 bit keys? " & LDAPObj.EnableSSL128 & vbcrlf 

Str = Str & "*** Logging ***" & vbcrlf
Str = Str & "Enable Logging? " & LDAPObj.EnableLog & vbcrlf




Title = "--------------- LDAP Properties for LDAP Server “ & inst &” -----------------"

‘ This creates the popup here
wshshll.popup Str,0,Title,0
End Sub

Setting Up a Membership Authentication Service Instance

In the example below, a new Membership Authentication service instance is created.  The new instance will require  an LDAP service instance that has been properly configured.  The basic steps for setting up the LDAP service are given in the example Setting Up a New Directory Service.

This example uses the following COM classes:

The ObjCreator object is used to create the instances of the BrokServers and BrokConfig COM classes.  The properties for the new Membership Authentication Server instance are then set using the values presented in the LDAP example in the previoussection.

VBScript

set brok = objc.createobjauth("MemAdmin.BrokConfig.1")
set servers = objc.createobjauth("MemAdmin.BrokServers.1")

servers.init

id = 3
Port = 9000
SecurePort = 9001
DBUsername="sa"
DBPassword="sa"
ServerName = "Server1"
Database="db1"
DirectorySuperPass="password"

' create the Membership Auth Instance
servers.createserver id

'  call getconfig for this instance and set props
brok.getconfig id
brok.blocal = FALSE
brok.bszServerName = ServerName
brok.lPort = Port
brok.lSecurePort = SecurePort
brok.bszbaseDN = "Realm"
brok.bEnabled=1
brok.bszDSName = "o=" & Realm & "/ou=members/cn=administrator"
brok.bszDSPwd = DirectorySuperPass

wscript.echo "calling setconfig"
brok.setconfig

© 1997-2000 Microsoft Corporation. All rights reserved.