void m_initialize(String findType, String findValue) { switch (findType.ToLower()) { case "name": String cn = "CN=" + escapeChars(findValue) + ", CN=Certificate Templates, CN=Public Key Services, CN=Services," + ActiveDirectory.ConfigContext; DirectoryEntry entry = new DirectoryEntry("LDAP://" + cn); m_fillproperties(entry); break; case "displayname": cn = "CN=Certificate Templates, CN=Public Key Services, CN=Services," + ActiveDirectory.ConfigContext; DirectoryEntries entries = ActiveDirectory.GetChildItems(cn); foreach (DirectoryEntry item in entries.Cast <DirectoryEntry>().Where(item => String.Equals(((String)item.Properties["displayName"].Value), findValue, StringComparison.CurrentCultureIgnoreCase))) { m_fillproperties(item); } break; case "oid": cn = "CN=Certificate Templates, CN=Public Key Services, CN=Services," + ActiveDirectory.ConfigContext; entries = ActiveDirectory.GetChildItems(cn); foreach (DirectoryEntry item in entries.Cast <DirectoryEntry>().Where(item => (String)item.Properties["msPKI-Cert-Template-OID"].Value == findValue)) { m_fillproperties(item); } break; default: throw new Exception("The value for 'findType' must be either 'Name', 'DisplayName' or 'OID'."); } }
/// <summary> /// Enumerates certificate templates registered in Active Directory. /// </summary> /// <returns>An array of certificate templates.</returns> public static CertificateTemplate[] EnumTemplates() { if (ActiveDirectory.Ping()) { String cn = "CN=Certificate Templates, CN=Public Key Services, CN=Services," + ActiveDirectory.ConfigContext; DirectoryEntries entries = ActiveDirectory.GetChildItems(cn); return((from DirectoryEntry item in entries select new CertificateTemplate("name", (String)item.Properties["cn"].Value)).ToArray()); } throw new Exception(Error.E_DCUNAVAILABLE); }