View | Details | Raw Unified | Return to bug 1555 | Differences between
and this patch

Collapse All | Expand All

(-)ssh.orig/sftp-client.c (-1 / +39 lines)
Lines 63-68 struct sftp_conn { Link Here
63
#define SFTP_EXT_POSIX_RENAME	0x00000001
63
#define SFTP_EXT_POSIX_RENAME	0x00000001
64
#define SFTP_EXT_STATVFS	0x00000002
64
#define SFTP_EXT_STATVFS	0x00000002
65
#define SFTP_EXT_FSTATVFS	0x00000004
65
#define SFTP_EXT_FSTATVFS	0x00000004
66
#define SFTP_EXT_LINK		0x00000008
66
	u_int exts;
67
	u_int exts;
67
};
68
};
68
69
Lines 328-337 do_init(int fd_in, int fd_out, u_int tra Link Here
328
		    strcmp(value, "2") == 0) {
329
		    strcmp(value, "2") == 0) {
329
			exts |= SFTP_EXT_STATVFS;
330
			exts |= SFTP_EXT_STATVFS;
330
			known = 1;
331
			known = 1;
331
		} if (strcmp(name, "fstatvfs@openssh.com") == 0 &&
332
		} else if (strcmp(name, "fstatvfs@openssh.com") == 0 &&
332
		    strcmp(value, "2") == 0) {
333
		    strcmp(value, "2") == 0) {
333
			exts |= SFTP_EXT_FSTATVFS;
334
			exts |= SFTP_EXT_FSTATVFS;
334
			known = 1;
335
			known = 1;
336
		} else if (strcmp(name, "link@openssh.com") == 0 &&
337
		    strcmp(value, "1") == 0) {
338
			exts |= SFTP_EXT_LINK;
339
			known = 1;
335
		}
340
		}
