Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 private static SecureString ToSecureString(object[] array)
 {
     char[] chr = new char[(int)array.Length];
     for (int i = 0; i < (int)array.Length; i++)
     {
         chr[i]   = Convert.ToChar(array[i], CultureInfo.InvariantCulture);
         array[i] = (char)0;
     }
     return(PowwaSession.ToSecureString(chr));
 }
Esempio n. 3
0
 public ClientMessage[] SetReadLineAsSecureStringReply(char[] reply)
 {
     ClientMessage[] clientMessages;
     PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetReadLineAsSecureStringReply(): Enter");
     try
     {
         lock (this.clientRequestLock)
         {
             lock (this.sessionStateLock)
             {
                 this.ValidateSessionStateForMessageReply <ReadLineAsSecureStringMessage>();
                 SecureString secureString = PowwaSession.ToSecureString(reply);
                 this.messageQueue.SetInputMessageReply(secureString);
             }
             clientMessages = this.GetClientMessages();
         }
     }
     finally
     {
         PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetReadLineAsSecureStringReply(): Exit");
     }
     return(clientMessages);
 }
Esempio n. 4
0
        private static object PromptReplyObjectToObject(object reply, PromptFieldDescription description)
        {
            PromptFieldType promptFieldType = description.PromptFieldType;

            switch (promptFieldType)
            {
            case PromptFieldType.String:
            {
                if (reply as string != null)
                {
                    return(reply);
                }
                else
                {
                    throw new ArgumentException("Expected a string", "reply");
                }
            }

            case PromptFieldType.SecureString:
            {
                object[] objArray = reply as object[];
                if (objArray != null)
                {
                    return(PowwaSession.ToSecureString(objArray));
                }
                else
                {
                    throw new ArgumentException("Expected an object[]", "reply");
                }
            }

            case PromptFieldType.Credential:
            {
                Dictionary <string, object> strs = reply as Dictionary <string, object>;
                if (strs == null || !strs.ContainsKey("username") || !strs.ContainsKey("password"))
                {
                    throw new ArgumentException("Expected an object with username and password properties", "reply");
                }
                else
                {
                    string item = strs["username"] as string;
                    if (item != null)
                    {
                        object[] item1 = strs["password"] as object[];
                        if (item1 != null)
                        {
                            return(new PSCredential(item, PowwaSession.ToSecureString(item1)));
                        }
                        else
                        {
                            throw new ArgumentException("The password should be an object[]", "reply");
                        }
                    }
                    else
                    {
                        throw new ArgumentException("The username should be a string", "reply");
                    }
                }
            }
            }
            throw new ArgumentException("Unknown reply type", "reply");
        }