aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2010-02-23 22:50:43 +0100
committerAndreas Schneider <mail@cynapses.org>2010-02-23 22:50:43 +0100
commit39d6ef884a6b66e8fb1773fe01e361703224ab73 (patch)
tree4d90984c16faa30b727e581560af412a2fd146cb /libssh
parent492d1f24c834a5d1320dfe9699c6fda65ab3e1ba (diff)
downloadlibssh-39d6ef884a6b66e8fb1773fe01e361703224ab73.tar.gz
libssh-39d6ef884a6b66e8fb1773fe01e361703224ab73.tar.xz
libssh-39d6ef884a6b66e8fb1773fe01e361703224ab73.zip
Added owner and group information in sftp attributes.
Parse the longname which is the output of 'ls -l' and set the owner and group if we are talking to an openssh server.
Diffstat (limited to 'libssh')
-rw-r--r--libssh/sftp.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/libssh/sftp.c b/libssh/sftp.c
index 31b5ceee..4f2f4eb3 100644
--- a/libssh/sftp.c
+++ b/libssh/sftp.c
@@ -25,6 +25,7 @@
/* This file contains code written by Nick Zitzmann */
#include <errno.h>
+#include <ctype.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
@@ -1111,6 +1112,44 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
return attr;
}
+enum sftp_longname_field_e {
+ SFTP_LONGNAME_PERM = 0,
+ SFTP_LONGNAME_FIXME,
+ SFTP_LONGNAME_OWNER,
+ SFTP_LONGNAME_GROUP,
+ SFTP_LONGNAME_SIZE,
+ SFTP_LONGNAME_DATE,
+ SFTP_LONGNAME_TIME,
+ SFTP_LONGNAME_NAME,
+};
+
+static char *sftp_parse_longname(const char *longname,
+ enum sftp_longname_field_e longname_field) {
+ const char *p, *q;
+ size_t field = 0;
+
+ p = longname;
+ /* Find the beginning of the field which is specified by sftp_longanme_field_e. */
+ while(field != longname_field) {
+ if(isspace(*p)) {
+ field++;
+ p++;
+ while(*p && isspace(*p)) {
+ p++;
+ }
+ } else {
+ p++;
+ }
+ }
+
+ q = p;
+ while (! isspace(*q)) {
+ q++;
+ }
+
+ return strndup(p, q - p);
+}
+
/* sftp version 0-3 code. It is different from the v4 */
/* maybe a paste of the draft is better than the code */
/*
@@ -1186,6 +1225,18 @@ static sftp_attributes sftp_parse_attr_3(sftp_session sftp, ssh_buffer buf,
}
attr->uid = ntohl(attr->uid);
attr->gid = ntohl(attr->gid);
+
+ if (ssh_get_openssh_version(sftp->session)) {
+ attr->owner = sftp_parse_longname(attr->longname, SFTP_LONGNAME_OWNER);
+ if (attr->owner == NULL) {
+ break;
+ }
+
+ attr->group = sftp_parse_longname(attr->longname, SFTP_LONGNAME_GROUP);
+ if (attr->group == NULL) {
+ break;
+ }
+ }
}
if (flags & SSH_FILEXFER_ATTR_PERMISSIONS) {
@@ -1254,6 +1305,8 @@ static sftp_attributes sftp_parse_attr_3(sftp_session sftp, ssh_buffer buf,
string_free(attr->extended_data);
SAFE_FREE(attr->name);
SAFE_FREE(attr->longname);
+ SAFE_FREE(attr->owner);
+ SAFE_FREE(attr->group);
SAFE_FREE(attr);
ssh_set_error(sftp->session, SSH_FATAL, "Invalid ATTR structure");