Esempio n. 1
0
        private void CreateFromGroupMailbox()
        {
            ADUser groupMailbox = this.GetGroupMailbox(this.FromGroupMailbox, this.recipientSession);
            ADUser creator      = this.GetCreator(groupMailbox, this.recipientSession);

            string[]  array       = base.GetMembers(groupMailbox, this.recipientSession, "New-UnifiedGroup");
            string[]  array2      = base.GetOwners(groupMailbox, creator, this.recipientSession);
            string    description = (groupMailbox.Description != null && groupMailbox.Description.Count > 0) ? groupMailbox.Description[0] : string.Empty;
            AADClient aadclient   = this.CreateAADClient(creator);
            string    text        = this.CreateGroup(groupMailbox.DisplayName, groupMailbox.Name, description, groupMailbox.ModernGroupType == ModernGroupObjectType.Public, aadclient);

            base.AddOwnersInAAD(array2, aadclient, text);
            base.AddMembersInAAD(array, aadclient, text);
            try
            {
                base.WriteVerbose("Updating group mailbox with new ExternalDirectoryObjectId", new object[0]);
                groupMailbox.ExternalDirectoryObjectId = text;
                groupMailbox.CustomAttribute13         = "AADGroup";
                this.recipientSession.Save(groupMailbox);
                base.WriteVerbose("Updated group mailbox with new ExternalDirectoryObjectId", new object[0]);
            }
            catch (LocalizedException ex)
            {
                base.WriteVerbose("Failed to update ExternalDirectoryObjectId property on group mailbox due exception: {0}", new object[]
                {
                    ex
                });
                this.WriteWarning(Strings.ErrorCannotUpdateExternalDirectoryObjectId(groupMailbox.Id.ToString(), text));
                aadclient.DeleteGroup(text);
                return;
            }
            this.ReplicateMailboxAssociation(groupMailbox);
            this.WriteGroup(aadclient, text);
        }
Esempio n. 2
0
    public static AADClient Inject(uint processId, InjectionClrVersion clrVersion, string pipeName)
    {
        if (processId == 0)
        {
            throw new ArgumentNullException(nameof(processId));
        }
        if (string.IsNullOrEmpty(pipeName))
        {
            throw new ArgumentException($"'{nameof(pipeName)}' cannot be null or empty.", nameof(pipeName));
        }

        bool b = Injector.InjectManaged(processId, GetAADCorePath(), "ExtremeDumper.AntiAntiDump.Injection", "Main", pipeName, clrVersion);

        if (!b)
        {
            throw new InvalidOperationException("Can't inject ExtremeDumper.AntiAntiDump.dll to target process.");
        }
        Logger.Info($"ExtremeDumper.AntiAntiDump.dll has been injected into process {processId} and clr version is {clrVersion}");

        var client = AADClient.Create(pipeName);

        if (client is null)
        {
            throw new InvalidOperationException($"Can't create {nameof(AADClient)}.");
        }
        Logger.Info($"Create {nameof(AADClient)} of process {processId} successfully and clr version is {clrVersion}");

        return(client);
    }
Esempio n. 3
0
 internal void RemoveOwnersInAAD(string[] owners, AADClient aadClient, string groupObjectId)
 {
     AADClient.LinkResult[] array = aadClient.RemoveOwners(groupObjectId, owners);
     if (array != null)
     {
         this.WriteWarning(Strings.WarningUnableToRemoveOwners(string.Join(",", (from linkResult in array
                                                                                 select linkResult.FailedLink).ToArray <string>())));
     }
 }
Esempio n. 4
0
        private AADClient CreateAADClient(ADUser user)
        {
            AADClient aadclient = AADClientFactory.Create(user);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            return(aadclient);
        }
Esempio n. 5
0
        private void CreateUnifiedGroup()
        {
            AADClient aadclient     = this.CreateAADClient(this.executingUser);
            string    groupObjectId = this.CreateGroup(this.DisplayName, this.Alias, this.Description, this.IsPublic == null || this.IsPublic.Value, aadclient);

            aadclient.AddMembers(groupObjectId, new string[]
            {
                this.executingUser.ExternalDirectoryObjectId
            });
            base.AddOwnersInAAD(this.owners, aadclient, groupObjectId);
            base.AddMembersInAAD(this.members, aadclient, groupObjectId);
            this.WriteGroup(aadclient, groupObjectId);
        }
