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); }
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 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 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); }
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"); } }
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); }
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 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); }
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); }