Exemple #1
0
        internal static bool IsKB922817InstalledOnServer(string computerName, Task.TaskErrorLoggingDelegate errorHandler)
        {
            Exception ex     = null;
            bool      result = false;

            try
            {
                using (RegistryKey registryKey = RegistryUtil.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName))
                {
                    using (RegistryKey registryKey2 = registryKey.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\KB922817"))
                    {
                        result = (registryKey2 != null);
                    }
                }
            }
            catch (SecurityException ex2)
            {
                ex = ex2;
            }
            catch (IOException ex3)
            {
                ex = ex3;
            }
            catch (UnauthorizedAccessException ex4)
            {
                ex = ex4;
            }
            if (ex != null)
            {
                errorHandler(new InvalidOperationException(Strings.ErrorAccessingRegistryRaisesException(computerName, ex.Message)), ErrorCategory.ReadError, null);
            }
            return(result);
        }
        internal static void UpdateServerLegdnForDatabaseSite(Task.TaskErrorLoggingDelegate writeErrorDelegate, Task.TaskVerboseLoggingDelegate writeVerboseDelegate, ITopologyConfigurationSession adSession, DatabaseCopy dbCopy)
        {
            ADObjectId hostServer = dbCopy.HostServer;

            PropertyDefinition[] properties = new PropertyDefinition[]
            {
                ServerSchema.ServerSite
            };
            MiniServer miniServer = adSession.ReadMiniServer(hostServer, properties);

            if (miniServer == null)
            {
                writeErrorDelegate(new ADServerNotFoundException(hostServer.ToString()), ErrorCategory.InvalidArgument, null);
            }
            IADToplogyConfigurationSession adSession2 = ADSessionFactory.CreateWrapper(adSession);
            SimpleAdObjectLookup <IADClientAccessArray> findClientAccessArray      = new SimpleAdObjectLookup <IADClientAccessArray>(adSession2);
            SimpleMiniClientAccessServerOrArrayLookup   findMiniClientAccessServer = new SimpleMiniClientAccessServerOrArrayLookup(adSession);
            ADObjectId serverSite = miniServer.ServerSite;
            LegacyDN   legacyDN   = ActiveManagerImplementation.FindClientAccessArrayOrServerFromSite(serverSite, miniServer.Id, findClientAccessArray, findMiniClientAccessServer, AdObjectLookupFlags.ReadThrough);
            ADObjectId parent     = dbCopy.Id.Parent;
            Database   database   = adSession.Read <Database>(parent);

            if (legacyDN != null)
            {
                LegacyDN databaseLegacyDNFromRcaLegacyDN = Database.GetDatabaseLegacyDNFromRcaLegacyDN(legacyDN, database.IsPublicFolderDatabase);
                database.ExchangeLegacyDN = databaseLegacyDNFromRcaLegacyDN.ToString();
                writeVerboseDelegate(Strings.UpdatingLegDnForDatabaseToServer(database.Name, legacyDN.ToString(), legacyDN.ToString()));
                adSession.Save(database);
                return;
            }
            ExTraceGlobals.CmdletsTracer.TraceDebug <ADObjectId>(0L, "Could not find a new CAS machines for site '{0}'. Leaving the database's legdn unchanged.", serverSite);
        }
 public static void ValidateStartAfterTime(DateTime startAfterUtc, Task.TaskErrorLoggingDelegate writeError, DateTime utcNow)
 {
     if (utcNow.AddDays(30.0) < startAfterUtc)
     {
         writeError(new MoveStartAfterDateRangeException(30), ErrorCategory.InvalidArgument, startAfterUtc);
     }
 }
Exemple #4
0
 internal void Validate(Task.TaskErrorLoggingDelegate writeError)
 {
     if ((this.Cmdlets == null || this.Cmdlets.Count == 0) && this.Parameters != null && this.Parameters.Count != 0)
     {
         writeError(new ArgumentException(Strings.AdminAuditLogSearchMissingCmdletsWhileParameterProvided), ErrorCategory.InvalidArgument, null);
     }
 }
 internal static void ValidateUserName(string userName, Task.TaskErrorLoggingDelegate taskErrorLoggingDelegate)
 {
     if (string.IsNullOrEmpty(userName))
     {
         taskErrorLoggingDelegate(new InvalidOperationException(Strings.IncomingUserNameEmpty), ErrorCategory.InvalidData, null);
     }
 }
