public void CancelCommand() { PowwaEvents.PowwaEVENT_DEBUG_LOG0("CancelCommand(): Enter"); try { lock (this.cancelCommandLock) { lock (this.sessionStateLock) { PowwaSession.SessionState state = this.State; switch (state) { case PowwaSession.SessionState.Available: case PowwaSession.SessionState.CancellingCommand: { return; } case PowwaSession.SessionState.ExecutingCommand: { this.State = PowwaSession.SessionState.CancellingCommand; this.executingCommandPowerShell.BeginStop(null, null); this.messageQueue.CommandCancelled(); return; } } throw new InvalidOperationException(); } } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("CancelCommand(): Exit"); } }
public ClientMessage[] SetPromptForCredentialReply(string userName, char[] password) { ClientMessage[] clientMessages; PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptForCredentialReply(): Enter"); try { lock (this.clientRequestLock) { lock (this.sessionStateLock) { PromptForCredentialMessage promptForCredentialMessage = this.ValidateSessionStateForMessageReply <PromptForCredentialMessage>(); if (promptForCredentialMessage.DomainCredentials) { StringBuilder stringBuilder = new StringBuilder(0x202); StringBuilder stringBuilder1 = new StringBuilder(0x152); uint num = PowwaSession.CredUIParseUserName(userName, stringBuilder, stringBuilder.Capacity, stringBuilder1, stringBuilder1.Capacity); if (num != 0) { PowwaEvents.PowwaEVENT_DEBUG_LOG2("SetPromptForCredentialReply(): Invalid UserName", "userName", userName, "errorCode", num.ToString(CultureInfo.InvariantCulture)); throw PowwaException.CreateValidationErrorException(Resources.InvalidUserNameInDomainCredentials); } } PSCredential pSCredential = new PSCredential(userName, PowwaSession.ToSecureString(password)); this.messageQueue.SetInputMessageReply(pSCredential); } clientMessages = this.GetClientMessages(); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptForCredentialReply(): Exit"); } return(clientMessages); }
public PowwaSession CreateSession(string sessionId, RunspaceConnectionInfo connectionInfo, ClientInfo clientInfo, string authenticatedUserName) { bool flag = false; PowwaSession powwaSession; PowwaSession stringSid = new PowwaSession(sessionId, authenticatedUserName, connectionInfo, clientInfo); string str = null; stringSid.AuthenticatedUserSid = PowwaAuthorizationManager.Instance.activeDirectoryHelper.ConvertAccountNameToStringSid(authenticatedUserName, out flag, out str); lock (this.sessionsLock) { bool userActiveSessions = this.GetUserActiveSessions(stringSid.AuthenticatedUserSid) < PowwaAuthorizationManager.Instance.UserSessionsLimit; if (userActiveSessions) { stringSid.Name = this.GetSessionName(stringSid); try { this.sessions.Add(sessionId, stringSid); } catch (ArgumentException argumentException) { PowwaEvents.PowwaEVENT_DEBUG_LOG0("CreateSession: Attempt to create a session that already exists"); throw new ArgumentException("There is already a PowWA session with the given ID", "sessionId"); } powwaSession = stringSid; } else { object[] objArray = new object[1]; objArray[0] = authenticatedUserName; throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.UserActiveSessionLimitReached, objArray)); } } return(powwaSession); }
public ClientMessage[] SetPromptForChoiceReply(int reply) { ClientMessage[] clientMessages; PowwaEvents.PowwaEVENT_DEBUG_LOG1("SetPromptForChoiceReply(): Enter", "reply", reply.ToString(CultureInfo.InvariantCulture)); try { lock (this.clientRequestLock) { lock (this.sessionStateLock) { PromptForChoiceMessage promptForChoiceMessage = this.ValidateSessionStateForMessageReply <PromptForChoiceMessage>(); if (reply < 0 || reply >= promptForChoiceMessage.Choices.Count) { int count = promptForChoiceMessage.Choices.Count; PowwaEvents.PowwaEVENT_DEBUG_LOG2("SetPromptForChoiceReply(): Choice not within the valid range", "reply", reply.ToString(CultureInfo.InvariantCulture), "message.Choices.Count", count.ToString(CultureInfo.InvariantCulture)); throw new ArgumentException("The choice is not within the valid range", "reply"); } else { this.messageQueue.SetInputMessageReply(reply); } } clientMessages = this.GetClientMessages(); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptForChoiceReply(): Exit"); } return(clientMessages); }
private void Application_Start(object sender, EventArgs e) { ScriptingJsonSerializationSection section; string item = ConfigurationManager.AppSettings["maxSessionsAllowedPerUser"]; if (item != null) { int num = 0; if (!int.TryParse(item, NumberStyles.Integer, CultureInfo.InvariantCulture, out num)) { PowwaEvents.PowwaEVENT_INVALID_APPLICATION_SETTING("maxSessionsAllowedPerUser", item); } else { PowwaAuthorizationManager.Instance.UserSessionsLimit = num; } } try { Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/"); section = (ScriptingJsonSerializationSection)configuration.GetSection("system.web.extensions/scripting/webServices/jsonSerialization"); } catch { section = new ScriptingJsonSerializationSection(); } PowwaSessionManager.Instance.JsonSerializer.MaxJsonLength = section.MaxJsonLength; }
protected void OnLogOnButtonClick(object sender, EventArgs e) { string str = null; string str1 = null; IEtwActivity etwActivity = PowwaEvents.EventCorrelator.StartActivity(); using (etwActivity) { try { LogOn.FormInfo formInfo = this.ValidateForm(); using (formInfo) { this.CreateSession(formInfo); } } catch (PowwaValidationException powwaValidationException1) { PowwaValidationException powwaValidationException = powwaValidationException1; this.ShowError(powwaValidationException.Message); } catch (Exception exception1) { Exception exception = exception1; LogOn.GetLogonErrorMessage(exception, out str, out str1); this.ShowError(str); object[] objArray = new object[1]; objArray[0] = str1; PowwaEvents.PowwaEVENT_LOGON_FAILURE(this.userNameTextBox.Value, SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor(), string.Format(CultureInfo.CurrentCulture, Resources.LogonError_LogMessage, objArray)); Thread.Sleep(0x3e8); } } }
private void Application_Error(object sender, EventArgs e) { HttpRequestValidationException lastError = base.Server.GetLastError() as HttpRequestValidationException; if (lastError != null) { PowwaEvents.PowwaEVENT_MALICIOUS_DATA(SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor(), lastError.Message); } }
public PowwaSessionStatusInfo GetSessionStatus() { PowwaSessionStatusInfo powwaSessionStatusInfo; PowwaEvents.PowwaEVENT_DEBUG_LOG0("GetSessionStatus(): Enter"); try { lock (this.clientRequestLock) { lock (this.sessionStateLock) { PowwaSession.SessionState state = this.State; switch (state) { case PowwaSession.SessionState.Available: { powwaSessionStatusInfo = new PowwaSessionStatusInfo(PowwaSessionStatus.Available, null); return(powwaSessionStatusInfo); } case PowwaSession.SessionState.ExecutingCommand: { if (!this.messageQueue.WaitingForUserReply) { powwaSessionStatusInfo = new PowwaSessionStatusInfo(PowwaSessionStatus.Executing, null); return(powwaSessionStatusInfo); } else { powwaSessionStatusInfo = new PowwaSessionStatusInfo(PowwaSessionStatus.Prompting, this.messageQueue.PendingInputMessage); return(powwaSessionStatusInfo); } } case PowwaSession.SessionState.CancellingCommand: { powwaSessionStatusInfo = new PowwaSessionStatusInfo(PowwaSessionStatus.Cancelling, null); return(powwaSessionStatusInfo); } case PowwaSession.SessionState.Closed: { powwaSessionStatusInfo = new PowwaSessionStatusInfo(PowwaSessionStatus.Closed, null); return(powwaSessionStatusInfo); } } throw new InvalidOperationException(); } } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("GetSessionStatus(): Exit"); } return(powwaSessionStatusInfo); }
private void OnRunspaceStateChanged(object sender, RunspaceStateEventArgs e) { lock (this.sessionStateLock) { if (e.RunspaceStateInfo.State == RunspaceState.Broken) { PowwaEvents.PowwaEVENT_PSREXECUTION_FAILURE(this.Name, e.RunspaceStateInfo.Reason.Message); this.PostClientMessage(new SessionTerminatedMessage(), false); } } }
public string[] GetTabCompletion(string commandLine) { string[] strArrays; if (commandLine != null) { lock (this.clientRequestLock) { if (this.State == PowwaSession.SessionState.Available) { this.State = PowwaSession.SessionState.ExecutingCommand; System.Management.Automation.PowerShell powerShell = null; try { try { powerShell = System.Management.Automation.PowerShell.Create(); powerShell.Runspace = this.Runspace; CommandCompletion commandCompletion = CommandCompletion.CompleteInput(commandLine, commandLine.Length, null, powerShell); string str = commandLine.Substring(0, commandCompletion.ReplacementIndex); string[] strArrays1 = new string[commandCompletion.CompletionMatches.Count]; for (int i = 0; i < commandCompletion.CompletionMatches.Count; i++) { strArrays1[i] = string.Concat(str, commandCompletion.CompletionMatches[i].CompletionText); } strArrays = strArrays1; } catch { strArrays = new string[0]; } } finally { if (powerShell != null) { powerShell.Dispose(); } this.State = PowwaSession.SessionState.Available; } } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("GetTabCompletion(): Invalid Session State", "SessionState", this.State.ToString()); throw new InvalidOperationException("The session is not available"); } } return(strArrays); } else { throw new ArgumentNullException("commandLine"); } }
public override void SetShouldExit(int exitCode) { PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetShouldExit(): Enter"); try { this.OnMessageCreated(new MessageCreatedEventArgs(new ExitMessage(exitCode), false)); } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetShouldExit(): Exit"); } }
private void Session_End(object sender, EventArgs e) { try { SessionHelper.TerminateSession(base.Session.SessionID, false, Resources.EventLog_ASPNET_SessionTimeout); } catch (Exception exception1) { Exception exception = exception1; PowwaEvents.PowwaEVENT_TERMINATE_SESSION_ERROR(SessionHelper.GetAuthenticatedUser(), exception.Message); } }
public ClientMessage[] GetClientMessages() { ClientMessage[] messages; lock (this.clientRequestLock) { bool flag = false; lock (this.sessionStateLock) { PowwaSession.SessionState state = this.State; switch (state) { case PowwaSession.SessionState.Available: { break; } case PowwaSession.SessionState.ExecutingCommand: case PowwaSession.SessionState.CancellingCommand: { flag = true; break; } case PowwaSession.SessionState.Closed: { throw PowwaException.CreateInvalidSessionException(); } default: { break; } } } if (flag) { this.messageQueue.WaitForMessages(); } lock (this.sessionStateLock) { if (this.State != PowwaSession.SessionState.Closed) { messages = this.messageQueue.GetMessages(); } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("GetClientMessages() Invalid Session State", "SessionState", this.State.ToString()); throw PowwaException.CreateInvalidSessionException(); } } } return(messages); }
public static PowwaReturnValue <object> ResetSessionTimeout(string sessionKey) { PowwaReturnValue <object> powwaReturnValue; IEtwActivity etwActivity = PowwaEvents.EventCorrelator.StartActivity(); using (etwActivity) { PowwaEvents.PowwaEVENT_DEBUG_LOG0("ResetSessionTimeout"); string str = sessionKey; powwaReturnValue = Console.HttpEndpointWrapper <object>(str, (PowwaSession session) => null); } return(powwaReturnValue); }
public ClientConfiguration GetClientConfiguration() { ClientConfiguration clientConfiguration; string computerName; PowwaEvents.PowwaEVENT_DEBUG_LOG0("GetClientConfiguration(): Enter"); try { lock (this.clientRequestLock) { if (this.State == PowwaSession.SessionState.Available) { ClientConfiguration bufferSize = new ClientConfiguration(); bufferSize.BufferSize = this.host.UI.RawUI.BufferSize; bufferSize.WindowSize = this.host.UI.RawUI.WindowSize; bufferSize.ForegroundColor = HtmlHelper.ToHtmlColor(this.host.UI.RawUI.ForegroundColor); bufferSize.BackgroundColor = HtmlHelper.ToHtmlColor(this.host.UI.RawUI.BackgroundColor); bufferSize.WindowTitle = this.host.UI.RawUI.WindowTitle; bufferSize.Prompt = this.GetPowerShellPrompt(); ClientConfiguration clientConfiguration1 = bufferSize; if (this.Runspace.ConnectionInfo != null) { computerName = this.Runspace.ConnectionInfo.ComputerName; } else { computerName = string.Empty; } clientConfiguration1.ComputerName = computerName; bufferSize.InputForegroundColor = HtmlHelper.ToHtmlColor(ConsoleColor.Yellow); bufferSize.InputBackgroundColor = HtmlHelper.ToHtmlColor(ConsoleColor.DarkBlue); bufferSize.ErrorForegroundColor = HtmlHelper.ToHtmlColor(ConsoleColor.Red); bufferSize.ErrorBackgroundColor = HtmlHelper.ToHtmlColor(ConsoleColor.Black); bufferSize.WarningForegroundColor = HtmlHelper.ToHtmlColor(ConsoleColor.Yellow); bufferSize.WarningBackgroundColor = HtmlHelper.ToHtmlColor(ConsoleColor.Black); bufferSize.StartupMessages = this.GetClientMessages(); clientConfiguration = bufferSize; } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("GetClientConfiguration(): Invalid Session State", "SessionState", this.State.ToString()); throw new InvalidOperationException("The session is not available"); } } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("GetClientConfiguration(): Exit"); } return(clientConfiguration); }
private static PowwaReturnValue <T> HttpEndpointWrapper <T>(string sessionKey, Func <PowwaSession, T> function) { PowwaReturnValue <T> powwaReturnValue; PowwaSession session = null; try { try { session = PowwaSessionManager.Instance.GetSession(SessionHelper.GetSessionId()); } catch (ArgumentException argumentException) { powwaReturnValue = PowwaReturnValue <T> .CreateError(PowwaException.CreateInvalidSessionException()); return(powwaReturnValue); } if (string.Compare(sessionKey, session.SessionKey, StringComparison.OrdinalIgnoreCase) == 0) { if (string.Compare(SessionHelper.GetAuthenticatedUser(), session.UserName, StringComparison.OrdinalIgnoreCase) == 0) { powwaReturnValue = PowwaReturnValue <T> .CreateSuccess(function(session)); } else { PowwaEvents.PowwaEVENT_INVALID_SESSION_USER(session.Name, SessionHelper.GetAuthenticatedUser(), session.UserName, SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor()); powwaReturnValue = PowwaReturnValue <T> .CreateError(PowwaException.CreateInvalidSessionException()); } } else { PowwaEvents.PowwaEVENT_INVALID_SESSION_KEY(session.Name, SessionHelper.GetAuthenticatedUser(), SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor()); powwaReturnValue = PowwaReturnValue <T> .CreateError(PowwaException.CreateInvalidSessionException()); } } catch (PowwaException powwaException1) { PowwaException powwaException = powwaException1; powwaReturnValue = PowwaReturnValue <T> .CreateError(powwaException); } catch (Exception exception1) { Exception exception = exception1; PowwaEvents.PowwaEVENT_GENERIC_FAILURE(session.Name, exception.Message); powwaReturnValue = PowwaReturnValue <T> .CreateGenericError(exception); } return(powwaReturnValue); }
public override int PromptForChoice(string caption, string message, Collection <ChoiceDescription> choices, int defaultChoice) { int reply; PowwaEvents.PowwaEVENT_DEBUG_LOG0("PromptForChoice(): Enter"); try { MessageCreatedEventArgs messageCreatedEventArg = new MessageCreatedEventArgs(new PromptForChoiceMessage(caption, message, choices, defaultChoice), true); this.OnMessageCreated(messageCreatedEventArg); reply = (int)messageCreatedEventArg.Reply; } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("PromptForChoice(): Exit"); } return(reply); }
internal bool AuthenticateUser(string userName, string password) { bool flag; string statusSuccess; PowwaEvents.PowwaEVENT_AUTHENTICATION_START(userName); bool flag1 = false; try { try { bool flag2 = this.AccessCheck(userName, password); flag1 = flag2; flag = flag2; } catch (Exception exception1) { Exception exception = exception1; PowwaEvents.PowwaEVENT_DEBUG_LOG0(exception.Message); bool flag3 = false; flag1 = flag3; flag = flag3; } } finally { string str = userName; if (flag1) { statusSuccess = Resources.Status_Success; } else { statusSuccess = Resources.Status_Failure; } PowwaEvents.PowwaEVENT_AUTHENTICATION_STOP(str, statusSuccess); } return(flag); }
public ClientMessage[] SetReadLineReply(string reply) { ClientMessage[] clientMessages; PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetReadLineReply(): Enter"); try { lock (this.clientRequestLock) { lock (this.sessionStateLock) { this.ValidateSessionStateForMessageReply <ReadLineMessage>(); this.messageQueue.SetInputMessageReply(reply); } clientMessages = this.GetClientMessages(); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetReadLineReply(): Exit"); } return(clientMessages); }
public static void TerminateSession(string sessionId, bool terminateAspNetSession, string reasonForTermination) { IEtwActivity etwActivity = PowwaEvents.EventCorrelator.StartActivity(); using (etwActivity) { try { string str = PowwaSessionManager.Instance.TerminateSession(sessionId); PowwaEvents.PowwaEVENT_SESSION_END(str, reasonForTermination); } catch (ArgumentException argumentException) { } if (terminateAspNetSession) { FormsAuthentication.SignOut(); HttpContext.Current.Session.Abandon(); SessionHelper.RemoveSessionCookie(HttpContext.Current.Response); } } }
private T ValidateSessionStateForMessageReply <T>() where T : ClientMessage { /* this.State != PowwaSession.SessionState.ExecutingCommand || */ /* TODO: The command is reset to Available... */ if (!this.WaitingForUserReply) { PowwaEvents.PowwaEVENT_DEBUG_LOG1("ValidateSessionStateForMessageReply(): Session not waiting for reply", "SessionState", this.State.ToString()); throw new InvalidOperationException("The session is not waiting for a reply"); } else { T pendingInputMessage = (T)(this.messageQueue.PendingInputMessage as T); if (pendingInputMessage != null) { return(pendingInputMessage); } else { throw new InvalidOperationException("Invalid reply type"); } } }
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options) { PSCredential reply; string str; PowwaEvents.PowwaEVENT_DEBUG_LOG0("PromptForCredential(): Enter"); try { if (string.IsNullOrEmpty(targetName)) { bool flag = (allowedCredentialTypes & PSCredentialTypes.Domain) == PSCredentialTypes.Domain; string str1 = "PromptForCredential()"; string str2 = "domainCredentials"; if (flag) { str = "true"; } else { str = "false"; } PowwaEvents.PowwaEVENT_DEBUG_LOG1(str1, str2, str); MessageCreatedEventArgs messageCreatedEventArg = new MessageCreatedEventArgs(new PromptForCredentialMessage(caption, message, userName, flag), true); this.OnMessageCreated(messageCreatedEventArg); reply = (PSCredential)messageCreatedEventArg.Reply; } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("PromptForCredential(): Invalid Argument", "targetName", "null"); throw new NotSupportedException(Resources.PromptForCredentialTargetNameNotSupported); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("PromptForCredential(): Exit"); } return(reply); }
public ClientMessage[] SetPromptReply(object[] reply) { ClientMessage[] clientMessages; PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptReply(): Enter"); try { lock (this.clientRequestLock) { lock (this.sessionStateLock) { PromptMessage promptMessage = this.ValidateSessionStateForMessageReply <PromptMessage>(); if ((int)reply.Length == (int)promptMessage.Descriptions.Length) { Dictionary <string, PSObject> strs = new Dictionary <string, PSObject>(); for (int i = 0; i < (int)reply.Length; i++) { strs.Add(promptMessage.Descriptions[i].Name, PowwaSession.PromptReplyObjectToPsObject(reply[i], promptMessage.Descriptions[i])); } this.messageQueue.SetInputMessageReply(strs); } else { int length = (int)reply.Length; int num = (int)promptMessage.Descriptions.Length; PowwaEvents.PowwaEVENT_DEBUG_LOG2("SetPromptReply(): Number of items in the reply does not match prompt message", "reply.Length", length.ToString(CultureInfo.InvariantCulture), "message.Descriptions.Length", num.ToString(CultureInfo.InvariantCulture)); throw new ArgumentException("The number of items in the reply does not match the prompt message", "reply"); } } clientMessages = this.GetClientMessages(); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptReply(): Exit"); } return(clientMessages); }
internal bool AuthorizeSession(string userName, string computerName, Uri connectionUri, string configuration) { bool flag; object obj; string statusSuccess; PowwaEvents.PowwaEVENT_GATEWAY_AUTHORIZATION_START(userName); bool length = false; PswaAuthorizationRuleManager instance = PswaAuthorizationRuleManager.Instance; instance.TestRuleInvalidRule += new EventHandler <TestRuleInvalidRuleEventArgs>(this.OnInvalidRule); try { ArrayList arrayLists = new ArrayList(); SortedList <int, PswaAuthorizationRule> nums = PswaAuthorizationRuleManager.Instance.LoadFromFile(arrayLists); this.CheckLoadError(arrayLists); if (nums != null) { PswaAuthorizationRule[] array = nums.Values.ToArray <PswaAuthorizationRule>(); this.invalidRules = 0; if (computerName == null) { length = (int)PswaAuthorizationRuleManager.Instance.TestRule(array, userName, connectionUri, configuration, false, MatchingWildcard.None).Length > 0; } else { length = (int)PswaAuthorizationRuleManager.Instance.TestRule(array, userName, computerName, configuration, false, MatchingWildcard.None).Length > 0; } if (length || this.invalidRules <= 0) { flag = length; } else { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string str = "Test-PswaAuthorizationRule -UserName '{0}' -{1} '{2}' -ConfigurationName '{3}'"; object[] objArray = new object[4]; objArray[0] = userName; object[] objArray1 = objArray; int num = 1; if (computerName != null) { obj = "ComputerName"; } else { obj = "ConnectionUri"; } objArray1[num] = obj; objArray[2] = computerName; objArray[3] = configuration; string str1 = string.Format(invariantCulture, str, objArray); PowwaEvents.PowwaEVENT_AUTHORIZATION_FAILURE_INVALID_RULES(str1); throw PowwaException.CreateLogOnFailureException(Resources.GatewayAuthorizationFailureInvalidRules); } } else { bool flag1 = false; length = flag1; flag = flag1; } } finally { PswaAuthorizationRuleManager pswaAuthorizationRuleManager = PswaAuthorizationRuleManager.Instance; pswaAuthorizationRuleManager.TestRuleInvalidRule -= new EventHandler <TestRuleInvalidRuleEventArgs>(this.OnInvalidRule); string str2 = userName; if (length) { statusSuccess = Resources.Status_Success; } else { statusSuccess = Resources.Status_Failure; } PowwaEvents.PowwaEVENT_GATEWAY_AUTHORIZATION_STOP(str2, statusSuccess); } return(flag); }
private void CreateSession(LogOn.FormInfo formInfo) { string str; string applicationName; string str1; string originalString; WSManConnectionInfo wSManConnectionInfo = null; if (formInfo.ConfigurationName.Length == 0) { str = null; } else { str = string.Concat("http://schemas.microsoft.com/powershell/", formInfo.ConfigurationName); } string str2 = str; PSCredential pSCredential = new PSCredential(formInfo.DestinationUserName, formInfo.DestinationPassword); if (!formInfo.IsUriConnection) { if (string.Compare(formInfo.ApplicationName, "WSMAN", StringComparison.OrdinalIgnoreCase) == 0) { applicationName = null; } else { applicationName = formInfo.ApplicationName; } string str3 = applicationName; try { wSManConnectionInfo = new WSManConnectionInfo(formInfo.UseSsl, formInfo.ComputerName, formInfo.Port, str3, str2, pSCredential); } catch (UriFormatException uriFormatException) { throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidComputerNameUriFormat); } wSManConnectionInfo.AuthenticationMechanism = formInfo.AuthenticationType; PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_COMPUTERNAME(formInfo.DestinationUserName, wSManConnectionInfo.ComputerName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri, wSManConnectionInfo.AuthenticationMechanism.ToString()); } else { wSManConnectionInfo = new WSManConnectionInfo(formInfo.ConnectionUri, str2, pSCredential); if (!formInfo.AllowRedirection) { wSManConnectionInfo.MaximumConnectionRedirectionCount = 0; } PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_URI(formInfo.DestinationUserName, wSManConnectionInfo.ConnectionUri.AbsoluteUri, wSManConnectionInfo.ShellUri); } string sourceIPAddressRemoteAddr = SessionHelper.GetSourceIPAddressRemoteAddr(); string sourceIPAddressHttpXForwardedFor = SessionHelper.GetSourceIPAddressHttpXForwardedFor(); if (formInfo.IsUriConnection) { str1 = null; } else { str1 = PswaHelper.TranslateLocalComputerName(formInfo.ComputerName); } string str4 = str1; PowwaAuthorizationManager.Instance.CheckLogOnCredential(formInfo.UserName, formInfo.Password, str4, formInfo.ConnectionUri, formInfo.ConfigurationName, sourceIPAddressRemoteAddr, sourceIPAddressHttpXForwardedFor); ClientInfo clientInfo = new ClientInfo(HttpContext.Current.Request.UserAgent, CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture); PowwaSession powwaSession = PowwaSessionManager.Instance.CreateSession(this.Session.SessionID, wSManConnectionInfo, clientInfo, formInfo.UserName); string name = powwaSession.Name; string userName = formInfo.UserName; string str5 = sourceIPAddressRemoteAddr; string str6 = sourceIPAddressHttpXForwardedFor; if (formInfo.IsUriConnection) { originalString = wSManConnectionInfo.ConnectionUri.OriginalString; } else { originalString = wSManConnectionInfo.ComputerName; } PowwaEvents.PowwaEVENT_SESSION_START(name, userName, str5, str6, originalString, formInfo.DestinationUserName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri); HttpCookie item = base.Request.Cookies["ASP.NET_SessionId"]; if (FormsAuthentication.RequireSSL && item != null) { item.Secure = true; } FormsAuthentication.SetAuthCookie(formInfo.UserName, false, "/"); base.Response.Redirect("~/default.aspx"); //FormsAuthentication.RedirectFromLoginPage(formInfo.UserName, false); }
public ClientMessage[] ExecuteCommand(string command) { ClientMessage[] clientMessages; if (command != null) { lock (this.clientRequestLock) { lock (this.sessionStateLock) { if (this.State == PowwaSession.SessionState.Available) { PSCommand commands = null; try { commands = ScriptBlock.Create(command).GetPowerShell(new object[0]).Commands; } catch (ScriptBlockToPowerShellNotSupportedException scriptBlockToPowerShellNotSupportedException) { } catch (RuntimeException runtimeException) { } if (commands == null) { commands = new PSCommand(); commands.AddScript(command); } commands.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); Command outputCmd = new Command("Out-Default", false, false); commands.AddCommand(outputCmd); this.executingCommandPowerShell.Commands = commands; this.executingCommandPowerShell.HistoryString = command; try { PSInvocationSettings pSInvocationSetting = new PSInvocationSettings(); pSInvocationSetting.AddToHistory = true; /*Exception ex; * this.State = PowwaSession.SessionState.ExecutingCommand; * this.exec.ExecuteCommandAsync(command, out ex, Microsoft.PowerShell.Executor.ExecutionOptions.AddOutputter | Microsoft.PowerShell.Executor.ExecutionOptions.AddToHistory); * if (ex != null) throw ex; */ this.executingCommandPowerShell.BeginInvoke <object>(null, pSInvocationSetting, null, null); } catch (Exception exception1) { Exception exception = exception1; this.WriteException(exception); if (exception as InvalidRunspaceStateException != null) { this.PostClientMessage(new SessionTerminatedMessage(), false); } } } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("ExecuteCommand(): Invalid Session State", "SessionState", this.State.ToString()); throw new InvalidOperationException("The session is not available"); } } clientMessages = this.GetClientMessages(); } return(clientMessages); } else { throw new ArgumentNullException("command"); } }
public void CheckLogOnCredential(string userName, string password, string computerName, Uri connectionUri, string configuration, string sourceIPAddressRemoteAddr, string sourceIPAddressHttpXForwardedFor) { string statusSuccess; string originalString; if (computerName != null ^ connectionUri != null) { if (this.AuthenticateUser(userName, password)) { if (this.AuthorizeSession(userName, computerName, connectionUri, configuration)) { bool flag = this.CheckUserSessionLimit(userName); string str = userName; if (flag) { statusSuccess = Resources.Status_Success; } else { statusSuccess = Resources.Status_Failure; } PowwaEvents.PowwaEVENT_SESSION_LIMIT_CHECK(str, statusSuccess); if (flag) { return; } else { PowwaEvents.PowwaEVENT_SESSION_LIMIT_REACHED(userName); object[] objArray = new object[1]; objArray[0] = userName; throw PowwaException.CreateLogOnFailureException(string.Format(CultureInfo.CurrentCulture, Resources.UserActiveSessionLimitReached, objArray)); } } else { string str1 = userName; string str2 = sourceIPAddressRemoteAddr; string str3 = sourceIPAddressHttpXForwardedFor; string gatewayAuthorizationFailure = Resources.GatewayAuthorizationFailure; if (connectionUri != null) { originalString = connectionUri.OriginalString; } else { originalString = computerName; } string str4 = configuration; string empty = str4; if (str4 == null) { empty = string.Empty; } PowwaEvents.PowwaEVENT_GATEWAY_AUTHORIZATION_FAILURE(str1, str2, str3, gatewayAuthorizationFailure, originalString, empty); throw PowwaException.CreateLogOnFailureException(Resources.GatewayAuthorizationFailure); } } else { PowwaEvents.PowwaEVENT_AUTHENTICATION_FAILURE(userName, sourceIPAddressRemoteAddr, sourceIPAddressHttpXForwardedFor, Resources.LoginFailure); throw PowwaException.CreateLogOnFailureException(Resources.LoginFailure); } } else { throw new ArgumentException("computerName and connectionUri are mutually exclusive", "computerName"); } }
public override Dictionary <string, PSObject> Prompt(string caption, string message, Collection <FieldDescription> descriptions) { bool flag = false; Dictionary <string, PSObject> reply; PowwaEvents.PowwaEVENT_DEBUG_LOG0("Prompt(): Enter"); try { if (descriptions != null) { if (descriptions.Count != 0) { PromptFieldDescription[] promptFieldDescriptionArray = new PromptFieldDescription[descriptions.Count]; int num = 0; while (num < descriptions.Count) { if (descriptions[num] != null) { Type fieldType = PowwaHostUserInterface.GetFieldType(descriptions[num], out flag); PromptFieldType promptFieldType = PromptFieldType.String; if (fieldType != typeof(SecureString)) { if (fieldType == typeof(PSCredential)) { promptFieldType = PromptFieldType.Credential; } } else { promptFieldType = PromptFieldType.SecureString; } PromptFieldDescription promptFieldDescription = new PromptFieldDescription(); promptFieldDescription.Name = descriptions[num].Name; promptFieldDescription.Label = descriptions[num].Label; promptFieldDescription.HelpMessage = descriptions[num].HelpMessage; promptFieldDescription.PromptFieldType = promptFieldType; promptFieldDescription.PromptFieldTypeIsList = flag; promptFieldDescriptionArray[num] = promptFieldDescription; num++; } else { object[] objArray = new object[1]; objArray[0] = num; string str = string.Format(CultureInfo.InvariantCulture, "descriptions[{0}]", objArray); PowwaEvents.PowwaEVENT_DEBUG_LOG1("Prompt(): Invalid Description", str, "null"); throw new ArgumentNullException(str); } } MessageCreatedEventArgs messageCreatedEventArg = new MessageCreatedEventArgs(new PromptMessage(caption, message, promptFieldDescriptionArray), true); this.OnMessageCreated(messageCreatedEventArg); reply = (Dictionary <string, PSObject>)messageCreatedEventArg.Reply; } else { int count = descriptions.Count; PowwaEvents.PowwaEVENT_DEBUG_LOG1("Prompt(): Invalid Argument", "Descriptions.Count", count.ToString(CultureInfo.InvariantCulture)); throw new ArgumentException("descriptions cannot be an empty array", "descriptions"); } } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("Prompt(): Invalid Argument", "Descriptions", "null"); throw new ArgumentNullException("descriptions"); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("Prompt(): Exit"); } return(reply); }