mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-10 18:28:10 +09:00
Reformat most of the sftpserver.c
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
@@ -87,7 +87,7 @@ sftp_make_client_message(sftp_session sftp, sftp_packet packet)
|
||||
ssh_buffer_get_u32(payload, &msg->id);
|
||||
}
|
||||
|
||||
switch(msg->type) {
|
||||
switch (msg->type) {
|
||||
case SSH_FXP_INIT:
|
||||
rc = ssh_buffer_unpack(payload,
|
||||
"d",
|
||||
@@ -277,39 +277,48 @@ sftp_get_client_message_from_packet(sftp_session sftp)
|
||||
return sftp_make_client_message(sftp, packet);
|
||||
}
|
||||
|
||||
/* Send an sftp client message. Can be used in cas of proxying */
|
||||
int sftp_send_client_message(sftp_session sftp, sftp_client_message msg){
|
||||
/* Send an sftp client message. Can be used in case of proxying */
|
||||
int sftp_send_client_message(sftp_session sftp, sftp_client_message msg)
|
||||
{
|
||||
return sftp_packet_write(sftp, msg->type, msg->complete_message);
|
||||
}
|
||||
|
||||
uint8_t sftp_client_message_get_type(sftp_client_message msg){
|
||||
uint8_t sftp_client_message_get_type(sftp_client_message msg)
|
||||
{
|
||||
return msg->type;
|
||||
}
|
||||
|
||||
const char *sftp_client_message_get_filename(sftp_client_message msg){
|
||||
const char *sftp_client_message_get_filename(sftp_client_message msg)
|
||||
{
|
||||
return msg->filename;
|
||||
}
|
||||
|
||||
void sftp_client_message_set_filename(sftp_client_message msg, const char *newname){
|
||||
void
|
||||
sftp_client_message_set_filename(sftp_client_message msg, const char *newname)
|
||||
{
|
||||
free(msg->filename);
|
||||
msg->filename = strdup(newname);
|
||||
}
|
||||
|
||||
const char *sftp_client_message_get_data(sftp_client_message msg){
|
||||
const char *sftp_client_message_get_data(sftp_client_message msg)
|
||||
{
|
||||
if (msg->str_data == NULL)
|
||||
msg->str_data = ssh_string_to_char(msg->data);
|
||||
return msg->str_data;
|
||||
}
|
||||
|
||||
uint32_t sftp_client_message_get_flags(sftp_client_message msg){
|
||||
uint32_t sftp_client_message_get_flags(sftp_client_message msg)
|
||||
{
|
||||
return msg->flags;
|
||||
}
|
||||
|
||||
const char *sftp_client_message_get_submessage(sftp_client_message msg){
|
||||
const char *sftp_client_message_get_submessage(sftp_client_message msg)
|
||||
{
|
||||
return msg->submessage;
|
||||
}
|
||||
|
||||
void sftp_client_message_free(sftp_client_message msg) {
|
||||
void sftp_client_message_free(sftp_client_message msg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -325,8 +334,9 @@ void sftp_client_message_free(sftp_client_message msg) {
|
||||
SAFE_FREE(msg);
|
||||
}
|
||||
|
||||
int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
sftp_attributes attr) {
|
||||
int
|
||||
sftp_reply_name(sftp_client_message msg, const char *name, sftp_attributes attr)
|
||||
{
|
||||
ssh_buffer out;
|
||||
ssh_string file;
|
||||
|
||||
@@ -341,6 +351,8 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSH_LOG(SSH_LOG_PROTOCOL, "Sending name %s", ssh_string_get_char(file));
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
ssh_buffer_add_u32(out, htonl(1)) < 0 ||
|
||||
ssh_buffer_add_ssh_string(out, file) < 0 ||
|
||||
@@ -357,7 +369,8 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
|
||||
int sftp_reply_handle(sftp_client_message msg, ssh_string handle)
|
||||
{
|
||||
ssh_buffer out;
|
||||
|
||||
out = ssh_buffer_new();
|
||||
@@ -365,6 +378,10 @@ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_log_hexdump("Sending handle:",
|
||||
(const unsigned char *)ssh_string_get_char(handle),
|
||||
ssh_string_len(handle));
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
ssh_buffer_add_ssh_string(out, handle) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_HANDLE, out) < 0) {
|
||||
@@ -376,7 +393,8 @@ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
|
||||
int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr)
|
||||
{
|
||||
ssh_buffer out;
|
||||
|
||||
out = ssh_buffer_new();
|
||||
@@ -384,6 +402,8 @@ int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSH_LOG(SSH_LOG_PROTOCOL, "Sending attr");
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
buffer_add_attributes(out, attr) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_ATTRS, out) < 0) {
|
||||
@@ -395,8 +415,10 @@ int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
const char *longname, sftp_attributes attr) {
|
||||
int
|
||||
sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
const char *longname, sftp_attributes attr)
|
||||
{
|
||||
ssh_string name;
|
||||
|
||||
name = ssh_string_from_char(file);
|
||||
@@ -422,8 +444,8 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
if (name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (ssh_buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
|
||||
buffer_add_attributes(msg->attrbuf,attr) < 0) {
|
||||
if (ssh_buffer_add_ssh_string(msg->attrbuf, name) < 0 ||
|
||||
buffer_add_attributes(msg->attrbuf, attr) < 0) {
|
||||
SSH_STRING_FREE(name);
|
||||
return -1;
|
||||
}
|
||||
@@ -433,7 +455,8 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sftp_reply_names(sftp_client_message msg) {
|
||||
int sftp_reply_names(sftp_client_message msg)
|
||||
{
|
||||
ssh_buffer out;
|
||||
|
||||
out = ssh_buffer_new();
|
||||
@@ -442,6 +465,8 @@ int sftp_reply_names(sftp_client_message msg) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSH_LOG(SSH_LOG_PROTOCOL, "Sending %d names", msg->attr_num);
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
ssh_buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
|
||||
ssh_buffer_add_data(out, ssh_buffer_get(msg->attrbuf),
|
||||
@@ -461,8 +486,9 @@ int sftp_reply_names(sftp_client_message msg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sftp_reply_status(sftp_client_message msg, uint32_t status,
|
||||
const char *message) {
|
||||
int
|
||||
sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message)
|
||||
{
|
||||
ssh_buffer out;
|
||||
ssh_string s;
|
||||
|
||||
@@ -477,6 +503,9 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSH_LOG(SSH_LOG_PROTOCOL, "Sending status %d, message: %s", status,
|
||||
ssh_string_get_char(s));
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
ssh_buffer_add_u32(out, htonl(status)) < 0 ||
|
||||
ssh_buffer_add_ssh_string(out, s) < 0 ||
|
||||
@@ -493,7 +522,8 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
|
||||
int sftp_reply_data(sftp_client_message msg, const void *data, int len)
|
||||
{
|
||||
ssh_buffer out;
|
||||
|
||||
out = ssh_buffer_new();
|
||||
@@ -501,6 +531,8 @@ int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSH_LOG(SSH_LOG_PROTOCOL, "Sending data, length: %d", len);
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
ssh_buffer_add_u32(out, ntohl(len)) < 0 ||
|
||||
ssh_buffer_add_data(out, data, len) < 0 ||
|
||||
@@ -534,6 +566,8 @@ sftp_reply_statvfs(sftp_client_message msg, sftp_statvfs_t st)
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSH_LOG(SSH_LOG_PROTOCOL, "Sending statvfs reply");
|
||||
|
||||
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
|
||||
ssh_buffer_add_u64(out, ntohll(st->f_bsize)) < 0 ||
|
||||
ssh_buffer_add_u64(out, ntohll(st->f_frsize)) < 0 ||
|
||||
@@ -608,7 +642,8 @@ int sftp_process_init_packet(sftp_client_message client_msg)
|
||||
* the handle. Care is given that a corrupted handle won't give a
|
||||
* valid info (or worse).
|
||||
*/
|
||||
ssh_string sftp_handle_alloc(sftp_session sftp, void *info) {
|
||||
ssh_string sftp_handle_alloc(sftp_session sftp, void *info)
|
||||
{
|
||||
ssh_string ret;
|
||||
uint32_t val;
|
||||
uint32_t i;
|
||||
@@ -642,7 +677,8 @@ ssh_string sftp_handle_alloc(sftp_session sftp, void *info) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *sftp_handle(sftp_session sftp, ssh_string handle){
|
||||
void *sftp_handle(sftp_session sftp, ssh_string handle)
|
||||
{
|
||||
uint32_t val;
|
||||
|
||||
if (sftp->handles == NULL) {
|
||||
@@ -662,7 +698,8 @@ void *sftp_handle(sftp_session sftp, ssh_string handle){
|
||||
return sftp->handles[val];
|
||||
}
|
||||
|
||||
void sftp_handle_remove(sftp_session sftp, void *handle) {
|
||||
void sftp_handle_remove(sftp_session sftp, void *handle)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SFTP_HANDLES; i++) {
|
||||
@@ -674,6 +711,7 @@ void sftp_handle_remove(sftp_session sftp, void *handle) {
|
||||
}
|
||||
|
||||
/* Default SFTP handlers */
|
||||
|
||||
static const char *
|
||||
ssh_str_error(int u_errno)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user