DcerpcBind.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.Dcerpc.Ndr;
  18. using SharpCifs.Util;
  19. namespace SharpCifs.Dcerpc
  20. {
  21. public class DcerpcBind : DcerpcMessage
  22. {
  23. internal static readonly string[] ResultMessage =
  24. {
  25. "0",
  26. "DCERPC_BIND_ERR_ABSTRACT_SYNTAX_NOT_SUPPORTED",
  27. "DCERPC_BIND_ERR_PROPOSED_TRANSFER_SYNTAXES_NOT_SUPPORTED",
  28. "DCERPC_BIND_ERR_LOCAL_LIMIT_EXCEEDED"
  29. };
  30. internal static string GetResultMessage(int result)
  31. {
  32. return result < 4 ? ResultMessage[result] : "0x" + Hexdump.ToHexString(result, 4);
  33. }
  34. public override DcerpcException GetResult()
  35. {
  36. if (Result != 0)
  37. {
  38. return new DcerpcException(GetResultMessage(Result));
  39. }
  40. return null;
  41. }
  42. internal DcerpcBinding Binding;
  43. internal int MaxXmit;
  44. internal int MaxRecv;
  45. public DcerpcBind()
  46. {
  47. }
  48. internal DcerpcBind(DcerpcBinding binding, DcerpcHandle handle)
  49. {
  50. this.Binding = binding;
  51. MaxXmit = handle.MaxXmit;
  52. MaxRecv = handle.MaxRecv;
  53. Ptype = 11;
  54. Flags = DcerpcConstants.DcerpcFirstFrag | DcerpcConstants.DcerpcLastFrag;
  55. }
  56. public override int GetOpnum()
  57. {
  58. return 0;
  59. }
  60. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  61. public override void Encode_in(NdrBuffer dst)
  62. {
  63. dst.Enc_ndr_short(MaxXmit);
  64. dst.Enc_ndr_short(MaxRecv);
  65. dst.Enc_ndr_long(0);
  66. dst.Enc_ndr_small(1);
  67. dst.Enc_ndr_small(0);
  68. dst.Enc_ndr_short(0);
  69. dst.Enc_ndr_short(0);
  70. dst.Enc_ndr_small(1);
  71. dst.Enc_ndr_small(0);
  72. Binding.Uuid.Encode(dst);
  73. dst.Enc_ndr_short(Binding.Major);
  74. dst.Enc_ndr_short(Binding.Minor);
  75. DcerpcConstants.DcerpcUuidSyntaxNdr.Encode(dst);
  76. dst.Enc_ndr_long(2);
  77. }
  78. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  79. public override void Decode_out(NdrBuffer src)
  80. {
  81. src.Dec_ndr_short();
  82. src.Dec_ndr_short();
  83. src.Dec_ndr_long();
  84. int n = src.Dec_ndr_short();
  85. src.Advance(n);
  86. src.Align(4);
  87. src.Dec_ndr_small();
  88. src.Align(4);
  89. Result = src.Dec_ndr_short();
  90. src.Dec_ndr_short();
  91. src.Advance(20);
  92. }
  93. }
  94. }