diff --git a/src/CommonLib/Enums/CollectionMethods.cs b/src/CommonLib/Enums/CollectionMethods.cs index 1964f863..d4ebf61e 100644 --- a/src/CommonLib/Enums/CollectionMethods.cs +++ b/src/CommonLib/Enums/CollectionMethods.cs @@ -24,10 +24,11 @@ public enum ResolvedCollectionMethod UserRights = 1 << 15, CARegistry = 1 << 16, DCRegistry = 1 << 17, + CertServices = 1 << 18, LocalGroups = DCOM | RDP | LocalAdmin | PSRemote, ComputerOnly = LocalGroups | Session | UserRights | CARegistry | DCRegistry, - DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup, - Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container, + DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup | CertServices, + Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container | CertServices, All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry | DCRegistry } } \ No newline at end of file diff --git a/src/CommonLib/LDAPQueries/LDAPFilter.cs b/src/CommonLib/LDAPQueries/LDAPFilter.cs index 5474e9b4..ab7296ad 100644 --- a/src/CommonLib/LDAPQueries/LDAPFilter.cs +++ b/src/CommonLib/LDAPQueries/LDAPFilter.cs @@ -245,16 +245,23 @@ public LDAPFilter AddFilter(string filter, bool enforce) /// public string GetFilter() { - var temp = string.Join("", _filterParts.ToArray()); - if (_filterParts.Count == 1) - temp = _filterParts[0]; - else if (_filterParts.Count > 1) - temp = $"(|{temp})"; - var mandatory = string.Join("", _mandatory.ToArray()); - temp = _mandatory.Count > 0 ? $"(&{temp}{mandatory})" : temp; + var filterPartList = _filterParts.ToArray().Distinct(); + var mandatoryList = _mandatory.ToArray().Distinct(); - return temp; + var filterPartsExceptMandatory = filterPartList.Except(mandatoryList).ToList(); + + var filterPartsDistinct = string.Join("", filterPartsExceptMandatory); + var mandatoryDistinct = string.Join("", mandatoryList); + + if (filterPartsExceptMandatory.Count == 1) + filterPartsDistinct = filterPartsExceptMandatory[0]; + else if (filterPartsExceptMandatory.Count > 1) + filterPartsDistinct = $"(|{filterPartsDistinct})"; + + filterPartsDistinct = _mandatory.Count > 0 ? $"(&{filterPartsDistinct}{mandatoryDistinct})" : filterPartsDistinct; + + return filterPartsDistinct; } public IEnumerable GetFilterList()