View | Details | Raw Unified | Return to bug 2828
Collapse All | Expand All

(-)a/PROTOCOL (+23 lines)
Lines 454-457 respond with a SSH_FXP_STATUS message. Link Here
454
This extension is advertised in the SSH_FXP_VERSION hello with version
454
This extension is advertised in the SSH_FXP_VERSION hello with version
455
"1".
455
"1".
456
456
457
10. sftp: Extension request "flock@openssh.com"
458
459
This request asks the server to call flock(2) on an open file handle.
460
461
	uint32		id
462
	string		"flock@openssh.com"
463
	string		handle
464
	uint32		op
465
466
On receiving this request, a server will call flock(handle_fd, op)
467
and will respond with a SSH_FXP_STATUS message.
468
469
Iterpretation of return code depends on op:
470
471
	1 LOCK_SH		SSH2_FX_OP_UNSUPPORTED (not implemented yet)
472
	2 LOCK_EX		SSH2_FX_OP_UNSUPPORTED (not implemented yet)
473
	5 LOCK_SH|LOCK_NB	SSH2_FX_EOF if already locked
474
	6 LOCK_EX|LOCK_NB	SSH2_FX_EOF if already locked
475
	8 LOCK_UN		SSH2_FX_OK
476
477
This extension is advertised in the SSH_FXP_VERSION hello with version
478
"1".
479
457
$OpenBSD: PROTOCOL,v 1.30 2016/04/08 06:35:54 djm Exp $
480
$OpenBSD: PROTOCOL,v 1.30 2016/04/08 06:35:54 djm Exp $
(-)a/sftp-server.c (+39 lines)
Lines 28-33 Link Here
28
#ifdef HAVE_SYS_STATVFS_H
28
#ifdef HAVE_SYS_STATVFS_H
29
#include <sys/statvfs.h>
29
#include <sys/statvfs.h>
30
#endif
30
#endif
31
#include <sys/file.h>
31
32
32
#include <dirent.h>
33
#include <dirent.h>
33
#include <errno.h>
34
#include <errno.h>
Lines 107-112 static void process_extended_statvfs(u_int32_t id); Link Here
107
static void process_extended_fstatvfs(u_int32_t id);
108
static void process_extended_fstatvfs(u_int32_t id);
108
static void process_extended_hardlink(u_int32_t id);
109
static void process_extended_hardlink(u_int32_t id);
109
static void process_extended_fsync(u_int32_t id);
110
static void process_extended_fsync(u_int32_t id);
111
static void process_extended_flock(u_int32_t id);
110
static void process_extended(u_int32_t id);
112
static void process_extended(u_int32_t id);
111
113
112
struct sftp_handler {
114
struct sftp_handler {
Lines 148-153 struct sftp_handler extended_handlers[] = { Link Here
148
	{ "fstatvfs", "fstatvfs@openssh.com", 0, process_extended_fstatvfs, 0 },
150
	{ "fstatvfs", "fstatvfs@openssh.com", 0, process_extended_fstatvfs, 0 },
149
	{ "hardlink", "hardlink@openssh.com", 0, process_extended_hardlink, 1 },
151
	{ "hardlink", "hardlink@openssh.com", 0, process_extended_hardlink, 1 },
150
	{ "fsync", "fsync@openssh.com", 0, process_extended_fsync, 1 },
152
	{ "fsync", "fsync@openssh.com", 0, process_extended_fsync, 1 },
153
	{ "flock", "flock@openssh.com", 0, process_extended_flock, 1 },
151
	{ NULL, NULL, 0, NULL, 0 }
154
	{ NULL, NULL, 0, NULL, 0 }
152
};
155
};
153
156
Lines 664-669 process_init(void) Link Here
664
	    /* hardlink extension */
667
	    /* hardlink extension */
665
	    (r = sshbuf_put_cstring(msg, "hardlink@openssh.com")) != 0 ||
668
	    (r = sshbuf_put_cstring(msg, "hardlink@openssh.com")) != 0 ||
666
	    (r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */
669
	    (r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */
670
	    /* flock extension */
671
	    (r = sshbuf_put_cstring(msg, "flock@openssh.com")) != 0 ||
672
	    (r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */
667
	    /* fsync extension */
673
	    /* fsync extension */
668
	    (r = sshbuf_put_cstring(msg, "fsync@openssh.com")) != 0 ||
674
	    (r = sshbuf_put_cstring(msg, "fsync@openssh.com")) != 0 ||
669
	    (r = sshbuf_put_cstring(msg, "1")) != 0) /* version */
675
	    (r = sshbuf_put_cstring(msg, "1")) != 0) /* version */
Lines 1369-1374 process_extended_fsync(u_int32_t id) Link Here
1369
	send_status(id, status);
1375
	send_status(id, status);
1370
}
1376
}
1371
1377
1378
static void
1379
process_extended_flock(u_int32_t id)
1380
{
1381
	int handle, fd, r, status = SSH2_FX_OP_UNSUPPORTED;
1382
	u_int32_t op;
1383
1384
	r = get_handle(iqueue, &handle);
1385
	if (r != 0)
1386
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
1387
1388
	r = sshbuf_get_u32(iqueue, &op);
1389
	if (r != 0)
1390
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
1391
1392
	debug3("request %u: flock (handle %u)", id, handle);
1393
	verbose("flock \"%s\" 0x%x", handle_to_name(handle), op);
1394
1395
	fd = handle_to_fd(handle);
1396
	if (fd < 0)
1397
		status = SSH2_FX_NO_SUCH_FILE;
1398
	else if (op == LOCK_UN || (op & LOCK_NB)) {
1399
		r = flock(fd, op);
1400
		if (r < 0 && errno == EWOULDBLOCK) {
1401
			status = SSH2_FX_EOF;
1402
		} else if (r < 0) {
1403
			status = errno_to_portable(errno);
1404
		} else {
1405
			status = SSH2_FX_OK;
1406
		}
1407
	}
1408
	send_status(id, status);
1409
}
1410
1372
static void
1411
static void
1373
process_extended(u_int32_t id)
1412
process_extended(u_int32_t id)
1374
{
1413
{

Return to bug 2828