Esempio n. 1
0
        internal static bool AccessCheck(ADObjectId accessRequestedForId, ADObjectId executingUserId, IRecipientSession session, out string diagnosticText)
        {
            diagnosticText = string.Empty;
            if (executingUserId == null)
            {
                diagnosticText = "ExecutingUserId is null, access denied. BypassDelegateChecking must be specified to use message-tracking.";
                return(false);
            }
            ADUser aduser = session.Read(executingUserId) as ADUser;

            if (aduser == null)
            {
                diagnosticText = string.Format("Could not find user with ID {0}.  Aborting authorization check.", executingUserId);
                return(false);
            }
            if (executingUserId.Equals(accessRequestedForId))
            {
                ExTraceGlobals.TaskTracer.TraceDebug <string>(0L, "Authenticated user {0} tracking as self.", aduser.Alias);
                return(true);
            }
            ADUser accessRequestedForADUser = (ADUser)session.Read(accessRequestedForId);
            bool   flag = Utils.CheckFullAccessPermissions(aduser, accessRequestedForADUser, session);

            if (!flag)
            {
                diagnosticText = "Access check failed.";
            }
            return(flag);
        }
Esempio n. 2
0
        internal List <string> GetClassificationNames(IList <string> classificationGuids)
        {
            IRecipientSession     tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 2087, "GetClassificationNames", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Common\\recipient\\InboxRule.cs");
            ADRecipient           adrecipient = tenantOrRootOrgRecipientSession.Read(base.MailboxOwnerId);
            IConfigurationSession systemConfigurationSession = this.provider.GetSystemConfigurationSession(adrecipient.OrganizationId);
            List <string>         list = new List <string>();

            foreach (string text in classificationGuids)
            {
                if (!string.IsNullOrEmpty(text))
                {
                    Guid guid;
                    try
                    {
                        guid = new Guid(text);
                    }
                    catch (OverflowException)
                    {
                        continue;
                    }
                    catch (FormatException)
                    {
                        continue;
                    }
                    ADObjectId            entryId = new ADObjectId(guid);
                    MessageClassification messageClassification = systemConfigurationSession.Read <MessageClassification>(entryId);
                    if (messageClassification != null)
                    {
                        list.Add(messageClassification.DisplayName);
                    }
                }
            }
            return(list);
        }
        protected sealed override IConfigDataProvider CreateSession()
        {
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(base.DomainController, true, ConsistencyMode.PartiallyConsistent, base.SessionSettings, 51, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\StoreTasks\\UserOptions\\SetMailboxConfigurationTaskBase.cs");
            ADUser            aduser = (ADUser)base.GetDataObject <ADUser>(this.Identity, tenantOrRootOrgRecipientSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.Identity.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.Identity.ToString())));

            StoreTasksHelper.CheckUserVersion(aduser, new Task.TaskErrorLoggingDelegate(base.WriteError));
            IDirectorySession directorySession = tenantOrRootOrgRecipientSession;

            if (this.ReadUserFromDC)
            {
                IRecipientSession tenantOrRootOrgRecipientSession2 = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(base.DomainController, true, ConsistencyMode.PartiallyConsistent, base.SessionSettings, 70, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\StoreTasks\\UserOptions\\SetMailboxConfigurationTaskBase.cs");
                tenantOrRootOrgRecipientSession2.UseGlobalCatalog = false;
                if (aduser.OrganizationId.Equals(OrganizationId.ForestWideOrgId))
                {
                    tenantOrRootOrgRecipientSession2.EnforceDefaultScope = false;
                }
                ADUser aduser2 = (ADUser)tenantOrRootOrgRecipientSession2.Read <ADUser>(aduser.Identity);
                if (aduser2 != null)
                {
                    aduser           = aduser2;
                    directorySession = tenantOrRootOrgRecipientSession2;
                }
            }
            if (TaskHelper.ShouldUnderscopeDataSessionToOrganization(directorySession, aduser))
            {
                directorySession = TaskHelper.UnderscopeSessionToOrganization(directorySession, aduser.OrganizationId, true);
            }
            base.VerifyIsWithinScopes(directorySession, aduser, true, new DataAccessTask <TDataObject> .ADObjectOutOfScopeString(Strings.ErrorCannotChangeMailboxOutOfWriteScope));
            this.mailboxStoreIdParameter = new MailboxStoreIdParameter(new MailboxStoreIdentity(aduser.Id));
            return(this.CreateMailboxDataProvider(aduser));
        }
