protected override void InternalProcessRecord()
        {
            HostedContentFilterRule hostedContentFilterRule = new HostedContentFilterRule(null, base.Name, base.Priority, base.Enabled ? RuleState.Enabled : RuleState.Disabled, base.Comments, base.Conditions, base.Exceptions, new HostedContentFilterPolicyIdParameter(this.policyObject.Name));

            if (this.policyObject.EnableEndUserSpamNotifications && !hostedContentFilterRule.IsEsnCompatible)
            {
                base.WriteError(new OperationNotAllowedException(Strings.ErrorCannotScopeEsnPolicy(this.policyObject.Name)), ErrorCategory.InvalidOperation, null);
            }
            int           priority      = base.Fields.IsModified("Priority") ? hostedContentFilterRule.Priority : -1;
            TransportRule transportRule = null;

            try
            {
                TransportRule        rule = hostedContentFilterRule.ToInternalRule();
                ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession);
                adruleStorageManager.LoadRuleCollection();
                adruleStorageManager.NewRule(rule, this.ResolveCurrentOrganization(), ref priority, out transportRule);
                FfoDualWriter.SaveToFfo <TransportRule>(this, transportRule, TenantSettingSyncLogType.DUALSYNCTR, null);
            }
            catch (RulesValidationException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidArgument, base.Name);
            }
            catch (InvalidPriorityException exception2)
            {
                base.WriteError(exception2, ErrorCategory.InvalidArgument, null);
            }
            catch (ParserException exception3)
            {
                base.WriteError(exception3, ErrorCategory.InvalidData, null);
            }
            hostedContentFilterRule.Priority = priority;
            hostedContentFilterRule.SetTransportRule(transportRule);
            base.WriteObject(hostedContentFilterRule);
        }
示例#2
0
        private void BackupRulesForEheMigration()
        {
            ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession);

            adruleStorageManager.LoadRuleCollection();
            this.transportRuleCollectionBackUp = adruleStorageManager.GetRuleCollection();
        }
示例#3
0
        private void WriteRawRules()
        {
            ADRuleStorageManager ruleStorageManager = base.RuleStorageManager;

            using (Stream stream = new MemoryStream())
            {
                using (StreamWriter streamWriter = new StreamWriter(stream))
                {
                    ruleStorageManager.LoadRuleCollectionWithoutParsing();
                    ruleStorageManager.WriteRawRulesToStream(streamWriter);
                    if (base.NeedSuppressingPiiData)
                    {
                        stream.Seek(0L, SeekOrigin.Begin);
                        StreamReader streamReader = new StreamReader(stream);
                        string       value        = SuppressingPiiData.Redact(streamReader.ReadToEnd());
                        stream.SetLength(0L);
                        streamWriter.Write(value);
                        streamWriter.Flush();
                    }
                    stream.Seek(0L, SeekOrigin.Begin);
                    using (BinaryReader binaryReader = new BinaryReader(stream))
                    {
                        BinaryFileDataObject dataObject = new BinaryFileDataObject
                        {
                            FileData = binaryReader.ReadBytes((int)binaryReader.BaseStream.Length)
                        };
                        this.WriteResult(dataObject);
                    }
                }
            }
        }
示例#4
0
        public override void ProcessRecord()
        {
            if (!this.dataObject.Force && !base.ShouldContinue(Strings.PromptToOverwriteDlpPoliciesOnImport))
            {
                return;
            }
            ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(Utils.RuleCollectionNameFromRole(), base.DataSession);

            adruleStorageManager.LoadRuleCollection();
            foreach (TransportRuleHandle transportRuleHandle in adruleStorageManager.GetRuleHandles())
            {
                Guid guid;
                if (transportRuleHandle.Rule.TryGetDlpPolicyId(out guid))
                {
                    base.DataSession.Delete(transportRuleHandle.AdRule);
                }
            }
            DlpUtils.GetInstalledTenantDlpPolicies(base.DataSession).ToList <ADComplianceProgram>().ForEach(new Action <ADComplianceProgram>(base.DataSession.Delete));
            List <DlpPolicyMetaData> list = DlpUtils.LoadDlpPolicyInstances(this.dataObject.FileData).ToList <DlpPolicyMetaData>();

            foreach (DlpPolicyMetaData dlpPolicy in list)
            {
                IEnumerable <PSObject> enumerable;
                DlpUtils.AddTenantDlpPolicy(base.DataSession, dlpPolicy, Utils.GetOrganizationParameterValue(this.dataObject.Fields), new CmdletRunner(DlpPolicyTemplateMetaData.AllowedCommands, DlpPolicyTemplateMetaData.RequiredParams, null), out enumerable);
            }
        }
