LDAP Active Directory path - active-directory

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.

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.

Is domain component in Active Directory the same with the domain my account is in?

My account is in the hc domain. When I log into my computer, I will enter hc\xxx in the account name textbox. So I think my domain name is hc.
But when I try to explore the domain server, there is a lot of information that confuses me.
In the root of the node tree in the picture, I see it is hc.cn. What is this? Is it the domain name? If so, why do I use hc\xxx to log into my computer, not hc.cn\xxx? And also near the hc.cn, I see the [xxx.xxx.xxx], is it the domain controller that Active Directory explorer is connecting to?
In the second line, I see DC=hc, DC=cn. I am not very clear with domain component concepts. Does that mean cn is a big domain and hc is a sub domain of it? Here in DC=hc, is the hc the same with hc\xxx's hc?
My account is in the hc domain. When I log into my computer, I will
enter hc\xxx in the account name textbox. So I think my domain name is
hc.
No, hc is the NetBIOS name of your domain. It is required for name resolution, and a bit older thing.
In the root of the node tree in the picture, I see it is hc.cn. What
is this? Is it the domain name?
Yes. Based on your screenshot, hc.cn appears to be the domain name.
If so, why do I use hc\xxx to log into my computer, not hc.cn\xxx?
This is called pre-Windows 2000 logon name.
And also near the hc.cn, I see the [xxx.xxx.xxx], is it the domain
controller that Active Directory explorer is connecting to?
Yes, you're correct.
In the second line, I see DC=hc, DC=cn. I am not very clear with
domain component concepts. Does that mean cn is a big domain and hc is
a sub domain of it?
This is the distinguished name representation of your domain (also called Base DN). Any domain name should have at least two words separated by a period (as per Microsoft's recommendation). Check the link about "Naming conventions in Active Directory for computers, domains, sites, and OUs" for additional information.
As I said, it is the DN representation of your domain. So, if your domain name is alpha.beta.gamma, then the DN for the same would be DC=alpha,DC=beta,DC=gamma.
Here in DC=hc, is the hc the same with hc\xxx's hc?
Yes, relatively.
You can get the details of concepts/terms mentioned above doing few web search. If you require any help, please let me know.

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.

How can I programatically determine my Active Directory domain using just my User Principal Name in C?

My current C program authenticates across multiple active directory domains using sAMAccountName/domain. It uses a config file to map the domain to the correct VIP (Virtual IP) server to bind and query to. I am modifying it to use userPrincipalName, which is an email address. The domain portion of the userPrincipalName is not necessarily the same domain that maps to the VIP servers.
Using my account, I am able to bind to any one of the VIP servers, but since I am not necessarily an Active Directory member on that server, I am unable to query. Right now, I have to iterate through each server until I find the one which I am a member of. This is not my ideal approach.
My question is, is there a way to retrieve what Active Directory domain I am a member of using just the userPrincipalName? I have read that there may be a way to achieve this by accessing the Global Catalog. Is this the correct approach, and if so how is this done using OpenLDAP LDAP api? If this isn't the correct approach, is there a way to query the first VIP server I'm bound to to ask what my Active Directory domain is?
Any help would be appreciated.
you can use system.secutiry principal and name will be returned in domain\usename format the first bit being domain , you dont need to go to AD
mystring= System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Finding CN of users in 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.

Resources