336
		if (known) {
341
		if (known) {
337
			debug2("Server supports extension \"%s\" revision %s",
342
			debug2("Server supports extension \"%s\" revision %s",
Lines 731-736 do_rename(struct sftp_conn *conn, char * Link Here
731
		    newpath, fx2txt(status));
736
		    newpath, fx2txt(status));
732
737
733
	return(status);
738
	return(status);
739
}
740
741
int
742
do_link(struct sftp_conn *conn, char *oldpath, char *newpath)
743
{
744
	Buffer msg;
745
	u_int status, id;
746
747
	buffer_init(&msg);
748
749
	/* Send link request */
750
	id = conn->msg_id++;
751
	if ((conn->exts & SFTP_EXT_LINK) == 0) {
752
		error("Server does not support link@openssh.com extension");
753
		return -1;
754
	}
755
756
	buffer_put_char(&msg, SSH2_FXP_EXTENDED);
757
	buffer_put_int(&msg, id);
758
	buffer_put_cstring(&msg, "link@openssh.com");
759
	buffer_put_cstring(&msg, oldpath);
760
	buffer_put_cstring(&msg, newpath);
761
	send_msg(conn->fd_out, &msg);
762
	debug3("Sent message link@openssh.com \"%s\" -> \"%s\"",
763
	       oldpath, newpath);
764
	buffer_free(&msg);
765
766
	status = get_status(conn->fd_in, id);
767
	if (status != SSH2_FX_OK)
768
		error("Couldn't link file \"%s\" to \"%s\": %s", oldpath,
769
		    newpath, fx2txt(status));
770
771
	return(status);
734
}
772
}
735
773
736
int
774
int
(-)ssh.orig/sftp-client.h (+3 lines)
Lines 94-99 int do_statvfs(struct sftp_conn *, const Link Here
94
/* Rename 'oldpath' to 'newpath' */
94
/* Rename 'oldpath' to 'newpath' */
95
int do_rename(struct sftp_conn *, char *, char *);
95
int do_rename(struct sftp_conn *, char *, char *);
96
96
97
/* Link 'oldpath' to 'newpath' */
98
int do_link(struct sftp_conn *, char *, char *);
99
97
/* Rename 'oldpath' to 'newpath' */
100
/* Rename 'oldpath' to 'newpath' */
98
int do_symlink(struct sftp_conn *, char *, char *);
101
int do_symlink(struct sftp_conn *, char *, char *);
99
102
(-)ssh.orig/sftp-server.c (+22 lines)
Lines 523-528 process_init(void) Link Here
523
	/* fstatvfs extension */
523
	/* fstatvfs extension */
524
	buffer_put_cstring(&msg, "fstatvfs@openssh.com");
524
	buffer_put_cstring(&msg, "fstatvfs@openssh.com");
525
	buffer_put_cstring(&msg, "2"); /* version */
525
	buffer_put_cstring(&msg, "2"); /* version */
526
	/* link extension */
527
	buffer_put_cstring(&msg, "link@openssh.com");
528
	buffer_put_cstring(&msg, "1"); /* version */
526
	send_msg(&msg);
529
	send_msg(&msg);
527
	buffer_free(&msg);
530
	buffer_free(&msg);
528
}
531
}
Lines 1153-1158 process_extended_fstatvfs(u_int32_t id) Link Here
1153
}
1156
}
1154
1157
1155
static void
1158
static void
1159
process_extended_link(u_int32_t id)
1160
{
1161
	char *oldpath, *newpath;
1162
1163
	oldpath = get_string(NULL);
1164
	newpath = get_string(NULL);
1165
	debug3("request %u: link", id);
1166
	logit("link old \"%s\" new \"%s\"", oldpath, newpath);
1167
	if (link(oldpath, newpath) == -1)
1168
		send_status(id, errno_to_portable(errno));
1169
	else
1170
		send_status(id, SSH2_FX_OK);
1171
	xfree(oldpath);
1172
	xfree(newpath);
1173
}
1174
1175
static void
1156
process_extended(void)
1176
process_extended(void)
1157
{
1177
{
1158
	u_int32_t id;
1178
	u_int32_t id;
Lines 1166-1171 process_extended(void) Link Here
1166
		process_extended_statvfs(id);
1186
		process_extended_statvfs(id);
1167
	else if (strcmp(request, "fstatvfs@openssh.com") == 0)
1187
	else if (strcmp(request, "fstatvfs@openssh.com") == 0)
1168
		process_extended_fstatvfs(id);
1188
		process_extended_fstatvfs(id);
1189
	else if (strcmp(request, "link@openssh.com") == 0)
1190
		process_extended_link(id);
1169
	else
1191
	else
1170
		send_status(id, SSH2_FX_OP_UNSUPPORTED);	/* MUST */
1192
		send_status(id, SSH2_FX_OP_UNSUPPORTED);	/* MUST */
1171
	xfree(request);
1193
	xfree(request);
(-)ssh.orig/sftp.c (+9 lines)
Lines 98-103 int remote_glob(struct sftp_conn *, cons Link Here
98
#define I_GET		5
98
#define I_GET		5
99
#define I_HELP		6
99
#define I_HELP		6
100
#define I_LCHDIR	7
100
#define I_LCHDIR	7
101
#define I_LINK		25
101
#define I_LLS		8
102
#define I_LLS		8
102
#define I_LMKDIR	9
103
#define I_LMKDIR	9
103
#define I_LPWD		10
104
#define I_LPWD		10
Lines 135-140 static const struct CMD cmds[] = { Link Here
135
	{ "help",	I_HELP },
136
	{ "help",	I_HELP },
136
	{ "lcd",	I_LCHDIR },
137
	{ "lcd",	I_LCHDIR },
137
	{ "lchdir",	I_LCHDIR },
138
	{ "lchdir",	I_LCHDIR },
139
	{ "link",	I_LINK },
138
	{ "lls",	I_LLS },
140
	{ "lls",	I_LLS },
139
	{ "lmkdir",	I_LMKDIR },
141
	{ "lmkdir",	I_LMKDIR },
140
	{ "ln",		I_SYMLINK },
142
	{ "ln",		I_SYMLINK },
Lines 198-203 help(void) Link Here
198
	    "get [-P] remote-path [local-path]  Download file\n"
200
	    "get [-P] remote-path [local-path]  Download file\n"
199
	    "help                               Display this help text\n"
201
	    "help                               Display this help text\n"
200
	    "lcd path                           Change local directory to 'path'\n"
202
	    "lcd path                           Change local directory to 'path'\n"
203
	    "link oldpath newpath               Create hard link to remote file\n"
201
	    "lls [ls-options [path]]            Display local directory listing\n"
204
	    "lls [ls-options [path]]            Display local directory listing\n"
202
	    "lmkdir path                        Create local directory\n"
205
	    "lmkdir path                        Create local directory\n"
203
	    "ln oldpath newpath                 Symlink remote file\n"
206
	    "ln oldpath newpath                 Symlink remote file\n"
Lines 1111-1116 parse_args(const char **cpp, int *pflag, Link Here
1111
		}
1114
		}
1112
		break;
1115
		break;
1113
	case I_RENAME:
1116
	case I_RENAME:
1117
	case I_LINK:
1114
	case I_SYMLINK:
1118
	case I_SYMLINK:
1115
		if (argc - optidx < 2) {
1119
		if (argc - optidx < 2) {
1116
			error("You must specify two paths after a %s "
1120
			error("You must specify two paths after a %s "
Lines 1250-1255 parse_dispatch_command(struct sftp_conn Link Here
1250
		path2 = make_absolute(path2, *pwd);
1254
		path2 = make_absolute(path2, *pwd);
1251
		err = do_rename(conn, path1, path2);
1255
		err = do_rename(conn, path1, path2);
1252
		break;
1256
		break;
1257
	case I_LINK:
1258
		path1 = make_absolute(path1, *pwd);
1259
		path2 = make_absolute(path2, *pwd);
1260
		err = do_link(conn, path1, path2);
1261
		break;
1253
	case I_SYMLINK:
1262
	case I_SYMLINK:
1254
		path2 = make_absolute(path2, *pwd);
1263
		path2 = make_absolute(path2, *pwd);
1255
		err = do_symlink(conn, path1, path2);
1264
		err = do_symlink(conn, path1, path2);
(-)ssh.orig/PROTOCOL (+16 lines)
Lines 240-243 The values of the f_flag bitmask are as Link Here
240
Both the "statvfs@openssh.com" and "fstatvfs@openssh.com" extensions are
240
Both the "statvfs@openssh.com" and "fstatvfs@openssh.com" extensions are
241
advertised in the SSH_FXP_VERSION hello with version "2".
241
advertised in the SSH_FXP_VERSION hello with version "2".
242
242
243
10. sftp: Extension request "link@openssh.com"
244
245
This request is for creating a hard link to a regular file. This
246
request is implemented as a SSH_FXP_EXTENDED request with the
247
following format:
248
249
	uint32		id
250
	string		"link@openssh.com"
251
	string		oldpath
252
	string		newpath
253
254
On receiving this request the server will perform the operation
255
link(oldpath, newpath) and will respond with a SSH_FXP_STATUS message.
256
This extension is advertised in the SSH_FXP_VERSION hello with version
257
"1".
258
243
$OpenBSD: PROTOCOL,v 1.11 2008/07/05 05:16:01 djm Exp $
259
$OpenBSD: PROTOCOL,v 1.11 2008/07/05 05:16:01 djm Exp $

Return to bug 1555