示例#5
0
 public static TransportRule ResolvePolicyRuleObject <T>(T policy, IConfigDataProvider session, string ruleCollectionName) where T : ADObject, new()
 {
     if (typeof(T) != typeof(MalwareFilterPolicy) && typeof(T) != typeof(HostedContentFilterPolicy))
     {
         throw new NotSupportedException();
     }
     try
     {
         ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(ruleCollectionName, session);
         adruleStorageManager.LoadRuleCollection();
         foreach (Rule rule in adruleStorageManager.GetRuleCollection())
         {
             TransportRule transportRule = (TransportRule)rule;
             if (transportRule.Actions != null && transportRule.Actions.Count > 0 && transportRule.Actions[0].Arguments != null && transportRule.Actions[0].Arguments.Count == 2)
             {
                 string strA = transportRule.Actions[0].Arguments[1].GetValue(null) as string;
                 if (string.Compare(strA, policy.Name, true) == 0)
                 {
                     return(transportRule);
                 }
             }
         }
     }
     catch (RuleCollectionNotInAdException)
     {
         return(null);
     }
     return(null);
 }
示例#6
0
 protected override void InternalProcessRecord()
 {
     try
     {
         ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession);
         adruleStorageManager.LoadRuleCollection();
         if (base.Fields.IsModified("Priority"))
         {
             this.SetRuleWithPriorityChange(adruleStorageManager);
         }
         else
         {
             this.SetRuleWithoutPriorityChange(adruleStorageManager);
         }
     }
     catch (RuleCollectionNotInAdException)
     {
         base.WriteError(new ArgumentException(Strings.RuleNotFound(this.Identity.ToString()), "Identity"), ErrorCategory.InvalidArgument, this.Identity);
     }
     catch (ParserException exception)
     {
         base.WriteError(exception, ErrorCategory.InvalidData, null);
     }
     catch (ArgumentException exception2)
     {
         base.WriteError(exception2, ErrorCategory.InvalidArgument, null);
     }
     catch (InvalidPriorityException exception3)
     {
         base.WriteError(exception3, ErrorCategory.InvalidArgument, null);
     }
 }
示例#7
0
        private Dictionary <OrganizationId, ADRuleStorageManager> GetRuleCollections(IEnumerable <TransportRule> rules)
        {
            Dictionary <OrganizationId, ADRuleStorageManager> dictionary = new Dictionary <OrganizationId, ADRuleStorageManager>();

            foreach (TransportRule transportRule in rules)
            {
                if (!dictionary.ContainsKey(transportRule.OrganizationId))
                {
                    ADSessionSettings     sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, transportRule.OrganizationId, base.ExecutingUserOrganizationId, false);
                    IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, sessionSettings, 169, "GetRuleCollections", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\MessageHygiene\\HygieneConfiguration\\GetHygieneFilterRuleTaskBase.cs");
                    ADRuleStorageManager  adruleStorageManager;
                    try
                    {
                        adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, tenantOrTopologyConfigurationSession);
                        adruleStorageManager.LoadRuleCollectionWithoutParsing();
                    }
                    catch (RuleCollectionNotInAdException)
                    {
                        continue;
                    }
                    dictionary.Add(transportRule.OrganizationId, adruleStorageManager);
                }
            }
            return(dictionary);
        }
        protected override void InternalProcessRecord()
        {
            MalwareFilterRule malwareFilterRule = new MalwareFilterRule(null, base.Name, base.Priority, base.Enabled ? RuleState.Enabled : RuleState.Disabled, base.Comments, base.Conditions, base.Exceptions, new MalwareFilterPolicyIdParameter(this.policyObject.Name));
            int           priority      = base.Fields.IsModified("Priority") ? malwareFilterRule.Priority : -1;
            TransportRule transportRule = null;

            try
            {
                TransportRule        rule = malwareFilterRule.ToInternalRule();
                ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession);
                adruleStorageManager.LoadRuleCollection();
                adruleStorageManager.NewRule(rule, this.ResolveCurrentOrganization(), ref priority, out transportRule);
            }
            catch (RulesValidationException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidArgument, base.Name);
            }
            catch (InvalidPriorityException exception2)
            {
                base.WriteError(exception2, ErrorCategory.InvalidArgument, null);
            }
            catch (ParserException exception3)
            {
                base.WriteError(exception3, ErrorCategory.InvalidData, null);
            }
            malwareFilterRule.Priority = priority;
            malwareFilterRule.SetTransportRule(transportRule);
            base.WriteObject(malwareFilterRule);
        }
