public SampleBot(BotRunner runner, TargetServer server, AuthInfo auth) : base(runner, server, auth) { lastStamp = Network.Util.Clock.GetTimeMilliseconds(); stateMachine = new BotStateMachine(); refreshStateMachine = true; }
private string BuildSql(CohortAggregateContainer container, ParameterManager parameterManager) { Dictionary <CohortQueryBuilderDependency, string> sqlDictionary; //if we are fully cached on everything if (Dependencies.All(d => d.SqlFullyCached != null)) { SetTargetServer(GetCacheServer(), "all dependencies are fully cached"); //run on the cache server //all are cached CountOfCachedSubQueries = CountOfSubQueries; sqlDictionary = Dependencies.ToDictionary(k => k, v => v.SqlFullyCached.Use(parameterManager)); //run the fully cached sql } else { string uncached = "CacheUsageDecision is " + CacheUsageDecision + " and the following were not cached:" + string.Join(Environment.NewLine, Dependencies.Where(d => d.SqlFullyCached == null)); switch (CacheUsageDecision) { case CacheUsage.MustUse: throw new QueryBuildingException( "Could not build final SQL because some queries are not fully cached and " + uncached); case CacheUsage.Opportunistic: //The cache and dataset are on the same server so run it SetTargetServer(DependenciesSingleServer.GetDistinctServer(), "not all dependencies are cached while " + uncached); CountOfCachedSubQueries = Dependencies.Count(d => d.SqlFullyCached != null); sqlDictionary = Dependencies.ToDictionary(k => k, v => v.SqlFullyCached?.Use(parameterManager) ?? v.SqlPartiallyCached?.Use(parameterManager) ?? v.SqlCacheless.Use(parameterManager)); //run the fully cached sql break; case CacheUsage.AllOrNothing: //It's not fully cached so we have to run it entirely uncached SetTargetServer(DependenciesSingleServer.GetDistinctServer(), "not all dependencies are cached while " + uncached); //cannot use any of the caches because it's all or nothing CountOfCachedSubQueries = 0; sqlDictionary = Dependencies.ToDictionary(k => k, v => v.SqlCacheless.Use(parameterManager)); //run the fully uncached sql break; default: throw new ArgumentOutOfRangeException(); } } return(WriteContainers(container, TargetServer.GetQuerySyntaxHelper(), sqlDictionary, 0)); }
public static ImpersonationContext SetTargetSQLServerImpersonationContext() { ImpersonationContext ic = m_ImpersonationContext; m_ImpersonationContext = ImpersonationContext.TargetSQLServer; if (ic != ImpersonationContext.TargetSQLServer) { using (logX.loggerX.VerboseCall()) { if (ic == ImpersonationContext.TargetComputer) { if (m_targetImpersionationContext != null) { logX.loggerX.Verbose(string.Format("Leaving Target Computer Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); m_targetImpersionationContext.Undo(); m_targetImpersionationContext.Dispose(); m_targetImpersionationContext = null; } else { if (TargetServer != null) { logX.loggerX.Verbose(string.Format("Leaving Target Computer Bind Context: {0}", m_targetUserName)); TargetServer.Unbind(); } } } else if (ic == ImpersonationContext.Local) { logX.loggerX.Verbose(string.Format("Leaving Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); //if (m_LocalImpersionationContext != null) //{ // m_LocalImpersionationContext.Undo(); // m_LocalImpersionationContext.Dispose(); // m_LocalImpersionationContext = null; //} } if (m_targetSQLServerIdentity != null) { m_targetSQLServerImpersionationContext = m_targetSQLServerIdentity.Impersonate(); logX.loggerX.Verbose(string.Format("Entering Target SQL Server Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); } else { if (m_UserSQLAuthentication) { logX.loggerX.Verbose("Using SQL Server Credentials"); } else { logX.loggerX.Verbose("Failed to Enter Target SQL Server Impersonation Context"); logX.loggerX.Verbose(string.Format("Using Local User Context for Target SQL Server: {0}", WindowsIdentity.GetCurrent().Name)); } } } } return(ic); }
public async Task <TeamProject> GetTargetProjectAsync(CancellationToken cancellationToken) { if (_target == null && TargetServer != null && !String.IsNullOrEmpty(TargetProjectName)) { _target = await TargetServer.FindProjectAsync(TargetProjectName, cancellationToken).ConfigureAwait(false); } return(_target); }
/// <summary> /// Constructs the bot runner using a custom configuration file. Note that the /// bot runner is not automatically executed. Call 'Start()' to run the bot /// runner. /// </summary> /// <param name="configurationFile">Configuration file to read.</param> public BotRunner(string configurationFile) { ConfigFile = configurationFile; // TODO: Replace with config. EchelonAddress = new TargetServer("glacier2a.cis.vtc.edu", 4063); bots = new List <VTankBot>(); threads = new List <BotPackage>(); }
/// <summary> /// Constructs a VTankBot. /// </summary> /// <param name="runner">Parent bot runner.</param> /// <param name="server">Target Echelon server.</param> /// <param name="auth">Authentication information.</param> public VTankBot(BotRunner runner, TargetServer server, AuthInfo auth) { BotRunner = runner; ServerAddress = server; AuthInfo = auth; Game = new GameTracker(this); buffer = new EventBuffer(); CreateMasterCommunicator(); }
public override string ToString() { StringBuilder sb = new StringBuilder(10); sb.AppendLine(string.Format("RestoreBackupsFromPath:{0}", RestoreBackupsFromPath)); sb.AppendLine(string.Format("DatabaseToRestore:{0}", DatabasesToRestore.ToString())); sb.AppendLine(string.Format("TargetServer:{0}", TargetServer.ToString())); sb.AppendLine(string.Format("PostRestore:{0}", PostRestore.ToString())); return(sb.ToString()); }
protected override async void OnInitialized() { var navigationService = Container.Resolve <INavigationService>(); await navigationService.NavigateAsync("MainPage"); var reloadManager = Container.Resolve <IReloadManager>(); var targetServer = new TargetServer(new TargetConfiguration { ListenPort = 50124 }); await targetServer.Run(reloadManager); }
public static ImpersonationContext SetLocalImpersonationContext() { ImpersonationContext ic = m_ImpersonationContext; m_ImpersonationContext = ImpersonationContext.Local; if (ic != ImpersonationContext.Local) { using (logX.loggerX.VerboseCall()) { if (ic == ImpersonationContext.TargetComputer) { if (m_targetImpersionationContext != null) { logX.loggerX.Verbose(string.Format("Leaving Target Computer Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); m_targetImpersionationContext.Undo(); m_targetImpersionationContext.Dispose(); m_targetImpersionationContext = null; } else { logX.loggerX.Verbose(string.Format("Leaving Target Computer Bind Context: {0}", m_targetUserName)); if (TargetServer != null) { TargetServer.Unbind(); } } } else if (ic == ImpersonationContext.TargetSQLServer) { if (m_targetSQLServerImpersionationContext != null) { logX.loggerX.Verbose(string.Format("Leaving Target SQL Server Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); m_targetSQLServerImpersionationContext.Undo(); m_targetSQLServerImpersionationContext.Dispose(); m_targetSQLServerImpersionationContext = null; } } //if (m_LocalIdentity != null) //{ // m_LocalImpersionationContext = m_LocalIdentity.Impersonate(); // logX.loggerX.Verbose(string.Format("Entering Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); //} logX.loggerX.Verbose(string.Format("Entering Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); } } return(ic); }
public MigrationContext() { _sourceProject = new Lazy <TeamProject>(() => SourceServer?.FindProjectAsync(SourceProjectName, CancellationToken.None).Result); _targetProject = new Lazy <TeamProject>(() => TargetServer?.FindProjectAsync(TargetProjectName, CancellationToken.None).Result); }
static void Main(string[] args) { //for manual run (for developers) /*args = new string[4]; * args[0] = "-TargetInstance"; * args[1] = "SS_SQL_SECURE\\MSSQLSERVER2012"; * args[2] = "-Repository"; * args[3] = "SS_SQL_SECURE\\MSSQLSERVER2014";*/ string targetName = string.Empty; bool isOK = true; bool needToWriteFailedSnapshot = false; System.Diagnostics.Stopwatch swTotal = new System.Diagnostics.Stopwatch(); swTotal.Start(); try { // Initialize the data loader utility. string argsString = Utility.ProgramArgs.ArgsToString(args); // Parse the command line arguments. Utility.ProgramArgs programArgs = new Utility.ProgramArgs(args); if (string.IsNullOrEmpty(programArgs.EncryptedPassword)) { startup(programArgs, argsString); using (logX.m_logX.DebugCall()) { if (programArgs.Valid) { targetName = programArgs.TargetInstance; // Initialize and validate the repository. m_Repository = new Repository(programArgs.Repository, programArgs.RepositoryUser, programArgs.RepositoryPassword); if (m_Repository.IsValid) { // Check license. if (m_Repository.IsLicenseOk()) { Sql.Database.CreateApplicationActivityEventInRepository( m_Repository.ConnectionString, programArgs.TargetInstance, 0, Collector.Constants. ActivityType_Info, Collector.Constants. ActivityEvent_Start, "Starting snapshot collection for " + programArgs.TargetInstance); // Check if the target instance is registered in the Repository. if (m_Repository.IsTargetRegistered(programArgs.TargetInstance)) { // Retrieve target instance credentials from the repository. string server, sqlLogin, sqlPassword, sqlAuthTypeString, serverLogin, serverPassword, serverTypeString; int? port; ServerType serverType = ServerType.OnPremise; AuthType authType = AuthType.Null; if (m_Repository.GetTargetCredentials(programArgs.TargetInstance, out server, out port, out sqlLogin, out sqlPassword, out sqlAuthTypeString, out serverLogin, out serverPassword, out serverTypeString)) { serverType = Helper.ConvertSQLTypeStringToEnum(serverTypeString); authType = (AuthType)Enum.Parse(typeof(AuthType), sqlAuthTypeString); m_targetUserName = serverLogin; m_targetUserPassword = serverPassword; // SQLSecure 3.1 (Biresh Kumar Mishra) - Add Support for Azure VM if (serverType == ServerType.SQLServerOnAzureVM) { m_SQLServerOnAzureVM_FullName = server; if (server.IndexOf(".") != -1) { m_SQLServerOnAzureVM_DomainName = server.Substring(server.IndexOf(".") + 1); server = server.Substring(0, server.IndexOf(".")); } } if (string.IsNullOrEmpty(serverLogin)) { // Only issue warning for this case Sql.Database.CreateApplicationActivityEventInRepository(m_Repository.ConnectionString, targetName, 0, Collector.Constants.ActivityType_Warning, Collector.Constants.ActivityEvent_Start, string.Format("No credentials specified for Operating System and Active Directory, using SQLsecure Collector user {0}", WindowsIdentity.GetCurrent().Name)); } if (string.IsNullOrEmpty(sqlLogin)) { throw new Exception("No credentials specified for collecting SQL Server security."); } if (serverType == ServerType.OnPremise) { GetIdentitiesForImpersonation(sqlLogin, sqlPassword, authType, serverLogin, serverPassword); } else if (serverType == ServerType.AzureSQLDatabase && authType == AuthType.W) { //AuthenticationResult authenticationResult= AzureDatabase.GetConnectionToken(serverLogin, serverPassword); } //SQLsecure 3.1 (Tushar)--Support for Azure VM. else if (serverType == ServerType.SQLServerOnAzureVM) { GetIdentitiesForImpersonation(sqlLogin, sqlPassword, authType, serverLogin, serverPassword); } } Program.ImpersonationContext wi; // Initialize and validate the target. System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); if (serverType == ServerType.OnPremise) { wi = SetTargetSQLServerImpersonationContext(); m_Target = new Target(programArgs.TargetInstance, m_Repository); RestoreImpersonationContext(wi); } else if (serverType == ServerType.AzureSQLDatabase) { m_Target = new Target(programArgs.TargetInstance, m_Repository); } //SQLsecure 3.1 (Tushar)--Support for Azure VM. else if (serverType == ServerType.SQLServerOnAzureVM) { wi = SetTargetSQLServerImpersonationContext(); m_Target = new Target(programArgs.TargetInstance, m_Repository); RestoreImpersonationContext(wi); } sw.Stop(); logX.loggerX.Verbose("TIMING - Time to initialize and validate target = " + sw.ElapsedMilliseconds.ToString() + " msec"); if (m_Target.IsValid) { if (serverType == ServerType.OnPremise) { wi = SetTargetImpersonationContext(); // Load the permissions data. m_Target.LoadData(programArgs.AutomatedRun); RestoreImpersonationContext(wi); } else if (serverType == ServerType.AzureSQLDatabase) { //SQLsecure 3.1 (Tushar)--Passing the server name becasue we are not creating server object for azure DB. m_Target.LoadDataAzureDB(programArgs.AutomatedRun, server); } //SQLsecure 3.1 (Tushar)--Support for Azure VM. else if (serverType == ServerType.SQLServerOnAzureVM) { wi = SetTargetImpersonationContext(); m_Target.LoadDataForAzureVM(programArgs.AutomatedRun); RestoreImpersonationContext(wi); } } else { needToWriteFailedSnapshot = true; logX.loggerX.Error("ERROR - target instance is not valid"); Sql.Database.CreateApplicationActivityEventInRepository( m_Repository.ConnectionString, programArgs.TargetInstance, 0, Constants.ActivityType_Error, Constants.ActivityEvent_Error, "Target " + programArgs.TargetInstance + " could not be found"); AppLog.WriteAppEventError(SQLsecureEvent.DlErrOpenTargetConnectionFailed, SQLsecureCat.DlValidationCat, "Target " + programArgs.TargetInstance + " could not be found"); isOK = false; } } else { needToWriteFailedSnapshot = true; logX.loggerX.Error("ERROR - target instance is not registered"); Sql.Database.CreateApplicationActivityEventInRepository( m_Repository.ConnectionString, programArgs.TargetInstance, 0, Collector.Constants.ActivityType_Error, Collector.Constants.ActivityEvent_Error, "Target " + programArgs.TargetInstance + " is not registered"); AppLog.WriteAppEventError(SQLsecureEvent.DlErrTargetNotRegistered, SQLsecureCat.DlValidationCat, "Target " + programArgs.TargetInstance + " is not registered"); isOK = false; } if (needToWriteFailedSnapshot) { int snapshotID = m_Repository.CreateErrorSnapshot(programArgs.TargetInstance); if (snapshotID != 0) { Sql.Database.UpdateRepositoryRegisteredServerTable( m_Repository.ConnectionString, snapshotID, Constants.StatusError); } } } else { logX.loggerX.Error("ERROR - license check failed."); Sql.Database.CreateApplicationActivityEventInRepository( m_Repository.ConnectionString, programArgs.TargetInstance, 0, Collector.Constants. ActivityType_Error, Collector.Constants. ActivityEvent_Error, "The SQLsecure Collector was unable to aquire a valid license"); AppLog.WriteAppEventInfo(SQLsecureEvent.DlErrNoLicense, SQLsecureCat.DlValidationCat); isOK = false; } } else { logX.loggerX.Error("ERROR - SQLsecure Repository is invalid."); isOK = false; } } else // Invalid args display usage { if (logX == null) { logX = new LogX("Idera.SQLsecure.Collector.Program"); } logX.loggerX.Error("ERROR: Failed to parse the arguments"); Console.WriteLine(Constants.CopyrightMsg); Console.WriteLine(Constants.UsageMsg); isOK = false; } } } else //handle output of the encrypted password { Console.WriteLine(string.Format("Encrypted Password: {0}", programArgs.EncryptedPassword)); } } catch (Exception ex) { string msg = "Collection Error: " + ex.Message; if (m_Repository != null && m_Repository.IsValid) { Sql.Database.CreateApplicationActivityEventInRepository(m_Repository.ConnectionString, targetName, 0, Collector.Constants.ActivityType_Error, Collector.Constants.ActivityEvent_Error, msg); } AppLog.WriteAppEventError(SQLsecureEvent.DlErrOpenTargetConnectionFailed, SQLsecureCat.DlValidationCat, "Target " + targetName + " " + ex.Message); if (logX == null) { logX = new LogX("Idera.SQLsecure.Collector.Program"); } logX.loggerX.Error(msg); } finally { // Undo the impersonation if (m_targetImpersionationContext != null) { m_targetImpersionationContext.Undo(); m_targetImpersionationContext.Dispose(); } if (m_targetSQLServerImpersionationContext != null) { m_targetSQLServerImpersionationContext.Undo(); m_targetSQLServerImpersionationContext.Dispose(); } if (TargetServer != null) { TargetServer.RealUnbind(); } } swTotal.Stop(); logX.loggerX.Verbose("TIMING - Total Time for Collector = " + swTotal.ElapsedMilliseconds.ToString() + " msec"); // Exiting utility, do shutdown processing. shutdown(); Environment.ExitCode = isOK ? 0 : 1; }
public static void RestoreImpersonationContext(ImpersonationContext ic) { using (logX.loggerX.VerboseCall()) { // Reset old if different than new // ------------------------------- if (m_ImpersonationContext == ImpersonationContext.TargetComputer && ic != ImpersonationContext.TargetComputer) { if (m_targetImpersionationContext != null) { logX.loggerX.Verbose( string.Format("Leaving Target Computer Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); m_targetImpersionationContext.Undo(); m_targetImpersionationContext.Dispose(); m_targetImpersionationContext = null; } else { if (TargetServer != null) { logX.loggerX.Verbose(string.Format("Leaving Target Computer Bind Context: {0}", m_targetUserName)); TargetServer.Unbind(); } } } else if (m_ImpersonationContext == ImpersonationContext.TargetSQLServer && ic != ImpersonationContext.TargetSQLServer) { if (m_targetSQLServerImpersionationContext != null) { logX.loggerX.Verbose( string.Format("Leaving Target SQL Server Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); m_targetSQLServerImpersionationContext.Undo(); m_targetSQLServerImpersionationContext.Dispose(); m_targetSQLServerImpersionationContext = null; } } else if (m_ImpersonationContext == ImpersonationContext.Local && ic != ImpersonationContext.Local) { logX.loggerX.Verbose( string.Format("Leaving Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); //if (m_LocalImpersionationContext != null) //{ // m_LocalImpersionationContext.Undo(); // m_LocalImpersionationContext.Dispose(); // m_LocalImpersionationContext = null; //} } // Set new if different than old // ----------------------------- if (ic == ImpersonationContext.TargetComputer && m_ImpersonationContext != ImpersonationContext.TargetComputer) { if (m_targetIdentity != null) { m_targetImpersionationContext = m_targetIdentity.Impersonate(); logX.loggerX.Verbose( string.Format("Entering Target Computer Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); } else { if (TargetServer != null) { TargetServer.Bind(); logX.loggerX.Verbose(string.Format("Entering Target Computer Bind Context: {0}", m_targetUserName)); } } } else if (ic == ImpersonationContext.TargetSQLServer && m_ImpersonationContext != ImpersonationContext.TargetSQLServer) { if (m_targetSQLServerIdentity != null) { m_targetSQLServerImpersionationContext = m_targetSQLServerIdentity.Impersonate(); logX.loggerX.Verbose( string.Format("Entering Target SQL Server Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); } else { if (m_UserSQLAuthentication) { logX.loggerX.Verbose("Using SQL Server Credentials"); } else { logX.loggerX.Verbose("Failed to Enter Target SQL Server Impersonation Context"); logX.loggerX.Verbose(string.Format("Using Local User Context for Target SQL Server: {0}", WindowsIdentity.GetCurrent().Name)); } } } else if (ic == ImpersonationContext.Local && m_ImpersonationContext != ImpersonationContext.Local) { logX.loggerX.Verbose( string.Format("Entering Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); //if (m_LocalIdentity != null) //{ // m_LocalImpersionationContext = m_LocalIdentity.Impersonate(); // logX.loggerX.Verbose( // string.Format("Entering Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name)); //} } m_ImpersonationContext = ic; } }