Esempio n. 4
0
        private static bool TryGetADRecipient(Trace tracer, ADRecipientCache <TransportMiniRecipient> recipientCache, MailRecipient mailRecipient, out ADRecipient recipient)
        {
            recipient = null;
            ProxyAddress           proxyAddress   = new SmtpProxyAddress((string)mailRecipient.Email, true);
            TransportMiniRecipient recipientEntry = recipientCache.FindAndCacheRecipient(proxyAddress).Data;

            if (recipientEntry == null)
            {
                tracer.TraceWarning <RoutingAddress>(0L, "Could not find recipient entry for {0}", mailRecipient.Email);
                return(false);
            }
            ADRecipient tempRecipient = null;

            ADNotificationAdapter.TryRunADOperation(delegate()
            {
                SmtpAddress smtpAddress           = new SmtpAddress(proxyAddress.AddressString);
                ADSessionSettings sessionSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(smtpAddress.Domain);
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, null, LcidMapper.DefaultLcid, true, ConsistencyMode.IgnoreInvalid, null, sessionSettings, 178, "TryGetADRecipient", "f:\\15.00.1497\\sources\\dev\\MailboxTransport\\src\\MailboxTransportDelivery\\StoreDriver\\agents\\UM\\UMAgentUtil.cs");
                tempRecipient = tenantOrRootOrgRecipientSession.Read(recipientEntry.Id);
            });
            if (tempRecipient == null)
            {
                tracer.TraceWarning <ADObjectId>(0L, "Could not read recipient object for {0}", recipientEntry.Id);
                return(false);
            }
            recipient = tempRecipient;
            return(true);
        }
        private void SaveCultures(IRecipientSession adRecipientSession)
        {
            PreferredCultures preferredCultures = new PreferredCultures(base.Principal.PreferredCultures);

            preferredCultures.AddSupportedCulture(this.Language, (CultureInfo culture) => true);
            ADUser aduser = adRecipientSession.Read(base.Principal.ObjectId) as ADUser;

            if (aduser != null)
            {
                aduser.Languages.Clear();
                Util.AddRange <CultureInfo, CultureInfo>(aduser.Languages, preferredCultures);
                try
                {
                    adRecipientSession.Save(aduser);
                }
                catch (DataValidationException innerException)
                {
                    throw new CorruptDataException(ServerStrings.ExCannotSaveInvalidObject(aduser), innerException);
                }
                catch (DataSourceOperationException ex)
                {
                    throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "MailboxRegionalConfiguration::SaveCultures. Failed due to directory exception {0}.", new object[]
                    {
                        ex
                    });
                }
                catch (DataSourceTransientException ex2)
                {
                    throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "MailboxRegionalConfiguration::SaveCultures. Failed due to directory exception {0}.", new object[]
                    {
                        ex2
                    });
                }
            }
        }
Esempio n. 6
0
        protected override PerformInvitationResults InternalPerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator)
        {
            if (recipients.Length != 1)
            {
                throw new InvalidOperationException("Only single recipient is allowed.");
            }
            ValidRecipient    validRecipient     = recipients[0];
            string            folderId           = context.FolderId.ToBase64String();
            ExternalUser      externalUser       = this.ApplyPermission(mailboxSession, new SmtpAddress(validRecipient.SmtpAddress), context);
            IRecipientSession adrecipientSession = mailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent);
            ADUser            aduser             = (ADUser)adrecipientSession.Read(mailboxSession.MailboxOwner.ObjectId);
            string            text         = aduser.SharingAnonymousIdentities.FindExistingUrlId(SharingDataType.ReachCalendar.PublishResourceName, folderId);
            Uri         owaVdirUrl         = OwaAnonymousVdirLocater.Instance.GetOwaVdirUrl(mailboxSession.MailboxOwner, frontEndLocator);
            SmtpAddress primarySmtpAddress = mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress;
            ObscureUrl  obscureUrl         = ObscureUrl.CreatePublishReachCalendarUrl(owaVdirUrl.ToString(), mailboxSession.MailboxGuid, primarySmtpAddress.Domain, text, externalUser.Sid);

            if (string.IsNullOrEmpty(text))
            {
                aduser.SharingAnonymousIdentities.AddOrUpdate(SharingDataType.ReachCalendar.PublishResourceName, obscureUrl.Identity, folderId);
                adrecipientSession.Save(aduser);
            }
            context.BrowseUrl = obscureUrl.ToString() + ".html";
            context.ICalUrl   = obscureUrl.ToString() + ".ics";
            return(new PerformInvitationResults(recipients));
        }
