private void SaveObject(ADConfigurationObject dataObject)
 {
     try
     {
         if (dataObject.Identity != null)
         {
             base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(dataObject, this.configurationSession, dataObject.GetType()));
         }
         using (TaskPerformanceData.SaveResult.StartRequestTimer())
         {
             this.configurationSession.Save(dataObject);
         }
     }
     catch (DataSourceTransientException exception)
     {
         base.WriteError(exception, (ErrorCategory)1002, null);
     }
     finally
     {
         if (dataObject.Identity != null)
         {
             base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.configurationSession));
         }
     }
 }
        private void PostOrganization(ADObjectId resAl)
        {
            IConfigurationSession configurationSession    = (IConfigurationSession)base.DataSession;
            Organization          organization            = (base.Organization != null) ? configurationSession.Read <ExchangeConfigurationUnit>(base.CurrentOrgContainerId) : configurationSession.Read <Organization>(configurationSession.GetOrgContainerId());
            ADObjectId            deletedObjectsContainer = configurationSession.DeletedObjectsContainer;
            List <ADObjectId>     list = new List <ADObjectId>();

            foreach (ADObjectId adobjectId in organization.ResourceAddressLists)
            {
                if (adobjectId.Parent.Equals(deletedObjectsContainer))
                {
                    list.Add(adobjectId);
                }
            }
            foreach (ADObjectId item in list)
            {
                organization.ResourceAddressLists.Remove(item);
            }
            organization.ResourceAddressLists.Add(resAl);
            base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(organization, configurationSession, typeof(Organization)));
            try
            {
                configurationSession.Save(organization);
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(configurationSession));
            }
        }
Beispiel #3
0
 protected void SaveDerivedRoleAndWarnOnValidationErrors(ExchangeRole role)
 {
     if (role.IsRootRole)
     {
         throw new ArgumentNullException("Only derive roles should be");
     }
     try
     {
         int count = role.RoleEntries.Count;
         ValidationError[] array = role.Validate();
         role.AllowEmptyRole = true;
         this.settings.ConfigurationSession.Save(role);
         this.settings.LogWriteObject(role);
         this.settings.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(role, this.settings.ConfigurationSession, typeof(ExchangeRole)));
         if (array != null && array.Length != 0)
         {
             this.settings.WriteWarning(Strings.WarningInvalidRoleAfterUpgrade(role.Identity.ToString(), MultiValuedPropertyBase.FormatMultiValuedProperty(array)));
         }
     }
     catch (DataSourceOperationException ex)
     {
         this.settings.WriteWarning(Strings.WarningCannotUpgradeRole(role.Identity.ToString(), ex.Message));
     }
     catch (DataValidationException ex2)
     {
         this.settings.WriteWarning(Strings.WarningCannotUpgradeRole(role.Identity.ToString(), ex2.Message));
     }
 }
Beispiel #4
0
 private void CreateCannedSystemAddressLists(IConfigurationSession session, AddressBookBase parent, out Dictionary <string, bool> addressListsCreated)
 {
     addressListsCreated = new Dictionary <string, bool>();
     foreach (string text in CannedSystemAddressLists.RecipientFilters.Keys)
     {
         AddressBookBase addressBookBase = session.Read <AddressBookBase>(parent.Id.GetChildId(text));
         bool            flag            = false;
         bool            flag2           = false;
         if (addressBookBase == null)
         {
             flag            = true;
             addressBookBase = new AddressBookBase();
             addressBookBase.SetId(parent.Id.GetChildId(text));
             addressBookBase.DisplayName         = text;
             addressBookBase.OrganizationId      = parent.OrganizationId;
             addressBookBase.IsSystemAddressList = CannedSystemAddressLists.SystemFlags[text];
         }
         if (flag || !string.Equals(LdapFilterBuilder.LdapFilterFromQueryFilter(CannedSystemAddressLists.RecipientFilters[text]), addressBookBase.LdapRecipientFilter, StringComparison.OrdinalIgnoreCase))
         {
             flag2 = true;
             addressBookBase.SetRecipientFilter(CannedSystemAddressLists.RecipientFilters[text]);
             addressBookBase[AddressBookBaseSchema.RecipientFilterFlags] = RecipientFilterableObjectFlags.FilterApplied;
             base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(addressBookBase, session, typeof(AddressBookBase)));
             try
             {
                 session.Save(addressBookBase);
             }
             finally
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(session));
             }
         }
         addressListsCreated.Add(text, flag || flag2);
     }
 }
        protected void PostExchange(ADObjectId alContainer)
        {
            IConfigurationSession configurationSession = base.CreateGlobalWritableConfigSession();
            bool skipRangedAttributes = configurationSession.SkipRangedAttributes;

            configurationSession.SkipRangedAttributes = true;
            try
            {
                ExchangeConfigurationContainerWithAddressLists exchangeConfigurationContainerWithAddressLists = configurationSession.GetExchangeConfigurationContainerWithAddressLists();
                if (exchangeConfigurationContainerWithAddressLists.LinkedAddressBookRootAttributesPresent())
                {
                    exchangeConfigurationContainerWithAddressLists.AddressBookRoots2.Add(alContainer);
                }
                base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeConfigurationContainerWithAddressLists, configurationSession, typeof(ExchangeConfigurationContainer)));
                configurationSession.Save(exchangeConfigurationContainerWithAddressLists);
                exchangeConfigurationContainerWithAddressLists.ResetChangeTracking();
                if (!AddressBookUtilities.IsTenantAddressList(configurationSession, alContainer))
                {
                    exchangeConfigurationContainerWithAddressLists.AddressBookRoots.Add(alContainer);
                    base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeConfigurationContainerWithAddressLists, configurationSession, typeof(ExchangeConfigurationContainer)));
                    configurationSession.Save(exchangeConfigurationContainerWithAddressLists);
                }
            }
            finally
            {
                configurationSession.SkipRangedAttributes = skipRangedAttributes;
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(configurationSession));
            }
        }