Exemple #6
0
 public static void FixAuthMetadataUrl(AuthServer authServer, Task.TaskErrorLoggingDelegate writeError)
 {
     if (authServer.Type == AuthServerType.ADFS)
     {
         Uri    uri             = null;
         string authMetadataUrl = authServer.AuthMetadataUrl;
         try
         {
             uri = new Uri(authServer.AuthMetadataUrl);
         }
         catch (ArgumentNullException)
         {
             writeError(new TaskException(Strings.ErrorInvalidMetadataUrl(authMetadataUrl)), ErrorCategory.InvalidArgument, null);
         }
         catch (UriFormatException)
         {
             writeError(new TaskException(Strings.ErrorInvalidMetadataUrl(authMetadataUrl)), ErrorCategory.InvalidArgument, null);
         }
         if ((uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp) && uri.AbsolutePath == "/")
         {
             authServer.AuthMetadataUrl = new UriBuilder(uri)
             {
                 Path = "federationmetadata/2007-06/federationmetadata.xml"
             }.ToString();
         }
     }
 }
Exemple #7
0
 public static void CheckReplayServiceRunningOnNode(AmServerName nodeName, Task.TaskErrorLoggingDelegate writeError)
 {
     if (!DatabaseTasksHelper.IsServiceRunningOnNode("msexchangerepl", nodeName))
     {
         writeError(new ReplServiceNotRunningOnNodeException(nodeName.NetbiosName), ErrorCategory.InvalidOperation, null);
     }
 }
 internal static void CheckDomainForRemoval(AcceptedDomain acceptedDomain, Task.TaskErrorLoggingDelegate writeError)
 {
     if (acceptedDomain.Default)
     {
         writeError(new CannotRemoveDefaultAcceptedDomainException(), ErrorCategory.InvalidOperation, acceptedDomain);
     }
 }
Exemple #9
0
        public static string EncryptSecretWithDKM(string secretInClearText, Task.TaskErrorLoggingDelegate writeError)
        {
            if (string.IsNullOrEmpty(secretInClearText))
            {
                throw new ArgumentNullException("secretInClearText");
            }
            if (writeError == null)
            {
                throw new ArgumentNullException("writeError");
            }
            ExchangeGroupKey exchangeGroupKey = new ExchangeGroupKey(null, "Microsoft Exchange DKM");
            string           result;

            try
            {
                result = exchangeGroupKey.ClearStringToEncryptedString(secretInClearText);
            }
            catch (Exception ex)
            {
                if (ex is CryptographicException || ex is InvalidDataException || exchangeGroupKey.IsDkmException(ex))
                {
                    writeError(ex, ErrorCategory.InvalidData, null);
                }
                throw;
            }
            return(result);
        }
Exemple #10
0
 public static void ProcessRecord(Action action, Task.TaskErrorLoggingDelegate handleError, object identity)
 {
     try
     {
         action();
     }
     catch (OwaExtensionOperationException exception)
     {
         handleError(exception, ErrorCategory.InvalidOperation, identity);
     }
     catch (StorageTransientException exception2)
     {
         handleError(exception2, ErrorCategory.WriteError, null);
     }
     catch (StoragePermanentException exception3)
     {
         handleError(exception3, ErrorCategory.WriteError, null);
     }
     catch (XmlException exception4)
     {
         handleError(exception4, ErrorCategory.InvalidData, null);
     }
     catch (XPathException exception5)
     {
         handleError(exception5, ErrorCategory.InvalidData, null);
     }
 }