Esempio n. 7
0
        public void LoadInitialData()
        {
            ExTraceGlobals.OehCallTracer.TraceDebug((long)this.GetHashCode(), "ReadADOrgPersonEventHandler.LoadInitialData");
            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(Culture.GetUserCulture().LCID, true, ConsistencyMode.IgnoreInvalid, true, base.UserContext, false);
            IADOrgPerson      iadorgPerson     = recipientSession.Read((ADObjectId)base.GetParameter("id")) as IADOrgPerson;

            if (iadorgPerson == null)
            {
                throw new OwaInvalidRequestException("couldn't find person");
            }
            StringBuilder stringBuilder = new StringBuilder();
            StringWriter  stringWriter  = new StringWriter(stringBuilder);

            ReadADOrgPerson.RenderOrganizationContents(stringWriter, base.UserContext, iadorgPerson, recipientSession);
            stringWriter.Close();
            this.Writer.Write("sOrg = '");
            Utilities.JavascriptEncode(stringBuilder.ToString(), this.Writer);
            this.Writer.Write("';");
            if (base.IsParameterSet("EA") && base.UserContext.IsFeatureEnabled(Feature.Calendar))
            {
                string text = this.RenderFreeBusyData((string)base.GetParameter("EA"), (ExDateTime)base.GetParameter("SD"), (ExDateTime)base.GetParameter("ED"), true);
                if (text != null)
                {
                    this.Writer.Write("sFBErr = \"");
                    Utilities.JavascriptEncode(text, this.Writer);
                    this.Writer.Write("\";");
                }
            }
        }
Esempio n. 8
0
        protected override IConfigurable PrepareDataObject()
        {
            ADUser            aduser           = (ADUser)base.PrepareDataObject();
            IRecipientSession recipientSession = (IRecipientSession)base.DataSession;

            this.DebugTrace("{0}: ADUser.OriginatingServer:{1} - UseGlobalCatalog:{2}", new object[]
            {
                base.GetType().Name,
                aduser.OriginatingServer,
                recipientSession.UseGlobalCatalog
            });
            if (recipientSession.UseGlobalCatalog)
            {
                recipientSession.UseGlobalCatalog = false;
                this.DebugTrace("{0}: Reading {1}", new object[]
                {
                    base.GetType().Name,
                    aduser.Id
                });
                aduser = (ADUser)recipientSession.Read(aduser.Id);
                if (aduser == null)
                {
                    this.WriteObjectNotFoundError();
                }
                recipientSession.UseGlobalCatalog = true;
                this.DebugTrace("{0}: ADUser.OriginatingServer(after read):{1}", new object[]
                {
                    base.GetType().Name,
                    aduser.OriginatingServer
                });
            }
            return(aduser);
        }
Esempio n. 9
0
        internal static void UpdateRecipientForSoftDelete(IRecipientSession session, ADUser recipient, bool includeInGarbageCollection, bool isInactive)
        {
            int num = 1;

            if (includeInGarbageCollection)
            {
                num |= 4;
            }
            if (isInactive)
            {
                num |= 8;
            }
            recipient.propertyBag.SetField(ADRecipientSchema.RecipientSoftDeletedStatus, num);
            recipient.propertyBag.SetField(ADRecipientSchema.WhenSoftDeleted, new DateTime?(DateTime.UtcNow));
            int num2 = (int)recipient.propertyBag[ADRecipientSchema.TransportSettingFlags];

            num2 |= 8;
            recipient.propertyBag.SetField(ADRecipientSchema.TransportSettingFlags, num2);
            if (!"Soft Deleted Objects".Equals(recipient.Id.Parent.Name))
            {
                ADObjectId childId = recipient.Id.Parent.GetChildId("OU", "Soft Deleted Objects");
                childId = childId.GetChildId(SoftDeletedTaskHelper.ReservedADNameStringRegex.Replace(recipient.Id.Name, string.Empty));
                string userPrincipalName = recipient.UserPrincipalName;
                session.SessionSettings.IncludeSoftDeletedObjects = true;
                if (session.Read(childId) != null)
                {
                    childId = childId.Parent.GetChildId(MailboxTaskHelper.AppendRandomNameSuffix(childId.Name));
                }
                session.SessionSettings.IncludeSoftDeletedObjects = false;
                recipient.SetId(childId);
                recipient.UserPrincipalName = userPrincipalName;
            }
        }
        // Token: 0x06001089 RID: 4233 RVA: 0x000606C4 File Offset: 0x0005E8C4
        internal void SaveGroupMetricsToAD(IRecipientSession session, ADRawEntry group, int totalMemberCount, int externalMemberCount)
        {
            bool savedToAD = false;

            this.TryRunPerGroupADOperation(delegate
            {
                ADRawEntry adrawEntry         = session.Read(group.Id);
                ADGroup adgroup               = adrawEntry as ADGroup;
                ADDynamicGroup addynamicGroup = adrawEntry as ADDynamicGroup;
                if (adgroup != null)
                {
                    adgroup.GroupMemberCount         = totalMemberCount;
                    adgroup.GroupExternalMemberCount = externalMemberCount;
                    session.Save(adgroup);
                    savedToAD = true;
                    return;
                }
                if (addynamicGroup != null)
                {
                    addynamicGroup.GroupMemberCount         = totalMemberCount;
                    addynamicGroup.GroupExternalMemberCount = externalMemberCount;
                    session.Save(addynamicGroup);
                    savedToAD = true;
                }
            }, group.Id.DistinguishedName);
            if (!savedToAD)
            {
                string organizationIdString = this.GetOrganizationIdString();
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToSaveGroupMetricsToAD, organizationIdString, new object[]
                {
                    organizationIdString,
                    group.Id.DistinguishedName
                });
            }
        }
