diff options
Diffstat (limited to 'Emby.Common.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs')
| -rw-r--r-- | Emby.Common.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs | 400 |
1 files changed, 205 insertions, 195 deletions
diff --git a/Emby.Common.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs b/Emby.Common.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs index a1642391c..24c2a1dff 100644 --- a/Emby.Common.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs +++ b/Emby.Common.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs @@ -20,215 +20,225 @@ using SharpCifs.Util.Sharpen; namespace SharpCifs.Smb { - internal class SmbComSessionSetupAndX : AndXServerMessageBlock - { - private static readonly int BatchLimit = Config.GetInt("jcifs.smb.client.SessionSetupAndX.TreeConnectAndX" - , 1); + internal class SmbComSessionSetupAndX : AndXServerMessageBlock + { + private static readonly int BatchLimit + = Config.GetInt("jcifs.smb.client.SessionSetupAndX.TreeConnectAndX", 1); - private static readonly bool DisablePlainTextPasswords = Config.GetBoolean("jcifs.smb.client.disablePlainTextPasswords" - , true); + private static readonly bool DisablePlainTextPasswords + = Config.GetBoolean("jcifs.smb.client.disablePlainTextPasswords", true); - private byte[] _lmHash; + private byte[] _lmHash; - private byte[] _ntHash; + private byte[] _ntHash; - private byte[] _blob; + private byte[] _blob; - private int _sessionKey; + private int _sessionKey; - private int _capabilities; + private int _capabilities; - private string _accountName; + private string _accountName; - private string _primaryDomain; + private string _primaryDomain; - internal SmbSession Session; + internal SmbSession Session; - internal object Cred; + internal object Cred; - /// <exception cref="SharpCifs.Smb.SmbException"></exception> - 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; + /// <exception cref="SharpCifs.Smb.SmbException"></exception> + 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 (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"); - } - } - } - - internal override int GetBatchLimit(byte command) - { - return command == SmbComTreeConnectAndx ? BatchLimit : 0; - } - - internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex) - { - int start = dstIndex; - WriteInt2(Session.transport.SndBufSize, dst, dstIndex); - dstIndex += 2; - WriteInt2(Session.transport.MaxMpxCount, dst, dstIndex); - dstIndex += 2; + { + 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"); + } + } + } + + internal override int GetBatchLimit(byte command) + { + return command == SmbComTreeConnectAndx ? BatchLimit : 0; + } + + internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex) + { + int start = dstIndex; + WriteInt2(Session.transport.SndBufSize, dst, dstIndex); + dstIndex += 2; + WriteInt2(Session.transport.MaxMpxCount, dst, dstIndex); + dstIndex += 2; WriteInt2(SmbConstants.VcNumber, dst, dstIndex); - dstIndex += 2; - WriteInt4(_sessionKey, dst, dstIndex); - dstIndex += 4; - if (_blob != null) - { - WriteInt2(_blob.Length, dst, dstIndex); - dstIndex += 2; - } - else - { - WriteInt2(_lmHash.Length, dst, dstIndex); - dstIndex += 2; - WriteInt2(_ntHash.Length, dst, dstIndex); - dstIndex += 2; - } - dst[dstIndex++] = unchecked(unchecked(0x00)); - dst[dstIndex++] = unchecked(unchecked(0x00)); - dst[dstIndex++] = unchecked(unchecked(0x00)); - dst[dstIndex++] = unchecked(unchecked(0x00)); - WriteInt4(_capabilities, dst, dstIndex); - dstIndex += 4; - return dstIndex - start; - } - - internal override int WriteBytesWireFormat(byte[] dst, int dstIndex) - { - int start = dstIndex; - if (_blob != null) - { - Array.Copy(_blob, 0, dst, dstIndex, _blob.Length); - dstIndex += _blob.Length; - } - else - { - Array.Copy(_lmHash, 0, dst, dstIndex, _lmHash.Length); - dstIndex += _lmHash.Length; - Array.Copy(_ntHash, 0, dst, dstIndex, _ntHash.Length); - dstIndex += _ntHash.Length; - dstIndex += WriteString(_accountName, dst, dstIndex); - dstIndex += WriteString(_primaryDomain, dst, dstIndex); - } + dstIndex += 2; + WriteInt4(_sessionKey, dst, dstIndex); + dstIndex += 4; + if (_blob != null) + { + WriteInt2(_blob.Length, dst, dstIndex); + dstIndex += 2; + } + else + { + WriteInt2(_lmHash.Length, dst, dstIndex); + dstIndex += 2; + WriteInt2(_ntHash.Length, dst, dstIndex); + dstIndex += 2; + } + dst[dstIndex++] = unchecked(unchecked(0x00)); + dst[dstIndex++] = unchecked(unchecked(0x00)); + dst[dstIndex++] = unchecked(unchecked(0x00)); + dst[dstIndex++] = unchecked(unchecked(0x00)); + WriteInt4(_capabilities, dst, dstIndex); + dstIndex += 4; + return dstIndex - start; + } + + internal override int WriteBytesWireFormat(byte[] dst, int dstIndex) + { + int start = dstIndex; + if (_blob != null) + { + Array.Copy(_blob, 0, dst, dstIndex, _blob.Length); + dstIndex += _blob.Length; + } + else + { + Array.Copy(_lmHash, 0, dst, dstIndex, _lmHash.Length); + dstIndex += _lmHash.Length; + Array.Copy(_ntHash, 0, dst, dstIndex, _ntHash.Length); + dstIndex += _ntHash.Length; + dstIndex += WriteString(_accountName, dst, dstIndex); + dstIndex += WriteString(_primaryDomain, dst, dstIndex); + } dstIndex += WriteString(SmbConstants.NativeOs, dst, dstIndex); dstIndex += WriteString(SmbConstants.NativeLanman, dst, dstIndex); - return dstIndex - start; - } - - internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex - ) - { - return 0; - } - - internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex) - { - return 0; - } - - public override string ToString() - { - string result = "SmbComSessionSetupAndX[" + base.ToString() + ",snd_buf_size=" - + Session.transport.SndBufSize + ",maxMpxCount=" + Session.transport.MaxMpxCount - + ",VC_NUMBER=" + SmbConstants.VcNumber + ",sessionKey=" + _sessionKey + ",lmHash.length=" - + (_lmHash == null ? 0 : _lmHash.Length) + ",ntHash.length=" + (_ntHash == null ? - 0 : _ntHash.Length) + ",capabilities=" + _capabilities + ",accountName=" + _accountName - + ",primaryDomain=" + _primaryDomain + ",NATIVE_OS=" + SmbConstants.NativeOs - + ",NATIVE_LANMAN=" + SmbConstants.NativeLanman + "]"; - return result; - } - } + return dstIndex - start; + } + + internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex) + { + return 0; + } + + internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex) + { + return 0; + } + + public override string ToString() + { + string result = "SmbComSessionSetupAndX[" + + base.ToString() + + ",snd_buf_size=" + Session.transport.SndBufSize + + ",maxMpxCount=" + Session.transport.MaxMpxCount + + ",VC_NUMBER=" + SmbConstants.VcNumber + + ",sessionKey=" + _sessionKey + + ",lmHash.length=" + (_lmHash == null + ? 0 + : _lmHash.Length) + + ",ntHash.length=" + (_ntHash == null + ? 0 + : _ntHash.Length) + + ",capabilities=" + _capabilities + + ",accountName=" + _accountName + + ",primaryDomain=" + _primaryDomain + + ",NATIVE_OS=" + SmbConstants.NativeOs + + ",NATIVE_LANMAN=" + SmbConstants.NativeLanman + "]"; + return result; + } + } } |
