2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//Virtual Circuit
|
|
|
|
// TID
|
|
|
|
// PID
|
|
|
|
// FID
|
|
|
|
//
|
|
|
|
//
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Text;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Smb.Shared;
|
|
|
|
|
|
|
|
namespace Smb.Protocol
|
|
|
|
{
|
|
|
|
public /*static*/ sealed class SmbProtocol
|
|
|
|
{
|
|
|
|
private SmbProtocol() {}
|
|
|
|
|
|
|
|
public static readonly byte[] SmbSignature = { 0xff, (byte)'S', (byte)'M', (byte)'B' };
|
|
|
|
public const int NativeFileServicePort = 445;
|
|
|
|
public const int NbtVirtualCircuitPort = 139;
|
|
|
|
|
|
|
|
|
|
|
|
public const int SmbHeaderSize = 37; // 0x1d; // sizeof(SmbHeader);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Facility code for use in NTSTATUS values.
|
|
|
|
/// </summary>
|
|
|
|
public const uint SmbErrorFacilityCode = 0x00980000;
|
|
|
|
|
|
|
|
public static bool IsSuccess(SmbError error)
|
|
|
|
{
|
|
|
|
return ((uint)error & 0x80000000) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsError(SmbError error)
|
|
|
|
{
|
|
|
|
return ((uint)error & 0x80000000) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SmbError ToSmbError(byte errorClass, ushort code)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
switch ((SmbErrorClass)errorClass) {
|
2008-03-05 09:52:00 -05:00
|
|
|
case SmbErrorClass.Success:
|
|
|
|
return SmbError.Success;
|
|
|
|
|
|
|
|
case SmbErrorClass.FileServer:
|
|
|
|
return (SmbError)((uint)SmbNtErrorClass.FileServer | code);
|
|
|
|
|
|
|
|
case SmbErrorClass.OperatingSystem:
|
|
|
|
return (SmbError)((uint)SmbNtErrorClass.Dos | code);
|
|
|
|
|
|
|
|
case SmbErrorClass.HardwareError:
|
|
|
|
return (SmbError)((uint)SmbNtErrorClass.Hardware | code);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (SmbError)((uint)SmbNtErrorClass.Unrecognized | code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string! GetErrorText(byte errorClass, int code)
|
|
|
|
{
|
|
|
|
return GetErrorText((SmbErrorClass)errorClass, code);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string! GetErrorText(SmbErrorClass errorClass, int code)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
switch (errorClass) {
|
2008-03-05 09:52:00 -05:00
|
|
|
case SmbErrorClass.Success:
|
|
|
|
return "Success." + ((SmbSuccessMessage)code).ToString();
|
|
|
|
|
|
|
|
case SmbErrorClass.OperatingSystem:
|
|
|
|
return "OperatingSystem." + ((SmbOsError)code).ToString();
|
|
|
|
|
|
|
|
case SmbErrorClass.FileServer:
|
|
|
|
return "FileServer." + ((SmbFileServerError)code).ToString();
|
|
|
|
|
|
|
|
case SmbErrorClass.Unrecognized:
|
|
|
|
return "Unrecognized:" + code;
|
|
|
|
|
|
|
|
case SmbErrorClass.HardwareError:
|
|
|
|
return "Hardware." + ((SmbHardwareError)code).ToString();
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "UNKNOWN CLASS " + errorClass + " CODE " + code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|