2
0

DcerpcException.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 System.IO;
  19. using SharpCifs.Util;
  20. using SharpCifs.Util.Sharpen;
  21. namespace SharpCifs.Dcerpc
  22. {
  23. public class DcerpcException : IOException
  24. {
  25. internal static string GetMessageByDcerpcError(int errcode)
  26. {
  27. int min = 0;
  28. int max = DcerpcError.DcerpcFaultCodes.Length;
  29. while (max >= min)
  30. {
  31. int mid = (min + max) / 2;
  32. if (errcode > DcerpcError.DcerpcFaultCodes[mid])
  33. {
  34. min = mid + 1;
  35. }
  36. else
  37. {
  38. if (errcode < DcerpcError.DcerpcFaultCodes[mid])
  39. {
  40. max = mid - 1;
  41. }
  42. else
  43. {
  44. return DcerpcError.DcerpcFaultMessages[mid];
  45. }
  46. }
  47. }
  48. return "0x" + Hexdump.ToHexString(errcode, 8);
  49. }
  50. private int _error;
  51. private Exception _rootCause;
  52. internal DcerpcException(int error) : base(GetMessageByDcerpcError(error))
  53. {
  54. this._error = error;
  55. }
  56. public DcerpcException(string msg) : base(msg)
  57. {
  58. }
  59. public DcerpcException(string msg, Exception rootCause) : base(msg)
  60. {
  61. this._rootCause = rootCause;
  62. }
  63. public virtual int GetErrorCode()
  64. {
  65. return _error;
  66. }
  67. public virtual Exception GetRootCause()
  68. {
  69. return _rootCause;
  70. }
  71. public override string ToString()
  72. {
  73. if (_rootCause != null)
  74. {
  75. StringWriter sw = new StringWriter();
  76. PrintWriter pw = new PrintWriter(sw);
  77. Runtime.PrintStackTrace(_rootCause, pw);
  78. return base.ToString() + "\n" + sw;
  79. }
  80. return base.ToString();
  81. }
  82. }
  83. }