sftpserver.c: Add support for O_TRUNC while opening files

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Eshan Kelkar
2025-03-15 17:50:33 +05:30
committed by Jakub Jelen
parent 6c4e4a9e1c
commit a59d587060

View File

@@ -882,17 +882,26 @@ process_open(sftp_client_message client_msg)
SSH_LOG(SSH_LOG_PROTOCOL, "Processing open: filename %s, mode=0%o" PRIu32, SSH_LOG(SSH_LOG_PROTOCOL, "Processing open: filename %s, mode=0%o" PRIu32,
filename, mode); filename, mode);
if (((msg_flag & (uint32_t)SSH_FXF_READ) == SSH_FXF_READ) && if ((msg_flag & (uint32_t)SSH_FXF_WRITE) == SSH_FXF_WRITE) {
((msg_flag & (uint32_t)SSH_FXF_WRITE) == SSH_FXF_WRITE)) { if ((msg_flag & (uint32_t)SSH_FXF_READ) == SSH_FXF_READ) {
file_flag = O_RDWR; // file must exist /* Both read and write */
if ((msg_flag & (uint32_t)SSH_FXF_CREAT) == SSH_FXF_CREAT) file_flag = O_RDWR;
file_flag |= O_CREAT; } else {
} else if ((msg_flag & (uint32_t)SSH_FXF_WRITE) == SSH_FXF_WRITE) { /* Only write */
file_flag = O_WRONLY; file_flag = O_WRONLY;
if ((msg_flag & (uint32_t)SSH_FXF_APPEND) == SSH_FXF_APPEND) }
if ((msg_flag & (uint32_t)SSH_FXF_APPEND) == SSH_FXF_APPEND) {
file_flag |= O_APPEND; file_flag |= O_APPEND;
if ((msg_flag & (uint32_t)SSH_FXF_CREAT) == SSH_FXF_CREAT) }
if ((msg_flag & (uint32_t)SSH_FXF_CREAT) == SSH_FXF_CREAT) {
file_flag |= O_CREAT; file_flag |= O_CREAT;
}
if ((msg_flag & (uint32_t)SSH_FXF_TRUNC) == SSH_FXF_TRUNC) {
file_flag |= O_TRUNC;
}
} else if ((msg_flag & (uint32_t)SSH_FXF_READ) == SSH_FXF_READ) { } else if ((msg_flag & (uint32_t)SSH_FXF_READ) == SSH_FXF_READ) {
file_flag = O_RDONLY; file_flag = O_RDONLY;
} else { } else {