コード例 #1
0
        private void ValidateLawfulInterceptionTenantConfiguration()
        {
            string config = JournalConfigSchema.Configuration.GetConfig <string>("LegalInterceptTenantName");

            if (string.IsNullOrEmpty(config))
            {
                base.WriteError(new InvalidOperationException(Strings.JournalingParameterErrorGccTenantSettingNotExist), ErrorCategory.ObjectNotFound, null);
            }
            Guid lawfulInterceptTenantGuid = ADJournalRuleStorageManager.GetLawfulInterceptTenantGuid(config);

            if (lawfulInterceptTenantGuid == Guid.Empty)
            {
                base.WriteError(new InvalidOperationException(Strings.JournalingParameterErrorGccTenantNotFound(config)), ErrorCategory.ObjectNotFound, null);
            }
        }
コード例 #2
0
        internal static JournalNdrValidationCheckResult ValidateJournalNdrMailboxSetting(IConfigDataProvider dataProvider, SmtpAddress journalNdrToAddress)
        {
            ADJournalRuleStorageManager adjournalRuleStorageManager = null;
            bool flag = false;

            try
            {
                adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", dataProvider);
            }
            catch (RuleCollectionNotInAdException)
            {
            }
            if (adjournalRuleStorageManager != null)
            {
                adjournalRuleStorageManager.LoadRuleCollection();
                RoutingAddress value = new RoutingAddress(journalNdrToAddress.ToString());
                if (value == RoutingAddress.NullReversePath)
                {
                    if (adjournalRuleStorageManager.Count > 0)
                    {
                        return(JournalNdrValidationCheckResult.JournalNdrCannotBeNullReversePath);
                    }
                }
                else
                {
                    foreach (Microsoft.Exchange.MessagingPolicies.Rules.Rule rule in adjournalRuleStorageManager.GetRuleCollection())
                    {
                        TransportRule     transportRule     = (TransportRule)rule;
                        JournalRuleObject journalRuleObject = new JournalRuleObject();
                        journalRuleObject.Deserialize(transportRule as JournalingRule);
                        if (journalRuleObject.Recipient != null && journalRuleObject.Recipient != null && journalNdrToAddress == journalRuleObject.Recipient.Value)
                        {
                            return(JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleRecipient);
                        }
                        if (journalNdrToAddress == journalRuleObject.JournalEmailAddress)
                        {
                            flag = true;
                        }
                    }
                }
            }
            if (!flag)
            {
                return(JournalNdrValidationCheckResult.JournalNdrValidationPassed);
            }
            return(JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleJournalEmailAddress);
        }
コード例 #3
0
        protected override void InternalProcessRecord()
        {
            ADJournalRuleStorageManager adjournalRuleStorageManager = null;

            try
            {
                adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", base.DataSession);
            }
            catch (RuleCollectionNotInAdException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
                return;
            }
            int               num           = 0;
            TransportRule     transportRule = null;
            SmtpAddress       journalingReportNdrToSmtpAddress = JournalRuleObject.GetJournalingReportNdrToSmtpAddress(this.ResolveCurrentOrganization(), this.ConfigurationSession);
            JournalRuleObject journalRuleObject;

            try
            {
                if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled&& journalingReportNdrToSmtpAddress == SmtpAddress.NullReversePath)
                {
                    base.WriteError(new InvalidOperationException(Strings.JournalNdrMailboxCannotBeNull), ErrorCategory.InvalidOperation, null);
                }
                bool        flag = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled&& !this.LawfulInterception;
                SmtpAddress smtpAddress;
                if (!JournalRuleObject.LookupAndCheckAllowedTypes(this.JournalEmailAddress, base.TenantGlobalCatalogSession, base.SessionSettings.CurrentOrganizationId, flag, out smtpAddress))
                {
                    base.WriteError(new InvalidOperationException(Strings.JournalingToExternalOnly), ErrorCategory.InvalidOperation, null);
                    return;
                }
                if (smtpAddress == journalingReportNdrToSmtpAddress)
                {
                    this.WriteWarning(Strings.JournalingReportNdrToSameAsJournalEmailAddress);
                }
                if (flag)
                {
                    adjournalRuleStorageManager.LoadRuleCollection();
                    if (adjournalRuleStorageManager.Count >= 10)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorTooManyJournalRules(10)), ErrorCategory.InvalidOperation, null);
                        return;
                    }
                }
                if (this.Recipient != null && this.Recipient != null && this.Recipient.Value == journalingReportNdrToSmtpAddress)
                {
                    base.WriteError(new InvalidOperationException(Strings.JournalingReportNdrToSameAsRecipient), ErrorCategory.InvalidOperation, null);
                    return;
                }
                GccType gccRuleType = GccType.None;
                if (this.LawfulInterception)
                {
                    this.ValidateLawfulInterceptionTenantConfiguration();
                    if ((base.Fields.IsChanged("FullReport") || base.Fields.IsModified("FullReport")) && this.FullReport)
                    {
                        gccRuleType = GccType.Full;
                    }
                    else
                    {
                        gccRuleType = GccType.Prtt;
                    }
                }
                DateTime?expiryDate = null;
                if (this.ExpiryDate != null)
                {
                    expiryDate = new DateTime?(this.ExpiryDate.Value.ToUniversalTime());
                }
                journalRuleObject = new JournalRuleObject(base.Name, this.Enabled, this.Recipient, smtpAddress, this.Scope, expiryDate, gccRuleType);
            }
            catch (DataValidationException exception2)
            {
                base.WriteError(exception2, ErrorCategory.InvalidArgument, base.Name);
                return;
            }
            catch (RecipientInvalidException exception3)
            {
                base.WriteError(exception3, ErrorCategory.InvalidArgument, this.JournalEmailAddress);
                return;
            }
            try
            {
                JournalingRule rule = journalRuleObject.Serialize();
                adjournalRuleStorageManager.NewRule(rule, this.ResolveCurrentOrganization(), ref num, out transportRule);
            }
            catch (RulesValidationException)
            {
                base.WriteError(new ArgumentException(Strings.RuleNameAlreadyExists, "Name"), ErrorCategory.InvalidArgument, base.Name);
                return;
            }
            catch (ParserException exception4)
            {
                base.WriteError(exception4, ErrorCategory.InvalidData, null);
                return;
            }
            if (Utils.Exchange12HubServersExist(this))
            {
                this.WriteWarning(Strings.NewRuleSyncAcrossDifferentVersionsNeeded);
            }
            journalRuleObject.SetTransportRule(transportRule);
            if (journalingReportNdrToSmtpAddress == SmtpAddress.NullReversePath)
            {
                this.WriteWarning(Strings.JournalingReportNdrToNotSet);
            }
            base.WriteObject(journalRuleObject);
        }
