protected override void Dispose(bool disposing)
 {
     if (disposing && this.DirectoryAgent != null)
     {
         this.DirectoryAgent.Dispose();
         this.DirectoryAgent = null;
     }
     base.Dispose(disposing);
 }
Example #2
0
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     using (var directoryAgent = new DirectoryAgent(this.DirectoryContext))
     {
         directoryAgent.ChangeBootKey(this.OldBootKey, this.NewBootKey);
     }
     // TODO: Verbosity
     // TODO: Exception handling
 }
Example #3
0
        // TODO: Add optional Guid parameter

        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            using (var directoryAgent = new DirectoryAgent(this.DirectoryContext))
            {
                foreach (var rootKey in directoryAgent.GetKdsRootKeys())
                {
                    this.WriteObject(rootKey);
                }
            }
            // TODO: Exception handling
        }
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     using (var directoryAgent = new DirectoryAgent(this.DirectoryContext))
     {
         foreach (var secret in directoryAgent.GetDPAPIBackupKeys(this.BootKey))
         {
             this.WriteObject(secret);
         }
     }
     // TODO: Exception handling
 }
Example #5
0
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     byte[] oldBinaryBootKey = this.OldBootKey.HexToBinary();
     byte[] newBinaryBootKey = this.NewBootKey.HexToBinary();
     using (var directoryAgent = new DirectoryAgent(this.DirectoryContext))
     {
         directoryAgent.ChangeBootKey(oldBinaryBootKey, newBinaryBootKey);
     }
     // TODO: Verbosity
     // TODO: Exception handling
 }
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     try
     {
         this.DirectoryAgent = new DirectoryAgent(this.DirectoryContext);
     }
     catch (Exception ex)
     {
         ErrorRecord error = new ErrorRecord(ex, "TableOpenError", ErrorCategory.OpenError, null);
         // Terminate on this error:
         this.ThrowTerminatingError(error);
     }
 }
