/// <summary> /// Enumerates registered Enterprise Certification Authorities from the current Active Directory forest. /// </summary> /// <param name="findType">Specifies CA object search type. The search type can be either: <strong>Name</strong> /// or <strong>Server</strong>.</param> /// <param name="findValue">Specifies search pattern for a type specifed in <strong>findType</strong> argument. /// Wildcard characters: * and ? are accepted.</param> /// <returns>Enterprise Certification Authority collection.</returns> public static CertificateAuthority[] EnumEnterpriseCAs(String findType, String findValue) { if (!DsUtils.Ping()) { throw new Exception("Non-domain environments are not supported."); } List <CertificateAuthority> CAs = new List <CertificateAuthority>(); CCertConfig certConfig = new CCertConfig(); while (certConfig.Next() >= 0) { Int32 flags = Convert.ToInt32(certConfig.GetField("Flags")); if ((flags & 1) == 0) { continue; } Wildcard wildcard = new Wildcard(findValue, RegexOptions.IgnoreCase); switch (findType.ToLower()) { case "name": if (!wildcard.IsMatch(certConfig.GetField("CommonName"))) { continue; } break; case "server": if (!wildcard.IsMatch(certConfig.GetField("Server"))) { continue; } break; default: throw new ArgumentException("The value for 'findType' must be either 'Name' or 'Server'."); } CAs.Add(new CertificateAuthority(certConfig.GetField("Server"), certConfig.GetField("SanitizedName"))); } CryptographyUtils.ReleaseCom(certConfig); return(CAs.ToArray()); }
void lookInDs(String computerName) { if (!DsUtils.Ping()) { return; } if (!computerName.Contains(".")) { computerName = computerName + "." + DsUtils.GetCurrentDomainName(); } _certConfig.Reset(0); //TODO while (_certConfig.Next() >= 0) { Int32 flags = Convert.ToInt32(_certConfig.GetField(CertConfigConstants.FieldFlags)); Boolean serverNameMatch = String.Equals(_certConfig.GetField(CertConfigConstants.FieldServer), computerName, StringComparison.InvariantCultureIgnoreCase); if (serverNameMatch && (flags & 1) > 0) { foundInDs = true; return; } } }
void lookInDs(String computerName) { if (!ActiveDirectory.Ping()) { return; } if (!computerName.Contains(".")) { computerName = computerName + "." + Domain.GetCurrentDomain().Name; } _certConfig.Reset(0); //TODO while (_certConfig.Next() >= 0) { Int32 flags = Convert.ToInt32(_certConfig.GetField("Flags")); Boolean serverNameMatch = String.Equals(_certConfig.GetField("Server"), computerName, StringComparison.InvariantCultureIgnoreCase); if (serverNameMatch && (flags & 1) > 0) { foundInDs = true; return; } } }