SharpCifs.Smb.SmbComSessionSetupAndX.SmbComSessionSetupAndX C# (CSharp) Method

SmbComSessionSetupAndX() private method

private SmbComSessionSetupAndX ( SmbSession session, ServerMessageBlock andx, object cred ) : System
session SmbSession
andx ServerMessageBlock
cred object
return System
		internal SmbComSessionSetupAndX(SmbSession session, ServerMessageBlock andx, object
			 cred) : base(andx)
		{
			Command = SmbComSessionSetupAndx;
			this.Session = session;
			this.Cred = cred;
			_sessionKey = session.transport.SessionKey;
			_capabilities = session.transport.Capabilities;
            if (session.transport.Server.Security == SmbConstants.SecurityUser)
			{
				if (cred is NtlmPasswordAuthentication)
				{
					NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
					if (auth == NtlmPasswordAuthentication.Anonymous)
					{
						_lmHash = new byte[0];
						_ntHash = new byte[0];
						_capabilities &= ~SmbConstants.CapExtendedSecurity;
					}
					else
					{
						if (session.transport.Server.EncryptedPasswords)
						{
							_lmHash = auth.GetAnsiHash(session.transport.Server.EncryptionKey);
							_ntHash = auth.GetUnicodeHash(session.transport.Server.EncryptionKey);
							// prohibit HTTP auth attempts for the null session
							if (_lmHash.Length == 0 && _ntHash.Length == 0)
							{
								throw new RuntimeException("Null setup prohibited.");
							}
						}
						else
						{
						    if (DisablePlainTextPasswords)
							{
								throw new RuntimeException("Plain text passwords are disabled");
							}
						    if (UseUnicode)
						    {
						        // plain text
						        string password = auth.GetPassword();
						        _lmHash = new byte[0];
						        _ntHash = new byte[(password.Length + 1) * 2];
						        WriteString(password, _ntHash, 0);
						    }
						    else
						    {
						        // plain text
						        string password = auth.GetPassword();
						        _lmHash = new byte[(password.Length + 1) * 2];
						        _ntHash = new byte[0];
						        WriteString(password, _lmHash, 0);
						    }
						}
					}
					_accountName = auth.Username;
					if (UseUnicode)
					{
						_accountName = _accountName.ToUpper();
					}
					_primaryDomain = auth.Domain.ToUpper();
				}
				else
				{
					if (cred is byte[])
					{
						_blob = (byte[])cred;
					}
					else
					{
						throw new SmbException("Unsupported credential type");
					}
				}
			}
			else
			{
                if (session.transport.Server.Security == SmbConstants.SecurityShare)
				{
					if (cred is NtlmPasswordAuthentication)
					{
						NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
						_lmHash = new byte[0];
						_ntHash = new byte[0];
						_accountName = auth.Username;
						if (UseUnicode)
						{
							_accountName = _accountName.ToUpper();
						}
						_primaryDomain = auth.Domain.ToUpper();
					}
					else
					{
						throw new SmbException("Unsupported credential type");
					}
				}
				else
				{
					throw new SmbException("Unsupported");
				}
			}
		}