Exemple #11
0
 internal static void VerifyMailboxVersion(ADObject adObject, Task.TaskErrorLoggingDelegate writeErrorDelegate)
 {
     if (adObject.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2010))
     {
         writeErrorDelegate(new TaskException(Strings.ErrorMailboxVersionTooOld(adObject.Id.ToString())), ErrorCategory.ReadError, null);
     }
 }
 public static void ValidateCompleteAfterTime(DateTime completeAfterUtc, Task.TaskErrorLoggingDelegate writeError, DateTime utcNow)
 {
     if (utcNow.AddDays(120.0) < completeAfterUtc)
     {
         writeError(new MoveCompleteAfterDateRangeException(120), ErrorCategory.InvalidArgument, completeAfterUtc);
     }
 }
Exemple #13
0
 internal static void CheckUserVersion(ADUser user, Task.TaskErrorLoggingDelegate writeError)
 {
     if (user.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2010))
     {
         writeError(new InvalidOperationException(Strings.ErrorCannotOpenLegacyMailbox(user.Identity.ToString())), ErrorCategory.InvalidOperation, user.Identity);
     }
 }
Exemple #14
0
        internal static void WriteRpcError(RpcException e, string server, Task.TaskErrorLoggingDelegate errorHandler)
        {
            LocalizedException exception;
            ErrorCategory      category;

            ManageExchangeCertificate.ProcessRpcError(e, server, out exception, out category);
            errorHandler(exception, category, null);
        }
 internal static void ValidateIncomingServerLength(string incomingServer, Task.TaskErrorLoggingDelegate taskErrorLoggingDelegate)
 {
     SyncUtilities.ThrowIfArgumentNullOrEmpty("incomingServer", incomingServer);
     SyncUtilities.ThrowIfArgumentNull("taskErrorLoggingDelegate", taskErrorLoggingDelegate);
     if (incomingServer.Length > SyncUtilities.MaximumFqdnLength)
     {
         taskErrorLoggingDelegate(new IncomingServerTooLongException(), ErrorCategory.InvalidArgument, null);
     }
 }
Exemple #16
0
 internal HaTaskOutputHelper(string taskName, Task.TaskErrorLoggingDelegate writeError, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose, Task.TaskProgressLoggingDelegate writeProgress, int hashCode)
 {
     this.m_taskName      = taskName;
     this.m_writeError    = writeError;
     this.m_writeWarning  = writeWarning;
     this.m_writeVerbose  = writeVerbose;
     this.m_writeProgress = writeProgress;
     this.m_hashCode      = hashCode;
 }
Exemple #17
0
        internal static void VerifyIsInScopes(ADObject adObject, ScopeSet scopeSet, Task.TaskErrorLoggingDelegate writeErrorDelegate)
        {
            ADScopeException ex;

            if (!ADSession.TryVerifyIsWithinScopes(adObject, scopeSet.RecipientReadScope, scopeSet.RecipientWriteScopes, scopeSet.ExclusiveRecipientScopes, false, out ex))
            {
                writeErrorDelegate(new TaskException(Strings.ErrorCannotChangeObjectOutOfWriteScope(adObject.Identity.ToString(), (ex == null) ? string.Empty : ex.Message), ex), ErrorCategory.PermissionDenied, null);
            }
        }
Exemple #18
0
 internal void Validate(Task.TaskErrorLoggingDelegate writeError)
 {
     this.LogonTypes = new MultiValuedProperty <string>();
     if (this.LogonTypesUserInput == null)
     {
         this.LogonTypes.Add("Admin");
         this.LogonTypes.Add("Delegate");
         if (this.ShowDetails)
         {
             this.LogonTypes.Add("Owner");
         }
     }
     else
     {
         if (!this.ShowDetails && base.ExternalAccess != null && base.ExternalAccess.Value && this.LogonTypesUserInput.Count == 1 && (this.LogonTypesUserInput[0] & AuditScopes.Delegate) == AuditScopes.Delegate)
         {
             writeError(new ArgumentException(Strings.ErrorInvalidLogonType), ErrorCategory.InvalidArgument, null);
         }
         foreach (AuditScopes auditScopes in this.LogonTypesUserInput)
         {
             if ((auditScopes & AuditScopes.Admin) == AuditScopes.Admin)
             {
                 this.LogonTypes.Add("Admin");
             }
             if ((auditScopes & AuditScopes.Delegate) == AuditScopes.Delegate)
             {
                 this.LogonTypes.Add("Delegate");
             }
             if ((auditScopes & AuditScopes.Owner) == AuditScopes.Owner)
             {
                 if (!this.ShowDetails)
                 {
                     writeError(new ArgumentException(Strings.ErrorInvalidMailboxAuditLogSearchCriteria), ErrorCategory.InvalidArgument, null);
                 }
                 else
                 {
                     this.LogonTypes.Add("Owner");
                 }
             }
         }
     }
     if (this.OperationsUserInput != null)
     {
         if (!this.LogonTypes.Contains("Owner") && this.OperationsUserInput.Contains(MailboxAuditOperations.MailboxLogin))
         {
             writeError(new ArgumentException(Strings.ErrorInvalidOperation), ErrorCategory.InvalidArgument, null);
         }
         foreach (MailboxAuditOperations mailboxAuditOperations in this.OperationsUserInput)
         {
             if (mailboxAuditOperations != MailboxAuditOperations.None)
             {
                 this.Operations.Add(mailboxAuditOperations.ToString());
             }
         }
     }
 }
