1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Fixed a remaining problem with doing SFTP directory listings on a re-used

persistent connection. Mentioned by Immanuel Gregoire on the mailing list.
This commit is contained in:
Daniel Stenberg 2007-11-12 23:04:44 +00:00
parent f5971f54ff
commit c508d70258
3 changed files with 37 additions and 33 deletions

View File

@ -6,6 +6,10 @@
Changelog Changelog
Daniel S (13 Nov 2007)
- Fixed a remaining problem with doing SFTP directory listings on a re-used
persistent connection. Mentioned by Immanuel Gregoire on the mailing list.
Daniel S (12 Nov 2007) Daniel S (12 Nov 2007)
- Bug report #1830637 (http://curl.haxx.se/bug/view.cgi?id=1830637), which was - Bug report #1830637 (http://curl.haxx.se/bug/view.cgi?id=1830637), which was
forwarded from the Gentoo bug tracker by Daniel Black and was originally forwarded from the Gentoo bug tracker by Daniel Black and was originally

View File

@ -1340,9 +1340,18 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
sshc->actualcode = CURLE_OUT_OF_MEMORY; sshc->actualcode = CURLE_OUT_OF_MEMORY;
break; break;
} }
result = Curl_client_write(conn, CLIENTWRITE_BODY, tmpLine, 0); result = Curl_client_write(conn, CLIENTWRITE_BODY,
tmpLine, sshc->readdir_len+1);
Curl_safefree(tmpLine); Curl_safefree(tmpLine);
if(result) {
state(conn, SSH_STOP);
break;
}
/* since this counts what we send to the client, we include the newline
in this counter */
data->reqdata.keep.bytecount += sshc->readdir_len+1;
/* output debug output if that is requested */ /* output debug output if that is requested */
if(data->set.verbose) { if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_filename, Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_filename,
@ -1450,16 +1459,25 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
sshc->readdir_totalLen - sshc->readdir_totalLen -
sshc->readdir_currLen, "\n"); sshc->readdir_currLen, "\n");
result = Curl_client_write(conn, CLIENTWRITE_BODY, result = Curl_client_write(conn, CLIENTWRITE_BODY,
sshc->readdir_line, 0); sshc->readdir_line,
sshc->readdir_currLen);
/* output debug output if that is requested */ if(result == CURLE_OK) {
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_line, /* output debug output if that is requested */
sshc->readdir_currLen, conn); if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_line,
sshc->readdir_currLen, conn);
}
data->reqdata.keep.bytecount += sshc->readdir_currLen;
} }
Curl_safefree(sshc->readdir_line); Curl_safefree(sshc->readdir_line);
sshc->readdir_line = NULL; sshc->readdir_line = NULL;
state(conn, SSH_SFTP_READDIR); if(result) {
state(conn, SSH_STOP);
}
else
state(conn, SSH_SFTP_READDIR);
break; break;
case SSH_SFTP_READDIR_DONE: case SSH_SFTP_READDIR_DONE:
@ -1818,12 +1836,8 @@ static CURLcode ssh_easy_statemach(struct connectdata *conn)
struct ssh_conn *sshc = &conn->proto.sshc; struct ssh_conn *sshc = &conn->proto.sshc;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
while(sshc->state != SSH_STOP) { while((sshc->state != SSH_STOP) && !result)
result = ssh_statemach_act(conn); result = ssh_statemach_act(conn);
if(result) {
break;
}
}
return result; return result;
} }
@ -1844,9 +1858,6 @@ static CURLcode ssh_init(struct connectdata *conn)
data->reqdata.proto.ssh = ssh; data->reqdata.proto.ssh = ssh;
/* get some initial data into the ssh struct */
ssh->bytecountp = &data->reqdata.keep.bytecount;
return CURLE_OK; return CURLE_OK;
} }
@ -1978,17 +1989,6 @@ static CURLcode ssh_do(struct connectdata *conn, bool *done)
*done = FALSE; /* default to false */ *done = FALSE; /* default to false */
/*
* Since connections can be re-used between SessionHandles, this might be a
* connection already existing but on a fresh SessionHandle struct so we must
* make sure we have a good 'struct SSHPROTO' to play with. For new
* connections, the struct SSHPROTO is allocated and setup in the
* Curl_ssh_connect() function.
*/
res = ssh_init(conn);
if(res)
return res;
data->reqdata.size = -1; /* make sure this is unknown at this point */ data->reqdata.size = -1; /* make sure this is unknown at this point */
Curl_pgrsSetUploadCounter(data, 0); Curl_pgrsSetUploadCounter(data, 0);
@ -2011,6 +2011,9 @@ static CURLcode scp_disconnect(struct connectdata *conn)
{ {
CURLcode result; CURLcode result;
Curl_safefree(conn->data->reqdata.proto.ssh);
conn->data->reqdata.proto.ssh = NULL;
state(conn, SSH_SESSION_DISCONNECT); state(conn, SSH_SESSION_DISCONNECT);
result = ssh_easy_statemach(conn); result = ssh_easy_statemach(conn);
@ -2044,11 +2047,8 @@ static CURLcode scp_done(struct connectdata *conn, CURLcode status,
if(done) { if(done) {
struct SSHPROTO *sftp_scp = conn->data->reqdata.proto.ssh; struct SSHPROTO *sftp_scp = conn->data->reqdata.proto.ssh;
Curl_safefree(sftp_scp->path); Curl_safefree(sftp_scp->path);
sftp_scp->path = NULL;
Curl_safefree(sftp_scp);
conn->data->reqdata.proto.ssh = NULL;
Curl_pgrsDone(conn); Curl_pgrsDone(conn);
} }
@ -2154,6 +2154,9 @@ static CURLcode sftp_disconnect(struct connectdata *conn)
DEBUGF(infof(conn->data, "SSH DISCONNECT starts now\n")); DEBUGF(infof(conn->data, "SSH DISCONNECT starts now\n"));
Curl_safefree(conn->data->reqdata.proto.ssh);
conn->data->reqdata.proto.ssh = NULL;
state(conn, SSH_SFTP_SHUTDOWN); state(conn, SSH_SFTP_SHUTDOWN);
result = ssh_easy_statemach(conn); result = ssh_easy_statemach(conn);
@ -2195,8 +2198,6 @@ static CURLcode sftp_done(struct connectdata *conn, CURLcode status,
} }
if(done) { if(done) {
Curl_safefree(conn->data->reqdata.proto.ssh);
conn->data->reqdata.proto.ssh = NULL;
Curl_pgrsDone(conn); Curl_pgrsDone(conn);
} }

View File

@ -490,7 +490,6 @@ typedef enum {
Everything that is strictly related to a connection is banned from this Everything that is strictly related to a connection is banned from this
struct. */ struct. */
struct SSHPROTO { struct SSHPROTO {
curl_off_t *bytecountp;
char *path; /* the path we operate on */ char *path; /* the path we operate on */
}; };