NetServerEnum2Response.cs 4.2 KB

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