internal static string GenerateUniqueAliasForSiteMailbox(IRecipientSession recipientSession, OrganizationId organizationId, string preferredAlias, string prefix, bool isMicrosoftHostedOnlyDatacenter, Task.TaskVerboseLoggingDelegate logHandler, Task.ErrorLoggerDelegate writeError)
        {
            string text = WindowsLiveIDLocalPartConstraint.RemoveInvalidPartOfWindowsLiveID(preferredAlias);

            if (!string.IsNullOrEmpty(text) && text.Length > 3)
            {
                logHandler(Strings.VerboseGenerateAliasBySiteDisplayName(preferredAlias));
                text = RecipientTaskHelper.GenerateUniqueAlias(recipientSession, organizationId, (!string.IsNullOrEmpty(prefix)) ? (prefix + text) : text, logHandler, 63);
            }
            else
            {
                int num = 1000;
                if (string.IsNullOrEmpty(prefix))
                {
                    prefix = (isMicrosoftHostedOnlyDatacenter ? "SMO-" : "SM-");
                }
                do
                {
                    text = TeamMailboxHelper.GenerateRandomString();
                    text = prefix + text;
                    logHandler(Strings.VerboseGenerateAliasByRandomString(preferredAlias, text));
                    if (RecipientTaskHelper.IsAliasUnique(recipientSession, organizationId, null, text, logHandler, writeError, ExchangeErrorCategory.Client))
                    {
                        break;
                    }
                    text = string.Empty;
                }while (num-- > 0);
            }
            if (string.IsNullOrEmpty(text))
            {
                writeError(new ErrorCannotGenerateSiteMailboxAliasException(), ExchangeErrorCategory.Client, null);
            }
            return(text);
        }
Esempio n. 2
0
 protected override void PrepareRecipientAlias(ADGroup dataObject)
 {
     if (!string.IsNullOrEmpty(base.Alias))
     {
         dataObject.Alias = base.Alias;
         return;
     }
     dataObject.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, dataObject.OrganizationId, dataObject.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
 }
 protected virtual void PrepareRecipientAlias(TDataObject dataObject)
 {
     if (string.IsNullOrEmpty(this.Alias))
     {
         dataObject.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, dataObject.OrganizationId, dataObject.Name, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
         return;
     }
     dataObject.Alias = this.Alias;
 }
Esempio n. 4
0
 protected override void PrepareRecipientAlias(ADUser dataObject)
 {
     if (!string.IsNullOrEmpty(base.Alias))
     {
         dataObject.Alias = base.Alias;
         return;
     }
     if (string.IsNullOrEmpty(dataObject.Alias))
     {
         dataObject.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, dataObject.OrganizationId, string.IsNullOrEmpty(dataObject.UserPrincipalName) ? dataObject.SamAccountName : RecipientTaskHelper.GetLocalPartOfUserPrincalName(dataObject.UserPrincipalName), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
     }
 }
Esempio n. 5
0
        protected override void PrepareRecipientObject(ADUser user)
        {
            TaskLogger.LogEnter();
            string userPrincipalName = user.UserPrincipalName;

            base.PrepareRecipientObject(user);
            bool flag = base.Fields.Contains("SoftDeletedObject");

            if (flag && userPrincipalName != user.UserPrincipalName)
            {
                user.UserPrincipalName = userPrincipalName;
            }
            using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "NewUserBase.PrepareUserObject", LoggerHelper.CmdletPerfMonitors))
            {
                this.PrepareUserObject(user);
            }
            if (!string.IsNullOrEmpty(this.ImmutableId))
            {
                this.DataObject.ImmutableId = this.ImmutableId;
            }
            if (base.IsDebugOn)
            {
                base.WriteDebug(Strings.DebugStartUpnUniquenessCheck);
            }
            using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.IsUserPrincipalNameUnique", LoggerHelper.CmdletPerfMonitors))
            {
                RecipientTaskHelper.IsUserPrincipalNameUnique(base.TenantGlobalCatalogSession, user, user.UserPrincipalName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.ServerOperation, !flag);
            }
            if (base.IsDebugOn)
            {
                base.WriteDebug(Strings.DebugEndUpnUniquenessCheck);
            }
            if (!string.IsNullOrEmpty(user.SamAccountName))
            {
                using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.IsSamAccountNameUnique", LoggerHelper.CmdletPerfMonitors))
                {
                    RecipientTaskHelper.IsSamAccountNameUnique(base.TenantGlobalCatalogSession, user, user.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.Client, !flag);
                    goto IL_2C1;
                }
            }
            bool useRandomSuffix = this.WindowsLiveID != null && this.WindowsLiveID.SmtpAddress != SmtpAddress.Empty;

            if (base.IsDebugOn)
            {
                base.WriteDebug(Strings.DebugStartGeneratingUniqueSamAccountName);
            }
            using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.PrepareRecipientObject/VariantConfiguration", LoggerHelper.CmdletPerfMonitors))
            {
                IRecipientSession[] recipientSessions = new IRecipientSession[]
                {
                    base.RootOrgGlobalCatalogSession
                };
                if (VariantConfiguration.InvariantNoFlightingSnapshot.CmdletInfra.ServiceAccountForest.Enabled && base.CurrentOrganizationId != OrganizationId.ForestWideOrgId)
                {
                    recipientSessions = new IRecipientSession[]
                    {
                        base.RootOrgGlobalCatalogSession,
                        base.PartitionOrRootOrgGlobalCatalogSession
                    };
                }
                using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.GenerateUniqueSamAccountName", LoggerHelper.CmdletPerfMonitors))
                {
                    user.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(recipientSessions, user.Id.DomainId, RecipientTaskHelper.GetLocalPartOfUserPrincalName(user.UserPrincipalName), false, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), useRandomSuffix);
                }
            }
            if (base.IsDebugOn)
            {
                base.WriteDebug(Strings.DebugEndGeneratingUniqueSamAccountName);
            }
