=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sftp.c,v retrieving revision 1.63.2.2 retrieving revision 1.64 diff -u -r1.63.2.2 -r1.64 --- src/usr.bin/ssh/sftp.c 2006/02/03 02:53:45 1.63.2.2 +++ src/usr.bin/ssh/sftp.c 2005/06/17 02:44:33 1.64 @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.63.2.2 2006/02/03 02:53:45 brad Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.64 2005/06/17 02:44:33 djm Exp $"); #include #include @@ -692,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); } @@ -1232,7 +1230,7 @@ char *dir = NULL; char cmd[2048]; struct sftp_conn *conn; - int err, interactive; + int err; EditLine *el = NULL; History *hl = NULL; HistEvent hev; @@ -1291,7 +1289,6 @@ setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(infile, NULL, _IOLBF, 0); - interactive = !batchmode && isatty(STDIN_FILENO); err = 0; for (;;) { char *cp; @@ -1301,24 +1298,16 @@ signal(SIGINT, SIG_IGN); if (el == NULL) { - if (interactive) - printf("sftp> "); + printf("sftp> "); if (fgets(cmd, sizeof(cmd), infile) == NULL) { - if (interactive) - printf("\n"); + printf("\n"); break; } - if (!interactive) { /* Echo command */ - printf("sftp> %s", cmd); - if (strlen(cmd) > 0 && - cmd[strlen(cmd) - 1] != '\n') - printf("\n"); - } + if (batchmode) /* Echo command */ + printf("%s", cmd); } else { - if ((line = el_gets(el, &count)) == NULL || count <= 0) { - printf("\n"); + if ((line = el_gets(el, &count)) == NULL || count <= 0) break; - } history(hl, &hev, H_ENTER, line); if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { fprintf(stderr, "Error: input line too long\n"); @@ -1340,9 +1329,6 @@ } xfree(pwd); - if (el != NULL) - el_end(el); - /* err == 1 signifies normal "quit" exit */ return (err >= 0 ? 0 : -1); } @@ -1430,15 +1416,10 @@ extern int optind; 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; - addargs(&args, 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; @@ -1470,7 +1451,6 @@ break; case 'S': ssh_program = optarg; - replacearg(&args, 0, "%s", ssh_program); break; case 'b': if (batchmode) @@ -1478,7 +1458,7 @@ /* Allow "-" as stdin */ if (strcmp(optarg, "-") != 0 && - (infile = fopen(optarg, "r")) == NULL) + (infile = fopen(optarg, "r")) == NULL) fatal("%s (%s).", strerror(errno), optarg); showprogress = 0; batchmode = 1; @@ -1547,6 +1527,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); @@ -1559,7 +1540,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);