NetServerEnum2.cs 3.4 KB

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