Example #1
0
 public ADDomainInfo GetDomainInfo()
 {
     if (domainInfo == null)
     {
         domainInfo = GetDomainInfoInternal();
     }
     return(domainInfo);
 }
Example #2
0
        protected override ADDomainInfo GetDomainInfoInternal()
        {
            IntPtr result;
            var    r = ldap_search_s(connection, "", LDAPScope.LDAP_SCOPE_BASE, "(objectclass=*)", null, false, out result);

            if (r != 0)
            {
                throw new LDAPException(r);
            }
            try
            {
                ADDomainInfo info = new ADDomainInfo();
                info.DefaultNamingContext       = GetValue(result, "defaultNamingContext");
                info.ConfigurationNamingContext = GetValue(result, "configurationNamingContext");
                info.DnsHostName = GetValue(result, "dnsHostName");
                if (!string.IsNullOrEmpty(GetValue(result, "domainFunctionality")))
                {
                    info.DomainFunctionality = int.Parse(GetValue(result, "domainFunctionality"));
                }
                if (!string.IsNullOrEmpty(GetValue(result, "forestFunctionality")))
                {
                    info.ForestFunctionality = int.Parse(GetValue(result, "forestFunctionality"));
                }
                info.NetBIOSName             = GetValue(result, "netBIOSName");
                info.RootDomainNamingContext = GetValue(result, "rootDomainNamingContext");
                info.SchemaNamingContext     = GetValue(result, "schemaNamingContext");
                Trace.WriteLine("supportedLDAPVersion: ");
                var supportedLDAPVersion = GetValues(result, "supportedLDAPVersion");
                if (supportedLDAPVersion != null)
                {
                    foreach (string version in supportedLDAPVersion)
                    {
                        Trace.WriteLine(version);
                    }
                }
                Trace.WriteLine("supportedControl: ");
                var supportedControl = GetValues(result, "supportedControl");
                if (supportedControl != null)
                {
                    foreach (string control in supportedControl)
                    {
                        Trace.WriteLine(control);
                    }
                }
                Trace.WriteLine("namingContexts: ");
                info.NamingContexts = new List <string>();
                foreach (var nc in GetValues(result, "namingContexts"))
                {
                    Trace.WriteLine(nc);
                    info.NamingContexts.Add(nc);
                }
                return(info);
            }
            finally
            {
                ldap_memfree(result);
            }
        }
Example #3
0
 public ADDomainInfo GetDomainInfo()
 {
     if (domainInfo == null)
     {
         ConnectionTime = DateTime.Now;
         domainInfo     = GetDomainInfoInternal();
     }
     return(domainInfo);
 }
        private ADDomainInfo GetLDAPDomainInfo()
        {
            DirectoryEntry rootDse = new DirectoryEntry("LDAP://" + Server + "/RootDSE");

            if (Credential == null)
            {
                rootDse = new DirectoryEntry(@"LDAP://" + Server + (Port == 0 ? null : ":" + Port) + "/RootDSE", null, null, AuthenticationTypes.ServerBind | AuthenticationTypes.Secure | (Port == 636 ? AuthenticationTypes.SecureSocketsLayer : 0));
            }
            else
            {
                rootDse = new DirectoryEntry(@"LDAP://" + Server + (Port == 0 ? null : ":" + Port) + "/RootDSE", Credential.UserName, Credential.Password, AuthenticationTypes.ServerBind | AuthenticationTypes.Secure | (Port == 636 ? AuthenticationTypes.SecureSocketsLayer : 0));
            }
            return(ADDomainInfo.Create(rootDse));
        }
Example #5
0
        public static ADDomainInfo Create(DirectoryEntry rootDSE)
        {
            ADDomainInfo info = new ADDomainInfo();

            info.DefaultNamingContext       = rootDSE.Properties["defaultNamingContext"].Value as string;
            info.ConfigurationNamingContext = rootDSE.Properties["configurationNamingContext"].Value as string;
            info.DnsHostName = rootDSE.Properties["dnsHostName"].Value as string;
            if (rootDSE.Properties.Contains("domainFunctionality"))
            {
                info.DomainFunctionality = int.Parse(rootDSE.Properties["domainFunctionality"].Value as string);
            }
            if (rootDSE.Properties.Contains("forestFunctionality"))
            {
                info.ForestFunctionality = int.Parse(rootDSE.Properties["forestFunctionality"].Value as string);
            }
            if (rootDSE.Properties.Contains("netBIOSName"))
            {
                info.NetBIOSName = rootDSE.Properties["netBIOSName"].Value as string;
            }
            info.RootDomainNamingContext = rootDSE.Properties["rootDomainNamingContext"].Value as string;
            info.SchemaNamingContext     = rootDSE.Properties["schemaNamingContext"].Value as string;
            Trace.WriteLine("supportedLDAPVersion: ");
            object[] supportedLDAPVersion = rootDSE.Properties["supportedLDAPVersion"].Value as object[];
            if (supportedLDAPVersion != null)
            {
                foreach (string version in supportedLDAPVersion)
                {
                    Trace.WriteLine(version);
                }
            }
            Trace.WriteLine("supportedControl: ");
            object[] supportedControl = rootDSE.Properties["supportedControl"].Value as object[];
            if (supportedControl != null)
            {
                foreach (string control in supportedControl)
                {
                    Trace.WriteLine(control);
                }
            }
            Trace.WriteLine("supportedLDAPVersion: ");
            info.NamingContexts = new List <string>();
            foreach (var nc in (object[])rootDSE.Properties["namingContexts"].Value)
            {
                info.NamingContexts.Add((string)nc);
            }
            return(info);
        }
