}
extern int select_result(WPARAM, LPARAM);
+/*
+ * In pscp, all agent requests should be synchronous, so this is a
+ * never-called stub.
+ */
+void agent_schedule_callback(void (*callback)(void *, void *, int),
+ void *callback_ctx, void *data, int len)
+{
+ assert(!"We shouldn't be here");
+}
+
/*
* Receive a block of data from the SSH link. Block until all data
* is available.
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
-int from_backend(void *frontend, int is_stderr, char *data, int datalen)
+int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
- pending = (pending ? srealloc(pending, pendsize) :
- smalloc(pendsize));
+ pending = sresize(pending, pendsize, unsigned char);
if (!pending)
fatalbox("Out of memory");
}
select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
}
using_sftp = !ssh_fallback_cmd(backhandle);
+ if (verbose) {
+ if (using_sftp)
+ tell_user(stderr, "Using SFTP");
+ else
+ tell_user(stderr, "Using SCP1");
+ }
}
/*
*/
static void do_cmd(char *host, char *user, char *cmd)
{
- char *err, *realhost;
+ const char *err;
+ char *realhost;
DWORD namelen;
if (host == NULL || host[0] == '\0')
namelen = 0;
if (GetUserName(user, &namelen) == FALSE)
bump("Empty user name");
- user = smalloc(namelen * sizeof(char));
+ user = snewn(namelen, char);
GetUserName(user, &namelen);
if (verbose)
tell_user(stderr, "Guessing user name: %s", user);
struct fxp_handle *dirh;
struct fxp_names *names;
struct fxp_name *ournames;
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
int nnames, namesize;
int i;
printf("Listing directory %s\n", dirname);
- dirh = fxp_opendir(dirname);
+ sftp_register(req = fxp_opendir_send(dirname));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ dirh = fxp_opendir_recv(pktin);
+
if (dirh == NULL) {
printf("Unable to open %s: %s\n", dirname, fxp_error());
} else {
while (1) {
- names = fxp_readdir(dirh);
+ sftp_register(req = fxp_readdir_send(dirh));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ names = fxp_readdir_recv(pktin);
+
if (names == NULL) {
if (fxp_error_type() == SSH_FX_EOF)
break;
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
- ournames =
- srealloc(ournames, namesize * sizeof(*ournames));
+ ournames = sresize(ournames, namesize, struct fxp_name);
}
for (i = 0; i < names->nnames; i++)
names->nnames = 0; /* prevent free_names */
fxp_free_names(names);
}
- fxp_close(dirh);
+ sftp_register(req = fxp_close_send(dirh));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ fxp_close_recv(pktin);
/*
* Now we have our filenames. Sort them by actual file
* Find out whether the target filespec is in fact a
* directory.
*/
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
struct fxp_attrs attrs;
+ int ret;
if (!fxp_init()) {
tell_user(stderr, "unable to initialise SFTP: %s", fxp_error());
return;
}
- if (!fxp_stat(target, &attrs) ||
- !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS))
+ sftp_register(req = fxp_stat_send(target));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ ret = fxp_stat_recv(pktin, &attrs);
+
+ if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS))
scp_sftp_targetisdir = 0;
else
scp_sftp_targetisdir = (attrs.permissions & 0040000) != 0;
{
if (using_sftp) {
char *fullname;
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+
if (scp_sftp_targetisdir) {
fullname = dupcat(scp_sftp_remotepath, "/", name, NULL);
} else {
fullname = dupstr(scp_sftp_remotepath);
}
- scp_sftp_filehandle =
- fxp_open(fullname, SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC);
+
+ sftp_register(req = fxp_open_send(fullname, SSH_FXF_WRITE |
+ SSH_FXF_CREAT | SSH_FXF_TRUNC));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ scp_sftp_filehandle = fxp_open_recv(pktin);
+
if (!scp_sftp_filehandle) {
tell_user(stderr, "pscp: unable to open %s: %s",
fullname, fxp_error());
int scp_send_filedata(char *data, int len)
{
if (using_sftp) {
+ int ret;
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+
if (!scp_sftp_filehandle) {
return 1;
}
- if (!fxp_write(scp_sftp_filehandle, data, scp_sftp_fileoffset, len)) {
+
+ sftp_register(req = fxp_write_send(scp_sftp_filehandle,
+ data, scp_sftp_fileoffset, len));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ ret = fxp_write_recv(pktin);
+
+ if (!ret) {
tell_user(stderr, "error while writing: %s\n", fxp_error());
errs++;
return 1;
{
if (using_sftp) {
struct fxp_attrs attrs;
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+ int ret;
+
if (!scp_sftp_filehandle) {
return 1;
}
attrs.flags = SSH_FILEXFER_ATTR_ACMODTIME;
attrs.atime = scp_sftp_atime;
attrs.mtime = scp_sftp_mtime;
- if (!fxp_fsetstat(scp_sftp_filehandle, attrs)) {
+ sftp_register(req = fxp_fsetstat_send(scp_sftp_filehandle, attrs));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ ret = fxp_fsetstat_recv(pktin);
+ if (!ret) {
tell_user(stderr, "unable to set file times: %s\n", fxp_error());
errs++;
}
}
- fxp_close(scp_sftp_filehandle);
+ sftp_register(req = fxp_close_send(scp_sftp_filehandle));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ fxp_close_recv(pktin);
scp_has_times = 0;
return 0;
} else {
char *fullname;
char const *err;
struct fxp_attrs attrs;
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+ int ret;
+
if (scp_sftp_targetisdir) {
fullname = dupcat(scp_sftp_remotepath, "/", name, NULL);
} else {
* exists and is a directory we will assume we were either
* successful or it didn't matter.
*/
- if (!fxp_mkdir(fullname))
+ sftp_register(req = fxp_mkdir_send(fullname));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ ret = fxp_mkdir_recv(pktin);
+
+ if (!ret)
err = fxp_error();
else
err = "server reported no error";
- if (!fxp_stat(fullname, &attrs) ||
- !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS) ||
+
+ sftp_register(req = fxp_stat_send(fullname));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ ret = fxp_stat_recv(pktin, &attrs);
+
+ if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS) ||
!(attrs.permissions & 0040000)) {
tell_user(stderr, "unable to create directory %s: %s",
fullname, err);
* wildcardness comes before the final slash) and arrange
* things so that a dirstack entry will be set up.
*/
- newsource = smalloc(1+strlen(source));
+ newsource = snewn(1+strlen(source), char);
if (!wc_unescape(newsource, source)) {
/* Yes, here we go; it's a wildcard. Bah. */
char *dupsource, *lastpart, *dirpart, *wildcard;
* wildcard escapes from the directory part, throwing
* an error if it contains a real wildcard.
*/
- dirpart = smalloc(1+strlen(dupsource));
+ dirpart = snewn(1+strlen(dupsource), char);
if (!wc_unescape(dirpart, dupsource)) {
tell_user(stderr, "%s: multiple-level wildcards unsupported",
source);
char *fname;
int must_free_fname;
struct fxp_attrs attrs;
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
int ret;
if (!scp_sftp_dirstack_head) {
* Now we have a filename. Stat it, and see if it's a file
* or a directory.
*/
- ret = fxp_stat(fname, &attrs);
+ sftp_register(req = fxp_stat_send(fname));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ ret = fxp_stat_recv(pktin, &attrs);
+
if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) {
tell_user(stderr, "unable to identify %s: %s", fname,
ret ? "file type not supplied" : fxp_error());
* list), we must push the other (target,namelist) pair
* on a stack.
*/
- dirhandle = fxp_opendir(fname);
+ sftp_register(req = fxp_opendir_send(fname));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ dirhandle = fxp_opendir_recv(pktin);
+
if (!dirhandle) {
tell_user(stderr, "scp: unable to open directory %s: %s",
fname, fxp_error());
while (1) {
int i;
- names = fxp_readdir(dirhandle);
+ sftp_register(req = fxp_readdir_send(dirhandle));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ names = fxp_readdir_recv(pktin);
+
if (names == NULL) {
if (fxp_error_type() == SSH_FX_EOF)
break;
}
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
- ournames =
- srealloc(ournames, namesize * sizeof(*ournames));
+ ournames = sresize(ournames, namesize, struct fxp_name);
}
for (i = 0; i < names->nnames; i++)
ournames[nnames++] = names->names[i];
names->nnames = 0; /* prevent free_names */
fxp_free_names(names);
}
- fxp_close(dirhandle);
+ sftp_register(req = fxp_close_send(dirhandle));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ fxp_close_recv(pktin);
- newitem = smalloc(sizeof(struct scp_sftp_dirstack));
+ newitem = snew(struct scp_sftp_dirstack);
newitem->next = scp_sftp_dirstack_head;
newitem->names = ournames;
newitem->namepos = 0;
bump("Lost connection");
if (i >= bufsize) {
bufsize = i + 128;
- act->buf = srealloc(act->buf, bufsize);
+ act->buf = sresize(act->buf, bufsize, char);
}
act->buf[i++] = ch;
} while (ch != '\n');
int scp_accept_filexfer(void)
{
if (using_sftp) {
- scp_sftp_filehandle =
- fxp_open(scp_sftp_currentname, SSH_FXF_READ);
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+
+ sftp_register(req = fxp_open_send(scp_sftp_currentname, SSH_FXF_READ));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ scp_sftp_filehandle = fxp_open_recv(pktin);
+
if (!scp_sftp_filehandle) {
tell_user(stderr, "pscp: unable to open %s: %s",
scp_sftp_currentname, fxp_error());
int scp_recv_filedata(char *data, int len)
{
if (using_sftp) {
- int actuallen = fxp_read(scp_sftp_filehandle, data,
- scp_sftp_fileoffset, len);
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+ int actuallen;
+
+ sftp_register(req = fxp_read_send(scp_sftp_filehandle,
+ scp_sftp_fileoffset, len));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ actuallen = fxp_read_recv(pktin, data, len);
+
if (actuallen == -1 && fxp_error_type() != SSH_FX_EOF) {
tell_user(stderr, "pscp: error while reading: %s", fxp_error());
errs++;
int scp_finish_filerecv(void)
{
if (using_sftp) {
- fxp_close(scp_sftp_filehandle);
+ struct sftp_packet *pktin;
+ struct sftp_request *req, *rreq;
+
+ sftp_register(req = fxp_close_send(scp_sftp_filehandle));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ fxp_close_recv(pktin);
return 0;
} else {
back->send(backhandle, "", 1);
user = NULL;
}
- cmd = smalloc(4 * strlen(src) + 100);
+ cmd = snewn(4 * strlen(src) + 100, char);
strcpy(cmd, "ls -la '");
p = cmd + strlen(cmd);
for (q = src; *q; q++) {
default_protocol = PROT_TELNET;
- flags = FLAG_STDERR;
+ flags = FLAG_STDERR | FLAG_SYNCAGENT;
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
ssh_get_line = &console_get_line;
init_winsock();