Esempio n. 11
0
        // Token: 0x06002A99 RID: 10905 RVA: 0x000EEF08 File Offset: 0x000ED108
        internal static void RenderOrganizationContents(TextWriter writer, UserContext userContext, IADOrgPerson orgPerson, IRecipientSession adRecipientSession)
        {
            object[][] managementChainView = orgPerson.GetManagementChainView(false, new PropertyDefinition[]
            {
                ADObjectSchema.Id,
                ADRecipientSchema.DisplayName,
                ADOrgPersonSchema.Title
            });
            if (managementChainView != null)
            {
                ReadADOrgPerson.RenderManagerList(writer, userContext, managementChainView);
            }
            ADRecipient adrecipient = null;

            if (orgPerson.Manager != null)
            {
                try
                {
                    adrecipient = adRecipientSession.Read(orgPerson.Manager);
                }
                catch (NonUniqueRecipientException ex)
                {
                    ExTraceGlobals.DirectoryTracer.TraceDebug <string>(0L, "ReadADOrgPerson.RenderOrganizationContents: NonUniqueRecipientException thrown by IRecipientSession.Read: {0}", ex.Message);
                }
            }
            if (adrecipient != null)
            {
                IADOrgPerson iadorgPerson      = (IADOrgPerson)adrecipient;
                object[][]   directReportsView = iadorgPerson.GetDirectReportsView(new PropertyDefinition[]
                {
                    ADObjectSchema.Id,
                    ADRecipientSchema.DisplayName,
                    ADOrgPersonSchema.Title
                });
                if (directReportsView != null)
                {
                    ReadADOrgPerson.RenderPeersList(writer, directReportsView, orgPerson.Id, orgPerson.DisplayName, orgPerson.Title);
                }
            }
            else
            {
                ReadADOrgPerson.RenderPeopleLabelHeading(writer, LocalizedStrings.GetHtmlEncoded(1804838102));
                ReadADOrgPerson.RenderSelf(writer, orgPerson.Id, orgPerson.DisplayName, orgPerson.Title);
            }
            object[][] directReportsView2 = orgPerson.GetDirectReportsView(new PropertyDefinition[]
            {
                ADObjectSchema.Id,
                ADRecipientSchema.DisplayName,
                ADOrgPersonSchema.Title
            });
            if (directReportsView2 != null)
            {
                ReadADOrgPerson.RenderDirectReportsList(writer, directReportsView2);
            }
        }
Esempio n. 12
0
        // Token: 0x06001151 RID: 4433 RVA: 0x00047DC8 File Offset: 0x00045FC8
        private ADRecipient FindRecipient(IRecipientSession session, ADObjectId recipientId)
        {
            ADRecipient adrecipient = session.Read(recipientId);

            if (adrecipient == null)
            {
                this.tracer.TraceError <ADObjectId>((long)this.GetHashCode(), "AD photo reader: user {0} not found in AD.", recipientId);
                throw new ADNoSuchObjectException(DirectoryStrings.ExceptionADOperationFailedNoSuchObject(session.DomainController, recipientId.DistinguishedName));
            }
            return(adrecipient);
        }
Esempio n. 13
0
        internal static string GetUniqueNameForRecovery(IRecipientSession session, string name, ADObjectId id)
        {
            string      result      = name;
            ADRecipient adrecipient = session.Read(id.Parent.Parent.GetChildId(name));

            if (adrecipient != null)
            {
                result = MailboxTaskHelper.AppendRandomNameSuffix(name);
            }
            return(result);
        }
Esempio n. 14
0
        public IGenericADUser FindByObjectId(IRecipientSession recipientSession, ADObjectId directoryEntry)
        {
            ArgumentValidator.ThrowIfNull("recipientSession", recipientSession);
            IGenericADUser adUser = null;

            this.DoAdCallAndTranslateExceptions(delegate
            {
                adUser = this.TranslateADRecipient(recipientSession.Read(directoryEntry), false);
            }, "DirectoryAccessor::FindByObjectId");
            return(adUser);
        }
        public override void SetMailboxOwnerAsSender(MessageItem message)
        {
            PublicFolderSession publicFolderSession = base.StoreSession as PublicFolderSession;

            if (base.CurrentFolder.PropertyBag.GetValueOrDefault <bool>(FolderSchema.MailEnabled))
            {
                Exception ex = null;
                try
                {
                    byte[] valueOrDefault = base.CurrentFolder.PropertyBag.GetValueOrDefault <byte[]>(FolderSchema.ProxyGuid);
                    if (valueOrDefault != null && valueOrDefault.Length == 16)
                    {
                        IRecipientSession adrecipientSession = publicFolderSession.GetADRecipientSession(true, ConsistencyMode.PartiallyConsistent);
                        ADRawEntry        adrawEntry         = adrecipientSession.Read(new ADObjectId(valueOrDefault)) as ADPublicFolder;
                        if (adrawEntry != null)
                        {
                            message.From = new Participant(adrawEntry);
                            return;
                        }
                    }
                    ex = new ObjectNotFoundException(ServerStrings.ExItemNotFound);
                }
                catch (ADTransientException ex2)
                {
                    ex = ex2;
                }
                catch (ADExternalException ex3)
                {
                    ex = ex3;
                }
                catch (ADOperationException ex4)
                {
                    ex = ex4;
                }
                catch (DataValidationException ex5)
                {
                    ex = ex5;
                }
                catch (ObjectNotFoundException ex6)
                {
                    ex = ex6;
                }
                if (ex != null)
                {
                    StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_PFRuleSettingFromAddressFailure, base.CurrentFolder.StoreObjectId.ToHexEntryId(), new object[]
                    {
                        ex
                    });
                }
            }
            message.From = (publicFolderSession.ConnectAsParticipant ?? new Participant(publicFolderSession.MailboxPrincipal));
        }
