IFPCNonWindowsUsers2::AddLdapUser method

Applies to: desktop apps only

The AddLdapUser method creates a new FPCNonWindowsUser object in the collection for an LDAP user and returns a reference to it.

Syntax

HRESULT AddLdapUser(
  [in]   BSTR Username,
  [in]   BSTR LdapServerUsername,
  [in]   BSTR LdapServerUserPassword,
  [in]   BSTR LdapServerSetName,
  [out]  IFPCNonWindowsUser **ppNonWindowsUser
);
FPCNonWindowsUsers.AddLdapUser( _
  ByVal Username As String, _
  ByVal LdapServerUsername As String, _
  ByVal LdapServerUserPassword As String, _
  ByVal LdapServerSetName As String, _
  ByRef ppNonWindowsUser As IFPCNonWindowsUser _
) As FPCNonWindowsUser

Parameters

  • Username [in]

    C++ Required. BSTR that specifies the user name of the new LDAP user.
    VB Required. String that specifies the user name of the new LDAP user.
  • LdapServerUsername [in]

    C++ Required. BSTR that specifies the user name that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
    VB Required. String that specifies the user name that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
  • LdapServerUserPassword [in]

    C++ Required. BSTR that specifies the password that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
    VB Required. String that specifies the password that will be presented for accessing an LDAP server in the LDAP server set specified in the LdapServerSetName parameter.
  • LdapServerSetName [in]

    C++ Required. BSTR that specifies the name of the LADP server set to be used for the new LDAP user.
    VB Required. String that specifies the name of the LADP server set to be used for the new LDAP user.
  • ppNonWindowsUser [out]
    Address of an interface pointer that on return points to the new IFPCNonWindowsUser interface created.

Return value

C++

This method can return one of the following:

  • S_OK, indicating that the operation succeeded.
  • An error code, indicating that the operation failed. In this case, the [out] parameter returned is a null object.

VB

This method returns a reference to an FPCNonWindowsUser object if successful. Otherwise, an error is raised that can be intercepted by using an error handler.

Remarks

If a user name is specified in the domain\user-name format in the Username parameter, the domain name will be ignored.

Examples

This VBScript script adds LDAP users to the users set specified on the command line using the user name and password provided on the command line to access an LDAP server in the LDAP server set specified on the command line. Note that the user name for accessing an LDAP server must be specified in the domain\user-name format.

Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_AccessDenied = &H80070005
Const Error_IncorrectParameter = &H80070057
Const Error_AlreadyExists = &H800700B7
Main(WScript.Arguments)
Sub Main(args)
    If(args.Count <> 4) Then
        Usage()
    End If
    AddLdapUsers args(0), args(1), args(2), args(3)
End Sub
Sub AddLdapUsers(userSetName, ldapServerSet, userName, password)
    ' Create the root object.
    Dim root  ' The FPCLib.FPC root object
    Set root = CreateObject("FPC.Root")
    'Declare the other objects needed.
    Dim isaArray     ' An FPCArray object
    Dim userSets     ' An FPCUserSets collection
    Dim userSet      ' An FPCUserSet object
    Dim nwUsers      ' An FPCNonWindowsUsers collection
    Dim input        ' A String
    ' Get references to the array object and the user sets collection.
    Set isaArray = root.GetContainingArray()
    Set userSets = isaArray.RuleElements.UserSets
    ' Get a reference to the user set specified by the user.
    On Error Resume Next
    Set userSet = userSets.Item(userSetName)
    If err.Number = Error_FileNotFound Then
        WScript.Echo "The user set " & userSetName & " does not exist. Aborting ..."
        WScript.Quit
    End If
    On Error GoTo 0
    ' Get a reference the collection of non-Windows users in the user set.
    Set nwUsers = userSet.NonWindowsUsers
    Do
        input = InputBox("Name of the LDAP user to add (or Quit to exit)", ,"Quit")
        If input = "Quit" Then
            Exit Do
        End If
        On Error Resume Next
        nwUsers.AddLdapUser input, userName, password, ldapServerSet
        If err.Number = Error_IncorrectParameter Then
            WScript.Echo "The LDAP server set specified does not exit, " _
                & "or the operation was canceled."
            Err.Clear
            WScript.Quit
        ElseIf err.Number = Error_AccessDenied Then
            WScript.Echo "Access to the LDAP server was denied."
            Err.Clear
            WScript.Quit
        ElseIf err.Number = Error_AlreadyExists Then
            WScript.Echo "The user " & input & " is already an LDAP user."
            Err.Clear
        ElseIf err.Number <> 0 Then
            WScript.Echo "An error occurred: 0x" & Hex(Err.Number) & " " & Err.Description
            Err.Clear
            WScript.Quit
        Else
            WScript.Echo "The user " & input & " was added as an LDAP user."
        End If
        On Error GoTo 0
    Loop
    ' Save changes.
    userSet.Save        
    WScript.Echo "Done!"
End Sub 
Sub Usage()
    WScript.Echo "Usage:" & VbCrLf _
        & "  " & WScript.ScriptName & " UserSet LdapServerSet UserName Password" & VbCrLf _
        & "" & VbCrLf _
        & "  UserSet - Name of the user set" & VbCrLf _
        & "  LdapServerSet - Name of the LDAP server set" & VbCrLf _
        & "  UserName - User name for accessing an LDAP server" & VbCrLf _
        & "  Password - Password for accessing an LDAP server" 
    WScript.Quit
End Sub

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 (64-bit only)

Version

Forefront Threat Management Gateway (TMG) 2010

IDL

Msfpccom.idl

DLL

Msfpccom.dll

See also

FPCNonWindowsUsers

 

 

Build date: 7/12/2010