Esempio n. 6
0
        protected override void InternalProcessRecord()
        {
            AADClient aadclient = AADClientFactory.Create(base.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
                return;
            }
            if (this.Identity != null)
            {
                Group group;
                try
                {
                    group = aadclient.GetGroup(this.Identity.Value.ToString(), true);
                }
                catch (AADException ex)
                {
                    base.WriteVerbose("GetGroup failed with exception: {0}", new object[]
                    {
                        ex
                    });
                    base.WriteError(new TaskException(Strings.ErrorUnableToGetUnifiedGroup), base.GetErrorCategory(ex), null);
                    return;
                }
                aadclient.Service.LoadProperty(group, "createdOnBehalfOf");
                aadclient.Service.LoadProperty(group, "members");
                aadclient.Service.LoadProperty(group, "owners");
                this.WriteAADGroupObject(group);
                return;
            }
            try
            {
                foreach (Group group2 in aadclient.GetGroups())
                {
                    this.WriteAADGroupObject(group2);
                }
            }
            catch (AADException ex2)
            {
                base.WriteVerbose("GetGroups failed with exception: {0}", new object[]
                {
                    ex2
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToGetUnifiedGroup), base.GetErrorCategory(ex2), null);
            }
        }
Esempio n. 7
0
        private static Uri GetRootSiteUrlFromAAD(OrganizationId organizationId)
        {
            AADClient aadclient = AADClientFactory.Create(organizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                SharePointUrl.Tracer.TraceDebug <OrganizationId>(0L, "Failed to create AADClient for organization {0}", organizationId);
                return(null);
            }
            Uri rootSiteUrlFromServiceInfo = SharePointUrl.GetRootSiteUrlFromServiceInfo(aadclient);

            if (rootSiteUrlFromServiceInfo != null)
            {
                SharePointUrl.Tracer.TraceDebug <OrganizationId, Uri>(0L, "Found SharePoint Root Site Url in ServiceInfo for organization {0}: {1}", organizationId, rootSiteUrlFromServiceInfo);
            }
            return(rootSiteUrlFromServiceInfo);
        }
Esempio n. 8
0
 private void WriteGroup(AADClient aadClient, string groupObjectId)
 {
     try
     {
         Group group = aadClient.GetGroup(groupObjectId, true);
         aadClient.Service.LoadProperty(group, "members");
         aadClient.Service.LoadProperty(group, "owners");
         base.WriteObject(new AADGroupPresentationObject(group));
     }
     catch (AADException ex)
     {
         base.WriteVerbose("GetGroup failed with exception: {0}", new object[]
         {
             ex
         });
         this.WriteWarning(Strings.ErrorUnableToGetUnifiedGroup);
     }
 }
Esempio n. 9
0
        private static Uri GetRootSiteUrlFromDefaultDomain(AADClient aadClient)
        {
            string siteDomainSubstring = SharePointUrl.GetSiteDomainSubstring();

            if (string.IsNullOrEmpty(siteDomainSubstring))
            {
                SharePointUrl.Tracer.TraceError(0L, "Failed to get site domain substring");
                return(null);
            }
            string text = null;

            try
            {
                text = aadClient.GetDefaultDomain();
                if (string.IsNullOrEmpty(text))
                {
                    SharePointUrl.Tracer.TraceError(0L, "Failed to get default domain");
                    return(null);
                }
            }
            catch (AADException arg)
            {
                SharePointUrl.Tracer.TraceError <AADException>(0L, "GetDefaultDomain failed: {0}", arg);
                return(null);
            }
            int num = text.IndexOf('.');

            if (num > 0)
            {
                string str  = text.Substring(0, num);
                string str2 = str + (siteDomainSubstring.StartsWith(".", StringComparison.Ordinal) ? siteDomainSubstring : ("." + siteDomainSubstring));
                try
                {
                    return(new Uri("https://" + str2));
                }
                catch (UriFormatException arg2)
                {
                    SharePointUrl.Tracer.TraceError <string, UriFormatException>(0L, "Invalid Uri: {0}, {1}", "https://" + str2, arg2);
                }
            }
            return(null);
        }
