Bugzilla – Attachment 3117 Details for
Bug 2828
Extension for BSD style advisory file locking operations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Suggested patch 1
66.patch (text/plain), 3.85 KB, created by
github
on 2018-01-31 23:54:36 AEDT
(
hide
)
Description:
Suggested patch 1
Filename:
MIME Type:
Creator:
github
Created:
2018-01-31 23:54:36 AEDT
Size:
3.85 KB
patch
obsolete
>From 6a2529aa2cc72829609a6c45b9f91bda317932fe Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Christian=20H=C3=A4ggstr=C3=B6m?= > <christian.haggstrom@orexplore.com> >Date: Mon, 15 May 2017 08:21:41 +0200 >Subject: [PATCH] Add support for file locking operations LOCK_EX|LOCK_NB and > LOCK_SH|LOCK_NB to sftp-server. Allocate a new extension string for the flock > operations. > >--- > PROTOCOL | 23 +++++++++++++++++++++++ > sftp-server.c | 39 +++++++++++++++++++++++++++++++++++++++ > 2 files changed, 62 insertions(+) > >diff --git a/PROTOCOL b/PROTOCOL >index 192da55b2..113bdcc75 100644 >--- a/PROTOCOL >+++ b/PROTOCOL >@@ -454,4 +454,27 @@ respond with a SSH_FXP_STATUS message. > This extension is advertised in the SSH_FXP_VERSION hello with version > "1". > >+10. sftp: Extension request "flock@openssh.com" >+ >+This request asks the server to call flock(2) on an open file handle. >+ >+ uint32 id >+ string "flock@openssh.com" >+ string handle >+ uint32 op >+ >+On receiving this request, a server will call flock(handle_fd, op) >+and will respond with a SSH_FXP_STATUS message. >+ >+Iterpretation of return code depends on op: >+ >+ 1 LOCK_SH SSH2_FX_OP_UNSUPPORTED (not implemented yet) >+ 2 LOCK_EX SSH2_FX_OP_UNSUPPORTED (not implemented yet) >+ 5 LOCK_SH|LOCK_NB SSH2_FX_EOF if already locked >+ 6 LOCK_EX|LOCK_NB SSH2_FX_EOF if already locked >+ 8 LOCK_UN SSH2_FX_OK >+ >+This extension is advertised in the SSH_FXP_VERSION hello with version >+"1". >+ > $OpenBSD: PROTOCOL,v 1.30 2016/04/08 06:35:54 djm Exp $ >diff --git a/sftp-server.c b/sftp-server.c >index df0fb5068..a1c3dd358 100644 >--- a/sftp-server.c >+++ b/sftp-server.c >@@ -28,6 +28,7 @@ > #ifdef HAVE_SYS_STATVFS_H > #include <sys/statvfs.h> > #endif >+#include <sys/file.h> > > #include <dirent.h> > #include <errno.h> >@@ -107,6 +108,7 @@ static void process_extended_statvfs(u_int32_t id); > static void process_extended_fstatvfs(u_int32_t id); > static void process_extended_hardlink(u_int32_t id); > static void process_extended_fsync(u_int32_t id); >+static void process_extended_flock(u_int32_t id); > static void process_extended(u_int32_t id); > > struct sftp_handler { >@@ -148,6 +150,7 @@ struct sftp_handler extended_handlers[] = { > { "fstatvfs", "fstatvfs@openssh.com", 0, process_extended_fstatvfs, 0 }, > { "hardlink", "hardlink@openssh.com", 0, process_extended_hardlink, 1 }, > { "fsync", "fsync@openssh.com", 0, process_extended_fsync, 1 }, >+ { "flock", "flock@openssh.com", 0, process_extended_flock, 1 }, > { NULL, NULL, 0, NULL, 0 } > }; > >@@ -664,6 +667,9 @@ process_init(void) > /* hardlink extension */ > (r = sshbuf_put_cstring(msg, "hardlink@openssh.com")) != 0 || > (r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */ >+ /* flock extension */ >+ (r = sshbuf_put_cstring(msg, "flock@openssh.com")) != 0 || >+ (r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */ > /* fsync extension */ > (r = sshbuf_put_cstring(msg, "fsync@openssh.com")) != 0 || > (r = sshbuf_put_cstring(msg, "1")) != 0) /* version */ >@@ -1369,6 +1375,39 @@ process_extended_fsync(u_int32_t id) > send_status(id, status); > } > >+static void >+process_extended_flock(u_int32_t id) >+{ >+ int handle, fd, r, status = SSH2_FX_OP_UNSUPPORTED; >+ u_int32_t op; >+ >+ r = get_handle(iqueue, &handle); >+ if (r != 0) >+ fatal("%s: buffer error: %s", __func__, ssh_err(r)); >+ >+ r = sshbuf_get_u32(iqueue, &op); >+ if (r != 0) >+ fatal("%s: buffer error: %s", __func__, ssh_err(r)); >+ >+ debug3("request %u: flock (handle %u)", id, handle); >+ verbose("flock \"%s\" 0x%x", handle_to_name(handle), op); >+ >+ fd = handle_to_fd(handle); >+ if (fd < 0) >+ status = SSH2_FX_NO_SUCH_FILE; >+ else if (op == LOCK_UN || (op & LOCK_NB)) { >+ r = flock(fd, op); >+ if (r < 0 && errno == EWOULDBLOCK) { >+ status = SSH2_FX_EOF; >+ } else if (r < 0) { >+ status = errno_to_portable(errno); >+ } else { >+ status = SSH2_FX_OK; >+ } >+ } >+ send_status(id, status); >+} >+ > static void > process_extended(u_int32_t id) > {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2828
: 3117