SmbComSessionSetupAndXResponse.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. int start = bufferIndex;
  41. IsLoggedInAsGuest = (buffer[bufferIndex] & 0x01) == 0x01
  42. ? true
  43. : false;
  44. bufferIndex += 2;
  45. if (ExtendedSecurity)
  46. {
  47. int blobLength = ReadInt2(buffer, bufferIndex);
  48. bufferIndex += 2;
  49. Blob = new byte[blobLength];
  50. }
  51. return bufferIndex - start;
  52. }
  53. internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
  54. {
  55. int start = bufferIndex;
  56. if (ExtendedSecurity)
  57. {
  58. Array.Copy(buffer, bufferIndex, Blob, 0, Blob.Length);
  59. bufferIndex += Blob.Length;
  60. }
  61. _nativeOs = ReadString(buffer, bufferIndex);
  62. bufferIndex += StringWireLength(_nativeOs, bufferIndex);
  63. _nativeLanMan = ReadString(buffer, bufferIndex, start + ByteCount, 255, UseUnicode);
  64. bufferIndex += StringWireLength(_nativeLanMan, bufferIndex);
  65. if (!ExtendedSecurity)
  66. {
  67. _primaryDomain = ReadString(buffer, bufferIndex, start + ByteCount, 255, UseUnicode);
  68. bufferIndex += StringWireLength(_primaryDomain, bufferIndex);
  69. }
  70. return bufferIndex - start;
  71. }
  72. public override string ToString()
  73. {
  74. string result = "SmbComSessionSetupAndXResponse["
  75. + base.ToString()
  76. + ",isLoggedInAsGuest=" + IsLoggedInAsGuest
  77. + ",nativeOs=" + _nativeOs
  78. + ",nativeLanMan=" + _nativeLanMan
  79. + ",primaryDomain=" + _primaryDomain + "]";
  80. return result;
  81. }
  82. }
  83. }