IL_2C1:
            if (string.IsNullOrEmpty(user.Alias))
            {
                using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.GenerateUniqueAlias", LoggerHelper.CmdletPerfMonitors))
                {
                    user.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, user.OrganizationId, string.IsNullOrEmpty(user.UserPrincipalName) ? user.SamAccountName : RecipientTaskHelper.GetLocalPartOfUserPrincalName(user.UserPrincipalName), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                }
            }
            if (base.Fields.IsModified("SKUCapability"))
            {
                user.SKUCapability = new Capability?(this.SKUCapability);
            }
            if (base.Fields.IsModified("AddOnSKUCapability"))
            {
                CapabilityHelper.SetAddOnSKUCapabilities(this.AddOnSKUCapability, user.PersistedCapabilities);
                RecipientTaskHelper.UpgradeArchiveQuotaOnArchiveAddOnSKU(user, user.PersistedCapabilities);
            }
            if (base.Fields.IsModified(ADRecipientSchema.SKUAssigned))
            {
                user.SKUAssigned = new bool?(this.SKUAssigned);
            }
            TaskLogger.LogExit();
        }
Esempio n. 6
0
        protected override void PrepareRecipientObject(ADPublicFolder publicFolder)
        {
            this.DataObject = publicFolder;
            if (MapiTaskHelper.IsDatacenter)
            {
                publicFolder.OrganizationId = base.CurrentOrganizationId;
            }
            publicFolder.StampPersistableDefaultValues();
            if (this.Name.Contains("\n"))
            {
                this.Name = this.Name.Replace("\n", "_");
            }
            if (this.Name.Length > 64)
            {
                publicFolder.Name = this.Name.Substring(0, 64);
            }
            else
            {
                publicFolder.Name = this.Name;
            }
            publicFolder.DisplayName = publicFolder.Name;
            publicFolder.Alias       = RecipientTaskHelper.GenerateUniqueAlias(this.RecipientSession, OrganizationId.ForestWideOrgId, this.Alias, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
            if (this.WindowsEmailAddress != SmtpAddress.Empty)
            {
                publicFolder.WindowsEmailAddress = this.WindowsEmailAddress;
            }
            else
            {
                publicFolder.WindowsEmailAddress = publicFolder.PrimarySmtpAddress;
            }
            publicFolder.HiddenFromAddressListsEnabled = this.HiddenFromAddressListsEnabled;
            publicFolder.SendModerationNotifications   = TransportModerationNotificationFlags.Never;
            publicFolder.RecipientTypeDetails          = RecipientTypeDetails.PublicFolder;
            publicFolder.ObjectCategory   = this.ConfigurationSession.SchemaNamingContext.GetChildId(publicFolder.ObjectCategoryCN);
            publicFolder.LegacyExchangeDN = PublicFolderSession.ConvertToLegacyDN("e71f13d1-0178-42a7-8c47-24206de84a77", this.EntryId);
            ADObjectId adobjectId;

            if (base.CurrentOrganizationId == OrganizationId.ForestWideOrgId)
            {
                adobjectId = base.CurrentOrgContainerId.DomainId.GetChildId("Microsoft Exchange System Objects");
            }
            else
            {
                adobjectId = base.CurrentOrganizationId.OrganizationalUnit;
            }
            ADObjectId  childId     = adobjectId.GetChildId(publicFolder.Name);
            ADRecipient adrecipient = this.RecipientSession.Read(childId);

            if (adrecipient != null)
            {
                Random random = new Random();
                childId = adobjectId.GetChildId(string.Format("{0} {1}", publicFolder.Name, random.Next(100000000).ToString("00000000")));
            }
            publicFolder.SetId(childId);
            if (base.IsProvisioningLayerAvailable)
            {
                base.WriteVerbose(Strings.VerboseInvokingRUS(publicFolder.Identity.ToString(), publicFolder.GetType().Name));
                ADPublicFolder adpublicFolder = new ADPublicFolder();
                adpublicFolder.CopyChangesFrom(publicFolder);
                ProvisioningLayer.UpdateAffectedIConfigurable(this, RecipientTaskHelper.ConvertRecipientToPresentationObject(adpublicFolder), false);
                publicFolder.CopyChangesFrom(adpublicFolder);
            }
            else
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorNoProvisioningHandlerAvailable), ErrorCategory.InvalidOperation, null);
            }
            if (this.ExternalEmailAddress != SmtpAddress.Empty)
            {
                publicFolder.ExternalEmailAddress = ProxyAddress.Parse(this.ExternalEmailAddress.ToString());
            }
            else
            {
                publicFolder.ExternalEmailAddress = ProxyAddress.Parse(publicFolder.WindowsEmailAddress.ToString());
            }
            MailUserTaskHelper.ValidateExternalEmailAddress(publicFolder, this.ConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError), base.ProvisioningCache);
            if (this.EmailAddresses != null)
            {
                foreach (ProxyAddress proxyAddress in this.EmailAddresses)
                {
                    if (proxyAddress != null && !publicFolder.EmailAddresses.Contains(proxyAddress))
                    {
                        publicFolder.EmailAddresses.Add(proxyAddress);
                    }
                }
            }
            adrecipient = this.RecipientSession.FindByProxyAddress(ProxyAddress.Parse("X500:" + publicFolder.LegacyExchangeDN));
            if (adrecipient != null)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorObjectAlreadyExists("ADPublicFolder object : ", this.Name)), ErrorCategory.InvalidData, null);
            }
            publicFolder.EmailAddresses.Add(ProxyAddress.Parse("X500:" + publicFolder.LegacyExchangeDN));
            RecipientTaskHelper.ValidateEmailAddressErrorOut(this.RecipientSession, publicFolder.EmailAddresses, publicFolder, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerReThrowDelegate(this.WriteError));
        }
