mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
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.
This commit is contained in:
@@ -149,17 +149,16 @@ struct sftp_status_message_struct {
|
|||||||
char *langmsg;
|
char *langmsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* don't worry much of these aren't really used */
|
|
||||||
struct sftp_attributes_struct {
|
struct sftp_attributes_struct {
|
||||||
char *name;
|
char *name;
|
||||||
char *longname; /* some weird stuff */
|
char *longname; /* ls -l output on openssh, not reliable else */
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
uint32_t gid;
|
uint32_t gid;
|
||||||
char *owner;
|
char *owner; /* set if openssh and version 4 */
|
||||||
char *group;
|
char *group; /* set if openssh and version 4 */
|
||||||
uint32_t permissions;
|
uint32_t permissions;
|
||||||
uint64_t atime64;
|
uint64_t atime64;
|
||||||
uint32_t atime;
|
uint32_t atime;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
/* This file contains code written by Nick Zitzmann */
|
/* This file contains code written by Nick Zitzmann */
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -1111,6 +1112,44 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
|
|||||||
return attr;
|
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 */
|
/* sftp version 0-3 code. It is different from the v4 */
|
||||||
/* maybe a paste of the draft is better than the code */
|
/* 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->uid = ntohl(attr->uid);
|
||||||
attr->gid = ntohl(attr->gid);
|
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) {
|
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);
|
string_free(attr->extended_data);
|
||||||
SAFE_FREE(attr->name);
|
SAFE_FREE(attr->name);
|
||||||
SAFE_FREE(attr->longname);
|
SAFE_FREE(attr->longname);
|
||||||
|
SAFE_FREE(attr->owner);
|
||||||
|
SAFE_FREE(attr->group);
|
||||||
SAFE_FREE(attr);
|
SAFE_FREE(attr);
|
||||||
|
|
||||||
ssh_set_error(sftp->session, SSH_FATAL, "Invalid ATTR structure");
|
ssh_set_error(sftp->session, SSH_FATAL, "Invalid ATTR structure");
|
||||||
|
|||||||
Reference in New Issue
Block a user