Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Directory LDAP Query by sAMAccountName and Domain

How do you do a query of an LDAP store by sAMAccountName and Domain? What is the "domain" property named in Active Directory or LDAP terms?

This is what I have for the filter so far. I'd like to be able to add in the domain:

(&(objectCategory=Person)(sAMAccountName=BTYNDALL)) 
like image 463
BuddyJoe Avatar asked Feb 03 '09 17:02

BuddyJoe


People also ask

What is sAMAccountName in LDAP?

sAMAccountName is the ldap attribute that should match the login name. dn is the distinguished name returned by the LDAP server that matches sAMAccountName. jsmith is the login id of the user logging into Vertica.


1 Answers

First, modify your search filter to only look for users and not contacts:

(&(objectCategory=person)(objectClass=user)(sAMAccountName=BTYNDALL)) 

You can enumerate all of the domains of a forest by connecting to the configuration partition and enumerating all the entries in the partitions container. Sorry I don't have any C# code right now but here is some vbscript code I've used in the past:

Set objRootDSE = GetObject("LDAP://RootDSE") AdComm.Properties("Sort on") = "name" AdComm.CommandText = "<LDAP://cn=Partitions," & _     objRootDSE.Get("ConfigurationNamingContext") & ">;" & _         "(&(objectcategory=crossRef)(systemFlags=3));" & _             "name,nCName,dnsRoot;onelevel" set AdRs = AdComm.Execute 

From that you can retrieve the name and dnsRoot of each partition:

AdRs.MoveFirst With AdRs   While Not .EOF     dnsRoot = .Fields("dnsRoot")      Set objOption = Document.createElement("OPTION")     objOption.Text = dnsRoot(0)     objOption.Value = "LDAP://" & dnsRoot(0) & "/" & .Fields("nCName").Value     Domain.Add(objOption)     .MoveNext    Wend  End With 
like image 100
Dscoduc Avatar answered Oct 01 '22 08:10

Dscoduc