示例#9
0
        protected override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            TransportRule transportRule = (TransportRule)base.PrepareDataObject();

            if (base.HasErrors)
            {
                return(null);
            }
            TransportRule transportRule2;

            try
            {
                transportRule2 = (TransportRule)TransportRuleParser.Instance.GetRule(transportRule.Xml);
            }
            catch (ParserException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidData, null);
                return(null);
            }
            if (transportRule2.IsTooAdvancedToParse)
            {
                base.WriteError(new InvalidOperationException(Strings.CannotModifyRuleDueToVersion(transportRule2.Name)), ErrorCategory.InvalidOperation, null);
                return(null);
            }
            OrganizationId organizationId = transportRule.OrganizationId;

            if (organizationId != OrganizationId.ForestWideOrgId)
            {
                ADRuleStorageManager adruleStorageManager;
                try
                {
                    adruleStorageManager = new ADRuleStorageManager(base.RuleCollectionName, base.DataSession);
                }
                catch (RuleCollectionNotInAdException exception2)
                {
                    base.WriteError(exception2, ErrorCategory.InvalidOperation, null);
                    return(null);
                }
                adruleStorageManager.LoadRuleCollection();
                InvalidOperationException ex = Utils.CheckRuleForOrganizationLimits((IConfigurationSession)base.DataSession, base.TenantGlobalCatalogSession, adruleStorageManager, organizationId, transportRule2, false);
                if (ex != null)
                {
                    base.WriteError(ex, ErrorCategory.InvalidOperation, null);
                    return(null);
                }
            }
            if (Utils.Exchange12HubServersExist(this))
            {
                this.WriteWarning(Strings.SetRuleSyncAcrossDifferentVersionsNeeded);
            }
            transportRule2.Enabled = RuleState.Enabled;
            transportRule2.Mode    = (base.Fields.IsModified("Mode") ? this.Mode : RuleMode.Enforce);
            string xml = TransportRuleSerializer.Instance.SaveRuleToString(transportRule2);

            transportRule.Xml = xml;
            TaskLogger.LogExit();
            return(transportRule);
        }
示例#10
0
 private void RecoverDeletedRules(string domainController)
 {
     if (this.transportRuleCollectionBackUp != null)
     {
         IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(domainController, false, ConsistencyMode.IgnoreInvalid, base.SessionSettings, 631, "RecoverDeletedRules", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\TransportRule\\ImportTransportRuleCollection.cs");
         IConfigDataProvider   session = new MessagingPoliciesSyncLogDataSession(tenantOrTopologyConfigurationSession, null, null);
         ADRuleStorageManager  adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, session);
         adruleStorageManager.ClearRules(null);
         adruleStorageManager.ReplaceRules(this.transportRuleCollectionBackUp, this.ResolveCurrentOrganization());
     }
 }
示例#11
0
        private static TransportRule GetTransportRuleUnParsed(IConfigDataProvider dataSession, string collectionName, QueryFilter filter)
        {
            ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(collectionName, dataSession);

            adruleStorageManager.LoadRuleCollectionWithoutParsing(filter);
            TransportRule result = null;

            if (adruleStorageManager.Count > 0)
            {
                adruleStorageManager.GetRuleWithoutParsing(0, out result);
            }
            return(result);
        }
示例#12
0
        internal static ILookup <string, Microsoft.Exchange.MessagingPolicies.Rules.Rule> GetDataClassificationsInUse(IConfigDataProvider tenantSession, IEnumerable <string> dataClassificationIds, IEqualityComparer <string> dataClassificationIdComparer = null)
        {
            ArgumentValidator.ThrowIfNull("tenantSession", tenantSession);
            ArgumentValidator.ThrowIfNull("dataClassificationIds", dataClassificationIds);
            if (!dataClassificationIds.Any <string>())
            {
                return(Enumerable.Empty <Microsoft.Exchange.MessagingPolicies.Rules.Rule>().ToLookup((Microsoft.Exchange.MessagingPolicies.Rules.Rule rule) => null));
            }
            ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(Utils.RuleCollectionNameFromRole(), tenantSession);

            adruleStorageManager.LoadRuleCollection();
            return(DlpUtils.GetDataClassificationsReferencedByRuleCollection(adruleStorageManager.GetRuleCollection(), dataClassificationIds, dataClassificationIdComparer));
        }
        private TransportRule GetTransportRule(string ruleName)
        {
            ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager("HostedContentFilterVersioned", base.DataSession);

            adruleStorageManager.LoadRuleCollectionWithoutParsing(new TextFilter(ADObjectSchema.Name, ruleName, MatchOptions.FullString, MatchFlags.Default));
            TransportRule result = null;

            if (adruleStorageManager.Count > 0)
            {
                adruleStorageManager.GetRuleWithoutParsing(0, out result);
            }
            return(result);
        }
示例#14
0
        private void ProcessE15Format(IEnumerable <string> cmdlets)
        {
            Exception ex = null;

            try
            {
                IConfigDataProvider  session     = new MessagingPoliciesSyncLogDataSession(base.DataSession, null, null);
                ADRuleStorageManager storedRules = new ADRuleStorageManager(this.ruleCollectionName, session);
                this.ClearExistingRules(storedRules);
            }
            catch (RuleCollectionNotInAdException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
                return;
            }
            string lastUsedDc = (base.DataSession as IConfigurationSession).LastUsedDc;

            cmdlets = this.ProcessCmdlets(cmdlets);
            try
            {
                string       organizationParameterValue = Utils.GetOrganizationParameterValue(base.Fields);
                CmdletRunner cmdletRunner = new CmdletRunner(ImportTransportRuleCollection.AllowedCommands, null, null);
                foreach (string policyCommand in cmdlets)
                {
                    string cmdlet = Utils.AddOrganizationScopeToCmdlet(policyCommand, organizationParameterValue);
                    cmdletRunner.RunCmdlet(cmdlet, !this.ContinueOnFailure);
                }
            }
            catch (ArgumentException ex2)
            {
                ex = ex2;
            }
            catch (ParseException ex3)
            {
                ex = ex3;
            }
            catch (RuntimeException ex4)
            {
                ex = ex4;
            }
            catch (CmdletExecutionException ex5)
            {
                ex = ex5;
            }
            if (ex != null)
            {
                this.RecoverDeletedRules(lastUsedDc);
                base.WriteError(ex, ErrorCategory.InvalidArgument, "Error executing script from the cmdlet block: " + ex.Message);
            }
        }
