Improved code readability and exception messages

This commit is contained in:
Tal Aloni 2017-02-21 12:43:44 +02:00
parent 2141e649fa
commit 6b56e2a8ca
4 changed files with 14 additions and 14 deletions

View file

@ -73,7 +73,7 @@ namespace SMBLibrary.NetBios
case SessionPacketTypeName.SessionKeepAlive: case SessionPacketTypeName.SessionKeepAlive:
return new SessionKeepAlivePacket(buffer, offset); return new SessionKeepAlivePacket(buffer, offset);
default: default:
throw new InvalidRequestException("Invalid NetBIOS session packet type"); throw new InvalidRequestException("Invalid NetBIOS session packet type: 0x" + type.ToString("X"));
} }
} }
} }

View file

@ -156,7 +156,7 @@ namespace SMBLibrary.SMB1
case CommandName.SMB_COM_NT_CREATE_ANDX: case CommandName.SMB_COM_NT_CREATE_ANDX:
return new NTCreateAndXRequest(buffer, offset, isUnicode); return new NTCreateAndXRequest(buffer, offset, isUnicode);
default: default:
throw new NotImplementedException("SMB Command 0x" + ((byte)commandName).ToString("X")); throw new NotImplementedException("SMB Command 0x" + commandName.ToString("X"));
} }
} }
@ -288,7 +288,7 @@ namespace SMBLibrary.SMB1
case CommandName.SMB_COM_NT_CREATE_ANDX: case CommandName.SMB_COM_NT_CREATE_ANDX:
return new NTCreateAndXResponse(buffer, offset); return new NTCreateAndXResponse(buffer, offset);
default: default:
throw new NotImplementedException("SMB Command 0x" + ((byte)commandName).ToString("X")); throw new NotImplementedException("SMB Command 0x" + commandName.ToString("X"));
} }
} }

View file

@ -191,7 +191,7 @@ namespace SMBLibrary.Server
catch (Exception ex) catch (Exception ex)
{ {
state.ClientSocket.Close(); state.ClientSocket.Close();
Log(Severity.Warning, "Rejected Invalid NetBIOS session packet: " + ex.ToString()); Log(Severity.Warning, "Rejected Invalid NetBIOS session packet: " + ex.Message);
break; break;
} }

View file

@ -43,15 +43,15 @@ namespace SMBLibrary.Win32.Security
bool success = LogonUser(userName, String.Empty, password, (int)logonType, LOGON32_PROVIDER_WINNT40, out token); bool success = LogonUser(userName, String.Empty, password, (int)logonType, LOGON32_PROVIDER_WINNT40, out token);
if (!success) if (!success)
{ {
uint error = (uint)Marshal.GetLastWin32Error(); Win32Error error = (Win32Error)Marshal.GetLastWin32Error();
if (error == (uint)Win32Error.ERROR_ACCOUNT_RESTRICTION || if (error == Win32Error.ERROR_ACCOUNT_RESTRICTION ||
error == (uint)Win32Error.ERROR_ACCOUNT_DISABLED || error == Win32Error.ERROR_ACCOUNT_DISABLED ||
error == (uint)Win32Error.ERROR_LOGON_FAILURE || error == Win32Error.ERROR_LOGON_FAILURE ||
error == (uint)Win32Error.ERROR_LOGON_TYPE_NOT_GRANTED) error == Win32Error.ERROR_LOGON_TYPE_NOT_GRANTED)
{ {
return false; return false;
} }
throw new Exception("ValidateUser failed, error: 0x" + ((uint)error).ToString("X")); throw new Exception("ValidateUser failed, Win32 error: " + error.ToString("D"));
} }
CloseHandle(token); CloseHandle(token);
return success; return success;
@ -68,10 +68,10 @@ namespace SMBLibrary.Win32.Security
} }
else else
{ {
uint error = (uint)Marshal.GetLastWin32Error(); Win32Error error = (Win32Error)Marshal.GetLastWin32Error();
return (error == (uint)Win32Error.ERROR_ACCOUNT_RESTRICTION || return (error == Win32Error.ERROR_ACCOUNT_RESTRICTION ||
error == (uint)Win32Error.ERROR_ACCOUNT_DISABLED || error == Win32Error.ERROR_ACCOUNT_DISABLED ||
error == (uint)Win32Error.ERROR_LOGON_TYPE_NOT_GRANTED); error == Win32Error.ERROR_LOGON_TYPE_NOT_GRANTED);
} }
} }
} }