Exemplo n.º 1
0
        private void WriteRuleObject(TransportRule transportRule)
        {
            JournalingRule  journalingRule = null;
            ParserException ex             = null;

            try
            {
                journalingRule = (JournalingRule)JournalingRuleParser.Instance.GetRule(transportRule.Xml);
            }
            catch (ParserException ex2)
            {
                ex = ex2;
            }
            Exception ex3 = null;

            if (journalingRule != null && journalingRule.GccRuleType != GccType.None && !this.LawfulInterception)
            {
                return;
            }
            if (journalingRule != null && journalingRule.GccRuleType == GccType.None && this.LawfulInterception)
            {
                return;
            }
            JournalRuleObject journalRuleObject;

            if (journalingRule == null)
            {
                journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CorruptRule(transportRule.Name, ex.Message));
            }
            else if (journalingRule.IsTooAdvancedToParse)
            {
                journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CannotParseRuleDueToVersion(transportRule.Name));
            }
            else
            {
                journalRuleObject = new JournalRuleObject();
                try
                {
                    journalRuleObject.Deserialize(journalingRule);
                }
                catch (RecipientInvalidException ex4)
                {
                    ex3 = ex4;
                }
                catch (JournalRuleCorruptException ex5)
                {
                    ex3 = ex5;
                }
            }
            if (ex3 != null)
            {
                journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CorruptRule(transportRule.Name, ex3.Message));
            }
            journalRuleObject.SetTransportRule(transportRule);
            this.WriteResult(journalRuleObject);
        }
Exemplo n.º 2
0
        protected override void InternalValidate()
        {
            if (base.OptionalIdentityData != null)
            {
                base.OptionalIdentityData.ConfigurationContainerRdn = RuleIdParameter.GetRuleCollectionRdn("JournalingVersioned");
            }
            if (!Utils.ValidateGccJournalRuleParameters(this, false))
            {
                return;
            }
            if (this.ExpiryDate != null && this.ExpiryDate.Value.ToUniversalTime().Date < DateTime.UtcNow.Date)
            {
                base.WriteError(new InvalidOperationException(Strings.JournalingExpiryDateAlreadyExpired), ErrorCategory.InvalidOperation, null);
                return;
            }
            this.DataObject = (TransportRule)base.GetDataObject <TransportRule>(this.Identity, base.DataSession, this.RootId, base.OptionalIdentityData, null, null);
            if (!this.DataObject.OrganizationId.Equals(OrganizationId.ForestWideOrgId) && !((IDirectorySession)base.DataSession).SessionSettings.CurrentOrganizationId.Equals(this.DataObject.OrganizationId))
            {
                base.UnderscopeDataSession(this.DataObject.OrganizationId);
            }
            if (base.HasErrors)
            {
                return;
            }
            if (!Utils.IsChildOfRuleContainer(this.Identity, "JournalingVersioned"))
            {
                throw new ManagementObjectNotFoundException(base.GetErrorMessageObjectNotFound((this.Identity != null) ? this.Identity.ToString() : null, typeof(RuleIdParameter).ToString(), (base.DataSession != null) ? base.DataSession.Source : null));
            }
            JournalingRule journalingRule = null;

            try
            {
                journalingRule = (JournalingRule)JournalingRuleParser.Instance.GetRule(this.DataObject.Xml);
            }
            catch (ParserException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidData, null);
                return;
            }
            if (journalingRule.GccRuleType != GccType.None && !this.LawfulInterception)
            {
                throw new ManagementObjectNotFoundException(base.GetErrorMessageObjectNotFound((this.Identity != null) ? this.Identity.ToString() : null, typeof(RuleIdParameter).ToString(), (base.DataSession != null) ? base.DataSession.Source : null));
            }
            if (journalingRule.IsTooAdvancedToParse)
            {
                base.WriteError(new InvalidOperationException(Strings.CannotModifyRuleDueToVersion(journalingRule.Name)), ErrorCategory.InvalidOperation, this.Name);
            }
        }
Exemplo n.º 3
0
        internal JournalingRule Serialize()
        {
            Microsoft.Exchange.MessagingPolicies.Rules.Condition condition  = this.CreateScopeCondition();
            Microsoft.Exchange.MessagingPolicies.Rules.Condition condition2 = this.CreateRecipientCondition();
            Microsoft.Exchange.MessagingPolicies.Rules.Condition condition3 = this.CombineUsingAnd(new Microsoft.Exchange.MessagingPolicies.Rules.Condition[]
            {
                condition,
                condition2
            });
            Microsoft.Exchange.MessagingPolicies.Rules.Action item = this.CreateAction();
            JournalingRule journalingRule = (JournalingRule)JournalingRuleParser.Instance.CreateRule(base.Name);

            journalingRule.Condition = condition3;
            journalingRule.Actions.Add(item);
            journalingRule.ExpiryDate  = this.ExpiryDate;
            journalingRule.GccRuleType = JournalRuleObject.ConvertJournalRuleTypeToGccType(this.RuleType);
            journalingRule.Enabled     = (this.enabled ? RuleState.Enabled : RuleState.Disabled);
            return(journalingRule);
        }
Exemplo n.º 4
0
        internal void Deserialize(JournalingRule rule)
        {
            base.Name = rule.Name;
            this.ReadAction(rule);
            this.enabled    = (rule.Enabled == RuleState.Enabled);
            this.ExpiryDate = rule.ExpiryDate;
            this.RuleType   = JournalRuleObject.ConvertGccTypeToJournalRuleType(rule.GccRuleType);
            this.Recipient  = null;
            this.Scope      = JournalRuleScope.Global;
            if (rule.Condition.ConditionType == ConditionType.True)
            {
                return;
            }
            if (this.TryReadScopeCondition(rule.Condition))
            {
                return;
            }
            if (this.TryReadRecipientCondition(rule.Condition))
            {
                return;
            }
            if (rule.Condition.ConditionType != ConditionType.And)
            {
                throw new JournalRuleCorruptException();
            }
            List <Microsoft.Exchange.MessagingPolicies.Rules.Condition> subConditions = ((AndCondition)rule.Condition).SubConditions;

            if (subConditions.Count != 2)
            {
                throw new JournalRuleCorruptException();
            }
            foreach (Microsoft.Exchange.MessagingPolicies.Rules.Condition condition in subConditions)
            {
                if (!this.TryReadScopeCondition(condition) && !this.TryReadRecipientCondition(condition))
                {
                    throw new JournalRuleCorruptException();
                }
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
            }
        }