示例#15
0
        private void SetRuleWithoutPriorityChange(ADRuleStorageManager storedRules)
        {
            TransportRule     transportRule     = (TransportRule)TransportRuleParser.Instance.GetRule(this.DataObject.Xml);
            HygieneFilterRule hygieneFilterRule = this.CreateTaskRuleFromInternalRule(transportRule, -1);

            this.UpdateRuleFromParameters(hygieneFilterRule);
            this.ValidateRuleEsnCompatibility(hygieneFilterRule);
            transportRule       = hygieneFilterRule.ToInternalRule();
            this.DataObject.Xml = TransportRuleSerializer.Instance.SaveRuleToString(transportRule);
            if (base.Fields.IsModified("Name") && !storedRules.CanRename((ADObjectId)this.DataObject.Identity, ((ADObjectId)this.DataObject.Identity).Name, transportRule.Name))
            {
                base.WriteError(new ArgumentException(Strings.RuleNameAlreadyExist, "Name"), ErrorCategory.InvalidArgument, this.Name);
            }
            base.InternalProcessRecord();
        }
        private static SupervisionPolicy GetPresentationObject(ADRuleStorageManager storageManager, ref Dictionary <string, string> rules, bool displayDetails)
        {
            SupervisionPolicy supervisionPolicy = new SupervisionPolicy("SupervisionPolicy" + storageManager.RuleCollectionId.GetHashCode().ToString());

            foreach (Microsoft.Exchange.MessagingPolicies.Rules.Rule rule in storageManager.GetRuleCollection())
            {
                TransportRule transportRule = (TransportRule)rule;
                if (!transportRule.IsTooAdvancedToParse)
                {
                    Microsoft.Exchange.MessagingPolicies.Rules.Tasks.Rule rule2 = Microsoft.Exchange.MessagingPolicies.Rules.Tasks.Rule.CreateFromInternalRule(TransportRulePredicate.BridgeheadMappings, TransportRuleAction.BridgeheadMappings, transportRule, 0, null);
                    if (transportRule.Name.Equals(GetSupervisionPolicy.ClosedCampusInboundRuleName))
                    {
                        supervisionPolicy.ClosedCampusInboundPolicyEnabled = (transportRule.Enabled == RuleState.Enabled);
                        if (displayDetails)
                        {
                            supervisionPolicy.ClosedCampusInboundPolicyGroupExceptions  = GetSupervisionPolicy.ConvertToSmtpAddressMVP(rule2.ExceptIfSentToMemberOf);
                            supervisionPolicy.ClosedCampusInboundPolicyDomainExceptions = GetSupervisionPolicy.ConvertToSmtpDomains(rule2.ExceptIfFromAddressMatchesPatterns);
                        }
                        rules.Remove(GetSupervisionPolicy.ClosedCampusInboundRuleName);
                    }
                    else if (transportRule.Name.Equals(GetSupervisionPolicy.ClosedCampusOutboundRuleName))
                    {
                        supervisionPolicy.ClosedCampusOutboundPolicyEnabled = (transportRule.Enabled == RuleState.Enabled);
                        if (displayDetails)
                        {
                            supervisionPolicy.ClosedCampusOutboundPolicyGroupExceptions  = GetSupervisionPolicy.ConvertToSmtpAddressMVP(rule2.ExceptIfFromMemberOf);
                            supervisionPolicy.ClosedCampusOutboundPolicyDomainExceptions = GetSupervisionPolicy.ConvertToSmtpDomains(rule2.ExceptIfRecipientAddressMatchesPatterns);
                        }
                        rules.Remove(GetSupervisionPolicy.ClosedCampusOutboundRuleName);
                    }
                    else if (transportRule.Name.Equals(GetSupervisionPolicy.BadWordsRuleName))
                    {
                        supervisionPolicy.BadWordsPolicyEnabled = (transportRule.Enabled == RuleState.Enabled);
                        if (displayDetails)
                        {
                            supervisionPolicy.BadWordsList = GetSupervisionPolicy.ConvertToCommaSeparatedString(rule2.SubjectOrBodyContainsWords);
                        }
                        rules.Remove(GetSupervisionPolicy.BadWordsRuleName);
                    }
                    else if (transportRule.Name.Equals(GetSupervisionPolicy.AntiBullyingRuleName))
                    {
                        supervisionPolicy.AntiBullyingPolicyEnabled = (transportRule.Enabled == RuleState.Enabled);
                        rules.Remove(GetSupervisionPolicy.AntiBullyingRuleName);
                    }
                }
            }
            return(supervisionPolicy);
        }
