Finding CN of users in Active Directory - active-directory

I'm trying to find the Base DN of the user that can access or controls all the users in Active Directory so I can put it in my LDAP.
Usually someone will give me this, and it looks like DC=domain,DC=company,DC=com
But the admin is not available, so I don't know how to find this in Active Directory.
I'm looking for a step by step to find this info. Which tree and tabs to open and how to construct it.
My user is: admin, the server is: controller-16.domain.company.com
But I don't know if they added OU or groups or something else
I know that this:
CN=admin,DC=domain,DC=company,DC=com
does not work. Nor does:
DC=domain,DC=company,DC=com
If the Base DN works on Gawor's LDAP Browser, then it will work for my LDAP.

You could try my Beavertail ADSI browser - it should show you the current AD tree, and from it, you should be able to figure out the path and all.
Or if you're on .NET 3.5, using the System.DirectoryServices.AccountManagement namespace, you could also do it programmatically:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
This would create a basic, default domain context and you should be able to peek at its properties and find a lot of stuff from it.
Or:
UserPrincipal myself = UserPrincipal.Current;
This will give you a UserPrincipal object for yourself, again, with a ton of properties to inspect. I'm not 100% sure what you're looking for - but you most likely will be able to find it on the context or the user principal somewhere!

Most common AD default design is to have a container, cn=users just after the root of the domain. Thus a DN might be:
cn=admin,cn=users,DC=domain,DC=company,DC=com
Also, you might have sufficient rights in an LDAP bind to connect anonymously, and query for (cn=admin). If so, you should get the full DN back in that query.

CN refers to class name, so put in your LDAP query CN=Users. Should work.

Related

user principal name issues and LDAP

So... this question is maybe not solely a programming question but I hope one of you can shed some light on my issue:
The base need we have in our software is to query the groups a user is associated too with
LDAP. For this task we actually use parts of LDAP Admin to query the user. Actually we want to query for the UserPrincipalName which at least to my knowledge is the most common way right?
So.. our problem is that the AD is setup such that the user has an UPN like foo#HUS
but the user actually is bound to the domain HUS.adomain.com (aka LDAP base: dc=HUS,dc=adomain,dc=com) and searching using an UPN like foo#HUS.adomain.com does not work - only foo#HUS works. So... the question is:
Is this common?
And is there a name/resource for that?
(sorry I'm quite new to that all...)
The goal would be to use as less parameters in the administration tool as possible
aka only the base (and form from the base the UPN username).
Update: I found at least one resource (in German) that states that this is possible but not recommended by Microsoft for Azure AD. (aka having a different mail address than UPN )
When you initiate a LDAP search using a UPN like foo#HUS.adomain.com it wont work because this value is not present in the userPrincipalName value. When you search for a user by building its UPN using all the domain suffix available in the forest, then you would not consider searching the userPrincipalName attribute.
It is very difficult to build every constructed attribute from base for querying because every Active directory environment would be different. As you have mentioned that you would like to build the attribute from base, it may work if this is the only AD infra that you are targeting. Every AD infra would have its own ways in which it will be setup.
However if you would want your tool to work in any AD environment you would have to consider some other parameters.
UPN is a editable attribute . An organization can set it up or can create a user without a UPN value. Below is example of user created programmatically by using old ADSI libraries. You can repro the same by removing any users userprincipalName attribute value and the user logon account name as shown in the pictures below.
UPN is an optional attribute and a user account can be present in AD without it as well. Coming back to your specific environment in this environment only foo#HUS works because "HUS" might be setup as a valid domain suffix within the Active directory. You can check this by opening the domain.msc console on any domain controller or a machine with Remote Server Administration Tools installed. You would find the UPN suffix as shown below . I changed it in my environment as shown below.
The value you will add will now show up in the . If you remove HUS from here for example any existing user who have user#HUS userPrincipalName populated will get removed because this is a optional constructed attribute in AD. And you will have to setup this for all the users in the environment . For example check below after I changed the username to dh # HUS .
The userprincipalName value also got populated with the same.
Hope this helps clarify your query and understand more on how to use the native Active directory tools to understand more while you develop your custom LDAP search functionality/tool.

Why can I see an AD container from ADExplorer and not from other browsers?

Ok, so I need a really Active Directory expert for this one.
I am encoutering a problem where I view different things from different LDAP Browsers.
I want to view the deleted objects container.
When I access Active Directory through ADExplorer I can see this container. When I access the same Active Directory, with the same user from JXplorer I cannot see the deleted objects container.
Also from Softera LDAP Browser happens the same as JXPlorer
Do you have any idea why this is happening?
Do you have maybe any other LDAP Browser you can reccomend?
Thanks
The ability to enumerate the deleted objects container in Active Directory will depend on the software in use (as you found out). To be able to view the deleted objects container (and any deleted objects in general), the software needs to use the LDAP control called LDAP_SERVER_SHOW_DELETED_OID. From the MSDN page:
LDAP_SERVER_SHOW_DELETED_OID control code
The LDAP_SERVER_SHOW_DELETED_OID control is used with an extended LDAP
search function to specify that the search results include any deleted
objects that match the search filter.
Unless the software lets you use a custom LDAP control when connecting to AD (or has builtin support for viewing deleted objects in AD), then it wont be able to see them at all.

Why is full name used for DN in Active Directory?

[Rewriting my question based on comments]
My DN in Active Directory is "CN=Jesse Barnum,cn=users,dc=360works,dc=com".
I'm writing a web application which attempts to bind to the LDAP server, using the username and password of the active user. When doing the bind, I use the format "CN=$loginName$,cn=users,dc=360works,dc=com". Therefore, my users need to type in their full name (ie. 'Jesse Barnum'), rather than their shorter UID ('jbarnum').
Since users logging in typically expect to type a short name (like 'jbarnum', rather than 'Jesse Barnum'), I'd like for my DN to use my short name, like this: "CN=jbarnum,cn=users,dc=360works,dc=com". Doesn't it seem like that should be the default behavior (Windows Server 2012)?
So my question is: Can I change how the DN is constructed in Active Directory to use the short name instead of the full name?
You can change that behaviour but why should you? As you want to create a login there are much more elegant and more flexible solutions available.
When creating an LDAP based login I'm always doing the following:
bind to the server with a special account that can search the LDAP. Often that can also be done with a so called "anonymous bind".
search the LDAP for the given username in any attribute you like. A filter of (|(uid=username)(mail=username)(cn=username)) would allow your user to either use the uid, mail or cn to log in.
get the dn from the retrieved result and use that DN whic should be the DN of the users record) for a second bind - this time with the provided Password
That way the DN is completely irrellevant for your login as i is retrieved using the provided information based on attributes.
For an example in PHP have a look at https://gist.github.com/heiglandreas/5689592
The CN can be based on anything, really. It comes down to how you provision your users in the directory. If you use the out-of-box AD Users and Computers or AD Administrative Center tools to create users, they default to the full name format. You can change the CN after the fact, or if you are using something programmatic to create users, then you can create them however you like initially.