コード例 #4
0
        protected override void InternalProcessRecord()
        {
            if (!base.ShouldContinue(Strings.PromptToOverwriteRulesOnImport))
            {
                return;
            }
            ADJournalRuleStorageManager adjournalRuleStorageManager;

            try
            {
                adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", base.DataSession);
            }
            catch (RuleCollectionNotInAdException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
                return;
            }
            TransportRuleCollection transportRuleCollection = null;

            using (Stream stream = new MemoryStream(this.FileData))
            {
                try
                {
                    transportRuleCollection = (TransportRuleCollection)JournalingRuleParser.Instance.LoadStream(stream);
                }
                catch (ParserException exception2)
                {
                    base.WriteError(exception2, ErrorCategory.InvalidData, "FileData");
                    return;
                }
            }
            JournalRuleObject journalRuleObject = new JournalRuleObject();

            foreach (Microsoft.Exchange.MessagingPolicies.Rules.Rule rule in transportRuleCollection)
            {
                JournalingRule journalingRule = (JournalingRule)rule;
                try
                {
                    journalRuleObject.Deserialize(journalingRule);
                }
                catch (RecipientInvalidException exception3)
                {
                    base.WriteError(exception3, ErrorCategory.InvalidArgument, journalRuleObject.JournalEmailAddress);
                    return;
                }
                catch (JournalRuleCorruptException exception4)
                {
                    base.WriteError(exception4, ErrorCategory.InvalidArgument, journalingRule.Name);
                }
                if (journalingRule.IsTooAdvancedToParse)
                {
                    base.WriteError(new InvalidOperationException(Strings.CannotCreateRuleDueToVersion(journalingRule.Name)), ErrorCategory.InvalidOperation, null);
                    return;
                }
            }
            try
            {
                adjournalRuleStorageManager.ReplaceRules(transportRuleCollection, this.ResolveCurrentOrganization());
            }
            catch (DataValidationException exception5)
            {
                base.WriteError(exception5, ErrorCategory.InvalidArgument, null);
            }
        }