示例#17
0
        private int GetSequenceNumberForPriority(int priority, int currentSequenceNumber)
        {
            if (priority < 0)
            {
                throw new ArgumentOutOfRangeException("priority");
            }
            List <TransportRule> list = (from r in this.rules
                                         where r.Priority != currentSequenceNumber
                                         select r).ToList <TransportRule>();

            if (priority > list.Count)
            {
                priority = list.Count;
            }
            ADRuleStorageManager.NormalizeInternalSequenceNumbersIfNecessary(list, this.session);
            return(ADRuleStorageManager.AssignInternalSequenceNumber(list, priority));
        }
示例#18
0
        private void WriteFormattedRules()
        {
            ADRuleStorageManager ruleStorageManager = base.RuleStorageManager;

            ruleStorageManager.LoadRuleCollection();
            IEnumerable <TransportRuleHandle> ruleHandles = ruleStorageManager.GetRuleHandles();
            List <Rule> list = new List <Rule>();

            foreach (TransportRuleHandle transportRuleHandle in ruleHandles)
            {
                string text = null;
                try
                {
                    Rule rule = Rule.CreateFromInternalRule(this.supportedPredicates, this.supportedActions, transportRuleHandle.Rule, transportRuleHandle.AdRule.Priority, transportRuleHandle.AdRule);
                    if (base.NeedSuppressingPiiData)
                    {
                        rule.SuppressPiiData(Utils.GetSessionPiiMap(base.ExchangeRunspaceConfig));
                    }
                    list.Add(rule);
                }
                catch (ArgumentException ex)
                {
                    text = ex.Message;
                }
                catch (InvalidOperationException ex2)
                {
                    text = ex2.Message;
                }
                catch (ParserException ex3)
                {
                    text = ex3.Message;
                }
                catch (RulesValidationException ex4)
                {
                    text = ex4.Message;
                }
                if (text != null)
                {
                    base.WriteWarning(Strings.ErrorObjectHasValidationErrorsWithId(transportRuleHandle.AdRule.Identity.ToString()) + " " + text);
                }
            }
            this.WriteResult(new BinaryFileDataObject
            {
                FileData = PowershellTransportRuleSerializer.Serialize(list)
            });
        }
示例#19
0
        private void ClearExistingRules(ADRuleStorageManager storedRules)
        {
            switch ((base.Fields["MigrationSource"] == null) ? MigrationSourceType.None : ((MigrationSourceType)base.Fields["MigrationSource"]))
            {
            case MigrationSourceType.Fope:
                storedRules.ClearRules(new ADRuleStorageManager.RuleFilter(ImportTransportRuleCollection.IsMigratedRule));
                return;

            case MigrationSourceType.Ehe:
                this.BackupRulesForEheMigration();
                storedRules.ClearRules(null);
                return;

            default:
                storedRules.ClearRules(null);
                return;
            }
        }
示例#20
0
 protected override void WriteResult <T>(IEnumerable <T> dataObjects)
 {
     try
     {
         if (this.Identity == null)
         {
             ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession);
             adruleStorageManager.LoadRuleCollectionWithoutParsing();
             for (int i = 0; i < adruleStorageManager.Count; i++)
             {
                 TransportRule transportRule;
                 adruleStorageManager.GetRuleWithoutParsing(i, out transportRule);
                 this.OutputRule(i, transportRule);
             }
         }
         else
         {
             List <TransportRule> list = new List <TransportRule>();
             list.AddRange((IEnumerable <TransportRule>)dataObjects);
             Dictionary <OrganizationId, ADRuleStorageManager> ruleCollections = this.GetRuleCollections(list);
             foreach (KeyValuePair <OrganizationId, ADRuleStorageManager> keyValuePair in ruleCollections)
             {
                 for (int j = 0; j < keyValuePair.Value.Count; j++)
                 {
                     TransportRule transportRule;
                     keyValuePair.Value.GetRuleWithoutParsing(j, out transportRule);
                     if (Utils.IsRuleIdInList(transportRule.Id, list))
                     {
                         this.OutputRule(j, transportRule);
                     }
                 }
             }
         }
     }
     catch (RuleCollectionNotInAdException)
     {
     }
 }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            Dictionary <string, string> ruleNames            = GetSupervisionPolicy.GetRuleNames();
            ADRuleStorageManager        adruleStorageManager = null;

            try
            {
                adruleStorageManager = new ADRuleStorageManager("TransportVersioned", base.DataSession);
            }
            catch (RuleCollectionNotInAdException exception)
            {
                base.WriteError(exception, (ErrorCategory)1003, null);
            }
            QueryFilter queryFilter = GetSupervisionPolicy.GetQueryFilter(ruleNames.Keys);

            adruleStorageManager.LoadRuleCollectionWithoutParsing(queryFilter);
            try
            {
                adruleStorageManager.ParseRuleCollection();
            }
            catch (ParserException exception2)
            {
                base.WriteError(exception2, (ErrorCategory)1003, null);
            }
            SupervisionPolicy presentationObject = GetSupervisionPolicy.GetPresentationObject(adruleStorageManager, ref ruleNames, this.DisplayDetails.ToBool());

            this.WriteResult(presentationObject);
            string missingPolicies = GetSupervisionPolicy.GetMissingPolicies(ruleNames);

            if (!string.IsNullOrEmpty(missingPolicies))
            {
                this.WriteWarning(Strings.SupervisionPoliciesNotFound(missingPolicies));
            }
            TaskLogger.LogExit();
        }