Esempio n. 7
0
        protected sealed override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            TDataObject tdataObject = (TDataObject)((object)base.PrepareDataObject());

            if (string.IsNullOrEmpty(tdataObject.Alias))
            {
                using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.GenerateUniqueAlias", LoggerHelper.CmdletPerfMonitors))
                {
                    tdataObject.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, base.CurrentOrganizationId, base.Name, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                }
            }
            if (!this.GetEmailAddressPolicyEnabledDefaultValue(tdataObject))
            {
                tdataObject.EmailAddressPolicyEnabled = false;
            }
            if (string.IsNullOrEmpty(tdataObject.DisplayName))
            {
                tdataObject.DisplayName = tdataObject.Name;
            }
            if (base.IsProvisioningLayerAvailable)
            {
                ProvisioningLayer.UpdateAffectedIConfigurable(this, this.ConvertDataObjectToPresentationObject(tdataObject), false);
            }
            else
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorNoProvisioningHandlerAvailable), (ErrorCategory)1001, null);
            }
            if (tdataObject.EmailAddresses.Count > 0)
            {
                using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "NewRecipientObjectTask<TDataObject>.VerifyProxyAddress", LoggerHelper.CmdletPerfMonitors))
                {
                    ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, tdataObject.OrganizationId, base.ExecutingUserOrganizationId, false);
                    IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(base.DomainController, true, ConsistencyMode.PartiallyConsistent, string.IsNullOrEmpty(base.DomainController) ? null : base.NetCredential, sessionSettings, 867, "PrepareDataObject", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\BaseTasks\\NewAdObjectTask.cs");
                    bool flag = base.Fields["SoftDeletedObject"] != null;
                    if (flag)
                    {
                        RecipientTaskHelper.StripInvalidSMTPAddress(this.ConfigurationSession, tdataObject, base.ProvisioningCache, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerReThrowDelegate(this.WriteError));
                        RecipientTaskHelper.StripConflictEmailAddress(tenantOrRootOrgRecipientSession, tdataObject, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerReThrowDelegate(this.WriteError));
                    }
                    else
                    {
                        if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && this.ShouldCheckAcceptedDomains())
                        {
                            RecipientTaskHelper.ValidateSmtpAddress(this.ConfigurationSession, tdataObject.EmailAddresses, tdataObject, new Task.ErrorLoggerDelegate(base.WriteError), base.ProvisioningCache);
                        }
                        RecipientTaskHelper.ValidateEmailAddressErrorOut(tenantOrRootOrgRecipientSession, tdataObject.EmailAddresses, tdataObject, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerReThrowDelegate(this.WriteError));
                    }
                }
            }
            if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled)
            {
                ADRecipient adrecipient = tdataObject;
                if ((RecipientTaskHelper.GetAcceptedRecipientTypes() & adrecipient.RecipientTypeDetails) != RecipientTypeDetails.None && string.IsNullOrEmpty(adrecipient.ExternalDirectoryObjectId))
                {
                    adrecipient.ExternalDirectoryObjectId = Guid.NewGuid().ToString("D");
                }
            }
            TaskLogger.LogExit();
            return(tdataObject);
        }
        protected override void PrepareRecipientObject(ADGroup group)
        {
            TaskLogger.LogEnter();
            base.PrepareRecipientObject(group);
            Organization organization;

            if (base.Organization == null)
            {
                organization = this.ConfigurationSession.GetOrgContainer();
            }
            else
            {
                organization = this.ConfigurationSession.Read <ExchangeConfigurationUnit>(base.CurrentOrgContainerId);
            }
            ADObjectId adobjectId = null;

            base.TryGetExecutingUserId(out adobjectId);
            if (!this.IgnoreNamingPolicy.IsPresent && adobjectId != null)
            {
                ADUser user = (ADUser)RecipientTaskHelper.CreatePartitionOrRootOrgScopedGcSession(null, adobjectId).Read(adobjectId);
                string groupNameWithNamingPolicy = DistributionGroupTaskHelper.GetGroupNameWithNamingPolicy(organization, user, group, base.Name, ADObjectSchema.Name, new Task.ErrorLoggerDelegate(base.WriteError));
                if (groupNameWithNamingPolicy.Length > 64)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorDistributionGroupNameTooLong), ExchangeErrorCategory.Client, null);
                }
                base.Name = groupNameWithNamingPolicy;
                if (!string.IsNullOrEmpty(base.DisplayName))
                {
                    base.DisplayName = DistributionGroupTaskHelper.GetGroupNameWithNamingPolicy(organization, user, group, base.DisplayName, ADRecipientSchema.DisplayName, new Task.ErrorLoggerDelegate(base.WriteError));
                }
            }
            if (base.OrganizationalUnit == null && !ADObjectId.IsNullOrEmpty(organization.DistributionGroupDefaultOU))
            {
                group.SetId(organization.DistributionGroupDefaultOU.GetChildId(base.Name));
            }
            if (base.OrganizationalUnit == null && group[ADRecipientSchema.DefaultDistributionListOU] != null)
            {
                ADObjectId adobjectId2 = (ADObjectId)group[ADRecipientSchema.DefaultDistributionListOU];
                RecipientTaskHelper.ResolveOrganizationalUnitInOrganization(new OrganizationalUnitIdParameter(adobjectId2), this.ConfigurationSession, base.CurrentOrganizationId, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ExchangeOrganizationalUnit>), ExchangeErrorCategory.Client, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
                group.SetId(adobjectId2.GetChildId(base.Name));
            }
            if (this.Type != GroupType.Distribution && this.Type != GroupType.Security)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorGroupTypeInvalid), ExchangeErrorCategory.Client, null);
            }
            if (base.Fields.IsModified(DistributionGroupSchema.ManagedBy))
            {
                MailboxTaskHelper.StampOnManagedBy(this.DataObject, this.managedByRecipients, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            if (this.RoomList.IsPresent)
            {
                if (this.Type != GroupType.Distribution)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorCreateRoomListSecurityGroup(base.Name)), ExchangeErrorCategory.Client, base.Name);
                }
                group.RecipientTypeDetails = RecipientTypeDetails.RoomList;
                if (group.ManagedBy != null)
                {
                    group.AcceptMessagesOnlyFromSendersOrMembers = new MultiValuedProperty <ADObjectId>(group.ManagedBy);
                }
            }
            MailboxTaskHelper.ValidateGroupManagedBy(base.TenantGlobalCatalogSession, group, this.managedByRecipients, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>), new Task.ErrorLoggerDelegate(base.WriteError));
            MailboxTaskHelper.ValidateGroupManagedByRecipientRestriction(base.TenantGlobalCatalogSession, group, this.managedByRecipients, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>), new Task.ErrorLoggerDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning));
            group.GroupType = (GroupTypeFlags)((GroupType)8 | this.Type);
            if (!group.IsChanged(ADRecipientSchema.RecipientDisplayType))
            {
                if ((group.GroupType & GroupTypeFlags.SecurityEnabled) == GroupTypeFlags.SecurityEnabled)
                {
                    group.RecipientDisplayType = new RecipientDisplayType?(RecipientDisplayType.SecurityDistributionGroup);
                }
                else
                {
                    group.RecipientDisplayType = new RecipientDisplayType?(RecipientDisplayType.DistributionGroup);
                }
            }
            if (string.IsNullOrEmpty(group.SamAccountName))
            {
                IRecipientSession[] recipientSessions = new IRecipientSession[]
                {
                    base.RootOrgGlobalCatalogSession
                };
                if (VariantConfiguration.InvariantNoFlightingSnapshot.CmdletInfra.ServiceAccountForest.Enabled && base.CurrentOrganizationId != OrganizationId.ForestWideOrgId)
                {
                    recipientSessions = new IRecipientSession[]
                    {
                        base.RootOrgGlobalCatalogSession,
                        base.PartitionOrRootOrgGlobalCatalogSession
                    };
                }
                group.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(recipientSessions, group.Id.DomainId, group.Name, true, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), false);
            }
            else
            {
                RecipientTaskHelper.IsSamAccountNameUnique(group, group.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.Client);
            }
            if (string.IsNullOrEmpty(group.Alias))
            {
                group.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, base.CurrentOrganizationId, group.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
            }
            if (base.Fields.IsChanged(ADGroupSchema.Members) && this.Members != null)
            {
                foreach (RecipientIdParameter member in this.Members)
                {
                    MailboxTaskHelper.ValidateAndAddMember(base.TenantGlobalCatalogSession, group, member, false, new Task.ErrorLoggerDelegate(base.WriteError), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>));
                }
            }
            if (this.CopyOwnerToMember.IsPresent && this.managedByRecipients != null)
            {
                foreach (ADRecipient adrecipient in this.managedByRecipients)
                {
                    if (!group.Members.Contains(adrecipient.Id))
                    {
                        MailboxTaskHelper.ValidateMemberInGroup(adrecipient, group, new Task.ErrorLoggerDelegate(base.WriteError));
                        group.Members.Add(adrecipient.Id);
                    }
                }
            }
            if ((group.GroupType & GroupTypeFlags.Universal) == GroupTypeFlags.Universal)
            {
                MailboxTaskHelper.ValidateAddedMembers(base.TenantGlobalCatalogSession, group, new Task.ErrorLoggerDelegate(base.WriteError), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>));
            }
            if (!this.DataObject.IsModified(ADGroupSchema.MemberDepartRestriction))
            {
                this.DataObject.MemberDepartRestriction = ((this.Type == GroupType.Security) ? MemberUpdateType.Closed : MemberUpdateType.Open);
            }
            if (group.ArbitrationMailbox == null)
            {
                group.ArbitrationMailbox = MailboxTaskHelper.GetArbitrationMailbox(base.TenantGlobalCatalogSession, base.CurrentOrgContainerId);
                if (group.ArbitrationMailbox == null)
                {
                    if (group.MemberJoinRestriction == MemberUpdateType.ApprovalRequired || group.MemberDepartRestriction == MemberUpdateType.ApprovalRequired)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMbxNotSetForApproval(base.Name)), ExchangeErrorCategory.Client, group.Identity);
                    }
                    if (group.ModerationEnabled)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMbxNotSetForModeration(base.Name)), ExchangeErrorCategory.Client, group.Identity);
                    }
                }
            }
            DistributionGroupTaskHelper.CheckMembershipRestriction(group, new Task.ErrorLoggerDelegate(base.WriteError));
            TaskLogger.LogExit();
        }
        private ADPublicFolder CreatePublicFolderProxy()
        {
            ADPublicFolder adpublicFolder = new ADPublicFolder();

            if (MapiTaskHelper.IsDatacenter)
            {
                adpublicFolder.OrganizationId = base.CurrentOrganizationId;
            }
            adpublicFolder.StampPersistableDefaultValues();
            string text = this.currentPublicFolder.Name.Trim();

            if (text.Length > 256)
            {
                adpublicFolder.DisplayName = text.Substring(0, 256);
            }
            else
            {
                adpublicFolder.DisplayName = text.Trim();
            }
            if (text.Length > 64)
            {
                adpublicFolder.Name = text.Substring(0, 64);
            }
            else
            {
                adpublicFolder.Name = text;
            }
            adpublicFolder.Alias = RecipientTaskHelper.GenerateUniqueAlias(this.RecipientSession, OrganizationId.ForestWideOrgId, adpublicFolder.Name, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
            adpublicFolder.WindowsEmailAddress         = adpublicFolder.PrimarySmtpAddress;
            adpublicFolder.SendModerationNotifications = TransportModerationNotificationFlags.Never;
            adpublicFolder.RecipientTypeDetails        = RecipientTypeDetails.PublicFolder;
            adpublicFolder.ObjectCategory = this.ConfigurationSession.SchemaNamingContext.GetChildId(adpublicFolder.ObjectCategoryCN);
            ADRecipient adrecipient = this.RecipientSession.FindByExchangeGuid(this.currentPublicFolder.ContentMailboxGuid);

            if (adrecipient == null || adrecipient.RecipientTypeDetails != RecipientTypeDetails.PublicFolderMailbox)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorUnableToDetermineContentMailbox(this.Identity.ToString(), this.currentPublicFolder.ContentMailboxGuid)), ErrorCategory.InvalidData, this.Identity);
            }
            adpublicFolder.ContentMailbox   = adrecipient.Id;
            adpublicFolder.EntryId          = this.currentPublicFolder.EntryId;
            adpublicFolder.LegacyExchangeDN = PublicFolderSession.ConvertToLegacyDN(this.currentPublicFolder.ContentMailboxGuid.ToString(), this.currentPublicFolder.EntryId);
            ADObjectId adobjectId;

            if (!MapiTaskHelper.IsDatacenter)
            {
                adobjectId = base.CurrentOrgContainerId.DomainId.GetChildId("Microsoft Exchange System Objects");
            }
            else
            {
                adobjectId = base.CurrentOrganizationId.OrganizationalUnit;
            }
            ADObjectId  childId      = adobjectId.GetChildId(adpublicFolder.Name);
            ADRecipient adrecipient2 = this.RecipientSession.Read(childId);

            if (adrecipient2 != null)
            {
                string text2 = adpublicFolder.Name;
                if (text2.Length > 55)
                {
                    text2 = text2.Substring(0, 55);
                }
                Random random = new Random();
                childId = adobjectId.GetChildId(string.Format("{0} {1}", text2, random.Next(100000000).ToString("00000000")));
            }
            adpublicFolder.SetId(childId);
            if (base.IsProvisioningLayerAvailable)
            {
                base.WriteVerbose(Strings.VerboseInvokingRUS(adpublicFolder.Identity.ToString(), adpublicFolder.GetType().Name));
                ADPublicFolder adpublicFolder2 = new ADPublicFolder();
                adpublicFolder2.CopyChangesFrom(adpublicFolder);
                ProvisioningLayer.UpdateAffectedIConfigurable(this, RecipientTaskHelper.ConvertRecipientToPresentationObject(adpublicFolder2), false);
                adpublicFolder.CopyChangesFrom(adpublicFolder2);
            }
            else
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorNoProvisioningHandlerAvailable), ErrorCategory.InvalidOperation, null);
            }
            return(adpublicFolder);
        }
