Add slave option to run sftp over stdin and stdout

Add -o slave. This option routes the sftp communication over stdin and stdout,
bypassing SSH and network.
This commit is contained in:
Chris Wolfe 2012-02-08 10:11:10 -05:00 committed by Benjamin Fleischer
parent ff32332e83
commit 0d34c7b742
3 changed files with 36 additions and 1 deletions

View File

@ -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>
* Add -o idmap=file, -o uidmap=FILE, -o gidmap=FILE. These options

View File

@ -138,6 +138,8 @@ path to sftp server or subsystem (default: sftp)
.TP
\fB\-o\fR directport=PORT
directly connect to PORT bypassing ssh
\fB\-o\fR slave
communicate over stdin and stdout bypassing network
.TP
\fB\-o\fR transform_symlinks
transform absolute symlinks to relative

30
sshfs.c
View File

@ -244,6 +244,7 @@ struct sshfs {
int foreground;
int reconnect;
int delay_connect;
int slave;
char *host;
char *base_path;
GHashTable *reqtab;
@ -386,6 +387,7 @@ static struct fuse_opt sshfs_opts[] = {
SSHFS_OPT("no_check_root", no_check_root, 1),
SSHFS_OPT("password_stdin", password_stdin, 1),
SSHFS_OPT("delay_connect", delay_connect, 1),
SSHFS_OPT("slave", slave, 1),
FUSE_OPT_KEY("-p ", KEY_PORT),
FUSE_OPT_KEY("-C", KEY_COMPRESS),
@ -1164,6 +1166,13 @@ static int start_ssh(void)
return 0;
}
static int connect_slave()
{
sshfs.rfd = STDIN_FILENO;
sshfs.wfd = STDOUT_FILENO;
return 0;
}
static int connect_to(char *host, char *port)
{
int err;
@ -1744,7 +1753,9 @@ static int connect_remote(void)
{
int err;
if (sshfs.directport)
if (sshfs.slave)
err = connect_slave();
else if (sshfs.directport)
err = connect_to(sshfs.host, sshfs.directport);
else
err = start_ssh();
@ -3299,6 +3310,7 @@ static void usage(const char *progname)
" -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 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 follow_symlinks follow symlinks on the server\n"
" -o no_check_root don't check for existence of 'dir' on server\n"
@ -3827,6 +3839,7 @@ int main(int argc, char *argv[])
sshfs.ptyfd = -1;
sshfs.ptyslavefd = -1;
sshfs.delay_connect = 0;
sshfs.slave = 0;
sshfs.detect_uid = 0;
#if __APPLE__
sshfs.idmap = IDMAP_USER;
@ -3864,6 +3877,16 @@ int main(int argc, char *argv[])
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) {
res = read_password();
if (res == -1)
@ -3952,6 +3975,11 @@ int main(int argc, char *argv[])
if (res == -1)
exit(1);
if (sshfs.slave) {
/* Force sshfs to the foreground when using stdin+stdout */
foreground = 1;
}
res = stat(mountpoint, &st);
if (res == -1) {
perror(mountpoint);