Example #6
0
 protected override ADDomainInfo GetDomainInfoInternal()
 {
     try
     {
         var data = Resource.Get();
         return(ADDomainInfo.Create(data));
     }
     catch (FaultException ex)
     {
         Trace.WriteLine("Fault Exception: " + ex.Message);
         Trace.WriteLine("Reason: " + ex.Reason);
         var stringWriter  = new StringWriter();
         var xmlTextWriter = new XmlTextWriter(stringWriter);
         var messageFault  = ex.CreateMessageFault();
         messageFault.WriteTo(xmlTextWriter, EnvelopeVersion.Soap12);
         var stringValue = Convert.ToString(stringWriter);
         Trace.WriteLine("Exception:");
         Trace.WriteLine(stringValue);
         Trace.WriteLine("The connection didn't worked");
         throw;
     }
 }
Example #7
0
        private ADDomainInfo GetLDAPDomainInfo()
        {
            DirectoryEntry rootDse;

            try
            {
                if (Credential == null)
                {
                    rootDse = new DirectoryEntry(@"LDAP://" + Server + (Port == 0 ? null : ":" + Port) + "/RootDSE", null, null, AuthenticationTypes.ServerBind | AuthenticationTypes.Secure | (Port == 636 ? AuthenticationTypes.SecureSocketsLayer : 0));
                }
                else
                {
                    rootDse = new DirectoryEntry(@"LDAP://" + Server + (Port == 0 ? null : ":" + Port) + "/RootDSE", Credential.UserName, Credential.Password, AuthenticationTypes.ServerBind | AuthenticationTypes.Secure | (Port == 636 ? AuthenticationTypes.SecureSocketsLayer : 0));
                }
                // force the connection to the LDAP server via an access to the "properties" property
                Trace.WriteLine("rootDse property count: " + rootDse.Properties.Count);
            }
            catch (COMException ex)
            {
                // Windows 2000 does not support a bind to the rootDse and returns "The server is not operational" (0x8007203A)
                if (ex.ErrorCode == -2147016646)
                {
                    if (Credential == null)
                    {
                        rootDse = new DirectoryEntry(@"LDAP://" + Server + (Port == 0 ? null : ":" + Port) + "/RootDSE", null, null, AuthenticationTypes.Secure | (Port == 636 ? AuthenticationTypes.SecureSocketsLayer : 0));
                    }
                    else
                    {
                        rootDse = new DirectoryEntry(@"LDAP://" + Server + (Port == 0 ? null : ":" + Port) + "/RootDSE", Credential.UserName, Credential.Password, AuthenticationTypes.Secure | (Port == 636 ? AuthenticationTypes.SecureSocketsLayer : 0));
                    }
                }
                else
                {
                    throw;
                }
            }
            return(ADDomainInfo.Create(rootDse));
        }
Example #8
0
        public static ADDomainInfo Create(top data)
        {
            ADDomainInfo info = new ADDomainInfo();

            foreach (XmlElement item in data.Any)
            {
                string attribute = StripNamespace(item.Name);

                switch (attribute)
                {
                case "configurationNamingContext":
                    info.ConfigurationNamingContext = ExtractStringValue(item);
                    break;

                case "defaultNamingContext":
                    info.DefaultNamingContext = ExtractStringValue(item);
                    break;

                case "dnsHostName":
                    info.DnsHostName = ExtractStringValue(item);
                    break;

                case "domainFunctionality":
                    info.DomainFunctionality = ExtractIntValue(item);
                    break;

                case "forestFunctionality":
                    info.ForestFunctionality = ExtractIntValue(item);
                    break;

                case "netBIOSName":
                    info.NetBIOSName = ExtractStringValue(item);
                    break;

                case "rootDomainNamingContext":
                    info.RootDomainNamingContext = ExtractStringValue(item);
                    break;

                case "schemaNamingContext":
                    info.SchemaNamingContext = ExtractStringValue(item);
                    break;

                case "supportedLDAPVersion":
                    Trace.WriteLine("supportedLDAPVersion: ");
                    if (item.ChildNodes != null)
                    {
                        foreach (XmlNode child in item.ChildNodes)
                        {
                            if (child != null)
                            {
                                Trace.WriteLine(child.InnerText);
                            }
                        }
                    }
                    break;

                case "supportedControl":
                    Trace.WriteLine("supportedControl: ");
                    if (item.ChildNodes != null)
                    {
                        foreach (XmlNode child in item.ChildNodes)
                        {
                            if (child != null)
                            {
                                Trace.WriteLine(child.InnerText);
                            }
                        }
                    }
                    break;

                default:
                    Trace.WriteLine("Other attribute found:" + attribute);
                    break;
                }
            }
            return(info);
        }
 public LinuxFileConnection(NetworkCredential credential, ADDomainInfo domainInfo)
 {
     Credential      = credential;
     this.domainInfo = domainInfo;
     Init();
 }
Example #10
0
        private ADDomainInfo GetLDAPDomainInfo()
        {
            DirectoryEntry rootDse = new DirectoryEntry("LDAP://" + Server + "/RootDSE");

            return(ADDomainInfo.Create(rootDse));
        }