=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sftp.c,v retrieving revision 1.66.2.3 retrieving revision 1.67 diff -u -r1.66.2.3 -r1.67 --- src/usr.bin/ssh/sftp.c 2006/11/08 00:44:05 1.66.2.3 +++ src/usr.bin/ssh/sftp.c 2005/09/13 23:40:07 1.67 @@ -1,4 +1,3 @@ -/* $OpenBSD: sftp.c,v 1.66.2.3 2006/11/08 00:44:05 brad Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller * @@ -15,31 +14,20 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#include -#include -#include -#include +#include "includes.h" -#include +RCSID("$OpenBSD: sftp.c,v 1.67 2005/09/13 23:40:07 djm Exp $"); + #include #include -#include -#include -#include -#include -#include -#include -#include +#include "buffer.h" #include "xmalloc.h" #include "log.h" #include "pathnames.h" #include "misc.h" #include "sftp.h" -#include "buffer.h" #include "sftp-common.h" #include "sftp-client.h" @@ -242,7 +230,7 @@ if (errno != EINTR) fatal("Couldn't wait for child: %s", strerror(errno)); if (!WIFEXITED(status)) - error("Shell exited abnormally"); + error("Shell exited abormally"); else if (WEXITSTATUS(status)) error("Shell exited with status %d", WEXITSTATUS(status)); } @@ -481,7 +469,7 @@ if (stat(path, &sb) == -1) return(0); - return(S_ISDIR(sb.st_mode)); + return(sb.st_mode & S_IFDIR); } static int @@ -505,7 +493,7 @@ return(0); if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) return(0); - return(S_ISDIR(a->perm)); + return(a->perm & S_IFDIR); } static int @@ -545,7 +533,6 @@ if (g.gl_matchc == 1 && dst) { /* If directory specified, append filename */ - xfree(tmp); if (is_dir(dst)) { if (infer_path(g.gl_pathv[0], &tmp)) { err = 1; @@ -570,6 +557,8 @@ out: xfree(abs_src); + if (abs_dst) + xfree(abs_dst); globfree(&g); return(err); } @@ -703,8 +692,6 @@ } if (lflag & SORT_FLAGS) { - for (n = 0; d[n] != NULL; n++) - ; /* count entries */ sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT); qsort(d, n, sizeof(*d), sdirent_comp); } @@ -965,7 +952,6 @@ case I_CHOWN: case I_CHGRP: /* Get numeric arg (mandatory) */ - errno = 0; l = strtol(cp, &cp2, base); if (cp2 == cp || ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) || l < 0) { @@ -1283,7 +1269,6 @@ if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) { xfree(dir); xfree(pwd); - xfree(conn); return (-1); } } else { @@ -1296,7 +1281,6 @@ err = parse_dispatch_command(conn, cmd, &pwd, 1); xfree(dir); xfree(pwd); - xfree(conn); return (err); } xfree(dir); @@ -1353,7 +1337,6 @@ break; } xfree(pwd); - xfree(conn); if (el != NULL) el_end(el); @@ -1367,12 +1350,23 @@ { 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]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) fatal("socketpair: %s", strerror(errno)); *in = *out = inout[0]; c_in = c_out = inout[1]; +#endif /* USE_PIPES */ if ((sshpid = fork()) == -1) fatal("fork: %s", strerror(errno)); @@ -1437,12 +1431,10 @@ /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ sanitise_stdfd(); - memset(&args, '\0', sizeof(args)); args.list = NULL; - addargs(&args, "%s", ssh_program); + addargs(&args, "ssh"); /* overwritten with ssh_program */ addargs(&args, "-oForwardX11 no"); addargs(&args, "-oForwardAgent no"); - addargs(&args, "-oPermitLocalCommand no"); addargs(&args, "-oClearAllForwardings yes"); ll = SYSLOG_LEVEL_INFO; @@ -1474,7 +1466,6 @@ break; case 'S': ssh_program = optarg; - replacearg(&args, 0, "%s", ssh_program); break; case 'b': if (batchmode) @@ -1551,6 +1542,7 @@ addargs(&args, "%s", host); addargs(&args, "%s", (sftp_server != NULL ? sftp_server : "sftp")); + args.list[0] = ssh_program; if (!batchmode) fprintf(stderr, "Connecting to %s...\n", host); @@ -1563,7 +1555,6 @@ fprintf(stderr, "Attaching to %s...\n", sftp_direct); connect_to_server(sftp_direct, args.list, &in, &out); } - freeargs(&args); err = interactive_loop(in, out, file1, file2);