Esempio n. 16
0
        // Token: 0x06000862 RID: 2146 RVA: 0x0003E540 File Offset: 0x0003C740
        internal static void SetPreferredCulture(ExchangePrincipal exchangePrincipal, IEnumerable <CultureInfo> preferredCultures, IRecipientSession recipientSession)
        {
            ADUser aduser = recipientSession.Read(exchangePrincipal.ObjectId) as ADUser;

            if (aduser != null)
            {
                aduser.Languages.Clear();
                foreach (CultureInfo item in preferredCultures)
                {
                    aduser.Languages.Add(item);
                }
                recipientSession.Save(aduser);
            }
        }
Esempio n. 17
0
        // Token: 0x06001BC8 RID: 7112 RVA: 0x0006B090 File Offset: 0x00069290
        private void SaveCultures(ADObjectId adUserObjectId, IRecipientSession adRecipientSession, IEnumerable <CultureInfo> preferredCultures)
        {
            ADUser aduser = adRecipientSession.Read(adUserObjectId) as ADUser;

            if (aduser != null)
            {
                aduser.Languages.Clear();
                foreach (CultureInfo item in preferredCultures)
                {
                    aduser.Languages.Add(item);
                }
                adRecipientSession.Save(aduser);
            }
        }
 // Token: 0x06000BCE RID: 3022 RVA: 0x0004DF24 File Offset: 0x0004C124
 internal static bool InRole(IRecipientSession rs, ADRecipient recipient, MultiValuedProperty <string> roleMembersLegDN, MultiValuedProperty <ADObjectId> roleMemberslegacy)
 {
     if (recipient == null)
     {
         return(false);
     }
     if (roleMemberslegacy == null && roleMembersLegDN == null)
     {
         return(false);
     }
     if (roleMembersLegDN != null && roleMembersLegDN.Count != 0)
     {
         foreach (string text in roleMembersLegDN)
         {
             if (string.Equals(text, recipient.LegacyExchangeDN, StringComparison.InvariantCultureIgnoreCase))
             {
                 return(true);
             }
             ADRecipient adrecipient = rs.FindByLegacyExchangeDN(text);
             if (adrecipient != null && adrecipient is ADGroup && recipient.IsMemberOf(adrecipient.Id, false))
             {
                 BookingPolicy.Tracer.TraceDebug((long)recipient.GetHashCode(), "{0}: Group match", new object[]
                 {
                     TraceContext.Get()
                 });
                 return(true);
             }
         }
     }
     if (roleMemberslegacy != null && roleMemberslegacy.Count != 0)
     {
         foreach (ADObjectId adobjectId in roleMemberslegacy)
         {
             if (ADObjectId.Equals(adobjectId, recipient.Id))
             {
                 return(true);
             }
             ADRecipient adrecipient2 = rs.Read(adobjectId);
             if (adrecipient2 != null && adrecipient2 is ADGroup && recipient.IsMemberOf(adrecipient2.Id, false))
             {
                 BookingPolicy.Tracer.TraceDebug((long)recipient.GetHashCode(), "{0}: Group match", new object[]
                 {
                     TraceContext.Get()
                 });
                 return(true);
             }
         }
     }
     return(false);
 }
        internal static string FindUniqueCN(IRecipientSession session, ADObjectId parentId, string cnOrig)
        {
            string suffix = "";

            for (int i = 1; i < 100; i++)
            {
                string text = InitializeExchangeUniversalGroups.Concat(cnOrig, suffix, 64);
                if (session.Read(parentId.GetChildId(text)) == null)
                {
                    return(text);
                }
                suffix = i.ToString();
            }
            return(InitializeExchangeUniversalGroups.Concat(cnOrig, Guid.NewGuid().ToString("N"), 64));
        }
