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:
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:
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
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
- Option Explicit
- Const ADS_SECURE_AUTHENTICATION = &H1
- Public oDSObj As IADsOpenDSObject ' Hält die Verbindung
- Public oAuth As IADsContainer ' Hält die Anmeldung
- Public strServerName As String
- Public strUserADSPath As String
- Public Type tUserObject
- strBenutzername As String
- strPasswort As String
- strVorname As String
- strNachname As String
- strOU_Pfad As String
- End Type
- Public Function AuthenticateUser(ByVal strBenutzername As String, ByVal strPassword As String, ByVal strDomain As String) As Boolean
- 'Dim oDSObj As IADsOpenDSObject
- 'Dim oAuth As IADsContainer
- Dim oRootDSE As IADs
- Dim oUser As IADsUser
- Dim blnUserExists As Boolean
- Dim adoConnection As New ADODB.Connection
- Dim adoRecordset As New ADODB.Recordset
- 'Dim strServerName As String
- 'Dim strUserADSPath As String
- Dim strNamingContext As String
- Dim strQuery As String
- ' Initialisierung
- strUserADSPath = ""
- blnUserExists = False
- ' Fehlerbehandlung
- On Error GoTo ErrorHandel
- ' DNS Name des Servers ermitteln
- Set oRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
- strServerName = oRootDSE.Get("dnsHostName")
- strNamingContext = strServerName & "/" & oRootDSE.Get("defaultNamingContext")
- Set oRootDSE = Nothing
- ' Kompletter DSN Pfad des Benutzers ermitteln
- adoConnection.Open "Provider=ADsDSOObject"
- strQuery = "<LDAP://" & strNamingContext & ">;(sAMAccountName=" & strBenutzername & ");AdsPath, cn"
- With adoRecordset
- Set .ActiveConnection = adoConnection
- .CursorLocation = adUseClient
- .CursorType = adOpenStatic
- .LockType = adLockOptimistic
- .PageSize = 3 '<--- this is the value to change for how many records to return.
- .CacheSize = .PageSize
- .Open strQuery, , adOpenStatic, adLockReadOnly, adCmdText
- .Filter = adFilterFetchedRecords
- End With
- ' Prüfe ob der Benutzer überhaupt existiert
- If adoRecordset.RecordCount = 0 Then
- PrintDebug "User Name " & strBenutzername & " not exists in the directory."
- Else
- PrintDebug "User Name " & strBenutzername & " exists in the directory."
- strUserADSPath = adoRecordset.Fields("ADSPATH").Value
- PrintDebug "strUserADSPath = " & strUserADSPath
- blnUserExists = True
- End If
- adoRecordset.Close
- Set adoRecordset = Nothing
- adoConnection.Close
- Set adoConnection = Nothing
- ' Prüfen ob der Benutzer existiert
- If Not blnUserExists Then
- AuthenticateUser = False
- Exit Function
- End If
- ' Prüfen ob der Benutzer deaktiviert ist
- Set oUser = GetObject(strUserADSPath)
- PrintDebug "Account Disabled = " & oUser.AccountDisabled
- If oUser.AccountDisabled Then
- AuthenticateUser = False
- Exit Function
- End If
- ' Versuchen den Benutzer an der Domaine anzumelden
- Set oDSObj = GetObject("LDAP:")
- Set oAuth = oDSObj.OpenDSObject("LDAP://" & strNamingContext, strBenutzername, strPassword, ADS_SECURE_AUTHENTICATION)
- If Not oAuth Is Nothing Then
- PrintDebug "Authentication Success for User " & strBenutzername
- 'Set oAuth = Nothing
- Else
- PrintDebug "Authentication not Success for User " & strBenutzername
- End If
- AuthenticateUser = True
- Exit Function
- ErrorHandel:
- PrintDebug "Error->AuthenticateUser(): " & Err.Number & " - " & Err.Description
- End Function
- Public Function createUser(tUser As tUserObject, strDomain) As Boolean
- Dim ou As IADsContainer
- 'Dim ou As IADsOpenDSObject
- Dim usr As Object
- On Error GoTo ErrorHandel
- ' Öffne die OU
- 'Set ou = oDSObj.OpenDSObject("LDAP://" & strServerName & "/" & tUser.strOU_Pfad, "tcr", vbNullString, ADS_SECURE_AUTHENTICATION)
- 'Set ou = oDSObj.OpenDSObject("LDAP://" & strServerName & "/" & tUser.strOU_Pfad, vbNullString, vbNullString, ADS_SECURE_AUTHENTICATION)
- 'Set ou = oAuth.GetObject(organizationalUnit, tUser.strOU_Pfad)
- ' Erstelle den Benutzer in der geöffneten OU
- Set usr = ou.Create("user", "CN=" & CStr(tUser.strBenutzername))
- With usr
- .Put "sAMAccountName", CStr(tUser.strBenutzername)
- If IsNull(tUser.strNachname) = False Or Not tUser.strNachname = Empty Then
- .Put "sn", CStr(tUser.strNachname)
- End If
- If IsNull(tUser.strVorname) = False Or Not tUser.strVorname = Empty Then
- .Put "givenName", CStr(tUser.strVorname)
- End If
- .Put "displayName", CStr(tUser.strVorname & " " & tUser.strNachname)
- .Put "userPrincipalName", CStr(tUser.strBenutzername) & "@" & strDomain
- .SetInfo
- If IsNull(tUser.strPasswort) = False Or Not tUser.strPasswort = Empty Then
- .SetPassword tUser.strPasswort
- Else
- .SetPassword ""
- End If
- .AccountDisabled = False
- .SetInfo
- End With
- Exit Function
- ErrorHandel:
- PrintDebug "Beim erstellen des Benutzers (" & tUser.strBenutzername & ") ist ein Fehler aufgetreten!" & vbCrLf & "Fehler Nr." _
- & Err.Number & vbCrLf & "Beschreibung" & vbCrLf & Err.Description _
- & vbCrLf & vbCrLf
- 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“ ()