aboutsummaryrefslogtreecommitdiff
path: root/libssh/sftpserver.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-27 11:39:25 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-27 11:39:25 +0000
commitdb79fff00d861a14e8ef08ed34ba403c84775b9c (patch)
treecf31f18e81019a4d87b9fe24c2072a12c34bf3c9 /libssh/sftpserver.c
parent5d231425998aca6af38045cd94a09986d79adb5d (diff)
downloadlibssh-db79fff00d861a14e8ef08ed34ba403c84775b9c.tar.gz
libssh-db79fff00d861a14e8ef08ed34ba403c84775b9c.tar.xz
libssh-db79fff00d861a14e8ef08ed34ba403c84775b9c.zip
Improve sftp_reply_name.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@622 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/sftpserver.c')
-rw-r--r--libssh/sftpserver.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 51c21176..07f432a9 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -224,19 +224,36 @@ void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg) {
SAFE_FREE(msg);
}
-int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, char *name, SFTP_ATTRIBUTES *attr){
- BUFFER *out=buffer_new();
- STRING *file=string_from_char(name);
- int r;
- buffer_add_u32(out,msg->id);
- buffer_add_u32(out,htonl(1));
- buffer_add_ssh_string(out,file);
- buffer_add_ssh_string(out,file); /* the protocol is broken here between 3 & 4 */
- free(file);
- buffer_add_attributes(out,attr);
- r=sftp_packet_write(msg->sftp,SSH_FXP_NAME,out);
+int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name,
+ SFTP_ATTRIBUTES *attr) {
+ BUFFER *out;
+ STRING *file;
+
+ out = buffer_new();
+ if (out == NULL) {
+ return -1;
+ }
+
+ file = string_from_char(name);
+ if (file == NULL) {
buffer_free(out);
- return r<0;
+ return -1;
+ }
+
+ if (buffer_add_u32(out, msg->id) < 0 ||
+ buffer_add_u32(out, htonl(1)) < 0 ||
+ buffer_add_ssh_string(out, file) < 0 ||
+ buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
+ buffer_add_attributes(out, attr) < 0 ||
+ sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
+ buffer_free(out);
+ string_free(file);
+ return -1;
+ }
+ buffer_free(out);
+ string_free(file);
+
+ return 0;
}
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle){