Esempio n. 1
0
 private void SetAction(bool responseCodeModified, bool responseTextModified, bool actionModified, bool pathModified, bool timeIntervalModified)
 {
     if (responseCodeModified || responseTextModified || actionModified || timeIntervalModified || pathModified)
     {
         string customResponseCode = this.CustomResponseCode;
         bool   flag = false;
         if (!responseCodeModified && !SmtpResponse.Empty.Equals(this.rule.Action.Response))
         {
             customResponseCode = this.rule.Action.Response.StatusCode;
             flag = true;
         }
         string customResponseText = this.CustomResponseString;
         bool   flag2 = false;
         if (!responseTextModified && !SmtpResponse.Empty.Equals(this.rule.Action.Response))
         {
             customResponseText = this.rule.Action.Response.StatusText[0];
             flag2 = true;
         }
         TimeSpan timeInterval = timeIntervalModified ? this.TimeInterval : this.rule.Action.Delay;
         InterceptorAgentAction interceptorAgentAction;
         LocalizedString        warning;
         LocalizedString        localizedString;
         if (!InterceptorHelper.TryCreateAction(actionModified ? this.Action : this.rule.Action.Action, customResponseCode, responseCodeModified || flag, customResponseText, responseTextModified || flag2, timeInterval, pathModified ? this.Path : this.rule.Action.Path, out interceptorAgentAction, out warning, out localizedString))
         {
             base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, actionModified ? this.Action : this.rule.Action.Action);
         }
         this.WriteWarningAndReset(warning);
         if (actionModified && InterceptorAgentAction.IsArchivingBehavior(interceptorAgentAction.Action))
         {
             this.WriteWarning(InterceptorHelper.GetArchivedItemRetentionMessage(interceptorAgentAction.Action, this.Identity.ToString(), this.Path, 14));
         }
         this.rule.Action = interceptorAgentAction;
     }
 }
Esempio n. 2
0
 internal static bool TryCreateAction(InterceptorAgentRuleBehavior behavior, string customResponseCode, bool responseCodeModified, string customResponseText, bool responseTextModified, TimeSpan timeInterval, string path, out InterceptorAgentAction action, out LocalizedString warning, out LocalizedString error)
 {
     action  = null;
     error   = LocalizedString.Empty;
     warning = LocalizedString.Empty;
     if (!InterceptorAgentAction.IsValidRuleBehavior(behavior))
     {
         error = Strings.InterceptorErrorInvalidBehavior(behavior.ToString(), string.Join(", ", InterceptorAgentAction.AllActions));
         return(false);
     }
     if (behavior == InterceptorAgentRuleBehavior.TransientReject || behavior == InterceptorAgentRuleBehavior.PermanentReject)
     {
         return(InterceptorHelper.TryCreateRejectAction(behavior, customResponseCode, responseCodeModified, customResponseText, responseTextModified, out action, out error));
     }
     if ((responseCodeModified || responseTextModified) && !InterceptorAgentAction.IsRejectingBehavior(behavior))
     {
         warning = Strings.InterceptorWarningCustomResponseCodeTextWithoutRejectAction;
     }
     if (behavior == InterceptorAgentRuleBehavior.Delay || behavior == InterceptorAgentRuleBehavior.Defer)
     {
         if (timeInterval <= TimeSpan.Zero || timeInterval >= TimeSpan.FromMilliseconds(2147483647.0))
         {
             error = Strings.InterceptorErrorTimeIntervalInvalid(timeInterval);
             return(false);
         }
         action = new InterceptorAgentAction(behavior, timeInterval);
     }
     else if (InterceptorAgentAction.IsArchivingBehavior(behavior))
     {
         if (!string.IsNullOrEmpty(path))
         {
             if (Path.GetInvalidPathChars().Any((char ch) => path.Contains(ch)))
             {
                 error = Strings.InterceptorErrorPathInvalidCharacters(path);
                 return(false);
             }
         }
         if (!string.IsNullOrEmpty(path) && Path.IsPathRooted(path))
         {
             error = Strings.InterceptorErrorRootedPathNotAllowed(path);
             return(false);
         }
         SmtpResponse response;
         if (!InterceptorHelper.CreateRejectSmtpResponse(behavior, customResponseCode, responseCodeModified, customResponseText, responseTextModified, out response, out error))
         {
             return(false);
         }
         action = new InterceptorAgentAction(behavior, path, response);
     }
     else
     {
         action = new InterceptorAgentAction(behavior);
     }
     if (!string.IsNullOrEmpty(path) && !InterceptorAgentAction.IsArchivingBehavior(behavior))
     {
         warning = Strings.InterceptorWarningPathIgnored;
     }
     return(true);
 }