Beispiel #6
0
        protected void SaveRoleAndSuggestCleanupOnFailure(ExchangeRole role)
        {
            Exception ex = null;

            try
            {
                this.settings.ConfigurationSession.Save(role);
                this.settings.LogWriteObject(role);
                this.settings.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(role, this.settings.ConfigurationSession, typeof(ExchangeRole)));
            }
            catch (DataSourceOperationException ex2)
            {
                ex = ex2;
            }
            catch (DataValidationException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                CorruptedRoleNeedsCleanupException ex4 = new CorruptedRoleNeedsCleanupException(role.Identity.ToString(), ex.Message, ex);
                if (!this.settings.Task.Stopping)
                {
                    TaskLogger.SendWatsonReport(ex4);
                }
                this.settings.WriteError(ex4, ErrorCategory.InvalidOperation, null);
            }
        }
Beispiel #7
0
        private void CloneRoleAssignment(ExchangeRoleAssignment templateAssignment)
        {
            ExchangeRoleAssignment exchangeRoleAssignment = new ExchangeRoleAssignment();

            exchangeRoleAssignment.ProvisionalClone(templateAssignment);
            exchangeRoleAssignment.User = this.originalUserId;
            string unescapedCommonName = templateAssignment.Name.Substring(0, Math.Min(templateAssignment.Name.Length, 55)) + "_" + (Environment.TickCount % 1000).ToString("0000");

            exchangeRoleAssignment.SetId(templateAssignment.Id.Parent.GetChildId(unescapedCommonName));
            base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeRoleAssignment, templateAssignment.Session, typeof(ExchangeRoleAssignment)));
            templateAssignment.Session.Save(exchangeRoleAssignment);
        }
        private void CreateCannedAddressList(string name, QueryFilter recipientFilter)
        {
            bool flag = string.Equals(name, CannedAddressListsFilterHelper.DefaultAllModernGroups, StringComparison.InvariantCulture);

            if (flag && (!this.CreateModernGroupsAddressList.IsPresent || !VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).CmdletInfra.InstallModernGroupsAddressList.Enabled))
            {
                return;
            }
            ADObjectId id = this.DataObject.Id;

            AddressBookBase[] array = this.FindAddressList(name, recipientFilter);
            if (array == null || array.Length == 0)
            {
                AddressBookBase addressBookBase = new AddressBookBase();
                string          text            = name;
                if (flag)
                {
                    text = Strings.DefaultAllGroups;
                    addressBookBase.IsModernGroupsAddressList = true;
                }
                ADObjectId childId = id.GetChildId(text);
                addressBookBase.SetId(childId);
                addressBookBase.DisplayName = text;
                addressBookBase.SetRecipientFilter(recipientFilter);
                RecipientFilterHelper.StampE2003FilterMetadata(addressBookBase, addressBookBase.LdapRecipientFilter, AddressBookBaseSchema.PurportedSearchUI);
                addressBookBase.OrganizationId = (base.CurrentOrganizationId ?? OrganizationId.ForestWideOrgId);
                base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(addressBookBase, base.DataSession, typeof(AddressBookBase)));
                try
                {
                    base.DataSession.Save(addressBookBase);
                    if (string.Equals(name, CannedAddressListsFilterHelper.DefaultAllRooms, StringComparison.InvariantCulture))
                    {
                        this.PostOrganization(childId);
                    }
                }
                catch (ADObjectAlreadyExistsException)
                {
                    base.WriteVerbose(Strings.VerboseCannedAddressListAlreadyExists(name));
                }
                finally
                {
                    base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
                }
                base.WriteObject(addressBookBase);
            }
        }
