2014-09-25 92 views
0

我需要檢查LDAP屬性的語法OID,但我找不到任何好的起點。我正在使用C#和當前的System.DirectoryServices.Protocols(必須保持通用/非Active Directory特定)。C#獲取LDAP屬性語法OID

例如,使用Apache Directory Studio反對我們可以看到,在Active Directory中,「distinguishedName」屬性的語法OID爲「1.3.6.1.4.1.1466.115.121.1.12」。

任何人都可以請我在正確的方向嗎?

回答

1

好的,我想通了。我使用了thisthis 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); 
}