Skip to content

Commit

Permalink
Add slave option to run sftp over stdin and stdout
Browse files Browse the repository at this point in the history
Add -o slave. This option routes the sftp communication over stdin and stdout,
bypassing SSH and network.
  • Loading branch information
Chris Wolfe authored and Miklos Szeredi committed Feb 14, 2012
1 parent acb0832 commit b3af91b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2012-02-08 Chris Wolfe <cwolfe@chromium.org>

* Add -o slave. This option routes the sftp communication over stdin
and stdout, bypassing SSH and network.

2011-12-16 Mike Kelly <mike@pair.com> 2011-12-16 Mike Kelly <mike@pair.com>


* Add -o idmap=file, -o uidmap=FILE, -o gidmap=FILE. These options * Add -o idmap=file, -o uidmap=FILE, -o gidmap=FILE. These options
Expand Down
2 changes: 2 additions & 0 deletions sshfs.1
Expand Up @@ -138,6 +138,8 @@ path to sftp server or subsystem (default: sftp)
.TP .TP
\fB\-o\fR directport=PORT \fB\-o\fR directport=PORT
directly connect to PORT bypassing ssh directly connect to PORT bypassing ssh
\fB\-o\fR slave
communicate over stdin and stdout bypassing network
.TP .TP
\fB\-o\fR transform_symlinks \fB\-o\fR transform_symlinks
transform absolute symlinks to relative transform absolute symlinks to relative
Expand Down
30 changes: 29 additions & 1 deletion sshfs.c
Expand Up @@ -218,6 +218,7 @@ struct sshfs {
int foreground; int foreground;
int reconnect; int reconnect;
int delay_connect; int delay_connect;
int slave;
char *host; char *host;
char *base_path; char *base_path;
GHashTable *reqtab; GHashTable *reqtab;
Expand Down Expand Up @@ -356,6 +357,7 @@ static struct fuse_opt sshfs_opts[] = {
SSHFS_OPT("no_check_root", no_check_root, 1), SSHFS_OPT("no_check_root", no_check_root, 1),
SSHFS_OPT("password_stdin", password_stdin, 1), SSHFS_OPT("password_stdin", password_stdin, 1),
SSHFS_OPT("delay_connect", delay_connect, 1), SSHFS_OPT("delay_connect", delay_connect, 1),
SSHFS_OPT("slave", slave, 1),


FUSE_OPT_KEY("-p ", KEY_PORT), FUSE_OPT_KEY("-p ", KEY_PORT),
FUSE_OPT_KEY("-C", KEY_COMPRESS), FUSE_OPT_KEY("-C", KEY_COMPRESS),
Expand Down Expand Up @@ -1092,6 +1094,13 @@ static int start_ssh(void)
return 0; return 0;
} }


static int connect_slave()
{
sshfs.rfd = STDIN_FILENO;
sshfs.wfd = STDOUT_FILENO;
return 0;
}

static int connect_to(char *host, char *port) static int connect_to(char *host, char *port)
{ {
int err; int err;
Expand Down Expand Up @@ -1668,7 +1677,9 @@ static int connect_remote(void)
{ {
int err; int err;


if (sshfs.directport) if (sshfs.slave)
err = connect_slave();
else if (sshfs.directport)
err = connect_to(sshfs.host, sshfs.directport); err = connect_to(sshfs.host, sshfs.directport);
else else
err = start_ssh(); err = start_ssh();
Expand Down Expand Up @@ -3178,6 +3189,7 @@ static void usage(const char *progname)
" -o ssh_protocol=N ssh protocol to use (default: 2)\n" " -o ssh_protocol=N ssh protocol to use (default: 2)\n"
" -o sftp_server=SERV path to sftp server or subsystem (default: sftp)\n" " -o sftp_server=SERV path to sftp server or subsystem (default: sftp)\n"
" -o directport=PORT directly connect to PORT bypassing ssh\n" " -o directport=PORT directly connect to PORT bypassing ssh\n"
" -o slave communicate over stdin and stdout bypassing network\n"
" -o transform_symlinks transform absolute symlinks to relative\n" " -o transform_symlinks transform absolute symlinks to relative\n"
" -o follow_symlinks follow symlinks on the server\n" " -o follow_symlinks follow symlinks on the server\n"
" -o no_check_root don't check for existence of 'dir' on server\n" " -o no_check_root don't check for existence of 'dir' on server\n"
Expand Down Expand Up @@ -3676,6 +3688,7 @@ int main(int argc, char *argv[])
sshfs.ptyfd = -1; sshfs.ptyfd = -1;
sshfs.ptyslavefd = -1; sshfs.ptyslavefd = -1;
sshfs.delay_connect = 0; sshfs.delay_connect = 0;
sshfs.slave = 0;
sshfs.detect_uid = 0; sshfs.detect_uid = 0;
sshfs.idmap = IDMAP_NONE; sshfs.idmap = IDMAP_NONE;
sshfs.nomap = NOMAP_ERROR; sshfs.nomap = NOMAP_ERROR;
Expand Down Expand Up @@ -3709,6 +3722,16 @@ int main(int argc, char *argv[])


DEBUG("SSHFS version %s\n", PACKAGE_VERSION); DEBUG("SSHFS version %s\n", PACKAGE_VERSION);


if (sshfs.slave) {
/* Force sshfs to the foreground when using stdin+stdout */
sshfs.foreground = 1;
}

if (sshfs.slave && sshfs.password_stdin) {
fprintf(stderr, "the password_stdin and slave options cannot both be specified\n");
exit(1);
}

if (sshfs.password_stdin) { if (sshfs.password_stdin) {
res = read_password(); res = read_password();
if (res == -1) if (res == -1)
Expand Down Expand Up @@ -3797,6 +3820,11 @@ int main(int argc, char *argv[])
if (res == -1) if (res == -1)
exit(1); exit(1);


if (sshfs.slave) {
/* Force sshfs to the foreground when using stdin+stdout */
foreground = 1;
}

res = stat(mountpoint, &st); res = stat(mountpoint, &st);
if (res == -1) { if (res == -1) {
perror(mountpoint); perror(mountpoint);
Expand Down

0 comments on commit b3af91b

Please sign in to comment.