Beispiel #9
0
 protected void SaveRoleAndWarnOnFailure(ExchangeRole role)
 {
     try
     {
         this.settings.ConfigurationSession.Save(role);
         this.settings.LogWriteObject(role);
         this.settings.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(role, this.settings.ConfigurationSession, typeof(ExchangeRole)));
     }
     catch (DataSourceOperationException ex)
     {
         this.settings.WriteWarning(Strings.WarningCannotUpgradeRole(role.Identity.ToString(), ex.Message));
     }
     catch (DataValidationException ex2)
     {
         this.settings.WriteWarning(Strings.WarningCannotUpgradeRole(role.Identity.ToString(), ex2.Message));
     }
 }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            IConfigurationSession configurationSession  = (IConfigurationSession)base.DataSession;
            OrganizationId        currentOrganizationId = (this.Identity != null) ? this.DataObject.OrganizationId : base.CurrentOrganizationId;
            ADSessionSettings     sessionSettings       = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, currentOrganizationId, base.ExecutingUserOrganizationId, false);

            configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(configurationSession.DomainController, false, ConsistencyMode.PartiallyConsistent, configurationSession.NetworkCredential, sessionSettings, 62, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\organization\\DisableAddressListPaging.cs");
            Organization orgContainer = configurationSession.GetOrgContainer();

            if (orgContainer.IsAddressListPagingEnabled)
            {
                orgContainer.IsAddressListPagingEnabled = false;
                base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(orgContainer, configurationSession, typeof(Organization)));
                configurationSession.Save(orgContainer);
            }
        }
        private void CloneRoleAssignment(ExchangeRole newRole, ExchangeRoleAssignment oldRoleAssignment)
        {
            ExTraceGlobals.AccessCheckTracer.TraceFunction <string, string, string>(20008L, "-->CloneRoleAssignment: newRole.Name = {0}, oldRoleAssignment.Name = {1}, oldRoleAssignment.User.Name = {2}", newRole.Name, oldRoleAssignment.Name, oldRoleAssignment.User.Name);
            ExchangeRoleAssignment exchangeRoleAssignment = new ExchangeRoleAssignment();

            exchangeRoleAssignment.ProvisionalClone(oldRoleAssignment);
            exchangeRoleAssignment.SetExchangeVersion(oldRoleAssignment.ExchangeVersion);
            exchangeRoleAssignment.Role = newRole.Id;
            this.settings.ConfigurationSession.SessionSettings.IsSharedConfigChecked = true;
            string text = RoleAssignmentHelper.GenerateUniqueRoleAssignmentName(this.settings.ConfigurationSession, this.settings.OrgContainerId, newRole.Name, oldRoleAssignment.User.Name, oldRoleAssignment.RoleAssignmentDelegationType, this.settings.WriteVerbose);

            exchangeRoleAssignment.SetId(this.settings.OrgContainerId.GetDescendantId(ExchangeRoleAssignment.RdnContainer).GetChildId(text));
            ExTraceGlobals.AccessCheckTracer.TraceFunction <string>(20008L, "----CloneRoleAssignment: newRoleAssignmentName = {0}", text);
            this.settings.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeRoleAssignment, this.settings.ConfigurationSession, typeof(ExchangeRoleAssignment)));
            this.settings.ConfigurationSession.Save(exchangeRoleAssignment);
            this.settings.LogWriteObject(exchangeRoleAssignment);
            ExTraceGlobals.AccessCheckTracer.TraceFunction(20008L, "<--CloneRoleAssignment");
        }
Beispiel #12
0
 protected override void InternalEndProcessing()
 {
     TaskLogger.LogEnter();
     this.PrepareDataObjectToSave();
     if (this.objectToSave != null)
     {
         try
         {
             this.PreSaveValidate(this.objectToSave);
             if (base.HasErrors)
             {
                 return;
             }
             if (this.objectToSave.Identity != null)
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(this.objectToSave, base.DataSession, typeof(ComplianceJob)));
             }
             base.DataSession.Save(this.objectToSave);
             this.DataObject = this.objectToSave;
             if (!base.HasErrors)
             {
                 this.WriteResult();
             }
         }
         catch (SqlException exception)
         {
             base.WriteError(exception, ErrorCategory.WriteError, null);
         }
         catch (ArgumentException exception2)
         {
             base.WriteError(exception2, ErrorCategory.WriteError, null);
         }
         finally
         {
             if (this.objectToSave.Identity != null)
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
             }
         }
     }
     base.InternalEndProcessing();
     TaskLogger.LogExit();
 }
Beispiel #13
0
        private void CreateDefaultGal(ADObjectId defaultGal)
        {
            AddressBookBase addressBookBase = new AddressBookBase();

            addressBookBase.SetId(defaultGal);
            addressBookBase.DisplayName = defaultGal.Name;
            addressBookBase.SetRecipientFilter(GlobalAddressList.RecipientFilterForDefaultGal);
            addressBookBase[AddressBookBaseSchema.RecipientFilterFlags] = (RecipientFilterableObjectFlags.FilterApplied | RecipientFilterableObjectFlags.IsDefault);
            RecipientFilterHelper.StampE2003FilterMetadata(addressBookBase, addressBookBase.LdapRecipientFilter, AddressBookBaseSchema.PurportedSearchUI);
            addressBookBase.OrganizationId = (base.CurrentOrganizationId ?? OrganizationId.ForestWideOrgId);
            base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(addressBookBase, base.DataSession, typeof(AddressBookBase)));
            try
            {
                base.DataSession.Save(addressBookBase);
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
            }
            base.WriteObject(addressBookBase);
        }
