DcerpcBind.cs 2.8 KB

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