Trans2GetDfsReferralResponse.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 SharpCifs.Util.Sharpen;
  18. namespace SharpCifs.Smb
  19. {
  20. internal class Trans2GetDfsReferralResponse : SmbComTransactionResponse
  21. {
  22. internal class Referral
  23. {
  24. private int _version;
  25. private int _size;
  26. private int _serverType;
  27. private int _flags;
  28. private int _proximity;
  29. private int _pathOffset;
  30. private int _altPathOffset;
  31. private int _nodeOffset;
  32. private string _altPath;
  33. internal int Ttl;
  34. internal string Path;
  35. internal string Node;
  36. internal virtual int ReadWireFormat(byte[] buffer, int bufferIndex, int len)
  37. {
  38. int start = bufferIndex;
  39. _version = ReadInt2(buffer, bufferIndex);
  40. if (_version != 3 && _version != 1)
  41. {
  42. throw new RuntimeException("Version " + _version + " referral not supported. Please report this to jcifs at samba dot org."
  43. );
  44. }
  45. bufferIndex += 2;
  46. _size = ReadInt2(buffer, bufferIndex);
  47. bufferIndex += 2;
  48. _serverType = ReadInt2(buffer, bufferIndex);
  49. bufferIndex += 2;
  50. _flags = ReadInt2(buffer, bufferIndex);
  51. bufferIndex += 2;
  52. if (_version == 3)
  53. {
  54. _proximity = ReadInt2(buffer, bufferIndex);
  55. bufferIndex += 2;
  56. Ttl = ReadInt2(buffer, bufferIndex);
  57. bufferIndex += 2;
  58. _pathOffset = ReadInt2(buffer, bufferIndex);
  59. bufferIndex += 2;
  60. _altPathOffset = ReadInt2(buffer, bufferIndex);
  61. bufferIndex += 2;
  62. _nodeOffset = ReadInt2(buffer, bufferIndex);
  63. bufferIndex += 2;
  64. Path = _enclosing.ReadString(buffer, start + _pathOffset, len, (_enclosing.Flags2 & SmbConstants.Flags2Unicode) != 0);
  65. if (_nodeOffset > 0)
  66. {
  67. Node = _enclosing.ReadString(buffer, start + _nodeOffset, len, (_enclosing.Flags2 & SmbConstants.Flags2Unicode) != 0);
  68. }
  69. }
  70. else
  71. {
  72. if (_version == 1)
  73. {
  74. Node = _enclosing.ReadString(buffer, bufferIndex, len, (_enclosing
  75. .Flags2 & SmbConstants.Flags2Unicode) != 0);
  76. }
  77. }
  78. return _size;
  79. }
  80. public override string ToString()
  81. {
  82. return "Referral[" + "version=" + _version + ",size=" + _size
  83. + ",serverType=" + _serverType + ",flags=" + _flags + ",proximity=" + _proximity + ",ttl=" + Ttl + ",pathOffset=" + _pathOffset + ",altPathOffset="
  84. + _altPathOffset + ",nodeOffset=" + _nodeOffset + ",path=" + Path
  85. + ",altPath=" + _altPath + ",node=" + Node + "]";
  86. }
  87. internal Referral(Trans2GetDfsReferralResponse enclosing)
  88. {
  89. this._enclosing = enclosing;
  90. }
  91. private readonly Trans2GetDfsReferralResponse _enclosing;
  92. }
  93. internal int PathConsumed;
  94. internal int NumReferrals;
  95. internal int flags;
  96. internal Referral[] Referrals;
  97. public Trans2GetDfsReferralResponse()
  98. {
  99. SubCommand = Smb.SmbComTransaction.Trans2GetDfsReferral;
  100. }
  101. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  102. {
  103. return 0;
  104. }
  105. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  106. {
  107. return 0;
  108. }
  109. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  110. {
  111. return 0;
  112. }
  113. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
  114. )
  115. {
  116. return 0;
  117. }
  118. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
  119. len)
  120. {
  121. return 0;
  122. }
  123. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  124. {
  125. int start = bufferIndex;
  126. PathConsumed = ReadInt2(buffer, bufferIndex);
  127. bufferIndex += 2;
  128. if ((Flags2 & SmbConstants.Flags2Unicode) != 0)
  129. {
  130. PathConsumed /= 2;
  131. }
  132. NumReferrals = ReadInt2(buffer, bufferIndex);
  133. bufferIndex += 2;
  134. flags = ReadInt2(buffer, bufferIndex);
  135. bufferIndex += 4;
  136. Referrals = new Referral[NumReferrals];
  137. for (int ri = 0; ri < NumReferrals; ri++)
  138. {
  139. Referrals[ri] = new Referral(this);
  140. bufferIndex += Referrals[ri].ReadWireFormat(buffer, bufferIndex, len);
  141. }
  142. return bufferIndex - start;
  143. }
  144. public override string ToString()
  145. {
  146. return "Trans2GetDfsReferralResponse[" + base.ToString() + ",pathConsumed="
  147. + PathConsumed + ",numReferrals=" + NumReferrals + ",flags=" + flags + "]";
  148. }
  149. }
  150. }