Get Netbios domain name from active directory

J

jerome pesenti

Greetings,

I am trying to accomplish a simple task but can't figure out if it's
possible in active directory.

A users log in into IIS and our application gets the NT login from the
web server:

MYDOMAIN\myuser
From this logon we would like to get the distinguished name of the
user, like:

cn=John User,dc=domain,dc=com

I know that it's possible to do in VBScript (through the NameTranslate
object) but our application tries to be portable and can only use LDAP
requests to the Active Directory.

It's possible to do a search for sAMAccountName=myuser but that may
return muliple users from different domains and there doesn't seem to
be any good way to match them back with the Netbios domain (MYDOMAIN)
with complete certainty given that it may not be related at all with
dc=domain,dc=com.

Thanks for your help!
Jerome
 
W

Wayne Tilton

Greetings,

I am trying to accomplish a simple task but can't figure out if it's
possible in active directory.

A users log in into IIS and our application gets the NT login from the
web server:

MYDOMAIN\myuser

user, like:

cn=John User,dc=domain,dc=com

I know that it's possible to do in VBScript (through the NameTranslate
object) but our application tries to be portable and can only use LDAP
requests to the Active Directory.

It's possible to do a search for sAMAccountName=myuser but that may
return muliple users from different domains and there doesn't seem to
be any good way to match them back with the Netbios domain (MYDOMAIN)
with complete certainty given that it may not be related at all with
dc=domain,dc=com.

Thanks for your help!
Jerome

Here's a little subroutine that will get the NetBIOS name of the current
user's AD domain (caution, it will wrap...):

' Returns the NetBIOS Domain Name of the users AD domain
Function NTDomain
Dim Partitions, Partition
Set Partitions = GetObject("LDAP://CN=Partitions,CN=Configuration," &
GetObject("LDAP://RootDSE").Get("DefaultNamingC
ontext"))
On Error Resume Next
For Each Partition In Partitions
NTDomain = Partition.Get("nETBIOSName")
If Err.Number = 0 then Exit For
Next
End Function


HTH,

Wayne Tilton
 
J

jerome pesenti

Wayne said:
Here's a little subroutine that will get the NetBIOS name of the current
user's AD domain (caution, it will wrap...):

' Returns the NetBIOS Domain Name of the users AD domain
Function NTDomain
Dim Partitions, Partition
Set Partitions = GetObject("LDAP://CN=Partitions,CN=Configuration," &
GetObject("LDAP://RootDSE").Get("DefaultNamingC
ontext"))
On Error Resume Next
For Each Partition In Partitions
NTDomain = Partition.Get("nETBIOSName")
If Err.Number = 0 then Exit For
Next
End Function


HTH,

Wayne Tilton

Thanks for the answer. I am actually not getting any nETBIOSname but
the name field seems to be what I want. Unfortunately, as you show it
in your code, there could be multiple partitions. In that case how
would I know which one corresponds to the user logon domain?

Jerome
 
W

Wayne Tilton

Thanks for the answer. I am actually not getting any nETBIOSname but
the name field seems to be what I want. Unfortunately, as you show it
in your code, there could be multiple partitions. In that case how
would I know which one corresponds to the user logon domain?

Jerome

Jerome,

I have managed to keep all of the forests I manage single domains, so I
can't emulate your situation, but based on what I've seen, you should be
able to do an LDAP search against the Partitions container in the
Configuration naming context for an object that has netBIOSname set. Using
Joe's great adfind.exe:

adfind -config -rb cn=partitions -f netbiosname=* netbiosname

should give you the netBIOSName of the logon users domain. If, due to
multiple domains, etc., that doesn't work, I would think you could
determine the search base by getting the users DN (via AdSystemInfo or NTO)
and build the path: CN=Partitions,CN=Configuration,DC=users,DC=domain.

Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top