[Gluster-devel] Problems about acl_get_file used in posix_pacl_get

Kinglong Mee kinglongmee at gmail.com
Fri Aug 17 07:04:43 UTC 2018


Hello folks,

nfs-ganesha using the new gfapi named glfs_h_acl_set/glfs_h_acl_get,
at xlator posix, glusterfsd calls acl_get_file/acl_set_file (libacl functions) to process xattrs.

By default, sys_lsetxattr/sys_llistxattr/sys_lgetxattr/sys_lremovexattr are used to process xattrs.
But, unfortunately, those two functions do syscall by getxattr/setxattr.
I don't think that is we want.

Is it a known problem ?

------------ following are acl_get_file/acl_set_file functions ------------------

/* 23.4.16 */
acl_t
acl_get_file(const char *path_p, acl_type_t type)
{
        const size_t size_guess = acl_ea_size(16);
        char *ext_acl_p = alloca(size_guess);
        const char *name;
        int retval;

        switch(type) {
                case ACL_TYPE_ACCESS:
                        name = ACL_EA_ACCESS;
                        break;
                case ACL_TYPE_DEFAULT:
                        name = ACL_EA_DEFAULT;
                        break;
                default:
                        errno = EINVAL;
                        return NULL;
        }

        if (!ext_acl_p)
                return NULL;
        retval = getxattr(path_p, name, ext_acl_p, size_guess);
        if (retval == -1 && errno == ERANGE) {
                retval = getxattr(path_p, name, NULL, 0);
                if (retval > 0) {
                        ext_acl_p = alloca(retval);
                        if (!ext_acl_p)
                                return NULL;
                        retval = getxattr(path_p, name, ext_acl_p, retval);
                }
        }
        if (retval > 0) {
                acl_t acl = __acl_from_xattr(ext_acl_p, retval);
                return acl;
        } else if (retval == 0 || errno == ENOATTR || errno == ENODATA) {
                struct stat st;

                if (stat(path_p, &st) != 0)
                        return NULL;

                if (type == ACL_TYPE_DEFAULT) {
                        if (S_ISDIR(st.st_mode))
                                return acl_init(0);
                        else {
                                errno = EACCES;
                                return NULL;
                        }
                } else
                        return acl_from_mode(st.st_mode);
        } else
                return NULL;
}

/* 23.4.22 */
int
acl_set_file(const char *path_p, acl_type_t type, acl_t acl)
{
        acl_obj *acl_obj_p = ext2int(acl, acl);
        char *ext_acl_p;
        const char *name;
        size_t size;
        int error;

        if (!acl_obj_p)
                return -1;
        switch (type) {
                case ACL_TYPE_ACCESS:
                        name = ACL_EA_ACCESS;
                        break;
                case ACL_TYPE_DEFAULT:
                        name = ACL_EA_DEFAULT;
                        break;
                default:
                        errno = EINVAL;
                        return -1;
        }

        if (type == ACL_TYPE_DEFAULT) {
                struct stat st;

                if (stat(path_p, &st) != 0)
                        return -1;

                /* Only directories may have default ACLs. */
                if (!S_ISDIR(st.st_mode)) {
                        errno = EACCES;
                        return -1;
                }
        }

        ext_acl_p = __acl_to_xattr(acl_obj_p, &size);
        if (!ext_acl_p)
                return -1;
        error = setxattr(path_p, name, (char *)ext_acl_p, size, 0);
        free(ext_acl_p);
        return error;
}

thanks,
Kinglong Mee


More information about the Gluster-devel mailing list