mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-23 07:20:48 +02:00
NTFileSystemHelper.CreateFile: Corrected FILE_SUPERSEDE implementation
This commit is contained in:
parent
a9f92df47b
commit
4be937e7c1
1 changed files with 42 additions and 8 deletions
|
@ -30,7 +30,8 @@ namespace SMBLibrary.Server
|
|||
|
||||
if (forceDirectory & (createDisposition != CreateDisposition.FILE_CREATE &&
|
||||
createDisposition != CreateDisposition.FILE_OPEN &&
|
||||
createDisposition != CreateDisposition.FILE_OPEN_IF))
|
||||
createDisposition != CreateDisposition.FILE_OPEN_IF &&
|
||||
createDisposition != CreateDisposition.FILE_SUPERSEDE))
|
||||
{
|
||||
entry = null;
|
||||
return NTStatus.STATUS_INVALID_PARAMETER;
|
||||
|
@ -146,16 +147,15 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (createDisposition == CreateDisposition.FILE_OVERWRITE ||
|
||||
createDisposition == CreateDisposition.FILE_OVERWRITE_IF ||
|
||||
createDisposition == CreateDisposition.FILE_SUPERSEDE)
|
||||
{
|
||||
if (!requestedWriteAccess)
|
||||
{
|
||||
return NTStatus.STATUS_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
if (createDisposition == CreateDisposition.FILE_OVERWRITE ||
|
||||
createDisposition == CreateDisposition.FILE_OVERWRITE_IF)
|
||||
{
|
||||
// Truncate the file
|
||||
try
|
||||
{
|
||||
|
@ -169,6 +169,40 @@ namespace SMBLibrary.Server
|
|||
return status;
|
||||
}
|
||||
}
|
||||
else if (createDisposition == CreateDisposition.FILE_SUPERSEDE)
|
||||
{
|
||||
// Delete the old file
|
||||
try
|
||||
{
|
||||
fileSystem.Delete(path);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
state.LogToServer(Severity.Debug, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (forceDirectory)
|
||||
{
|
||||
state.LogToServer(Severity.Information, "CreateFile: Creating directory '{0}'", path);
|
||||
entry = fileSystem.CreateDirectory(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.LogToServer(Severity.Information, "CreateFile: Creating file '{0}'", path);
|
||||
entry = fileSystem.CreateFile(path);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NTStatus status = ToNTStatus(ex);
|
||||
state.LogToServer(Severity.Debug, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue