NetServerEnum2.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. using SharpCifs.Util.Sharpen;
  19. namespace SharpCifs.Smb
  20. {
  21. internal class NetServerEnum2 : SmbComTransaction
  22. {
  23. internal const int SvTypeAll = unchecked((int)(0xFFFFFFFF));
  24. internal const int SvTypeDomainEnum = unchecked((int)(0x80000000));
  25. internal static readonly string[] Descr =
  26. {
  27. "WrLehDO\u0000B16BBDz\u0000",
  28. "WrLehDz\u0000B16BBDz\u0000"
  29. };
  30. internal string Domain;
  31. internal string LastName;
  32. internal int ServerTypes;
  33. internal NetServerEnum2(string domain, int serverTypes)
  34. {
  35. this.Domain = domain;
  36. this.ServerTypes = serverTypes;
  37. Command = SmbComTransaction;
  38. SubCommand = NetServerEnum2;
  39. // not really true be used by upper logic
  40. Name = "\\PIPE\\LANMAN";
  41. MaxParameterCount = 8;
  42. MaxDataCount = 16384;
  43. MaxSetupCount = unchecked(unchecked(0x00));
  44. SetupCount = 0;
  45. Timeout = 5000;
  46. }
  47. internal override void Reset(int key, string lastName)
  48. {
  49. base.Reset();
  50. this.LastName = lastName;
  51. }
  52. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  53. {
  54. return 0;
  55. }
  56. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  57. {
  58. int start = dstIndex;
  59. byte[] descr;
  60. int which = SubCommand == NetServerEnum2 ? 0 : 1;
  61. try
  62. {
  63. descr = Runtime.GetBytesForString(Descr[which], "UTF-8"); //"ASCII");
  64. }
  65. catch (UnsupportedEncodingException)
  66. {
  67. return 0;
  68. }
  69. WriteInt2(SubCommand & unchecked(0xFF), dst, dstIndex);
  70. dstIndex += 2;
  71. Array.Copy(descr, 0, dst, dstIndex, descr.Length);
  72. dstIndex += descr.Length;
  73. WriteInt2(unchecked(0x0001), dst, dstIndex);
  74. dstIndex += 2;
  75. WriteInt2(MaxDataCount, dst, dstIndex);
  76. dstIndex += 2;
  77. WriteInt4(ServerTypes, dst, dstIndex);
  78. dstIndex += 4;
  79. dstIndex += WriteString(Domain.ToUpper(), dst, dstIndex, false);
  80. if (which == 1)
  81. {
  82. dstIndex += WriteString(LastName.ToUpper(), dst, dstIndex, false);
  83. }
  84. return dstIndex - start;
  85. }
  86. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  87. {
  88. return 0;
  89. }
  90. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len)
  91. {
  92. return 0;
  93. }
  94. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int len)
  95. {
  96. return 0;
  97. }
  98. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  99. {
  100. return 0;
  101. }
  102. public override string ToString()
  103. {
  104. return "NetServerEnum2["
  105. + base.ToString()
  106. + ",name=" + Name
  107. + ",serverTypes=" + (ServerTypes == SvTypeAll
  108. ? "SV_TYPE_ALL"
  109. : "SV_TYPE_DOMAIN_ENUM") + "]";
  110. }
  111. }
  112. }