示例#22
0
        private void SetRuleWithPriorityChange(ADRuleStorageManager storedRules)
        {
            TransportRule transportRule;
            int           priority;

            storedRules.GetRule(this.DataObject.Identity, out transportRule, out priority);
            if (transportRule == null)
            {
                base.WriteError(new ArgumentException(Strings.RuleNotFound(this.Identity.ToString()), "Identity"), ErrorCategory.InvalidArgument, this.Identity);
            }
            HygieneFilterRule hygieneFilterRule = this.CreateTaskRuleFromInternalRule(transportRule, priority);

            this.UpdateRuleFromParameters(hygieneFilterRule);
            this.ValidateRuleEsnCompatibility(hygieneFilterRule);
            transportRule = hygieneFilterRule.ToInternalRule();
            try
            {
                storedRules.UpdateRule(transportRule, hygieneFilterRule.Identity, hygieneFilterRule.Priority);
            }
            catch (RulesValidationException)
            {
                base.WriteError(new ArgumentException(Strings.RuleNameAlreadyExist, "Name"), ErrorCategory.InvalidArgument, this.Name);
            }
        }
示例#23
0
        protected override void InternalProcessRecord()
        {
            ADRuleStorageManager adruleStorageManager = this.RuleStorageManager;

            if (adruleStorageManager == null)
            {
                return;
            }
            using (Stream stream = new MemoryStream())
            {
                using (StreamWriter streamWriter = new StreamWriter(stream))
                {
                    adruleStorageManager.LoadRuleCollectionWithoutParsing();
                    IEnumerable <Rule> source = adruleStorageManager.WriteToStream(streamWriter, ExportRuleCollectionTaskBase.MaxLegacyFormatVersion, null);
                    stream.Seek(0L, SeekOrigin.Begin);
                    BinaryReader         binaryReader = new BinaryReader(stream);
                    BinaryFileDataObject dataObject   = new BinaryFileDataObject
                    {
                        FileData = binaryReader.ReadBytes((int)binaryReader.BaseStream.Length)
                    };
                    this.WriteResult(dataObject);
                    if (source.Any <Rule>())
                    {
                        this.WriteWarning(Strings.ExportSkippedE15Rules(source.Count <Rule>()));
                    }
                }
            }
            try
            {
                adruleStorageManager.ParseRuleCollection();
            }
            catch (ParserException ex)
            {
                this.WriteWarning(Strings.CorruptRuleCollection(ex.Message));
            }
        }
示例#24
0
 internal static IEnumerable <TransportRuleHandle> GetTransportRuleHandles(IConfigDataProvider dataSession, out ADRuleStorageManager ruleStorageManager)
 {
     ruleStorageManager = new ADRuleStorageManager(Utils.RuleCollectionNameFromRole(), dataSession);
     ruleStorageManager.LoadRuleCollection();
     return(ruleStorageManager.GetRuleHandles());
 }
