Ejemplo n.º 1
0
        public static List <string> LoadDomainList()
        {
            dl.Clear();
            Mutex loadMutex = new Mutex(false, "NetworkComputer");

            loadMutex.WaitOne();
            myDomains = new DomainCollection();
            myDomains.Refresh();
            for (int i = 0; i < myDomains.Count; i++)
            {
                dl.Add(myDomains[i].Name);
            }
            loadMutex.ReleaseMutex();
            return(dl);
        }
Ejemplo n.º 2
0
        public bool updateDomainControllers(DomainCollection domains)
        {
            ConfiguredDomainControllersList.Clear();
            UnconfiguredDomainControllersList.Clear();
            UnreachableDomainControllersList.Clear();
            AllDomainControllers.Clear();
            bool retVal = true;

            try
            {
                foreach (Domain domain in domains)
                {
                    DomainControllerCollection dcCollection = domain.FindAllDiscoverableDomainControllers();

                    foreach (DomainController dc in dcCollection)
                    {
                        try
                        {
                            AllDomainControllers.Add(dc);

                            if (checkRegKey(dc.IPAddress))
                            {
                                ConfiguredDomainControllersList.Add(dc.Name);
                            }
                            else
                            {
                                UnconfiguredDomainControllersList.Add(dc.Name);
                            }
                        }
                        catch (Exception e)
                        {
                            UnconfiguredDomainControllersList.Add(e.ToString());
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                UnconfiguredDomainControllersList.Add("Error Retrieving Domain Controllers");
                ConfiguredDomainControllersList.Add("Error Retrieving Domain Controllers");
                retVal = false;
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        private void ListDomains()
        {
            try
            {
                Forest           currentForest = Forest.GetCurrentForest();
                DomainCollection domains       = currentForest.Domains;

                foreach (System.DirectoryServices.ActiveDirectory.Domain domain in domains)
                {
                    comboDomain.Items.Add(domain.Name);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Retrieving of domains failed:" + Environment.NewLine + e.Message, EnumStrings.hMailServerAdministrator);
            }
        }
Ejemplo n.º 4
0
        public void updateDomainControllers()
        {
            ConfiguredDomainControllersList.Clear();
            UnconfiguredDomainControllersList.Clear();

            try
            {
                Forest           forest        = Forest.GetCurrentForest();
                DomainCollection domCollection = forest.Domains;

                foreach (Domain domain in domCollection)
                {
                    DomainControllerCollection dcCollection = domain.FindAllDiscoverableDomainControllers();

                    foreach (DomainController dc in dcCollection)
                    {
                        try
                        {
                            if (checkSystemReachable(dc.IPAddress))
                            {
                                AllDomainControllers.Add(dc);

                                if (checkRegKey(dc.IPAddress))
                                {
                                    ConfiguredDomainControllersList.Add(dc.Name);
                                }
                                else
                                {
                                    UnconfiguredDomainControllersList.Add(dc.Name);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            UnconfiguredDomainControllersList.Add(e.ToString());
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                UnconfiguredDomainControllersList.Add("Error Retrieving Domain Controllers");
                ConfiguredDomainControllersList.Add("Error Retrieving Domain Controllers");
            }
        }
Ejemplo n.º 5
0
        private static QueryProcessResponse CreateResponse(Type type, IEnumerable items, ProcessURI uri)
        {
            var domains = new DomainCollection();
            var enumerator = items.GetEnumerator();
            while (enumerator.MoveNext())
            {
                var instance = enumerator.Current;
                var entity = new EntityDomain(type, uri)
                {
                    Instance = instance,
                    Value = ContextFactory.GetContext(type).GetID(instance),
                };

                domains.Add(entity);
            }
            return new QueryProcessResponse(type, domains) { URI = uri };
        }
        static int Main()
        {
            bool      ret       = false; // assume failure
            ADSection adSection = ConfigurationManager.GetSection("activeDir") as ADSection;

            if (adSection == null)
            {
                Console.WriteLine("Error creating ADSection");
            }
            else
            {
                _domains = adSection.Domains;
                Task <bool> pini = permissionsAsync();
                ret = pini.Result;
            }

            return((ret) ? 0 : 1);
        }
Ejemplo n.º 7
0
      /// <summary>
      /// Obtiene la lista de dominios
      /// </summary>
      /// <returns></returns>
      public static StringCollection Domain_GetList()
      {
          StringCollection domainList = new StringCollection();

          try
          {
              DomainCollection domains = Forest.GetCurrentForest().Domains;

              foreach (Domain domain in domains)
              {
                  domainList.Add(domain.Name);
              }
          }
          catch (Exception ex)
          {
              throw ProcessActiveDirectoryException(ex);
          }
          return(domainList);
      }
Ejemplo n.º 8
0
        // Initialize our class variables with values from LatestOverlaps.exe.config. Returns true if all values
        // successfully read and class variables initialized, false otherwise. ConfigurationErrorsException caught
        // and logged in %LOCALAPPDATA%\AcTools\Logs\LatestOverlaps-YYYY-MM-DD.log on initialization failure.
        private static bool initAppConfigData()
        {
            bool ret = true; // assume success

            try
            {
                _fromHoursAgo = AcQuery.getAppConfigSetting <int>("FromHoursAgo");
                _outputFile   = AcQuery.getAppConfigSetting <string>("OutputFile").Trim();

                ADSection adSection = ConfigurationManager.GetSection("activeDir") as ADSection;
                if (adSection == null)
                {
                    AcDebug.Log("Error in Program.initAppConfigData creating ADSection");
                    ret = false;
                }
                else
                {
                    _domains    = adSection.Domains;
                    _properties = adSection.Props;
                }

                DepotsSection depotsConfigSection = ConfigurationManager.GetSection("Depots") as DepotsSection;
                if (depotsConfigSection == null)
                {
                    AcDebug.Log("Error in Program.initAppConfigData creating DepotsSection");
                    ret = false;
                }
                else
                {
                    _selDepots = depotsConfigSection.Depots;
                }
            }

            catch (ConfigurationErrorsException exc)
            {
                Process       currentProcess = Process.GetCurrentProcess();
                ProcessModule pm             = currentProcess.MainModule;
                AcDebug.Log($"Invalid data in {pm.ModuleName}.config{Environment.NewLine}{exc.Message}");
                ret = false;
            }

            return(ret);
        }
Ejemplo n.º 9
0
        private void GetNetworks()
        {
            cmbNetworks.Items.Clear();
            cmbNetworks.Items.Add(StringValue.LocalNetwork);
            try
            {
                //Get Domain Name
                Forest           hostForest = Forest.GetCurrentForest();
                DomainCollection domains    = hostForest.Domains;

                foreach (Domain domain in domains)
                {
                    cmbNetworks.Items.Add(domain.Name);
                }
            }
            catch
            {
                //fail silently because it's not on A/D
            }
        }
Ejemplo n.º 10
0
        public void GetDomainsInForest()
        {
            Domain dRoot = forest.RootDomain;

            try
            {
                DomainCollection dc = forest.Domains;
                foreach (Domain d in dc)
                {
                    Console.WriteLine("\t\t{0} {1}", d.Name.Equals(dRoot.Name) ? "*" : "-", d.Name);
                }
            }
            catch (ActiveDirectoryOperationException e)
            {
                Console.WriteLine("Error: {0}", e);
            }
            catch (ActiveDirectoryServerDownException e)
            {
                Console.WriteLine("Server Down Error: {0}", e);
            }
        }
Ejemplo n.º 11
0
        public override string[] Execute(ParsedArgs args)
        {
            try
            {
                Amass            forestDomains    = new Amass();
                Forest           theCurrentForest = forestDomains.GetForestObject();
                DomainCollection forestDomainList = theCurrentForest.Domains;

                List <string> result = new List <string>();

                foreach (Domain internalDomain in forestDomainList)
                {
                    result.Add(internalDomain.Name);
                }

                return(result.ToArray());
            }
            catch (Exception e)
            {
                return(new string[] { "[X] Failure to enumerate info - " + e });
            }
        }
Ejemplo n.º 12
0
        public static List <string> GetADList()
        {
            List <string> adList = new List <string>();

            try
            {
                Forest           currentForest = Forest.GetCurrentForest();
                DomainCollection domains       = currentForest.Domains;
                foreach (Domain objDomain in domains)
                {
                    foreach (DomainController controler in objDomain.DomainControllers)
                    {
                        adList.Add(controler.Name.Split('.')[0]);
                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }

            return(adList);
        }
Ejemplo n.º 13
0
        public List <string> EnumerateDomains(string userName)
        {
            List <string> alDomains = new List <string>();

            try
            {
                Forest           currentForest = Forest.GetCurrentForest();
                DomainCollection myDomains     = currentForest.Domains;

                foreach (Domain objDomain in myDomains)
                {
                    alDomains.Add(objDomain.Name);
                }


                IsDomainAdministrator = IsAdministrator(alDomains.FirstOrDefault(), userName);

                return(alDomains);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 14
0
        public static Hashtable getMembers(Hashtable members, string filter_, string label,
                                           CheckedListBox SVDBox, Func <string, bool> report)
        {
            if (members != null)
            {
                return(members);
            }
            members = new Hashtable();
            new List <string>(SVDBox.Items.OfType <string>()).AsParallel().ForAll(SVD_ =>
            {
                Random rand = new Random(); int retry = AD_Retry; while (retry-- > 0)
                {
                    try
                    {
                        string SVD = SVD_;
                        if (SVD.IndexOf('-') >= 0)
                        {
                            SVD = SVD.Substring(SVD.IndexOf('-') + 1);
                        }
                        string filter = "(&(ObjectClass=user)(!ObjectClass=computer)(employeeID=*)"
                                        //+ "(!userAccountControl=514)(!userAccountControl=66050)"
                                        //+ "(|(l=" + SVD + ")(st=" + SVD + "))"
                                        + (filter_ == null ? "" : filter_) + ")";

                        DomainCollection dc = Forest.GetCurrentForest().Domains;
                        Domain[] domains    = new Domain[dc.Count]; dc.CopyTo(domains, 0);
                        string current      = Domain.GetCurrentDomain().Name;
                        domains.All(domain =>
                        {
                            Random rand2 = new Random(); int retry2 = AD_Retry; while (retry2-- > 0)
                            {
                                try
                                {
                                    DirectoryEntry site = null;
                                    try
                                    {
                                        DirectoryEntry de = domain.GetDirectoryEntry();

                                        site = de.Children.Find("OU=" + SVD);
                                    }
                                    catch (Exception e)
                                    {
                                        ;
                                    }
                                    SearchResultCollection col = site == null ? null : new DirectorySearcher(site, filter,
                                                                                                             new string[] { "distinguishedName", "displayName", "department", "title" },
                                                                                                             SearchScope.Subtree).FindAll();
                                    //Console.WriteLine(domain + "/" + SVD + " -> " + (col == null ? 0 : col.Count));
                                    List <string> newmembers = new List <string>();
                                    if (col != null)
                                    {
                                        foreach (SearchResult r in col)
                                        {
                                            string dn    = r.Properties["distinguishedName"].Count > 0 ? r.Properties["distinguishedName"][0].ToString().ToLower() : "";
                                            string disp  = r.Properties["displayName"].Count > 0 ? r.Properties["displayName"][0].ToString() : "";
                                            string dpt   = r.Properties["department"].Count > 0 ? r.Properties["department"][0].ToString() : "";
                                            string title = r.Properties["title"].Count > 0 ? r.Properties["title"][0].ToString() : "";
                                            if (!dn.Contains("terminated") &&
                                                !dn.Contains("system-accounts"))
                                            {
//Console.WriteLine(domain + "/" + SVD + "/" + dpt + "/" + title + " " + disp);
                                                newmembers.Add(disp);
                                            }
                                        }
                                    }
                                    lock (members)
                                    {
                                        List <string> SVDMembers;
                                        if (members.Contains(SVD_))
                                        {
                                            if (members[SVD_] == errorList)
                                            {
                                                SVDMembers = errorList;
                                            }
                                            else
                                            {
                                                SVDMembers = (List <string>)members[SVD_];
                                                SVDMembers.AddRange(newmembers);
                                            }
                                        }
                                        else
                                        {
                                            SVDMembers = newmembers;
                                        }
                                        //Console.WriteLine("\t" + SVD + " in " + domain.Name + ": " + DomainCount + ", in total:" + SVDCount);
                                        if (members.Contains(SVD_))
                                        {
                                            members.Remove(SVD_);
                                        }
                                        members.Add(SVD_, SVDMembers);
                                    }
                                    retry2 = 0;
                                    return(true);
                                }
                                catch (Exception ee)
                                {
                                    if (retry2 <= 0)
                                    {
                                        if (report != null)
                                        {
                                            report(label + " " + SVD_ + "... Error:" + ee.Message);
                                        }
                                        lock (members)
                                        {
                                            if (members.Contains(SVD_))
                                            {
                                                members.Remove(SVD_);
                                            }
                                            members.Add(SVD_, errorList);
                                        }
                                    }
                                    else
                                    {
                                        if (report != null)
                                        {
                                            report("Oups" + (AD_Retry - retry2) + "! I couldn't get " + label + " for " + SVD_);
                                        }
                                        Thread.Sleep(1000 * rand2.Next(AD_Wait, AD_Wait * (AD_Retry - retry2)));
                                    }
                                }
                            }
                            return(false);
                        });
                        if (report != null &&
                            ((List <string>)members[SVD_]).Count > 0
                            )
                        {
                            report(label + " " + SVD_ + "... "
                                   + (((List <string>)members[SVD_]).Count == 0 ? "none" : ((List <string>)members[SVD_]).Aggregate((x, y) => x + "; " + y))
                                   );
                        }
                        retry = 0;
                    }
                    catch (Exception e)
                    {
                        if (retry == 0)
                        {
                            if (report != null)
                            {
                                report(label + " " + SVD_ + "... Error:" + e.Message);
                            }
                            lock (members)
                            {
                                if (members.Contains(SVD_))
                                {
                                    members.Remove(SVD_);
                                }
                                members.Add(SVD_, errorList);
                            }
                        }
                        else
                        {
                            if (report != null)
                            {
                                report("Oups" + (AD_Retry - retry) + "! I couldn't get " + label + " for " + SVD_);
                            }
                            Thread.Sleep(1000 * rand.Next(AD_Wait, AD_Wait * (AD_Retry - retry)));
                        }
                    }
                }
            });
            return(members);
        }
Ejemplo n.º 15
0
        public static Hashtable getCounts(Hashtable counts, string filter_, string label,
                                          CheckedListBox SVDBox, Func <string, bool> report)
        {
            if (counts != null)
            {
                return(counts);
            }
            counts = new Hashtable();
            new List <string>(SVDBox.Items.OfType <string>()).AsParallel().ForAll(SVD_ =>
            {
                Random rand = new Random(); int retry = AD_Retry; while (retry-- > 0)
                {
                    try
                    {
                        string SVD = SVD_;
                        if (SVD.IndexOf('-') >= 0)
                        {
                            SVD = SVD.Substring(SVD.IndexOf('-') + 1);
                        }
                        string filter = "(&(ObjectClass=user)(!ObjectClass=computer)(employeeID=*)"
                                        //+ "(!userAccountControl=514)(!userAccountControl=66050)"
                                        + "(|(l=" + SVD + ")(st=" + SVD + "))"
                                        + (filter_ == null ? "" : filter_) + ")";

                        DomainCollection dc = Forest.GetCurrentForest().Domains;
                        Domain[] domains    = new Domain[dc.Count]; dc.CopyTo(domains, 0);
                        string current      = Domain.GetCurrentDomain().Name;
                        domains.All(domain =>
                        {
                            Random rand2 = new Random(); int retry2 = AD_Retry; while (retry2-- > 0)
                            {
                                try
                                {
                                    SearchResultCollection col = new DirectorySearcher(domain.GetDirectoryEntry(), filter,
                                                                                       new string[] { "distinguishedName" }, SearchScope.Subtree).FindAll();
                                    //int DomainCount = col.Count;
                                    int DomainCount = 0;
                                    foreach (SearchResult r in col)
                                    {
                                        string dn = r.Properties["distinguishedName"].Count > 0 ? r.Properties["distinguishedName"][0].ToString().ToLower() : "";
                                        if (!dn.Contains("terminated"))
                                        {
                                            DomainCount++;
                                        }
                                    }
                                    lock (counts)
                                    {
                                        int SVDCount = counts.Contains(SVD_) ? ((int)counts[SVD_] == -1 ? -1 : (int)counts[SVD_] + DomainCount) : DomainCount;
//Console.WriteLine("\t" + SVD + " in " + domain.Name + ": " + DomainCount + ", in total:" + SVDCount);
                                        if (counts.Contains(SVD_))
                                        {
                                            counts.Remove(SVD_);
                                        }
                                        counts.Add(SVD_, SVDCount);
                                    }
                                    retry2 = 0;
                                    return(true);
                                }
                                catch (Exception ee)
                                {
                                    if (retry2 <= 0)
                                    {
                                        if (report != null)
                                        {
                                            report(SVD_ + "-" + label + "=Error:" + ee.Message);
                                        }
                                        lock (counts)
                                        {
                                            if (counts.Contains(SVD_))
                                            {
                                                counts.Remove(SVD_);
                                            }
                                            counts.Add(SVD_, -1);
                                        }
                                    }
                                    else
                                    {
                                        if (report != null)
                                        {
                                            report("Oups" + (AD_Retry - retry2) + "! I couldn't get " + label + " for " + SVD_);
                                        }
                                        Thread.Sleep(1000 * rand2.Next(AD_Wait, AD_Wait * (AD_Retry - retry2)));
                                    }
                                }
                            }
                            return(false);
                        });
                        if (report != null)
                        {
                            report(SVD_ + "-" + label + "=" + counts[SVD_]);
                        }
                        retry = 0;
                    }
                    catch (Exception e)
                    {
                        if (retry == 0)
                        {
                            if (report != null)
                            {
                                report(SVD_ + "-" + label + "=Error:" + e.Message);
                            }
                            lock (counts)
                            {
                                if (counts.Contains(SVD_))
                                {
                                    counts.Remove(SVD_);
                                }
                                counts.Add(SVD_, -1);
                            }
                        }
                        else
                        {
                            if (report != null)
                            {
                                report("Oups" + (AD_Retry - retry) + "! I couldn't get " + label + " for " + SVD_);
                            }
                            Thread.Sleep(1000 * rand.Next(AD_Wait, AD_Wait * (AD_Retry - retry)));
                        }
                    }
                }
            });
            return(counts);
        }
Ejemplo n.º 16
0
        public static void SetBreaks(this Animal animal, IEnumerable <AnimalBreak> items)
        {
            DomainCollection <AnimalBreak> dc = new DomainCollection <AnimalBreak>(BreaksProperty, items);

            animal.SetValue(BreaksProperty, dc);
        }
Ejemplo n.º 17
0
        public static void SetEyeCounts(this Animal animal, IEnumerable <decimal> items)
        {
            DomainCollection <decimal> dc = new DomainCollection <decimal>(EyeCountsProperty, items);

            animal.SetValue(EyeCountsProperty, dc);
        }
Ejemplo n.º 18
0
        public bool ADRefresh(Tree <ADNode> tree)
        {
            bool ret = true;

            if (tree.shown())
            {
                tree.GUI.update(tree.tree, true);
            }
            if (tree.depth > 0 && tree.depth2 >= tree.depth)
            {
                try
                {
                    DomainCollection dc      = Forest.GetCurrentForest().Domains;
                    Domain[]         domains = new Domain[dc.Count]; dc.CopyTo(domains, 0);
                    domains.ToArray().AsParallel().ForAll(domain =>
                    {
                        try
                        {
                            ADNode item   = new ADNode(null, tree, domain.GetDirectoryEntry(), 1);
                            TreeNode node = new TreeNode(item.Name, 2, 3);
                            item.node     = node;
                            tree.item2node[tree.node2item[node] = item] = node;
                            //Console.WriteLine(domain.GetDirectoryEntry().Name + " " + item.level + "/" + tree.depth2);


                            if (tree.shown())
                            {
                                tree.GUI.set(tree.count, "" + tree.node2item.Count);
                            }
                            if (tree.shown())
                            {
                                tree.GUI.add(tree.tree, node);
                            }
                            if (tree.shown())
                            {
                                tree.GUI.add(tree.list, item.Name);
                            }
                            if (!ADRefresh(tree, node, item, false))
                            {
                                ret = false;
                            }
                        }
                        catch (Exception e)
                        {
                            ret = false;
                            Console.WriteLine("AD Error: Domain " + domain + ": " + e.ToString());
                        }
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine("AD Error: " + e.ToString());
                    ret = false;
                }
            }
            if (tree.shown())
            {
                tree.GUI.sort(tree.tree);
            }
            if (tree.shown())
            {
                foreach (TreeNode node in tree.tree.Nodes)
                {
                    tree.GUI.expand(node, false);
                }
            }
            if (tree.shown())
            {
                tree.GUI.update(tree.tree, false);
            }
            return(ret);
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Pls key in your Login ID");
            var loginid = Console.ReadLine();

            Console.WriteLine("Pls key in your Password");
            var password = ReadPassword();

            Console.Write("Your Password is:" + password);
            Console.ReadLine();



            DomainCollection dc = Forest.GetCurrentForest().Domains;

            foreach (Domain d in dc)
            {
                Console.WriteLine(d.Name);
            }

            var doExit = false;

            while (doExit != true)
            {
                string ldapFilter = "";
                string ou         = "";
                Console.WriteLine("Choose the OU you want to Search or Function.\n");
                Console.WriteLine("1 - Nellis");
                Console.WriteLine("2 - Arcata Way");
                Console.WriteLine("3 - Computer Name");
                Console.WriteLine("S - Shutdown Computer");
                Console.WriteLine("R - Reboot Computer");

                Console.WriteLine("Q - Quit");

                char myChoice = Console.ReadKey(true).KeyChar;

                switch (myChoice)
                {
                case '1':
                    ou         = "LDAP://OU=Arcata Way,OU=NTTR,OU=Workstations,DC=jt3,DC=com";
                    ldapFilter = "(&(objectClass=computer))";
                    break;

                case '2':
                    ou         = "LDAP://OU=Nellis,OU=NTTR,OU=Workstations,DC=jt3,DC=com";
                    ldapFilter = "(&(objectClass=computer))";
                    break;

                case '3':
                    ldapFilter = "(&(objectClass=computer)(cn=LSV-VM-TRN*))";
                    break;

                case 'S':
                case 's':
                    DoHostCommand("LSV-VM-TRN1", "Shutdown");
                    Console.Clear();
                    continue;

                case 'R':
                case 'r':
                    DoHostCommand("LSV-VM-TRN0", "Reboot");
                    Console.Clear();
                    continue;

                case 'Q':
                case 'q':
                    doExit = true;
                    continue;

                default:
                    Console.WriteLine("{0} is not a valid choice", myChoice);
                    continue;
                }
                DirectoryEntry entry = new DirectoryEntry("LDAP://JT3-DC-ARC.JT3.com")
                {
                    Path = ou,
                    AuthenticationType = AuthenticationTypes.Secure
                };

                using (DirectorySearcher ds = new DirectorySearcher(entry))
                {
                    ds.PropertiesToLoad.Add("name");
                    ds.Filter            = ldapFilter;
                    ds.Sort.Direction    = SortDirection.Ascending;
                    ds.Sort.PropertyName = "name";

                    SearchResultCollection results = ds.FindAll();

                    int itemCount = results.Count;

                    foreach (SearchResult result in results)
                    {
                        Console.WriteLine("{0}", result.Properties["name"][0]);
                    }
                    Console.WriteLine("Computer Count: {0}", itemCount);
                    Console.ReadKey();
                    Console.Clear();
                }
            }
            Environment.Exit(0);
        }
Ejemplo n.º 20
0
        public static void SetWheels(this Animal animal, IEnumerable <AnimalWheel> items)
        {
            DomainCollection <AnimalWheel> dc = new DomainCollection <AnimalWheel>(WheelsProperty, items);

            animal.SetValue(WheelsProperty, dc);
        }
Ejemplo n.º 21
0
        public static void SetMyColors(this Animal animal, IEnumerable <AnimalColor> items)
        {
            DomainCollection <AnimalColor> dc = new DomainCollection <AnimalColor>(MyColorsProperty, items);

            animal.SetValue(MyColorsProperty, dc);
        }
        /// <summary>
        /// Initialize information from PTF config
        /// </summary>
        /// <param name="testSite"></param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);

            Site.Log.Add(LogEntryKind.Debug, "Read common properties from PTF configure file.");

            AllowBreakEnvironment    = GetBoolProperty(propertyGroup + "AllowBreakEnvironment");
            DomainFunctionLevel      = GetEnumProperty <DomainFunctionLevel>(propertyGroup + "DomainFunctionLevel");
            DomainAdminGroup         = GetProperty(propertyGroup + "DomainAdminGroup");
            DomainAdministratorName  = GetProperty(propertyGroup + "DomainAdministratorName", true);
            DomainUserPassword       = GetProperty(propertyGroup + "DomainUserPassword", true);
            PrimaryDomainDnsName     = GetProperty(propertyGroup + "PrimaryDomain.DNSName", true);
            PrimaryDomainNetBiosName = GetProperty(propertyGroup + "PrimaryDomain.NetBiosName" ?? (PrimaryDomainDnsName.Split('.'))[0].ToString());
            PrimaryDomainSrvGUID     = GetProperty(propertyGroup + "PrimaryDomain.ServerGUID", true);
            PrimaryDomainSID         = GetProperty(propertyGroup + "PrimaryDomain.SID", true);
            PDCNetbiosName           = GetProperty(propertyGroup + "WritableDC1.NetbiosName", true);
            PDCPassword            = GetProperty(propertyGroup + "WritableDC1.Password", true);
            PDCIPAddress           = GetProperty(propertyGroup + "WritableDC1.IPAddress");
            PDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "WritableDC1.OSVersion");
            PDCIsWindows           = (PDCOSVersion == ServerVersion.NonWin ? false : true);
            SDCNetbiosName         = GetProperty(propertyGroup + "WritableDC2.NetbiosName");
            SDCPassword            = GetProperty(propertyGroup + "WritableDC2.Password");
            SDCIPAddress           = GetProperty(propertyGroup + "WritableDC2.IPAddress");
            SDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "WritableDC2.OSVersion");
            SDCIsWindows           = (SDCOSVersion == ServerVersion.NonWin ? false : true);
            RODCNetbiosName        = GetProperty(propertyGroup + "RODC.NetbiosName");
            RODCPassword           = GetProperty(propertyGroup + "RODC.Password");
            RODCIPAddress          = GetProperty(propertyGroup + "RODC.IPAddress");
            RODCOSVersion          = GetEnumProperty <ServerVersion>(propertyGroup + "RODC.OSVersion");
            RODCIsWindows          = (RODCOSVersion == ServerVersion.NonWin ? false : true);
            ChildDomainDnsName     = GetProperty(propertyGroup + "ChildDomain.DNSName");
            ChildDomainNetBiosName = GetProperty(propertyGroup + "ChildDomain.NetBiosName") ?? (ChildDomainDnsName.Split('.'))[0].ToString();
            CDCNetbiosName         = GetProperty(propertyGroup + "CDC.NetbiosName");
            CDCIPAddress           = GetProperty(propertyGroup + "CDC.IPAddress");
            CDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "CDC.OSVersion");
            CDCIsWindows           = (CDCOSVersion == ServerVersion.NonWin ? false : true);
            TrustDomainDnsName     = GetProperty(propertyGroup + "TrustDomain.DNSName");
            TrustDomainNetBiosName = GetProperty(propertyGroup + "TrustDomain.NetBiosName") ?? (TrustDomainDnsName.Split('.'))[0].ToString();
            TDCNetbiosName         = GetProperty(propertyGroup + "TDC.NetbiosName");
            TDCIPAddress           = GetProperty(propertyGroup + "TDC.IPAddress");
            TDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "TDC.OSVersion");
            TDCIsWindows           = (TDCOSVersion == ServerVersion.NonWin ? false : true);
            DMNetbiosName          = GetProperty(propertyGroup + "DM.NetbiosName");
            DMPassword             = GetProperty(propertyGroup + "DM.Password");
            DMOldPassword          = GetProperty(propertyGroup + "DM.OldPassword");
            DMIPAddress            = GetProperty(propertyGroup + "DM.IPAddress");
            ENDPOINTNetbiosName    = GetProperty(propertyGroup + "ENDPOINT.NetbiosName", true);
            ENDPOINTPassword       = GetProperty(propertyGroup + "ENDPOINT.Password", true);
            ENDPOINTOldPassword    = GetProperty(propertyGroup + "ENDPOINT.OldPassword");
            ENDPOINTIPAddress      = GetProperty(propertyGroup + "ENDPOINT.IPAddress");
            ADLDSInstanceName      = GetProperty(propertyGroup + "ADLDSInstanceName");
            ADDSPortNum            = GetProperty(propertyGroup + "ADDSPortNum");
            ADLDSPortNum           = GetProperty(propertyGroup + "ADLDSPortNum");
            ADLDSSSLPortNum        = GetProperty(propertyGroup + "ADLDSSSLPortNum");
            LDSApplicationNC       = GetProperty(propertyGroup + "LDSApplicationNC");
            ClientUserName         = GetProperty(propertyGroup + "ClientUserName");
            ClientUserPassword     = GetProperty(propertyGroup + "ClientUserPassword");

            Site.Log.Add(LogEntryKind.Debug, "Read common properties from PTF configure file completed.");
            Site.Log.Add(LogEntryKind.Debug, "Construct common classes for domain, domain controller and endpoint.");

            domains           = new DomainCollection();
            domainControllers = new DomainControllerCollection();

            Domain primaryDomain = new Domain(PrimaryDomainDnsName, PrimaryDomainNetBiosName);

            domains.Add(primaryDomain);
            DomainController pdc  = new DomainController(primaryDomain, PDCNetbiosName, PDCIPAddress, (ServerVersion)PDCOSVersion);
            DomainController sdc  = new DomainController(primaryDomain, SDCNetbiosName, SDCIPAddress, (ServerVersion)SDCOSVersion);
            DomainController rodc = new DomainController(primaryDomain, RODCNetbiosName, RODCIPAddress, (ServerVersion)RODCOSVersion);

            domainControllers.Add(pdc);
            domainControllers.Add(sdc);
            domainControllers.Add(rodc);

            if (string.IsNullOrEmpty(ChildDomainDnsName))
            {
                Site.Log.Add(LogEntryKind.Warning, "ChildDomainDnsName is not configured in PTF, indicating the environment has no child domain.");
            }
            else
            {
                Domain           childDomain = new Domain(ChildDomainDnsName);
                DomainController cdc         = new DomainController(childDomain, CDCNetbiosName, CDCIPAddress, (ServerVersion)CDCOSVersion);
                domains.Add(childDomain);
                domainControllers.Add(cdc);
            }

            if (string.IsNullOrEmpty(TrustDomainDnsName))
            {
                Site.Log.Add(LogEntryKind.Warning, "TrustDomainDnsName is not configured in PTF, indicating the environment has no trusted domain.");
            }
            else
            {
                Domain           trustDomain = new Domain(TrustDomainDnsName);
                DomainController tdc         = new DomainController(trustDomain, TDCNetbiosName, TDCIPAddress, (ServerVersion)TDCOSVersion);
                domains.Add(trustDomain);
                domainControllers.Add(tdc);
            }

            Computer endpoint = new Computer(primaryDomain, ENDPOINTNetbiosName, ENDPOINTIPAddress);

            domainMembers = new ComputerCollection();
            domainMembers.Add(endpoint);

            Site.Log.Add(LogEntryKind.Debug, "Construct common classes for domain, domain controller and endpoint completed.");
        }
        public static string[] GetAvailableDomains(bool includeLocalMachine, bool includeFullName)
        {
            int domainsCount         = 1;
            DomainCollection domains = null;

            try
            {
                domains = Forest.GetCurrentForest().Domains;

                domainsCount += domains.Count;
            }
            catch (Exception exc)
            {
                Log.WriteWarning("Failed to obtain available domains. Details : {0}", exc.Message);
            }

            List <string> domainNames = new List <string>(domainsCount);

            if (includeLocalMachine)
            {
                domainNames.Add(Environment.MachineName);

                //Log.WriteInfo("Added local machine name : [{0}]", Environment.MachineName);
            }

            string domainName;

            if (domains != null && domains.Count > 0)
            {
                foreach (Domain domain in domains)
                {
                    if (includeFullName)
                    {
                        domainName = domain.Name;

                        //Log.WriteInfo("Added full domain name : [{0}]", domainName);
                    }
                    else
                    {
                        domainName = domain.GetDirectoryEntry().Properties["name"].Value.ToString();

                        //Log.WriteInfo("Added short domain name : [{0}]", domainName);
                    }

                    domainNames.Add(domainName);
                }
            }
            else
            {
                try
                {
                    ManagementObjectSearcher searcher =
                        new ManagementObjectSearcher("SELECT Domain FROM Win32_ComputerSystem");

                    searcher.Options.ReturnImmediately = true;
                    searcher.Options.Rewindable        = true;
                    searcher.Options.DirectRead        = true;

                    foreach (ManagementObject oManagementObj in searcher.Get())
                    {
                        object domain = oManagementObj.GetPropertyValue("Domain");

                        if (domain != null)
                        {
                            domainName = domain.ToString();

                            domainNames.Add(domainName);

                            //Log.WriteInfo("Added domain name : [{0}]", domainName);
                        }

                        break;
                    }
                }
                catch (Exception exc)
                {
                    Log.WriteWarning("Failed to obtain available domains. Details : {0}", exc.Message);
                }
            }

            return(domainNames.ToArray());
        }
Ejemplo n.º 24
0
        private void Reenabler_Load(object sender, EventArgs e)
        {
            //Console.WriteLine("form load");
            domainBox.Items.Clear();

            if (parent != null)
            {
                domainBox.Items.Add(parent.domainBox.SelectedItem);
                domainBox.SelectedItem = parent.domainBox.SelectedItem;
            }
            else
            {
                try
                {
                    DomainCollection dc      = Forest.GetCurrentForest().Domains;
                    Domain[]         domains = new Domain[dc.Count]; dc.CopyTo(domains, 0);
                    domainBox.Items.AddRange(domains);
                    domainBox.Text = Domain.GetCurrentDomain().Name;
                }
                catch (Exception ee)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            if (targetDomain != null)
            {
                domainBox.Text = targetDomain;
            }

            OUBox.Items.Clear();
            if (parent != null)
            {
                OUBox.Items.AddRange(parent.OUBox.Items.OfType <string>().ToList().ToArray <string>());
                startBox.Text = OUBox.Text = parent.OUBox.Text;
            }
            else
            {
                string           domain  = domainBox.SelectedItem.ToString();
                DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domain);
                Domain           d       = Domain.GetDomain(context);
                DirectoryEntry   de      = d.GetDirectoryEntry();

                DirectorySearcher ds = new DirectorySearcher(de, "(objectClass=organizationalUnit)", null, SearchScope.OneLevel);
                ds.PropertiesToLoad.Add("name");

                foreach (SearchResult r in ds.FindAll())
                {
                    string ou    = r.Properties["name"][0].ToString();
                    bool   match = false; try
                    {
                        match = System.Text.RegularExpressions.Regex.IsMatch(ou, AuditSec.defaultOUMask,
                                                                             System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine("OU=" + ou + " IsMatch Regex=" + AuditSec.defaultOUMask + " = " + ee.Message);
                    }
                    if (match)
                    {
                        OUBox.Items.Add(ou);
                    }
                    //Console.WriteLine("OU=" + ou + " IsMatch Regex=" + OUMaskBox.Text + " = " + match);
                }

                string me = new DirectorySearcher("(&(ObjectClass=user)(sAMAccountName="
                                                  + UserPrincipal.Current.SamAccountName + "))")
                            .FindOne().GetDirectoryEntry().Properties["DistinguishedName"].Value.ToString();
                foreach (string s in me.Split(',').Reverse())
                {
                    string[] t = s.Split(new char[] { '=' }, 2);
                    if (t[0].Equals("OU"))
                    {
                        OUBox.Text = t[1]; break;
                    }
                }
            }

            OUBox_SelectionChangeCommitted(sender, e);
            change = true;
            timer1_Tick(sender, e);

            if (targetMachine != null)
            {
                OUBox.SelectedItem = null; OUBox.Text = "";
                startBox.Text      = targetMachine;
            }
        }
Ejemplo n.º 25
0
    public DataTable LoadDomains()
    {
        DomainCollection   domColl   = null;
        XMDomainCollection xmDomains = new XMDomainCollection();

        DataTable domTable = new DataTable();

        domTable.Columns.Add("id", typeof(string));
        domTable.Columns.Add("name", typeof(string));
        domTable.Columns.Add("type", typeof(string));

        // xmail
        if (_isServerExist && AdminPanelUtils.IsSuperAdmin(Page.Session, (Page as DefaultPage).Settings))
        {
            xmDomains = XMDomain.GetDomains();
            XMDomainCollection xmDomsCust = XMDomain.GetCustomDomainins();
            xmDomains.Add(xmDomsCust);
        }

        // webmail
        if (_isWebMailExist)
        {
            try
            {
                if (AdminPanelUtils.IsSuperAdmin(Page.Session, (Page as DefaultPage).Settings))
                {
                    if (_isServerExist)
                    {
                        domColl = Domain.GetDomains();
                    }
                    else
                    {
                        domColl = Domain.GetDomains(new short[] { (short)IncomingMailProtocol.Pop3, (short)IncomingMailProtocol.Imap4 });
                    }
                }
                else
                {
                    domColl = Subadmin.GetDomains(adminID);
                }

                foreach (XMDomain xmDom in xmDomains)
                {
                    Domain dom = domColl.GetItem(xmDom.Name);
                    if (dom == null)
                    {
                        WebmailSettings settings = new WebMailSettingsCreator().CreateWebMailSettings();
                        Domain          new_dom  = new Domain(0, xmDom.Name, IncomingMailProtocol.WMServer, settings.WmServerHost, 143, settings.WmServerHost, settings.XMailSmtpPort, false);
                        new_dom.Save();
                        xmDom.Type = AdminPanelConstants.UserType.xma;
                    }
                }

                foreach (Domain dom in domColl)
                {
                    XMDomain xmDomain = xmDomains.GetItem(dom.Name);
                    if (xmDomain != null)
                    {
                        xmDomains.Remove(xmDomain);
                        xmDomains.Add(new XMDomain(dom.Name, dom.Name, dom.MailIncomingProtocol == IncomingMailProtocol.WMServer ? AdminPanelConstants.UserType.xma : AdminPanelConstants.UserType.wm));
                    }
                    else
                    {
                        xmDomains.Add(new XMDomain(dom.Name, dom.Name, dom.MailIncomingProtocol == IncomingMailProtocol.WMServer ? AdminPanelConstants.UserType.xma : AdminPanelConstants.UserType.wm));
                        if (_isServerExist && dom.MailIncomingProtocol == IncomingMailProtocol.WMServer)
                        {
                            XMDomain.AddDomain(dom.Name);
                        }
                    }
                }

                foreach (XMDomain xmDomain in xmDomains)
                {
                    domTable.Rows.Add(xmDomain.Name, xmDomain.Name, xmDomain.Type);
                }
            }
            catch (Exception ex)
            {
                AdminPanelUtils.SetPageErrorMessage(this.Page, (ex.InnerException != null ? ex.InnerException.Message : ex.Message));
                Log.WriteException(ex);
            }
        }
        return(domTable);
    }
Ejemplo n.º 26
0
        private void ReflectTestMethod(
            RunInvokerTree tree,
            RunInvokerVertex parent,
            object fixture,
            MethodInfo method,
            IgnoreAttribute ignore,
            ExplicitAttribute expl)
        {
            // Check if fixture/method is ignored/explicit
            if (ignore == null && TypeHelper.HasCustomAttribute(method, typeof(IgnoreAttribute)))
            {
                ignore = TypeHelper.GetFirstCustomAttribute(method, typeof(IgnoreAttribute)) as IgnoreAttribute;
            }
            if (expl == null && TypeHelper.HasCustomAttribute(method, typeof(ExplicitAttribute)))
            {
                expl = TypeHelper.GetFirstCustomAttribute(method, typeof(ExplicitAttribute)) as ExplicitAttribute;
            }

            if (ignore != null)
            {
                // Do not generate unnecessary test cases
                IgnoredLoadingRunInvoker invoker = new IgnoredLoadingRunInvoker(this, method, ignore.Description);
                tree.AddChild(parent, invoker);
            }
            else if (expl != null)
            {
                // Do not generate unnecessary test cases
                IgnoredLoadingRunInvoker invoker = new IgnoredLoadingRunInvoker(this, method, expl.Description);
                tree.AddChild(parent, invoker);
            }
            else
            {
                CombinatorialTestAttribute testAttribute = TypeHelper.GetFirstCustomAttribute(method, typeof(CombinatorialTestAttribute))
                                                           as CombinatorialTestAttribute;

                ParameterInfo[] parameters = method.GetParameters();
                if (parameters.Length == 0)
                {
                    Exception ex = new Exception("No parameters");
                    MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method);
                    tree.AddChild(parent, invoker);
                    return;
                }

                // create the models
                DomainCollection domains        = new DomainCollection();
                Type[]           parameterTypes = new Type[parameters.Length];
                int index = 0;
                foreach (ParameterInfo parameter in parameters)
                {
                    parameterTypes[index] = parameter.ParameterType;

                    DomainCollection pdomains = new DomainCollection();
                    foreach (UsingBaseAttribute usingAttribute in parameter.GetCustomAttributes(typeof(UsingBaseAttribute), true))
                    {
                        try
                        {
                            usingAttribute.GetDomains(pdomains, parameter, fixture);
                        }
                        catch (Exception ex)
                        {
                            Exception pex = new Exception("Failed while loading domains from parameter " + parameter.Name,
                                                          ex);
                            MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, pex, method);
                            tree.AddChild(parent, invoker);
                        }
                    }
                    if (pdomains.Count == 0)
                    {
                        Exception ex = new Exception("Could not find domain for argument " + parameter.Name);
                        MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method);
                        tree.AddChild(parent, invoker);
                        return;
                    }
                    domains.Add(Domains.ToDomain(pdomains));

                    index++;
                }

                // get the validator method if any
                MethodInfo validator = null;
                if (testAttribute.TupleValidatorMethod != null)
                {
                    validator = fixture.GetType().GetMethod(testAttribute.TupleValidatorMethod, parameterTypes);
                    if (validator == null)
                    {
                        Exception ex = new Exception("Could not find validator method " + testAttribute.TupleValidatorMethod);
                        MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method);
                        tree.AddChild(parent, invoker);
                        return;
                    }
                }

                // we make a cartesian product of all those
                foreach (ITuple tuple in Products.Cartesian(domains))
                {
                    // create data domains
                    DomainCollection tdomains = new DomainCollection();
                    for (int i = 0; i < tuple.Count; ++i)
                    {
                        IDomain dm = (IDomain)tuple[i];
                        tdomains.Add(dm);
                    }

                    // computing the pairwize product
                    foreach (ITuple ptuple in testAttribute.GetProduct(tdomains))
                    {
                        if (validator != null)
                        {
                            bool isValid = (bool)validator.Invoke(fixture, ptuple.ToObjectArray());
                            if (!isValid)
                            {
                                continue;
                            }
                        }

                        TupleRunInvoker invoker  = new TupleRunInvoker(this, method, tuple, ptuple);
                        IRunInvoker     dinvoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker);
                        tree.AddChild(parent, dinvoker);
                    }
                }
            }
        }
Ejemplo n.º 27
0
 public void AddItems(IEnumerable <Permission> items)
 {
     ItemsImpl = new DomainCollection <Permission>(ItemsProperty, items);
 }
Ejemplo n.º 28
0
 internal void SetPermissions(IEnumerable <Permission> items)
 {
     PermissionsImpl = new DomainCollection <Permission>(Organization.PermissionsProperty, items);
 }
Ejemplo n.º 29
0
 private void RemoveAnimalBreak(AnimalBreak mybreak, DomainCollection <AnimalBreak> breaks)
 {
     breaks.Remove(mybreak);
 }
Ejemplo n.º 30
0
 public Car(Guid id, DomainCollection <CarWheel> wheels)
     : base(id)
 {
     _Wheels = wheels;
     this.OnConstructed();
 }
Ejemplo n.º 31
0
        public void DomainListByKindTest2()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM domain;");

            User user1 = new User(context);

            user1.Username = "******";
            user1.Store();

            User user2 = new User(context);

            user2.Username = "******";
            user2.Store();

            User user3 = new User(context);

            user3.Username = "******";
            user3.Store();

            Domain domain1 = new Domain(context);

            domain1.Identifier = "domain1";
            domain1.Kind       = DomainKind.Hidden;
            domain1.Store();

            Domain domain2 = new Domain(context);

            domain2.Identifier = "domain2";
            domain2.Kind       = DomainKind.Hidden;
            domain2.Store();

            Domain publicDomain = new Domain(context);

            publicDomain.Identifier = "publicDomain";
            publicDomain.Kind       = DomainKind.Public;
            publicDomain.Store();

            Role privateUsageRole = new Role(context);

            privateUsageRole.Identifier = "private";
            privateUsageRole.Store();
            privateUsageRole.GrantToUser(user1, domain1);
            privateUsageRole.GrantToUser(user2, domain2);

            Role grantedRole = new Role(context);

            grantedRole.Identifier = "granted";
            grantedRole.Store();
            grantedRole.GrantToUser(user1, domain2);

            context.StartImpersonation(user1.Id);

            context.ConsoleDebug = true;

            DomainCollection domains = new DomainCollection(context);

            domains.Load();
            Assert.AreEqual(3, domains.Count);
            domains.LoadRestricted();
            Assert.AreEqual(3, domains.Count);
            context.EndImpersonation();

            context.StartImpersonation(user2.Id);
            domains = new DomainCollection(context);
            domains.LoadRestricted();
            Assert.AreEqual(2, domains.Count);
            context.EndImpersonation();

            context.StartImpersonation(user3.Id);
            domains = new DomainCollection(context);
            domains.LoadRestricted();
            Assert.AreEqual(1, domains.Count);
            domains.LoadRestricted(new DomainKind[] { });
            Assert.AreEqual(0, domains.Count);
            context.EndImpersonation();
        }