aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/vssh
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-10-16 12:11:24 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-10-16 12:11:24 +0000
commit40811e93f3fdf9342a9295369994012420fac548 (patch)
treea8d85e094a9c21e10aa250f537c101fc2016a049 /contrib/libs/curl/lib/vssh
parent30ebe5357bb143648c6be4d151ecd4944af81ada (diff)
parent28a0c4a9f297064538a018c512cd9bbd00a1a35d (diff)
downloadydb-40811e93f3fdf9342a9295369994012420fac548.tar.gz
Merge branch 'rightlib' into mergelibs-241016-1210
Diffstat (limited to 'contrib/libs/curl/lib/vssh')
-rw-r--r--contrib/libs/curl/lib/vssh/libssh.c276
-rw-r--r--contrib/libs/curl/lib/vssh/libssh2.c275
-rw-r--r--contrib/libs/curl/lib/vssh/ssh.h8
-rw-r--r--contrib/libs/curl/lib/vssh/wolfssh.c77
4 files changed, 321 insertions, 315 deletions
diff --git a/contrib/libs/curl/lib/vssh/libssh.c b/contrib/libs/curl/lib/vssh/libssh.c
index 7addb23ea8..88bfd6a409 100644
--- a/contrib/libs/curl/lib/vssh/libssh.c
+++ b/contrib/libs/curl/lib/vssh/libssh.c
@@ -31,6 +31,9 @@
#include <limits.h>
+#error #include <libssh/libssh.h>
+#error #include <libssh/sftp.h>
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -86,6 +89,14 @@
#include "curl_memory.h"
#include "memdebug.h"
+/* in 0.10.0 or later, ignore deprecated warnings */
+#if defined(__GNUC__) && \
+ (LIBSSH_VERSION_MINOR >= 10) || \
+ (LIBSSH_VERSION_MAJOR > 0)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
/* A recent macro provided by libssh. Or make our own. */
#ifndef SSH_STRING_FREE_CHAR
#define SSH_STRING_FREE_CHAR(x) \
@@ -156,8 +167,7 @@ const struct Curl_handler Curl_handler_scp = {
ZERO_NULL, /* domore_getsock */
myssh_getsock, /* perform_getsock */
scp_disconnect, /* disconnect */
- ZERO_NULL, /* write_resp */
- ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
PORT_SSH, /* defport */
@@ -184,8 +194,7 @@ const struct Curl_handler Curl_handler_sftp = {
ZERO_NULL, /* domore_getsock */
myssh_getsock, /* perform_getsock */
sftp_disconnect, /* disconnect */
- ZERO_NULL, /* write_resp */
- ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
PORT_SSH, /* defport */
@@ -383,25 +392,28 @@ static int myssh_is_known(struct Curl_easy *data)
goto cleanup;
}
- if(data->set.str[STRING_SSH_KNOWNHOSTS]) {
+ if(data->set.ssl.primary.verifyhost != TRUE) {
+ rc = SSH_OK;
+ goto cleanup;
+ }
#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,9,0)
- /* Get the known_key from the known hosts file */
- vstate = ssh_session_get_known_hosts_entry(sshc->ssh_session,
- &knownhostsentry);
-
- /* Case an entry was found in a known hosts file */
- if(knownhostsentry) {
- if(knownhostsentry->publickey) {
- rc = ssh_pki_export_pubkey_base64(knownhostsentry->publickey,
- &known_base64);
- if(rc != SSH_OK) {
- goto cleanup;
- }
- knownkey.key = known_base64;
- knownkey.len = strlen(known_base64);
+ /* Get the known_key from the known hosts file */
+ vstate = ssh_session_get_known_hosts_entry(sshc->ssh_session,
+ &knownhostsentry);
- switch(ssh_key_type(knownhostsentry->publickey)) {
+ /* Case an entry was found in a known hosts file */
+ if(knownhostsentry) {
+ if(knownhostsentry->publickey) {
+ rc = ssh_pki_export_pubkey_base64(knownhostsentry->publickey,
+ &known_base64);
+ if(rc != SSH_OK) {
+ goto cleanup;
+ }
+ knownkey.key = known_base64;
+ knownkey.len = strlen(known_base64);
+
+ switch(ssh_key_type(knownhostsentry->publickey)) {
case SSH_KEYTYPE_RSA:
knownkey.keytype = CURLKHTYPE_RSA;
break;
@@ -423,51 +435,55 @@ static int myssh_is_known(struct Curl_easy *data)
default:
rc = SSH_ERROR;
goto cleanup;
- }
- knownkeyp = &knownkey;
}
+ knownkeyp = &knownkey;
}
+ }
- switch(vstate) {
+ switch(vstate) {
case SSH_KNOWN_HOSTS_OK:
keymatch = CURLKHMATCH_OK;
break;
case SSH_KNOWN_HOSTS_OTHER:
+ /* fallthrough */
case SSH_KNOWN_HOSTS_NOT_FOUND:
+ /* fallthrough */
case SSH_KNOWN_HOSTS_UNKNOWN:
+ /* fallthrough */
case SSH_KNOWN_HOSTS_ERROR:
keymatch = CURLKHMATCH_MISSING;
break;
- default:
+ default:
keymatch = CURLKHMATCH_MISMATCH;
break;
- }
+ }
#else
- vstate = ssh_is_server_known(sshc->ssh_session);
- switch(vstate) {
+ vstate = ssh_is_server_known(sshc->ssh_session);
+ switch(vstate) {
case SSH_SERVER_KNOWN_OK:
keymatch = CURLKHMATCH_OK;
break;
case SSH_SERVER_FILE_NOT_FOUND:
+ /* fallthrough */
case SSH_SERVER_NOT_KNOWN:
keymatch = CURLKHMATCH_MISSING;
break;
- default:
+ default:
keymatch = CURLKHMATCH_MISMATCH;
break;
- }
+ }
#endif
- if(func) { /* use callback to determine action */
- rc = ssh_pki_export_pubkey_base64(pubkey, &found_base64);
- if(rc != SSH_OK)
- goto cleanup;
+ if(func) { /* use callback to determine action */
+ rc = ssh_pki_export_pubkey_base64(pubkey, &found_base64);
+ if(rc != SSH_OK)
+ goto cleanup;
- foundkey.key = found_base64;
- foundkey.len = strlen(found_base64);
+ foundkey.key = found_base64;
+ foundkey.len = strlen(found_base64);
- switch(ssh_key_type(pubkey)) {
+ switch(ssh_key_type(pubkey)) {
case SSH_KEYTYPE_RSA:
foundkey.keytype = CURLKHTYPE_RSA;
break;
@@ -493,15 +509,15 @@ static int myssh_is_known(struct Curl_easy *data)
default:
rc = SSH_ERROR;
goto cleanup;
- }
+ }
- Curl_set_in_callback(data, true);
- rc = func(data, knownkeyp, /* from the knownhosts file */
- &foundkey, /* from the remote host */
- keymatch, data->set.ssh_keyfunc_userp);
- Curl_set_in_callback(data, false);
+ Curl_set_in_callback(data, true);
+ rc = func(data, knownkeyp, /* from the knownhosts file */
+ &foundkey, /* from the remote host */
+ keymatch, data->set.ssh_keyfunc_userp);
+ Curl_set_in_callback(data, false);
- switch(rc) {
+ switch(rc) {
case CURLKHSTAT_FINE_ADD_TO_FILE:
#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,8,0)
rc = ssh_session_update_known_hosts(sshc->ssh_session);
@@ -517,13 +533,12 @@ static int myssh_is_known(struct Curl_easy *data)
default: /* REJECT/DEFER */
rc = SSH_ERROR;
goto cleanup;
- }
}
- else {
- if(keymatch != CURLKHMATCH_OK) {
- rc = SSH_ERROR;
- goto cleanup;
- }
+ }
+ else {
+ if(keymatch != CURLKHMATCH_OK) {
+ rc = SSH_ERROR;
+ goto cleanup;
}
}
rc = SSH_OK;
@@ -614,7 +629,7 @@ restart:
if(rc < 0)
return SSH_ERROR;
- FALLTHROUGH();
+ /* FALLTHROUGH */
case 1:
sshc->kbd_state = 1;
@@ -656,7 +671,7 @@ restart:
/*
* ssh_statemach_act() runs the SSH state machine as far as it can without
- * blocking and without reaching the end. The data the pointer 'block' points
+ * blocking and without reaching the end. The data the pointer 'block' points
* to will be set to TRUE if the libssh function returns SSH_AGAIN
* meaning it wants to be called again when the socket is ready
*/
@@ -670,7 +685,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
int rc = SSH_NO_ERROR, err;
int seekerr = CURL_SEEKFUNC_OK;
const char *err_msg;
- *block = 0; /* we are not blocking by default */
+ *block = 0; /* we're not blocking by default */
do {
@@ -689,7 +704,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
ssh_set_blocking(sshc->ssh_session, 0);
state(data, SSH_S_STARTUP);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_S_STARTUP:
rc = ssh_connect(sshc->ssh_session);
@@ -704,7 +719,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
state(data, SSH_HOSTKEY);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_HOSTKEY:
rc = myssh_is_known(data);
@@ -714,7 +729,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
state(data, SSH_AUTHLIST);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_AUTHLIST:{
sshc->authed = FALSE;
@@ -735,8 +750,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
break;
}
- sshc->auth_methods =
- (unsigned int)ssh_userauth_list(sshc->ssh_session, NULL);
+ sshc->auth_methods = ssh_userauth_list(sshc->ssh_session, NULL);
if(sshc->auth_methods)
infof(data, "SSH authentication methods available: %s%s%s%s",
sshc->auth_methods & SSH_AUTH_METHOD_PUBLICKEY ?
@@ -896,7 +910,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
break;
}
state(data, SSH_AUTH_PASS);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_AUTH_PASS:
rc = ssh_userauth_password(sshc->ssh_session, NULL, conn->passwd);
@@ -959,7 +973,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
break;
}
state(data, SSH_SFTP_REALPATH);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_SFTP_REALPATH:
/*
* Get the "home" directory
@@ -1147,22 +1161,22 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
else if(statvfs) {
#ifdef _MSC_VER
- #define CURL_LIBSSH_VFS_SIZE_MASK "I64u"
+ #define LIBSSH_VFS_SIZE_MASK "I64u"
#else
- #define CURL_LIBSSH_VFS_SIZE_MASK PRIu64
+ #define LIBSSH_VFS_SIZE_MASK PRIu64
#endif
char *tmp = aprintf("statvfs:\n"
- "f_bsize: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_frsize: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_blocks: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_bfree: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_bavail: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_files: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_ffree: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_favail: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_fsid: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_flag: %" CURL_LIBSSH_VFS_SIZE_MASK "\n"
- "f_namemax: %" CURL_LIBSSH_VFS_SIZE_MASK "\n",
+ "f_bsize: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_frsize: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_blocks: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_bfree: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_bavail: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_files: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_ffree: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_favail: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_fsid: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_flag: %" LIBSSH_VFS_SIZE_MASK "\n"
+ "f_namemax: %" LIBSSH_VFS_SIZE_MASK "\n",
statvfs->f_bsize, statvfs->f_frsize,
statvfs->f_blocks, statvfs->f_bfree,
statvfs->f_bavail, statvfs->f_files,
@@ -1236,7 +1250,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
if(attrs) {
curl_off_t size = attrs->size;
if(size < 0) {
- failf(data, "Bad file size (%" FMT_OFF_T ")", size);
+ failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
MOVE_TO_ERROR_STATE(CURLE_BAD_DOWNLOAD_RESUME);
break;
}
@@ -1288,10 +1302,10 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
position. */
if(data->state.resume_from > 0) {
/* Let's read off the proper amount of bytes from the input. */
- if(data->set.seek_func) {
+ if(conn->seek_func) {
Curl_set_in_callback(data, true);
- seekerr = data->set.seek_func(data->set.seek_client,
- data->state.resume_from, SEEK_SET);
+ seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
+ SEEK_SET);
Curl_set_in_callback(data, false);
}
@@ -1302,16 +1316,15 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
failf(data, "Could not seek stream");
return CURLE_FTP_COULDNT_USE_REST;
}
- /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */
+ /* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
do {
- char scratch[4*1024];
size_t readthisamountnow =
- (data->state.resume_from - passed >
- (curl_off_t)sizeof(scratch)) ?
- sizeof(scratch) : curlx_sotouz(data->state.resume_from - passed);
+ (data->state.resume_from - passed > data->set.buffer_size) ?
+ (size_t)data->set.buffer_size :
+ curlx_sotouz(data->state.resume_from - passed);
size_t actuallyread =
- data->state.fread_func(scratch, 1,
+ data->state.fread_func(data->state.buffer, 1,
readthisamountnow, data->state.in);
passed += actuallyread;
@@ -1345,21 +1358,21 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
Curl_pgrsSetUploadSize(data, data->state.infilesize);
}
/* upload data */
- Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
- /* store this original bitmask setup to use later on if we cannot
+ /* store this original bitmask setup to use later on if we can't
figure out a "real" bitmask */
sshc->orig_waitfor = data->req.keepon;
/* we want to use the _sending_ function even when the socket turns
out readable as the underlying libssh sftp send function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_OUT;
+ conn->cselect_bits = CURL_CSELECT_OUT;
- /* since we do not really wait for anything at this point, we want the
+ /* since we don't really wait for anything at this point, we want the
state machine to move on as soon as possible so we set a very short
timeout here */
Curl_expire(data, 0, EXPIRE_RUN_NOW);
@@ -1398,7 +1411,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
++sshc->slash_pos;
if(rc < 0) {
/*
- * Abort if failure was not that the dir already exists or the
+ * Abort if failure wasn't that the dir already exists or the
* permission was denied (creation might succeed further down the
* path) - retry on unspecific FAILURE also
*/
@@ -1547,7 +1560,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->readdir_longentry = NULL;
state(data, SSH_SFTP_READDIR_BOTTOM);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_SFTP_READDIR_BOTTOM:
if(Curl_dyn_addn(&sshc->readdir_buf, "\n", 1))
result = CURLE_OUT_OF_MEMORY;
@@ -1571,7 +1584,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->sftp_dir = NULL;
/* no data to transfer */
- Curl_xfer_setup_nop(data);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
state(data, SSH_STOP);
break;
@@ -1605,9 +1618,9 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
!(attrs->flags & SSH_FILEXFER_ATTR_SIZE) ||
(attrs->size == 0)) {
/*
- * sftp_fstat did not return an error, so maybe the server
- * just does not support stat()
- * OR the server does not return a file size with a stat()
+ * sftp_fstat didn't return an error, so maybe the server
+ * just doesn't support stat()
+ * OR the server doesn't return a file size with a stat()
* OR file size is 0
*/
data->req.size = -1;
@@ -1621,7 +1634,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
sftp_attributes_free(attrs);
if(size < 0) {
- failf(data, "Bad file size (%" FMT_OFF_T ")", size);
+ failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
if(data->state.use_range) {
@@ -1651,8 +1664,9 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
to = size - 1;
}
if(from > size) {
- failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%"
- FMT_OFF_T ")", from, size);
+ failf(data, "Offset (%"
+ CURL_FORMAT_CURL_OFF_T ") was beyond file size (%"
+ CURL_FORMAT_CURL_OFF_T ")", from, size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
if(from > to) {
@@ -1660,8 +1674,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
size = 0;
}
else {
- if((to - from) == CURL_OFF_T_MAX)
- return CURLE_RANGE_ERROR;
size = to - from + 1;
}
@@ -1679,10 +1691,12 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
/* We can resume if we can seek to the resume position */
if(data->state.resume_from) {
if(data->state.resume_from < 0) {
- /* We are supposed to download the last abs(from) bytes */
+ /* We're supposed to download the last abs(from) bytes */
if((curl_off_t)size < -data->state.resume_from) {
- failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%"
- FMT_OFF_T ")", data->state.resume_from, size);
+ failf(data, "Offset (%"
+ CURL_FORMAT_CURL_OFF_T ") was beyond file size (%"
+ CURL_FORMAT_CURL_OFF_T ")",
+ data->state.resume_from, size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
/* download from where? */
@@ -1690,8 +1704,8 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
else {
if((curl_off_t)size < data->state.resume_from) {
- failf(data, "Offset (%" FMT_OFF_T
- ") was beyond file size (%" FMT_OFF_T ")",
+ failf(data, "Offset (%" CURL_FORMAT_CURL_OFF_T
+ ") was beyond file size (%" CURL_FORMAT_CURL_OFF_T ")",
data->state.resume_from, size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
@@ -1713,20 +1727,20 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
/* Setup the actual download */
if(data->req.size == 0) {
/* no data to transfer */
- Curl_xfer_setup_nop(data);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
infof(data, "File already completely downloaded");
state(data, SSH_STOP);
break;
}
- Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE);
+ Curl_setup_transfer(data, FIRSTSOCKET, data->req.size, FALSE, -1);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh recv function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_IN;
+ conn->cselect_bits = CURL_CSELECT_IN;
if(result) {
/* this should never occur; the close state should be entered
@@ -1842,19 +1856,19 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
/* upload data */
- Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
+ Curl_setup_transfer(data, -1, data->req.size, FALSE, FIRSTSOCKET);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
- /* store this original bitmask setup to use later on if we cannot
+ /* store this original bitmask setup to use later on if we can't
figure out a "real" bitmask */
sshc->orig_waitfor = data->req.keepon;
/* we want to use the _sending_ function even when the socket turns
out readable as the underlying libssh scp send function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_OUT;
+ conn->cselect_bits = CURL_CSELECT_OUT;
state(data, SSH_STOP);
@@ -1870,7 +1884,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
break;
}
state(data, SSH_SCP_DOWNLOAD);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_SCP_DOWNLOAD:{
curl_off_t bytecount;
@@ -1886,15 +1900,15 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
/* download data */
bytecount = ssh_scp_request_get_size(sshc->scp_session);
data->req.maxdownload = (curl_off_t) bytecount;
- Curl_xfer_setup1(data, CURL_XFER_RECV, bytecount, FALSE);
+ Curl_setup_transfer(data, FIRSTSOCKET, bytecount, FALSE, -1);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh recv function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_IN;
+ conn->cselect_bits = CURL_CSELECT_IN;
state(data, SSH_STOP);
break;
@@ -1934,10 +1948,10 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
ssh_set_blocking(sshc->ssh_session, 0);
state(data, SSH_SESSION_DISCONNECT);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_SESSION_DISCONNECT:
- /* during weird times when we have been prematurely aborted, the channel
+ /* during weird times when we've been prematurely aborted, the channel
is still alive when we reach this state and we MUST kill the channel
properly first */
if(sshc->scp_session) {
@@ -1957,7 +1971,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
data->state.most_recent_ftp_entrypath = NULL;
state(data, SSH_SESSION_FREE);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_SESSION_FREE:
if(sshc->ssh_session) {
ssh_free(sshc->ssh_session);
@@ -2008,6 +2022,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
break;
case SSH_QUIT:
+ /* fallthrough, just stop! */
default:
/* internal error */
sshc->nextstate = SSH_NO_STATE;
@@ -2054,7 +2069,7 @@ static void myssh_block2waitfor(struct connectdata *conn, bool block)
{
struct ssh_conn *sshc = &conn->proto.sshc;
- /* If it did not block, or nothing was returned by ssh_get_poll_flags
+ /* If it didn't block, or nothing was returned by ssh_get_poll_flags
* have the original set */
conn->waitfor = sshc->orig_waitfor;
@@ -2349,7 +2364,7 @@ static CURLcode scp_disconnect(struct Curl_easy *data,
(void) dead_connection;
if(ssh->ssh_session) {
- /* only if there is a session still around to use! */
+ /* only if there's a session still around to use! */
state(data, SSH_SESSION_DISCONNECT);
@@ -2396,13 +2411,12 @@ static CURLcode scp_done(struct Curl_easy *data, CURLcode status,
}
static ssize_t scp_send(struct Curl_easy *data, int sockindex,
- const void *mem, size_t len, bool eos, CURLcode *err)
+ const void *mem, size_t len, CURLcode *err)
{
int rc;
struct connectdata *conn = data->conn;
(void) sockindex; /* we only support SCP on the fixed known primary socket */
(void) err;
- (void)eos;
rc = ssh_scp_write(conn->proto.sshc.scp_session, mem, len);
@@ -2515,7 +2529,7 @@ static CURLcode sftp_disconnect(struct Curl_easy *data,
DEBUGF(infof(data, "SSH DISCONNECT starts now"));
if(conn->proto.sshc.ssh_session) {
- /* only if there is a session still around to use! */
+ /* only if there's a session still around to use! */
state(data, SSH_SFTP_SHUTDOWN);
result = myssh_block_statemach(data, TRUE);
}
@@ -2545,13 +2559,11 @@ static CURLcode sftp_done(struct Curl_easy *data, CURLcode status,
/* return number of sent bytes */
static ssize_t sftp_send(struct Curl_easy *data, int sockindex,
- const void *mem, size_t len, bool eos,
- CURLcode *err)
+ const void *mem, size_t len, CURLcode *err)
{
ssize_t nwrite;
struct connectdata *conn = data->conn;
(void)sockindex;
- (void)eos;
/* limit the writes to the maximum specified in Section 3 of
* https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02
@@ -2601,13 +2613,13 @@ static ssize_t sftp_recv(struct Curl_easy *data, int sockindex,
return -1;
}
- FALLTHROUGH();
+ /* FALLTHROUGH */
case 1:
conn->proto.sshc.sftp_recv_state = 1;
nread = sftp_async_read(conn->proto.sshc.sftp_file,
mem, (uint32_t)len,
- (uint32_t)conn->proto.sshc.sftp_file_index);
+ conn->proto.sshc.sftp_file_index);
myssh_block2waitfor(conn, (nread == SSH_AGAIN)?TRUE:FALSE);
@@ -2711,7 +2723,7 @@ static void sftp_quote(struct Curl_easy *data)
}
/*
- * SFTP is a binary protocol, so we do not send text commands
+ * SFTP is a binary protocol, so we don't send text commands
* to the server. Instead, we scan for commands used by
* OpenSSH's sftp program and call the appropriate libssh
* functions.
@@ -2945,4 +2957,10 @@ void Curl_ssh_version(char *buffer, size_t buflen)
(void)msnprintf(buffer, buflen, "libssh/%s", ssh_version(0));
}
+#if defined(__GNUC__) && \
+ (LIBSSH_VERSION_MINOR >= 10) || \
+ (LIBSSH_VERSION_MAJOR > 0)
+#pragma GCC diagnostic pop
+#endif
+
#endif /* USE_LIBSSH */
diff --git a/contrib/libs/curl/lib/vssh/libssh2.c b/contrib/libs/curl/lib/vssh/libssh2.c
index b01580c82d..6560dba2ed 100644
--- a/contrib/libs/curl/lib/vssh/libssh2.c
+++ b/contrib/libs/curl/lib/vssh/libssh2.c
@@ -30,6 +30,9 @@
#include <limits.h>
+#error #include <libssh2.h>
+#error #include <libssh2_sftp.h>
+
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
@@ -135,8 +138,7 @@ const struct Curl_handler Curl_handler_scp = {
ZERO_NULL, /* domore_getsock */
ssh_getsock, /* perform_getsock */
scp_disconnect, /* disconnect */
- ZERO_NULL, /* write_resp */
- ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ssh_attach, /* attach */
PORT_SSH, /* defport */
@@ -165,8 +167,7 @@ const struct Curl_handler Curl_handler_sftp = {
ZERO_NULL, /* domore_getsock */
ssh_getsock, /* perform_getsock */
sftp_disconnect, /* disconnect */
- ZERO_NULL, /* write_resp */
- ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ssh_attach, /* attach */
PORT_SSH, /* defport */
@@ -200,8 +201,7 @@ kbd_callback(const char *name, int name_len, const char *instruction,
if(num_prompts == 1) {
struct connectdata *conn = data->conn;
responses[0].text = strdup(conn->passwd);
- responses[0].length =
- responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd));
+ responses[0].length = curlx_uztoui(strlen(conn->passwd));
}
(void)prompts;
} /* kbd_callback */
@@ -402,8 +402,8 @@ static int sshkeycallback(struct Curl_easy *easy,
#endif
/*
- * Earlier libssh2 versions did not have the ability to seek to 64-bit
- * positions with 32-bit size_t.
+ * Earlier libssh2 versions didn't have the ability to seek to 64bit positions
+ * with 32bit size_t.
*/
#ifdef HAVE_LIBSSH2_SFTP_SEEK64
#define SFTP_SEEK(x,y) libssh2_sftp_seek64(x, (libssh2_uint64_t)y)
@@ -412,27 +412,27 @@ static int sshkeycallback(struct Curl_easy *easy,
#endif
/*
- * Earlier libssh2 versions did not do SCP properly beyond 32-bit sizes on
- * 32-bit architectures so we check of the necessary function is present.
+ * Earlier libssh2 versions didn't do SCP properly beyond 32bit sizes on 32bit
+ * architectures so we check of the necessary function is present.
*/
#ifndef HAVE_LIBSSH2_SCP_SEND64
#define SCP_SEND(a,b,c,d) libssh2_scp_send_ex(a, b, (int)(c), (size_t)d, 0, 0)
#else
#define SCP_SEND(a,b,c,d) libssh2_scp_send64(a, b, (int)(c), \
- (libssh2_int64_t)d, 0, 0)
+ (libssh2_uint64_t)d, 0, 0)
#endif
/*
- * libssh2 1.2.8 fixed the problem with 32-bit ints used for sockets on win64.
+ * libssh2 1.2.8 fixed the problem with 32bit ints used for sockets on win64.
*/
#ifdef HAVE_LIBSSH2_SESSION_HANDSHAKE
#define session_startup(x,y) libssh2_session_handshake(x, y)
#else
#define session_startup(x,y) libssh2_session_startup(x, (int)y)
#endif
-static enum curl_khtype convert_ssh2_keytype(int sshkeytype)
+static int convert_ssh2_keytype(int sshkeytype)
{
- enum curl_khtype keytype = CURLKHTYPE_UNKNOWN;
+ int keytype = CURLKHTYPE_UNKNOWN;
switch(sshkeytype) {
case LIBSSH2_HOSTKEY_TYPE_RSA:
keytype = CURLKHTYPE_RSA;
@@ -473,7 +473,7 @@ static CURLcode ssh_knownhost(struct Curl_easy *data)
#ifdef HAVE_LIBSSH2_KNOWNHOST_API
if(data->set.str[STRING_SSH_KNOWNHOSTS]) {
- /* we are asked to verify the host against a file */
+ /* we're asked to verify the host against a file */
struct connectdata *conn = data->conn;
struct ssh_conn *sshc = &conn->proto.sshc;
struct libssh2_knownhost *host = NULL;
@@ -484,8 +484,8 @@ static CURLcode ssh_knownhost(struct Curl_easy *data)
if(remotekey) {
/*
- * A subject to figure out is what hostname we need to pass in here.
- * What hostname does OpenSSH store in its file if an IDN name is
+ * A subject to figure out is what host name we need to pass in here.
+ * What host name does OpenSSH store in its file if an IDN name is
* used?
*/
enum curl_khmatch keymatch;
@@ -523,7 +523,7 @@ static CURLcode ssh_knownhost(struct Curl_easy *data)
break;
#endif
default:
- infof(data, "unsupported key type, cannot check knownhosts");
+ infof(data, "unsupported key type, can't check knownhosts");
keybit = 0;
break;
}
@@ -589,23 +589,25 @@ static CURLcode ssh_knownhost(struct Curl_easy *data)
switch(rc) {
default: /* unknown return codes will equal reject */
+ /* FALLTHROUGH */
case CURLKHSTAT_REJECT:
state(data, SSH_SESSION_FREE);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case CURLKHSTAT_DEFER:
/* DEFER means bail out but keep the SSH_HOSTKEY state */
result = sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION;
break;
case CURLKHSTAT_FINE_REPLACE:
- /* remove old host+key that does not match */
+ /* remove old host+key that doesn't match */
if(host)
libssh2_knownhost_del(sshc->kh, host);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case CURLKHSTAT_FINE:
+ /* FALLTHROUGH */
case CURLKHSTAT_FINE_ADD_TO_FILE:
/* proceed */
if(keycheck != LIBSSH2_KNOWNHOST_CHECK_MATCH) {
- /* the found host+key did not match but has been told to be fine
+ /* the found host+key didn't match but has been told to be fine
anyway so we add it in memory */
int addrc = libssh2_knownhost_add(sshc->kh,
conn->host.name, NULL,
@@ -659,7 +661,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data)
size_t b64_pos = 0;
#ifdef LIBSSH2_HOSTKEY_HASH_SHA256
- /* The fingerprint points to static storage (!), do not free() it. */
+ /* The fingerprint points to static storage (!), don't free() it. */
fingerprint = libssh2_hostkey_hash(sshc->ssh_session,
LIBSSH2_HOSTKEY_HASH_SHA256);
#else
@@ -739,7 +741,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data)
LIBSSH2_HOSTKEY_HASH_MD5);
if(fingerprint) {
- /* The fingerprint points to static storage (!), do not free() it. */
+ /* The fingerprint points to static storage (!), don't free() it. */
int i;
for(i = 0; i < 16; i++) {
msnprintf(&md5buffer[i*2], 3, "%02x", (unsigned char) fingerprint[i]);
@@ -777,10 +779,10 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data)
const char *remotekey = libssh2_session_hostkey(sshc->ssh_session,
&keylen, &sshkeytype);
if(remotekey) {
- enum curl_khtype keytype = convert_ssh2_keytype(sshkeytype);
+ int keytype = convert_ssh2_keytype(sshkeytype);
Curl_set_in_callback(data, true);
rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp,
- (int)keytype, remotekey, keylen);
+ keytype, remotekey, keylen);
Curl_set_in_callback(data, false);
if(rc!= CURLKHMATCH_OK) {
state(data, SSH_SESSION_FREE);
@@ -957,7 +959,7 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data)
/*
* ssh_statemach_act() runs the SSH state machine as far as it can without
- * blocking and without reaching the end. The data the pointer 'block' points
+ * blocking and without reaching the end. The data the pointer 'block' points
* to will be set to TRUE if the libssh2 function returns LIBSSH2_ERROR_EAGAIN
* meaning it wants to be called again when the socket is ready
*/
@@ -974,7 +976,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
unsigned long sftperr;
int seekerr = CURL_SEEKFUNC_OK;
size_t readdir_len;
- *block = 0; /* we are not blocking by default */
+ *block = 0; /* we're not blocking by default */
do {
switch(sshc->state) {
@@ -995,7 +997,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
}
state(data, SSH_S_STARTUP);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_S_STARTUP:
rc = session_startup(sshc->ssh_session, sock);
@@ -1014,7 +1016,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
state(data, SSH_HOSTKEY);
- FALLTHROUGH();
+ /* FALLTHROUGH */
case SSH_HOSTKEY:
/*
* Before we authenticate we should check the hostkey's fingerprint
@@ -1034,7 +1036,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
* must never change it later. Thus, always specify the correct username
* here, even though the libssh2 docs kind of indicate that it should be
* possible to get a 'generic' list (not user-specific) of authentication
- * methods, presumably with a blank username. That will not work in my
+ * methods, presumably with a blank username. That won't work in my
* experience.
* So always specify it here.
*/
@@ -1083,7 +1085,6 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
/* To ponder about: should really the lib be messing about with the
HOME environment variable etc? */
char *home = curl_getenv("HOME");
- struct_stat sbuf;
/* If no private key file is specified, try some common paths. */
if(home) {
@@ -1091,12 +1092,12 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->rsa = aprintf("%s/.ssh/id_rsa", home);
if(!sshc->rsa)
out_of_memory = TRUE;
- else if(stat(sshc->rsa, &sbuf)) {
+ else if(access(sshc->rsa, R_OK) != 0) {
Curl_safefree(sshc->rsa);
sshc->rsa = aprintf("%s/.ssh/id_dsa", home);
if(!sshc->rsa)
out_of_memory = TRUE;
- else if(stat(sshc->rsa, &sbuf)) {
+ else if(access(sshc->rsa, R_OK) != 0) {
Curl_safefree(sshc->rsa);
}
}
@@ -1105,10 +1106,10 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
if(!out_of_memory && !sshc->rsa) {
/* Nothing found; try the current dir. */
sshc->rsa = strdup("id_rsa");
- if(sshc->rsa && stat(sshc->rsa, &sbuf)) {
+ if(sshc->rsa && access(sshc->rsa, R_OK) != 0) {
Curl_safefree(sshc->rsa);
sshc->rsa = strdup("id_dsa");
- if(sshc->rsa && stat(sshc->rsa, &sbuf)) {
+ if(sshc->rsa && access(sshc->rsa, R_OK) != 0) {
Curl_safefree(sshc->rsa);
/* Out of guesses. Set to the empty string to avoid
* surprising info messages. */
@@ -1437,7 +1438,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
if(sftperr)
result = sftp_libssh2_error_to_CURLE(sftperr);
else
- /* in this case, the error was not in the SFTP level but for example
+ /* in this case, the error wasn't in the SFTP level but for example
a time-out or similar */
result = CURLE_SSH;
sshc->actualcode = result;
@@ -1568,7 +1569,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
}
/*
- * SFTP is a binary protocol, so we do not send text commands
+ * SFTP is a binary protocol, so we don't send text commands
* to the server. Instead, we scan for commands used by
* OpenSSH's sftp program and call the appropriate libssh2
* functions.
@@ -1706,7 +1707,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
if(!strncasecompare(cmd, "chmod", 5)) {
/* Since chown and chgrp only set owner OR group but libssh2 wants to
* set them both at once, we need to obtain the current ownership
- * first. This takes an extra protocol round trip.
+ * first. This takes an extra protocol round trip.
*/
rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshc->quote_path2,
curlx_uztoui(strlen(sshc->quote_path2)),
@@ -1783,7 +1784,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
}
#if SIZEOF_TIME_T > SIZEOF_LONG
if(date > 0xffffffff) {
- /* if 'long' cannot old >32-bit, this date cannot be sent */
+ /* if 'long' can't old >32bit, this date cannot be sent */
failf(data, "date overflow");
fail = TRUE;
}
@@ -1857,7 +1858,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
case SSH_SFTP_QUOTE_MKDIR:
rc = libssh2_sftp_mkdir_ex(sshc->sftp_session, sshc->quote_path1,
curlx_uztoui(strlen(sshc->quote_path1)),
- (long)data->set.new_directory_perms);
+ data->set.new_directory_perms);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
@@ -1960,22 +1961,22 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
}
else if(rc == 0) {
#ifdef _MSC_VER
- #define CURL_LIBSSH2_VFS_SIZE_MASK "I64u"
+ #define LIBSSH2_VFS_SIZE_MASK "I64u"
#else
- #define CURL_LIBSSH2_VFS_SIZE_MASK "llu"
+ #define LIBSSH2_VFS_SIZE_MASK "llu"
#endif
char *tmp = aprintf("statvfs:\n"
- "f_bsize: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_frsize: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_blocks: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_bfree: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_bavail: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_files: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_ffree: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_favail: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_fsid: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_flag: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n"
- "f_namemax: %" CURL_LIBSSH2_VFS_SIZE_MASK "\n",
+ "f_bsize: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_frsize: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_blocks: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_bfree: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_bavail: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_files: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_ffree: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_favail: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_fsid: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_flag: %" LIBSSH2_VFS_SIZE_MASK "\n"
+ "f_namemax: %" LIBSSH2_VFS_SIZE_MASK "\n",
statvfs.f_bsize, statvfs.f_frsize,
statvfs.f_blocks, statvfs.f_bfree,
statvfs.f_bavail, statvfs.f_files,
@@ -2023,7 +2024,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
break;
}
if(rc == 0) {
- data->info.filetime = (time_t)attrs.mtime;
+ data->info.filetime = attrs.mtime;
}
state(data, SSH_SFTP_TRANS_INIT);
@@ -2066,7 +2067,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
else {
curl_off_t size = attrs.filesize;
if(size < 0) {
- failf(data, "Bad file size (%" FMT_OFF_T ")", size);
+ failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
data->state.resume_from = attrs.filesize;
@@ -2087,7 +2088,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->sftp_handle =
libssh2_sftp_open_ex(sshc->sftp_session, sshp->path,
curlx_uztoui(strlen(sshp->path)),
- flags, (long)data->set.new_file_perms,
+ flags, data->set.new_file_perms,
LIBSSH2_SFTP_OPENFILE);
if(!sshc->sftp_handle) {
@@ -2143,10 +2144,10 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
position. */
if(data->state.resume_from > 0) {
/* Let's read off the proper amount of bytes from the input. */
- if(data->set.seek_func) {
+ if(conn->seek_func) {
Curl_set_in_callback(data, true);
- seekerr = data->set.seek_func(data->set.seek_client,
- data->state.resume_from, SEEK_SET);
+ seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
+ SEEK_SET);
Curl_set_in_callback(data, false);
}
@@ -2157,17 +2158,16 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
failf(data, "Could not seek stream");
return CURLE_FTP_COULDNT_USE_REST;
}
- /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */
+ /* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
do {
- char scratch[4*1024];
size_t readthisamountnow =
- (data->state.resume_from - passed >
- (curl_off_t)sizeof(scratch)) ?
- sizeof(scratch) : curlx_sotouz(data->state.resume_from - passed);
+ (data->state.resume_from - passed > data->set.buffer_size) ?
+ (size_t)data->set.buffer_size :
+ curlx_sotouz(data->state.resume_from - passed);
size_t actuallyread;
Curl_set_in_callback(data, true);
- actuallyread = data->state.fread_func(scratch, 1,
+ actuallyread = data->state.fread_func(data->state.buffer, 1,
readthisamountnow,
data->state.in);
Curl_set_in_callback(data, false);
@@ -2196,9 +2196,9 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
Curl_pgrsSetUploadSize(data, data->state.infilesize);
}
/* upload data */
- Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
if(result) {
@@ -2206,16 +2206,16 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->actualcode = result;
}
else {
- /* store this original bitmask setup to use later on if we cannot
+ /* store this original bitmask setup to use later on if we can't
figure out a "real" bitmask */
sshc->orig_waitfor = data->req.keepon;
/* we want to use the _sending_ function even when the socket turns
out readable as the underlying libssh2 sftp send function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_OUT;
+ conn->cselect_bits = CURL_CSELECT_OUT;
- /* since we do not really wait for anything at this point, we want the
+ /* since we don't really wait for anything at this point, we want the
state machine to move on as soon as possible so we set a very short
timeout here */
Curl_expire(data, 0, EXPIRE_RUN_NOW);
@@ -2251,7 +2251,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
/* 'mode' - parameter is preliminary - default to 0644 */
rc = libssh2_sftp_mkdir_ex(sshc->sftp_session, sshp->path,
curlx_uztoui(strlen(sshp->path)),
- (long)data->set.new_directory_perms);
+ data->set.new_directory_perms);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
@@ -2259,7 +2259,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
++sshc->slash_pos;
if(rc < 0) {
/*
- * Abort if failure was not that the dir already exists or the
+ * Abort if failure wasn't that the dir already exists or the
* permission was denied (creation might succeed further down the
* path) - retry on unspecific FAILURE also
*/
@@ -2399,8 +2399,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
rc =
libssh2_sftp_symlink_ex(sshc->sftp_session,
Curl_dyn_ptr(&sshp->readdir_link),
- (unsigned int)
- Curl_dyn_len(&sshp->readdir_link),
+ (int)Curl_dyn_len(&sshp->readdir_link),
sshp->readdir_filename,
PATH_MAX, LIBSSH2_SFTP_READLINK);
if(rc == LIBSSH2_ERROR_EAGAIN) {
@@ -2450,7 +2449,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
Curl_safefree(sshp->readdir_longentry);
/* no data to transfer */
- Curl_xfer_setup_nop(data);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
state(data, SSH_STOP);
break;
@@ -2461,7 +2460,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->sftp_handle =
libssh2_sftp_open_ex(sshc->sftp_session, sshp->path,
curlx_uztoui(strlen(sshp->path)),
- LIBSSH2_FXF_READ, (long)data->set.new_file_perms,
+ LIBSSH2_FXF_READ, data->set.new_file_perms,
LIBSSH2_SFTP_OPENFILE);
if(!sshc->sftp_handle) {
if(libssh2_session_last_errno(sshc->ssh_session) ==
@@ -2494,9 +2493,9 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
!(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) ||
(attrs.filesize == 0)) {
/*
- * libssh2_sftp_open() did not return an error, so maybe the server
- * just does not support stat()
- * OR the server does not return a file size with a stat()
+ * libssh2_sftp_open() didn't return an error, so maybe the server
+ * just doesn't support stat()
+ * OR the server doesn't return a file size with a stat()
* OR file size is 0
*/
data->req.size = -1;
@@ -2507,7 +2506,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
curl_off_t size = attrs.filesize;
if(size < 0) {
- failf(data, "Bad file size (%" FMT_OFF_T ")", size);
+ failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
if(data->state.use_range) {
@@ -2535,8 +2534,10 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
to = size - 1;
}
if(from > size) {
- failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%"
- FMT_OFF_T ")", from, (curl_off_t)attrs.filesize);
+ failf(data, "Offset (%"
+ CURL_FORMAT_CURL_OFF_T ") was beyond file size (%"
+ CURL_FORMAT_CURL_OFF_T ")", from,
+ (curl_off_t)attrs.filesize);
return CURLE_BAD_DOWNLOAD_RESUME;
}
if(from > to) {
@@ -2544,8 +2545,6 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
size = 0;
}
else {
- if((to - from) == CURL_OFF_T_MAX)
- return CURLE_RANGE_ERROR;
size = to - from + 1;
}
@@ -2559,10 +2558,11 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
/* We can resume if we can seek to the resume position */
if(data->state.resume_from) {
if(data->state.resume_from < 0) {
- /* We are supposed to download the last abs(from) bytes */
+ /* We're supposed to download the last abs(from) bytes */
if((curl_off_t)attrs.filesize < -data->state.resume_from) {
- failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%"
- FMT_OFF_T ")",
+ failf(data, "Offset (%"
+ CURL_FORMAT_CURL_OFF_T ") was beyond file size (%"
+ CURL_FORMAT_CURL_OFF_T ")",
data->state.resume_from, (curl_off_t)attrs.filesize);
return CURLE_BAD_DOWNLOAD_RESUME;
}
@@ -2571,8 +2571,8 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
}
else {
if((curl_off_t)attrs.filesize < data->state.resume_from) {
- failf(data, "Offset (%" FMT_OFF_T
- ") was beyond file size (%" FMT_OFF_T ")",
+ failf(data, "Offset (%" CURL_FORMAT_CURL_OFF_T
+ ") was beyond file size (%" CURL_FORMAT_CURL_OFF_T ")",
data->state.resume_from, (curl_off_t)attrs.filesize);
return CURLE_BAD_DOWNLOAD_RESUME;
}
@@ -2589,20 +2589,20 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
/* Setup the actual download */
if(data->req.size == 0) {
/* no data to transfer */
- Curl_xfer_setup_nop(data);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
infof(data, "File already completely downloaded");
state(data, SSH_STOP);
break;
}
- Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE);
+ Curl_setup_transfer(data, FIRSTSOCKET, data->req.size, FALSE, -1);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh2 recv function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_IN;
+ conn->cselect_bits = CURL_CSELECT_IN;
if(result) {
/* this should never occur; the close state should be entered
@@ -2708,7 +2708,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
case SSH_SCP_UPLOAD_INIT:
/*
* libssh2 requires that the destination path is a full path that
- * includes the destination file and name OR ends in a "/" . If this is
+ * includes the destination file and name OR ends in a "/" . If this is
* not done the destination file will be named the same name as the last
* directory in the path.
*/
@@ -2740,9 +2740,9 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
/* upload data */
data->req.size = data->state.infilesize;
Curl_pgrsSetUploadSize(data, data->state.infilesize);
- Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
if(result) {
@@ -2750,14 +2750,14 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->actualcode = result;
}
else {
- /* store this original bitmask setup to use later on if we cannot
+ /* store this original bitmask setup to use later on if we can't
figure out a "real" bitmask */
sshc->orig_waitfor = data->req.keepon;
/* we want to use the _sending_ function even when the socket turns
out readable as the underlying libssh2 scp send function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_OUT;
+ conn->cselect_bits = CURL_CSELECT_OUT;
state(data, SSH_STOP);
}
@@ -2811,15 +2811,15 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
/* download data */
bytecount = (curl_off_t)sb.st_size;
data->req.maxdownload = (curl_off_t)sb.st_size;
- Curl_xfer_setup1(data, CURL_XFER_RECV, bytecount, FALSE);
+ Curl_setup_transfer(data, FIRSTSOCKET, bytecount, FALSE, -1);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh2 recv function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_IN;
+ conn->cselect_bits = CURL_CSELECT_IN;
if(result) {
state(data, SSH_SCP_CHANNEL_FREE);
@@ -2910,7 +2910,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
break;
case SSH_SESSION_DISCONNECT:
- /* during weird times when we have been prematurely aborted, the channel
+ /* during weird times when we've been prematurely aborted, the channel
is still alive when we reach this state and we MUST kill the channel
properly first */
if(sshc->ssh_channel) {
@@ -3024,6 +3024,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
break;
case SSH_QUIT:
+ /* fallthrough, just stop! */
default:
/* internal error */
sshc->nextstate = SSH_NO_STATE;
@@ -3066,7 +3067,7 @@ static int ssh_getsock(struct Curl_easy *data,
* When one of the libssh2 functions has returned LIBSSH2_ERROR_EAGAIN this
* function is used to figure out in what direction and stores this info so
* that the multi interface can take advantage of it. Make sure to call this
- * function in all cases so that when it _does not_ return EAGAIN we can
+ * function in all cases so that when it _doesn't_ return EAGAIN we can
* restore the default wait bits.
*/
static void ssh_block2waitfor(struct Curl_easy *data, bool block)
@@ -3083,7 +3084,7 @@ static void ssh_block2waitfor(struct Curl_easy *data, bool block)
}
}
if(!dir)
- /* It did not block or libssh2 did not reveal in which direction, put back
+ /* It didn't block or libssh2 didn't reveal in which direction, put back
the original set */
conn->waitfor = sshc->orig_waitfor;
}
@@ -3099,7 +3100,7 @@ static CURLcode ssh_multi_statemach(struct Curl_easy *data, bool *done)
do {
result = ssh_statemach_act(data, &block);
*done = (sshc->state == SSH_STOP) ? TRUE : FALSE;
- /* if there is no error, it is not done and it did not EWOULDBLOCK, then
+ /* if there's no error, it isn't done and it didn't EWOULDBLOCK, then
try again */
} while(!result && !*done && !block);
ssh_block2waitfor(data, block);
@@ -3192,13 +3193,12 @@ static ssize_t ssh_tls_recv(libssh2_socket_t sock, void *buffer,
struct connectdata *conn = data->conn;
Curl_recv *backup = conn->recv[0];
struct ssh_conn *ssh = &conn->proto.sshc;
- int socknum = Curl_conn_sockindex(data, sock);
(void)flags;
/* swap in the TLS reader function for this call only, and then swap back
the SSH one again */
conn->recv[0] = ssh->tls_recv;
- result = Curl_conn_recv(data, socknum, buffer, length, &nread);
+ result = Curl_read(data, sock, buffer, length, &nread);
conn->recv[0] = backup;
if(result == CURLE_AGAIN)
return -EAGAIN; /* magic return code for libssh2 */
@@ -3212,25 +3212,24 @@ static ssize_t ssh_tls_send(libssh2_socket_t sock, const void *buffer,
size_t length, int flags, void **abstract)
{
struct Curl_easy *data = (struct Curl_easy *)*abstract;
- size_t nwrite;
+ ssize_t nwrite;
CURLcode result;
struct connectdata *conn = data->conn;
Curl_send *backup = conn->send[0];
struct ssh_conn *ssh = &conn->proto.sshc;
- int socknum = Curl_conn_sockindex(data, sock);
(void)flags;
/* swap in the TLS writer function for this call only, and then swap back
the SSH one again */
conn->send[0] = ssh->tls_send;
- result = Curl_conn_send(data, socknum, buffer, length, FALSE, &nwrite);
+ result = Curl_write(data, sock, buffer, length, &nwrite);
conn->send[0] = backup;
if(result == CURLE_AGAIN)
return -EAGAIN; /* magic return code for libssh2 */
else if(result)
return -1; /* error */
- Curl_debug(data, CURLINFO_DATA_OUT, (char *)buffer, nwrite);
- return (ssize_t)nwrite;
+ Curl_debug(data, CURLINFO_DATA_OUT, (char *)buffer, (size_t)nwrite);
+ return nwrite;
}
#endif
@@ -3271,7 +3270,7 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
#endif /* CURL_LIBSSH2_DEBUG */
/* libcurl MUST to set custom memory functions so that the kbd_callback
- function's memory allocations can be properly freed */
+ funciton's memory allocations can be properled freed */
sshc->ssh_session = libssh2_session_init_ex(my_libssh2_malloc,
my_libssh2_free,
my_libssh2_realloc, data);
@@ -3281,38 +3280,19 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
return CURLE_FAILED_INIT;
}
+#ifdef HAVE_LIBSSH2_VERSION
/* Set the packet read timeout if the libssh2 version supports it */
#if LIBSSH2_VERSION_NUM >= 0x010B00
if(data->set.server_response_timeout > 0) {
libssh2_session_set_read_timeout(sshc->ssh_session,
- (long)(data->set.server_response_timeout / 1000));
+ data->set.server_response_timeout / 1000);
}
#endif
+#endif
#ifndef CURL_DISABLE_PROXY
if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) {
/*
- Setup libssh2 callbacks to make it read/write TLS from the socket.
-
- ssize_t
- recvcb(libssh2_socket_t sock, void *buffer, size_t length,
- int flags, void **abstract);
-
- ssize_t
- sendcb(libssh2_socket_t sock, const void *buffer, size_t length,
- int flags, void **abstract);
-
- */
-#if LIBSSH2_VERSION_NUM >= 0x010b01
- infof(data, "Uses HTTPS proxy");
- libssh2_session_callback_set2(sshc->ssh_session,
- LIBSSH2_CALLBACK_RECV,
- (libssh2_cb_generic *)ssh_tls_recv);
- libssh2_session_callback_set2(sshc->ssh_session,
- LIBSSH2_CALLBACK_SEND,
- (libssh2_cb_generic *)ssh_tls_send);
-#else
- /*
* This crazy union dance is here to avoid assigning a void pointer a
* function pointer as it is invalid C. The problem is of course that
* libssh2 has such an API...
@@ -3332,11 +3312,22 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
sshsend.sendptr = ssh_tls_send;
infof(data, "Uses HTTPS proxy");
+ /*
+ Setup libssh2 callbacks to make it read/write TLS from the socket.
+
+ ssize_t
+ recvcb(libssh2_socket_t sock, void *buffer, size_t length,
+ int flags, void **abstract);
+
+ ssize_t
+ sendcb(libssh2_socket_t sock, const void *buffer, size_t length,
+ int flags, void **abstract);
+
+ */
libssh2_session_callback_set(sshc->ssh_session,
LIBSSH2_CALLBACK_RECV, sshrecv.recvp);
libssh2_session_callback_set(sshc->ssh_session,
LIBSSH2_CALLBACK_SEND, sshsend.sendp);
-#endif
/* Store the underlying TLS recv/send function pointers to be used when
reading from the proxy */
@@ -3486,7 +3477,7 @@ static CURLcode scp_disconnect(struct Curl_easy *data,
(void) dead_connection;
if(sshc->ssh_session) {
- /* only if there is a session still around to use! */
+ /* only if there's a session still around to use! */
state(data, SSH_SESSION_DISCONNECT);
result = ssh_block_statemach(data, conn, TRUE);
}
@@ -3534,13 +3525,12 @@ static CURLcode scp_done(struct Curl_easy *data, CURLcode status,
}
static ssize_t scp_send(struct Curl_easy *data, int sockindex,
- const void *mem, size_t len, bool eos, CURLcode *err)
+ const void *mem, size_t len, CURLcode *err)
{
ssize_t nwrite;
struct connectdata *conn = data->conn;
struct ssh_conn *sshc = &conn->proto.sshc;
(void)sockindex; /* we only support SCP on the fixed known primary socket */
- (void)eos;
/* libssh2_channel_write() returns int! */
nwrite = (ssize_t) libssh2_channel_write(sshc->ssh_channel, mem, len);
@@ -3643,7 +3633,7 @@ static CURLcode sftp_disconnect(struct Curl_easy *data,
DEBUGF(infof(data, "SSH DISCONNECT starts now"));
if(sshc->ssh_session) {
- /* only if there is a session still around to use! */
+ /* only if there's a session still around to use! */
state(data, SSH_SFTP_SHUTDOWN);
result = ssh_block_statemach(data, conn, TRUE);
}
@@ -3673,13 +3663,12 @@ static CURLcode sftp_done(struct Curl_easy *data, CURLcode status,
/* return number of sent bytes */
static ssize_t sftp_send(struct Curl_easy *data, int sockindex,
- const void *mem, size_t len, bool eos, CURLcode *err)
+ const void *mem, size_t len, CURLcode *err)
{
ssize_t nwrite;
struct connectdata *conn = data->conn;
struct ssh_conn *sshc = &conn->proto.sshc;
(void)sockindex;
- (void)eos;
nwrite = libssh2_sftp_write(sshc->sftp_handle, mem, len);
diff --git a/contrib/libs/curl/lib/vssh/ssh.h b/contrib/libs/curl/lib/vssh/ssh.h
index 1af514806b..ff1d0a1efe 100644
--- a/contrib/libs/curl/lib/vssh/ssh.h
+++ b/contrib/libs/curl/lib/vssh/ssh.h
@@ -30,8 +30,6 @@
#error #include <libssh2.h>
#error #include <libssh2_sftp.h>
#elif defined(USE_LIBSSH)
-/* in 0.10.0 or later, ignore deprecated warnings */
-#define SSH_SUPPRESS_DEPRECATED
#error #include <libssh/libssh.h>
#error #include <libssh/sftp.h>
#elif defined(USE_WOLFSSH)
@@ -165,7 +163,7 @@ struct ssh_conn {
unsigned kbd_state; /* 0 or 1 */
ssh_key privkey;
ssh_key pubkey;
- unsigned int auth_methods;
+ int auth_methods;
ssh_session ssh_session;
ssh_scp scp_session;
sftp_session sftp_session;
@@ -245,10 +243,10 @@ struct ssh_conn {
#endif
#ifdef HAVE_LIBSSH2_VERSION
-/* get it runtime if possible */
+/* get it run-time if possible */
#define CURL_LIBSSH2_VERSION libssh2_version(0)
#else
-/* use build-time if runtime not possible */
+/* use build-time if run-time not possible */
#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
#endif
diff --git a/contrib/libs/curl/lib/vssh/wolfssh.c b/contrib/libs/curl/lib/vssh/wolfssh.c
index 91b39a46b0..e32e98cc75 100644
--- a/contrib/libs/curl/lib/vssh/wolfssh.c
+++ b/contrib/libs/curl/lib/vssh/wolfssh.c
@@ -28,6 +28,8 @@
#include <limits.h>
+#error #include <wolfssh/ssh.h>
+#error #include <wolfssh/wolfsftp.h>
#include "urldata.h"
#include "cfilters.h"
#include "connect.h"
@@ -40,7 +42,6 @@
#include "select.h"
#include "multiif.h"
#include "warnless.h"
-#include "strdup.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -91,8 +92,7 @@ const struct Curl_handler Curl_handler_scp = {
ZERO_NULL, /* domore_getsock */
wssh_getsock, /* perform_getsock */
wscp_disconnect, /* disconnect */
- ZERO_NULL, /* write_resp */
- ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
PORT_SSH, /* defport */
@@ -121,8 +121,7 @@ const struct Curl_handler Curl_handler_sftp = {
ZERO_NULL, /* domore_getsock */
wssh_getsock, /* perform_getsock */
wsftp_disconnect, /* disconnect */
- ZERO_NULL, /* write_resp */
- ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
PORT_SSH, /* defport */
@@ -218,15 +217,13 @@ static void state(struct Curl_easy *data, sshstate nowstate)
}
static ssize_t wscp_send(struct Curl_easy *data, int sockindex,
- const void *mem, size_t len, bool eos,
- CURLcode *err)
+ const void *mem, size_t len, CURLcode *err)
{
ssize_t nwrite = 0;
(void)data;
(void)sockindex; /* we only support SCP on the fixed known primary socket */
(void)mem;
(void)len;
- (void)eos;
(void)err;
return nwrite;
@@ -247,14 +244,13 @@ static ssize_t wscp_recv(struct Curl_easy *data, int sockindex,
/* return number of sent bytes */
static ssize_t wsftp_send(struct Curl_easy *data, int sockindex,
- const void *mem, size_t len, bool eos, CURLcode *err)
+ const void *mem, size_t len, CURLcode *err)
{
struct connectdata *conn = data->conn;
struct ssh_conn *sshc = &conn->proto.sshc;
word32 offset[2];
int rc;
(void)sockindex;
- (void)eos;
offset[0] = (word32)sshc->offset&0xFFFFFFFF;
offset[1] = (word32)(sshc->offset>>32)&0xFFFFFFFF;
@@ -281,7 +277,7 @@ static ssize_t wsftp_send(struct Curl_easy *data, int sockindex,
return -1;
}
DEBUGASSERT(rc == (int)len);
- infof(data, "sent %zu bytes SFTP from offset %" FMT_OFF_T,
+ infof(data, "sent %zu bytes SFTP from offset %" CURL_FORMAT_CURL_OFF_T,
len, sshc->offset);
sshc->offset += len;
return (ssize_t)rc;
@@ -401,7 +397,7 @@ static CURLcode wssh_connect(struct Curl_easy *data, bool *done)
rc = wolfSSH_SetUsername(sshc->ssh_session, conn->user);
if(rc != WS_SUCCESS) {
- failf(data, "wolfSSH failed to set username");
+ failf(data, "wolfSSH failed to set user name");
goto error;
}
@@ -434,7 +430,7 @@ error:
/*
* wssh_statemach_act() runs the SSH state machine as far as it can without
- * blocking and without reaching the end. The data the pointer 'block' points
+ * blocking and without reaching the end. The data the pointer 'block' points
* to will be set to TRUE if the wolfssh function returns EAGAIN meaning it
* wants to be called again when the socket is ready
*/
@@ -447,7 +443,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
struct SSHPROTO *sftp_scp = data->req.p.ssh;
WS_SFTPNAME *name;
int rc = 0;
- *block = FALSE; /* we are not blocking by default */
+ *block = FALSE; /* we're not blocking by default */
do {
switch(sshc->state) {
@@ -516,9 +512,15 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
return CURLE_OK;
}
else if(name && (rc == WS_SUCCESS)) {
- sshc->homedir = Curl_memdup0(name->fName, name->fSz);
- if(!sshc->homedir)
+ sshc->homedir = malloc(name->fSz + 1);
+ if(!sshc->homedir) {
sshc->actualcode = CURLE_OUT_OF_MEMORY;
+ }
+ else {
+ memcpy(sshc->homedir, name->fName, name->fSz);
+ sshc->homedir[name->fSz] = 0;
+ infof(data, "wolfssh SFTP realpath succeeded");
+ }
wolfSSH_SFTPNAME_list_free(name);
state(data, SSH_STOP);
return CURLE_OK;
@@ -578,7 +580,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
else {
curl_off_t size = ((curl_off_t)attrs.sz[1] << 32) | attrs.sz[0];
if(size < 0) {
- failf(data, "Bad file size (%" FMT_OFF_T ")", size);
+ failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
return CURLE_BAD_DOWNLOAD_RESUME;
}
data->state.resume_from = size;
@@ -628,10 +630,10 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
if(data->state.resume_from > 0) {
/* Let's read off the proper amount of bytes from the input. */
int seekerr = CURL_SEEKFUNC_OK;
- if(data->set.seek_func) {
+ if(conn->seek_func) {
Curl_set_in_callback(data, true);
- seekerr = data->set.seek_func(data->set.seek_client,
- data->state.resume_from, SEEK_SET);
+ seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
+ SEEK_SET);
Curl_set_in_callback(data, false);
}
@@ -642,17 +644,16 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
failf(data, "Could not seek stream");
return CURLE_FTP_COULDNT_USE_REST;
}
- /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */
+ /* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
do {
- char scratch[4*1024];
size_t readthisamountnow =
- (data->state.resume_from - passed >
- (curl_off_t)sizeof(scratch)) ?
- sizeof(scratch) : curlx_sotouz(data->state.resume_from - passed);
+ (data->state.resume_from - passed > data->set.buffer_size) ?
+ (size_t)data->set.buffer_size :
+ curlx_sotouz(data->state.resume_from - passed);
size_t actuallyread;
Curl_set_in_callback(data, true);
- actuallyread = data->state.fread_func(scratch, 1,
+ actuallyread = data->state.fread_func(data->state.buffer, 1,
readthisamountnow,
data->state.in);
Curl_set_in_callback(data, false);
@@ -681,9 +682,9 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
Curl_pgrsSetUploadSize(data, data->state.infilesize);
}
/* upload data */
- Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
if(result) {
@@ -691,16 +692,16 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->actualcode = result;
}
else {
- /* store this original bitmask setup to use later on if we cannot
+ /* store this original bitmask setup to use later on if we can't
figure out a "real" bitmask */
sshc->orig_waitfor = data->req.keepon;
/* we want to use the _sending_ function even when the socket turns
out readable as the underlying libssh2 sftp send function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_OUT;
+ conn->cselect_bits = CURL_CSELECT_OUT;
- /* since we do not really wait for anything at this point, we want the
+ /* since we don't really wait for anything at this point, we want the
state machine to move on as soon as possible so we set a very short
timeout here */
Curl_expire(data, 0, EXPIRE_RUN_NOW);
@@ -769,7 +770,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
data->req.maxdownload = size;
Curl_pgrsSetDownloadSize(data, size);
- infof(data, "SFTP download %" FMT_OFF_T " bytes", size);
+ infof(data, "SFTP download %" CURL_FORMAT_CURL_OFF_T " bytes", size);
/* We cannot seek with wolfSSH so resuming and range requests are not
possible */
@@ -781,20 +782,20 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
/* Setup the actual download */
if(data->req.size == 0) {
/* no data to transfer */
- Curl_xfer_setup_nop(data);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
infof(data, "File already completely downloaded");
state(data, SSH_STOP);
break;
}
- Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE);
+ Curl_setup_transfer(data, FIRSTSOCKET, data->req.size, FALSE, -1);
- /* not set by Curl_xfer_setup to preserve keepon bits */
+ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh2 recv function will deal
with both accordingly */
- data->state.select_bits = CURL_CSELECT_IN;
+ conn->cselect_bits = CURL_CSELECT_IN;
if(result) {
/* this should never occur; the close state should be entered
@@ -909,7 +910,7 @@ static CURLcode wssh_multi_statemach(struct Curl_easy *data, bool *done)
do {
result = wssh_statemach_act(data, &block);
*done = (sshc->state == SSH_STOP) ? TRUE : FALSE;
- /* if there is no error, it is not done and it did not EWOULDBLOCK, then
+ /* if there's no error, it isn't done and it didn't EWOULDBLOCK, then
try again */
if(*done) {
DEBUGF(infof(data, "wssh_statemach_act says DONE"));
@@ -1122,7 +1123,7 @@ static CURLcode wsftp_disconnect(struct Curl_easy *data,
DEBUGF(infof(data, "SSH DISCONNECT starts now"));
if(conn->proto.sshc.ssh_session) {
- /* only if there is a session still around to use! */
+ /* only if there's a session still around to use! */
state(data, SSH_SFTP_SHUTDOWN);
result = wssh_block_statemach(data, TRUE);
}