-/* $OpenBSD: scp.c,v 1.230 2021/08/10 03:33:34 djm Exp $ */
+/* $OpenBSD: scp.c,v 1.231 2021/08/11 14:05:19 naddy Exp $ */
/*
* scp - secure remote copy. This is basically patched BSD rcp which
* uses ssh to do the data transfer (instead of using rcmd).
#define COPY_BUFLEN 16384
-int do_cmd(char *program, char *host, char *remuser, int port, char *cmd,
- int *fdin, int *fdout, pid_t *pidp);
-int do_cmd2(char *host, char *remuser, int port, char *cmd,
- int fdin, int fdout);
+int do_cmd(char *, char *, char *, int, int, char *, int *, int *, pid_t *);
+int do_cmd2(char *, char *, int, char *, int, int);
/* Struct for addargs */
arglist args;
*/
int
-do_cmd(char *program, char *host, char *remuser, int port, char *cmd,
- int *fdin, int *fdout, pid_t *pid)
+do_cmd(char *program, char *host, char *remuser, int port, int subsystem,
+ char *cmd, int *fdin, int *fdout, pid_t *pid)
{
int pin[2], pout[2], reserved[2];
addargs(&args, "-l");
addargs(&args, "%s", remuser);
}
+ if (subsystem)
+ addargs(&args, "-s");
addargs(&args, "--");
addargs(&args, "%s", host);
addargs(&args, "%s", cmd);
int *reminp, int *remoutp, int *pidp)
{
if (sftp_direct == NULL) {
- addargs(&args, "-s");
- if (do_cmd(ssh_program, host, user, port, "sftp",
+ if (do_cmd(ssh_program, host, user, port, 1, "sftp",
reminp, remoutp, pidp) < 0)
return NULL;
} else {
args.list = NULL;
addargs(&args, "sftp-server");
- if (do_cmd(sftp_direct, host, NULL, -1, "sftp",
+ if (do_cmd(sftp_direct, host, NULL, -1, 0, "sftp",
reminp, remoutp, pidp) < 0)
return NULL;
}
} else {
xasprintf(&bp, "%s -f %s%s", cmd,
*src == '-' ? "-- " : "", src);
- if (do_cmd(ssh_program, host, suser, sport,
+ if (do_cmd(ssh_program, host, suser, sport, 0,
bp, &remin, &remout, &do_cmd_pid) < 0)
exit(1);
free(bp);
if (remin == -1) {
xasprintf(&bp, "%s -t %s%s", cmd,
*targ == '-' ? "-- " : "", targ);
- if (do_cmd(ssh_program, thost, tuser, tport, bp,
- &remin, &remout, &do_cmd_pid) < 0)
+ if (do_cmd(ssh_program, thost, tuser, tport, 0,
+ bp, &remin, &remout, &do_cmd_pid) < 0)
exit(1);
if (response() < 0)
exit(1);
/* SCP */
xasprintf(&bp, "%s -f %s%s",
cmd, *src == '-' ? "-- " : "", src);
- if (do_cmd(ssh_program, host, suser, sport, bp,
+ if (do_cmd(ssh_program, host, suser, sport, 0, bp,
&remin, &remout, &do_cmd_pid) < 0) {
free(bp);
++errs;