version 1.66, 2005/08/08 13:22:48 |
version 1.66.2.2, 2006/10/06 03:19:33 |
|
|
|
/* $OpenBSD$ */ |
/* |
/* |
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
* |
* |
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
|
|
#include "includes.h" |
#include <sys/types.h> |
|
#include <sys/ioctl.h> |
|
#include <sys/wait.h> |
|
#include <sys/stat.h> |
|
#include <sys/socket.h> |
|
#include <sys/param.h> |
|
|
RCSID("$OpenBSD$"); |
#include <errno.h> |
|
|
#include <glob.h> |
#include <glob.h> |
#include <histedit.h> |
#include <histedit.h> |
|
#include <paths.h> |
|
#include <signal.h> |
|
#include <stdlib.h> |
|
#include <stdio.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
#include <stdarg.h> |
|
|
#include "buffer.h" |
|
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "log.h" |
#include "log.h" |
#include "pathnames.h" |
#include "pathnames.h" |
#include "misc.h" |
#include "misc.h" |
|
|
#include "sftp.h" |
#include "sftp.h" |
|
#include "buffer.h" |
#include "sftp-common.h" |
#include "sftp-common.h" |
#include "sftp-client.h" |
#include "sftp-client.h" |
|
|
|
|
if (errno != EINTR) |
if (errno != EINTR) |
fatal("Couldn't wait for child: %s", strerror(errno)); |
fatal("Couldn't wait for child: %s", strerror(errno)); |
if (!WIFEXITED(status)) |
if (!WIFEXITED(status)) |
error("Shell exited abormally"); |
error("Shell exited abnormally"); |
else if (WEXITSTATUS(status)) |
else if (WEXITSTATUS(status)) |
error("Shell exited with status %d", WEXITSTATUS(status)); |
error("Shell exited with status %d", WEXITSTATUS(status)); |
} |
} |
|
|
|
|
if (g.gl_matchc == 1 && dst) { |
if (g.gl_matchc == 1 && dst) { |
/* If directory specified, append filename */ |
/* If directory specified, append filename */ |
|
xfree(tmp); |
if (is_dir(dst)) { |
if (is_dir(dst)) { |
if (infer_path(g.gl_pathv[0], &tmp)) { |
if (infer_path(g.gl_pathv[0], &tmp)) { |
err = 1; |
err = 1; |
|
|
|
|
out: |
out: |
xfree(abs_src); |
xfree(abs_src); |
if (abs_dst) |
|
xfree(abs_dst); |
|
globfree(&g); |
globfree(&g); |
return(err); |
return(err); |
} |
} |
|
|
} |
} |
|
|
if (lflag & SORT_FLAGS) { |
if (lflag & SORT_FLAGS) { |
|
for (n = 0; d[n] != NULL; n++) |
|
; /* count entries */ |
sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT); |
sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT); |
qsort(d, n, sizeof(*d), sdirent_comp); |
qsort(d, n, sizeof(*d), sdirent_comp); |
} |
} |
|
|
if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) { |
if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) { |
xfree(dir); |
xfree(dir); |
xfree(pwd); |
xfree(pwd); |
|
xfree(conn); |
return (-1); |
return (-1); |
} |
} |
} else { |
} else { |
|
|
err = parse_dispatch_command(conn, cmd, &pwd, 1); |
err = parse_dispatch_command(conn, cmd, &pwd, 1); |
xfree(dir); |
xfree(dir); |
xfree(pwd); |
xfree(pwd); |
|
xfree(conn); |
return (err); |
return (err); |
} |
} |
xfree(dir); |
xfree(dir); |
|
|
break; |
break; |
} |
} |
xfree(pwd); |
xfree(pwd); |
|
xfree(conn); |
|
|
if (el != NULL) |
if (el != NULL) |
el_end(el); |
el_end(el); |
|
|
{ |
{ |
int c_in, c_out; |
int c_in, c_out; |
|
|
#ifdef USE_PIPES |
|
int pin[2], pout[2]; |
|
|
|
if ((pipe(pin) == -1) || (pipe(pout) == -1)) |
|
fatal("pipe: %s", strerror(errno)); |
|
*in = pin[0]; |
|
*out = pout[1]; |
|
c_in = pout[0]; |
|
c_out = pin[1]; |
|
#else /* USE_PIPES */ |
|
int inout[2]; |
int inout[2]; |
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) |
fatal("socketpair: %s", strerror(errno)); |
fatal("socketpair: %s", strerror(errno)); |
*in = *out = inout[0]; |
*in = *out = inout[0]; |
c_in = c_out = inout[1]; |
c_in = c_out = inout[1]; |
#endif /* USE_PIPES */ |
|
|
|
if ((sshpid = fork()) == -1) |
if ((sshpid = fork()) == -1) |
fatal("fork: %s", strerror(errno)); |
fatal("fork: %s", strerror(errno)); |
|
|
extern int optind; |
extern int optind; |
extern char *optarg; |
extern char *optarg; |
|
|
|
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ |
|
sanitise_stdfd(); |
|
|
|
memset(&args, '\0', sizeof(args)); |
args.list = NULL; |
args.list = NULL; |
addargs(&args, "ssh"); /* overwritten with ssh_program */ |
addargs(&args, "%s", ssh_program); |
addargs(&args, "-oForwardX11 no"); |
addargs(&args, "-oForwardX11 no"); |
addargs(&args, "-oForwardAgent no"); |
addargs(&args, "-oForwardAgent no"); |
|
addargs(&args, "-oPermitLocalCommand no"); |
addargs(&args, "-oClearAllForwardings yes"); |
addargs(&args, "-oClearAllForwardings yes"); |
|
|
ll = SYSLOG_LEVEL_INFO; |
ll = SYSLOG_LEVEL_INFO; |
|
|
break; |
break; |
case 'S': |
case 'S': |
ssh_program = optarg; |
ssh_program = optarg; |
|
replacearg(&args, 0, "%s", ssh_program); |
break; |
break; |
case 'b': |
case 'b': |
if (batchmode) |
if (batchmode) |
|
|
addargs(&args, "%s", host); |
addargs(&args, "%s", host); |
addargs(&args, "%s", (sftp_server != NULL ? |
addargs(&args, "%s", (sftp_server != NULL ? |
sftp_server : "sftp")); |
sftp_server : "sftp")); |
args.list[0] = ssh_program; |
|
|
|
if (!batchmode) |
if (!batchmode) |
fprintf(stderr, "Connecting to %s...\n", host); |
fprintf(stderr, "Connecting to %s...\n", host); |
|
|
fprintf(stderr, "Attaching to %s...\n", sftp_direct); |
fprintf(stderr, "Attaching to %s...\n", sftp_direct); |
connect_to_server(sftp_direct, args.list, &in, &out); |
connect_to_server(sftp_direct, args.list, &in, &out); |
} |
} |
|
freeargs(&args); |
|
|
err = interactive_loop(in, out, file1, file2); |
err = interactive_loop(in, out, file1, file2); |
|
|