2020-01-05 17:51:39 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2020-01-05 17:51:39 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2020-01-05 17:51:39 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2020-01-05 17:51:39 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "curl_setup.h"
|
|
|
|
|
|
|
|
#ifdef USE_WOLFSSH
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include <wolfssh/ssh.h>
|
|
|
|
#include <wolfssh/wolfsftp.h>
|
|
|
|
#include "urldata.h"
|
2022-11-11 18:45:34 +08:00
|
|
|
#include "cfilters.h"
|
2020-01-05 17:51:39 +08:00
|
|
|
#include "connect.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "progress.h"
|
|
|
|
#include "curl_path.h"
|
|
|
|
#include "strtoofft.h"
|
|
|
|
#include "transfer.h"
|
|
|
|
#include "speedcheck.h"
|
|
|
|
#include "select.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "warnless.h"
|
2023-12-05 22:55:35 +08:00
|
|
|
#include "strdup.h"
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
|
|
|
#include "curl_memory.h"
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_connect(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode wssh_multi_statemach(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode wssh_do(struct Curl_easy *data, bool *done);
|
2020-01-05 17:51:39 +08:00
|
|
|
#if 0
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wscp_done(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
CURLcode, bool premature);
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wscp_doing(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool *dophase_done);
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wscp_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool dead_connection);
|
|
|
|
#endif
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wsftp_done(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
CURLcode, bool premature);
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wsftp_doing(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool *dophase_done);
|
2021-01-21 20:46:59 +08:00
|
|
|
static CURLcode wsftp_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
bool dead);
|
|
|
|
static int wssh_getsock(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2020-01-05 17:51:39 +08:00
|
|
|
curl_socket_t *sock);
|
2021-01-21 20:46:59 +08:00
|
|
|
static CURLcode wssh_setup_connection(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* SCP protocol handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_scp = {
|
|
|
|
"SCP", /* scheme */
|
|
|
|
wssh_setup_connection, /* setup_connection */
|
|
|
|
wssh_do, /* do_it */
|
|
|
|
wscp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
wssh_connect, /* connect_it */
|
|
|
|
wssh_multi_statemach, /* connecting */
|
|
|
|
wscp_doing, /* doing */
|
|
|
|
wssh_getsock, /* proto_getsock */
|
|
|
|
wssh_getsock, /* doing_getsock */
|
|
|
|
ZERO_NULL, /* domore_getsock */
|
2021-01-21 20:46:59 +08:00
|
|
|
wssh_getsock, /* perform_getsock */
|
2020-01-05 17:51:39 +08:00
|
|
|
wscp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2020-01-05 17:51:39 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2020-01-05 17:51:39 +08:00
|
|
|
PORT_SSH, /* defport */
|
|
|
|
CURLPROTO_SCP, /* protocol */
|
|
|
|
PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION
|
|
|
|
| PROTOPT_NOURLQUERY /* flags */
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SFTP protocol handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_sftp = {
|
|
|
|
"SFTP", /* scheme */
|
|
|
|
wssh_setup_connection, /* setup_connection */
|
|
|
|
wssh_do, /* do_it */
|
|
|
|
wsftp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
wssh_connect, /* connect_it */
|
|
|
|
wssh_multi_statemach, /* connecting */
|
|
|
|
wsftp_doing, /* doing */
|
|
|
|
wssh_getsock, /* proto_getsock */
|
|
|
|
wssh_getsock, /* doing_getsock */
|
|
|
|
ZERO_NULL, /* domore_getsock */
|
2021-01-21 20:46:59 +08:00
|
|
|
wssh_getsock, /* perform_getsock */
|
2020-01-05 17:51:39 +08:00
|
|
|
wsftp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2020-01-05 17:51:39 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2020-01-05 17:51:39 +08:00
|
|
|
PORT_SSH, /* defport */
|
|
|
|
CURLPROTO_SFTP, /* protocol */
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLPROTO_SFTP, /* family */
|
2020-01-05 17:51:39 +08:00
|
|
|
PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION
|
|
|
|
| PROTOPT_NOURLQUERY /* flags */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSH State machine related code
|
|
|
|
*/
|
|
|
|
/* This is the ONLY way to change SSH state! */
|
2021-01-21 20:46:59 +08:00
|
|
|
static void state(struct Curl_easy *data, sshstate nowstate)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
2021-01-21 20:46:59 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
|
|
|
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
|
|
|
/* for debug purposes */
|
|
|
|
static const char * const names[] = {
|
|
|
|
"SSH_STOP",
|
|
|
|
"SSH_INIT",
|
|
|
|
"SSH_S_STARTUP",
|
|
|
|
"SSH_HOSTKEY",
|
|
|
|
"SSH_AUTHLIST",
|
|
|
|
"SSH_AUTH_PKEY_INIT",
|
|
|
|
"SSH_AUTH_PKEY",
|
|
|
|
"SSH_AUTH_PASS_INIT",
|
|
|
|
"SSH_AUTH_PASS",
|
|
|
|
"SSH_AUTH_AGENT_INIT",
|
|
|
|
"SSH_AUTH_AGENT_LIST",
|
|
|
|
"SSH_AUTH_AGENT",
|
|
|
|
"SSH_AUTH_HOST_INIT",
|
|
|
|
"SSH_AUTH_HOST",
|
|
|
|
"SSH_AUTH_KEY_INIT",
|
|
|
|
"SSH_AUTH_KEY",
|
|
|
|
"SSH_AUTH_GSSAPI",
|
|
|
|
"SSH_AUTH_DONE",
|
|
|
|
"SSH_SFTP_INIT",
|
|
|
|
"SSH_SFTP_REALPATH",
|
|
|
|
"SSH_SFTP_QUOTE_INIT",
|
|
|
|
"SSH_SFTP_POSTQUOTE_INIT",
|
|
|
|
"SSH_SFTP_QUOTE",
|
|
|
|
"SSH_SFTP_NEXT_QUOTE",
|
|
|
|
"SSH_SFTP_QUOTE_STAT",
|
|
|
|
"SSH_SFTP_QUOTE_SETSTAT",
|
|
|
|
"SSH_SFTP_QUOTE_SYMLINK",
|
|
|
|
"SSH_SFTP_QUOTE_MKDIR",
|
|
|
|
"SSH_SFTP_QUOTE_RENAME",
|
|
|
|
"SSH_SFTP_QUOTE_RMDIR",
|
|
|
|
"SSH_SFTP_QUOTE_UNLINK",
|
|
|
|
"SSH_SFTP_QUOTE_STATVFS",
|
|
|
|
"SSH_SFTP_GETINFO",
|
|
|
|
"SSH_SFTP_FILETIME",
|
|
|
|
"SSH_SFTP_TRANS_INIT",
|
|
|
|
"SSH_SFTP_UPLOAD_INIT",
|
|
|
|
"SSH_SFTP_CREATE_DIRS_INIT",
|
|
|
|
"SSH_SFTP_CREATE_DIRS",
|
|
|
|
"SSH_SFTP_CREATE_DIRS_MKDIR",
|
|
|
|
"SSH_SFTP_READDIR_INIT",
|
|
|
|
"SSH_SFTP_READDIR",
|
|
|
|
"SSH_SFTP_READDIR_LINK",
|
|
|
|
"SSH_SFTP_READDIR_BOTTOM",
|
|
|
|
"SSH_SFTP_READDIR_DONE",
|
|
|
|
"SSH_SFTP_DOWNLOAD_INIT",
|
|
|
|
"SSH_SFTP_DOWNLOAD_STAT",
|
|
|
|
"SSH_SFTP_CLOSE",
|
|
|
|
"SSH_SFTP_SHUTDOWN",
|
|
|
|
"SSH_SCP_TRANS_INIT",
|
|
|
|
"SSH_SCP_UPLOAD_INIT",
|
|
|
|
"SSH_SCP_DOWNLOAD_INIT",
|
|
|
|
"SSH_SCP_DOWNLOAD",
|
|
|
|
"SSH_SCP_DONE",
|
|
|
|
"SSH_SCP_SEND_EOF",
|
|
|
|
"SSH_SCP_WAIT_EOF",
|
|
|
|
"SSH_SCP_WAIT_CLOSE",
|
|
|
|
"SSH_SCP_CHANNEL_FREE",
|
|
|
|
"SSH_SESSION_DISCONNECT",
|
|
|
|
"SSH_SESSION_FREE",
|
|
|
|
"QUIT"
|
|
|
|
};
|
|
|
|
|
|
|
|
/* a precaution to make sure the lists are in sync */
|
|
|
|
DEBUGASSERT(sizeof(names)/sizeof(names[0]) == SSH_LAST);
|
|
|
|
|
|
|
|
if(sshc->state != nowstate) {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "wolfssh %p state change from %s to %s",
|
2020-01-05 17:51:39 +08:00
|
|
|
(void *)sshc, names[sshc->state], names[nowstate]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sshc->state = nowstate;
|
|
|
|
}
|
|
|
|
|
2021-01-21 20:46:59 +08:00
|
|
|
static ssize_t wscp_send(struct Curl_easy *data, int sockindex,
|
2020-01-05 17:51:39 +08:00
|
|
|
const void *mem, size_t len, CURLcode *err)
|
|
|
|
{
|
|
|
|
ssize_t nwrite = 0;
|
2021-01-21 20:46:59 +08:00
|
|
|
(void)data;
|
2020-01-05 17:51:39 +08:00
|
|
|
(void)sockindex; /* we only support SCP on the fixed known primary socket */
|
|
|
|
(void)mem;
|
|
|
|
(void)len;
|
|
|
|
(void)err;
|
|
|
|
|
|
|
|
return nwrite;
|
|
|
|
}
|
|
|
|
|
2021-01-21 20:46:59 +08:00
|
|
|
static ssize_t wscp_recv(struct Curl_easy *data, int sockindex,
|
2020-01-05 17:51:39 +08:00
|
|
|
char *mem, size_t len, CURLcode *err)
|
|
|
|
{
|
|
|
|
ssize_t nread = 0;
|
2021-01-21 20:46:59 +08:00
|
|
|
(void)data;
|
2020-01-05 17:51:39 +08:00
|
|
|
(void)sockindex; /* we only support SCP on the fixed known primary socket */
|
|
|
|
(void)mem;
|
|
|
|
(void)len;
|
|
|
|
(void)err;
|
|
|
|
|
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return number of sent bytes */
|
2021-01-21 20:46:59 +08:00
|
|
|
static ssize_t wsftp_send(struct Curl_easy *data, int sockindex,
|
2020-01-05 17:51:39 +08:00
|
|
|
const void *mem, size_t len, CURLcode *err)
|
|
|
|
{
|
2021-01-21 20:46:59 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
|
|
|
word32 offset[2];
|
|
|
|
int rc;
|
|
|
|
(void)sockindex;
|
|
|
|
|
2020-05-26 14:26:20 +08:00
|
|
|
offset[0] = (word32)sshc->offset&0xFFFFFFFF;
|
|
|
|
offset[1] = (word32)(sshc->offset>>32)&0xFFFFFFFF;
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
rc = wolfSSH_SFTP_SendWritePacket(sshc->ssh_session, sshc->handle,
|
|
|
|
sshc->handleSz,
|
|
|
|
&offset[0],
|
|
|
|
(byte *)mem, (word32)len);
|
|
|
|
|
|
|
|
if(rc == WS_FATAL_ERROR)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
*err = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
*err = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(rc < 0) {
|
2021-01-21 20:46:59 +08:00
|
|
|
failf(data, "wolfSSH_SFTP_SendWritePacket returned %d", rc);
|
2020-01-05 17:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
DEBUGASSERT(rc == (int)len);
|
2023-06-16 11:02:48 +08:00
|
|
|
infof(data, "sent %zu bytes SFTP from offset %" CURL_FORMAT_CURL_OFF_T,
|
2020-01-05 17:51:39 +08:00
|
|
|
len, sshc->offset);
|
|
|
|
sshc->offset += len;
|
|
|
|
return (ssize_t)rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return number of received (decrypted) bytes
|
|
|
|
* or <0 on error
|
|
|
|
*/
|
2021-01-21 20:46:59 +08:00
|
|
|
static ssize_t wsftp_recv(struct Curl_easy *data, int sockindex,
|
2020-01-05 17:51:39 +08:00
|
|
|
char *mem, size_t len, CURLcode *err)
|
|
|
|
{
|
|
|
|
int rc;
|
2021-01-21 20:46:59 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
|
|
|
word32 offset[2];
|
|
|
|
(void)sockindex;
|
|
|
|
|
2020-05-26 14:26:20 +08:00
|
|
|
offset[0] = (word32)sshc->offset&0xFFFFFFFF;
|
|
|
|
offset[1] = (word32)(sshc->offset>>32)&0xFFFFFFFF;
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
rc = wolfSSH_SFTP_SendReadPacket(sshc->ssh_session, sshc->handle,
|
|
|
|
sshc->handleSz,
|
|
|
|
&offset[0],
|
|
|
|
(byte *)mem, (word32)len);
|
|
|
|
if(rc == WS_FATAL_ERROR)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
*err = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
*err = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT(rc <= (int)len);
|
|
|
|
|
|
|
|
if(rc < 0) {
|
2021-01-21 20:46:59 +08:00
|
|
|
failf(data, "wolfSSH_SFTP_SendReadPacket returned %d", rc);
|
2020-01-05 17:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sshc->offset += len;
|
|
|
|
|
|
|
|
return (ssize_t)rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSH setup and connection
|
|
|
|
*/
|
2021-01-21 20:46:59 +08:00
|
|
|
static CURLcode wssh_setup_connection(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
|
|
|
struct SSHPROTO *ssh;
|
2021-01-21 20:46:59 +08:00
|
|
|
(void)conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
data->req.p.ssh = ssh = calloc(1, sizeof(struct SSHPROTO));
|
2020-01-05 17:51:39 +08:00
|
|
|
if(!ssh)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int userauth(byte authtype,
|
|
|
|
WS_UserAuthData* authdata,
|
|
|
|
void *ctx)
|
|
|
|
{
|
2021-01-21 20:46:59 +08:00
|
|
|
struct Curl_easy *data = ctx;
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "wolfssh callback: type %s",
|
2020-01-15 21:00:37 +08:00
|
|
|
authtype == WOLFSSH_USERAUTH_PASSWORD ? "PASSWORD" :
|
|
|
|
"PUBLICCKEY"));
|
2020-01-15 21:23:03 +08:00
|
|
|
if(authtype == WOLFSSH_USERAUTH_PASSWORD) {
|
2021-01-21 20:46:59 +08:00
|
|
|
authdata->sf.password.password = (byte *)data->conn->passwd;
|
|
|
|
authdata->sf.password.passwordSz = (word32) strlen(data->conn->passwd);
|
2020-01-15 21:23:03 +08:00
|
|
|
}
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_connect(struct Curl_easy *data, bool *done)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc;
|
|
|
|
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* initialize per-handle data if not already */
|
2020-11-23 15:32:41 +08:00
|
|
|
if(!data->req.p.ssh)
|
2021-01-21 20:46:59 +08:00
|
|
|
wssh_setup_connection(data, conn);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
/* We default to persistent connections. We set this already in this connect
|
2023-08-23 20:47:45 +08:00
|
|
|
function to make the reuse checks properly be able to check this bit. */
|
2020-01-05 17:51:39 +08:00
|
|
|
connkeep(conn, "SSH default");
|
|
|
|
|
|
|
|
if(conn->handler->protocol & CURLPROTO_SCP) {
|
|
|
|
conn->recv[FIRSTSOCKET] = wscp_recv;
|
|
|
|
conn->send[FIRSTSOCKET] = wscp_send;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
conn->recv[FIRSTSOCKET] = wsftp_recv;
|
|
|
|
conn->send[FIRSTSOCKET] = wsftp_send;
|
|
|
|
}
|
|
|
|
sshc = &conn->proto.sshc;
|
|
|
|
sshc->ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_CLIENT, NULL);
|
|
|
|
if(!sshc->ctx) {
|
|
|
|
failf(data, "No wolfSSH context");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
sshc->ssh_session = wolfSSH_new(sshc->ctx);
|
2021-04-19 16:46:11 +08:00
|
|
|
if(!sshc->ssh_session) {
|
2020-01-05 17:51:39 +08:00
|
|
|
failf(data, "No wolfSSH session");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = wolfSSH_SetUsername(sshc->ssh_session, conn->user);
|
|
|
|
if(rc != WS_SUCCESS) {
|
|
|
|
failf(data, "wolfSSH failed to set user name");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set callback for authentication */
|
|
|
|
wolfSSH_SetUserAuth(sshc->ctx, userauth);
|
2021-01-21 20:46:59 +08:00
|
|
|
wolfSSH_SetUserAuthCtx(sshc->ssh_session, data);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
rc = wolfSSH_set_fd(sshc->ssh_session, (int)sock);
|
|
|
|
if(rc) {
|
|
|
|
failf(data, "wolfSSH failed to set socket");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
wolfSSH_Debugging_ON();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
if(conn->handler->protocol & CURLPROTO_SCP)
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
else
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
return wssh_multi_statemach(data, done);
|
2023-05-18 12:54:18 +08:00
|
|
|
error:
|
2020-01-05 17:51:39 +08:00
|
|
|
wolfSSH_free(sshc->ssh_session);
|
|
|
|
wolfSSH_CTX_free(sshc->ctx);
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* to will be set to TRUE if the wolfssh function returns EAGAIN meaning it
|
|
|
|
* wants to be called again when the socket is ready
|
|
|
|
*/
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
2020-11-23 15:32:41 +08:00
|
|
|
struct SSHPROTO *sftp_scp = data->req.p.ssh;
|
2020-01-05 17:51:39 +08:00
|
|
|
WS_SFTPNAME *name;
|
|
|
|
int rc = 0;
|
|
|
|
*block = FALSE; /* we're not blocking by default */
|
|
|
|
|
|
|
|
do {
|
|
|
|
switch(sshc->state) {
|
|
|
|
case SSH_INIT:
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_S_STARTUP);
|
2021-09-29 16:00:52 +08:00
|
|
|
break;
|
|
|
|
|
2020-01-05 17:51:39 +08:00
|
|
|
case SSH_S_STARTUP:
|
|
|
|
rc = wolfSSH_connect(sshc->ssh_session);
|
|
|
|
if(rc != WS_SUCCESS)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc != WS_SUCCESS) {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_SSH;
|
|
|
|
}
|
2022-04-16 17:55:05 +08:00
|
|
|
infof(data, "wolfssh connected");
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
break;
|
|
|
|
case SSH_STOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSH_SFTP_INIT:
|
|
|
|
rc = wolfSSH_SFTP_connect(sshc->ssh_session);
|
|
|
|
if(rc != WS_SUCCESS)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_SUCCESS) {
|
2022-04-16 17:55:05 +08:00
|
|
|
infof(data, "wolfssh SFTP connected");
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_REALPATH);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "wolfssh SFTP connect error %d", rc);
|
|
|
|
return CURLE_SSH;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSH_SFTP_REALPATH:
|
|
|
|
name = wolfSSH_SFTP_RealPath(sshc->ssh_session, (char *)".");
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(name && (rc == WS_SUCCESS)) {
|
2023-12-08 21:27:29 +08:00
|
|
|
sshc->homedir = Curl_memdup0(name->fName, name->fSz);
|
2023-12-05 22:55:35 +08:00
|
|
|
if(!sshc->homedir)
|
2020-01-05 17:51:39 +08:00
|
|
|
sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
|
|
|
wolfSSH_SFTPNAME_list_free(name);
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
failf(data, "wolfssh SFTP realpath %d", rc);
|
|
|
|
return CURLE_SSH;
|
|
|
|
|
|
|
|
case SSH_SFTP_QUOTE_INIT:
|
2021-01-21 20:46:59 +08:00
|
|
|
result = Curl_getworkingpath(data, sshc->homedir, &sftp_scp->path);
|
2020-01-05 17:51:39 +08:00
|
|
|
if(result) {
|
|
|
|
sshc->actualcode = result;
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->set.quote) {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "Sending quote commands");
|
2020-01-05 17:51:39 +08:00
|
|
|
sshc->quote_item = data->set.quote;
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_QUOTE);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
else {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_GETINFO);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSH_SFTP_GETINFO:
|
|
|
|
if(data->set.get_filetime) {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_FILETIME);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
else {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_TRANS_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSH_SFTP_TRANS_INIT:
|
2023-04-25 14:28:01 +08:00
|
|
|
if(data->state.upload)
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_UPLOAD_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
else {
|
|
|
|
if(sftp_scp->path[strlen(sftp_scp->path)-1] == '/')
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_READDIR_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
else
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_DOWNLOAD_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSH_SFTP_UPLOAD_INIT: {
|
|
|
|
word32 flags;
|
|
|
|
WS_SFTP_FILEATRB createattrs;
|
|
|
|
if(data->state.resume_from) {
|
|
|
|
WS_SFTP_FILEATRB attrs;
|
|
|
|
if(data->state.resume_from < 0) {
|
|
|
|
rc = wolfSSH_SFTP_STAT(sshc->ssh_session, sftp_scp->path,
|
|
|
|
&attrs);
|
|
|
|
if(rc != WS_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(rc) {
|
|
|
|
data->state.resume_from = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_off_t size = ((curl_off_t)attrs.sz[1] << 32) | attrs.sz[0];
|
|
|
|
if(size < 0) {
|
|
|
|
failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
|
|
|
|
return CURLE_BAD_DOWNLOAD_RESUME;
|
|
|
|
}
|
|
|
|
data->state.resume_from = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 23:21:31 +08:00
|
|
|
if(data->set.remote_append)
|
2020-01-05 17:51:39 +08:00
|
|
|
/* Try to open for append, but create if nonexisting */
|
|
|
|
flags = WOLFSSH_FXF_WRITE|WOLFSSH_FXF_CREAT|WOLFSSH_FXF_APPEND;
|
|
|
|
else if(data->state.resume_from > 0)
|
|
|
|
/* If we have restart position then open for append */
|
|
|
|
flags = WOLFSSH_FXF_WRITE|WOLFSSH_FXF_APPEND;
|
|
|
|
else
|
2020-12-31 17:11:49 +08:00
|
|
|
/* Clear file before writing (normal behavior) */
|
2020-01-05 17:51:39 +08:00
|
|
|
flags = WOLFSSH_FXF_WRITE|WOLFSSH_FXF_CREAT|WOLFSSH_FXF_TRUNC;
|
|
|
|
|
|
|
|
memset(&createattrs, 0, sizeof(createattrs));
|
|
|
|
createattrs.per = (word32)data->set.new_file_perms;
|
|
|
|
sshc->handleSz = sizeof(sshc->handle);
|
|
|
|
rc = wolfSSH_SFTP_Open(sshc->ssh_session, sftp_scp->path,
|
|
|
|
flags, &createattrs,
|
|
|
|
sshc->handle, &sshc->handleSz);
|
|
|
|
if(rc == WS_FATAL_ERROR)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_SUCCESS) {
|
2022-04-16 17:55:05 +08:00
|
|
|
infof(data, "wolfssh SFTP open succeeded");
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "wolfssh SFTP upload open failed: %d", rc);
|
|
|
|
return CURLE_SSH;
|
|
|
|
}
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_DOWNLOAD_STAT);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
/* If we have a restart point then we need to seek to the correct
|
|
|
|
position. */
|
|
|
|
if(data->state.resume_from > 0) {
|
|
|
|
/* Let's read off the proper amount of bytes from the input. */
|
|
|
|
int seekerr = CURL_SEEKFUNC_OK;
|
|
|
|
if(conn->seek_func) {
|
|
|
|
Curl_set_in_callback(data, true);
|
|
|
|
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
|
|
|
|
SEEK_SET);
|
|
|
|
Curl_set_in_callback(data, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(seekerr != CURL_SEEKFUNC_OK) {
|
|
|
|
curl_off_t passed = 0;
|
|
|
|
|
|
|
|
if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
|
|
|
|
failf(data, "Could not seek stream");
|
|
|
|
return CURLE_FTP_COULDNT_USE_REST;
|
|
|
|
}
|
|
|
|
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
|
|
|
do {
|
2024-01-25 22:47:08 +08:00
|
|
|
char scratch[4*1024];
|
2020-01-05 17:51:39 +08:00
|
|
|
size_t readthisamountnow =
|
2024-01-25 22:47:08 +08:00
|
|
|
(data->state.resume_from - passed >
|
|
|
|
(curl_off_t)sizeof(scratch)) ?
|
|
|
|
sizeof(scratch) : curlx_sotouz(data->state.resume_from - passed);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
size_t actuallyread;
|
|
|
|
Curl_set_in_callback(data, true);
|
2024-01-25 22:47:08 +08:00
|
|
|
actuallyread = data->state.fread_func(scratch, 1,
|
2020-01-05 17:51:39 +08:00
|
|
|
readthisamountnow,
|
|
|
|
data->state.in);
|
|
|
|
Curl_set_in_callback(data, false);
|
|
|
|
|
|
|
|
passed += actuallyread;
|
|
|
|
if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
|
|
|
|
/* this checks for greater-than only to make sure that the
|
|
|
|
CURL_READFUNC_ABORT return code still aborts */
|
|
|
|
failf(data, "Failed to read data");
|
|
|
|
return CURLE_FTP_COULDNT_USE_REST;
|
|
|
|
}
|
|
|
|
} while(passed < data->state.resume_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now, decrease the size of the read */
|
|
|
|
if(data->state.infilesize > 0) {
|
|
|
|
data->state.infilesize -= data->state.resume_from;
|
|
|
|
data->req.size = data->state.infilesize;
|
|
|
|
Curl_pgrsSetUploadSize(data, data->state.infilesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
sshc->offset += data->state.resume_from;
|
|
|
|
}
|
|
|
|
if(data->state.infilesize > 0) {
|
|
|
|
data->req.size = data->state.infilesize;
|
|
|
|
Curl_pgrsSetUploadSize(data, data->state.infilesize);
|
|
|
|
}
|
|
|
|
/* upload data */
|
2024-02-14 19:09:32 +08:00
|
|
|
Curl_xfer_setup(data, -1, -1, FALSE, FIRSTSOCKET);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
2024-02-14 19:09:32 +08:00
|
|
|
/* not set by Curl_xfer_setup to preserve keepon bits */
|
2020-01-05 17:51:39 +08:00
|
|
|
conn->sockfd = conn->writesockfd;
|
|
|
|
|
|
|
|
if(result) {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_CLOSE);
|
2020-01-05 17:51:39 +08:00
|
|
|
sshc->actualcode = result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* 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 */
|
2023-12-13 18:25:20 +08:00
|
|
|
data->state.select_bits = CURL_CSELECT_OUT;
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SSH_SFTP_DOWNLOAD_INIT:
|
|
|
|
sshc->handleSz = sizeof(sshc->handle);
|
|
|
|
rc = wolfSSH_SFTP_Open(sshc->ssh_session, sftp_scp->path,
|
|
|
|
WOLFSSH_FXF_READ, NULL,
|
|
|
|
sshc->handle, &sshc->handleSz);
|
|
|
|
if(rc == WS_FATAL_ERROR)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_SUCCESS) {
|
2022-04-16 17:55:05 +08:00
|
|
|
infof(data, "wolfssh SFTP open succeeded");
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_DOWNLOAD_STAT);
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
failf(data, "wolfssh SFTP open failed: %d", rc);
|
|
|
|
return CURLE_SSH;
|
|
|
|
|
|
|
|
case SSH_SFTP_DOWNLOAD_STAT: {
|
|
|
|
WS_SFTP_FILEATRB attrs;
|
|
|
|
curl_off_t size;
|
|
|
|
|
|
|
|
rc = wolfSSH_SFTP_STAT(sshc->ssh_session, sftp_scp->path, &attrs);
|
|
|
|
if(rc == WS_FATAL_ERROR)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_SUCCESS) {
|
2022-04-16 17:55:05 +08:00
|
|
|
infof(data, "wolfssh STAT succeeded");
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "wolfssh SFTP open failed: %d", rc);
|
|
|
|
data->req.size = -1;
|
|
|
|
data->req.maxdownload = -1;
|
|
|
|
Curl_pgrsSetDownloadSize(data, -1);
|
|
|
|
return CURLE_SSH;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = ((curl_off_t)attrs.sz[1] <<32) | attrs.sz[0];
|
|
|
|
|
|
|
|
data->req.size = size;
|
|
|
|
data->req.maxdownload = size;
|
|
|
|
Curl_pgrsSetDownloadSize(data, size);
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "SFTP download %" CURL_FORMAT_CURL_OFF_T " bytes", size);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
/* We cannot seek with wolfSSH so resuming and range requests are not
|
|
|
|
possible */
|
2021-01-09 00:58:15 +08:00
|
|
|
if(data->state.use_range || data->state.resume_from) {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "wolfSSH cannot do range/seek on SFTP");
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_BAD_DOWNLOAD_RESUME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the actual download */
|
|
|
|
if(data->req.size == 0) {
|
|
|
|
/* no data to transfer */
|
2024-02-14 19:09:32 +08:00
|
|
|
Curl_xfer_setup(data, -1, -1, FALSE, -1);
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "File already completely downloaded");
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
break;
|
|
|
|
}
|
2024-02-14 19:09:32 +08:00
|
|
|
Curl_xfer_setup(data, FIRSTSOCKET, data->req.size, FALSE, -1);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
2024-02-14 19:09:32 +08:00
|
|
|
/* not set by Curl_xfer_setup to preserve keepon bits */
|
2020-01-05 17:51:39 +08:00
|
|
|
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 */
|
2023-12-13 18:25:20 +08:00
|
|
|
data->state.select_bits = CURL_CSELECT_IN;
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
/* this should never occur; the close state should be entered
|
|
|
|
at the time the error occurs */
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_CLOSE);
|
2020-01-05 17:51:39 +08:00
|
|
|
sshc->actualcode = result;
|
|
|
|
}
|
|
|
|
else {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SSH_SFTP_CLOSE:
|
|
|
|
if(sshc->handleSz)
|
|
|
|
rc = wolfSSH_SFTP_Close(sshc->ssh_session, sshc->handle,
|
|
|
|
sshc->handleSz);
|
|
|
|
else
|
|
|
|
rc = WS_SUCCESS; /* directory listing */
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_SUCCESS) {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
failf(data, "wolfssh SFTP CLOSE failed: %d", rc);
|
|
|
|
return CURLE_SSH;
|
|
|
|
|
|
|
|
case SSH_SFTP_READDIR_INIT:
|
|
|
|
Curl_pgrsSetDownloadSize(data, -1);
|
2022-11-11 17:57:04 +08:00
|
|
|
if(data->req.no_body) {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_READDIR);
|
2021-09-29 16:00:52 +08:00
|
|
|
break;
|
|
|
|
|
2020-01-05 17:51:39 +08:00
|
|
|
case SSH_SFTP_READDIR:
|
|
|
|
name = wolfSSH_SFTP_LS(sshc->ssh_session, sftp_scp->path);
|
|
|
|
if(!name)
|
|
|
|
rc = wolfSSH_get_error(sshc->ssh_session);
|
|
|
|
else
|
|
|
|
rc = WS_SUCCESS;
|
|
|
|
|
|
|
|
if(rc == WS_WANT_READ) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_RECV;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(rc == WS_WANT_WRITE) {
|
|
|
|
*block = TRUE;
|
|
|
|
conn->waitfor = KEEP_SEND;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else if(name && (rc == WS_SUCCESS)) {
|
|
|
|
WS_SFTPNAME *origname = name;
|
|
|
|
result = CURLE_OK;
|
|
|
|
while(name) {
|
|
|
|
char *line = aprintf("%s\n",
|
2021-02-08 23:40:34 +08:00
|
|
|
data->set.list_only ?
|
2020-01-05 17:51:39 +08:00
|
|
|
name->fName : name->lName);
|
2021-04-19 16:46:11 +08:00
|
|
|
if(!line) {
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_CLOSE);
|
2020-01-05 17:51:39 +08:00
|
|
|
sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2021-01-21 20:46:59 +08:00
|
|
|
result = Curl_client_write(data, CLIENTWRITE_BODY,
|
2020-01-05 17:51:39 +08:00
|
|
|
line, strlen(line));
|
|
|
|
free(line);
|
|
|
|
if(result) {
|
|
|
|
sshc->actualcode = result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
name = name->next;
|
|
|
|
}
|
|
|
|
wolfSSH_SFTPNAME_list_free(origname);
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
failf(data, "wolfssh SFTP ls failed: %d", rc);
|
|
|
|
return CURLE_SSH;
|
|
|
|
|
|
|
|
case SSH_SFTP_SHUTDOWN:
|
|
|
|
Curl_safefree(sshc->homedir);
|
|
|
|
wolfSSH_free(sshc->ssh_session);
|
|
|
|
wolfSSH_CTX_free(sshc->ctx);
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_STOP);
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(!rc && (sshc->state != SSH_STOP));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called repeatedly until done from multi.c */
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_multi_statemach(struct Curl_easy *data, bool *done)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
bool block; /* we store the status and use that to provide a ssh_getsock()
|
|
|
|
implementation */
|
|
|
|
do {
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wssh_statemach_act(data, &block);
|
2020-01-05 17:51:39 +08:00
|
|
|
*done = (sshc->state == SSH_STOP) ? TRUE : FALSE;
|
|
|
|
/* if there's no error, it isn't done and it didn't EWOULDBLOCK, then
|
|
|
|
try again */
|
|
|
|
if(*done) {
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "wssh_statemach_act says DONE"));
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
} while(!result && !*done && !block);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode wscp_perform(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool *connected,
|
|
|
|
bool *dophase_done)
|
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
(void)data;
|
2020-01-05 17:51:39 +08:00
|
|
|
(void)connected;
|
|
|
|
(void)dophase_done;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode wsftp_perform(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool *connected,
|
|
|
|
bool *dophase_done)
|
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "DO phase starts"));
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
*dophase_done = FALSE; /* not done yet */
|
|
|
|
|
|
|
|
/* start the first command in the DO phase */
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_QUOTE_INIT);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
/* run the state-machine */
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wssh_multi_statemach(data, dophase_done);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
*connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
if(*dophase_done) {
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "DO phase is complete"));
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The DO function is generic for both protocols.
|
|
|
|
*/
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_do(struct Curl_easy *data, bool *done)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
|
|
|
CURLcode result;
|
|
|
|
bool connected = 0;
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
|
|
|
|
|
|
|
*done = FALSE; /* default to false */
|
|
|
|
data->req.size = -1; /* make sure this is unknown at this point */
|
|
|
|
sshc->actualcode = CURLE_OK; /* reset error code */
|
|
|
|
sshc->secondCreateDirs = 0; /* reset the create dir attempt state
|
|
|
|
variable */
|
|
|
|
|
|
|
|
Curl_pgrsSetUploadCounter(data, 0);
|
|
|
|
Curl_pgrsSetDownloadCounter(data, 0);
|
|
|
|
Curl_pgrsSetUploadSize(data, -1);
|
|
|
|
Curl_pgrsSetDownloadSize(data, -1);
|
|
|
|
|
|
|
|
if(conn->handler->protocol & CURLPROTO_SCP)
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wscp_perform(data, &connected, done);
|
2020-01-05 17:51:39 +08:00
|
|
|
else
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wsftp_perform(data, &connected, done);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_block_statemach(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool disconnect)
|
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-01-05 17:51:39 +08:00
|
|
|
struct ssh_conn *sshc = &conn->proto.sshc;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
|
|
|
while((sshc->state != SSH_STOP) && !result) {
|
|
|
|
bool block;
|
|
|
|
timediff_t left = 1000;
|
|
|
|
struct curltime now = Curl_now();
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wssh_statemach_act(data, &block);
|
2020-01-05 17:51:39 +08:00
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(!disconnect) {
|
2021-01-21 20:46:59 +08:00
|
|
|
if(Curl_pgrsUpdate(data))
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_ABORTED_BY_CALLBACK;
|
|
|
|
|
|
|
|
result = Curl_speedcheck(data, now);
|
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
|
|
|
|
left = Curl_timeleft(data, NULL, FALSE);
|
|
|
|
if(left < 0) {
|
|
|
|
failf(data, "Operation timed out");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!result) {
|
|
|
|
int dir = conn->waitfor;
|
|
|
|
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
|
|
|
curl_socket_t fd_read = CURL_SOCKET_BAD;
|
|
|
|
curl_socket_t fd_write = CURL_SOCKET_BAD;
|
|
|
|
if(dir == KEEP_RECV)
|
|
|
|
fd_read = sock;
|
|
|
|
else if(dir == KEEP_SEND)
|
|
|
|
fd_write = sock;
|
|
|
|
|
|
|
|
/* wait for the socket to become ready */
|
|
|
|
(void)Curl_socket_check(fd_read, CURL_SOCKET_BAD, fd_write,
|
|
|
|
left>1000?1000:left); /* ignore result */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generic done function for both SCP and SFTP called from their specific
|
|
|
|
done functions */
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wssh_done(struct Curl_easy *data, CURLcode status)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
2021-01-09 00:58:15 +08:00
|
|
|
struct SSHPROTO *sftp_scp = data->req.p.ssh;
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
if(!status) {
|
|
|
|
/* run the state-machine */
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wssh_block_statemach(data, FALSE);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
result = status;
|
|
|
|
|
|
|
|
if(sftp_scp)
|
|
|
|
Curl_safefree(sftp_scp->path);
|
2021-01-21 20:46:59 +08:00
|
|
|
if(Curl_pgrsDone(data))
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_ABORTED_BY_CALLBACK;
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
data->req.keepon = 0; /* clear all bits */
|
2020-01-05 17:51:39 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wscp_done(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
CURLcode code, bool premature)
|
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
(void)conn;
|
|
|
|
(void)code;
|
|
|
|
(void)premature;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wscp_doing(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool *dophase_done)
|
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
(void)conn;
|
|
|
|
(void)dophase_done;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wscp_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn, bool dead_connection)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
2021-01-09 00:58:15 +08:00
|
|
|
(void)data;
|
2020-01-05 17:51:39 +08:00
|
|
|
(void)conn;
|
|
|
|
(void)dead_connection;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wsftp_done(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
CURLcode code, bool premature)
|
|
|
|
{
|
|
|
|
(void)premature;
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_CLOSE);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
return wssh_done(data, code);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode wsftp_doing(struct Curl_easy *data,
|
2020-01-05 17:51:39 +08:00
|
|
|
bool *dophase_done)
|
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode result = wssh_multi_statemach(data, dophase_done);
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
if(*dophase_done) {
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "DO phase is complete"));
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-21 20:46:59 +08:00
|
|
|
static CURLcode wsftp_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
bool dead)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
(void)dead;
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "SSH DISCONNECT starts now"));
|
2020-01-05 17:51:39 +08:00
|
|
|
|
|
|
|
if(conn->proto.sshc.ssh_session) {
|
|
|
|
/* only if there's a session still around to use! */
|
2021-01-21 20:46:59 +08:00
|
|
|
state(data, SSH_SFTP_SHUTDOWN);
|
2021-01-09 00:58:15 +08:00
|
|
|
result = wssh_block_statemach(data, TRUE);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
DEBUGF(infof(data, "SSH DISCONNECT is done"));
|
2020-01-05 17:51:39 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-21 20:46:59 +08:00
|
|
|
static int wssh_getsock(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2020-01-05 17:51:39 +08:00
|
|
|
curl_socket_t *sock)
|
|
|
|
{
|
|
|
|
int bitmap = GETSOCK_BLANK;
|
|
|
|
int dir = conn->waitfor;
|
2021-01-21 20:46:59 +08:00
|
|
|
(void)data;
|
2020-01-05 17:51:39 +08:00
|
|
|
sock[0] = conn->sock[FIRSTSOCKET];
|
|
|
|
|
|
|
|
if(dir == KEEP_RECV)
|
|
|
|
bitmap |= GETSOCK_READSOCK(FIRSTSOCKET);
|
|
|
|
else if(dir == KEEP_SEND)
|
|
|
|
bitmap |= GETSOCK_WRITESOCK(FIRSTSOCKET);
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2021-06-30 17:09:55 +08:00
|
|
|
void Curl_ssh_version(char *buffer, size_t buflen)
|
2020-01-05 17:51:39 +08:00
|
|
|
{
|
2021-06-30 17:09:55 +08:00
|
|
|
(void)msnprintf(buffer, buflen, "wolfssh/%s", LIBWOLFSSH_VERSION_STRING);
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_ssh_init(void)
|
|
|
|
{
|
2020-01-24 03:05:22 +08:00
|
|
|
if(WS_SUCCESS != wolfSSH_Init()) {
|
|
|
|
DEBUGF(fprintf(stderr, "Error: wolfSSH_Init failed\n"));
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
|
2020-01-05 17:51:39 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
void Curl_ssh_cleanup(void)
|
|
|
|
{
|
2023-09-23 01:59:53 +08:00
|
|
|
(void)wolfSSH_Cleanup();
|
2020-01-05 17:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_WOLFSSH */
|