public static void ValidateDatabase(string database) { Regex regex = new Regex(@"^[a-zA-Z]([a-zA-Z]|[0-9]|[!@#\$%\^&'\)\(\.\-_\{\}~\.]){0,62}$"); if (!regex.Match(database).Success) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.DatabaseInvalid, new object[] { database }), "Database", System.Diagnostics.TraceLevel.Error); } }
public static void ValidateEncryptionKey(NameValueCollection nameValueArgs) { if (nameValueArgs["CompanyName"] != null) { nameValueArgs.Set("CompanyName", nameValueArgs["CompanyName"].Trim()); } if ((nameValueArgs["CompanyName"] == null) || (nameValueArgs["CompanyName"].Length == 0)) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.CompanyNameNotSpecified, new object[] { }), "CompanyName", System.Diagnostics.TraceLevel.Error); } }
public static void ValidateServer(string server) { IPAddress address; if (!IPAddress.TryParse(server, out address)) { Regex regex = new Regex(@"^((np|tcp|spx|adsp|rpc|vines):)?([a-zA-Z]|[0-9]|[!@#\$%\^&'\)\(\.\-_\{\}~\.\\]){0,256}((,[0-9]{1,5})|(,(ncacn_np|ncacn_ip_tcp|ncacn_nb_nb|ncacn_spx|ncacn_vns_spp|ncadg_ip_udp|ncadg_ipx|ncalrpc)))?(\\([a-zA-Z]|[0-9]|[!@#\$%\^&'\)\(\.\-_\{\}~\.\\]){0,256})?$"); if (!regex.Match(server).Success) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.ServerInvalid, new object[] { server }), "Server", System.Diagnostics.TraceLevel.Error); } } }
public static void ValidateTimeout(NameValueCollection nameValueArgs) { int timeout; if (nameValueArgs["Timeout"] != null) { nameValueArgs.Set("Timeout", nameValueArgs["Timeout"].Trim()); } if ((nameValueArgs["Timeout"] != null) && (!int.TryParse(nameValueArgs["Timeout"], out timeout))) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.TimeoutInvalid, new object[] { }), "Timeout", System.Diagnostics.TraceLevel.Error); } }
public static void ValidateEncryptedFile(NameValueCollection nameValueArgs) { if ((nameValueArgs["NonEncryptedFile"] != null) && (nameValueArgs["NonEncryptedFile"].Length > 0)) { System.IO.FileInfo fi = new System.IO.FileInfo(nameValueArgs["NonEncryptedFile"]); if (!fi.Exists) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.NonEncryptedFileNotFound, new object[] { fi.FullName }), "NonEncryptedFile", System.Diagnostics.TraceLevel.Error); } } else { throw new CommandLineArgumentException(CommandResources.GetString(CommandResources.ResourceID.NonEncryptedFileNotSpecified), "NonEncryptedFile", System.Diagnostics.TraceLevel.Error); } }
public override void Execute() { try { string[] values = base.Args.GetValues((string)null); if ((values != null) && (values.Length > 0)) { string str = values[0]; throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.UnknownCommand, new object[] { str }), null, TraceLevel.Error); } this.WriteUsage(); base.commandResult = new CommandResult(); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); base.WriteLogEntry(LogEntryType.Error, exception.Message); base.commandResult = new CommandResult(exception); if ((exception is OutOfMemoryException) || (exception is StackOverflowException)) { throw; } } }
public override void WriteUsageHint() { Console.WriteLine(CommandResources.GetFormattedString(CommandResources.ResourceID.ProgramUsageHint, new object[] { this.Name })); }
public override void Execute() { try { this.Validate(); string key = base.Args["CompanyName"]; string file = base.Args["NonEncryptedFile"]; string timeout = base.Args["Timeout"]; string formattedString = CommandResources.GetFormattedString(CommandResources.ResourceID.Deploy, new object[] { key, file }); base.WriteLogEntry(LogEntryType.Information, formattedString); // We need to show the identity used to deploy to SSO System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (null != identity) { WriteLogEntry(LogEntryType.Verbose, string.Format("Current WindowsIdentity: AuthenticationType:{0} - IsAuthenticated:{1} - Name:{2}", identity.AuthenticationType, identity.IsAuthenticated, identity.Name)); using (System.Security.Principal.WindowsImpersonationContext context = identity.Impersonate()) { identity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (null != identity) { WriteLogEntry(LogEntryType.Verbose, string.Format("Impersonated WindowsIdentity: AuthenticationType:{0} - IsAuthenticated:{1} - Name:{2}", identity.AuthenticationType, identity.IsAuthenticated, identity.Name)); } // Deploy the non encrypted SSO XML file. //System.Diagnostics.Debugger.Launch(); string title; DeploySSO deploy = new DeploySSO() { NonEncryptedFile = file, CompanyName = key }; deploy.Overwrite = true; // We always overwrite the current SSO application settings deploy.Log += new DeploySSO.LogHandler(deploy_Log); deploy.Execute(out title); formattedString = CommandResources.GetFormattedString(CommandResources.ResourceID.DeploySuccess, new object[] { title }); base.WriteLogEntry(LogEntryType.Information, formattedString); } } identity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (null != identity) { WriteLogEntry(LogEntryType.Verbose, string.Format("After impersonation WindowsIdentity: AuthenticationType:{0} - IsAuthenticated:{1} - Name:{2}", identity.AuthenticationType, identity.IsAuthenticated, identity.Name)); } base.commandResult = new CommandResult(); } catch (Exception exception2) { base.ShowError(exception2); base.commandResult = new CommandResult(exception2); if ((exception2 is OutOfMemoryException) || (exception2 is StackOverflowException)) { throw; } } }