Esempio n. 20
0
 private static string[] GetStatusMailRecipients(MailboxDiscoverySearch searchObject, IRecipientSession recipientSession)
 {
     return((from r in searchObject.StatusMailRecipients.Select(delegate(ADObjectId recipientId)
     {
         ADRecipient adrecipient = recipientSession.Read(recipientId);
         if (adrecipient == null)
         {
             Util.Tracer.TraceWarning <ADObjectId>((long)searchObject.GetHashCode(), "Unable to find status mail recipient '{0}'", recipientId);
             return null;
         }
         return adrecipient.PrimarySmtpAddress.ToString();
     })
             where r != null
             select r).ToArray <string>());
 }
        // Token: 0x06000306 RID: 774 RVA: 0x00013504 File Offset: 0x00011704
        private Participant GetOfficialFileParticipant(ContentSetting policy)
        {
            Participant participant = null;

            if (!this.officialFileParticipantDictionary.TryGetValue(policy, out participant))
            {
                AutoCopyEnforcer.Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Getting the archive address for policy {1} from the AD.", TraceContext.Get(), policy.Name);
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, base.MailboxData.MailboxSession.MailboxOwner.MailboxInfo.OrganizationId.ToADSessionSettings(), 590, "GetOfficialFileParticipant", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\elc\\ManagedFolderAssistant\\AutoCopyEnforcer.cs");
                ADRecipient       adrecipient = tenantOrRootOrgRecipientSession.Read(policy.AddressForJournaling);
                string            arg         = adrecipient.PrimarySmtpAddress.ToString();
                participant = new Participant(adrecipient);
                AutoCopyEnforcer.Tracer.TraceDebug <object, string, string>((long)this.GetHashCode(), "{0}: Archive address for policy {1} is {2}.", TraceContext.Get(), policy.Name, arg);
                this.officialFileParticipantDictionary[policy] = participant;
            }
            return(participant);
        }
        internal static ExternalAudience GetUserPolicy(IExchangePrincipal mailboxOwner)
        {
            ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(mailboxOwner.MailboxInfo.OrganizationId ?? OrganizationId.ForestWideOrgId);
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 322, "GetUserPolicy", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\OOF\\UserOofSettingsStorage.cs");
            ADRecipient       adrecipient    = tenantOrRootOrgRecipientSession.Read(mailboxOwner.ObjectId);
            IADMailStorage    iadmailStorage = adrecipient as IADMailStorage;

            if (iadmailStorage == null)
            {
                throw new MailStorageNotFoundException();
            }
            if (iadmailStorage.ExternalOofOptions == ExternalOofOptions.InternalOnly)
            {
                return(ExternalAudience.None);
            }
            return(ExternalAudience.All);
        }
Esempio n. 23
0
 private ADUser GetCreator(ADUser groupMailbox, IRecipientSession recipientSession)
 {
     foreach (ADObjectId entryId in ((MultiValuedProperty <ADObjectId>)groupMailbox[GroupMailboxSchema.Owners]))
     {
         ADUser aduser = recipientSession.Read(entryId) as ADUser;
         if (aduser != null)
         {
             base.WriteVerbose("Group creator: {0}", new object[]
             {
                 aduser.Id
             });
             return(aduser);
         }
     }
     base.WriteError(new TaskException(Strings.ErrorUnableToGetCreatorFromGroupMailbox), ExchangeErrorCategory.Client, null);
     return(null);
 }
Esempio n. 24
0
 internal static void ParseResultPath(IRecipientSession recipientSession, string resultPath, out ADUser adUser, out string folderName)
 {
     if (string.IsNullOrEmpty(resultPath))
     {
         throw new ArgumentNullException(resultPath);
     }
     string[] array = resultPath.Split(new char[]
     {
         '\\'
     });
     if (array.Length != 2)
     {
         throw new FormatException("Invalid resultPath format");
     }
     adUser     = (ADUser)recipientSession.Read(new ADObjectId(array[0]));
     folderName = array[1];
 }