Exemple #19
0
 internal static void VerifyIsInScopes(ADObject adObject, ScopeSet scopeSet, Task.TaskErrorLoggingDelegate writeErrorDelegate)
 {
     try
     {
         ADSession.VerifyIsWithinScopes(adObject, scopeSet.RecipientReadScope, scopeSet.RecipientWriteScopes, scopeSet.ExclusiveRecipientScopes, false);
     }
     catch (ADScopeException)
     {
         writeErrorDelegate(new MailboxSearchScopeException(adObject.Id.ToString()), ErrorCategory.PermissionDenied, null);
     }
 }
Exemple #20
0
 public static void Validate(HybridConfiguration dataObject, bool hasErrors, Task.TaskErrorLoggingDelegate writeErrorFunc)
 {
     if (hasErrors)
     {
         return;
     }
     if (dataObject.MaximumSupportedExchangeObjectVersion.ExchangeBuild < dataObject.ExchangeVersion.ExchangeBuild)
     {
         writeErrorFunc(new InvalidObjectOperationException(HybridStrings.ErrorHybridConfigurationTooNew(dataObject.ExchangeVersion.ToString(), dataObject.MaximumSupportedExchangeObjectVersion.ToString())), ErrorCategory.InvalidArgument, null);
     }
 }
 protected override void InternalProcessComplete()
 {
     base.InternalProcessComplete();
     if (this.CertificateAuthentication)
     {
         T dataObject = this.DataObject;
         dataObject.CertificateAuthentication = new bool?(true);
         ADExchangeServiceVirtualDirectory virtualDirectory = this.DataObject;
         Task.TaskErrorLoggingDelegate     errorHandler     = new Task.TaskErrorLoggingDelegate(base.WriteError);
         T dataObject2 = this.DataObject;
         ExchangeServiceVDirHelper.SetIisVirtualDirectoryAuthenticationMethods(virtualDirectory, errorHandler, Strings.ErrorUpdatingVDir(dataObject2.MetabasePath, string.Empty));
     }
 }
        internal static void CheckServerDoesNotBelongToDifferentStampGroup(Task.TaskErrorLoggingDelegate writeError, IConfigDataProvider dataSession, Server server, string stampGroupName)
        {
            ADObjectId databaseAvailabilityGroup = server.DatabaseAvailabilityGroup;

            if (databaseAvailabilityGroup != null)
            {
                StampGroup stampGroup = (StampGroup)dataSession.Read <StampGroup>(databaseAvailabilityGroup);
                if (stampGroup != null && stampGroup.Name != stampGroupName)
                {
                    writeError(new DagTaskServerMailboxServerIsInDifferentDagException(server.Name, stampGroup.Name), ErrorCategory.InvalidArgument, null);
                }
            }
        }
 internal static void ValidateParamString(string paramName, string value, Task.TaskErrorLoggingDelegate errorLogger, bool blockWildcards)
 {
     if (string.IsNullOrEmpty(paramName))
     {
         throw new ArgumentNullException("paramName");
     }
     if (string.IsNullOrEmpty(value))
     {
         throw new ArgumentNullException("value");
     }
     if (value.Contains("\"") || value.Contains("$") || (blockWildcards && value.Contains("*")))
     {
         errorLogger(new ArgumentException(Strings.ErrorInvalidCharactersInParameterValue(paramName, value, blockWildcards ? "{'\"', '$', '*'}" : "{'\"', '$'}")), ErrorCategory.InvalidArgument, null);
     }
 }
