=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sftp.c,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -r1.11 -r1.11.2.1 --- src/usr.bin/ssh/sftp.c 2001/03/07 10:11:23 1.11 +++ src/usr.bin/ssh/sftp.c 2001/03/12 15:44:15 1.11.2.1 @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.11 2001/03/07 10:11:23 djm Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.11.2.1 2001/03/12 15:44:15 jason Exp $"); /* XXX: commandline mode */ /* XXX: copy between two remote hosts (commandline) */ @@ -43,7 +43,6 @@ int use_ssh1 = 0; char *ssh_program = _PATH_SSH_PROGRAM; char *sftp_server = NULL; -FILE* infile; void connect_to_server(char **args, int *in, int *out, pid_t *sshpid) @@ -92,14 +91,24 @@ static char **args = NULL; static int nargs = 0; char debug_buf[4096]; - int i; + int i, use_subsystem = 1; + /* no subsystem if protocol 1 or the server-spec contains a '/' */ + if (use_ssh1 || + (sftp_server != NULL && strchr(sftp_server, '/') != NULL)) + use_subsystem = 0; + /* Init args array */ if (args == NULL) { - nargs = 2; + nargs = use_subsystem ? 6 : 5; i = 0; args = xmalloc(sizeof(*args) * nargs); args[i++] = "ssh"; + args[i++] = use_ssh1 ? "-oProtocol=1" : "-oProtocol=2"; + if (use_subsystem) + args[i++] = "-s"; + args[i++] = "-oForwardAgent=no"; + args[i++] = "-oForwardX11=no"; args[i++] = NULL; } @@ -112,13 +121,6 @@ return(NULL); } - /* no subsystem if the server-spec contains a '/' */ - if (sftp_server == NULL || strchr(sftp_server, '/') == NULL) - make_ssh_args("-s"); - make_ssh_args("-oForwardX11=no"); - make_ssh_args("-oForwardAgent=no"); - make_ssh_args(use_ssh1 ? "-oProtocol=1" : "-oProtocol=2"); - /* Otherwise finish up and return the arg array */ if (sftp_server != NULL) make_ssh_args(sftp_server); @@ -141,7 +143,7 @@ void usage(void) { - fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host\n"); + fprintf(stderr, "usage: sftp [-1vC] [-osshopt=value] [user@]host\n"); exit(1); } @@ -155,10 +157,9 @@ extern int optind; extern char *optarg; - infile = stdin; /* Read from STDIN unless changed by -b */ debug_level = compress_flag = 0; - while ((ch = getopt(argc, argv, "1hvCo:s:S:b:")) != -1) { + while ((ch = getopt(argc, argv, "1hvCo:s:S:")) != -1) { switch (ch) { case 'C': compress_flag = 1; @@ -181,14 +182,6 @@ case 'S': ssh_program = optarg; break; - case 'b': - if (infile == stdin) { - infile = fopen(optarg, "r"); - if (infile == NULL) - fatal("%s (%s).", strerror(errno), optarg); - } else - fatal("Filename already specified."); - break; case 'h': default: usage(); @@ -249,12 +242,15 @@ connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid); + do_init(in, out); + interactive_loop(in, out); close(in); close(out); - if (infile != stdin) - fclose(infile); + + if (kill(sshpid, SIGHUP) == -1) + fatal("Couldn't terminate ssh process: %s", strerror(errno)); if (waitpid(sshpid, NULL, 0) == -1) fatal("Couldn't wait for ssh process: %s", strerror(errno));