Esempio n. 25
0
        public static ExDateTime GetPasswordExpirationDate(ADObjectId adUserObjectId, IRecipientSession recipientSession)
        {
            if (adUserObjectId.IsNullOrEmpty())
            {
                throw new ArgumentException("ADUser object ID cannot be null or empty", "adUserObjectId");
            }
            ADUser aduser = recipientSession.Read(adUserObjectId) as ADUser;

            if (aduser == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
            }
            if ((aduser.UserAccountControl & UserAccountControlFlags.DoNotExpirePassword) != UserAccountControlFlags.None)
            {
                return(ExDateTime.MaxValue);
            }
            ExDateTime?exDateTime = null;

            if (aduser.PasswordLastSet != null)
            {
                exDateTime = new ExDateTime?(new ExDateTime(ExTimeZone.UtcTimeZone, aduser.PasswordLastSet.Value));
            }
            if (exDateTime == null)
            {
                return(ExDateTime.MaxValue);
            }
            IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(adUserObjectId.GetPartitionId()), 86, "GetPasswordExpirationDate", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\DirectoryHelper.cs");

            tenantOrTopologyConfigurationSession.UseConfigNC = false;
            ADDomain addomain = tenantOrTopologyConfigurationSession.Read <ADDomain>(aduser.Id.DomainId);

            if (addomain == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
            }
            EnhancedTimeSpan?maximumPasswordAge = addomain.MaximumPasswordAge;
            TimeSpan?        timeSpan           = (maximumPasswordAge != null) ? new TimeSpan?(maximumPasswordAge.GetValueOrDefault()) : null;

            if (timeSpan == null || timeSpan == TimeSpan.Zero)
            {
                return(ExDateTime.MaxValue);
            }
            return(exDateTime.Value.Add(timeSpan.Value));
        }
		public static ADGroup GetWellKnownGroup(Guid groupGuid, IConfigurationSession configSession, ManageSendConnectors.ThrowTerminatingErrorDelegate throwDelegate, out IRecipientSession recipSession, out ITopologyConfigurationSession gcSession)
		{
			TaskLogger.LogEnter();
			ADGroup adgroup = null;
			recipSession = null;
			recipSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 530, "GetWellKnownGroup", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\Transport\\ManageSendConnectors.cs");
			try
			{
				recipSession.UseGlobalCatalog = true;
				adgroup = recipSession.ResolveWellKnownGuid<ADGroup>(groupGuid, configSession.ConfigurationNamingContext);
				recipSession.UseGlobalCatalog = false;
				adgroup = (ADGroup)recipSession.Read(adgroup.Id);
			}
			finally
			{
				recipSession.UseGlobalCatalog = false;
			}
			if (adgroup == null)
			{
				try
				{
					ADDomain addomain = ADForest.GetLocalForest().FindRootDomain(true);
					if (addomain != null)
					{
						recipSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(addomain.OriginatingServer, false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 564, "GetWellKnownGroup", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\Transport\\ManageSendConnectors.cs");
						adgroup = recipSession.ResolveWellKnownGuid<ADGroup>(groupGuid, configSession.ConfigurationNamingContext);
					}
				}
				catch (ADReferralException)
				{
				}
			}
			if (adgroup == null)
			{
				throwDelegate(new ErrorExchangeGroupNotFoundException(groupGuid), ErrorCategory.ObjectNotFound, null);
			}
			gcSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 589, "GetWellKnownGroup", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\Transport\\ManageSendConnectors.cs");
			gcSession.UseConfigNC = false;
			gcSession.UseGlobalCatalog = true;
			TaskLogger.LogExit();
			return adgroup;
		}
Esempio n. 27
0
        public virtual ExpandedGroup ExpandGroup(IRecipientSession session, ADObjectId groupId, out int ldapQueries)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            ExpandedGroup expandedGroup = null;
            int           numQueries    = 0;

            this.RunADOperation(groupId, delegate
            {
                IADDistributionList iaddistributionList = session.Read(groupId) as IADDistributionList;
                numQueries++;
                if (iaddistributionList != null)
                {
                    if (this.disableDynamicGroups && iaddistributionList is ADDynamicGroup)
                    {
                        expandedGroup = null;
                        return;
                    }
                    List <Guid> list  = new List <Guid>();
                    List <Guid> list2 = new List <Guid>();
                    ADPagedReader <ADRawEntry> adpagedReader = iaddistributionList.Expand(1000, IsMemberOfResolverADAdapter <GroupKeyType> .properties);
                    numQueries++;
                    foreach (ADRawEntry adrawEntry in adpagedReader)
                    {
                        Microsoft.Exchange.Data.Directory.Recipient.RecipientType recipientType = (Microsoft.Exchange.Data.Directory.Recipient.RecipientType)adrawEntry[ADRecipientSchema.RecipientType];
                        if (this.IsGroup(recipientType))
                        {
                            list.Add(adrawEntry.Id.ObjectGuid);
                        }
                        else
                        {
                            list2.Add(adrawEntry.Id.ObjectGuid);
                        }
                    }
                    expandedGroup = this.CreateExpandedGroup((ADObject)iaddistributionList, list, list2);
                }
            });
            ldapQueries = numQueries;
            return(expandedGroup);
        }
Esempio n. 28
0
        internal static List <ADRecipient> GetUsersGrantedSendOnBehalfPermission(ADRecipient mailbox, IRecipientSession galSession)
        {
            MultiValuedProperty <ADObjectId> grantSendOnBehalfTo = mailbox.GrantSendOnBehalfTo;
            List <ADRecipient> list = null;

            if (grantSendOnBehalfTo != null && grantSendOnBehalfTo.Count > 0)
            {
                list = new List <ADRecipient>(grantSendOnBehalfTo.Count);
                foreach (ADObjectId entryId in grantSendOnBehalfTo)
                {
                    ADRecipient adrecipient = galSession.Read(entryId);
                    if (adrecipient != null)
                    {
                        list.Add(adrecipient);
                        TraceWrapper.SearchLibraryTracer.TraceDebug <string, string>(0, "Added {0} to list of users who have SendOnBehlf permission for {1}.", adrecipient.DisplayName, mailbox.DisplayName);
                    }
                }
            }
            return(list);
        }
