aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-27 11:54:47 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-27 11:54:47 +0000
commitbf312c50a9c7f80d38ca394e6cb5ab37e6ff4b88 (patch)
tree8657627094550ba9cf83dff52b2de31a0db78555
parent52d20beb731bb00fd9770da04d21aeec04dfd9c9 (diff)
downloadlibssh-bf312c50a9c7f80d38ca394e6cb5ab37e6ff4b88.tar.gz
libssh-bf312c50a9c7f80d38ca394e6cb5ab37e6ff4b88.tar.xz
libssh-bf312c50a9c7f80d38ca394e6cb5ab37e6ff4b88.zip
Improve sftp_reply_data and fix sftp_reply_status.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@627 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--include/libssh/sftp.h4
-rw-r--r--libssh/sftpserver.c66
2 files changed, 48 insertions, 22 deletions
diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
index 486165d8..dc914b19 100644
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -653,11 +653,11 @@ int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle);
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info);
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr);
void *sftp_handle(SFTP_SESSION *sftp, STRING *handle);
-int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, char *message);
+int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, const char *message);
int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file,
const char *longname, SFTP_ATTRIBUTES *attr);
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg);
-int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, void *data, int len);
+int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len);
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle);
/* SFTP commands and constants */
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 901ad862..21f2d0c4 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -360,30 +360,56 @@ int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg) {
return 0;
}
-int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, char *message){
- BUFFER *out=buffer_new();
- int r;
- STRING *s;
- buffer_add_u32(out,msg->id);
- buffer_add_u32(out,htonl(status));
- s=string_from_char(message?message:"");
- buffer_add_ssh_string(out,s);
- free(s);
- buffer_add_u32(out,0); // language string
- r=sftp_packet_write(msg->sftp,SSH_FXP_STATUS,out);
+int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status,
+ const char *message) {
+ BUFFER *out;
+ STRING *s;
+
+ out = buffer_new();
+ if (out == NULL) {
+ return -1;
+ }
+
+ s = string_from_char(message ? message : "");
+ if (s == NULL) {
+ buffer_free(out);
+ return -1;
+ }
+
+ if (buffer_add_u32(out, msg->id) < 0 ||
+ buffer_add_u32(out, htonl(status)) < 0 ||
+ buffer_add_ssh_string(out, s) < 0 ||
+ buffer_add_u32(out, 0) < 0 || /* language string */
+ sftp_packet_write(msg->sftp, SSH_FXP_STATUS, out) < 0) {
buffer_free(out);
- return r<0;
+ string_free(s);
+ return -1;
+ }
+
+ buffer_free(out);
+ string_free(s);
+
+ return 0;
}
-int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, void *data, int len){
- BUFFER *out=buffer_new();
- int r;
- buffer_add_u32(out,msg->id);
- buffer_add_u32(out,ntohl(len));
- buffer_add_data(out,data,len);
- r=sftp_packet_write(msg->sftp,SSH_FXP_DATA,out);
+int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len) {
+ BUFFER *out;
+
+ out = buffer_new();
+ if (out == NULL) {
+ return -1;
+ }
+
+ if (buffer_add_u32(out, msg->id) < 0 ||
+ buffer_add_u32(out, ntohl(len)) < 0 ||
+ buffer_add_data(out, data, len) < 0 ||
+ sftp_packet_write(msg->sftp, SSH_FXP_DATA, out) < 0) {
buffer_free(out);
- return r<0;
+ return -1;
+ }
+ buffer_free(out);
+
+ return 0;
}
/* this function will return you a new handle to give the client.