Exemple #1
0
        public static IEnumerable <IDomainTrust> Get_ForestTrust(Args_Get_Forest args = null)
        {
            if (args == null)
            {
                args = new Args_Get_Forest();
            }

            var FoundForest = GetForest.Get_Forest(args);

            if (FoundForest != null)
            {
                var items        = FoundForest.Forest.GetAllTrustRelationships();
                var ForestTrusts = new List <IDomainTrust>();
                foreach (TrustRelationshipInformation item in items)
                {
                    ForestTrusts.Add(new NetDomainTrust
                    {
                        SourceName     = item.SourceName,
                        TargetName     = item.TargetName,
                        TrustDirection = item.TrustDirection,
                        TrustType      = item.TrustType
                    });
                }
                return(ForestTrusts);
            }
            return(null);
        }
Exemple #2
0
        public static IEnumerable <GlobalCatalog> Get_ForestGlobalCatalog(Args_Get_ForestGlobalCatalog args = null)
        {
            if (args == null)
            {
                args = new Args_Get_ForestGlobalCatalog();
            }

            var Arguments = new Args_Get_Forest
            {
                Forest     = args.Forest,
                Credential = args.Credential
            };

            var ForestObject = GetForest.Get_Forest(Arguments);

            if (ForestObject != null)
            {
                var ForestGlobalCatalogs = new List <GlobalCatalog>();
                var items = ForestObject.Forest.FindAllGlobalCatalogs();
                foreach (GlobalCatalog item in items)
                {
                    ForestGlobalCatalogs.Add(item);
                }
            }
            return(null);
        }
Exemple #3
0
        public static DomainCollection Get_ForestDomain(Args_Get_ForestDomain args = null)
        {
            if (args == null)
            {
                args = new Args_Get_ForestDomain();
            }

            var Arguments = new Args_Get_Forest
            {
                Forest     = args.Forest,
                Credential = args.Credential
            };

            var ForestObject = GetForest.Get_Forest(Arguments);

            if (ForestObject != null)
            {
                return(ForestObject.Forest?.Domains);
            }
            return(null);
        }
        public static Dictionary <string, string> Get_DomainGUIDMap(Args_Get_DomainGUIDMap args = null)
        {
            if (args == null)
            {
                args = new Args_Get_DomainGUIDMap();
            }

            var GUIDs = new Dictionary <string, string>
            {
                { @"00000000-0000-0000-0000-000000000000", @"All" }
            };

            var ForestArguments = new Args_Get_Forest()
            {
                Credential = args.Credential
            };

            string SchemaPath = null;

            try
            {
                SchemaPath = GetForest.Get_Forest(ForestArguments).Forest.Schema.Name;
            }
            catch
            {
                throw new Exception(@"[Get-DomainGUIDMap] Error in retrieving forest schema path from Get-Forest");
            }
            if (SchemaPath.IsNullOrEmpty())
            {
                throw new Exception(@"[Get-DomainGUIDMap] Error in retrieving forest schema path from Get-Forest");
            }

            var SearcherArguments = new Args_Get_DomainSearcher
            {
                SearchBase      = SchemaPath,
                LDAPFilter      = @"(schemaIDGUID=*)",
                Domain          = args.Domain,
                Server          = args.Server,
                ResultPageSize  = args.ResultPageSize,
                ServerTimeLimit = args.ServerTimeLimit,
                Credential      = args.Credential
            };
            var SchemaSearcher = GetDomainSearcher.Get_DomainSearcher(SearcherArguments);

            if (SchemaSearcher != null)
            {
                try
                {
                    var Results = SchemaSearcher.FindAll();
                    if (Results != null)
                    {
                        foreach (SearchResult result in Results)
                        {
                            GUIDs[(new Guid(result.Properties["schemaidguid"][0] as byte[])).ToString()] = result.Properties["name"][0].ToString();
                        }
                        try { Results.Dispose(); }
                        catch (Exception e)
                        {
                            Logger.Write_Verbose($@"[Get-DomainGUIDMap] Error disposing of the Results object: {e}");
                        }
                    }
                    SchemaSearcher.Dispose();
                }
                catch (Exception e)
                {
                    Logger.Write_Verbose($@"[Get-DomainGUIDMap] Error in building GUID map: {e}");
                }
            }

            SearcherArguments.SearchBase = SchemaPath.Replace(@"Schema", @"Extended-Rights");
            SearcherArguments.LDAPFilter = @"(objectClass=controlAccessRight)";
            var RightsSearcher = GetDomainSearcher.Get_DomainSearcher(SearcherArguments);

            if (RightsSearcher != null)
            {
                try
                {
                    var Results = RightsSearcher.FindAll();
                    if (Results != null)
                    {
                        foreach (SearchResult result in Results)
                        {
                            GUIDs[(new Guid(result.Properties["rightsguid"][0] as byte[])).ToString()] = result.Properties["name"][0].ToString();
                        }
                        try { Results.Dispose(); }
                        catch (Exception e)
                        {
                            Logger.Write_Verbose($@"[Get-DomainGUIDMap] Error disposing of the Results object: {e}");
                        }
                    }
                    RightsSearcher.Dispose();
                }
                catch (Exception e)
                {
                    Logger.Write_Verbose($@"[Get-DomainGUIDMap] Error in building GUID map: {e}");
                }
            }
            return(GUIDs);
        }
Exemple #5
0
 public static ForestEx Get_NetForest(Args_Get_Forest args = null)
 {
     return(GetForest.Get_Forest(args));
 }