예제 #1
0
        private EhfWellKnownGroup GetMembersOfGroupFromDN(string groupDistinguishedName, bool isPartnerAdminGroup, EdgeSyncDiag diagSession)
        {
            EhfWellKnownGroup ehfWellKnownGroup;

            if (isPartnerAdminGroup)
            {
                ExSearchResultEntry exSearchResultEntry = this.ehfTargetConnection.ADAdapter.ReadObjectEntry(groupDistinguishedName, false, EhfCompanyAdmins.AttributesToFetchFromMembers);
                if (exSearchResultEntry == null)
                {
                    diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Could not find wellknown partner admin group {0}", new object[]
                    {
                        groupDistinguishedName
                    });
                    return(null);
                }
                if (!EhfCompanyAdmins.IsPartnerManagedGroup(exSearchResultEntry, diagSession))
                {
                    diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Found the partner group {0}, but it is no partner Managed", new object[]
                    {
                        groupDistinguishedName
                    });
                    return(null);
                }
                Guid externalDirectoryObjectId;
                if (!EhfCompanyAdmins.TryGetExternalDirectoryObjectId(exSearchResultEntry, diagSession, out externalDirectoryObjectId))
                {
                    return(null);
                }
                ehfWellKnownGroup = new EhfWellKnownGroup(groupDistinguishedName, externalDirectoryObjectId);
            }
            else
            {
                ehfWellKnownGroup = new EhfWellKnownGroup(groupDistinguishedName);
            }
            Stack <string> stack = new Stack <string>();

            stack.Push(groupDistinguishedName);
            while (stack.Count != 0)
            {
                string text  = stack.Pop();
                string query = string.Format("(memberOf={0})", text);
                diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.High, "Expanding group {0}", new object[]
                {
                    text
                });
                IEnumerable <ExSearchResultEntry> enumerable = this.ehfTargetConnection.ADAdapter.PagedScan(this.tenantOU, query, EhfCompanyAdmins.AttributesToFetchFromMembers);
                int num = 0;
                foreach (ExSearchResultEntry exSearchResultEntry2 in enumerable)
                {
                    num++;
                    if (!exSearchResultEntry2.IsDeleted)
                    {
                        Guid objectGuid = exSearchResultEntry2.GetObjectGuid();
                        if (EhfCompanyAdmins.IsGroup(exSearchResultEntry2))
                        {
                            Guid partnerGroupGuid;
                            if (ehfWellKnownGroup.SubGroups.ContainsKey(objectGuid) || ehfWellKnownGroup.LinkedRoleGroups.ContainsKey(objectGuid))
                            {
                                this.ehfTargetConnection.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Group {0} is already processed. Ignoring it.", new object[]
                                {
                                    exSearchResultEntry2.DistinguishedName
                                });
                            }
                            else if (EhfCompanyAdmins.IsPartnerManagedLinkedRoleGroup(exSearchResultEntry2, diagSession, out partnerGroupGuid))
                            {
                                ehfWellKnownGroup.LinkedRoleGroups.Add(objectGuid, new PartnerGroupAdminSyncUser(exSearchResultEntry2.DistinguishedName, objectGuid, partnerGroupGuid));
                            }
                            else
                            {
                                ehfWellKnownGroup.SubGroups.Add(objectGuid, new AdminSyncUser(exSearchResultEntry2.DistinguishedName, objectGuid));
                                stack.Push(exSearchResultEntry2.DistinguishedName);
                            }
                        }
                        else
                        {
                            string text2 = string.Empty;
                            if (exSearchResultEntry2.Attributes.ContainsKey("msExchWindowsLiveID") && exSearchResultEntry2.Attributes["msExchWindowsLiveID"].Count != 0)
                            {
                                text2 = (string)exSearchResultEntry2.Attributes["msExchWindowsLiveID"][0];
                                if (text2 != null)
                                {
                                    text2 = text2.Trim();
                                }
                            }
                            else
                            {
                                diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "WindowsLiveID is not set for {0}", new object[]
                                {
                                    exSearchResultEntry2.DistinguishedName
                                });
                            }
                            if (!ehfWellKnownGroup.GroupMembers.ContainsKey(objectGuid))
                            {
                                ehfWellKnownGroup.GroupMembers.Add(objectGuid, new MailboxAdminSyncUser(text2, objectGuid, exSearchResultEntry2.DistinguishedName));
                            }
                        }
                    }
                    else
                    {
                        diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "{0} is deleted, ignoring...", new object[]
                        {
                            exSearchResultEntry2.DistinguishedName
                        });
                    }
                }
                diagSession.Tracer.TraceDebug <string, int>((long)this.GetHashCode(), "Expanded group {0}. Found {1} children", text, num);
            }
            return(ehfWellKnownGroup);
        }
예제 #2
0
        private static bool IsPartnerManagedLinkedRoleGroup(ExSearchResultEntry searchEntry, EdgeSyncDiag diagSession, out Guid groupGuid)
        {
            groupGuid = Guid.Empty;
            if (!EhfCompanyAdmins.IsPartnerManagedGroup(searchEntry, diagSession))
            {
                return(false);
            }
            DirectoryAttribute directoryAttribute;

            if (!searchEntry.Attributes.TryGetValue("msExchPartnerGroupID", out directoryAttribute))
            {
                diagSession.LogAndTraceError("msExchPartnerGroupID attribute is not present in the partner managed group '{0}'", new object[]
                {
                    searchEntry.DistinguishedName
                });
                return(false);
            }
            if (directoryAttribute == null || directoryAttribute.Count == 0)
            {
                diagSession.LogAndTraceError("msExchPartnerGroupID attribute is not set on the partner managed group '{0}'", new object[]
                {
                    searchEntry.DistinguishedName
                });
                return(false);
            }
            string text = directoryAttribute[0] as string;

            if (string.IsNullOrEmpty(text))
            {
                diagSession.LogAndTraceError("msExchPartnerGroupID attribute is empty for the partner managed group '{0}'", new object[]
                {
                    searchEntry.DistinguishedName
                });
                return(false);
            }
            LinkedPartnerGroupInformation linkedPartnerGroupInformation;

            try
            {
                linkedPartnerGroupInformation = LinkedPartnerGroupInformation.Parse(text);
            }
            catch (ArgumentException)
            {
                diagSession.LogAndTraceError("msExchPartnerGroupID attribute value '{0}' is not in the expected format for '{1}'", new object[]
                {
                    text,
                    searchEntry.DistinguishedName
                });
                return(false);
            }
            if (string.IsNullOrEmpty(linkedPartnerGroupInformation.LinkedPartnerGroupId))
            {
                diagSession.LogAndTraceError("msExchPartnerGroupID attribute value '{0}' has an empty LinkdedPartnetGroupId:  '{1}'", new object[]
                {
                    text,
                    searchEntry.DistinguishedName
                });
                return(false);
            }
            if (GuidHelper.TryParseGuid(linkedPartnerGroupInformation.LinkedPartnerGroupId, out groupGuid))
            {
                return(true);
            }
            diagSession.LogAndTraceError("msExchPartnerGroupID attribute value '{0}' is not a valid Guid: '{1}'", new object[]
            {
                text,
                searchEntry.DistinguishedName
            });
            return(false);
        }