SmbComSessionSetupAndXResponse.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using System;
  18. namespace SharpCifs.Smb
  19. {
  20. internal class SmbComSessionSetupAndXResponse : AndXServerMessageBlock
  21. {
  22. private string _nativeOs = string.Empty;
  23. private string _nativeLanMan = string.Empty;
  24. private string _primaryDomain = string.Empty;
  25. internal bool IsLoggedInAsGuest;
  26. internal byte[] Blob;
  27. internal SmbComSessionSetupAndXResponse(ServerMessageBlock andx) : base(andx)
  28. {
  29. }
  30. internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
  31. {
  32. return 0;
  33. }
  34. internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
  35. {
  36. return 0;
  37. }
  38. internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
  39. )
  40. {
  41. int start = bufferIndex;
  42. IsLoggedInAsGuest = (buffer[bufferIndex] & 0x01) == 0x01 ? true : false;
  43. bufferIndex += 2;
  44. if (ExtendedSecurity)
  45. {
  46. int blobLength = ReadInt2(buffer, bufferIndex);
  47. bufferIndex += 2;
  48. Blob = new byte[blobLength];
  49. }
  50. return bufferIndex - start;
  51. }
  52. internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
  53. {
  54. int start = bufferIndex;
  55. if (ExtendedSecurity)
  56. {
  57. Array.Copy(buffer, bufferIndex, Blob, 0, Blob.Length);
  58. bufferIndex += Blob.Length;
  59. }
  60. _nativeOs = ReadString(buffer, bufferIndex);
  61. bufferIndex += StringWireLength(_nativeOs, bufferIndex);
  62. _nativeLanMan = ReadString(buffer, bufferIndex, start + ByteCount, 255, UseUnicode
  63. );
  64. bufferIndex += StringWireLength(_nativeLanMan, bufferIndex);
  65. if (!ExtendedSecurity)
  66. {
  67. _primaryDomain = ReadString(buffer, bufferIndex, start + ByteCount, 255, UseUnicode
  68. );
  69. bufferIndex += StringWireLength(_primaryDomain, bufferIndex);
  70. }
  71. return bufferIndex - start;
  72. }
  73. public override string ToString()
  74. {
  75. string result = "SmbComSessionSetupAndXResponse[" + base.ToString() +
  76. ",isLoggedInAsGuest=" + IsLoggedInAsGuest + ",nativeOs=" + _nativeOs + ",nativeLanMan="
  77. + _nativeLanMan + ",primaryDomain=" + _primaryDomain + "]";
  78. return result;
  79. }
  80. }
  81. }