Exemple #24
0
        internal static void ValidateDomainName(AcceptedDomain domain, Task.TaskErrorLoggingDelegate errorWriter)
        {
            string domain2 = domain.DomainName.Domain;
            DuplicateAcceptedDomainException   ex = new DuplicateAcceptedDomainException(domain2);
            ConflictingAcceptedDomainException conflictingAcceptedDomainException = new ConflictingAcceptedDomainException(domain2);
            Exception ex2;

            if (!ADAccountPartitionLocator.ValidateDomainName(domain, ex, conflictingAcceptedDomainException, out ex2))
            {
                ErrorCategory category = ErrorCategory.InvalidOperation;
                if (ex2 == ex)
                {
                    category = ErrorCategory.ResourceExists;
                }
                errorWriter(ex2, category, domain);
            }
        }
 public SourceValidator(Task.TaskErrorLoggingDelegate writeErrorDelegate, Action <LocalizedString> writeWarningDelegate, Func <LocalizedString, bool> shouldContinueDelegate, ExecutionLog logger, string logTag, string tenantId, SourceValidator.Clients client)
 {
     if (client == SourceValidator.Clients.NewCompliancePolicy || client == SourceValidator.Clients.SetCompliancePolicy)
     {
         ArgumentValidator.ThrowIfNull("writeErrorDelegate", writeErrorDelegate);
         ArgumentValidator.ThrowIfNull("writeWarningDelegate", writeWarningDelegate);
         ArgumentValidator.ThrowIfNull("shouldContinueDelegate", shouldContinueDelegate);
     }
     this.writeErrorDelegate     = writeErrorDelegate;
     this.writeWarningDelegate   = writeWarningDelegate;
     this.shouldContinueDelegate = shouldContinueDelegate;
     this.logger           = logger;
     this.logTag           = logTag;
     this.tenantId         = tenantId;
     this.client           = client;
     this.logCorrelationId = Guid.NewGuid().ToString();
 }
 protected override void InternalProcessRecord()
 {
     base.InternalProcessRecord();
     base.InternalEnableLiveIdNegotiateAuxiliaryModule();
     if (base.Fields["CertificateAuthentication"] != null)
     {
         T dataObject = this.DataObject;
         dataObject.CertificateAuthentication = new bool?((bool)base.Fields["CertificateAuthentication"]);
         ADExchangeServiceVirtualDirectory virtualDirectory = this.DataObject;
         Task.TaskErrorLoggingDelegate     errorHandler     = new Task.TaskErrorLoggingDelegate(base.WriteError);
         T dataObject2 = this.DataObject;
         ExchangeServiceVDirHelper.SetIisVirtualDirectoryAuthenticationMethods(virtualDirectory, errorHandler, Strings.ErrorUpdatingVDir(dataObject2.MetabasePath, string.Empty));
         T dataObject3 = this.DataObject;
         ExchangeServiceVDirHelper.ConfigureAnonymousAuthentication(dataObject3.MetabasePath, false);
     }
     if (base.Fields["EnableCertificateHeaderAuthModule"] != null)
     {
         base.SetCertificateHeaderAuthenticationModule(this.EnableCertificateHeaderAuthModule, false);
     }
 }
