[prev in list] [next in list] [prev in thread] [next in thread]
List: openssh-unix-dev
Subject: [PATCH] Implement SSH2_FXF_APPEND
From: Ross Lagerwall <rosslagerwall () gmail ! com>
Date: 2013-09-30 8:22:23
Message-ID: 20130930082223.GA12650 () hobo
[Download RAW message or body]
Hi,
Here is a fairly simple patch to implement append mode for the sftp
server. The patch was tested against the portable version but it
applies cleanly to the normal version.
Regards
--
Ross Lagerwall
["sftp_append.patch" (text/x-diff)]
Index: sftp-server.c
===================================================================
RCS file: /cvs/openssh/sftp-server.c,v
retrieving revision 1.114
diff -u -p -r1.114 sftp-server.c
--- sftp-server.c 1 Jun 2013 21:31:19 -0000 1.114
+++ sftp-server.c 30 Sep 2013 08:16:57 -0000
@@ -130,6 +130,8 @@ flags_from_portable(int pflags)
} else if (pflags & SSH2_FXF_WRITE) {
flags = O_WRONLY;
}
+ if (pflags & SSH2_FXF_APPEND)
+ flags |= O_APPEND;
if (pflags & SSH2_FXF_CREAT)
flags |= O_CREAT;
if (pflags & SSH2_FXF_TRUNC)
@@ -156,6 +158,8 @@ string_from_portable(int pflags)
PAPPEND("READ")
if (pflags & SSH2_FXF_WRITE)
PAPPEND("WRITE")
+ if (pflags & SSH2_FXF_APPEND)
+ PAPPEND("APPEND")
if (pflags & SSH2_FXF_CREAT)
PAPPEND("CREATE")
if (pflags & SSH2_FXF_TRUNC)
@@ -179,6 +183,7 @@ struct Handle {
int use;
DIR *dirp;
int fd;
+ int flags;
char *name;
u_int64_t bytes_read, bytes_write;
int next_unused;
@@ -202,7 +207,7 @@ static void handle_unused(int i)
}
static int
-handle_new(int use, const char *name, int fd, DIR *dirp)
+handle_new(int use, const char *name, int fd, int flags, DIR *dirp)
{
int i;
@@ -220,6 +225,7 @@ handle_new(int use, const char *name, in
handles[i].use = use;
handles[i].dirp = dirp;
handles[i].fd = fd;
+ handles[i].flags = flags;
handles[i].name = xstrdup(name);
handles[i].bytes_read = handles[i].bytes_write = 0;
@@ -282,6 +288,14 @@ handle_to_fd(int handle)
return -1;
}
+static int
+handle_to_flags(int handle)
+{
+ if (handle_is_ok(handle, HANDLE_FILE))
+ return handles[handle].flags;
+ return -1;
+}
+
static void
handle_update_read(int handle, ssize_t bytes)
{
@@ -567,7 +581,7 @@ process_open(void)
if (fd < 0) {
status = errno_to_portable(errno);
} else {
- handle = handle_new(HANDLE_FILE, name, fd, NULL);
+ handle = handle_new(HANDLE_FILE, name, fd, flags, NULL);
if (handle < 0) {
close(fd);
} else {
@@ -660,7 +674,8 @@ process_write(void)
else if (readonly)
status = SSH2_FX_PERMISSION_DENIED;
else {
- if (lseek(fd, off, SEEK_SET) < 0) {
+ if (!(handle_to_flags(handle) & O_APPEND) &&
+ lseek(fd, off, SEEK_SET) < 0) {
status = errno_to_portable(errno);
error("process_write: seek failed");
} else {
@@ -893,7 +908,7 @@ process_opendir(void)
if (dirp == NULL) {
status = errno_to_portable(errno);
} else {
- handle = handle_new(HANDLE_DIR, path, 0, dirp);
+ handle = handle_new(HANDLE_DIR, path, 0, 0, dirp);
if (handle < 0) {
closedir(dirp);
} else {
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic