简体   繁体   English

C#获取LDAP属性语法OID

[英]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. 我需要检查LDAP属性的语法OID,但找不到任何好的起点。 I'm using C# and currently System.DirectoryServices.Protocols (must stay generic / non-Active Directory specific). 我使用的是C#,当前使用的是System.DirectoryServices.Protocols(必须保持通用/非Active Directory特定)。

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". 例如,针对Apache Directory Studio,我们可以看到在Active Directory中,“ distinguishedName”属性的语法为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. 我结合使用了这个这个 SO帖子来解决它。 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). 请注意,这适用于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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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