Beispiel #14
0
 protected override void InternalEndProcessing()
 {
     foreach (AddRemoveManagementRoleEntryActionBase.RoleAndSession roleAndSession in this.roleAndSessionCache.Values)
     {
         LocalizedException ex = null;
         try
         {
             if (roleAndSession.Role.Identity != null)
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(roleAndSession.Role, roleAndSession.ConfigSession, typeof(ExchangeRole)));
             }
             roleAndSession.Role.ApplyChangesToDownlevelData(roleAndSession.ParentRole ?? roleAndSession.Role);
             roleAndSession.ConfigSession.Save(roleAndSession.Role);
         }
         catch (ADOperationException ex2)
         {
             ex = ex2;
         }
         catch (DataSourceTransientException ex3)
         {
             ex = ex3;
         }
         finally
         {
             if (roleAndSession.Role.Identity != null)
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(roleAndSession.ConfigSession));
             }
         }
         if (ex != null)
         {
             foreach (AddRemoveManagementRoleEntryActionBase.PipelinedElement pipelinedElement in roleAndSession.PipelinedElements)
             {
                 this.WriteError(this.GetRoleSaveException(pipelinedElement.RoleEntryString, roleAndSession.Role.Id.ToString(), ex.Message), ErrorCategory.WriteError, pipelinedElement.ObjectIndex, false);
             }
         }
     }
     base.InternalEndProcessing();
 }
Beispiel #15
0
        private void PostExchange(ADObjectId defaultGal)
        {
            IConfigurationSession configurationSession = base.CreateGlobalWritableConfigSession();
            bool skipRangedAttributes = configurationSession.SkipRangedAttributes;

            configurationSession.SkipRangedAttributes = true;
            try
            {
                ExchangeConfigurationContainerWithAddressLists exchangeConfigurationContainerWithAddressLists = configurationSession.GetExchangeConfigurationContainerWithAddressLists();
                if (exchangeConfigurationContainerWithAddressLists.LinkedAddressBookRootAttributesPresent())
                {
                    exchangeConfigurationContainerWithAddressLists.DefaultGlobalAddressList2.Add(defaultGal);
                }
                base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeConfigurationContainerWithAddressLists, configurationSession, typeof(ExchangeConfigurationContainer)));
                configurationSession.Save(exchangeConfigurationContainerWithAddressLists);
                exchangeConfigurationContainerWithAddressLists.ResetChangeTracking();
                if (!AddressBookUtilities.IsTenantAddressList(configurationSession, defaultGal))
                {
                    try
                    {
                        exchangeConfigurationContainerWithAddressLists.DefaultGlobalAddressList.Add(defaultGal);
                        base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeConfigurationContainerWithAddressLists, configurationSession, typeof(ExchangeConfigurationContainer)));
                        configurationSession.Save(exchangeConfigurationContainerWithAddressLists);
                    }
                    catch (AdminLimitExceededException innerException)
                    {
                        throw new ADOperationException(Strings.ErrorTooManyGALsCreated, innerException);
                    }
                }
            }
            finally
            {
                configurationSession.SkipRangedAttributes = skipRangedAttributes;
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(configurationSession));
            }
        }
