Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LDAP - Retrieve a list of all attributes/values?

Is it possible to retrieve a list of all attributes/values from LDAP without specifying, if so how can this be possible?

like image 673
Mike Anderson Avatar asked Jul 13 '11 04:07

Mike Anderson


People also ask

How do I find the LDAP attribute name?

You can see the LDAP attribute name in the attribute editor. When working with scripts or creating a program you will need to use the LDAP attribute name. This page provides a visual reference of the LDAP field mappings in Active Directory.

How do I get ldapsearch command?

To search for the LDAP configuration, use the “ldapsearch” command and specify “cn=config” as the search base for your LDAP tree. To run this search, you have to use the “-Y” option and specify “EXTERNAL” as the authentication mechanism.

What is DN in LDAP search?

The LDAP API references an LDAP object by its distinguished name (DN). A DN is a sequence of relative distinguished names (RDN) connected by commas. An RDN is an attribute with an associated value in the form attribute=value; normally expressed in a UTF-8 string format.

What is an LDAP attribute?

An LDAP directory has entries that contain information pertaining to entities. Each attribute has a name and one or more values. The names of the attributes are mnemonic strings, such as cn for common name, or mail for email address. For example, a company may have an employee directory.


1 Answers

I grab list of all parameters my DirectoryEntry class object. I hope it will help:

objectClass = System.Object[]
cn = Administrator
sn = Kwiatek (Last name)
c = PL (Country Code)
l = Warszawa (City)
st = Mazowieckie (Voivodeship)
title = .NET Developer
description = Built-in account for administering the computer/domain
postalCode = 00-000
postOfficeBox = Warszawa Ursynów
physicalDeliveryOfficeName = Wojskowa Akademia Techniczna
givenName = Piotr (First name)
distinguishedName = CN=Administrator,CN=Users,DC=helpdesk,DC=wat,DC=edu
instanceType = 4
whenCreated = 2012-11-23 06:09:28
whenChanged = 2013-02-23 13:24:41
displayName = Piotr Kwiatek (Konto administratora)
uSNCreated = System.__ComObject
memberOf = System.Object[]
uSNChanged = System.__ComObject
co = Poland
company = HELPDESK
streetAddress = Kaliskiego 2
wWWHomePage = http://www.piotr.kwiatek.org
name = Administrator
objectGUID = System.Byte[]
userAccountControl = 512
badPwdCount = 0
codePage = 0
countryCode = 616
badPasswordTime = System.__ComObject
lastLogoff = System.__ComObject
lastLogon = System.__ComObject
logonHours = System.Byte[]
pwdLastSet = System.__ComObject
primaryGroupID = 513
objectSid = System.Byte[]
adminCount = 1
accountExpires = System.__ComObject
logonCount = 178
sAMAccountName = Administrator
sAMAccountType = 805306368
objectCategory = CN=Person,CN=Schema,CN=Configuration,DC=helpdesk,DC=wat,DC=edu
isCriticalSystemObject = True
dSCorePropagationData = System.Object[]
lastLogonTimestamp = System.__ComObject
mail = [email protected]
nTSecurityDescriptor = System.__ComObject

And here You have code:

string currentUserSid = WindowsIdentity.GetCurrent().User.Value;

            PrincipalContext ctx = new PrincipalContext(
                ContextType.Domain,
                "helpdesk.wat.edu");

            UserPrincipal up = UserPrincipal.FindByIdentity(
                ctx, IdentityType.Sid,
                currentUserSid);

            /*
             * 
             */
            DirectoryEntry entry = up.GetUnderlyingObject() as DirectoryEntry;
            PropertyCollection props = entry.Properties;

            /*
             * 
             */
            foreach (string propName in props.PropertyNames)
            {
                if (entry.Properties[propName].Value != null)
                {
                    Console.WriteLine(propName + " = " + entry.Properties[propName].Value.ToString());
                }
                else
                {
                    Console.WriteLine(propName + " = NULL");
                }
            }


            Console.ReadKey();
like image 85
Piotr Kwiatek Avatar answered Sep 20 '22 04:09

Piotr Kwiatek