summaryrefslogtreecommitdiff
path: root/sftp-server.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-12-05 09:02:47 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-12-05 09:02:47 +1100
commitaf1f90925494deba97a4b877798cf250f7dc75cf (patch)
treec6e44e388c2bd4ca0caad6ce9f422576fe650b57 /sftp-server.c
parentadab6f12992c522e1208fa2bdf89ce572840ccf8 (diff)
- djm@cvs.openbsd.org 2010/12/04 00:18:01
[sftp-server.c sftp.1 sftp-client.h sftp.c PROTOCOL sftp-client.c] add a protocol extension to support a hard link operation. It is available through the "ln" command in the client. The old "ln" behaviour of creating a symlink is available using its "-s" option or through the preexisting "symlink" command; based on a patch from miklos AT szeredi.hu in bz#1555; ok markus@
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/sftp-server.c b/sftp-server.c
index 47edcd0a..b268d088 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-server.c,v 1.92 2010/11/04 02:45:34 djm Exp $ */
+/* $OpenBSD: sftp-server.c,v 1.93 2010/12/04 00:18:01 djm Exp $ */
/*
* Copyright (c) 2000-2004 Markus Friedl. All rights reserved.
*
@@ -535,6 +535,9 @@ process_init(void)
/* fstatvfs extension */
buffer_put_cstring(&msg, "fstatvfs@openssh.com");
buffer_put_cstring(&msg, "2"); /* version */
+ /* hardlink extension */
+ buffer_put_cstring(&msg, "hardlink@openssh.com");
+ buffer_put_cstring(&msg, "1"); /* version */
send_msg(&msg);
buffer_free(&msg);
}
@@ -1223,6 +1226,27 @@ process_extended_fstatvfs(u_int32_t id)
}
static void
+process_extended_hardlink(u_int32_t id)
+{
+ char *oldpath, *newpath;
+ int ret, status;
+
+ oldpath = get_string(NULL);
+ newpath = get_string(NULL);
+ debug3("request %u: hardlink", id);
+ logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath);
+ if (readonly)
+ status = SSH2_FX_PERMISSION_DENIED;
+ else {
+ ret = link(oldpath, newpath);
+ status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
+ }
+ send_status(id, status);
+ xfree(oldpath);
+ xfree(newpath);
+}
+
+static void
process_extended(void)
{
u_int32_t id;
@@ -1236,6 +1260,8 @@ process_extended(void)
process_extended_statvfs(id);
else if (strcmp(request, "fstatvfs@openssh.com") == 0)
process_extended_fstatvfs(id);
+ else if (strcmp(request, "hardlink@openssh.com") == 0)
+ process_extended_hardlink(id);
else
send_status(id, SSH2_FX_OP_UNSUPPORTED); /* MUST */
xfree(request);