static Backend *back;
static void *backhandle;
static Conf *conf;
+int sent_eof = FALSE;
static void source(char *src);
static void rsource(char *src);
assert(!"Unexpected call to from_backend_untrusted()");
return 0; /* not reached */
}
+int from_backend_eof(void *frontend)
+{
+ /*
+ * We expect to be the party deciding when to close the
+ * connection, so if we see EOF before we sent it ourselves, we
+ * should panic.
+ */
+ if (!sent_eof) {
+ connection_fatal(frontend,
+ "Received unexpected end-of-file from server");
+ }
+ return FALSE;
+}
static int ssh_scp_recv(unsigned char *buf, int len)
{
outptr = buf;
if (back != NULL && back->connected(backhandle)) {
char ch;
back->special(backhandle, TS_EOF);
+ sent_eof = TRUE;
ssh_scp_recv((unsigned char *) &ch, 1);
}
if (try_scp) {
/* Fallback is to use the provided scp command. */
fallback_cmd_is_sftp = 0;
- conf_set_str(conf, CONF_remote_cmd2, "sftp");
+ conf_set_str(conf, CONF_remote_cmd2, cmd);
conf_set_int(conf, CONF_ssh_subsys2, FALSE);
} else {
/* Since we're not going to try SCP, we may as well try
}
}
-int scp_send_filename(char *name, uint64 size, int modes)
+int scp_send_filename(char *name, uint64 size, int permissions)
{
if (using_sftp) {
char *fullname;
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
+ struct fxp_attrs attrs;
if (scp_sftp_targetisdir) {
fullname = dupcat(scp_sftp_remotepath, "/", name, NULL);
fullname = dupstr(scp_sftp_remotepath);
}
+ attrs.flags = 0;
+ PUT_PERMISSIONS(attrs, permissions);
+
sftp_register(req = fxp_open_send(fullname, SSH_FXF_WRITE |
- SSH_FXF_CREAT | SSH_FXF_TRUNC));
+ SSH_FXF_CREAT | SSH_FXF_TRUNC,
+ &attrs));
rreq = sftp_find_request(pktin = sftp_recv());
assert(rreq == req);
scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
char buf[40];
char sizestr[40];
uint64_decimal(size, sizestr);
- sprintf(buf, "C%04o %s ", modes, sizestr);
+ if (permissions < 0)
+ permissions = 0644;
+ sprintf(buf, "C%04o %s ", (int)(permissions & 07777), sizestr);
back->send(backhandle, buf, strlen(buf));
back->send(backhandle, name, strlen(name));
back->send(backhandle, "\n", 1);
int action; /* FILE, DIR, ENDDIR */
char *buf; /* will need freeing after use */
char *name; /* filename or dirname (not ENDDIR) */
- int mode; /* access mode (not ENDDIR) */
+ long permissions; /* access permissions (not ENDDIR) */
uint64 size; /* file size (not ENDDIR) */
int settime; /* 1 if atime and mtime are filled */
unsigned long atime, mtime; /* access times for the file */
act->buf = dupstr(stripslashes(fname, 0));
act->name = act->buf;
act->size = uint64_make(0,0); /* duhh, it's a directory */
- act->mode = 07777 & attrs.permissions;
+ act->permissions = 07777 & attrs.permissions;
if (scp_sftp_preserve &&
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->size = attrs.size;
} else
act->size = uint64_make(ULONG_MAX,ULONG_MAX); /* no idea */
- act->mode = 07777 & attrs.permissions;
+ act->permissions = 07777 & attrs.permissions;
if (scp_sftp_preserve &&
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
{
char sizestr[40];
- if (sscanf(act->buf, "%o %s %n", &act->mode, sizestr, &i) != 2)
+ if (sscanf(act->buf, "%lo %s %n", &act->permissions,
+ sizestr, &i) != 2)
bump("Protocol error: Illegal file descriptor format");
act->size = uint64_from_decimal(sizestr);
act->name = act->buf + i;
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
- sftp_register(req = fxp_open_send(scp_sftp_currentname, SSH_FXF_READ));
+ sftp_register(req = fxp_open_send(scp_sftp_currentname, SSH_FXF_READ,
+ NULL));
rreq = sftp_find_request(pktin = sftp_recv());
assert(rreq == req);
scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
{
uint64 size;
unsigned long mtime, atime;
+ long permissions;
char *last;
RFile *f;
int attr;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
- f = open_existing_file(src, &size, &mtime, &atime);
+ f = open_existing_file(src, &size, &mtime, &atime, &permissions);
if (f == NULL) {
run_err("%s: Cannot open file", src);
return;
uint64_decimal(size, sizestr);
tell_user(stderr, "Sending file %s, size=%s", last, sizestr);
}
- if (scp_send_filename(last, size, 0644))
+ if (scp_send_filename(last, size, permissions))
return;
stat_bytes = uint64_make(0,0);
continue;
}
- f = open_new_file(destfname);
+ f = open_new_file(destfname, act.permissions);
if (f == NULL) {
run_err("%s: Cannot create file", destfname);
continue;
if (back != NULL && back->connected(backhandle)) {
char ch;
back->special(backhandle, TS_EOF);
+ sent_eof = TRUE;
ssh_scp_recv((unsigned char *) &ch, 1);
}
random_save_seed();