diff options
author | Damien Miller <djm@mindrot.org> | 2013-10-17 11:48:52 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2013-10-17 11:48:52 +1100 |
commit | f29238e67471a7f1088a99c3c3dbafce76b790cf (patch) | |
tree | 39ea232a72df52b4adbc3affea0108d8b0f45b42 /sftp-server.c | |
parent | 51682faa599550a69d8120e5e2bdbdc0625ef4be (diff) |
- djm@cvs.openbsd.org 2013/10/17 00:30:13
[PROTOCOL sftp-client.c sftp-client.h sftp-server.c sftp.1 sftp.c]
fsync@openssh.com protocol extension for sftp-server
client support to allow calling fsync() faster successful transfer
patch mostly by imorgan AT nas.nasa.gov; bz#1798
"fine" markus@ "grumble OK" deraadt@ "doesn't sound bad to me" millert@
Diffstat (limited to 'sftp-server.c')
-rw-r--r-- | sftp-server.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/sftp-server.c b/sftp-server.c index 3056c454e..ad158f8e2 100644 --- a/sftp-server.c +++ b/sftp-server.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp-server.c,v 1.101 2013/10/14 23:28:23 djm Exp $ */ | 1 | /* $OpenBSD: sftp-server.c,v 1.102 2013/10/17 00:30:13 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -112,6 +112,7 @@ static void process_extended_posix_rename(u_int32_t id); | |||
112 | static void process_extended_statvfs(u_int32_t id); | 112 | static void process_extended_statvfs(u_int32_t id); |
113 | static void process_extended_fstatvfs(u_int32_t id); | 113 | static void process_extended_fstatvfs(u_int32_t id); |
114 | static void process_extended_hardlink(u_int32_t id); | 114 | static void process_extended_hardlink(u_int32_t id); |
115 | static void process_extended_fsync(u_int32_t id); | ||
115 | static void process_extended(u_int32_t id); | 116 | static void process_extended(u_int32_t id); |
116 | 117 | ||
117 | struct sftp_handler { | 118 | struct sftp_handler { |
@@ -152,6 +153,7 @@ struct sftp_handler extended_handlers[] = { | |||
152 | { "statvfs", "statvfs@openssh.com", 0, process_extended_statvfs, 0 }, | 153 | { "statvfs", "statvfs@openssh.com", 0, process_extended_statvfs, 0 }, |
153 | { "fstatvfs", "fstatvfs@openssh.com", 0, process_extended_fstatvfs, 0 }, | 154 | { "fstatvfs", "fstatvfs@openssh.com", 0, process_extended_fstatvfs, 0 }, |
154 | { "hardlink", "hardlink@openssh.com", 0, process_extended_hardlink, 1 }, | 155 | { "hardlink", "hardlink@openssh.com", 0, process_extended_hardlink, 1 }, |
156 | { "fsync", "fsync@openssh.com", 0, process_extended_fsync, 1 }, | ||
155 | { NULL, NULL, 0, NULL, 0 } | 157 | { NULL, NULL, 0, NULL, 0 } |
156 | }; | 158 | }; |
157 | 159 | ||
@@ -652,6 +654,9 @@ process_init(void) | |||
652 | /* hardlink extension */ | 654 | /* hardlink extension */ |
653 | buffer_put_cstring(&msg, "hardlink@openssh.com"); | 655 | buffer_put_cstring(&msg, "hardlink@openssh.com"); |
654 | buffer_put_cstring(&msg, "1"); /* version */ | 656 | buffer_put_cstring(&msg, "1"); /* version */ |
657 | /* fsync extension */ | ||
658 | buffer_put_cstring(&msg, "fsync@openssh.com"); | ||
659 | buffer_put_cstring(&msg, "1"); /* version */ | ||
655 | send_msg(&msg); | 660 | send_msg(&msg); |
656 | buffer_free(&msg); | 661 | buffer_free(&msg); |
657 | } | 662 | } |
@@ -1298,6 +1303,23 @@ process_extended_hardlink(u_int32_t id) | |||
1298 | } | 1303 | } |
1299 | 1304 | ||
1300 | static void | 1305 | static void |
1306 | process_extended_fsync(u_int32_t id) | ||
1307 | { | ||
1308 | int handle, fd, ret, status = SSH2_FX_OP_UNSUPPORTED; | ||
1309 | |||
1310 | handle = get_handle(); | ||
1311 | debug3("request %u: fsync (handle %u)", id, handle); | ||
1312 | verbose("fsync \"%s\"", handle_to_name(handle)); | ||
1313 | if ((fd = handle_to_fd(handle)) < 0) | ||
1314 | status = SSH2_FX_NO_SUCH_FILE; | ||
1315 | else if (handle_is_ok(handle, HANDLE_FILE)) { | ||
1316 | ret = fsync(fd); | ||
1317 | status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; | ||
1318 | } | ||
1319 | send_status(id, status); | ||
1320 | } | ||
1321 | |||
1322 | static void | ||
1301 | process_extended(u_int32_t id) | 1323 | process_extended(u_int32_t id) |
1302 | { | 1324 | { |
1303 | char *request; | 1325 | char *request; |