Esempio n. 10
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            if ("Linked" == base.ParameterSetName)
            {
                try
                {
                    NetworkCredential userForestCredential = (this.LinkedCredential == null) ? null : this.LinkedCredential.GetNetworkCredential();
                    this.linkedUserSid = MailboxTaskHelper.GetAccountSidFromAnotherForest(this.LinkedMasterAccount, this.LinkedDomainController, userForestCredential, this.ResourceForestSession, new MailboxTaskHelper.GetUniqueObject(base.GetDataObject <ADUser>), new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                }
                catch (PSArgumentException exception)
                {
                    base.ThrowTerminatingError(exception, ErrorCategory.InvalidArgument, this.LinkedCredential);
                }
            }
            if (this.ManagedFolderMailboxPolicy != null)
            {
                ManagedFolderMailboxPolicy managedFolderMailboxPolicy = (ManagedFolderMailboxPolicy)base.GetDataObject <ManagedFolderMailboxPolicy>(this.ManagedFolderMailboxPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorManagedFolderMailboxPolicyNotFound(this.ManagedFolderMailboxPolicy.ToString())), new LocalizedString?(Strings.ErrorManagedFolderMailboxPolicyNotUnique(this.ManagedFolderMailboxPolicy.ToString())));
                this.elcPolicyId = (ADObjectId)managedFolderMailboxPolicy.Identity;
            }
            if (this.RetentionPolicy != null)
            {
                if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
                {
                    base.WriteError(new LocalizedException(Strings.ErrorLinkOpOnDehydratedTenant("RetentionPolicy")), ExchangeErrorCategory.Client, null);
                }
                RetentionPolicy retentionPolicy = (RetentionPolicy)base.GetDataObject <RetentionPolicy>(this.RetentionPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorRetentionPolicyNotFound(this.RetentionPolicy.ToString())), new LocalizedString?(Strings.ErrorRetentionPolicyNotUnique(this.RetentionPolicy.ToString())));
                this.retentionPolicyId = retentionPolicy.Id;
            }
            if (this.ActiveSyncMailboxPolicy != null)
            {
                MobileMailboxPolicy mobileMailboxPolicy = (MobileMailboxPolicy)base.GetDataObject <MobileMailboxPolicy>(this.ActiveSyncMailboxPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorMobileMailboxPolicyNotFound(this.ActiveSyncMailboxPolicy.ToString())), new LocalizedString?(Strings.ErrorMobileMailboxPolicyNotUnique(this.ActiveSyncMailboxPolicy.ToString())));
                this.mobilePolicyId = (ADObjectId)mobileMailboxPolicy.Identity;
            }
            if (this.AddressBookPolicy != null)
            {
                AddressBookMailboxPolicy addressBookMailboxPolicy = (AddressBookMailboxPolicy)base.GetDataObject <AddressBookMailboxPolicy>(this.AddressBookPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotFound(this.AddressBookPolicy.ToString())), new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotUnique(this.AddressBookPolicy.ToString())), ExchangeErrorCategory.Client);
                this.addressBookPolicyId = (ADObjectId)addressBookMailboxPolicy.Identity;
            }
            MailboxTaskHelper.ValidateMailboxIsDisconnected(this.GlobalCatalogSession, this.DataObject.MailboxGuid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
            if (!this.Archive)
            {
                ConnectMailbox.CheckLegacyDNNotInUse(this.DataObject.Identity, this.DataObject.LegacyDN, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            if (this.User != null)
            {
                this.userToConnect = (ADUser)base.GetDataObject <ADUser>(this.User, this.RecipientSession, null, new LocalizedString?(Strings.ErrorRecipientNotFound(this.User.ToString())), new LocalizedString?(Strings.ErrorRecipientNotUnique(this.User.ToString())));
                if (this.Archive)
                {
                    ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
                }
                else if (RecipientType.User != this.userToConnect.RecipientType)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorNoMatchedUserTypeFound(RecipientType.User.ToString(), this.User.ToString(), this.userToConnect.RecipientType.ToString())), ErrorCategory.InvalidArgument, this.User);
                }
            }
            else if (!this.Archive)
            {
                if ("ValidateOnly" == base.ParameterSetName)
                {
                    this.matchedUsers = this.FindMatchedUser(this.DataObject, null);
                }
                else
                {
                    this.matchedUsers = this.FindMatchedUser(this.DataObject, new bool?("User" == base.ParameterSetName));
                }
                if ("ValidateOnly" != base.ParameterSetName)
                {
                    if (this.matchedUsers.Length == 0)
                    {
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorNoMatchedUserFound), ErrorCategory.InvalidArgument, this.Identity);
                    }
                    else if (this.matchedUsers.Length > 1)
                    {
                        this.WriteWarning(Strings.ErrorMultipleMatchedUser(this.Identity.ToString()));
                        this.needListMatchingUser = true;
                    }
                    else
                    {
                        this.userToConnect = (ADUser)this.matchedUsers[0];
                        this.userToConnect = (ADUser)this.RecipientSession.Read(this.userToConnect.Id);
                        if (this.userToConnect == null)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorNoMatchedUserFound), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        if (this.Archive)
                        {
                            ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
                        }
                    }
                }
            }
            else
            {
                this.userToConnect = this.FindArchiveUser(this.DataObject, this.RecipientSession, new Task.TaskErrorLoggingDelegate(base.WriteError));
                ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
            }
            if (this.userToConnect != null && !this.Archive)
            {
                if ("User" == base.ParameterSetName)
                {
                    if ((this.userToConnect.UserAccountControl & UserAccountControlFlags.AccountDisabled) != UserAccountControlFlags.None && this.DataObject.MailboxType == StoreMailboxType.Private)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorAccountDisabledForUserMailbox), ErrorCategory.InvalidArgument, this.userToConnect);
                    }
                }
                else if ((this.userToConnect.UserAccountControl & UserAccountControlFlags.AccountDisabled) == UserAccountControlFlags.None)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorAccountEnabledForNonUserMailbox), ErrorCategory.InvalidArgument, this.userToConnect);
                }
                if (!string.IsNullOrEmpty(this.Alias))
                {
                    this.alias = this.Alias;
                }
                else
                {
                    this.alias = RecipientTaskHelper.GenerateUniqueAlias(this.globalCatalogSession, this.userToConnect.OrganizationId, this.userToConnect.Name, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                }
            }
            if (this.Archive && this.userToConnect.ManagedFolderMailboxPolicy != null)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorNoArchiveWithManagedFolder(this.userToConnect.Name)), ErrorCategory.InvalidData, this.Identity);
            }
            if (this.DataObject.IsArchiveMailbox != null && this.Archive != this.DataObject.IsArchiveMailbox.Value)
            {
                if (this.Archive)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorDisconnectedMailboxNotArchive(this.Identity.ToString(), this.userToConnect.Name)), ErrorCategory.InvalidArgument, this.Identity);
                }
                else
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorDisconnectedMailboxNotPrimary(this.Identity.ToString(), this.userToConnect.Name)), ErrorCategory.InvalidArgument, this.Identity);
                }
            }
            ADSessionSettings sessionSettings = ADSessionSettings.FromCustomScopeSet(base.ScopeSet, ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);

            MapiTaskHelper.VerifyDatabaseIsWithinScope(sessionSettings, this.OwnerMailboxDatabase, new Task.ErrorLoggerDelegate(base.WriteError));
            TaskLogger.LogExit();
        }