Beispiel #16
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            bool flag = base.Fields.Contains("SoftDeletedObject");

            if (base.IsVerboseOn)
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(this.DataObject, base.DataSession, typeof(ADUser)));
            }
            if (this.WindowsLiveID != null && this.DataObject.NetID == null)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorMissingWindowsLiveIdHandler), ExchangeErrorCategory.ServerOperation, null);
            }
            try
            {
                if (base.IsDebugOn)
                {
                    base.WriteDebug(Strings.DebugStartSaveDataObject);
                }
                base.DataSession.Save(this.DataObject);
                if (base.IsDebugOn)
                {
                    base.WriteDebug(Strings.DebugEndSaveDataObject);
                }
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
            }
            bool flag2 = false;

            try
            {
                if (!flag)
                {
                    this.StampChangesBeforeSettingPassword();
                    if (this.IsSetRandomPassword)
                    {
                        base.WriteVerbose(Strings.VerboseSettingPassword(this.DataObject.Id.ToString()));
                        MailboxTaskHelper.SetMailboxPassword((IRecipientSession)base.DataSession, this.DataObject, null, new Task.ErrorLoggerDelegate(base.WriteError));
                    }
                    else if (this.Password != null)
                    {
                        base.WriteVerbose(Strings.VerboseSettingPassword(this.DataObject.Id.ToString()));
                        ((IRecipientSession)base.DataSession).SetPassword(this.DataObject, this.Password);
                    }
                    bool       flag3 = base.Fields.IsModified(ADUserSchema.PasswordLastSetRaw) ? this.ResetPasswordOnNextLogon : this.DataObject.ResetPasswordOnNextLogon;
                    bool       bypassModerationCheck = this.DataObject.BypassModerationCheck;
                    ADObjectId id = this.DataObject.Id;
                    using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "DataSession.Read<ADUser>", LoggerHelper.CmdletPerfMonitors))
                    {
                        this.DataObject = (ADUser)base.DataSession.Read <ADUser>(this.DataObject.Identity);
                    }
                    if (this.DataObject == null || this.DataObject.Id == null)
                    {
                        string id2 = (id == null) ? string.Empty : id.ToString();
                        base.WriteError(new RecipientTaskException(Strings.ErrorCreatedUserNotExist(id2)), ExchangeErrorCategory.ServerOperation, null);
                    }
                    this.DataObject.BypassModerationCheck            = bypassModerationCheck;
                    this.DataObject[ADUserSchema.PasswordLastSetRaw] = new long?(flag3 ? 0L : -1L);
                    this.StampChangesAfterSettingPassword();
                }
                base.InternalProcessRecord();
                flag2 = !base.HasErrors;
            }
            finally
            {
                if (!flag2 && this.DataObject != null && this.DataObject.Id != null && !flag)
                {
                    try
                    {
                        base.WriteVerbose(TaskVerboseStringHelper.GetDeleteObjectVerboseString(this.DataObject.Id, base.DataSession, typeof(ADUser)));
                        base.DataSession.Delete(this.DataObject);
                    }
                    catch (DataSourceTransientException innerException)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorRemoveUserFailed(this.DataObject.Id.ToString()), innerException), ExchangeErrorCategory.ServerTransient, null);
                    }
                    finally
                    {
                        base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
                    }
                }
            }
            TaskLogger.LogExit();
        }
        internal static ADSystemMailbox SaveSystemMailbox(MailboxDatabase mdb, Server owningServer, ADObjectId rootOrgContainerId, ITopologyConfigurationSession configSession, IRecipientSession recipientSession, ADObjectId[] forcedReplicationSites, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            TaskLogger.LogEnter();
            bool               useConfigNC        = configSession.UseConfigNC;
            bool               useGlobalCatalog   = configSession.UseGlobalCatalog;
            string             text               = "SystemMailbox" + mdb.Guid.ToString("B");
            SecurityIdentifier securityIdentifier = new SecurityIdentifier("SY");
            ADSystemMailbox    adsystemMailbox    = new ADSystemMailbox();

            adsystemMailbox.StampPersistableDefaultValues();
            adsystemMailbox.Name        = text;
            adsystemMailbox.DisplayName = text;
            adsystemMailbox.Alias       = text;
            adsystemMailbox.HiddenFromAddressListsEnabled = true;
            adsystemMailbox.Database = mdb.Id;
            if (owningServer == null)
            {
                throw new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(mdb.Identity.ToString()));
            }
            adsystemMailbox.ServerLegacyDN = owningServer.ExchangeLegacyDN;
            adsystemMailbox.ExchangeGuid   = Guid.NewGuid();
            AcceptedDomain defaultAcceptedDomain = configSession.GetDefaultAcceptedDomain();

            if (defaultAcceptedDomain == null || defaultAcceptedDomain.DomainName == null || defaultAcceptedDomain.DomainName.Domain == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorNoDefaultAcceptedDomainFound(mdb.Identity.ToString()));
            }
            adsystemMailbox.EmailAddresses.Add(ProxyAddress.Parse("SMTP:" + adsystemMailbox.Alias + "@" + defaultAcceptedDomain.DomainName.Domain.ToString()));
            adsystemMailbox.WindowsEmailAddress         = adsystemMailbox.PrimarySmtpAddress;
            adsystemMailbox.SendModerationNotifications = TransportModerationNotificationFlags.Never;
            Organization organization = configSession.Read <Organization>(rootOrgContainerId);

            if (organization == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorOrganizationNotFound(rootOrgContainerId.Name));
            }
            string parentLegacyDN = string.Format(CultureInfo.InvariantCulture, "{0}/ou={1}/cn=Recipients", new object[]
            {
                organization.LegacyExchangeDN,
                configSession.GetAdministrativeGroupId().Name
            });

            adsystemMailbox.LegacyExchangeDN = LegacyDN.GenerateLegacyDN(parentLegacyDN, adsystemMailbox);
            ADComputer adcomputer;

            try
            {
                configSession.UseConfigNC      = false;
                configSession.UseGlobalCatalog = true;
                adcomputer = configSession.FindComputerByHostName(owningServer.Name);
            }
            finally
            {
                configSession.UseConfigNC      = useConfigNC;
                configSession.UseGlobalCatalog = useGlobalCatalog;
            }
            if (adcomputer == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorDBOwningServerNotFound(mdb.Identity.ToString()));
            }
            ADObjectId adobjectId = adcomputer.Id.DomainId;

            adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects");
            adsystemMailbox.SetId(adobjectId.GetChildId(text));
            GenericAce[] aces = new GenericAce[]
            {
                new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, 131075, securityIdentifier, false, null)
            };
            DirectoryCommon.SetAclOnAlternateProperty(adsystemMailbox, aces, ADSystemAttendantMailboxSchema.ExchangeSecurityDescriptor, securityIdentifier, securityIdentifier);
            recipientSession.LinkResolutionServer = mdb.OriginatingServer;
            bool enforceDefaultScope = recipientSession.EnforceDefaultScope;

            try
            {
                writeVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(adsystemMailbox, recipientSession, typeof(ADSystemMailbox)));
                recipientSession.EnforceDefaultScope = false;
                recipientSession.Save(adsystemMailbox);
            }
            catch (ADConstraintViolationException ex)
            {
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ex.Server, false, ConsistencyMode.PartiallyConsistent, configSession.SessionSettings, 705, "SaveSystemMailbox", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\database\\NewMailboxDatabase.cs");
                if (!tenantOrTopologyConfigurationSession.ReplicateSingleObjectToTargetDC(mdb, ex.Server))
                {
                    throw;
                }
                writeVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(adsystemMailbox, recipientSession, typeof(ADSystemMailbox)));
                recipientSession.Save(adsystemMailbox);
            }
            finally
            {
                writeVerbose(TaskVerboseStringHelper.GetSourceVerboseString(recipientSession));
                recipientSession.EnforceDefaultScope = enforceDefaultScope;
            }
            if (forcedReplicationSites != null)
            {
                DagTaskHelper.ForceReplication(recipientSession, adsystemMailbox, forcedReplicationSites, mdb.Name, writeWarning, writeVerbose);
            }
            TaskLogger.LogExit();
            return(adsystemMailbox);
        }
