ADSI... Anmeldung cachen

  • VB6

    ADSI... Anmeldung cachen

    Hallo Forum,

    ich bastele gerade ein wenig mit ADSI rum und möchte folgendes erreichen:

    Benutzerobjekte erstellen/verändern/löschen, OU´s erstellen, uvm.

    Das momentane Problem ist, das ich die Verwendete Anmeldung nicht cashen kann.

    Meine vorgehensweise momentan:

    Code von modADSI:

    Quellcode

    1. Option Explicit
    2. Const ADS_SECURE_AUTHENTICATION = &H1
    3. Public oDSObj As IADsOpenDSObject ' Hält die Verbindung
    4. Public oAuth As IADsContainer ' Hält die Anmeldung
    5. Public strServerName As String
    6. Public strUserADSPath As String
    7. Public Type tUserObject
    8. strBenutzername As String
    9. strPasswort As String
    10. strVorname As String
    11. strNachname As String
    12. strOU_Pfad As String
    13. End Type
    14. Public Function AuthenticateUser(ByVal strBenutzername As String, ByVal strPassword As String, ByVal strDomain As String) As Boolean
    15. 'Dim oDSObj As IADsOpenDSObject
    16. 'Dim oAuth As IADsContainer
    17. Dim oRootDSE As IADs
    18. Dim oUser As IADsUser
    19. Dim blnUserExists As Boolean
    20. Dim adoConnection As New ADODB.Connection
    21. Dim adoRecordset As New ADODB.Recordset
    22. 'Dim strServerName As String
    23. 'Dim strUserADSPath As String
    24. Dim strNamingContext As String
    25. Dim strQuery As String
    26. ' Initialisierung
    27. strUserADSPath = ""
    28. blnUserExists = False
    29. ' Fehlerbehandlung
    30. On Error GoTo ErrorHandel
    31. ' DNS Name des Servers ermitteln
    32. Set oRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
    33. strServerName = oRootDSE.Get("dnsHostName")
    34. strNamingContext = strServerName & "/" & oRootDSE.Get("defaultNamingContext")
    35. Set oRootDSE = Nothing
    36. ' Kompletter DSN Pfad des Benutzers ermitteln
    37. adoConnection.Open "Provider=ADsDSOObject"
    38. strQuery = "<LDAP://" & strNamingContext & ">;(sAMAccountName=" & strBenutzername & ");AdsPath, cn"
    39. With adoRecordset
    40. Set .ActiveConnection = adoConnection
    41. .CursorLocation = adUseClient
    42. .CursorType = adOpenStatic
    43. .LockType = adLockOptimistic
    44. .PageSize = 3 '<--- this is the value to change for how many records to return.
    45. .CacheSize = .PageSize
    46. .Open strQuery, , adOpenStatic, adLockReadOnly, adCmdText
    47. .Filter = adFilterFetchedRecords
    48. End With
    49. ' Prüfe ob der Benutzer überhaupt existiert
    50. If adoRecordset.RecordCount = 0 Then
    51. PrintDebug "User Name " & strBenutzername & " not exists in the directory."
    52. Else
    53. PrintDebug "User Name " & strBenutzername & " exists in the directory."
    54. strUserADSPath = adoRecordset.Fields("ADSPATH").Value
    55. PrintDebug "strUserADSPath = " & strUserADSPath
    56. blnUserExists = True
    57. End If
    58. adoRecordset.Close
    59. Set adoRecordset = Nothing
    60. adoConnection.Close
    61. Set adoConnection = Nothing
    62. ' Prüfen ob der Benutzer existiert
    63. If Not blnUserExists Then
    64. AuthenticateUser = False
    65. Exit Function
    66. End If
    67. ' Prüfen ob der Benutzer deaktiviert ist
    68. Set oUser = GetObject(strUserADSPath)
    69. PrintDebug "Account Disabled = " & oUser.AccountDisabled
    70. If oUser.AccountDisabled Then
    71. AuthenticateUser = False
    72. Exit Function
    73. End If
    74. ' Versuchen den Benutzer an der Domaine anzumelden
    75. Set oDSObj = GetObject("LDAP:")
    76. Set oAuth = oDSObj.OpenDSObject("LDAP://" & strNamingContext, strBenutzername, strPassword, ADS_SECURE_AUTHENTICATION)
    77. If Not oAuth Is Nothing Then
    78. PrintDebug "Authentication Success for User " & strBenutzername
    79. 'Set oAuth = Nothing
    80. Else
    81. PrintDebug "Authentication not Success for User " & strBenutzername
    82. End If
    83. AuthenticateUser = True
    84. Exit Function
    85. ErrorHandel:
    86. PrintDebug "Error->AuthenticateUser(): " & Err.Number & " - " & Err.Description
    87. End Function
    88. Public Function createUser(tUser As tUserObject, strDomain) As Boolean
    89. Dim ou As IADsContainer
    90. 'Dim ou As IADsOpenDSObject
    91. Dim usr As Object
    92. On Error GoTo ErrorHandel
    93. ' Öffne die OU
    94. 'Set ou = oDSObj.OpenDSObject("LDAP://" & strServerName & "/" & tUser.strOU_Pfad, "tcr", vbNullString, ADS_SECURE_AUTHENTICATION)
    95. 'Set ou = oDSObj.OpenDSObject("LDAP://" & strServerName & "/" & tUser.strOU_Pfad, vbNullString, vbNullString, ADS_SECURE_AUTHENTICATION)
    96. 'Set ou = oAuth.GetObject(organizationalUnit, tUser.strOU_Pfad)
    97. ' Erstelle den Benutzer in der geöffneten OU
    98. Set usr = ou.Create("user", "CN=" & CStr(tUser.strBenutzername))
    99. With usr
    100. .Put "sAMAccountName", CStr(tUser.strBenutzername)
    101. If IsNull(tUser.strNachname) = False Or Not tUser.strNachname = Empty Then
    102. .Put "sn", CStr(tUser.strNachname)
    103. End If
    104. If IsNull(tUser.strVorname) = False Or Not tUser.strVorname = Empty Then
    105. .Put "givenName", CStr(tUser.strVorname)
    106. End If
    107. .Put "displayName", CStr(tUser.strVorname & " " & tUser.strNachname)
    108. .Put "userPrincipalName", CStr(tUser.strBenutzername) & "@" & strDomain
    109. .SetInfo
    110. If IsNull(tUser.strPasswort) = False Or Not tUser.strPasswort = Empty Then
    111. .SetPassword tUser.strPasswort
    112. Else
    113. .SetPassword ""
    114. End If
    115. .AccountDisabled = False
    116. .SetInfo
    117. End With
    118. Exit Function
    119. ErrorHandel:
    120. PrintDebug "Beim erstellen des Benutzers (" & tUser.strBenutzername & ") ist ein Fehler aufgetreten!" & vbCrLf & "Fehler Nr." _
    121. & Err.Number & vbCrLf & "Beschreibung" & vbCrLf & Err.Description _
    122. & vbCrLf & vbCrLf
    123. End Function


    Also mit der Funktion AuthenticateUser() verbinde ich mich mit der Domäne und versuche mich dort mit alternativen Zugangsdaten zu verbinden (da der PC nicht Mitglied der Domaine ist sollte das möglisch sein...)

    Die Variablen oDSObj und oAuth sollten die Verbindung und Authentifizierung halten.

    Nur Dummerweisse tun Sie das nicht...

    Laut MSDN sollte das aber möglich sein.
    msdn.microsoft.com/library/def…dsobject_opendsobject.asp

    Dort wird geschieben:

    Multiple bind operations can be performed by specifying the user name and password for the first bind operation and then specifying only the user name in subsequent binds.


    So habe ich es auch schon versucht, aber bekomme dann die anmeldung in createUser() abgeleht.

    Hat da jemand eine Idee?

    Gruß,
    Thomas

    EDIT: Hier ist es auch so beschrieben...
    eside.deusto.es/grupos/gedi/re…e/adsi25/if_core_3uic.htm

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „aLiEnTxC“ ()