Esempio n. 1
0
        public void GetAllPolicies(List <Policy> ReturnValue)
        {
            //List<Policy> ReturnValue = new List<Policy>();


            int Current = 0;

            GPMGMTLib.GPM           gpm = new GPMGMTLib.GPM();
            GPMGMTLib.IGPMConstants gpc = gpm.GetConstants();

            GPMGMTLib.IGPMDomain        gpd  = gpm.GetDomain(GetDomainName(), "", gpc.UseAnyDC);
            GPMGMTLib.GPMSearchCriteria gps  = gpm.CreateSearchCriteria();
            GPMGMTLib.IGPMGPOCollection gpoc = gpd.SearchGPOs(gps);

            //GPMGMTLib.GPMSitesContainer gpsc = gpm.GetSitesContainer(GetForest(), GetDomainName(), "", gpc.UseAnyDC);

            string forest = GetForest();
            string domain = GetDomainName();

            foreach (GPMGMTLib.GPMGPO gpItem in gpoc)
            {
                while (CurrentThreads >= MAX_THREADS)
                {
                    Thread.Sleep(100);
                }

                Current++;
                LogProgress(gpoc.Count, Current, gpItem.DisplayName);

                Policy pol;

                int UserSysVolVersion = 0;

                try
                {
                    UserSysVolVersion = gpItem.UserSysvolVersionNumber;
                }
                catch
                {
                }

                pol = new Policy("\\\\" + gpd.DomainController + "\\sysvol\\" + gpd.Domain + "\\Policies\\" + gpItem.ID,
                                 gpItem.ID, gpItem.DisplayName, gpItem.ModificationTime, UserSysVolVersion, true);

                ReturnValue.Add(pol);

                ThreadParameterObj tpo = new ThreadParameterObj();
                tpo.Policy     = pol;
                tpo.GPOPolItem = gpItem;
                tpo.forest     = forest;
                tpo.domain     = GetDomainName();
                tpo.DC         = gpc.UseAnyDC;

                Thread thread = new Thread(this.GetPolicy);
                thread.Start(tpo);
                AddThreadCount(1);
            }

            while (CurrentThreads > 0)
            {
                Thread.Sleep(500);
            }

            return;
        }
Esempio n. 2
0
        private void GetPolicy(object passObj)
        {
            try
            {
                ThreadParameterObj polobj = (ThreadParameterObj)passObj;
                Policy             pol    = polobj.Policy;

                pol.Run();

                GPMGMTLib.GPMGPO name = polobj.GPOPolItem;

                GPMGMTLib.GPM           gpm = new GPMGMTLib.GPM();
                GPMGMTLib.IGPMConstants gpc = gpm.GetConstants();

                GPMGMTLib.IGPMDomain        gpd  = gpm.GetDomain(GetDomainName(), "", polobj.DC);
                GPMGMTLib.GPMSearchCriteria gps  = gpm.CreateSearchCriteria();
                GPMGMTLib.IGPMGPOCollection gpoc = gpd.SearchGPOs(gps);

                GPMGMTLib.GPMSitesContainer gpsc = gpm.GetSitesContainer(polobj.forest, polobj.domain, "", polobj.DC);

                GPMGMTLib.GPMSecurityInfo SecurityInfo = name.GetSecurityInfo();

                foreach (GPMGMTLib.GPMPermission Perm in SecurityInfo)
                {
                    if (Perm.Permission == gpc.permGPOApply)
                    {
                        AssignmentItem assItem = new AssignmentItem();
                        assItem.ParentPolicy = pol;
                        try
                        {
                            assItem.Assignment = Perm.Trustee.TrusteeDomain + "\\" + Perm.Trustee.TrusteeName;

                            pol.AppliedTo.Add(assItem);
                        }
                        catch
                        {
                            assItem.Assignment = Perm.Trustee.TrusteeSid;

                            pol.AppliedTo.Add(assItem);
                        }
                    }
                }

                GPMGMTLib.GPMSearchCriteria SearchLinkage = gpm.CreateSearchCriteria();

                SearchLinkage.Add(gpc.SearchPropertySOMLinks, gpc.SearchOpContains, name);

                foreach (GPMGMTLib.GPMSOM SOM in gpd.SearchSOMs(SearchLinkage))
                {
                    LinkageItem lnkItem = new LinkageItem();
                    lnkItem.ParentPolicy = pol;

                    if (SOM.Type == gpc.somDomain)
                    {
                        lnkItem.Linkage = SOM.Path + "(Domain) - Inheritence Blocked (" + SOM.GPOInheritanceBlocked.ToString() + ")";
                        pol.LinkedTo.Add(lnkItem);
                    }
                    else
                    {
                        lnkItem.Linkage = SOM.Path + "(OU) - Inheritence Blocked (" + SOM.GPOInheritanceBlocked.ToString() + ")";
                        pol.LinkedTo.Add(lnkItem);
                    }
                }


                foreach (GPMGMTLib.GPMSOM SOM in gpsc.SearchSites(SearchLinkage))
                {
                    LinkageItem lnkItem = new LinkageItem();
                    lnkItem.ParentPolicy = pol;
                    lnkItem.Linkage      = SOM.Name + "(Site)";

                    pol.LinkedTo.Add(lnkItem);
                }

                GPMGMTLib.GPMWMIFilter wmifilter = name.GetWMIFilter();

                if (wmifilter != null)
                {
                    Array rawWMIFilters = (Array)wmifilter.GetQueryList();

                    String[] WMIFilters = new String[rawWMIFilters.Length];
                    rawWMIFilters.CopyTo(WMIFilters, 0);


                    foreach (string filter in WMIFilters)
                    {
                        WMIItem wmiItem = new WMIItem();
                        wmiItem.ParentPolicy = pol;
                        wmiItem.WMIFilter    = filter;
                        pol.WMIFilters.Add(wmiItem);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                AddThreadCount(-1);
            }
        }