forked from openbsd/ports
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SFTP protocol extension to allow the server to expand ~-prefixed
paths, in particular ~user ones. Allows scp in sftp mode to accept these paths, like scp in rcp mode does. prompted by and much discussion deraadt@ ok markus@
- Loading branch information
Showing
7 changed files
with
187 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,25 @@ limits. | |
This extension is advertised in the SSH_FXP_VERSION hello with version | ||
"1". | ||
|
||
3.9. sftp: Extension request "[email protected]" | ||
|
||
This request supports canonicalisation of relative paths and | ||
those that need tilde-expansion, i.e. "~", "~/..." and "~user/..." | ||
These paths are expanded using shell-like rules and the resultant | ||
path is canonicalised similarly to SSH2_FXP_REALPATH. | ||
|
||
It is implemented as a SSH_FXP_EXTENDED request with the following | ||
format: | ||
|
||
uint32 id | ||
string "[email protected]" | ||
string path | ||
|
||
Its reply is the same format as that of SSH2_FXP_REALPATH. | ||
|
||
This extension is advertised in the SSH_FXP_VERSION hello with version | ||
"1". | ||
|
||
4. Miscellaneous changes | ||
|
||
4.1 Public key format | ||
|
@@ -556,4 +575,4 @@ OpenSSH's connection multiplexing uses messages as described in | |
PROTOCOL.mux over a Unix domain socket for communications between a | ||
master instance and later clients. | ||
|
||
$OpenBSD: PROTOCOL,v 1.41 2021/02/18 02:49:35 djm Exp $ | ||
$OpenBSD: PROTOCOL,v 1.42 2021/08/09 23:47:44 djm Exp $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: misc.h,v 1.97 2021/06/08 06:54:40 djm Exp $ */ | ||
/* $OpenBSD: misc.h,v 1.98 2021/08/09 23:47:44 djm Exp $ */ | ||
|
||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
|
@@ -71,6 +71,7 @@ int parse_user_host_port(const char *, char **, char **, int *); | |
int parse_uri(const char *, const char *, char **, char **, int *, char **); | ||
int convtime(const char *); | ||
const char *fmt_timeframe(time_t t); | ||
int tilde_expand(const char *, uid_t, char **); | ||
char *tilde_expand_filename(const char *, uid_t); | ||
|
||
char *dollar_expand(int *, const char *string, ...); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: sftp-client.c,v 1.153 2021/08/09 07:16:09 djm Exp $ */ | ||
/* $OpenBSD: sftp-client.c,v 1.154 2021/08/09 23:47:44 djm Exp $ */ | ||
/* | ||
* Copyright (c) 2001-2004 Damien Miller <[email protected]> | ||
* | ||
|
@@ -82,6 +82,7 @@ struct sftp_conn { | |
#define SFTP_EXT_FSYNC 0x00000010 | ||
#define SFTP_EXT_LSETSTAT 0x00000020 | ||
#define SFTP_EXT_LIMITS 0x00000040 | ||
#define SFTP_EXT_PATH_EXPAND 0x00000080 | ||
u_int exts; | ||
u_int64_t limit_kbps; | ||
struct bwlimit bwlimit_in, bwlimit_out; | ||
|
@@ -509,6 +510,10 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests, | |
strcmp((char *)value, "1") == 0) { | ||
ret->exts |= SFTP_EXT_LIMITS; | ||
known = 1; | ||
} else if (strcmp(name, "[email protected]") == 0 && | ||
strcmp((char *)value, "1") == 0) { | ||
ret->exts |= SFTP_EXT_PATH_EXPAND; | ||
known = 1; | ||
} | ||
if (known) { | ||
debug2("Server supports extension \"%s\" revision %s", | ||
|
@@ -944,23 +949,36 @@ do_fsetstat(struct sftp_conn *conn, const u_char *handle, u_int handle_len, | |
return status == SSH2_FX_OK ? 0 : -1; | ||
} | ||
|
||
char * | ||
do_realpath(struct sftp_conn *conn, const char *path) | ||
/* Implements both the realpath and expand-path operations */ | ||
static char * | ||
do_realpath_expand(struct sftp_conn *conn, const char *path, int expand) | ||
{ | ||
struct sshbuf *msg; | ||
u_int expected_id, count, id; | ||
char *filename, *longname; | ||
Attrib a; | ||
u_char type; | ||
int r; | ||
const char *what = "SSH2_FXP_REALPATH"; | ||
|
||
expected_id = id = conn->msg_id++; | ||
send_string_request(conn, id, SSH2_FXP_REALPATH, path, | ||
strlen(path)); | ||
|
||
if (expand) | ||
what = "[email protected]"; | ||
if ((msg = sshbuf_new()) == NULL) | ||
fatal_f("sshbuf_new failed"); | ||
|
||
expected_id = id = conn->msg_id++; | ||
if (expand) { | ||
if ((r = sshbuf_put_u8(msg, SSH2_FXP_EXTENDED)) != 0 || | ||
(r = sshbuf_put_u32(msg, id)) != 0 || | ||
(r = sshbuf_put_cstring(msg, | ||
"[email protected]")) != 0 || | ||
(r = sshbuf_put_cstring(msg, path)) != 0) | ||
fatal_fr(r, "compose %s", what); | ||
send_msg(conn, msg); | ||
} else { | ||
send_string_request(conn, id, SSH2_FXP_REALPATH, | ||
path, strlen(path)); | ||
} | ||
get_msg(conn, msg); | ||
if ((r = sshbuf_get_u8(msg, &type)) != 0 || | ||
(r = sshbuf_get_u32(msg, &id)) != 0) | ||
|
@@ -984,15 +1002,14 @@ do_realpath(struct sftp_conn *conn, const char *path) | |
if ((r = sshbuf_get_u32(msg, &count)) != 0) | ||
fatal_fr(r, "parse count"); | ||
if (count != 1) | ||
fatal("Got multiple names (%d) from SSH_FXP_REALPATH", count); | ||
fatal("Got multiple names (%d) from %s", count, what); | ||
|
||
if ((r = sshbuf_get_cstring(msg, &filename, NULL)) != 0 || | ||
(r = sshbuf_get_cstring(msg, &longname, NULL)) != 0 || | ||
(r = decode_attrib(msg, &a)) != 0) | ||
fatal_fr(r, "parse filename/attrib"); | ||
|
||
debug3("SSH_FXP_REALPATH %s -> %s size %lu", path, filename, | ||
(unsigned long)a.size); | ||
debug3("%s %s -> %s", what, path, filename); | ||
|
||
free(longname); | ||
|
||
|
@@ -1001,6 +1018,28 @@ do_realpath(struct sftp_conn *conn, const char *path) | |
return(filename); | ||
} | ||
|
||
char * | ||
do_realpath(struct sftp_conn *conn, const char *path) | ||
{ | ||
return do_realpath_expand(conn, path, 0); | ||
} | ||
|
||
int | ||
can_expand_path(struct sftp_conn *conn) | ||
{ | ||
return (conn->exts & SFTP_EXT_PATH_EXPAND) != 0; | ||
} | ||
|
||
char * | ||
do_expand_path(struct sftp_conn *conn, const char *path) | ||
{ | ||
if (!can_expand_path(conn)) { | ||
debug3_f("no server support, fallback to realpath"); | ||
return do_realpath_expand(conn, path, 0); | ||
} | ||
return do_realpath_expand(conn, path, 1); | ||
} | ||
|
||
int | ||
do_rename(struct sftp_conn *conn, const char *oldpath, const char *newpath, | ||
int force_legacy) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: sftp-client.h,v 1.33 2021/08/07 00:12:09 djm Exp $ */ | ||
/* $OpenBSD: sftp-client.h,v 1.34 2021/08/09 23:47:44 djm Exp $ */ | ||
|
||
/* | ||
* Copyright (c) 2001-2004 Damien Miller <[email protected]> | ||
|
@@ -107,11 +107,17 @@ int do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a); | |
/* Canonicalise 'path' - caller must free result */ | ||
char *do_realpath(struct sftp_conn *, const char *); | ||
|
||
/* Canonicalisation with tilde expansion (requires server extension) */ | ||
char *do_expand_path(struct sftp_conn *, const char *); | ||
|
||
/* Returns non-zero if server can tilde-expand paths */ | ||
int can_expand_path(struct sftp_conn *); | ||
|
||
/* Get statistics for filesystem hosting file at "path" */ | ||
int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int); | ||
|
||
/* Rename 'oldpath' to 'newpath' */ | ||
int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy); | ||
int do_rename(struct sftp_conn *, const char *, const char *, int); | ||
|
||
/* Link 'oldpath' to 'newpath' */ | ||
int do_hardlink(struct sftp_conn *, const char *, const char *); | ||
|
Oops, something went wrong.