NetShareEnumResponse.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. namespace SharpCifs.Smb
  18. {
  19. internal class NetShareEnumResponse : SmbComTransactionResponse
  20. {
  21. private int _converter;
  22. private int _totalAvailableEntries;
  23. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  24. {
  25. return 0;
  26. }
  27. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  28. {
  29. return 0;
  30. }
  31. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  32. {
  33. return 0;
  34. }
  35. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len)
  36. {
  37. return 0;
  38. }
  39. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int len)
  40. {
  41. int start = bufferIndex;
  42. Status = ReadInt2(buffer, bufferIndex);
  43. bufferIndex += 2;
  44. _converter = ReadInt2(buffer, bufferIndex);
  45. bufferIndex += 2;
  46. NumEntries = ReadInt2(buffer, bufferIndex);
  47. bufferIndex += 2;
  48. _totalAvailableEntries = ReadInt2(buffer, bufferIndex);
  49. bufferIndex += 2;
  50. return bufferIndex - start;
  51. }
  52. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  53. {
  54. int start = bufferIndex;
  55. SmbShareInfo e;
  56. UseUnicode = false;
  57. Results = new SmbShareInfo[NumEntries];
  58. for (int i = 0; i < NumEntries; i++)
  59. {
  60. Results[i] = e = new SmbShareInfo();
  61. e.NetName = ReadString(buffer, bufferIndex, 13, false);
  62. bufferIndex += 14;
  63. e.Type = ReadInt2(buffer, bufferIndex);
  64. bufferIndex += 2;
  65. int off = ReadInt4(buffer, bufferIndex);
  66. bufferIndex += 4;
  67. off = (off & unchecked(0xFFFF)) - _converter;
  68. off = start + off;
  69. e.Remark = ReadString(buffer, off, 128, false);
  70. if (Log.Level >= 4)
  71. {
  72. Log.WriteLine(e);
  73. }
  74. }
  75. return bufferIndex - start;
  76. }
  77. public override string ToString()
  78. {
  79. return "NetShareEnumResponse["
  80. + base.ToString()
  81. + ",status=" + Status
  82. + ",converter=" + _converter
  83. + ",entriesReturned=" + NumEntries
  84. + ",totalAvailableEntries=" + _totalAvailableEntries + "]";
  85. }
  86. }
  87. }