mirror of
https://github.com/curl/curl.git
synced 2026-07-22 19:47:16 +03:00
parent
0eed8b7330
commit
2253bc330f
64 changed files with 1218 additions and 1416 deletions
|
|
@ -74,12 +74,12 @@
|
|||
|
||||
/* A recent macro provided by libssh. Or make our own. */
|
||||
#ifndef SSH_STRING_FREE_CHAR
|
||||
#define SSH_STRING_FREE_CHAR(x) \
|
||||
do { \
|
||||
if(x) { \
|
||||
ssh_string_free_char(x); \
|
||||
x = NULL; \
|
||||
} \
|
||||
#define SSH_STRING_FREE_CHAR(x) \
|
||||
do { \
|
||||
if(x) { \
|
||||
ssh_string_free_char(x); \
|
||||
x = NULL; \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
|
|
@ -111,10 +111,9 @@ static CURLcode sftp_doing(struct Curl_easy *data,
|
|||
static CURLcode sftp_disconnect(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
bool dead);
|
||||
static
|
||||
CURLcode sftp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done);
|
||||
static CURLcode sftp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done);
|
||||
|
||||
static CURLcode myssh_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps);
|
||||
|
|
@ -189,22 +188,22 @@ const struct Curl_handler Curl_handler_sftp = {
|
|||
static CURLcode sftp_error_to_CURLE(int err)
|
||||
{
|
||||
switch(err) {
|
||||
case SSH_FX_OK:
|
||||
return CURLE_OK;
|
||||
case SSH_FX_OK:
|
||||
return CURLE_OK;
|
||||
|
||||
case SSH_FX_NO_SUCH_FILE:
|
||||
case SSH_FX_NO_SUCH_PATH:
|
||||
return CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
case SSH_FX_NO_SUCH_FILE:
|
||||
case SSH_FX_NO_SUCH_PATH:
|
||||
return CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
|
||||
case SSH_FX_PERMISSION_DENIED:
|
||||
case SSH_FX_WRITE_PROTECT:
|
||||
return CURLE_REMOTE_ACCESS_DENIED;
|
||||
case SSH_FX_PERMISSION_DENIED:
|
||||
case SSH_FX_WRITE_PROTECT:
|
||||
return CURLE_REMOTE_ACCESS_DENIED;
|
||||
|
||||
case SSH_FX_FILE_ALREADY_EXISTS:
|
||||
return CURLE_REMOTE_FILE_EXISTS;
|
||||
case SSH_FX_FILE_ALREADY_EXISTS:
|
||||
return CURLE_REMOTE_FILE_EXISTS;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return CURLE_SSH;
|
||||
|
|
@ -213,7 +212,7 @@ static CURLcode sftp_error_to_CURLE(int err)
|
|||
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
||||
static const char *myssh_statename(sshstate state)
|
||||
{
|
||||
static const char *const names[] = {
|
||||
static const char * const names[] = {
|
||||
"SSH_STOP",
|
||||
"SSH_INIT",
|
||||
"SSH_S_STARTUP",
|
||||
|
|
@ -284,7 +283,7 @@ static const char *myssh_statename(sshstate state)
|
|||
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */
|
||||
|
||||
|
||||
#define myssh_to(x,y,z) myssh_set_state(x,y,z)
|
||||
#define myssh_to(x, y, z) myssh_set_state(x, y, z)
|
||||
|
||||
/*
|
||||
* SSH State machine related code
|
||||
|
|
@ -328,8 +327,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc)
|
|||
enum curl_khmatch keymatch;
|
||||
struct curl_khkey foundkey;
|
||||
struct curl_khkey *knownkeyp = NULL;
|
||||
curl_sshkeycallback func =
|
||||
data->set.ssh_keyfunc;
|
||||
curl_sshkeycallback func = data->set.ssh_keyfunc;
|
||||
struct ssh_knownhosts_entry *knownhostsentry = NULL;
|
||||
struct curl_khkey knownkey;
|
||||
|
||||
|
|
@ -343,8 +341,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc)
|
|||
char md5buffer[33];
|
||||
const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5];
|
||||
|
||||
rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5,
|
||||
&hash, &hlen);
|
||||
rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5, &hash, &hlen);
|
||||
if(rc != SSH_OK || hlen != 16) {
|
||||
failf(data,
|
||||
"Denied establishing ssh session: md5 fingerprint not available");
|
||||
|
|
@ -352,7 +349,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc)
|
|||
}
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
curl_msnprintf(&md5buffer[i*2], 3, "%02x", (unsigned char)hash[i]);
|
||||
curl_msnprintf(&md5buffer[i * 2], 3, "%02x", (unsigned char)hash[i]);
|
||||
|
||||
infof(data, "SSH MD5 fingerprint: %s", md5buffer);
|
||||
|
||||
|
|
@ -461,7 +458,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc)
|
|||
|
||||
Curl_set_in_callback(data, TRUE);
|
||||
rc = func(data, knownkeyp, /* from the knownhosts file */
|
||||
&foundkey, /* from the remote host */
|
||||
&foundkey, /* from the remote host */
|
||||
keymatch, data->set.ssh_keyfunc_userp);
|
||||
Curl_set_in_callback(data, FALSE);
|
||||
|
||||
|
|
@ -519,8 +516,7 @@ static int myssh_to_SFTP_CLOSE(struct Curl_easy *data,
|
|||
struct ssh_conn *sshc)
|
||||
{
|
||||
myssh_to(data, sshc, SSH_SFTP_CLOSE);
|
||||
sshc->actualcode =
|
||||
sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session));
|
||||
sshc->actualcode = sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session));
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -613,7 +609,6 @@ static int myssh_in_SFTP_READDIR(struct Curl_easy *data,
|
|||
sshc->actualcode = result;
|
||||
return SSH_NO_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
if(curlx_dyn_add(&sshc->readdir_buf, sshc->readdir_longentry)) {
|
||||
|
|
@ -684,8 +679,7 @@ static int myssh_in_SFTP_READDIR_LINK(struct Curl_easy *data,
|
|||
|
||||
Curl_safefree(sshc->readdir_linkPath);
|
||||
|
||||
if(curlx_dyn_addf(&sshc->readdir_buf, " -> %s",
|
||||
sshc->readdir_filename)) {
|
||||
if(curlx_dyn_addf(&sshc->readdir_buf, " -> %s", sshc->readdir_filename)) {
|
||||
/* Not using:
|
||||
* return myssh_to_SFTP_CLOSE(data, sshc);
|
||||
*
|
||||
|
|
@ -808,56 +802,56 @@ static int myssh_auth_interactive(struct connectdata *conn,
|
|||
|
||||
restart:
|
||||
switch(sshc->kbd_state) {
|
||||
case 0:
|
||||
rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
case 0:
|
||||
rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
|
||||
if(rc != SSH_AUTH_INFO)
|
||||
return SSH_ERROR;
|
||||
|
||||
nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session);
|
||||
if(nprompts != 1)
|
||||
return SSH_ERROR;
|
||||
|
||||
rc = ssh_userauth_kbdint_setanswer(sshc->ssh_session, 0, conn->passwd);
|
||||
if(rc < 0)
|
||||
return SSH_ERROR;
|
||||
|
||||
FALLTHROUGH();
|
||||
case 1:
|
||||
sshc->kbd_state = 1;
|
||||
|
||||
rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
else if(rc == SSH_AUTH_SUCCESS)
|
||||
rc = SSH_OK;
|
||||
else if(rc == SSH_AUTH_INFO) {
|
||||
nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session);
|
||||
if(nprompts)
|
||||
return SSH_ERROR;
|
||||
|
||||
sshc->kbd_state = 2;
|
||||
goto restart;
|
||||
}
|
||||
else
|
||||
rc = SSH_ERROR;
|
||||
break;
|
||||
case 2:
|
||||
sshc->kbd_state = 2;
|
||||
|
||||
rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
else if(rc == SSH_AUTH_SUCCESS)
|
||||
rc = SSH_OK;
|
||||
else
|
||||
rc = SSH_ERROR;
|
||||
|
||||
break;
|
||||
default:
|
||||
if(rc != SSH_AUTH_INFO)
|
||||
return SSH_ERROR;
|
||||
|
||||
nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session);
|
||||
if(nprompts != 1)
|
||||
return SSH_ERROR;
|
||||
|
||||
rc = ssh_userauth_kbdint_setanswer(sshc->ssh_session, 0, conn->passwd);
|
||||
if(rc < 0)
|
||||
return SSH_ERROR;
|
||||
|
||||
FALLTHROUGH();
|
||||
case 1:
|
||||
sshc->kbd_state = 1;
|
||||
|
||||
rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
else if(rc == SSH_AUTH_SUCCESS)
|
||||
rc = SSH_OK;
|
||||
else if(rc == SSH_AUTH_INFO) {
|
||||
nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session);
|
||||
if(nprompts)
|
||||
return SSH_ERROR;
|
||||
|
||||
sshc->kbd_state = 2;
|
||||
goto restart;
|
||||
}
|
||||
else
|
||||
rc = SSH_ERROR;
|
||||
break;
|
||||
case 2:
|
||||
sshc->kbd_state = 2;
|
||||
|
||||
rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
else if(rc == SSH_AUTH_SUCCESS)
|
||||
rc = SSH_OK;
|
||||
else
|
||||
rc = SSH_ERROR;
|
||||
|
||||
break;
|
||||
default:
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
sshc->kbd_state = 0;
|
||||
|
|
@ -967,8 +961,7 @@ static int myssh_in_AUTH_PKEY_INIT(struct Curl_easy *data,
|
|||
* (2) use the "default" keys. */
|
||||
if(data->set.str[STRING_SSH_PRIVATE_KEY]) {
|
||||
if(sshc->pubkey && !data->set.ssl.key_passwd) {
|
||||
rc = ssh_userauth_try_publickey(sshc->ssh_session, NULL,
|
||||
sshc->pubkey);
|
||||
rc = ssh_userauth_try_publickey(sshc->ssh_session, NULL, sshc->pubkey);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
|
||||
|
|
@ -993,7 +986,7 @@ static int myssh_in_AUTH_PKEY_INIT(struct Curl_easy *data,
|
|||
}
|
||||
else {
|
||||
rc = ssh_userauth_publickey_auto(sshc->ssh_session, NULL,
|
||||
data->set.ssl.key_passwd);
|
||||
data->set.ssl.key_passwd);
|
||||
if(rc == SSH_AUTH_AGAIN)
|
||||
return SSH_AGAIN;
|
||||
|
||||
|
|
@ -1166,7 +1159,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data,
|
|||
}
|
||||
else
|
||||
/* Clear file before writing (normal behavior) */
|
||||
flags = O_WRONLY|O_CREAT|O_TRUNC;
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
|
||||
if(sshc->sftp_file)
|
||||
sftp_close(sshc->sftp_file);
|
||||
|
|
@ -1214,7 +1207,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data,
|
|||
}
|
||||
/* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */
|
||||
do {
|
||||
char scratch[4*1024];
|
||||
char scratch[4 * 1024];
|
||||
size_t readthisamountnow =
|
||||
(data->state.resume_from - passed >
|
||||
(curl_off_t)sizeof(scratch)) ?
|
||||
|
|
@ -1363,8 +1356,7 @@ static int myssh_in_SFTP_DOWNLOAD_STAT(struct Curl_easy *data,
|
|||
/* Now store the number of bytes we are expected to download */
|
||||
data->req.size = size - data->state.resume_from;
|
||||
data->req.maxdownload = size - data->state.resume_from;
|
||||
Curl_pgrsSetDownloadSize(data,
|
||||
size - data->state.resume_from);
|
||||
Curl_pgrsSetDownloadSize(data, size - data->state.resume_from);
|
||||
|
||||
rc = sftp_seek64(sshc->sftp_file, data->state.resume_from);
|
||||
if(rc)
|
||||
|
|
@ -1877,8 +1869,7 @@ static void conn_forget_socket(struct Curl_easy *data, int sockindex)
|
|||
if(conn && CONN_SOCK_IDX_VALID(sockindex)) {
|
||||
struct Curl_cfilter *cf = conn->cfilter[sockindex];
|
||||
if(cf)
|
||||
(void)Curl_conn_cf_cntrl(cf, data, TRUE,
|
||||
CF_CTRL_FORGET_SOCKET, 0, NULL);
|
||||
(void)Curl_conn_cf_cntrl(cf, data, TRUE, CF_CTRL_FORGET_SOCKET, 0, NULL);
|
||||
fake_sclose(conn->sock[sockindex]);
|
||||
conn->sock[sockindex] = CURL_SOCKET_BAD;
|
||||
}
|
||||
|
|
@ -2067,8 +2058,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
|
|||
break;
|
||||
if(rc && !sshc->acceptfail) {
|
||||
Curl_safefree(sshc->quote_path1);
|
||||
failf(data, "rm command failed: %s",
|
||||
ssh_get_error(sshc->ssh_session));
|
||||
failf(data, "rm command failed: %s", ssh_get_error(sshc->ssh_session));
|
||||
myssh_to(data, sshc, SSH_SFTP_CLOSE);
|
||||
sshc->nextstate = SSH_NO_STATE;
|
||||
sshc->actualcode = CURLE_QUOTE_ERROR;
|
||||
|
|
@ -2110,7 +2100,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
|
|||
if(data->state.upload)
|
||||
myssh_to(data, sshc, SSH_SFTP_UPLOAD_INIT);
|
||||
else if(sshp) {
|
||||
if(sshp->path[strlen(sshp->path)-1] == '/')
|
||||
if(sshp->path[strlen(sshp->path) - 1] == '/')
|
||||
myssh_to(data, sshc, SSH_SFTP_READDIR_INIT);
|
||||
else
|
||||
myssh_to(data, sshc, SSH_SFTP_DOWNLOAD_INIT);
|
||||
|
|
@ -2301,26 +2291,26 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
|
|||
FALLTHROUGH();
|
||||
|
||||
case SSH_SCP_DOWNLOAD: {
|
||||
curl_off_t bytecount;
|
||||
curl_off_t bytecount;
|
||||
|
||||
rc = ssh_scp_pull_request(sshc->scp_session);
|
||||
if(rc != SSH_SCP_REQUEST_NEWFILE) {
|
||||
err_msg = ssh_get_error(sshc->ssh_session);
|
||||
failf(data, "%s", err_msg);
|
||||
rc = myssh_to_ERROR(data, sshc, CURLE_REMOTE_FILE_NOT_FOUND);
|
||||
break;
|
||||
}
|
||||
|
||||
/* download data */
|
||||
bytecount = ssh_scp_request_get_size(sshc->scp_session);
|
||||
data->req.maxdownload = (curl_off_t) bytecount;
|
||||
Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount);
|
||||
|
||||
/* not set by Curl_xfer_setup to preserve keepon bits */
|
||||
conn->send_idx = 0;
|
||||
|
||||
myssh_to(data, sshc, SSH_STOP);
|
||||
rc = ssh_scp_pull_request(sshc->scp_session);
|
||||
if(rc != SSH_SCP_REQUEST_NEWFILE) {
|
||||
err_msg = ssh_get_error(sshc->ssh_session);
|
||||
failf(data, "%s", err_msg);
|
||||
rc = myssh_to_ERROR(data, sshc, CURLE_REMOTE_FILE_NOT_FOUND);
|
||||
break;
|
||||
}
|
||||
|
||||
/* download data */
|
||||
bytecount = ssh_scp_request_get_size(sshc->scp_session);
|
||||
data->req.maxdownload = (curl_off_t)bytecount;
|
||||
Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount);
|
||||
|
||||
/* not set by Curl_xfer_setup to preserve keepon bits */
|
||||
conn->send_idx = 0;
|
||||
|
||||
myssh_to(data, sshc, SSH_STOP);
|
||||
break;
|
||||
}
|
||||
case SSH_SCP_DONE:
|
||||
if(data->state.upload)
|
||||
|
|
@ -2406,7 +2396,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
|
|||
sshc->nextstate = SSH_NO_STATE;
|
||||
myssh_to(data, sshc, SSH_STOP);
|
||||
break;
|
||||
|
||||
}
|
||||
/* break the loop only on STOP or SSH_AGAIN. If `rc` is some
|
||||
* other error code, we will have progressed the state accordingly. */
|
||||
|
|
@ -2424,7 +2413,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* called by the multi interface to figure out what socket(s) to wait for and
|
||||
for what actions in the DO_DONE, PERFORM and WAITPERFORM states */
|
||||
static CURLcode myssh_pollset(struct Curl_easy *data,
|
||||
|
|
@ -2525,7 +2513,6 @@ static CURLcode myssh_block_statemach(struct Curl_easy *data,
|
|||
(void)Curl_socket_check(fd_read, CURL_SOCKET_BAD, CURL_SOCKET_BAD,
|
||||
left_ms > 1000 ? 1000 : left_ms);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -2717,9 +2704,8 @@ static CURLcode scp_doing(struct Curl_easy *data, bool *dophase_done)
|
|||
* the options previously setup.
|
||||
*/
|
||||
|
||||
static
|
||||
CURLcode scp_perform(struct Curl_easy *data,
|
||||
bool *connected, bool *dophase_done)
|
||||
static CURLcode scp_perform(struct Curl_easy *data,
|
||||
bool *connected, bool *dophase_done)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN);
|
||||
|
|
@ -2871,7 +2857,6 @@ static CURLcode myssh_done(struct Curl_easy *data,
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
static CURLcode scp_done(struct Curl_easy *data, CURLcode status,
|
||||
bool premature)
|
||||
{
|
||||
|
|
@ -2963,10 +2948,9 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex,
|
|||
* the options previously setup.
|
||||
*/
|
||||
|
||||
static
|
||||
CURLcode sftp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done)
|
||||
static CURLcode sftp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done)
|
||||
{
|
||||
struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN);
|
||||
CURLcode result = CURLE_OK;
|
||||
|
|
@ -3064,34 +3048,34 @@ static CURLcode sftp_send(struct Curl_easy *data, int sockindex,
|
|||
|
||||
#if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0)
|
||||
switch(sshc->sftp_send_state) {
|
||||
case 0:
|
||||
sftp_file_set_nonblocking(sshc->sftp_file);
|
||||
if(sftp_aio_begin_write(sshc->sftp_file, mem, len,
|
||||
&sshc->sftp_send_aio) == SSH_ERROR) {
|
||||
return CURLE_SEND_ERROR;
|
||||
}
|
||||
sshc->sftp_send_state = 1;
|
||||
FALLTHROUGH();
|
||||
case 1:
|
||||
nwrite = sftp_aio_wait_write(&sshc->sftp_send_aio);
|
||||
myssh_block2waitfor(conn, sshc, (nwrite == SSH_AGAIN) ? TRUE : FALSE);
|
||||
if(nwrite == SSH_AGAIN)
|
||||
return CURLE_AGAIN;
|
||||
else if(nwrite < 0)
|
||||
return CURLE_SEND_ERROR;
|
||||
|
||||
/*
|
||||
* sftp_aio_wait_write() would free sftp_send_aio and
|
||||
* assign it NULL in all cases except when it returns
|
||||
* SSH_AGAIN.
|
||||
*/
|
||||
|
||||
sshc->sftp_send_state = 0;
|
||||
*pnwritten = (size_t)nwrite;
|
||||
return CURLE_OK;
|
||||
default:
|
||||
/* we never reach here */
|
||||
case 0:
|
||||
sftp_file_set_nonblocking(sshc->sftp_file);
|
||||
if(sftp_aio_begin_write(sshc->sftp_file, mem, len,
|
||||
&sshc->sftp_send_aio) == SSH_ERROR) {
|
||||
return CURLE_SEND_ERROR;
|
||||
}
|
||||
sshc->sftp_send_state = 1;
|
||||
FALLTHROUGH();
|
||||
case 1:
|
||||
nwrite = sftp_aio_wait_write(&sshc->sftp_send_aio);
|
||||
myssh_block2waitfor(conn, sshc, (nwrite == SSH_AGAIN) ? TRUE : FALSE);
|
||||
if(nwrite == SSH_AGAIN)
|
||||
return CURLE_AGAIN;
|
||||
else if(nwrite < 0)
|
||||
return CURLE_SEND_ERROR;
|
||||
|
||||
/*
|
||||
* sftp_aio_wait_write() would free sftp_send_aio and
|
||||
* assign it NULL in all cases except when it returns
|
||||
* SSH_AGAIN.
|
||||
*/
|
||||
|
||||
sshc->sftp_send_state = 0;
|
||||
*pnwritten = (size_t)nwrite;
|
||||
return CURLE_OK;
|
||||
default:
|
||||
/* we never reach here */
|
||||
return CURLE_SEND_ERROR;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
|
|
@ -3143,54 +3127,53 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex,
|
|||
return CURLE_FAILED_INIT;
|
||||
|
||||
switch(sshc->sftp_recv_state) {
|
||||
case 0:
|
||||
case 0:
|
||||
#if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0)
|
||||
if(sftp_aio_begin_read(sshc->sftp_file, len,
|
||||
&sshc->sftp_recv_aio) == SSH_ERROR) {
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
#else
|
||||
sshc->sftp_file_index =
|
||||
sftp_async_read_begin(sshc->sftp_file, (uint32_t)len);
|
||||
if(sshc->sftp_file_index < 0)
|
||||
return CURLE_RECV_ERROR;
|
||||
#endif
|
||||
|
||||
FALLTHROUGH();
|
||||
case 1:
|
||||
sshc->sftp_recv_state = 1;
|
||||
|
||||
#if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0)
|
||||
nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len);
|
||||
#else
|
||||
nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len,
|
||||
(uint32_t)sshc->sftp_file_index);
|
||||
#endif
|
||||
|
||||
myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN));
|
||||
|
||||
if(nread == SSH_AGAIN)
|
||||
return CURLE_AGAIN;
|
||||
else if(nread < 0)
|
||||
return CURLE_RECV_ERROR;
|
||||
|
||||
/*
|
||||
* sftp_aio_wait_read() would free sftp_recv_aio and
|
||||
* assign it NULL in all cases except when it returns
|
||||
* SSH_AGAIN.
|
||||
*/
|
||||
|
||||
sshc->sftp_recv_state = 0;
|
||||
*pnread = (size_t)nread;
|
||||
return CURLE_OK;
|
||||
|
||||
default:
|
||||
/* we never reach here */
|
||||
if(sftp_aio_begin_read(sshc->sftp_file, len,
|
||||
&sshc->sftp_recv_aio) == SSH_ERROR) {
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
#else
|
||||
sshc->sftp_file_index =
|
||||
sftp_async_read_begin(sshc->sftp_file, (uint32_t)len);
|
||||
if(sshc->sftp_file_index < 0)
|
||||
return CURLE_RECV_ERROR;
|
||||
#endif
|
||||
|
||||
FALLTHROUGH();
|
||||
case 1:
|
||||
sshc->sftp_recv_state = 1;
|
||||
|
||||
#if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0)
|
||||
nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len);
|
||||
#else
|
||||
nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len,
|
||||
(uint32_t)sshc->sftp_file_index);
|
||||
#endif
|
||||
|
||||
myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN));
|
||||
|
||||
if(nread == SSH_AGAIN)
|
||||
return CURLE_AGAIN;
|
||||
else if(nread < 0)
|
||||
return CURLE_RECV_ERROR;
|
||||
|
||||
/*
|
||||
* sftp_aio_wait_read() would free sftp_recv_aio and
|
||||
* assign it NULL in all cases except when it returns
|
||||
* SSH_AGAIN.
|
||||
*/
|
||||
|
||||
sshc->sftp_recv_state = 0;
|
||||
*pnread = (size_t)nread;
|
||||
return CURLE_OK;
|
||||
|
||||
default:
|
||||
/* we never reach here */
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CURLcode Curl_ssh_init(void)
|
||||
{
|
||||
if(ssh_init()) {
|
||||
|
|
@ -3210,4 +3193,4 @@ void Curl_ssh_version(char *buffer, size_t buflen)
|
|||
(void)curl_msnprintf(buffer, buflen, "libssh/%s", ssh_version(0));
|
||||
}
|
||||
|
||||
#endif /* USE_LIBSSH */
|
||||
#endif /* USE_LIBSSH */
|
||||
|
|
|
|||
|
|
@ -154,12 +154,12 @@ const struct Curl_handler Curl_handler_sftp = {
|
|||
PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE
|
||||
};
|
||||
|
||||
static void
|
||||
kbd_callback(const char *name, int name_len, const char *instruction,
|
||||
int instruction_len, int num_prompts,
|
||||
const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
|
||||
LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
|
||||
void **abstract)
|
||||
static void kbd_callback(const char *name, int name_len,
|
||||
const char *instruction, int instruction_len,
|
||||
int num_prompts,
|
||||
const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
|
||||
LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
|
||||
void **abstract)
|
||||
{
|
||||
struct Curl_easy *data = (struct Curl_easy *)*abstract;
|
||||
|
||||
|
|
@ -187,30 +187,30 @@ kbd_callback(const char *name, int name_len, const char *instruction,
|
|||
static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err)
|
||||
{
|
||||
switch(err) {
|
||||
case LIBSSH2_FX_OK:
|
||||
return CURLE_OK;
|
||||
case LIBSSH2_FX_OK:
|
||||
return CURLE_OK;
|
||||
|
||||
case LIBSSH2_FX_NO_SUCH_FILE:
|
||||
case LIBSSH2_FX_NO_SUCH_PATH:
|
||||
return CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
case LIBSSH2_FX_NO_SUCH_FILE:
|
||||
case LIBSSH2_FX_NO_SUCH_PATH:
|
||||
return CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
|
||||
case LIBSSH2_FX_PERMISSION_DENIED:
|
||||
case LIBSSH2_FX_WRITE_PROTECT:
|
||||
case LIBSSH2_FX_LOCK_CONFlICT:
|
||||
return CURLE_REMOTE_ACCESS_DENIED;
|
||||
case LIBSSH2_FX_PERMISSION_DENIED:
|
||||
case LIBSSH2_FX_WRITE_PROTECT:
|
||||
case LIBSSH2_FX_LOCK_CONFlICT:
|
||||
return CURLE_REMOTE_ACCESS_DENIED;
|
||||
|
||||
case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM:
|
||||
case LIBSSH2_FX_QUOTA_EXCEEDED:
|
||||
return CURLE_REMOTE_DISK_FULL;
|
||||
case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM:
|
||||
case LIBSSH2_FX_QUOTA_EXCEEDED:
|
||||
return CURLE_REMOTE_DISK_FULL;
|
||||
|
||||
case LIBSSH2_FX_FILE_ALREADY_EXISTS:
|
||||
return CURLE_REMOTE_FILE_EXISTS;
|
||||
case LIBSSH2_FX_FILE_ALREADY_EXISTS:
|
||||
return CURLE_REMOTE_FILE_EXISTS;
|
||||
|
||||
case LIBSSH2_FX_DIR_NOT_EMPTY:
|
||||
return CURLE_QUOTE_ERROR;
|
||||
case LIBSSH2_FX_DIR_NOT_EMPTY:
|
||||
return CURLE_QUOTE_ERROR;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return CURLE_SSH;
|
||||
|
|
@ -219,39 +219,39 @@ static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err)
|
|||
static CURLcode libssh2_session_error_to_CURLE(int err)
|
||||
{
|
||||
switch(err) {
|
||||
/* Ordered by order of appearance in libssh2.h */
|
||||
case LIBSSH2_ERROR_NONE:
|
||||
return CURLE_OK;
|
||||
/* Ordered by order of appearance in libssh2.h */
|
||||
case LIBSSH2_ERROR_NONE:
|
||||
return CURLE_OK;
|
||||
|
||||
/* This is the error returned by libssh2_scp_recv2
|
||||
* on unknown file */
|
||||
case LIBSSH2_ERROR_SCP_PROTOCOL:
|
||||
return CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
/* This is the error returned by libssh2_scp_recv2
|
||||
* on unknown file */
|
||||
case LIBSSH2_ERROR_SCP_PROTOCOL:
|
||||
return CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
|
||||
case LIBSSH2_ERROR_SOCKET_NONE:
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
case LIBSSH2_ERROR_SOCKET_NONE:
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
|
||||
case LIBSSH2_ERROR_ALLOC:
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
case LIBSSH2_ERROR_ALLOC:
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
case LIBSSH2_ERROR_SOCKET_SEND:
|
||||
return CURLE_SEND_ERROR;
|
||||
case LIBSSH2_ERROR_SOCKET_SEND:
|
||||
return CURLE_SEND_ERROR;
|
||||
|
||||
case LIBSSH2_ERROR_HOSTKEY_INIT:
|
||||
case LIBSSH2_ERROR_HOSTKEY_SIGN:
|
||||
case LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED:
|
||||
case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED:
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
case LIBSSH2_ERROR_HOSTKEY_INIT:
|
||||
case LIBSSH2_ERROR_HOSTKEY_SIGN:
|
||||
case LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED:
|
||||
case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED:
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
|
||||
case LIBSSH2_ERROR_PASSWORD_EXPIRED:
|
||||
return CURLE_LOGIN_DENIED;
|
||||
case LIBSSH2_ERROR_PASSWORD_EXPIRED:
|
||||
return CURLE_LOGIN_DENIED;
|
||||
|
||||
case LIBSSH2_ERROR_SOCKET_TIMEOUT:
|
||||
case LIBSSH2_ERROR_TIMEOUT:
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
case LIBSSH2_ERROR_SOCKET_TIMEOUT:
|
||||
case LIBSSH2_ERROR_TIMEOUT:
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
|
||||
case LIBSSH2_ERROR_EAGAIN:
|
||||
return CURLE_AGAIN;
|
||||
case LIBSSH2_ERROR_EAGAIN:
|
||||
return CURLE_AGAIN;
|
||||
}
|
||||
|
||||
return CURLE_SSH;
|
||||
|
|
@ -283,7 +283,7 @@ static LIBSSH2_FREE_FUNC(my_libssh2_free)
|
|||
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
||||
static const char *myssh_statename(sshstate state)
|
||||
{
|
||||
static const char *const names[] = {
|
||||
static const char * const names[] = {
|
||||
"SSH_STOP",
|
||||
"SSH_INIT",
|
||||
"SSH_S_STARTUP",
|
||||
|
|
@ -354,7 +354,7 @@ static const char *myssh_statename(sshstate state)
|
|||
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */
|
||||
|
||||
|
||||
#define myssh_state(x,y,z) myssh_set_state(x,y,z)
|
||||
#define myssh_state(x, y, z) myssh_set_state(x, y, z)
|
||||
|
||||
/*
|
||||
* SSH State machine related code
|
||||
|
|
@ -663,7 +663,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data,
|
|||
/* The fingerprint points to static storage (!), do not free() it. */
|
||||
int i;
|
||||
for(i = 0; i < 16; i++) {
|
||||
curl_msnprintf(&md5buffer[i*2], 3, "%02x",
|
||||
curl_msnprintf(&md5buffer[i * 2], 3, "%02x",
|
||||
(unsigned char)fingerprint[i]);
|
||||
}
|
||||
|
||||
|
|
@ -703,7 +703,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data,
|
|||
rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp,
|
||||
(int)keytype, remotekey, keylen);
|
||||
Curl_set_in_callback(data, FALSE);
|
||||
if(rc!= CURLKHMATCH_OK) {
|
||||
if(rc != CURLKHMATCH_OK) {
|
||||
myssh_state(data, sshc, SSH_SESSION_FREE);
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
|
|
@ -1009,11 +1009,10 @@ static CURLcode sftp_quote(struct Curl_easy *data,
|
|||
return CURLE_QUOTE_ERROR;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
sftp_upload_init(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc,
|
||||
struct SSHPROTO *sshp,
|
||||
bool *blockp)
|
||||
static CURLcode sftp_upload_init(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc,
|
||||
struct SSHPROTO *sshp,
|
||||
bool *blockp)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
|
|
@ -1140,7 +1139,7 @@ sftp_upload_init(struct Curl_easy *data,
|
|||
}
|
||||
/* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */
|
||||
do {
|
||||
char scratch[4*1024];
|
||||
char scratch[4 * 1024];
|
||||
size_t readthisamountnow =
|
||||
(data->state.resume_from - passed >
|
||||
(curl_off_t)sizeof(scratch)) ?
|
||||
|
|
@ -1283,11 +1282,10 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
sftp_quote_stat(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc,
|
||||
struct SSHPROTO *sshp,
|
||||
bool *blockp)
|
||||
static CURLcode sftp_quote_stat(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc,
|
||||
struct SSHPROTO *sshp,
|
||||
bool *blockp)
|
||||
{
|
||||
char *cmd = sshc->quote_item->data;
|
||||
sshc->acceptfail = FALSE;
|
||||
|
|
@ -1395,11 +1393,10 @@ fail:
|
|||
return CURLE_QUOTE_ERROR;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
sftp_download_stat(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc,
|
||||
struct SSHPROTO *sshp,
|
||||
bool *blockp)
|
||||
static CURLcode sftp_download_stat(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc,
|
||||
struct SSHPROTO *sshp,
|
||||
bool *blockp)
|
||||
{
|
||||
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
||||
int rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshp->path,
|
||||
|
|
@ -1468,8 +1465,7 @@ sftp_download_stat(struct Curl_easy *data,
|
|||
/* Now store the number of bytes we are expected to download */
|
||||
data->req.size = attrs.filesize - data->state.resume_from;
|
||||
data->req.maxdownload = attrs.filesize - data->state.resume_from;
|
||||
Curl_pgrsSetDownloadSize(data,
|
||||
attrs.filesize - data->state.resume_from);
|
||||
Curl_pgrsSetDownloadSize(data, attrs.filesize - data->state.resume_from);
|
||||
libssh2_sftp_seek64(sshc->sftp_handle,
|
||||
(libssh2_uint64_t)data->state.resume_from);
|
||||
}
|
||||
|
|
@ -1507,7 +1503,7 @@ static CURLcode sftp_readdir(struct Curl_easy *data,
|
|||
return result;
|
||||
}
|
||||
if(rc > 0) {
|
||||
size_t readdir_len = (size_t) rc;
|
||||
size_t readdir_len = (size_t)rc;
|
||||
sshp->readdir_filename[readdir_len] = '\0';
|
||||
|
||||
if(data->set.list_only) {
|
||||
|
|
@ -1639,8 +1635,7 @@ static CURLcode ssh_state_authlist(struct Curl_easy *data,
|
|||
myssh_state(data, sshc, SSH_SESSION_FREE);
|
||||
return libssh2_session_error_to_CURLE(rc);
|
||||
}
|
||||
infof(data, "SSH authentication methods available: %s",
|
||||
sshc->authlist);
|
||||
infof(data, "SSH authentication methods available: %s", sshc->authlist);
|
||||
|
||||
myssh_state(data, sshc, SSH_AUTH_PKEY_INIT);
|
||||
return CURLE_OK;
|
||||
|
|
@ -1679,8 +1674,7 @@ static CURLcode ssh_state_auth_pkey(struct Curl_easy *data,
|
|||
err_msg = unknown;
|
||||
}
|
||||
else {
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
}
|
||||
infof(data, "SSH public key authentication failed: %s", err_msg);
|
||||
myssh_state(data, sshc, SSH_AUTH_PASS_INIT);
|
||||
|
|
@ -1742,8 +1736,8 @@ static CURLcode ssh_state_auth_agent_init(struct Curl_easy *data,
|
|||
struct ssh_conn *sshc)
|
||||
{
|
||||
int rc = 0;
|
||||
if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT)
|
||||
&& (strstr(sshc->authlist, "publickey") != NULL)) {
|
||||
if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) &&
|
||||
(strstr(sshc->authlist, "publickey") != NULL)) {
|
||||
|
||||
/* Connect to the ssh-agent */
|
||||
/* The agent could be shared by a curl thread i believe
|
||||
|
|
@ -1838,8 +1832,8 @@ static CURLcode ssh_state_auth_agent(struct Curl_easy *data,
|
|||
static CURLcode ssh_state_auth_key_init(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc)
|
||||
{
|
||||
if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD)
|
||||
&& (strstr(sshc->authlist, "keyboard-interactive") != NULL)) {
|
||||
if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) &&
|
||||
(strstr(sshc->authlist, "keyboard-interactive") != NULL)) {
|
||||
myssh_state(data, sshc, SSH_AUTH_KEY);
|
||||
}
|
||||
else {
|
||||
|
|
@ -1913,8 +1907,7 @@ static CURLcode ssh_state_sftp_init(struct Curl_easy *data,
|
|||
LIBSSH2_ERROR_EAGAIN)
|
||||
return CURLE_AGAIN;
|
||||
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
failf(data, "Failure initializing sftp session: %s", err_msg);
|
||||
myssh_state(data, sshc, SSH_SESSION_FREE);
|
||||
return CURLE_FAILED_INIT;
|
||||
|
|
@ -2384,8 +2377,7 @@ static CURLcode ssh_state_scp_download_init(struct Curl_easy *data,
|
|||
LIBSSH2_ERROR_EAGAIN)
|
||||
return CURLE_AGAIN;
|
||||
|
||||
ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0));
|
||||
ssh_err = libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
failf(data, "%s", err_msg);
|
||||
myssh_state(data, sshc, SSH_SCP_CHANNEL_FREE);
|
||||
return libssh2_session_error_to_CURLE(ssh_err);
|
||||
|
|
@ -2415,8 +2407,7 @@ static CURLcode ssh_state_sftp_close(struct Curl_easy *data,
|
|||
|
||||
if(rc < 0) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg);
|
||||
}
|
||||
sshc->sftp_handle = NULL;
|
||||
|
|
@ -2454,8 +2445,7 @@ static CURLcode ssh_state_sftp_shutdown(struct Curl_easy *data,
|
|||
|
||||
if(rc < 0) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg,
|
||||
NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg);
|
||||
}
|
||||
sshc->sftp_handle = NULL;
|
||||
|
|
@ -2527,8 +2517,7 @@ static CURLcode ssh_state_scp_upload_init(struct Curl_easy *data,
|
|||
LIBSSH2_ERROR_EAGAIN)
|
||||
return CURLE_AGAIN;
|
||||
|
||||
ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0));
|
||||
ssh_err = libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
failf(data, "%s", err_msg);
|
||||
myssh_state(data, sshc, SSH_SCP_CHANNEL_FREE);
|
||||
result = libssh2_session_error_to_CURLE(ssh_err);
|
||||
|
|
@ -2567,10 +2556,8 @@ static CURLcode ssh_state_session_disconnect(struct Curl_easy *data,
|
|||
|
||||
if(rc < 0) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
infof(data, "Failed to free libssh2 scp subsystem: %d %s",
|
||||
rc, err_msg);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to free libssh2 scp subsystem: %d %s", rc, err_msg);
|
||||
}
|
||||
sshc->ssh_channel = NULL;
|
||||
}
|
||||
|
|
@ -2582,10 +2569,8 @@ static CURLcode ssh_state_session_disconnect(struct Curl_easy *data,
|
|||
|
||||
if(rc < 0) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
infof(data, "Failed to disconnect libssh2 session: %d %s",
|
||||
rc, err_msg);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to disconnect libssh2 session: %d %s", rc, err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2750,8 +2735,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data,
|
|||
}
|
||||
break;
|
||||
|
||||
case SSH_SFTP_FILETIME:
|
||||
{
|
||||
case SSH_SFTP_FILETIME: {
|
||||
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
||||
int rc;
|
||||
|
||||
|
|
@ -2778,7 +2762,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data,
|
|||
if(data->state.upload)
|
||||
myssh_state(data, sshc, SSH_SFTP_UPLOAD_INIT);
|
||||
else if(sshp) {
|
||||
if(sshp->path[strlen(sshp->path)-1] == '/')
|
||||
if(sshp->path[strlen(sshp->path) - 1] == '/')
|
||||
myssh_state(data, sshc, SSH_SFTP_READDIR_INIT);
|
||||
else
|
||||
myssh_state(data, sshc, SSH_SFTP_DOWNLOAD_INIT);
|
||||
|
|
@ -3097,8 +3081,8 @@ static void ssh_block2waitfor(struct Curl_easy *data,
|
|||
dir = libssh2_session_block_directions(sshc->ssh_session);
|
||||
if(dir) {
|
||||
/* translate the libssh2 define bits into our own bit defines */
|
||||
sshc->waitfor = ((dir&LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) |
|
||||
((dir&LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0);
|
||||
sshc->waitfor = ((dir & LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) |
|
||||
((dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0);
|
||||
}
|
||||
}
|
||||
if(!dir)
|
||||
|
|
@ -3308,24 +3292,24 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
|
|||
{
|
||||
const char *crypto_str;
|
||||
switch(libssh2_crypto_engine()) {
|
||||
case libssh2_gcrypt:
|
||||
crypto_str = "libgcrypt";
|
||||
break;
|
||||
case libssh2_mbedtls:
|
||||
crypto_str = "mbedTLS";
|
||||
break;
|
||||
case libssh2_openssl:
|
||||
crypto_str = "openssl compatible";
|
||||
break;
|
||||
case libssh2_os400qc3:
|
||||
crypto_str = "OS400QC3";
|
||||
break;
|
||||
case libssh2_wincng:
|
||||
crypto_str = "WinCNG";
|
||||
break;
|
||||
default:
|
||||
crypto_str = NULL;
|
||||
break;
|
||||
case libssh2_gcrypt:
|
||||
crypto_str = "libgcrypt";
|
||||
break;
|
||||
case libssh2_mbedtls:
|
||||
crypto_str = "mbedTLS";
|
||||
break;
|
||||
case libssh2_openssl:
|
||||
crypto_str = "openssl compatible";
|
||||
break;
|
||||
case libssh2_os400qc3:
|
||||
crypto_str = "OS400QC3";
|
||||
break;
|
||||
case libssh2_wincng:
|
||||
crypto_str = "WinCNG";
|
||||
break;
|
||||
default:
|
||||
crypto_str = NULL;
|
||||
break;
|
||||
}
|
||||
if(crypto_str)
|
||||
infof(data, "libssh2 cryptography backend: %s", crypto_str);
|
||||
|
|
@ -3476,10 +3460,9 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
|
|||
* the options previously setup.
|
||||
*/
|
||||
|
||||
static
|
||||
CURLcode scp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done)
|
||||
static CURLcode scp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done)
|
||||
{
|
||||
struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN);
|
||||
CURLcode result = CURLE_OK;
|
||||
|
|
@ -3562,8 +3545,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data,
|
|||
rc = libssh2_agent_disconnect(sshc->ssh_agent);
|
||||
if((rc < 0) && data) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to disconnect from libssh2 agent: %d %s",
|
||||
rc, err_msg);
|
||||
}
|
||||
|
|
@ -3583,8 +3565,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data,
|
|||
rc = libssh2_sftp_close(sshc->sftp_handle);
|
||||
if((rc < 0) && data) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg,
|
||||
NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg);
|
||||
}
|
||||
if(!block && (rc == LIBSSH2_ERROR_EAGAIN))
|
||||
|
|
@ -3597,10 +3578,8 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data,
|
|||
rc = libssh2_channel_free(sshc->ssh_channel);
|
||||
if((rc < 0) && data) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
infof(data, "Failed to free libssh2 scp subsystem: %d %s",
|
||||
rc, err_msg);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to free libssh2 scp subsystem: %d %s", rc, err_msg);
|
||||
}
|
||||
if(!block && (rc == LIBSSH2_ERROR_EAGAIN))
|
||||
return CURLE_AGAIN;
|
||||
|
|
@ -3612,8 +3591,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data,
|
|||
rc = libssh2_sftp_shutdown(sshc->sftp_session);
|
||||
if((rc < 0) && data) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to stop libssh2 sftp subsystem: %d %s", rc, err_msg);
|
||||
}
|
||||
if(!block && (rc == LIBSSH2_ERROR_EAGAIN))
|
||||
|
|
@ -3626,8 +3604,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data,
|
|||
rc = libssh2_session_free(sshc->ssh_session);
|
||||
if((rc < 0) && data) {
|
||||
char *err_msg = NULL;
|
||||
(void)libssh2_session_last_error(sshc->ssh_session,
|
||||
&err_msg, NULL, 0);
|
||||
(void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
|
||||
infof(data, "Failed to free libssh2 session: %d %s", rc, err_msg);
|
||||
}
|
||||
if(!block && (rc == LIBSSH2_ERROR_EAGAIN))
|
||||
|
|
@ -3653,7 +3630,6 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data,
|
|||
return CURLE_OK;
|
||||
}
|
||||
|
||||
|
||||
/* BLOCKING, but the function is using the state machine so the only reason
|
||||
this is still blocking is that the multi interface code has no support for
|
||||
disconnecting operations that takes a while */
|
||||
|
|
@ -3701,7 +3677,6 @@ static CURLcode ssh_done(struct Curl_easy *data, CURLcode status)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
static CURLcode scp_done(struct Curl_easy *data, CURLcode status,
|
||||
bool premature)
|
||||
{
|
||||
|
|
@ -3731,8 +3706,8 @@ static CURLcode scp_send(struct Curl_easy *data, int sockindex,
|
|||
return CURLE_FAILED_INIT;
|
||||
|
||||
/* libssh2_channel_write() returns int! */
|
||||
nwritten = (ssize_t) libssh2_channel_write(sshc->ssh_channel,
|
||||
(const char *)mem, len);
|
||||
nwritten = (ssize_t)libssh2_channel_write(sshc->ssh_channel,
|
||||
(const char *)mem, len);
|
||||
|
||||
ssh_block2waitfor(data, sshc, (nwritten == LIBSSH2_ERROR_EAGAIN));
|
||||
|
||||
|
|
@ -3761,7 +3736,7 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex,
|
|||
return CURLE_FAILED_INIT;
|
||||
|
||||
/* libssh2_channel_read() returns int */
|
||||
nread = (ssize_t) libssh2_channel_read(sshc->ssh_channel, mem, len);
|
||||
nread = (ssize_t)libssh2_channel_read(sshc->ssh_channel, mem, len);
|
||||
|
||||
ssh_block2waitfor(data, sshc, (nread == LIBSSH2_ERROR_EAGAIN));
|
||||
if(nread == LIBSSH2_ERROR_EAGAIN)
|
||||
|
|
@ -3787,10 +3762,9 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex,
|
|||
* the options previously setup.
|
||||
*/
|
||||
|
||||
static
|
||||
CURLcode sftp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done)
|
||||
static CURLcode sftp_perform(struct Curl_easy *data,
|
||||
bool *connected,
|
||||
bool *dophase_done)
|
||||
{
|
||||
struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN);
|
||||
CURLcode result = CURLE_OK;
|
||||
|
|
@ -3850,7 +3824,6 @@ static CURLcode sftp_disconnect(struct Curl_easy *data,
|
|||
sshc_cleanup(sshc, data, TRUE);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
static CURLcode sftp_done(struct Curl_easy *data, CURLcode status,
|
||||
|
|
@ -3934,65 +3907,65 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex,
|
|||
static const char *sftp_libssh2_strerror(unsigned long err)
|
||||
{
|
||||
switch(err) {
|
||||
case LIBSSH2_FX_NO_SUCH_FILE:
|
||||
return "No such file or directory";
|
||||
case LIBSSH2_FX_NO_SUCH_FILE:
|
||||
return "No such file or directory";
|
||||
|
||||
case LIBSSH2_FX_PERMISSION_DENIED:
|
||||
return "Permission denied";
|
||||
case LIBSSH2_FX_PERMISSION_DENIED:
|
||||
return "Permission denied";
|
||||
|
||||
case LIBSSH2_FX_FAILURE:
|
||||
return "Operation failed";
|
||||
case LIBSSH2_FX_FAILURE:
|
||||
return "Operation failed";
|
||||
|
||||
case LIBSSH2_FX_BAD_MESSAGE:
|
||||
return "Bad message from SFTP server";
|
||||
case LIBSSH2_FX_BAD_MESSAGE:
|
||||
return "Bad message from SFTP server";
|
||||
|
||||
case LIBSSH2_FX_NO_CONNECTION:
|
||||
return "Not connected to SFTP server";
|
||||
case LIBSSH2_FX_NO_CONNECTION:
|
||||
return "Not connected to SFTP server";
|
||||
|
||||
case LIBSSH2_FX_CONNECTION_LOST:
|
||||
return "Connection to SFTP server lost";
|
||||
case LIBSSH2_FX_CONNECTION_LOST:
|
||||
return "Connection to SFTP server lost";
|
||||
|
||||
case LIBSSH2_FX_OP_UNSUPPORTED:
|
||||
return "Operation not supported by SFTP server";
|
||||
case LIBSSH2_FX_OP_UNSUPPORTED:
|
||||
return "Operation not supported by SFTP server";
|
||||
|
||||
case LIBSSH2_FX_INVALID_HANDLE:
|
||||
return "Invalid handle";
|
||||
case LIBSSH2_FX_INVALID_HANDLE:
|
||||
return "Invalid handle";
|
||||
|
||||
case LIBSSH2_FX_NO_SUCH_PATH:
|
||||
return "No such file or directory";
|
||||
case LIBSSH2_FX_NO_SUCH_PATH:
|
||||
return "No such file or directory";
|
||||
|
||||
case LIBSSH2_FX_FILE_ALREADY_EXISTS:
|
||||
return "File already exists";
|
||||
case LIBSSH2_FX_FILE_ALREADY_EXISTS:
|
||||
return "File already exists";
|
||||
|
||||
case LIBSSH2_FX_WRITE_PROTECT:
|
||||
return "File is write protected";
|
||||
case LIBSSH2_FX_WRITE_PROTECT:
|
||||
return "File is write protected";
|
||||
|
||||
case LIBSSH2_FX_NO_MEDIA:
|
||||
return "No media";
|
||||
case LIBSSH2_FX_NO_MEDIA:
|
||||
return "No media";
|
||||
|
||||
case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM:
|
||||
return "Disk full";
|
||||
case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM:
|
||||
return "Disk full";
|
||||
|
||||
case LIBSSH2_FX_QUOTA_EXCEEDED:
|
||||
return "User quota exceeded";
|
||||
case LIBSSH2_FX_QUOTA_EXCEEDED:
|
||||
return "User quota exceeded";
|
||||
|
||||
case LIBSSH2_FX_UNKNOWN_PRINCIPLE:
|
||||
return "Unknown principle";
|
||||
case LIBSSH2_FX_UNKNOWN_PRINCIPLE:
|
||||
return "Unknown principle";
|
||||
|
||||
case LIBSSH2_FX_LOCK_CONFlICT:
|
||||
return "File lock conflict";
|
||||
case LIBSSH2_FX_LOCK_CONFlICT:
|
||||
return "File lock conflict";
|
||||
|
||||
case LIBSSH2_FX_DIR_NOT_EMPTY:
|
||||
return "Directory not empty";
|
||||
case LIBSSH2_FX_DIR_NOT_EMPTY:
|
||||
return "Directory not empty";
|
||||
|
||||
case LIBSSH2_FX_NOT_A_DIRECTORY:
|
||||
return "Not a directory";
|
||||
case LIBSSH2_FX_NOT_A_DIRECTORY:
|
||||
return "Not a directory";
|
||||
|
||||
case LIBSSH2_FX_INVALID_FILENAME:
|
||||
return "Invalid filename";
|
||||
case LIBSSH2_FX_INVALID_FILENAME:
|
||||
return "Invalid filename";
|
||||
|
||||
case LIBSSH2_FX_LINK_LOOP:
|
||||
return "Link points to itself";
|
||||
case LIBSSH2_FX_LINK_LOOP:
|
||||
return "Link points to itself";
|
||||
}
|
||||
return "Unknown error in libssh2";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ struct ssh_conn {
|
|||
|
||||
#ifdef USE_LIBSSH
|
||||
#if LIBSSH_VERSION_INT < SSH_VERSION_INT(0, 9, 0)
|
||||
# error "SCP/SFTP protocols require libssh 0.9.0 or later"
|
||||
#error "SCP/SFTP protocols require libssh 0.9.0 or later"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ struct ssh_conn {
|
|||
non-configure platforms */
|
||||
|
||||
#if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x010208)
|
||||
# error "SCP/SFTP protocols require libssh2 1.2.8 or later"
|
||||
#error "SCP/SFTP protocols require libssh2 1.2.8 or later"
|
||||
/* 1.2.8 was released on April 5 2011 */
|
||||
#endif
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ void Curl_ssh_attach(struct Curl_easy *data,
|
|||
#else
|
||||
/* for non-SSH builds */
|
||||
#define Curl_ssh_cleanup()
|
||||
#define Curl_ssh_attach(x,y)
|
||||
#define Curl_ssh_attach(x, y)
|
||||
#define Curl_ssh_init() 0
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data,
|
|||
/* Copy a separating '/' if homedir does not end with one */
|
||||
len = curlx_dyn_len(&npath);
|
||||
p = curlx_dyn_ptr(&npath);
|
||||
if(len && (p[len-1] != '/'))
|
||||
if(len && (p[len - 1] != '/'))
|
||||
copyfrom = 2;
|
||||
|
||||
if(curlx_dyn_addn(&npath, &working_path[copyfrom],
|
||||
|
|
@ -147,7 +147,6 @@ CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir)
|
|||
|
||||
if(!curlx_dyn_len(&out))
|
||||
goto fail;
|
||||
|
||||
}
|
||||
else {
|
||||
struct Curl_str word;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue