简体   繁体   中英

C# get LDAP attribute syntax OID

I need to check the syntax OID's for LDAP attributes but I can't find any good starting point. I'm using C# and currently System.DirectoryServices.Protocols (must stay generic / non-Active Directory specific).

For example, using Apache Directory Studio against we can see that in Active Directory the "distinguishedName" attribute has syntax OID "1.3.6.1.4.1.1466.115.121.1.12".

Can anyone please kick me in the right direction?

Okay, I figured it out. I used a combination of this and this SO posts to work it out. Here it is stitched together, if any other soulds out there need it. Note that this works on Active Directory and OpenLDAP (using System.DirectoryServices.Protocols).

var ldapConnection = new LdapConnection( "hostname.tld" );
ldapConnection.AuthType = AuthType.Yours;
ldapConnection.Credential = new NetworkCredential( "username", "password", "domain" );
ldapConnection.SessionOptions.ProtocolVersion = 3;

// Find the subschema first...
var searchRequest = new SearchRequest( null, "(objectClass=*)", SearchScope.Base, "subschemasubentry" );
var searchResponse = (SearchResponse) ldapConnection.SendRequest( searchRequest );

var subSchemaArray = searchResponse.Entries[0].Attributes["subschemasubentry"].GetValues( typeof( String ) );
var subSchema = (String) subSchemaArray[0];

// Now query the LDAP server and get the attribute types
searchRequest = new SearchRequest( subSchema, "(objectClass=*)", SearchScope.Base, "attributetypes" );
searchResponse = (SearchResponse) ldapConnection.SendRequest( searchRequest );

foreach ( string attributeType in searchResponse.Entries[0].Attributes["attributeTypes"].GetValues( typeof( String ) ) )
{
    // This is a chunky string, but the name and syntax OID is listed here
    Console.WriteLine(attributeType);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM