示例#1
0
 public void Initialize(IADConnection adws)
 {
     string[] propertiesLaps = new string[] { "schemaIDGUID" };
     // note: the LDAP request does not contain ms-MCS-AdmPwd because in the old time, MS consultant was installing customized version of the attriute, * being replaced by the company name
     // check the oid instead ? (which was the same even if the attribute name was not)
     adws.Enumerate(DomainInfo.SchemaNamingContext, "(name=ms-*-AdmPwd)", propertiesLaps, (ADItem aditem) => {
         GuidsReadProperties.Add(new KeyValuePair <Guid, RelationType>(aditem.SchemaIDGUID, RelationType.READ_PROP_MS_MCS_ADMPWD));
     }, "OneLevel");
 }
示例#2
0
 public void Initialize(ADDomainInfo domainInfo, IADConnection adws)
 {
     databaseInformation["EngineVersion"]        = Assembly.GetExecutingAssembly().GetName().Version.ToString();
     databaseInformation["Date"]                 = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss");
     databaseInformation["DomainName"]           = domainInfo.DomainName;
     databaseInformation["DefaultNamingContext"] = domainInfo.DefaultNamingContext;
     databaseInformation["DomainSid"]            = domainInfo.DomainSid.Value;
     databaseInformation["DomainNetBIOS"]        = domainInfo.NetBIOSName;
     this.adws = adws;
 }
示例#3
0
        private void EstablishConnection()
        {
            switch (ConnectionType)
            {
            case ADConnectionType.ADWSOnly:
                connection = EstablishConnectionWithADWS();
                break;

            case ADConnectionType.LDAPOnly:
                Trace.WriteLine("Trying LDAP connection");
                connection = EstablishConnectionWithLDAP();
                Trace.WriteLine("LDAP connection successful");
                break;

            case ADConnectionType.ADWSThenLDAP:
                try
                {
                    connection         = EstablishConnectionWithADWS();
                    fallBackConnection = EstablishConnectionWithLDAP();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unable to connect to ADWS - trying LDAP");
                    try
                    {
                        connection = EstablishConnectionWithLDAP();;
                        Trace.WriteLine("Connected with LDAP");
                    }
                    catch (Exception ex2)
                    {
                        Trace.WriteLine("LDAP exception: " + ex2.Message + "(" + ex2.GetType() + ")");
                        if (ex2 as COMException != null)
                        {
                            COMException ex3 = (COMException)ex2;
                            Trace.WriteLine("COMException: " + ex3.ErrorCode);
                        }
                        Trace.WriteLine(ex2.StackTrace);
                        Trace.WriteLine("Throwing ADWS Exception again");
                        ThrowActiveDirectoryServerDownException(ex.Message);
                    }
                }
                break;

            case ADConnectionType.LDAPThenADWS:
                try
                {
                    Trace.WriteLine("Trying LDAP connection");
                    connection = EstablishConnectionWithLDAP();
                    Trace.WriteLine("LDAP connection successful");
                    fallBackConnection = EstablishConnectionWithADWS();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unable to connect to LDAP - trying ADWS");
                    try
                    {
                        var adwsConnection = EstablishConnectionWithADWS();
                        Trace.WriteLine("Connected with ADWS");
                        connection = adwsConnection;
                    }
                    catch (Exception ex2)
                    {
                        Trace.WriteLine("ADWS exception: " + ex2.Message + "(" + ex2.GetType() + ")");
                        Trace.WriteLine(ex2.StackTrace);
                        Trace.WriteLine("Throwing LDAP Exception again");
                        ThrowActiveDirectoryServerDownException(ex.Message);
                    }
                }
                break;

            case ADConnectionType.Unix:
                Trace.WriteLine("Trying Linux connection");
                var linuxConnection = new LinuxConnection(Server, Port, Credential);
                linuxConnection.EstablishConnection();
                Trace.WriteLine("Linux connection successful");
                connection = linuxConnection;
                break;
            }
        }
示例#4
0
        private void EstablishConnection()
        {
            ADWSConnection adwsConnection = null;
            LDAPConnection ldapConnection = new LDAPConnection(Server, Port, Credential);

            try
            {
                adwsConnection = new ADWSConnection(Server, Port, Credential);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Unable to load ADWS - .Net 2 only ? (" + ex.Message + ")");
            }
            switch (ConnectionType)
            {
            case ADConnectionType.ADWSOnly:
                Trace.WriteLine("Trying ADWS connection");
                adwsConnection.EstablishConnection();
                Trace.WriteLine("ADWS connection successful");
                connection = adwsConnection;
                break;

            case ADConnectionType.LDAPOnly:
                Trace.WriteLine("Trying LDAP connection");
                ldapConnection.EstablishConnection();
                Trace.WriteLine("LDAP connection successful");
                connection = ldapConnection;
                break;

            case ADConnectionType.ADWSThenLDAP:
                try
                {
                    Trace.WriteLine("Trying ADWS connection");
                    adwsConnection.EstablishConnection();
                    Trace.WriteLine("ADWS connection successful");
                    connection         = adwsConnection;
                    fallBackConnection = new LDAPConnection(adwsConnection.Server, adwsConnection.Port, Credential);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unable to connect to ADWS - trying LDAP");
                    try
                    {
                        ldapConnection.EstablishConnection();
                        Trace.WriteLine("Connected with LDAP");
                        connection = ldapConnection;
                    }
                    catch (Exception ex2)
                    {
                        Trace.WriteLine("LDAP exception: " + ex2.Message);
                        Trace.WriteLine(ex2.StackTrace);
                        Trace.WriteLine("Throwing ADWS Exception again");
                        throw new ActiveDirectoryServerDownException(ex.Message);
                    }
                }
                break;

            case ADConnectionType.LDAPThenADWS:
                try
                {
                    Trace.WriteLine("Trying LDAP connection");
                    ldapConnection.EstablishConnection();
                    Trace.WriteLine("LDAP connection successful");
                    connection         = ldapConnection;
                    fallBackConnection = new ADWSConnection(adwsConnection.Server, adwsConnection.Port, Credential);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unable to connect to LDAP - trying ADWS");
                    try
                    {
                        adwsConnection.EstablishConnection();
                        Trace.WriteLine("Connected with ADWS");
                        connection = adwsConnection;
                    }
                    catch (Exception ex2)
                    {
                        Trace.WriteLine("ADWS exception: " + ex2.Message);
                        Trace.WriteLine(ex2.StackTrace);
                        Trace.WriteLine("Throwing LDAP Exception again");
                        throw new ActiveDirectoryServerDownException(ex.Message);
                    }
                }
                break;
            }
        }
示例#5
0
        private void AnalyzeGPOItem(IADConnection adws, string gpoPath, string applyTo, string artefactPath, string artefactDescription, ProcessGPOItem processGPOItem)
        {
            string path = adws.FileConnection.PathCombine(adws.FileConnection.PathCombine(gpoPath, applyTo), artefactPath);

            try
            {
                var    PathFragment = artefactPath.Split(new char[] { '\\', '/' });
                string dirpath      = adws.FileConnection.PathCombine(gpoPath, applyTo);
                Dictionary <string, List <RelationType> > relationToAdd = null;
                for (int i = 0; i < PathFragment.Length; i++)
                {
                    dirpath = adws.FileConnection.PathCombine(dirpath, PathFragment[i]);
                    FileSystemSecurity fs = null;
                    if (i == PathFragment.Length - 1)
                    {
                        if (adws.FileConnection.FileExists(dirpath))
                        {
                            fs = adws.FileConnection.GetFileSecurity(dirpath);
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        try
                        {
                            fs = adws.FileConnection.GetDirectorySecurity(dirpath);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    var o = AnalyzeFileSecurityDescriptor(dirpath, fs, true);
                    if (relationToAdd == null)
                    {
                        relationToAdd = o;
                    }
                    else
                    {
                        relationToAdd = CombineSDAnalysis(relationToAdd, o);
                    }
                }
                if (relationToAdd != null)
                {
                    foreach (string target in relationToAdd.Keys)
                    {
                        foreach (RelationType link in relationToAdd[target])
                        {
                            {
                                Storage.InsertRelation(target, MappingType.Sid, path, MappingType.FileName, link);
                            }
                        }
                    }
                }

                if (adws.FileConnection.FileExists(path))
                {
                    Storage.InsertFileNode(path, artefactDescription);
                    Storage.InsertRelation(path, MappingType.FileName, gpoPath, MappingType.GPODirectory, RelationType.container_hierarchy);
                    if (processGPOItem != null)
                    {
                        processGPOItem(gpoPath, applyTo, artefactPath);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                Trace.WriteLine("Access denied for " + path);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception " + ex.Message + " for " + path);
                Trace.WriteLine(ex.StackTrace);
            }
        }
示例#6
0
 public RelationFactory(IDataStorage storage, ADDomainInfo domainInfo, IADConnection connection)
 {
     Storage    = storage;
     DomainInfo = domainInfo;
     adws       = connection;
 }