Exemple #27
0
 internal static void UpdateMetabase(ADOabVirtualDirectory virtualDirectory, Task.TaskErrorLoggingDelegate handler)
 {
     try
     {
         DirectoryEntry directoryEntry2;
         DirectoryEntry directoryEntry = directoryEntry2 = IisUtility.CreateIISDirectoryEntry(virtualDirectory.MetabasePath);
         try
         {
             ArrayList arrayList = new ArrayList();
             int       num       = (int)(IisUtility.GetIisPropertyValue("AccessSSLFlags", IisUtility.GetProperties(directoryEntry)) ?? 0);
             if (virtualDirectory.RequireSSL)
             {
                 num |= 8;
             }
             else
             {
                 num &= -9;
                 num &= -257;
                 num &= -65;
             }
             arrayList.Add(new MetabaseProperty("AccessSSLFlags", num, true));
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.Basic, virtualDirectory.BasicAuthentication);
             IisUtility.SetAuthenticationMethod(directoryEntry, AuthenticationMethodFlags.WindowsIntegrated, virtualDirectory.WindowsAuthentication);
             IisUtility.SetProperties(directoryEntry, arrayList);
             directoryEntry.CommitChanges();
             IisUtility.CommitMetabaseChanges((virtualDirectory.Server == null) ? null : virtualDirectory.Server.ToString());
         }
         finally
         {
             if (directoryEntry2 != null)
             {
                 ((IDisposable)directoryEntry2).Dispose();
             }
         }
     }
     catch (COMException exception)
     {
         handler(exception, ErrorCategory.InvalidOperation, virtualDirectory.Identity);
     }
 }
Exemple #28
0
        private static void RunNetShProcess(string args, Task.TaskErrorLoggingDelegate errorHandler)
        {
            string text  = null;
            string text2 = null;

            try
            {
                ProcessRunner.Run(ManageService.NetshExe, args, -1, null, out text, out text2);
            }
            catch (Win32Exception exception)
            {
                errorHandler(exception, ErrorCategory.InvalidOperation, null);
            }
            catch (System.TimeoutException exception2)
            {
                errorHandler(exception2, ErrorCategory.OperationTimeout, null);
            }
            catch (InvalidOperationException exception3)
            {
                errorHandler(exception3, ErrorCategory.InvalidOperation, null);
            }
        }
Exemple #29
0
 internal static void ValidateSwitches(DatabaseAvailabilityGroupNetwork net, Task.TaskErrorLoggingDelegate writeError)
 {
     if (net.IsModified(DatabaseAvailabilityGroupNetworkSchema.ReplicationEnabled) && net.IsModified(DatabaseAvailabilityGroupNetworkSchema.IgnoreNetwork))
     {
         if (net.IgnoreNetwork && net.ReplicationEnabled)
         {
             writeError(new DagNetworkInconsistentRoleException(), ErrorCategory.InvalidArgument, null);
             return;
         }
     }
     else
     {
         if (net.IsModified(DatabaseAvailabilityGroupNetworkSchema.ReplicationEnabled) && net.ReplicationEnabled)
         {
             net.IgnoreNetwork = false;
         }
         if (net.IsModified(DatabaseAvailabilityGroupNetworkSchema.IgnoreNetwork) && net.IgnoreNetwork)
         {
             net.ReplicationEnabled = false;
         }
     }
 }
Exemple #30
0
 public static void CheckDatabaseCopyForCopyTask(Database database, Task.TaskErrorLoggingDelegate writeError, Server server, out DatabaseCopy databaseCopy, out DatabaseCopy[] databaseCopies)
 {
     databaseCopy   = null;
     databaseCopies = database.GetDatabaseCopies();
     if (databaseCopies == null || databaseCopies.Length == 0)
     {
         writeError(new CopyConfigurationErrorException(Strings.ErrorCouldNotReadDatabaseCopy(database.Name)), ErrorCategory.ReadError, database.Identity);
     }
     else
     {
         foreach (DatabaseCopy databaseCopy2 in databaseCopies)
         {
             if (databaseCopy2.HostServer.ObjectGuid == server.Guid)
             {
                 databaseCopy = databaseCopy2;
                 break;
             }
         }
     }
     if (databaseCopy == null && database.ReplicationType == ReplicationType.Remote)
     {
         writeError(new InvalidOperationException(Strings.ErrorDbCopyNotHostedOnServer(database.Identity.ToString(), server.Identity.ToString())), ErrorCategory.InvalidData, database.Identity);
     }
 }