Follow POSIX write/append semantics in fileio_open (#276)

fileio_open previously treated all O_CREAT flags as CREATE_* flags in
CreateFile; CREATE_* always truncates files but O_CREAT only truncates
files when O_TRUNC is also set on POSIX platforms. This becomes
noticeable under SFTP sessions where remote files are opened with
O_APPEND: the file is instead truncated as in O_CREAT | O_TRUNC.

https://github.com/PowerShell/Win32-OpenSSH/issues/1078
This commit is contained in:
Daniel Sweet 2018-03-30 15:37:07 -04:00 committed by Manoj Ampalam
parent f607a0be96
commit 11726e3c8e
1 changed files with 4 additions and 2 deletions

View File

@ -295,7 +295,7 @@ static int
createFile_flags_setup(int flags, mode_t mode, struct createFile_flags* cf_flags)
{
/* check flags */
int rwflags = flags & 0x3, c_s_flags = flags & 0xfffffff0, ret = -1;
int rwflags = flags & 0x3, c_s_flags = flags & 0xfffffffc, ret = -1;
PSECURITY_DESCRIPTOR pSD = NULL;
wchar_t sddl[SDDL_LENGTH + 1] = { 0 }, owner_ace[MAX_ACE_LENGTH + 1] = {0}, everyone_ace[MAX_ACE_LENGTH + 1] = {0};
wchar_t owner_access[MAX_ATTRIBUTE_LENGTH + 1] = {0}, everyone_access[MAX_ATTRIBUTE_LENGTH + 1] = {0}, *sid_utf16 = NULL;
@ -341,8 +341,10 @@ createFile_flags_setup(int flags, mode_t mode, struct createFile_flags* cf_flags
if (c_s_flags & O_CREAT) {
if (c_s_flags & O_EXCL)
cf_flags->dwCreationDisposition = CREATE_NEW;
else
else if (c_s_flags & O_TRUNC)
cf_flags->dwCreationDisposition = CREATE_ALWAYS;
else
cf_flags->dwCreationDisposition = OPEN_ALWAYS;
}
if (c_s_flags & O_APPEND)