C#获取LDAP属性语法OID

本文关键字:OID 属性语法 LDAP 获取 | 更新日期: 2023-09-27 18:24:20

我需要检查LDAP属性的语法OID,但找不到任何好的起点。我正在使用C#和当前的System.DirectoryServices.Protocols(必须保持通用/非Active Directory特定)。

例如,使用Apache Directory Studio对抗,我们可以看到在Active Directory中,"distinguishedName"属性的语法OID为"1.3.6.1.4.1.1466.115.11.1.12"。

谁能把我踢向正确的方向吗?

C#获取LDAP属性语法OID

好吧,我想明白了。我使用了这个和这个SO帖子的组合来解决这个问题。在这里,如果有其他灵魂需要的话,它被缝合在一起。注意,这在Active Directory和OpenLDAP(使用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);
}