Esempio n. 10
0
        private void UpdateFromGroupMailbox()
        {
            ADUser aduser       = this.recipientSession.FindADUserByExternalDirectoryObjectId(this.Identity.ToString());
            ADUser ownerFromAAD = this.GetOwnerFromAAD(aduser, this.recipientSession);

            string[] members     = base.GetMembers(aduser, this.recipientSession, "Set-UnifiedGroup");
            string[] owners      = base.GetOwners(aduser, null, this.recipientSession);
            string   description = (aduser.Description != null && aduser.Description.Count > 0) ? aduser.Description[0] : string.Empty;

            string[]  exchangeResources = this.GetExchangeResources(aduser);
            AADClient aadclient         = AADClientFactory.Create(ownerFromAAD);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            this.UpdateGroup(aduser.DisplayName, description, exchangeResources, aduser.ExternalDirectoryObjectId, aadclient);
            base.AddOwnersInAAD(owners, aadclient, aduser.ExternalDirectoryObjectId);
            base.AddMembersInAAD(members, aadclient, aduser.ExternalDirectoryObjectId);
        }
Esempio n. 11
0
        protected override void InternalProcessRecord()
        {
            AADClient aadclient = AADClientFactory.Create(base.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            try
            {
                base.WriteVerbose("Calling DeleteGroup", new object[0]);
                aadclient.DeleteGroup(this.Identity.ToString());
                base.WriteVerbose("DeleteGroup succeeded", new object[0]);
            }
            catch (AADException ex)
            {
                base.WriteVerbose("DeleteGroup failed with exception: {0}", new object[]
                {
                    ex
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToRemove(this.Identity.ToString())), base.GetErrorCategory(ex), null);
            }
        }
Esempio n. 12
0
        protected override void InternalProcessRecord()
        {
            if (base.Fields.IsModified("SyncGroupMailbox") && this.SyncGroupMailbox)
            {
                this.UpdateFromGroupMailbox();
                return;
            }
            ADUser groupMailbox = this.recipientSession.FindADUserByExternalDirectoryObjectId(this.Identity.ToString());
            ADUser ownerFromAAD = this.GetOwnerFromAAD(groupMailbox, this.recipientSession);

            string[]  exchangeResources = this.GetExchangeResources(groupMailbox);
            AADClient aadclient         = AADClientFactory.Create(ownerFromAAD);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            this.UpdateGroup(this.DisplayName, this.Description, exchangeResources, this.Identity.ToString(), aadclient);
            base.AddOwnersInAAD(this.addOwners, aadclient, this.Identity.ToString());
            base.RemoveOwnersInAAD(this.removeOwners, aadclient, this.Identity.ToString());
            base.AddMembersInAAD(this.addMembers, aadclient, this.Identity.ToString());
            base.RemoveMembersInAAD(this.removeMembers, aadclient, this.Identity.ToString());
        }
        // Token: 0x06001B78 RID: 7032 RVA: 0x000691F4 File Offset: 0x000673F4
        private bool IsModernGroupUnique()
        {
            bool      result    = false;
            Stopwatch stopwatch = Stopwatch.StartNew();
            AADClient aadclient = AADClientFactory.Create(base.CallContext.ADRecipientSessionContext.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                return(true);
            }
            try
            {
                result = aadclient.IsAliasUnique(this.request.Alias);
                this.LogElapsedTime(CreateModernGroupCommandMetadata.AADAliasQueryTime, new TimeSpan?(stopwatch.Elapsed));
            }
            catch (AADException ex)
            {
                this.LogElapsedTime(CreateModernGroupCommandMetadata.AADAliasQueryTime, new TimeSpan?(stopwatch.Elapsed));
                ExTraceGlobals.ModernGroupsTracer.TraceError <SmtpAddress, AADException>((long)this.GetHashCode(), "CreateUnifiedGroupCommand: User: {0}. Exception: {1}. AADClient.IsAliasUnique failed", base.CallContext.AccessingPrincipal.MailboxInfo.PrimarySmtpAddress, ex);
                base.CallContext.ProtocolLog.Set(CreateModernGroupCommandMetadata.Exception, ex);
            }
            return(result);
        }
Esempio n. 14
0
 private static Uri GetRootSiteUrlFromServiceInfo(AADClient aadClient)
 {
     string[] array = null;
     try
     {
         array = aadClient.GetServiceInfo("SharePoint/");
     }
     catch (AADException arg)
     {
         SharePointUrl.Tracer.TraceError <AADException>(0L, "GetServiceInfo failed: {0}", arg);
     }
     if (array == null)
     {
         return(null);
     }
     foreach (string s in array)
     {
         using (StringReader stringReader = new StringReader(s))
         {
             try
             {
                 XmlDocument xmlDocument = new SafeXmlDocument();
                 xmlDocument.Load(stringReader);
                 Uri rootSiteUrlFromServiceInfo = ServiceInfoParser.GetRootSiteUrlFromServiceInfo(xmlDocument, SharePointUrl.Tracer);
                 if (rootSiteUrlFromServiceInfo != null && !string.IsNullOrWhiteSpace(rootSiteUrlFromServiceInfo.ToString()))
                 {
                     return(rootSiteUrlFromServiceInfo);
                 }
             }
             catch (XmlException arg2)
             {
                 SharePointUrl.Tracer.TraceError <XmlException>(0L, "Failed to get SPO_RootSiteUrl from ServiceInfo: {0}", arg2);
             }
         }
     }
     return(null);
 }
Esempio n. 15
0
    /// <summary>
    /// Create <see cref="AADServer"/>s in other application domains and get corresponding <see cref="AADClient"/>s
    /// </summary>
    /// <param name="clients"></param>
    /// <returns></returns>
    public bool EnableMultiDomain(out AADClient[] clients)
    {
        if (mainClient is not null)
        {
            Debug2.Assert(false, "do NOT call EnableMultiDomain in sub AADClient");
            clients = Array2.Empty <AADClient>();
            return(false);
        }

        if (multiDomainClients is not null)
        {
            foreach (var client in multiDomainClients)
            {
                Debug2.Assert(client.IsConnected);
            }
            clients = multiDomainClients;
            return(true);
        }

        clients = Array2.Empty <AADClient>();
        if (!Invoke <Handlers.EnableMultiDomainHandler.PipeNames>(AADCommand.EnableMultiDomain, EmptySerializable.Instance, out var pipeNames))
        {
            return(false);
        }
        clients = new AADClient[pipeNames.Values.Length];
        for (int i = 0; i < clients.Length; i++)
        {
            var client = Create(pipeNames.Values[i], this);
            if (client is null)
            {
                return(false);
            }
            clients[i] = client;
        }
        multiDomainClients = clients;
        return(true);
    }
Esempio n. 16
0
        private ADUser GetOwnerFromAAD(ADUser groupMailbox, IRecipientSession recipientSession)
        {
            Group     group     = null;
            AADClient aadclient = AADClientFactory.Create(base.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            try
            {
                group = aadclient.GetGroup(groupMailbox.ExternalDirectoryObjectId, true);
                aadclient.Service.LoadProperty(group, "owners");
            }
            catch (AADException ex)
            {
                base.WriteVerbose("Failed to get group owner from AAD with exception: {0}", new object[]
                {
                    ex
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToGetGroupOwners), base.GetErrorCategory(ex), null);
            }
            if (group.owners != null)
            {
                foreach (DirectoryObject directoryObject in group.owners)
                {
                    ADUser aduser = recipientSession.FindADUserByExternalDirectoryObjectId(directoryObject.objectId);
                    if (aduser != null)
                    {
                        return(aduser);
                    }
                }
            }
            base.WriteError(new TaskException(Strings.ErrorUnableToGetGroupOwners), ExchangeErrorCategory.Client, null);
            return(null);
        }
Esempio n. 17
0
 private void UpdateGroup(string displayName, string description, string[] exchangeResources, string groupObjectId, AADClient aadClient)
 {
     try
     {
         base.WriteVerbose("Updating UnifiedGroup for group {0}", new object[]
         {
             groupObjectId
         });
         aadClient.UpdateGroup(groupObjectId, description, exchangeResources, displayName, null);
         base.WriteVerbose("UnifiedGroup updated successfully", new object[0]);
     }
     catch (AADException ex)
     {
         base.WriteVerbose("UpdateGroup failed with exception: {0}", new object[]
         {
             ex
         });
         base.WriteError(new TaskException(Strings.ErrorUnableToUpdateUnifiedGroup), base.GetErrorCategory(ex), null);
     }
 }
Esempio n. 18
0
 public static IEnumerable <ModuleInfo> EnumerateModules(this AADClient client)
 {
     return(client.GetModules(out var modules) ? modules : throw new InvalidOperationException("Can't get modules"));
 }
Esempio n. 19
0
        private string CreateGroup(string displayName, string alias, string description, bool isPublic, AADClient aadClient)
        {
            string text = null;

            try
            {
                base.WriteVerbose("Creating UnifiedGroup for group {0}", new object[]
                {
                    alias
                });
                text = aadClient.CreateGroup(displayName, alias, description, isPublic);
                base.WriteVerbose("UnifiedGroup created successfully, ObjectId={0}", new object[]
                {
                    text
                });
            }
            catch (AADException ex)
            {
                base.WriteVerbose("CreateGroup failed with exception: {0}", new object[]
                {
                    ex
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToCreateUnifiedGroup), base.GetErrorCategory(ex), null);
            }
            return(text);
        }
Esempio n. 20
0
 public static PEInfo GetPEInfo(this AADClient client, ModuleInfo module)
 {
     return(client.GetPEInfo(module, out var peInfo) ? peInfo : throw new InvalidOperationException("Can't get PE info"));
 }
Esempio n. 21
0
        public bool Publish(int?publishedVersion)
        {
            if (!GroupMailboxExchangeResourcesPublisher.IsPublishedVersionOutdated(publishedVersion))
            {
                return(true);
            }
            MailboxUrls mailboxUrls = new MailboxUrls(ExchangePrincipal.FromADUser(this.groupADUser, null), true);
            AADClient   aadclient   = AADClientFactory.Create(this.groupADUser.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                string value = string.Format("AADClient was null for organization {0} and group {1}", this.groupADUser.OrganizationId, this.groupADUser.ExternalDirectoryObjectId);
                throw new LocalizedException(new LocalizedString(value));
            }
            if (publishedVersion == null)
            {
                Group group = aadclient.GetGroup(this.groupADUser.ExternalDirectoryObjectId, false);
                if (group == null)
                {
                    FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
                    {
                        {
                            FederatedDirectoryLogSchema.TraceTag.TaskName,
                            "PublishResourcesToAAD"
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.ActivityId,
                            this.activityId
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                            "GetGroupFromAAD"
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.Message,
                            string.Format("Unable to find group in AAD. ExternalId={0}", this.groupADUser.ExternalDirectoryObjectId)
                        }
                    });
                    return(false);
                }
                string[] array;
                if (group.exchangeResources == null)
                {
                    array = new string[0];
                }
                else
                {
                    array = (from s in @group.exchangeResources
                             select s.ToLower()).ToArray <string>();
                }
                string[] array2 = array;
                string[] array3 = (from s in mailboxUrls.ToExchangeResources()
                                   select s.ToLower()).ToArray <string>();
                if (array2.Length == array3.Length && array2.Except(array3).Count <string>() == 0)
                {
                    return(true);
                }
            }
            string[] exchangeResources = mailboxUrls.ToExchangeResources();
            aadclient.UpdateGroup(this.groupADUser.ExternalDirectoryObjectId, null, exchangeResources, null, null);
            this.TryNotifySharePointForExchangeResources(mailboxUrls);
            return(true);
        }