NetServerEnum2Response.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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;
  18. namespace SharpCifs.Smb
  19. {
  20. internal class NetServerEnum2Response : SmbComTransactionResponse
  21. {
  22. internal class ServerInfo1 : IFileEntry
  23. {
  24. internal string Name;
  25. internal int VersionMajor;
  26. internal int VersionMinor;
  27. internal int Type;
  28. internal string CommentOrMasterBrowser;
  29. public virtual string GetName()
  30. {
  31. return Name;
  32. }
  33. public new virtual int GetType()
  34. {
  35. return (Type & unchecked((int)(0x80000000))) != 0
  36. ? SmbFile.TypeWorkgroup
  37. : SmbFile.TypeServer;
  38. }
  39. public virtual int GetAttributes()
  40. {
  41. return SmbFile.AttrReadonly | SmbFile.AttrDirectory;
  42. }
  43. public virtual long CreateTime()
  44. {
  45. return 0L;
  46. }
  47. public virtual long LastModified()
  48. {
  49. return 0L;
  50. }
  51. public virtual long Length()
  52. {
  53. return 0L;
  54. }
  55. public override string ToString()
  56. {
  57. return "ServerInfo1["
  58. + "name=" + Name
  59. + ",versionMajor=" + VersionMajor
  60. + ",versionMinor=" + VersionMinor
  61. + ",type=0x" + Hexdump.ToHexString(Type, 8)
  62. + ",commentOrMasterBrowser=" + CommentOrMasterBrowser + "]";
  63. }
  64. internal ServerInfo1(NetServerEnum2Response enclosing)
  65. {
  66. this._enclosing = enclosing;
  67. }
  68. private readonly NetServerEnum2Response _enclosing;
  69. }
  70. private int _converter;
  71. private int _totalAvailableEntries;
  72. internal string LastName;
  73. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  74. {
  75. return 0;
  76. }
  77. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  78. {
  79. return 0;
  80. }
  81. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  82. {
  83. return 0;
  84. }
  85. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
  86. )
  87. {
  88. return 0;
  89. }
  90. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int len)
  91. {
  92. int start = bufferIndex;
  93. Status = ReadInt2(buffer, bufferIndex);
  94. bufferIndex += 2;
  95. _converter = ReadInt2(buffer, bufferIndex);
  96. bufferIndex += 2;
  97. NumEntries = ReadInt2(buffer, bufferIndex);
  98. bufferIndex += 2;
  99. _totalAvailableEntries = ReadInt2(buffer, bufferIndex);
  100. bufferIndex += 2;
  101. return bufferIndex - start;
  102. }
  103. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  104. {
  105. int start = bufferIndex;
  106. ServerInfo1 e = null;
  107. Results = new ServerInfo1[NumEntries];
  108. for (int i = 0; i < NumEntries; i++)
  109. {
  110. Results[i] = e = new ServerInfo1(this);
  111. e.Name = ReadString(buffer, bufferIndex, 16, false);
  112. bufferIndex += 16;
  113. e.VersionMajor = buffer[bufferIndex++] & unchecked(0xFF);
  114. e.VersionMinor = buffer[bufferIndex++] & unchecked(0xFF);
  115. e.Type = ReadInt4(buffer, bufferIndex);
  116. bufferIndex += 4;
  117. int off = ReadInt4(buffer, bufferIndex);
  118. bufferIndex += 4;
  119. off = (off & unchecked(0xFFFF)) - _converter;
  120. off = start + off;
  121. e.CommentOrMasterBrowser = ReadString(buffer, off, 48, false);
  122. if (Log.Level >= 4)
  123. {
  124. Log.WriteLine(e);
  125. }
  126. }
  127. LastName = NumEntries == 0 ? null : e.Name;
  128. return bufferIndex - start;
  129. }
  130. public override string ToString()
  131. {
  132. return "NetServerEnum2Response["
  133. + base.ToString()
  134. + ",status=" + Status
  135. + ",converter=" + _converter
  136. + ",entriesReturned=" + NumEntries
  137. + ",totalAvailableEntries=" + _totalAvailableEntries
  138. + ",lastName=" + LastName + "]";
  139. }
  140. }
  141. }