[PATCH] vfs_glusterfs: Make sure posix acls are formatted "before setting"/"after getting"
Christopher R. Hertel
crh at samba.org
Fri Aug 9 16:50:46 MDT 2013
I've updated the patch (fixed the formatting to meet Samba standards).
+1 for the attached.
Need one more approval so that I can commit.
Chris -)-----
On 08/07/2013 10:13 AM, Raghavendra Talur wrote:
>
>
>
> vfs_glusterfs: format acls and xattr correctly
>
> 1. In case of setting acls
> The format to set acls using xattr by setxattr call
> prescribes the acl entries to be in little endian format.
> This patch converts the values to little endian.
>
> 2. In case of getting acls
> As acl entries are always stored in little endian byte order,
> we have to convert the data to cpu's native byte order before
> using it.
>
> I have attached the patch.
>
>>From 877534ac5f98cb3aff57151c0aea754bfb078e65 Mon Sep 17 00:00:00 2001
> From: Raghavendra Talur <rtalur at redhat.com>
> Date: Wed, 7 Aug 2013 18:22:29 +0530
> Subject: [PATCH] vfs_glusterfs: format acls and xattr correctly
>
> 1. In case of setting acls
> The format to set acls using xattr by setxattr call
> prescribes the acl entries to be in little endian format.
> This patch converts the values to little endian.
>
> 2. In case of getting acls
> As acl entries are always stored in little endian byte order,
> we have to convert the data to cpu's native byte order before
> using it.
>
> Signed-off-by: Raghavendra Talur <rtalur at redhat.com>
> ---
> source3/modules/vfs_glusterfs.c | 58 +++++++++++++++++++++++++++++++++++------
> 1 file changed, 50 insertions(+), 8 deletions(-)
>
> diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
> index 1323e0e..39e9b9f 100644
> --- a/source3/modules/vfs_glusterfs.c
> +++ b/source3/modules/vfs_glusterfs.c
> @@ -1023,6 +1023,45 @@ struct gluster_acl_header {
> struct gluster_ace entries[];
> };
>
> +static int gluster_ace_cmp (const void *val1, const void *val2)
> +{
> + const struct gluster_ace *ace1 = NULL;
> + const struct gluster_ace *ace2 = NULL;
> + int ret = 0;
> +
> + ace1 = val1;
> + ace2 = val2;
> +
> + ret = (ace1->tag - ace2->tag);
> + if (!ret)
> + ret = (ace1->id - ace2->id);
> +
> + return ret;
> +}
> +
> +static void gluster_acl_normalize (struct gluster_acl_header *acl, int count)
> +{
> + qsort (acl->entries, count, sizeof (struct gluster_ace *),
> + gluster_ace_cmp);
> +}
> +
> +static void gluster_acl_to_xattr (struct gluster_acl_header *acl, int count)
> +{
> + struct gluster_ace *ace;
> + int i;
> +
> + ace = acl->entries;
> +
> + SIVAL(&acl->version, 0, acl->version);
> +
> + for (i = 0; i < count; i++) {
> + SSVAL(&ace->tag, 0, ace->tag);
> + SSVAL(&ace->perm, 0, ace->perm);
> + SIVAL(&ace->id, 0, ace->id);
> + ace++;
> + }
> +}
> +
> static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
> TALLOC_CTX *mem_ctx)
> {
> @@ -1059,9 +1098,9 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
>
> hdr = (void *)buf;
>
> - if (ntohl(hdr->version) != GLUSTER_ACL_VERSION) {
> + if (GLUSTER_ACL_VERSION != IVAL(&hdr->version, 0)) {
> DEBUG(0, ("Unknown gluster ACL version: %d\n",
> - ntohl(hdr->version)));
> + IVAL(&hdr->version, 0)));
> return NULL;
> }
>
> @@ -1084,7 +1123,7 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
> ace = hdr->entries;
>
> for (i = 0; i < count; i++) {
> - tag = ntohs(ace->tag);
> + tag = SVAL(&ace->tag, 0);
>
> switch(tag) {
> case GLUSTER_ACL_USER:
> @@ -1110,7 +1149,7 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
> return NULL;
> }
>
> - id = ntohl(ace->id);
> + id = IVAL(&ace->id, 0);
>
> switch(smb_ace->a_type) {
> case SMB_ACL_USER:
> @@ -1123,7 +1162,7 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
> break;
> }
>
> - perm = ntohs(ace->perm);
> + perm = SVAL(&ace->perm, 0);
>
> smb_ace->a_perm = 0;
> smb_ace->a_perm |=
> @@ -1169,7 +1208,7 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
> ace = hdr->entries;
> smb_ace = theacl->acl;
>
> - hdr->version = htonl(GLUSTER_ACL_VERSION);
> + hdr->version = GLUSTER_ACL_VERSION;
>
> for (i = 0; i < count; i++) {
> switch(smb_ace->a_type) {
> @@ -1198,7 +1237,7 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
> return -1;
> }
>
> - ace->tag = ntohs(tag);
> + ace->tag = tag;
>
> switch(smb_ace->a_type) {
> case SMB_ACL_USER:
> @@ -1212,7 +1251,7 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
> break;
> }
>
> - ace->id = ntohl(id);
> + ace->id = id;
>
> ace->perm = 0;
> ace->perm |=
> @@ -1226,6 +1265,9 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
> smb_ace++;
> }
>
> + gluster_acl_normalize (hdr, count);
> + gluster_acl_to_xattr (hdr, count);
> +
> return size;
> }
>
--
"Implementing CIFS - the Common Internet FileSystem" ISBN: 013047116X
Samba Team -- http://www.samba.org/ -)----- Christopher R. Hertel
jCIFS Team -- http://jcifs.samba.org/ -)----- ubiqx development, uninq.
ubiqx Team -- http://www.ubiqx.org/ -)----- crh at ubiqx.mn.org
OnLineBook -- http://ubiqx.org/cifs/ -)----- crh at ubiqx.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-vfs_glusterfs-format-acls-and-xattr-correctly.patch
Type: text/x-patch
Size: 4138 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20130809/c2a1f137/attachment.bin>
More information about the samba-technical
mailing list