Beispiel #18
0
 public void CreatePublicFolderTree()
 {
     this.pfTree = new PublicFolderTree();
     try
     {
         QueryFilter filter;
         ADObjectId  adobjectId;
         if (Datacenter.GetExchangeSku() != Datacenter.ExchangeSku.ExchangeDatacenter)
         {
             filter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, PublicFolderTreeContainer.DefaultName);
             PublicFolderTreeContainer[] array = this.taskInstance.GlobalConfigSession.Find <PublicFolderTreeContainer>(null, QueryScope.SubTree, filter, null, 1);
             PublicFolderTreeContainer   publicFolderTreeContainer;
             if (array == null || array.Length == 0)
             {
                 filter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, AdministrativeGroup.DefaultName);
                 AdministrativeGroup[] array2 = this.taskInstance.GlobalConfigSession.Find <AdministrativeGroup>(null, QueryScope.SubTree, filter, null, 1);
                 if (array2 == null || array2.Length < 1)
                 {
                     throw new AdminGroupNotFoundException(AdministrativeGroup.DefaultName);
                 }
                 publicFolderTreeContainer = new PublicFolderTreeContainer();
                 publicFolderTreeContainer.SetId(array2[0].Id.GetChildId(PublicFolderTreeContainer.DefaultName));
                 this.taskInstance.DataSession.Save(publicFolderTreeContainer);
             }
             else
             {
                 publicFolderTreeContainer = array[0];
             }
             adobjectId = publicFolderTreeContainer.Id;
         }
         else
         {
             adobjectId = this.OrganizationId.ConfigurationUnit;
             this.pfTree.OrganizationId = this.OrganizationId;
         }
         this.pfTree.SetId(adobjectId.GetChildId("Public Folders"));
         this.taskInstance.WriteVerbose(Strings.VerboseCreatePublicFolderTree(this.pfTree.Id.ToString()));
         this.pfTree.PublicFolderTreeType = PublicFolderTreeType.Mapi;
         filter = new ComparisonFilter(ComparisonOperator.Equal, ExtendedRightSchema.DisplayName, "Create public folder");
         this.taskInstance.WriteVerbose(TaskVerboseStringHelper.GetFindDataObjectsVerboseString(this.taskInstance.GlobalConfigSession, typeof(ExtendedRight), filter, this.taskInstance.GlobalConfigSession.ConfigurationNamingContext, true));
         ExtendedRight[] array3 = this.taskInstance.GlobalConfigSession.Find <ExtendedRight>(this.taskInstance.GlobalConfigSession.ConfigurationNamingContext, QueryScope.SubTree, filter, null, 1);
         if (0 < array3.Length)
         {
             ObjectAce        objectAce        = new ObjectAce(AceFlags.None, AceQualifier.AccessAllowed, 256, new SecurityIdentifier("AU"), ObjectAceFlags.ObjectAceTypePresent, array3[0].RightsGuid, Guid.Empty, false, null);
             DiscretionaryAcl discretionaryAcl = new DiscretionaryAcl(false, true, 11);
             discretionaryAcl.AddAccess(AccessControlType.Allow, objectAce.SecurityIdentifier, objectAce.AccessMask, objectAce.InheritanceFlags, objectAce.PropagationFlags, objectAce.ObjectAceFlags, objectAce.ObjectAceType, objectAce.InheritedObjectAceType);
             using (WindowsIdentity current = WindowsIdentity.GetCurrent())
             {
                 SecurityIdentifier       user = current.User;
                 CommonSecurityDescriptor commonSecurityDescriptor = new CommonSecurityDescriptor(false, true, ControlFlags.DiscretionaryAclPresent, user, user, null, discretionaryAcl);
                 byte[] binaryForm = new byte[commonSecurityDescriptor.BinaryLength];
                 commonSecurityDescriptor.GetBinaryForm(binaryForm, 0);
                 this.pfTree.SetPublicFolderDefaultAdminAcl(new RawSecurityDescriptor(binaryForm, 0));
             }
         }
         this.taskInstance.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.TenantSession));
         this.taskInstance.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(this.pfTree, this.TenantSession, typeof(PublicFolderTree)));
         this.TenantSession.Save(this.pfTree);
         if (Datacenter.GetExchangeSku() == Datacenter.ExchangeSku.ExchangeDatacenter)
         {
             this.SetOrganizationManagementACLs(this.pfTree);
         }
     }
     finally
     {
         this.taskInstance.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.TenantSession));
     }
 }