Esempio n. 11
0
        private static void UpdateRecipients(EmailAddressPolicy eap, OrganizationId organizationId, string domainController, IRecipientSession globalCatalogSession, Task.TaskVerboseLoggingDelegate writeVerbose, Task.TaskWarningLoggingDelegate writeWarning, WriteProgress writeProgress, Task cmdlet, bool fixMissingAlias)
        {
            UpdateEmailAddressPolicy.AssertArgumentNotNull(eap, "eap");
            UpdateEmailAddressPolicy.AssertArgumentNotNull(writeVerbose, "writeVerbose");
            UpdateEmailAddressPolicy.AssertArgumentNotNull(writeWarning, "writeWarning");
            UpdateEmailAddressPolicy.AssertArgumentNotNull(writeProgress, "writeProgress");
            if (string.IsNullOrEmpty(eap.LdapRecipientFilter) && !fixMissingAlias)
            {
                return;
            }
            int num = 0;

            try
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    return;
                }
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.PartiallyConsistent, globalCatalogSession.SessionSettings, 409, "UpdateRecipients", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\RecipientPolicy\\UpdateEmailAddressPolicy.cs");
                tenantOrRootOrgRecipientSession.EnforceDefaultScope = false;
                IEnumerable <ADRecipient> enumerable = eap.FindMatchingRecipientsPaged(globalCatalogSession, organizationId, null, fixMissingAlias);
                string    text      = null;
                Hashtable hashtable = new Hashtable();
                foreach (ADRecipient adrecipient in enumerable)
                {
                    if (cmdlet != null && cmdlet.Stopping)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(domainController) && string.IsNullOrEmpty(text))
                    {
                        try
                        {
                            string configurationDomainControllerFqdn = SystemConfigurationTasksHelper.GetConfigurationDomainControllerFqdn(domainController);
                            int    num2 = configurationDomainControllerFqdn.IndexOf(".");
                            if (0 <= num2)
                            {
                                text = configurationDomainControllerFqdn.Substring(num2);
                            }
                        }
                        catch (SocketException ex)
                        {
                            writeWarning(Strings.ErrorResolveFqdnForDomainController(domainController, ex.Message));
                            return;
                        }
                    }
                    string text2 = adrecipient.Id.DomainId.DistinguishedName.ToLowerInvariant();
                    if (!hashtable.ContainsKey(text2))
                    {
                        SystemConfigurationTasksHelper.PrepareDomainControllerRecipientSessionForUpdate(tenantOrRootOrgRecipientSession, adrecipient.Id, domainController, text);
                        IEnumerable <ADRecipient> collection = eap.FindMatchingRecipientsPaged(tenantOrRootOrgRecipientSession, organizationId, adrecipient.Id, fixMissingAlias);
                        List <ADRecipient>        list       = new List <ADRecipient>();
                        Exception ex2 = null;
                        Exception ex3 = null;
                        try
                        {
                            list.AddRange(collection);
                        }
                        catch (DataSourceOperationException ex4)
                        {
                            TaskLogger.Trace("Exception caught when re-read recipient from DC : {0}", new object[]
                            {
                                ex4.ToString()
                            });
                            if (ex4.InnerException is ActiveDirectoryObjectNotFoundException || ex4.InnerException is AuthenticationException)
                            {
                                ex3 = ex4;
                            }
                            else
                            {
                                ex2 = ex4;
                            }
                        }
                        catch (DataSourceTransientException ex5)
                        {
                            TaskLogger.Trace("Exception caught when re-read recipient from DC : {0}", new object[]
                            {
                                ex5.ToString()
                            });
                            if (ex5.InnerException is ActiveDirectoryOperationException || ex5.InnerException is ActiveDirectoryServerDownException)
                            {
                                ex3 = ex5;
                            }
                            else
                            {
                                ex2 = ex5;
                            }
                        }
                        if (ex3 != null)
                        {
                            hashtable.Add(text2, null);
                            writeWarning(Strings.ErrorCannotUpdateRecipientOfDomain(DNConvertor.FqdnFromDomainDistinguishedName(text2), ex3.Message));
                        }
                        else if (ex2 != null)
                        {
                            writeWarning(Strings.ErrorFailedToReadRecipientForUpdate(adrecipient.Id.ToString(), ex2.Message));
                        }
                        else if (1 == list.Count)
                        {
                            ADRecipient adrecipient2 = list[0];
                            if (cmdlet != null && cmdlet.Stopping)
                            {
                                return;
                            }
                            num = num++ % 99 + 1;
                            writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusUpdateRecipient(adrecipient2.Id.ToString()), num);
                            writeVerbose(Strings.ProgressStatusUpdateRecipient(adrecipient2.Id.ToString()));
                            try
                            {
                                if (fixMissingAlias && string.IsNullOrEmpty(adrecipient2.Alias))
                                {
                                    if (adrecipient2 is ADMicrosoftExchangeRecipient)
                                    {
                                        adrecipient2.Alias = RecipientTaskHelper.GenerateUniqueAlias(globalCatalogSession, adrecipient2.OrganizationId, ADMicrosoftExchangeRecipient.DefaultName, writeVerbose);
                                    }
                                    else if (adrecipient2 is ADSystemAttendantMailbox)
                                    {
                                        adrecipient2.Alias = RecipientTaskHelper.GenerateUniqueAlias(globalCatalogSession, adrecipient2.OrganizationId, (adrecipient2 as ADSystemAttendantMailbox).ServerName + "-SA", writeVerbose);
                                    }
                                    else
                                    {
                                        adrecipient2.Alias = RecipientTaskHelper.GenerateUniqueAlias(globalCatalogSession, adrecipient2.OrganizationId, adrecipient2.Name, writeVerbose);
                                    }
                                    writeWarning(Strings.WarningGeneratingMissingAlias(adrecipient2.Identity.ToString(), adrecipient2.Alias));
                                }
                                if (!adrecipient2.IsReadOnly)
                                {
                                    ProvisioningLayer.UpdateAffectedIConfigurable(cmdlet, RecipientTaskHelper.ConvertRecipientToPresentationObject(adrecipient2), true);
                                }
                                if (!adrecipient2.IsValid || adrecipient2.IsReadOnly)
                                {
                                    writeWarning(Strings.ErrorCannotUpdateInvalidRecipient(adrecipient2.Id.ToString()));
                                }
                                else
                                {
                                    if (cmdlet.IsVerboseOn && adrecipient2.ObjectState != ObjectState.Unchanged)
                                    {
                                        writeVerbose(TaskVerboseStringHelper.GetConfigurableObjectChangedProperties(adrecipient2));
                                    }
                                    tenantOrRootOrgRecipientSession.Save(adrecipient2);
                                }
                            }
                            catch (DataSourceTransientException ex6)
                            {
                                writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex6.Message));
                                TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                                {
                                    adrecipient2.Id.ToString(),
                                    ex6.Message
                                });
                            }
                            catch (DataSourceOperationException ex7)
                            {
                                writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex7.Message));
                                TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                                {
                                    adrecipient2.Id.ToString(),
                                    ex7.Message
                                });
                            }
                            catch (DataValidationException ex8)
                            {
                                writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex8.Message));
                                TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                                {
                                    adrecipient2.Id.ToString(),
                                    ex8.Message
                                });
                            }
                        }
                    }
                }
            }
            finally
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_RecipientsUpdateForEmailAddressPolicyCancelled, new string[]
                    {
                        eap.Identity.ToString(),
                        eap.LdapRecipientFilter,
                        ADRecipientSchema.EmailAddresses.Name
                    });
                }
            }
            if (num != 0)
            {
                writeVerbose(Strings.ProgressStatusFinished);
                writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusFinished, 100);
            }
        }