1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

examples: add sftpserver example and fix problems

Signed-off-by: tatataeki <shengzeyu19_98@163.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
tatataeki
2022-08-11 11:44:56 +08:00
committed by Jakub Jelen
parent f8bfb5a7a1
commit 48d14ee9a9
6 changed files with 1457 additions and 59 deletions

View File

@ -29,6 +29,10 @@ if (UNIX AND NOT WIN32)
add_executable(samplesftp samplesftp.c ${examples_SRCS})
target_compile_options(samplesftp PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
target_link_libraries(samplesftp ssh::ssh)
add_executable(sample_sftpserver sample_sftpserver.c ${examples_SRCS})
target_compile_options(sample_sftpserver PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
target_link_libraries(sample_sftpserver ssh::ssh)
endif (WITH_SFTP)
add_executable(ssh-client ssh_client.c ${examples_SRCS})

1451
examples/sample_sftpserver.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -864,7 +864,6 @@ LIBSSH_API char *sftp_canonicalize_path(sftp_session sftp, const char *path);
*/
LIBSSH_API int sftp_server_version(sftp_session sftp);
LIBSSH_API sftp_session sftp_from_session(ssh_session session, ssh_channel channel);
LIBSSH_API int sftp_decode_channel_data_to_packet(sftp_session sftp, void *data);

View File

@ -457,7 +457,6 @@ LIBSSH_4_9_0 # Released
ssh_session_set_disconnect_message;
ssh_userauth_publickey_auto_get_current_identity;
ssh_vlog;
sftp_from_session;
sftp_get_client_message_from_packet;
sftp_process_init_packet;
sftp_decode_channel_data_to_packet;

View File

@ -354,60 +354,6 @@ void sftp_server_free(sftp_session sftp)
SAFE_FREE(sftp);
}
sftp_session sftp_from_session(ssh_session session, ssh_channel channel)
{
sftp_session sftp;
if (session == NULL) {
return NULL;
}
sftp = calloc(1, sizeof(struct sftp_session_struct));
if (sftp == NULL) {
ssh_set_error_oom(session);
return NULL;
}
sftp->ext = sftp_ext_new();
if (sftp->ext == NULL) {
ssh_set_error_oom(session);
goto error;
}
sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
if (sftp->read_packet == NULL) {
ssh_set_error_oom(session);
goto error;
}
sftp->read_packet->payload = ssh_buffer_new();
if (sftp->read_packet->payload == NULL) {
ssh_set_error_oom(session);
goto error;
}
sftp->session = session;
sftp->channel = channel;
return sftp;
error:
if (sftp->ext != NULL) {
sftp_ext_free(sftp->ext);
}
if (sftp->channel != NULL) {
ssh_channel_free(sftp->channel);
}
if (sftp->read_packet != NULL) {
if (sftp->read_packet->payload != NULL) {
SSH_BUFFER_FREE(sftp->read_packet->payload);
}
SAFE_FREE(sftp->read_packet);
}
SAFE_FREE(sftp);
return NULL;
}
int sftp_process_init_packet(sftp_client_message client_msg) {
int ret = SSH_OK;
sftp_session sftp = client_msg->sftp;

View File

@ -257,12 +257,11 @@ sftp_client_message sftp_get_client_message_from_packet(sftp_session sftp) {
int rc;
int version;
msg = malloc(sizeof (struct sftp_client_message_struct));
msg = calloc(1, sizeof(struct sftp_client_message_struct));
if (msg == NULL) {
ssh_set_error_oom(session);
return NULL;
}
ZERO_STRUCTP(msg);
packet = sftp->read_packet;
if (packet == NULL) {