Beispiel #19
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            IConfigurationSession configurationSession = (IConfigurationSession)base.DataSession;
            OrganizationId        organizationId       = (this.Identity != null) ? this.DataObject.OrganizationId : base.CurrentOrganizationId;
            ADSessionSettings     sessionSettings      = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, organizationId, base.ExecutingUserOrganizationId, false);

            configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(configurationSession.DomainController, false, ConsistencyMode.PartiallyConsistent, configurationSession.NetworkCredential, sessionSettings, 102, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\organization\\EnableAddressListPaging.cs");
            ADObjectId descendantId;

            if (organizationId != OrganizationId.ForestWideOrgId)
            {
                descendantId = organizationId.ConfigurationUnit.GetDescendantId(SystemAddressList.RdnSystemAddressListContainerToOrganization);
            }
            else
            {
                descendantId = base.RootOrgContainerId.GetDescendantId(SystemAddressList.RdnSystemAddressListContainerToOrganization);
            }
            AddressBookBase addressBookBase = configurationSession.Read <AddressBookBase>(descendantId);

            if (null == addressBookBase)
            {
                addressBookBase = new AddressBookBase();
                addressBookBase.SetId(descendantId);
                addressBookBase.DisplayName    = SystemAddressList.RdnSystemAddressListContainerToOrganization.Name;
                addressBookBase.OrganizationId = organizationId;
                configurationSession.Save(addressBookBase);
            }
            Dictionary <string, bool> dictionary;

            this.CreateCannedSystemAddressLists(configurationSession, addressBookBase, out dictionary);
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(base.TenantGlobalCatalogSession.DomainController, true, ConsistencyMode.PartiallyConsistent, null, sessionSettings, 146, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\organization\\EnableAddressListPaging.cs");

            AddressBookBase[] array = configurationSession.Find <AddressBookBase>(descendantId, QueryScope.SubTree, null, null, 0);
            foreach (AddressBookBase addressBookBase2 in array)
            {
                if (base.Stopping)
                {
                    return;
                }
                bool flag = false;
                dictionary.TryGetValue(addressBookBase2.Name, out flag);
                if (this.DoNotUpdateRecipients.IsPresent)
                {
                    if (flag)
                    {
                        this.WriteWarning(Strings.WarningMustRunEnableAddressListPagingWithForceSwitch(addressBookBase2.Name));
                    }
                }
                else if (this.ForceUpdateOfRecipients.IsPresent || flag)
                {
                    UpdateAddressBookBase <AddressListIdParameter> .UpdateRecipients(addressBookBase2, base.DomainController, tenantOrRootOrgRecipientSession, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new WriteProgress(base.WriteProgress), this);
                }
            }
            Organization orgContainer = configurationSession.GetOrgContainer();

            if (!orgContainer.IsAddressListPagingEnabled)
            {
                orgContainer.IsAddressListPagingEnabled = true;
                base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(orgContainer, configurationSession, typeof(Organization)));
                configurationSession.Save(orgContainer);
            }
            TaskLogger.LogExit();
        }
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            RoleDefinition[]          array;
            RoleNameMappingCollection roleNameMappingCollection;

            string[] array2;
            InstallCannedRbacRoles.CalculateRoleConfigurationForCurrentSKU(this.Organization, out array, out roleNameMappingCollection, out array2, out this.allAllowedRoleEntriesForSKU);
            List <ExchangeRole> list  = new List <ExchangeRole>();
            List <ExchangeRole> list2 = new List <ExchangeRole>();
            bool flag = false;

            if (this.Organization != null)
            {
                ExchangeConfigurationUnit exchangeConfigUnitFromOrganizationId = OrganizationTaskHelper.GetExchangeConfigUnitFromOrganizationId(this.Organization, this.configurationSession, new Task.TaskErrorLoggingDelegate(base.WriteError), true);
                flag = !ServicePlanConfiguration.GetInstance().GetServicePlanSettings(exchangeConfigUnitFromOrganizationId.ProgramId, exchangeConfigUnitFromOrganizationId.OfferId).Organization.PerMBXPlanRoleAssignmentPolicyEnabled;
            }
            ADPagedReader <ExchangeRole> adpagedReader = this.configurationSession.FindAllPaged <ExchangeRole>();

            foreach (ExchangeRole exchangeRole in adpagedReader)
            {
                base.LogReadObject(exchangeRole);
                if (!exchangeRole.IsDeprecated)
                {
                    if (exchangeRole.HasDownlevelData)
                    {
                        exchangeRole[ExchangeRoleSchema.InternalDownlevelRoleEntries] = null;
                    }
                    this.RemoveObsoleteEntriesAndParameters(exchangeRole);
                    if (exchangeRole.RoleEntries.Count == 0)
                    {
                        base.WriteVerbose(Strings.VerboseDeprecatingRoleBecauseNoEntriesLeft(exchangeRole.Id.ToString()));
                        exchangeRole.RoleState = RoleState.Deprecated;
                    }
                    this.configurationSession.Save(exchangeRole);
                    base.LogWriteObject(exchangeRole);
                }
                if (flag && exchangeRole.IsEndUserRole)
                {
                    exchangeRole.MailboxPlanIndex = string.Empty;
                    this.configurationSession.Save(exchangeRole);
                    base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(exchangeRole, this.configurationSession, typeof(ExchangeRole)));
                    base.LogWriteObject(exchangeRole);
                }
                if (exchangeRole.IsDeprecated)
                {
                    this.DeleteRoleAssigments(exchangeRole);
                    if (exchangeRole.IsRootRole)
                    {
                        list.Add(exchangeRole);
                    }
                    else
                    {
                        list2.Add(exchangeRole);
                    }
                }
            }
            foreach (ExchangeRole exchangeRole2 in list)
            {
                this.configurationSession.DeleteTree(exchangeRole2, delegate(ADTreeDeleteNotFinishedException de)
                {
                    if (de != null)
                    {
                        base.WriteVerbose(de.LocalizedString);
                    }
                });
                base.WriteVerbose(Strings.ProgressActivityRemovingManagementRoleTree(exchangeRole2.Id.ToString()));
            }
            foreach (ExchangeRole exchangeRole3 in list2)
            {
                ExchangeRole exchangeRole4 = this.configurationSession.Read <ExchangeRole>(exchangeRole3.Id);
                if (exchangeRole4 != null)
                {
                    base.LogReadObject(exchangeRole4);
                    this.configurationSession.DeleteTree(exchangeRole4, delegate(ADTreeDeleteNotFinishedException de)
                    {
                        if (de != null)
                        {
                            base.WriteVerbose(de.LocalizedString);
                        }
                    });
                    base.WriteVerbose(Strings.ConfirmationMessageRemoveManagementRole(exchangeRole4.Id.ToString()));
                }
            }
        }
