mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-03 22:41:49 +02:00
NTFileSystemAdapter: Do not handle unexpected IFileSystem exceptions
This commit is contained in:
parent
6cab13c1c9
commit
86afb5af33
4 changed files with 173 additions and 58 deletions
|
@ -24,10 +24,17 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "GetFileInformation on '{0}' failed. {1}", path, status);
|
||||
result = null;
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "GetFileInformation on '{0}' failed. {1}", path, status);
|
||||
result = null;
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
switch (informationClass)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Utilities;
|
||||
|
||||
namespace SMBLibrary
|
||||
|
@ -66,9 +66,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "QueryDirectory: Error querying '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "QueryDirectory: Error querying '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
entries = new List<FileSystemEntry>();
|
||||
entries.Add(entry);
|
||||
|
|
|
@ -28,9 +28,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Failed to set file attributes on '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Failed to set file attributes on '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -39,9 +46,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Failed to set file dates on '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Failed to set file dates on '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return NTStatus.STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -71,9 +85,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Cannot rename '{0}' to '{1}'. {2}.", fileHandle.Path, newFileName, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Cannot rename '{0}' to '{1}'. {2}.", fileHandle.Path, newFileName, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
fileHandle.Path = newFileName;
|
||||
return NTStatus.STATUS_SUCCESS;
|
||||
|
@ -95,9 +116,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Information, "SetFileInformation: Error deleting '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Information, "SetFileInformation: Error deleting '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NTStatus.STATUS_SUCCESS;
|
||||
|
@ -111,9 +139,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Cannot set allocation for '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Cannot set allocation for '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return NTStatus.STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -126,9 +161,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Cannot set end of file for '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "SetFileInformation: Cannot set end of file for '{0}'. {1}.", fileHandle.Path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return NTStatus.STATUS_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -63,9 +63,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error retrieving '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error retrieving '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (createDisposition == CreateDisposition.FILE_OPEN)
|
||||
|
@ -116,9 +123,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
fileStatus = FileStatus.FILE_CREATED;
|
||||
}
|
||||
|
@ -154,9 +168,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
fileStatus = FileStatus.FILE_CREATED;
|
||||
}
|
||||
|
@ -193,9 +214,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
fileStatus = FileStatus.FILE_OVERWRITTEN;
|
||||
}
|
||||
|
@ -208,9 +236,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -228,9 +263,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
fileStatus = FileStatus.FILE_SUPERSEDED;
|
||||
}
|
||||
|
@ -282,9 +324,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString);
|
||||
|
@ -338,9 +387,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "ReadFile: Cannot read '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "ReadFile: Cannot read '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (bytesRead < maxCount)
|
||||
|
@ -370,9 +426,16 @@ namespace SMBLibrary
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "WriteFile: Cannot write '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
Log(Severity.Verbose, "WriteFile: Cannot write '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
numberOfBytesWritten = data.Length;
|
||||
return NTStatus.STATUS_SUCCESS;
|
||||
|
@ -444,11 +507,7 @@ namespace SMBLibrary
|
|||
/// <param name="exception">IFileSystem exception</param>
|
||||
private static NTStatus ToNTStatus(Exception exception)
|
||||
{
|
||||
if (exception is ArgumentException)
|
||||
{
|
||||
return NTStatus.STATUS_OBJECT_PATH_SYNTAX_BAD;
|
||||
}
|
||||
else if (exception is DirectoryNotFoundException)
|
||||
if (exception is DirectoryNotFoundException)
|
||||
{
|
||||
return NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue