protected TenantOutboundConnector GetHybridMailflowOutboundConnector()
        {
            Collection <PSObject>   collection = this.InvokeConnectorCmdletWithOrganization("Get-OutboundConnector", "Hybrid Mail Flow Outbound Connector", true);
            TenantOutboundConnector result     = null;

            if (collection != null && collection.Count > 0)
            {
                foreach (PSObject psobject in collection)
                {
                    if (psobject.BaseObject is TenantOutboundConnector)
                    {
                        TenantOutboundConnector tenantOutboundConnector = psobject.BaseObject as TenantOutboundConnector;
                        if (tenantOutboundConnector.ConnectorType == TenantConnectorType.OnPremises)
                        {
                            result = tenantOutboundConnector;
                            break;
                        }
                        this.WriteWarning(Strings.HybridMailflowConnectorNameAndTypeWarning("Hybrid Mail Flow Outbound Connector"));
                    }
                    else
                    {
                        base.WriteError(new ApplicationException(Strings.HybridMailflowUnexpectedType("Get-OutboundConnector")), ErrorCategory.InvalidData, null);
                    }
                }
            }
            return(result);
        }
        public static void ValidateIfAcceptedDomainsCanBeRoutedWithConnectors(TenantOutboundConnector dataObject, IConfigDataProvider dataSession, Task task, bool dataObjectDeleted = false)
        {
            ArgumentValidator.ThrowIfNull("dataObject", dataObject);
            ArgumentValidator.ThrowIfNull("dataSession", dataSession);
            ArgumentValidator.ThrowIfNull("task", task);
            if (!VariantConfiguration.InvariantNoFlightingSnapshot.Transport.EnforceOutboundConnectorAndAcceptedDomainsRestriction.Enabled)
            {
                return;
            }
            if (!dataObjectDeleted && dataObject.Enabled && dataObject.ConnectorType == TenantConnectorType.OnPremises && dataObject.AllAcceptedDomains)
            {
                return;
            }
            List <SmtpDomainWithSubdomains> nonAuthoritativeAcceptedDomains = ManageTenantOutboundConnectors.GetNonAuthoritativeAcceptedDomains(dataSession);

            if (nonAuthoritativeAcceptedDomains == null)
            {
                return;
            }
            List <SmtpDomainWithSubdomains> source;

            if (!ManageTenantOutboundConnectors.ValidateIfConnectorsCanRouteDomains(ManageTenantOutboundConnectors.GetOutboundConnectorsToValidate(dataSession, dataObjectDeleted ? null : dataObject), nonAuthoritativeAcceptedDomains, out source))
            {
                task.WriteWarning(Strings.AcceptedDomainsCannotBeRoutedByOutboundConnector(string.Join(",", from d in source
                                                                                                       select d.Domain)));
            }
        }
 public static void ClearSmartHostsListIfNecessary(TenantOutboundConnector outboundConnector)
 {
     if (outboundConnector.UseMXRecord && outboundConnector.SmartHosts != null && outboundConnector.SmartHosts.Any <SmartHost>())
     {
         outboundConnector.SmartHosts = null;
     }
 }
 public static void ValidateOutboundConnectorDataObject(TenantOutboundConnector tenantOutboundConnector, Task task, IConfigDataProvider dataSession, bool skipIpIsNotReservedValidation)
 {
     ManageTenantOutboundConnectors.ValidateUseMxRecordRestriction(tenantOutboundConnector, task);
     ManageTenantOutboundConnectors.ValidateSmartHostRestrictions(tenantOutboundConnector, task, skipIpIsNotReservedValidation);
     ManageTenantOutboundConnectors.ValidateRouteAllMessagesViaOnPremisesParameter(tenantOutboundConnector, dataSession, task);
     ManageTenantOutboundConnectors.ValidateRecipientDomainsParameter(tenantOutboundConnector, task);
 }
 private static void ValidateRouteAllMessagesViaOnPremisesParameter(TenantOutboundConnector dataObject, IConfigDataProvider dataSession, Task task)
 {
     if (dataObject.RouteAllMessagesViaOnPremises && !NewInboundConnector.FindTenantScopedOnPremiseInboundConnector(dataSession, null))
     {
         task.WriteError(new CMCConnectorRequiresTenantScopedInboundConnectorException(), ErrorCategory.InvalidArgument, null);
     }
 }
 private static void ValidateUseMxRecordRestriction(TenantOutboundConnector tenantOutboundConnector, Task task)
 {
     if (tenantOutboundConnector.ConnectorType == TenantConnectorType.OnPremises && tenantOutboundConnector.UseMXRecord)
     {
         task.WriteError(new OnPremisesConnectorHasRouteUsingMXException(), ErrorCategory.InvalidArgument, null);
     }
 }
        protected static List <SmtpDomainWithSubdomains> GetRecipientDomains(TenantOutboundConnector outboundConnector, bool addWildcard)
        {
            IEnumerable <SmtpDomainWithSubdomains> domains = null;

            if (outboundConnector != null && outboundConnector.RecipientDomains != null)
            {
                domains = outboundConnector.RecipientDomains;
            }
            return(HybridMailflowTaskBase.GetRecipientDomains(domains, addWildcard));
        }
        public static LocalizedException ValidateConnectorNameReferences(TenantOutboundConnector tenantOutboundConnector, string previousName, IConfigDataProvider dataSession)
        {
            IEnumerable <TransportRule> source;

            if ((tenantOutboundConnector.IsChanged(TenantOutboundConnectorSchema.Enabled) || tenantOutboundConnector.IsChanged(TenantOutboundConnectorSchema.IsTransportRuleScoped) || tenantOutboundConnector.IsChanged(ADObjectSchema.Name)) && (!tenantOutboundConnector.Enabled || !tenantOutboundConnector.IsTransportRuleScoped || !string.Equals(previousName, tenantOutboundConnector.Name, StringComparison.OrdinalIgnoreCase)) && Utils.TryGetTransportRules(dataSession, new Utils.TransportRuleSelectionDelegate(Utils.RuleHasOutboundConnectorReference), out source, previousName) && source.Any <TransportRule>())
            {
                return(new ConnectorIncorrectUsageConnectorStillReferencedException());
            }
            return(null);
        }