Beispiel #21
0
 protected override void InternalEndProcessing()
 {
     TaskLogger.LogEnter();
     this.PrepareDataObjectToSave();
     if (this.objectToSave != null)
     {
         try
         {
             this.PreSaveValidate(this.objectToSave);
             if (base.HasErrors)
             {
                 return;
             }
             if (this.objectToSave.Identity != null)
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(this.objectToSave, base.DataSession, typeof(MailboxDiscoverySearch)));
             }
             ((DiscoverySearchDataProvider)base.DataSession).CreateOrUpdate <MailboxDiscoverySearch>(this.objectToSave);
             SearchEventLogger.Instance.LogDiscoveryAndHoldSavedEvent(this.objectToSave);
             this.DataObject = this.objectToSave;
             if (this.InPlaceHoldEnabled && this.sourceMailboxIdParameters != null && this.sourceMailboxIdParameters.Count > 0)
             {
                 LocalizedString localizedString = this.objectToSave.SynchronizeHoldSettings((DiscoverySearchDataProvider)base.DataSession, this.recipientSession, true, delegate(int percentage)
                 {
                     base.WriteProgress(Strings.NewMailboxSearchActivity, Strings.ApplyingHoldSettings(this.objectToSave.Name), percentage);
                 });
                 if (localizedString != LocalizedString.Empty)
                 {
                     base.WriteError(new MailboxSearchTaskException(localizedString), ErrorCategory.InvalidOperation, this);
                 }
                 this.WriteWarning(Strings.WarningDiscoveryHoldDelay(COWSettings.COWCacheLifeTime.TotalMinutes));
             }
             if (!base.HasErrors)
             {
                 this.WriteResult();
             }
         }
         catch (ObjectNotFoundException exception)
         {
             base.WriteError(exception, ErrorCategory.ObjectNotFound, null);
         }
         catch (DataSourceTransientException exception2)
         {
             base.WriteError(exception2, ErrorCategory.WriteError, null);
         }
         catch (ArgumentException exception3)
         {
             base.WriteError(exception3, ErrorCategory.WriteError, null);
         }
         catch (StorageTransientException innerException)
         {
             base.WriteError(new TaskException(Strings.ErrorMailboxSearchStorageTransient, innerException), ErrorCategory.WriteError, null);
         }
         catch (StoragePermanentException innerException2)
         {
             base.WriteError(new TaskException(Strings.ErrorMailboxSearchStoragePermanent, innerException2), ErrorCategory.WriteError, null);
         }
         finally
         {
             if (this.objectToSave.Identity != null)
             {
                 base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
             }
         }
     }
     base.InternalEndProcessing();
     TaskLogger.LogExit();
 }