Creating custom user attribute on LDAP (LDS)

I am running a webapp that connects to LDAP (LDS). In the app, I need to check on the user class the value for the attribute userAccountControl.
In my installation my user class does not have such attribute, even though I imported the MS-User*.ldf files when creating my instance.
So, I need to create this attribute in the user class. I am using ADSI Edit to connect to my LDS instance, but it does not provide any facility to create new attributes. What should I do?
It's a two stage process, however you do it. First, you need to create the userAccountControl attribute. Then you need to add the name userAccountControl to the mayContain attribute on the user class.
You can create the userAccountControl attribute using LDIFDE or ADAM Schema Manager. ADAM Schema Manager gives you a GUI to do this work but has limited options. LDIFDE is a program you run against a text file. The nice thing about this is that you could run LDIFDE against your AD DS installation to export the userAccountControl attribute attributes [yes, I did mean to type it like that]. You can then remove the ones you don't need (e.g. the ones marked as systemOnly in the schema, for a start) and then import the modified file to your AD LDS instance. I can provide more info if it would help.

LDAP Active Directory path

I am trying to add a user to Active Directory through an MPS Web Service. I've been trying a long time to find the correct LDAP-url to use to tell it to add the new user to the Users group. I've tried things like:
LDAP://XXXX.YYY/OU=Users,DC=XXXX,DC=YYY
LDAP://XXXX.YYY/CN=Users,DC=XXXX,DC=YYY
LDAP://XXXX.YYY/DN=Users,DC=XXXX,DC=YYY
It seems the "farthest" I've gotten is an error that says I have given it an invalid Customer.
I really don't have a lot of experience with LDAP (pretty much none at all), so even just a good LDAP and Active Directory tutorial would be extremely useful (even that is eluding me right now). Thanks!
I've since lookup up the actual distinguished name in ADSI Edit, which was LDAP://XXXX.YYY/CN=Users,DC=XXXX,DC=YYY, but still have no luck.
You have error in your LDAP string.
Let's have examle:
user with account name User1 in organization unit Office1 where contoso.com is domain.
Object:
contoso.com/Users/Office1/User1
LDAP Path is:
LDAP://CN=User1,OU=Office1,OU=Users,DC=contoso,DC=com
Note that there is no slash in path itself
CN = Common Name
OU = Organizational Unit
DC = Domain Component
You can start with:
LDAP Query Basics
Creating a list of Users and their e-mail addresses in Exchange 2000
How Can I Get a List of All the Users Whose Passwords Never Expire?
if your domain is xxxx.yyyy.zzzz and you are search for all users; your path is:
LDAP://CN=Users,DC=xxxx,DC=yyyy,DC=zzzz
means every dot in domain replace with dc=
More directly, the default Users container (not a group) in a default Active Directory install would be CN=Users,dc=domain,dc=com
You are not clear if you are having trouble adding a user to a group, or if you are having trouble creating a user in a specific location.

Resources