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:
@ -29,6 +29,10 @@ if (UNIX AND NOT WIN32)
|
|||||||
add_executable(samplesftp samplesftp.c ${examples_SRCS})
|
add_executable(samplesftp samplesftp.c ${examples_SRCS})
|
||||||
target_compile_options(samplesftp PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
|
target_compile_options(samplesftp PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
|
||||||
target_link_libraries(samplesftp ssh::ssh)
|
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)
|
endif (WITH_SFTP)
|
||||||
|
|
||||||
add_executable(ssh-client ssh_client.c ${examples_SRCS})
|
add_executable(ssh-client ssh_client.c ${examples_SRCS})
|
||||||
|
1451
examples/sample_sftpserver.c
Normal file
1451
examples/sample_sftpserver.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -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 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);
|
LIBSSH_API int sftp_decode_channel_data_to_packet(sftp_session sftp, void *data);
|
||||||
|
|
||||||
|
@ -457,10 +457,9 @@ LIBSSH_4_9_0 # Released
|
|||||||
ssh_session_set_disconnect_message;
|
ssh_session_set_disconnect_message;
|
||||||
ssh_userauth_publickey_auto_get_current_identity;
|
ssh_userauth_publickey_auto_get_current_identity;
|
||||||
ssh_vlog;
|
ssh_vlog;
|
||||||
sftp_from_session;
|
|
||||||
sftp_get_client_message_from_packet;
|
sftp_get_client_message_from_packet;
|
||||||
sftp_process_init_packet;
|
sftp_process_init_packet;
|
||||||
sftp_decode_channel_data_to_packet;
|
sftp_decode_channel_data_to_packet;
|
||||||
sftp_reply_statvfs;
|
sftp_reply_statvfs;
|
||||||
} LIBSSH_4_8_1;
|
} LIBSSH_4_8_1;
|
||||||
|
|
||||||
|
54
src/sftp.c
54
src/sftp.c
@ -354,60 +354,6 @@ void sftp_server_free(sftp_session sftp)
|
|||||||
SAFE_FREE(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 sftp_process_init_packet(sftp_client_message client_msg) {
|
||||||
int ret = SSH_OK;
|
int ret = SSH_OK;
|
||||||
sftp_session sftp = client_msg->sftp;
|
sftp_session sftp = client_msg->sftp;
|
||||||
|
@ -257,12 +257,11 @@ sftp_client_message sftp_get_client_message_from_packet(sftp_session sftp) {
|
|||||||
int rc;
|
int rc;
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
msg = malloc(sizeof (struct sftp_client_message_struct));
|
msg = calloc(1, sizeof(struct sftp_client_message_struct));
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ZERO_STRUCTP(msg);
|
|
||||||
|
|
||||||
packet = sftp->read_packet;
|
packet = sftp->read_packet;
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
|
Reference in New Issue
Block a user