示例#25
0
        private void ProcessE14Format(TransportRuleCollection rules)
        {
            ADRuleStorageManager adruleStorageManager;

            try
            {
                IConfigDataProvider session = new MessagingPoliciesSyncLogDataSession(base.DataSession, null, null);
                adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, session);
            }
            catch (RuleCollectionNotInAdException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
                return;
            }
            Exception ex = null;

            try
            {
                if (!Utils.IsEdgeRoleInstalled())
                {
                    Version v     = null;
                    bool    flag  = false;
                    bool    flag2 = false;
                    foreach (Rule rule in rules)
                    {
                        TransportRule transportRule = (TransportRule)rule;
                        if (transportRule.IsTooAdvancedToParse)
                        {
                            base.WriteError(new InvalidOperationException(Strings.CannotCreateRuleDueToVersion(transportRule.Name)), ErrorCategory.InvalidOperation, null);
                            return;
                        }
                        Version minimumVersion = transportRule.MinimumVersion;
                        if (v == null || v < minimumVersion)
                        {
                            v = minimumVersion;
                        }
                        if (!flag || !flag2)
                        {
                            foreach (Action action in transportRule.Actions)
                            {
                                if (string.Equals(action.Name, "ApplyDisclaimer") || string.Equals(action.Name, "ApplyDisclaimerWithSeparator") || string.Equals(action.Name, "ApplyDisclaimerWithSeparatorAndReadingOrder"))
                                {
                                    flag = true;
                                }
                                if (string.Equals(action.Name, "LogEvent"))
                                {
                                    flag2 = true;
                                }
                            }
                        }
                    }
                    if (flag && !this.Force && !base.ShouldContinue(Strings.PromptToUpgradeRulesFormat))
                    {
                        return;
                    }
                    if (flag2 && !this.Force && !base.ShouldContinue(Strings.PromptToRemoveLogEventAction))
                    {
                        return;
                    }
                }
                try
                {
                    adruleStorageManager.ReplaceRules(rules, this.ResolveCurrentOrganization());
                }
                catch (DataValidationException exception2)
                {
                    base.WriteError(exception2, ErrorCategory.InvalidArgument, null);
                    return;
                }
            }
            catch (ArgumentOutOfRangeException ex2)
            {
                ex = ex2;
            }
            catch (ArgumentException ex3)
            {
                ex = ex3;
            }
            catch (PathTooLongException ex4)
            {
                ex = ex4;
            }
            catch (DirectoryNotFoundException ex5)
            {
                ex = ex5;
            }
            catch (UnauthorizedAccessException ex6)
            {
                ex = ex6;
            }
            catch (FileNotFoundException ex7)
            {
                ex = ex7;
            }
            catch (IOException ex8)
            {
                ex = ex8;
            }
            catch (NotSupportedException ex9)
            {
                ex = ex9;
            }
            if (ex != null)
            {
                base.WriteError(ex, ErrorCategory.InvalidOperation, null);
            }
        }
        protected override void InternalValidate()
        {
            base.InternalValidate();
            TransportConfigContainer transportConfigContainer = (TransportConfigContainer)this.DataObject.GetOriginalObject();

            if (!(this.DataObject.Schema is TransportConfigContainerSchema))
            {
                if (this.DataObject.IsModified(TransportConfigContainerSchema.AnonymousSenderToRecipientRatePerHour) || this.DataObject.IsModified(TransportConfigContainerSchema.MaxDumpsterSizePerDatabase) || this.DataObject.IsModified(TransportConfigContainerSchema.MaxDumpsterTime) || this.DataObject.IsModified(TransportConfigContainerSchema.MaxReceiveSize) || this.DataObject.IsModified(TransportConfigContainerSchema.MaxRecipientEnvelopeLimit) || this.DataObject.IsModified(TransportConfigContainerSchema.SupervisionTags) || this.DataObject.IsModified(TransportConfigContainerSchema.ShadowHeartbeatFrequency) || this.DataObject.IsModified(TransportConfigContainerSchema.ShadowResubmitTimeSpan) || base.Fields.IsModified("QueueDiagnosticsAggregationInterval") || base.Fields.IsModified("DiagnosticsAggregationServicePort") || base.Fields.IsModified("AgentGeneratedMessageLoopDetectionInSubmissionEnabled") || base.Fields.IsModified("AgentGeneratedMessageLoopDetectionInSmtpEnabled") || base.Fields.IsModified("MaxAllowedAgentGeneratedMessageDepth") || base.Fields.IsModified("MaxAllowedAgentGeneratedMessageDepthPerAgent"))
                {
                    this.WriteWarning(Strings.WarningUnsupportedEdgeTransportConfigProperty);
                }
                if (Server.IsSubscribedGateway(base.GlobalConfigSession))
                {
                    ADPropertyDefinition[] array = new ADPropertyDefinition[]
                    {
                        ADAMTransportConfigContainerSchema.InternalSMTPServers,
                        ADAMTransportConfigContainerSchema.TLSReceiveDomainSecureList,
                        ADAMTransportConfigContainerSchema.TLSSendDomainSecureList,
                        ADAMTransportConfigContainerSchema.ShadowHeartbeatRetryCount,
                        ADAMTransportConfigContainerSchema.ShadowHeartbeatTimeoutInterval,
                        ADAMTransportConfigContainerSchema.ShadowMessageAutoDiscardInterval,
                        ADAMTransportConfigContainerSchema.RejectMessageOnShadowFailure,
                        ADAMTransportConfigContainerSchema.ShadowMessagePreferenceSetting,
                        ADAMTransportConfigContainerSchema.MaxRetriesForLocalSiteShadow,
                        ADAMTransportConfigContainerSchema.MaxRetriesForRemoteSiteShadow
                    };
                    foreach (ADPropertyDefinition adpropertyDefinition in array)
                    {
                        if (this.DataObject.IsModified(adpropertyDefinition))
                        {
                            base.WriteError(new CannotSetTransportServerPropertyOnSubscribedEdgeException(adpropertyDefinition.Name), ErrorCategory.InvalidOperation, base.Identity);
                        }
                    }
                    this.ValidateFlagSettingUnchanged <bool>(transportConfigContainer, ADAMTransportConfigContainerSchema.ShadowRedundancyDisabled, "ShadowRedundancyEnabled");
                    this.ValidateFlagSettingUnchanged <ShadowMessagePreference>(transportConfigContainer, ADAMTransportConfigContainerSchema.ShadowMessagePreferenceSetting, "ShadowMessagePreferenceSetting");
                    this.ValidateFlagSettingUnchanged <bool>(transportConfigContainer, ADAMTransportConfigContainerSchema.RejectMessageOnShadowFailure, "RejectMessageOnShadowFailure");
                }
            }
            if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled)
            {
                this.ValidateLegacyArchiveLiveJournalingConfiguration(transportConfigContainer);
                if (this.DataObject.IsModified(ADAMTransportConfigContainerSchema.JournalingReportNdrTo))
                {
                    SmtpAddress journalingReportNdrTo = this.DataObject.JournalingReportNdrTo;
                    if (this.DataObject.JournalingReportNdrTo.IsValidAddress)
                    {
                        JournalNdrValidationCheckResult journalNdrValidationCheckResult = JournalRuleObject.ValidateJournalNdrMailboxSetting(base.DataSession, this.DataObject.JournalingReportNdrTo);
                        if (journalNdrValidationCheckResult == JournalNdrValidationCheckResult.JournalNdrCannotBeNullReversePath)
                        {
                            base.WriteError(new InvalidOperationException(Strings.JournalNdrMailboxCannotBeNull), ErrorCategory.InvalidOperation, null);
                        }
                        else if (journalNdrValidationCheckResult == JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleRecipient)
                        {
                            base.WriteError(new InvalidOperationException(Strings.JournalNdrMailboxInJournalRuleRecipient), ErrorCategory.InvalidOperation, null);
                        }
                        else if (journalNdrValidationCheckResult == JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleJournalEmailAddress)
                        {
                            this.WriteWarning(Strings.JournalNdrMailboxInJournalRuleJournalEmailAddress);
                        }
                    }
                }
            }
            this.WarnForJournalNdrMailboxSetting(transportConfigContainer);
            if (this.DataObject.IsModified(ADAMTransportConfigContainerSchema.TLSReceiveDomainSecureList) && this.DataObject.TLSReceiveDomainSecureList.Count > 256)
            {
                base.WriteError(new ExceededMaximumCollectionCountException(ADAMTransportConfigContainerSchema.TLSReceiveDomainSecureList.Name, 256, this.DataObject.TLSReceiveDomainSecureList.Count), ErrorCategory.InvalidOperation, base.Identity);
            }
            if (this.DataObject.IsModified(ADAMTransportConfigContainerSchema.TLSSendDomainSecureList) && this.DataObject.TLSSendDomainSecureList.Count > 256)
            {
                base.WriteError(new ExceededMaximumCollectionCountException(ADAMTransportConfigContainerSchema.TLSSendDomainSecureList.Name, 256, this.DataObject.TLSSendDomainSecureList.Count), ErrorCategory.InvalidOperation, base.Identity);
            }
            if (this.DataObject.IsModified(ADAMTransportConfigContainerSchema.ExternalPostmasterAddress) && this.DataObject.ExternalPostmasterAddress != null && (!this.DataObject.ExternalPostmasterAddress.Value.IsValidAddress || this.DataObject.ExternalPostmasterAddress.Value == SmtpAddress.NullReversePath))
            {
                base.WriteError(new InvalidPostMasterAddressException(), ErrorCategory.InvalidOperation, base.Identity);
            }
            if (this.DataObject.IsModified(TransportConfigContainerSchema.TransportRuleRegexValidationTimeout) && this.DataObject.TransportRuleRegexValidationTimeout.TotalMilliseconds <= 0.0)
            {
                base.WriteError(new InvalidArgumentException("TransportRuleRegexValidationTimeout"), ErrorCategory.InvalidArgument, this.DataObject.TransportRuleRegexValidationTimeout);
            }
            if (this.DataObject.IsChanged(TransportConfigContainerSchema.SupervisionTags))
            {
                HashSet <string> hashSet = new HashSet <string>(transportConfigContainer.SupervisionTags, StringComparer.OrdinalIgnoreCase);
                foreach (string item in this.DataObject.SupervisionTags)
                {
                    hashSet.Remove(item);
                }
                if (hashSet.Count != 0)
                {
                    this.WriteWarning(Strings.WarningSupervisionTagsRemoved);
                }
            }
            this.ValidateShadowRedundancyPreference(transportConfigContainer);
            if (this.DataObject.IsModified(ADAMTransportConfigContainerSchema.SafetyNetHoldTime))
            {
                this.WriteWarning(Strings.WarningSafetyNetHoldTimeMustBeGreaterThanReplayLagTime);
            }
            if (VariantConfiguration.InvariantNoFlightingSnapshot.Transport.LimitTransportRules.Enabled && this.DataObject.IsModified(TransportConfigContainerSchema.TransportRuleLimit))
            {
                int num  = (int)this.DataObject[TransportConfigContainerSchema.TransportRuleLimit];
                int num2 = 0;
                try
                {
                    ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(Utils.RuleCollectionNameFromRole(), base.DataSession);
                    adruleStorageManager.LoadRuleCollection();
                    num2 = adruleStorageManager.Count;
                }
                catch (RuleCollectionNotInAdException)
                {
                }
                if (num2 > num)
                {
                    base.WriteError(new TransportRuleLimitTooSmallException(num, num2), ErrorCategory.InvalidOperation, base.Identity);
                }
            }
        }