public void Ctor_Flag() { var control = new ExtendedDNControl(ExtendedDNFlag.StandardString); Assert.True(control.IsCritical); Assert.Equal(ExtendedDNFlag.StandardString, control.Flag); Assert.True(control.ServerSide); Assert.Equal("1.2.840.113556.1.4.529", control.Type); Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 1 }, control.GetValue()); }
public void Ctor_Flag() { var control = new ExtendedDNControl(ExtendedDNFlag.StandardString); Assert.True(control.IsCritical); Assert.Equal(ExtendedDNFlag.StandardString, control.Flag); Assert.True(control.ServerSide); Assert.Equal("1.2.840.113556.1.4.529", control.Type); var expected = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 1 } : new byte[] { 48, 3, 2, 1, 1 }; Assert.Equal(expected, control.GetValue()); }
public static ReadOnlyCollection <DomainInfo> GetForestDomains(LdapConnection conn) { if (conn == null) { throw new ArgumentNullException("Method does not accept null parameters"); } string[] propsToLoad = new string[] { "namingContexts", "configurationNamingContext" }; List <DomainInfo> retVal = new List <DomainInfo>(); SearchRequest rq = new SearchRequest(); rq.Attributes.AddRange(propsToLoad); rq.Scope = SearchScope.Base; ExtendedDNControl ctrl = new ExtendedDNControl(ExtendedDNFlag.StandardString); rq.Controls.Add(ctrl); SearchResponse rsp = (SearchResponse)conn.SendRequest(rq); foreach (string nc in (string[])(rsp.Entries[0].Attributes["namingContexts"].GetValues(typeof(string)))) { int start = nc.IndexOf("<SID=", StringComparison.CurrentCultureIgnoreCase); if (start > -1) { DomainInfo di = new DomainInfo(); di.Dn = nc.Split(';')[2]; int end = nc.IndexOf('>', start); start += 5; //prefix of SID: <SID= string sid = nc.Substring(start, end - start); di.Sid = new SecurityIdentifier(sid); retVal.Add(di); } } string configNC = ((rsp.Entries[0].Attributes["configurationNamingContext"].GetValues(typeof(string)))[0] as string).Split(';')[1]; foreach (DomainInfo di in retVal) { rq = new SearchRequest(); rq.DistinguishedName = "cn=Partitions," + configNC; rq.Scope = SearchScope.OneLevel; rq.Attributes.Add("dnsRoot"); rq.Filter = string.Format(System.Globalization.CultureInfo.InvariantCulture, "(&(objectClass=crossRef)(nCName={0}))", di.Dn); rsp = (SearchResponse)conn.SendRequest(rq); di.DnsName = rsp.Entries[0].Attributes["dnsRoot"].GetValues(typeof(string))[0] as string; } return(new ReadOnlyCollection <DomainInfo>(retVal)); }
public static ForestInfo GetForestRootDomain() { ForestInfo retVal = new ForestInfo(); string[] propsToLoad = new string[] { "rootDomainNamingContext", "configurationNamingContext", "schemaNamingContext", "dnsHostName" }; using (LdapConnection conn = GetLdapConnection(ConnectionType.Ldap)) { SearchRequest rq = new SearchRequest(); rq.Attributes.AddRange(propsToLoad); rq.Scope = SearchScope.Base; ExtendedDNControl ctrl = new ExtendedDNControl(ExtendedDNFlag.StandardString); rq.Controls.Add(ctrl); SearchResponse rsp = (SearchResponse)conn.SendRequest(rq); string rootNC = (rsp.Entries[0].Attributes["rootDomainNamingContext"].GetValues(typeof(string)))[0] as string; int start = rootNC.IndexOf("<SID=", StringComparison.CurrentCultureIgnoreCase); if (start > -1) { retVal.RootDomain.Dn = rootNC.Split(';')[2]; int end = rootNC.IndexOf('>', start); start += 5; //prefix of SID: <SID= string sid = rootNC.Substring(start, end - start); retVal.RootDomain.Sid = new SecurityIdentifier(sid); } retVal.ConfigurationNamingContext = ((rsp.Entries[0].Attributes["configurationNamingContext"].GetValues(typeof(string)))[0] as string).Split(';')[1]; retVal.SchemaNamingContext = ((rsp.Entries[0].Attributes["schemaNamingContext"].GetValues(typeof(string)))[0] as string).Split(';')[1]; retVal.RootDomain.ConnectedHost = rsp.Entries[0].Attributes["dnsHostName"].GetValues(typeof(string))[0] as string; //get DNS name of forest root domain rq = new SearchRequest(); rq.DistinguishedName = "cn=Partitions," + retVal.ConfigurationNamingContext; rq.Scope = SearchScope.OneLevel; rq.Attributes.Add("dnsRoot"); rq.Filter = string.Format(System.Globalization.CultureInfo.InvariantCulture, "(&(objectClass=crossRef)(nCName={0}))", retVal.RootDomain.Dn); rsp = (SearchResponse)conn.SendRequest(rq); retVal.RootDomain.DnsName = rsp.Entries[0].Attributes["dnsRoot"].GetValues(typeof(string))[0] as string; } return(retVal); }