You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.3 KiB
94 lines
2.3 KiB
8 years ago
|
// This code is derived from jcifs smb client library <jcifs at samba dot org>
|
||
|
// Ported by J. Arturo <webmaster at komodosoft dot net>
|
||
|
//
|
||
|
// This library is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU Lesser General Public
|
||
|
// License as published by the Free Software Foundation; either
|
||
|
// version 2.1 of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This library is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
// Lesser General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU Lesser General Public
|
||
|
// License along with this library; if not, write to the Free Software
|
||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
using System;
|
||
|
using System.IO;
|
||
|
using SharpCifs.Util;
|
||
|
using SharpCifs.Util.Sharpen;
|
||
|
|
||
|
namespace SharpCifs.Dcerpc
|
||
|
{
|
||
7 years ago
|
|
||
|
public class DcerpcException : IOException
|
||
|
{
|
||
|
internal static string GetMessageByDcerpcError(int errcode)
|
||
|
{
|
||
|
int min = 0;
|
||
8 years ago
|
int max = DcerpcError.DcerpcFaultCodes.Length;
|
||
7 years ago
|
while (max >= min)
|
||
|
{
|
||
|
int mid = (min + max) / 2;
|
||
8 years ago
|
if (errcode > DcerpcError.DcerpcFaultCodes[mid])
|
||
7 years ago
|
{
|
||
|
min = mid + 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
8 years ago
|
if (errcode < DcerpcError.DcerpcFaultCodes[mid])
|
||
7 years ago
|
{
|
||
|
max = mid - 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
8 years ago
|
return DcerpcError.DcerpcFaultMessages[mid];
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return "0x" + Hexdump.ToHexString(errcode, 8);
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
private int _error;
|
||
8 years ago
|
|
||
7 years ago
|
private Exception _rootCause;
|
||
8 years ago
|
|
||
7 years ago
|
internal DcerpcException(int error) : base(GetMessageByDcerpcError(error))
|
||
|
{
|
||
|
this._error = error;
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public DcerpcException(string msg) : base(msg)
|
||
|
{
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public DcerpcException(string msg, Exception rootCause) : base(msg)
|
||
|
{
|
||
|
this._rootCause = rootCause;
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public virtual int GetErrorCode()
|
||
|
{
|
||
|
return _error;
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public virtual Exception GetRootCause()
|
||
|
{
|
||
|
return _rootCause;
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public override string ToString()
|
||
|
{
|
||
|
if (_rootCause != null)
|
||
|
{
|
||
|
StringWriter sw = new StringWriter();
|
||
|
PrintWriter pw = new PrintWriter(sw);
|
||
|
Runtime.PrintStackTrace(_rootCause, pw);
|
||
|
return base.ToString() + "\n" + sw;
|
||
|
}
|
||
|
return base.ToString();
|
||
|
}
|
||
|
}
|
||
8 years ago
|
}
|