Example #7
0
        private async Task <SystemAgent> CreateModel(SimulationContext context, int simulationId, int simNr)
        {
            var simConfig = _productionDomainContext.SimulationConfigurations.Single(x => x.Id == simulationId);

            //context.Register(new SimulationEndTrigger(() => (context.TimePeriod > simConfig.SimulationEndTime)));
            new SimulationEndTrigger(() => context.TimePeriod > simConfig.SimulationEndTime);


            var system         = new SystemAgent(null, "System", false, _productionDomainContext, _messageHub, simConfig);
            var randomWorkTime = new WorkTimeGenerator(simConfig.Seed, simConfig.WorkTimeDeviation, simNr);
            // Create Directory Agent,
            var directoryAgent = new DirectoryAgent(system, "Directory", false);

            system.ChildAgents.Add(directoryAgent);

            // Create Machine Agents
            foreach (var machine in _productionDomainContext.Machines.Include(m => m.MachineGroup))
            {
                system.ChildAgents.Add(new MachineAgent(creator: system,
                                                        name: "Machine: " + machine.Name,
                                                        debug: false,
                                                        directoryAgent: directoryAgent,
                                                        machine: machine,
                                                        workTimeGenerator: randomWorkTime));
            }

            // Create Stock Agents
            foreach (var stock in _productionDomainContext.Stocks.AsNoTracking()
                     .Include(x => x.StockExchanges)
                     .Include(x => x.Article).ThenInclude(x => x.ArticleToBusinessPartners)
                     .ThenInclude(x => x.BusinessPartner))
            {
                system.ChildAgents.Add(new StorageAgent(creator: system,
                                                        name: stock.Name,
                                                        debug: false,
                                                        stockElement: stock));
            }

            await system.PrepareAgents(simConfig, simNr);

            // Return System Agent to Context
            return(system);
        }
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     if (!Force.IsPresent)
     {
         // Do not continue with operation until the user enforces it.
         var exception = new ArgumentException(Resources.WarningMessage);
         var error     = new ErrorRecord(exception, "SetADDBDomainController_ForceRequired", ErrorCategory.InvalidArgument, null);
         this.ThrowTerminatingError(error);
     }
     try
     {
         this.DirectoryAgent = new DirectoryAgent(this.DirectoryContext);
     }
     catch (Exception ex)
     {
         ErrorRecord error = new ErrorRecord(ex, "TableOpenError", ErrorCategory.OpenError, null);
         // Terminate on this error:
         this.ThrowTerminatingError(error);
     }
 }
        protected override void ProcessRecord()
        {
            if (this.BootKey == null)
            {
                // No boot key has been provided so we need to get one from registry.
                // Presume that the database is part of an IFM backup:
                string registryPath         = Path.Combine(this.DirectoryContext.DSAWorkingDirectory, DefaultRegistryPath);
                string resolvedRegistryPath = this.ResolveFilePath(registryPath);
                this.BootKey = BootKeyRetriever.GetBootKey(resolvedRegistryPath);
            }

            using (var dsa = new DirectoryAgent(this.DirectoryContext))
            {
                bool bootKeyIsValid = dsa.CheckBootKey(this.BootKey);
                if (!bootKeyIsValid)
                {
                    throw new ArgumentException("The boot key provided cannot be used to decrypt the database.", "BootKey");
                }
            }

            var dc = this.DirectoryContext.DomainController;

            if (this.SysvolPath == null)
            {
                // Presume that the database is part of an IFM backup:
                this.SysvolPath = Path.Combine(this.DirectoryContext.DSAWorkingDirectory, DefaultSysvolPath, dc.DomainName);
            }

            // TODO: Check that the DC is a GC
            // TODO: Check that the DC is not a RODC
            // TODO: Check DNS partition presence
            // TODO: Check backup expiration time

            // Load the RFM script template and replace placeholders with values from the DB:
            string template = LoadScriptTemplate();
            var    script   = new StringBuilder(template).
                              Replace("{DCName}", dc.Name).
                              Replace("{DCGuid}", dc.Guid.ToString()).
                              Replace("{DomainName}", dc.DomainName).
                              Replace("{NetBIOSDomainName}", dc.NetBIOSDomainName).
                              Replace("{ForestName}", dc.ForestName).
                              Replace("{DomainGuid}", dc.DomainGuid.ToString()).
                              Replace("{DomainSid}", dc.DomainSid.ToString()).
                              Replace("{DomainMode}", ((int)dc.DomainMode).ToString()).
                              Replace("{ForestMode}", ((int)dc.ForestMode).ToString()).
                              Replace("{OSName}", dc.OSName).
                              Replace("{OldBootKey}", this.BootKey.ToHex()).
                              Replace("{SourceDBPath}", this.DirectoryContext.DSADatabaseFile).
                              Replace("{SourceDBDirPath}", this.DirectoryContext.DSAWorkingDirectory).
                              Replace("{SourceLogDirPath}", this.DirectoryContext.DatabaseLogFilesPath).
                              Replace("{TargetDBDirPath}", @"$env:SYSTEMROOT\NTDS").
                              Replace("{TargetLogDirPath}", @"$env:SYSTEMROOT\NTDS").
                              Replace("{SourceSysvolPath}", this.ResolveDirectoryPath(this.SysvolPath)).
                              Replace("{TargetSysvolPath}", @"$env:SYSTEMROOT\SYSVOL");

            // We need to inject cleartext version of the password into the script for dcpromo. The SecureString will therefore have to appear in managed memory, which is against best practices.
            using (var dsrmPassword = new SafeUnicodeSecureStringPointer(this.SafeModeAdministratorPassword))
            {
                script.Replace("{DSRMPassword}", dsrmPassword.ToString());
            }

            // The script is now ready so write it to standard output
            this.WriteObject(script.ToString());
            script.Clear();
        }