Beispiel #9
0
        public IOutboundConnector NewOutboundConnector(IOutboundConnector configuration)
        {
            SessionParameters       parameters = this.BuildParameters(configuration);
            TenantOutboundConnector tenantOutboundConnector = base.RemotePowershellSession.RunOneCommandSingleResult <TenantOutboundConnector>("New-OutboundConnector", parameters, false);

            if (tenantOutboundConnector != null)
            {
                return(new OutboundConnector(tenantOutboundConnector));
            }
            return(null);
        }
Beispiel #10
0
        public IOutboundConnector GetOutboundConnector(string identity)
        {
            SessionParameters sessionParameters = new SessionParameters();

            sessionParameters.Set("Identity", identity);
            TenantOutboundConnector tenantOutboundConnector = base.RemotePowershellSession.RunOneCommandSingleResult <TenantOutboundConnector>("Get-OutboundConnector", sessionParameters, true);

            if (tenantOutboundConnector != null)
            {
                return(new OutboundConnector(tenantOutboundConnector));
            }
            return(null);
        }
Beispiel #11
0
 public OutboundConnector(TenantOutboundConnector oc)
 {
     this.Identity                      = (ADObjectId)oc.Identity;
     this.Name                          = oc.Name;
     this.TlsDomain                     = TaskCommon.ToStringOrNull(oc.TlsDomain);
     this.ConnectorType                 = oc.ConnectorType;
     this.ConnectorSource               = oc.ConnectorSource;
     this.RecipientDomains              = oc.RecipientDomains;
     this.SmartHosts                    = oc.SmartHosts;
     this.TlsSettings                   = oc.TlsSettings;
     this.CloudServicesMailEnabled      = oc.CloudServicesMailEnabled;
     this.RouteAllMessagesViaOnPremises = oc.RouteAllMessagesViaOnPremises;
 }
 private static void ValidateRecipientDomainsParameter(TenantOutboundConnector dataObject, Task task)
 {
     if (dataObject.ConnectorType == TenantConnectorType.OnPremises && !dataObject.RouteAllMessagesViaOnPremises && dataObject.RecipientDomains != null && dataObject.RecipientDomains.Count > 0)
     {
         foreach (SmtpDomainWithSubdomains smtpDomainWithSubdomains in dataObject.RecipientDomains)
         {
             if (smtpDomainWithSubdomains.IsStar)
             {
                 task.WriteError(new RecipientDomainStarOnPremiseOutboundConnectorException(), ErrorCategory.InvalidArgument, null);
             }
         }
     }
 }
 private static void ValidateSmartHostRestrictions(TenantOutboundConnector tenantOutboundConnector, Task task, bool skipIpIsNotReservedValidation)
 {
     if (tenantOutboundConnector.IsChanged(TenantOutboundConnectorSchema.SmartHosts) && !MultiValuedPropertyBase.IsNullOrEmpty(tenantOutboundConnector.SmartHosts))
     {
         MultiValuedProperty <IPRange> multiValuedProperty = null;
         bool flag = false;
         using (MultiValuedProperty <SmartHost> .Enumerator enumerator = tenantOutboundConnector.SmartHosts.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 SmartHost smartHost = enumerator.Current;
                 if (smartHost.IsIPAddress)
                 {
                     if (smartHost.Address.AddressFamily != AddressFamily.InterNetwork || !IPAddressValidation.IsValidIPv4Address(smartHost.Address.ToString()))
                     {
                         task.WriteError(new SmartHostsIPValidationFailedException(smartHost.Address.ToString()), ErrorCategory.InvalidArgument, null);
                     }
                     if (!skipIpIsNotReservedValidation)
                     {
                         if (IPAddressValidation.IsReservedIPv4Address(smartHost.Address.ToString()))
                         {
                             task.WriteError(new IPRangeInConnectorContainsReservedIPAddressesException(smartHost.Address.ToString()), ErrorCategory.InvalidArgument, null);
                         }
                         if (!flag)
                         {
                             if (!HygieneDCSettings.GetFfoDCPublicIPAddresses(out multiValuedProperty))
                             {
                                 task.WriteError(new ConnectorValidationFailedException(), ErrorCategory.ConnectionError, null);
                             }
                             flag = true;
                         }
                         if (!MultiValuedPropertyBase.IsNullOrEmpty(multiValuedProperty))
                         {
                             if (multiValuedProperty.Any((IPRange ffoDCIP) => ffoDCIP.Contains(smartHost.Address)))
                             {
                                 task.WriteError(new IPRangeInConnectorContainsReservedIPAddressesException(smartHost.Address.ToString()), ErrorCategory.InvalidArgument, null);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        private void FindOnPremConnector(string target, List <MailFilterListReport> values)
        {
            if (this.Domain.Count == 0)
            {
                return;
            }
            OutboundConnectorIdParameter outboundConnectorIdParameter = OutboundConnectorIdParameter.Parse("*");
            TenantOutboundConnector      tenantOutboundConnector      = null;
            int    num    = -1;
            string domain = this.Domain[0].ToString();

            foreach (TenantOutboundConnector tenantOutboundConnector2 in outboundConnectorIdParameter.GetObjects <TenantOutboundConnector>(null, base.ConfigSession))
            {
                if (tenantOutboundConnector2.Enabled && tenantOutboundConnector2.ConnectorType == TenantConnectorType.OnPremises)
                {
                    if (tenantOutboundConnector2.RecipientDomains.Any((SmtpDomainWithSubdomains smtpDomain) => smtpDomain.Domain.Equals(domain, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        tenantOutboundConnector = tenantOutboundConnector2;
                        break;
                    }
                    foreach (SmtpDomainWithSubdomains smtpDomainWithSubdomains in tenantOutboundConnector2.RecipientDomains)
                    {
                        WildcardPattern wildcardPattern = new WildcardPattern(smtpDomainWithSubdomains.Address);
                        int             num2            = wildcardPattern.Match(domain);
                        if (num2 > num)
                        {
                            num = num2;
                            tenantOutboundConnector = tenantOutboundConnector2;
                        }
                    }
                }
            }
            if (tenantOutboundConnector != null)
            {
                values.Add(new MailFilterListReport
                {
                    Organization    = base.Organization.ToString(),
                    SelectionTarget = target,
                    Display         = "Name",
                    Value           = tenantOutboundConnector.Name
                });
            }
        }
        protected static HybridMailflowConfiguration ConvertToHybridMailflowConfiguration(TenantInboundConnector inbound, TenantOutboundConnector outbound)
        {
            ArgumentValidator.ThrowIfNull("inbound", inbound);
            ArgumentValidator.ThrowIfNull("outbound", outbound);
            HybridMailflowConfiguration hybridMailflowConfiguration = new HybridMailflowConfiguration();

            hybridMailflowConfiguration.OutboundDomains = new List <SmtpDomainWithSubdomains>();
            foreach (SmtpDomainWithSubdomains smtpDomainWithSubdomains in outbound.RecipientDomains)
            {
                if (!HybridMailflowTaskBase.IsWildcardDomain(smtpDomainWithSubdomains))
                {
                    hybridMailflowConfiguration.OutboundDomains.Add(new SmtpDomainWithSubdomains(smtpDomainWithSubdomains.Address));
                }
            }
            if (inbound.SenderIPAddresses != null)
            {
                hybridMailflowConfiguration.InboundIPs = new List <IPRange>();
                foreach (IPRange item in inbound.SenderIPAddresses)
                {
                    hybridMailflowConfiguration.InboundIPs.Add(item);
                }
            }
            if (!MultiValuedPropertyBase.IsNullOrEmpty(outbound.SmartHosts))
            {
                SmartHost smartHost = outbound.SmartHosts[0];
                if (smartHost.IsIPAddress)
                {
                    hybridMailflowConfiguration.OnPremisesFQDN = new Fqdn(smartHost.Address.ToString());
                }
                else
                {
                    hybridMailflowConfiguration.OnPremisesFQDN = new Fqdn(smartHost.ToString());
                }
            }
            if (inbound.TlsSenderCertificateName != null)
            {
                hybridMailflowConfiguration.CertificateSubject = inbound.TlsSenderCertificateName.ToString();
            }
            hybridMailflowConfiguration.SecureMailEnabled           = new bool?(inbound.RequireTls && outbound.TlsSettings != null && outbound.TlsSettings == TlsAuthLevel.DomainValidation);
            hybridMailflowConfiguration.CentralizedTransportEnabled = new bool?((inbound.RestrictDomainsToIPAddresses && HybridMailflowTaskBase.IsRecipientDomainsWildcard(outbound.RecipientDomains)) || outbound.RouteAllMessagesViaOnPremises);
            return(hybridMailflowConfiguration);
        }
 private static IEnumerable <TenantOutboundConnector> GetOutboundConnectorsToValidate(IConfigDataProvider dataSession, TenantOutboundConnector connectorBeingModified)
 {
     if (connectorBeingModified != null)
     {
         yield return(connectorBeingModified);
     }
     TenantOutboundConnector[] connectors = (TenantOutboundConnector[])dataSession.Find <TenantOutboundConnector>(null, null, true, null);
     foreach (TenantOutboundConnector connector in connectors)
     {
         if (connectorBeingModified == null || ((ADObjectId)connector.Identity).ObjectGuid != ((ADObjectId)connectorBeingModified.Identity).ObjectGuid)
         {
             yield return(connector);
         }
     }
     yield break;
 }