Esempio n. 3
0
        private static bool TryCreateRejectAction(InterceptorAgentRuleBehavior behavior, string customResponseCode, bool responseCodeModified, string customResponseText, bool responseTextModified, out InterceptorAgentAction action, out LocalizedString error)
        {
            action = null;
            SmtpResponse response;

            if (!InterceptorHelper.CreateRejectSmtpResponse(behavior, customResponseCode, responseCodeModified, customResponseText, responseTextModified, out response, out error))
            {
                return(false);
            }
            action = new InterceptorAgentAction(behavior, response);
            return(true);
        }
        protected override void InternalValidate()
        {
            base.InternalValidate();
            if (base.Fields.IsModified("ExpireTime") && DateTime.UtcNow > this.ExpireTime.ToUniversalTime())
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorExpireTimePassed(this.ExpireTime.ToString("G"))), ErrorCategory.InvalidData, "ExpireTime");
            }
            List <InterceptorAgentCondition> conditions;
            LocalizedString localizedString;

            if (!InterceptorHelper.TryCreateConditions(this.Condition, out conditions, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Condition);
                return;
            }
            if (this.Event == InterceptorAgentEvent.Invalid)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorEventInvalid), ErrorCategory.InvalidData, this.Event);
            }
            if (this.Action == InterceptorAgentRuleBehavior.NoOp)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorActionInvalid), ErrorCategory.InvalidData, this.Action);
            }
            if (!InterceptorHelper.ValidateEventConditionPairs(this.Event, conditions, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
            }
            if (!InterceptorHelper.ValidateEventActionPairs(this.Event, this.Action, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
            }
            InterceptorAgentAction interceptorAgentAction;
            LocalizedString        warning;

            if (!InterceptorHelper.TryCreateAction(this.Action, this.CustomResponseCode, base.Fields.IsChanged("CustomResponseCode"), this.CustomResponseString, base.Fields.IsChanged("CustomResponseText"), this.TimeInterval, this.Path, out interceptorAgentAction, out warning, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Action);
            }
            this.WriteWarningAndReset(warning);
            if (InterceptorAgentAction.IsArchivingBehavior(interceptorAgentAction.Action))
            {
                this.WriteWarning(InterceptorHelper.GetArchivedItemRetentionMessage(interceptorAgentAction.Action, this.Name, this.Path, 14));
            }
            this.ResolveTargets();
            if (!base.HasErrors)
            {
                this.rule = new InterceptorAgentRule(this.Name, this.Description, conditions, interceptorAgentAction, this.Event, this.Source, this.CreatedBy);
            }
        }
Esempio n. 5
0
        internal static bool TryCreateConditions(string filter, out List <InterceptorAgentCondition> conditions, out LocalizedString error)
        {
            error      = LocalizedString.Empty;
            conditions = new List <InterceptorAgentCondition>();
            if (filter.Trim().Contains(" -or "))
            {
                error = Strings.InterceptorErrorConditionConjunctionNotSupported("or");
                return(false);
            }
            bool   flag   = false;
            string header = null;
            InterceptorAgentConditionMatchType headerMatchType = InterceptorAgentConditionMatchType.CaseInsensitive;

            string[] array = filter.Trim().Split(new string[]
            {
                " -and "
            }, StringSplitOptions.RemoveEmptyEntries);
            string[] array2 = array;
            int      i      = 0;

            while (i < array2.Length)
            {
                string text = array2[i];
                string text2;
                string text3;
                string operand;
                bool   result;
                InterceptorAgentConditionType interceptorAgentConditionType;
                if (!InterceptorHelper.TryMatchCondition(text, out text2, out text3, out operand))
                {
                    error  = Strings.InterceptorErrorConditionInvalidFormat(text);
                    result = false;
                }
                else if (!EnumValidator <InterceptorAgentConditionType> .TryParse(text2, EnumParseOptions.IgnoreCase, out interceptorAgentConditionType) || interceptorAgentConditionType == InterceptorAgentConditionType.Invalid)
                {
                    error  = Strings.InterceptorErrorConditionInvalidProperty(text2);
                    result = false;
                }
                else if (!InterceptorHelper.CheckHeaderValue(flag, interceptorAgentConditionType, out error))
                {
                    result = false;
                }
                else
                {
                    InterceptorAgentConditionMatchType interceptorAgentConditionMatchType = InterceptorHelper.ParseMatchType(operand);
                    string error2;
                    if (!InterceptorAgentCondition.ValidateCondition(interceptorAgentConditionType, interceptorAgentConditionMatchType, out error2))
                    {
                        error  = Strings.InterceptorErrorInvalidConditionMatchTypePair(text, error2);
                        result = false;
                    }
                    else
                    {
                        if (InterceptorAgentCondition.ValidateConditionTypeValue(interceptorAgentConditionType, text3, out error2))
                        {
                            if (interceptorAgentConditionType == InterceptorAgentConditionType.HeaderName)
                            {
                                flag            = true;
                                header          = text3;
                                headerMatchType = interceptorAgentConditionMatchType;
                            }
                            else if (interceptorAgentConditionType == InterceptorAgentConditionType.HeaderValue)
                            {
                                try
                                {
                                    conditions.Add(new InterceptorAgentCondition(header, headerMatchType, text3, interceptorAgentConditionMatchType));
                                }
                                catch (ArgumentException error3)
                                {
                                    error = Strings.InterceptorErrorConditionInvalidRegex(text3, error3);
                                    return(false);
                                }
                                flag   = false;
                                header = null;
                            }
                            else
                            {
                                if (interceptorAgentConditionType == InterceptorAgentConditionType.ProcessRole)
                                {
                                    ProcessTransportRole[] processRoles;
                                    if (!InterceptorAgentCondition.ValidateProcessRole(interceptorAgentConditionMatchType, text3, out processRoles, out error2))
                                    {
                                        error = Strings.InterceptorErrorInvalidConditionMatchTypePair(text, error2);
                                        return(false);
                                    }
                                    try
                                    {
                                        conditions.Add(new InterceptorAgentCondition(processRoles, text3, interceptorAgentConditionMatchType));
                                        goto IL_259;
                                    }
                                    catch (ArgumentException ex)
                                    {
                                        error = Strings.InterceptorErrorInvalidConditionMatchTypePair(text, ex.Message);
                                        return(false);
                                    }
                                }
                                if (interceptorAgentConditionType == InterceptorAgentConditionType.ServerVersion)
                                {
                                    ServerVersion serverVersion;
                                    if (!InterceptorAgentCondition.ValidateServerVersion(interceptorAgentConditionMatchType, text3, out serverVersion, out error2))
                                    {
                                        error = Strings.InterceptorErrorInvalidConditionMatchTypePair(text, error2);
                                        return(false);
                                    }
                                    try
                                    {
                                        conditions.Add(new InterceptorAgentCondition(serverVersion, text3, interceptorAgentConditionMatchType));
                                        goto IL_259;
                                    }
                                    catch (ArgumentException ex2)
                                    {
                                        error = Strings.InterceptorErrorInvalidConditionMatchTypePair(text, ex2.Message);
                                        return(false);
                                    }
                                }
                                try
                                {
                                    conditions.Add(new InterceptorAgentCondition(interceptorAgentConditionType, text3, interceptorAgentConditionMatchType));
                                }
                                catch (ArgumentException error4)
                                {
                                    error = Strings.InterceptorErrorConditionInvalidRegex(text3, error4);
                                    return(false);
                                }
                            }
IL_259:
                            i++;
                            continue;
                        }
                        error  = Strings.InterceptorErrorInvalidConditionTypeValue(interceptorAgentConditionType.ToString(), text3, error2);
                        result = false;
                    }
                }
                return(result);
            }
            if (flag)
            {
                error = Strings.InterceptorErrorConditionHeaderValueMissing;
                conditions.Clear();
                return(false);
            }
            return(true);
        }
Esempio n. 6
0
        private static bool CreateRejectSmtpResponse(InterceptorAgentRuleBehavior behavior, string customResponseCode, bool responseCodeModified, string customResponseText, bool responseTextModified, out SmtpResponse smtpResponse, out LocalizedString error)
        {
            smtpResponse = SmtpResponse.Empty;
            error        = LocalizedString.Empty;
            bool flag  = (ushort)(behavior & InterceptorAgentRuleBehavior.TransientReject) != 0;
            bool flag2 = (ushort)(behavior & InterceptorAgentRuleBehavior.PermanentReject) != 0;

            if (!flag && !flag2)
            {
                return(true);
            }
            if (responseCodeModified || responseTextModified)
            {
                if (responseCodeModified)
                {
                    if (string.IsNullOrEmpty(customResponseCode) || customResponseCode.Length != 3)
                    {
                        error = Strings.InterceptorErrorCustomResponseCodeInvalid(customResponseCode);
                        return(false);
                    }
                    int num;
                    if (!int.TryParse(customResponseCode, NumberStyles.Integer, CultureInfo.InvariantCulture, out num))
                    {
                        error = Strings.InterceptorErrorCustomResponseCodeInvalid(customResponseCode);
                        return(false);
                    }
                    string text;
                    if (flag)
                    {
                        if (num > 499 || num < 400)
                        {
                            error = Strings.InterceptorErrorCustomResponseCodeMustMatchRejectAction(num, behavior.ToString(), 4);
                            return(false);
                        }
                        text = SmtpResponse.InterceptorTransientlyRejectedMessage.StatusText[0];
                    }
                    else
                    {
                        if (num > 599 || num < 500)
                        {
                            error = Strings.InterceptorErrorCustomResponseCodeMustMatchRejectAction(num, behavior.ToString(), 5);
                            return(false);
                        }
                        text = SmtpResponse.InterceptorPermanentlyRejectedMessage.StatusText[0];
                    }
                    if (responseTextModified)
                    {
                        if (!InterceptorHelper.TryValidateCustomResponseText(customResponseText, out error))
                        {
                            return(false);
                        }
                        text = customResponseText;
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendFormat("{0}.{1}.{2}", customResponseCode[0], customResponseCode[1], customResponseCode[2]);
                    smtpResponse = new SmtpResponse(customResponseCode, stringBuilder.ToString(), new string[]
                    {
                        text
                    });
                }
                else
                {
                    if (!InterceptorHelper.TryValidateCustomResponseText(customResponseText, out error))
                    {
                        return(false);
                    }
                    if (flag)
                    {
                        smtpResponse = new SmtpResponse(SmtpResponse.InterceptorTransientlyRejectedMessage.StatusCode, SmtpResponse.InterceptorTransientlyRejectedMessage.EnhancedStatusCode, new string[]
                        {
                            customResponseText
                        });
                    }
                    else
                    {
                        smtpResponse = new SmtpResponse(SmtpResponse.InterceptorPermanentlyRejectedMessage.StatusCode, SmtpResponse.InterceptorPermanentlyRejectedMessage.EnhancedStatusCode, new string[]
                        {
                            customResponseText
                        });
                    }
                }
                return(true);
            }
            if (flag)
            {
                smtpResponse = SmtpResponse.InterceptorTransientlyRejectedMessage;
                return(true);
            }
            smtpResponse = SmtpResponse.InterceptorPermanentlyRejectedMessage;
            return(true);
        }
Esempio n. 7
0
        protected override void InternalValidate()
        {
            bool flag  = base.Fields.IsModified("Event");
            bool flag2 = base.Fields.IsModified("Action");
            bool flag3 = base.Fields.IsModified("Condition");
            bool flag4 = base.Fields.IsModified("CustomResponseCode");
            bool flag5 = base.Fields.IsModified("CustomResponseText");
            bool flag6 = base.Fields.IsModified("Description");
            bool flag7 = base.Fields.IsModified("TimeInterval");
            bool flag8 = base.Fields.IsModified("Path");

            this.xmlNeedsUpdating = (flag2 || flag || flag3 || flag4 || flag5 || flag7 || flag6 || flag8 || base.Fields.IsModified("Identity"));
            if (base.Fields.IsModified("ExpireTime") && DateTime.UtcNow > this.ExpireTime.ToUniversalTime())
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorExpireTimePassed(this.ExpireTime.ToString("G"))), ErrorCategory.InvalidData, "ExpireTime");
            }
            this.DataObject = (InterceptorRule)this.ResolveDataObject();
            if (this.xmlNeedsUpdating)
            {
                try
                {
                    this.rule = InterceptorAgentRule.CreateRuleFromXml(this.DataObject.Xml);
                    this.rule.SetPropertiesFromAdObjet(this.DataObject);
                }
                catch (FormatException exception)
                {
                    base.WriteError(exception, ErrorCategory.InvalidData, null);
                    TaskLogger.LogExit();
                    return;
                }
                catch (InvalidOperationException exception2)
                {
                    base.WriteError(exception2, ErrorCategory.InvalidData, null);
                    TaskLogger.LogExit();
                    return;
                }
            }
            if (this.rule.RuleVersion > InterceptorAgentRule.Version)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorModifyingNewerVersion(this.rule.RuleVersion.ToString())), ErrorCategory.InvalidOperation, null);
            }
            if (flag2 || flag)
            {
                InterceptorAgentRuleBehavior action = flag2 ? this.Action : this.rule.Action.Action;
                InterceptorAgentEvent        interceptorAgentEvent = flag ? this.Event : this.rule.Events;
                LocalizedString localizedString;
                if (!InterceptorHelper.ValidateEventActionPairs(interceptorAgentEvent, action, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Events = interceptorAgentEvent;
                string customResponseCode;
                if (flag2 && !flag4 && InterceptorHelper.TryGetStatusCodeForModifiedRejectAction(this.Action, this.rule.Action.Action, this.rule.Action.Response.StatusCode, out customResponseCode))
                {
                    this.CustomResponseCode = customResponseCode;
                    flag4 = base.Fields.IsModified("CustomResponseCode");
                }
            }
            if (flag3)
            {
                LocalizedString localizedString;
                List <InterceptorAgentCondition> conditions;
                if (!InterceptorHelper.TryCreateConditions(this.Condition, out conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Condition);
                    return;
                }
                InterceptorAgentEvent evt = flag ? this.Event : this.rule.Events;
                if (!InterceptorHelper.ValidateEventConditionPairs(evt, conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Conditions = conditions;
            }
            if (flag)
            {
                LocalizedString localizedString;
                if (!flag3 && !InterceptorHelper.ValidateEventConditionPairs(this.Event, this.rule.Conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Events = this.Event;
            }
            if (flag6)
            {
                this.rule.Description = this.Description;
            }
            this.SetAction(flag4, flag5, flag2, flag8, flag7);
            this.ResolveTargets();
        }