Esempio n. 29
0
        private OrganizationId ResolveOrganization(ADObjectId entryId)
        {
            OrganizationId organizationId;

            try
            {
                if (entryId == null)
                {
                    throw new ArgumentNullException("entryId");
                }
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsOrRootOrgAutoDetect(entryId), 1191, "ResolveOrganization", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\MailboxSearch\\Common\\MailboxSearchConfigurationProvider.cs");
                ADRecipient       adrecipient = tenantOrRootOrgRecipientSession.Read(entryId);
                if (adrecipient == null)
                {
                    throw new ObjectNotFoundException(ServerStrings.ADUserNotFoundId(entryId));
                }
                organizationId = adrecipient.OrganizationId;
            }
            catch (InvalidOperationException arg)
            {
                Util.Tracer.TraceError <InvalidOperationException>((long)this.GetHashCode(), "ResolveUserOrganization error: {0}", arg);
                throw;
            }
            catch (DataSourceOperationException arg2)
            {
                Util.Tracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "ResolveUserOrganization error: {0}", arg2);
                throw;
            }
            catch (TransientException arg3)
            {
                Util.Tracer.TraceError <TransientException>((long)this.GetHashCode(), "ResolveUserOrganization error: {0}", arg3);
                throw;
            }
            catch (DataValidationException arg4)
            {
                Util.Tracer.TraceError <DataValidationException>((long)this.GetHashCode(), "ResolveUserOrganization error: {0}", arg4);
                throw;
            }
            return(organizationId);
        }
Esempio n. 30
0
 // Token: 0x060009E4 RID: 2532 RVA: 0x00041508 File Offset: 0x0003F708
 public void HandleEvent(MapiEvent mapiEvent, MailboxSession itemStore, StoreObject item)
 {
     if (ObjectType.MAPI_MESSAGE == mapiEvent.ItemType && item == null)
     {
         ExTraceGlobals.UserSettingsTracer.TraceDebug <string>((long)this.GetHashCode(), "Event is MAPI_MESSAGE but item is null, message class is {0}", mapiEvent.ObjectClass);
         return;
     }
     if (!itemStore.Capabilities.CanHaveUserConfigurationManager)
     {
         ExTraceGlobals.UserSettingsTracer.TraceDebug <string>((long)this.GetHashCode(), "Mailbox sesstion does not have UserConfigurationManager capability. Possibly an alternate mailbox, {0}.", itemStore.MailboxOwnerLegacyDN);
         return;
     }
     if (this.IsMailboxDeletedOrDisconnected(mapiEvent))
     {
         ExTraceGlobals.UserSettingsTracer.TraceDebug <string, Guid>((long)this.GetHashCode(), "Processing Disabling event for mailbox {0} on database {1}", itemStore.MailboxOwnerLegacyDN, itemStore.MdbGuid);
         UserSettings  settings      = new UserSettings(itemStore);
         SystemMailbox systemMailbox = this.GetSystemMailbox();
         if (systemMailbox != null)
         {
             NotificationFactories.Instance.UpdateSettingUnderSystemMailbox(settings, systemMailbox);
         }
         SettingsChangeListener.Instance.RaiseSettingsChangedEvent(settings, new InfoFromUserMailboxSession(itemStore));
         return;
     }
     if (this.IsMailboxCreatedOrConnected(mapiEvent))
     {
         ExTraceGlobals.UserSettingsTracer.TraceDebug <string, Guid>((long)this.GetHashCode(), "Processing Enabling event for mailbox {0} on database {1}", itemStore.MailboxOwnerLegacyDN, itemStore.MdbGuid);
         using (VersionedXmlDataProvider versionedXmlDataProvider = new VersionedXmlDataProvider(itemStore))
         {
             TextMessagingAccount account = (TextMessagingAccount)versionedXmlDataProvider.Read <TextMessagingAccount>(itemStore.MailboxOwner.ObjectId);
             IRecipientSession    tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.IgnoreInvalid, itemStore.GetADSessionSettings(), 194, "HandleEvent", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\CalendarNotification\\SettingsChangeProcessor.cs");
             ADRecipient          adrecipient = tenantOrRootOrgRecipientSession.Read(itemStore.MailboxOwner.ObjectId);
             if (adrecipient != null)
             {
                 TextMessagingHelper.UpdateAndSaveTextMessgaingStateOnAdUser(account, adrecipient, tenantOrRootOrgRecipientSession);
             }
         }
     }
     this.HandleSettingsEvent(itemStore);
 }