コード例 #5
0
        protected override void InternalProcessRecord()
        {
            if (base.Fields.IsModified("JournalEmailAddress") && this.JournalEmailAddress == null)
            {
                base.WriteError(new ArgumentException(Strings.NoRecipients, "JournalEmailAddress"), ErrorCategory.InvalidArgument, this.JournalEmailAddress);
                return;
            }
            if (!base.Fields.IsModified("Name") && !base.Fields.IsModified("Scope") && !base.Fields.IsModified("RecipientProperty") && !base.Fields.IsModified("JournalEmailAddress") && !base.Fields.IsModified("ExpiryDate") && !base.Fields.IsModified("FullReport"))
            {
                base.InternalProcessRecord();
                return;
            }
            ADJournalRuleStorageManager adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", base.DataSession);
            JournalingRule journalingRule;

            try
            {
                journalingRule = (JournalingRule)JournalingRuleParser.Instance.GetRule(this.DataObject.Xml);
            }
            catch (ParserException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidData, null);
                return;
            }
            JournalRuleObject journalRuleObject = new JournalRuleObject();

            try
            {
                journalRuleObject.Deserialize(journalingRule);
                journalRuleObject.Name = this.DataObject.Name;
            }
            catch (RecipientInvalidException exception2)
            {
                base.WriteError(exception2, ErrorCategory.InvalidArgument, this.JournalEmailAddress);
                return;
            }
            catch (JournalRuleCorruptException exception3)
            {
                base.WriteError(exception3, ErrorCategory.InvalidArgument, null);
            }
            if (base.Fields.IsChanged("Name") || base.Fields.IsModified("Name"))
            {
                journalRuleObject.Name = this.Name;
            }
            SmtpAddress journalingReportNdrToSmtpAddress = JournalRuleObject.GetJournalingReportNdrToSmtpAddress(this.DataObject.OrganizationId, this.ConfigurationSession);

            if (base.Fields.IsChanged("RecipientProperty") || base.Fields.IsModified("RecipientProperty"))
            {
                if (this.Recipient != null && this.Recipient != null && this.Recipient.Value == journalingReportNdrToSmtpAddress)
                {
                    base.WriteError(new InvalidOperationException(Strings.JournalingReportNdrToSameAsRecipient), ErrorCategory.InvalidOperation, null);
                    return;
                }
                journalRuleObject.Recipient = this.Recipient;
            }
            if (!base.Fields.IsChanged("JournalEmailAddress"))
            {
                if (!base.Fields.IsModified("JournalEmailAddress"))
                {
                    goto IL_2AE;
                }
            }
            try
            {
                bool        isNonGccInDc = Datacenter.IsMultiTenancyEnabled() && !this.LawfulInterception;
                SmtpAddress smtpAddress;
                if (!JournalRuleObject.LookupAndCheckAllowedTypes(this.JournalEmailAddress, base.TenantGlobalCatalogSession, this.DataObject.OrganizationId, isNonGccInDc, out smtpAddress))
                {
                    base.WriteError(new InvalidOperationException(Strings.JournalingToExternalOnly), ErrorCategory.InvalidOperation, null);
                    return;
                }
                if (smtpAddress == journalingReportNdrToSmtpAddress)
                {
                    this.WriteWarning(Strings.JournalingReportNdrToSameAsJournalEmailAddress);
                }
                journalRuleObject.JournalEmailAddress = smtpAddress;
            }
            catch (RecipientInvalidException exception4)
            {
                base.WriteError(exception4, ErrorCategory.InvalidArgument, "JournalEmailAddress");
                return;
            }
IL_2AE:
            if (base.Fields.IsChanged("Scope") || base.Fields.IsModified("Scope"))
            {
                journalRuleObject.Scope = this.Scope;
            }
            if (base.Fields.IsChanged("ExpiryDate") || base.Fields.IsModified("ExpiryDate"))
            {
                if (this.ExpiryDate != null)
                {
                    journalRuleObject.ExpiryDate = new DateTime?(this.ExpiryDate.Value.ToUniversalTime());
                }
                else
                {
                    journalRuleObject.ExpiryDate = null;
                }
            }
            if (base.Fields.IsChanged("FullReport") || base.Fields.IsModified("FullReport"))
            {
                GccType gccRuleType = GccType.None;
                if (this.LawfulInterception)
                {
                    if (this.FullReport)
                    {
                        gccRuleType = GccType.Full;
                    }
                    else
                    {
                        gccRuleType = GccType.Prtt;
                    }
                }
                journalRuleObject.RuleType = JournalRuleObject.ConvertGccTypeToJournalRuleType(gccRuleType);
            }
            journalingRule      = journalRuleObject.Serialize();
            this.DataObject.Xml = JournalingRuleSerializer.Instance.SaveRuleToString(journalingRule);
            if (!adjournalRuleStorageManager.CanRename((ADObjectId)this.DataObject.Identity, this.DataObject.Name, journalingRule.Name))
            {
                base.WriteError(new ArgumentException(Strings.RuleNameAlreadyExist, "Name"), ErrorCategory.InvalidArgument, this.Name);
                return;
            }
            if (Utils.Exchange12HubServersExist(this))
            {
                this.WriteWarning(Strings.SetRuleSyncAcrossDifferentVersionsNeeded);
            }
            this.DataObject.Name = journalingRule.Name;
            base.InternalProcessRecord();
            if (journalingReportNdrToSmtpAddress == SmtpAddress.NullReversePath)
            {
                this.WriteWarning(Strings.JournalingReportNdrToNotSet);
            }
            return;
        }