/** * Get security context xattr name used by policy. * * \retval >= 0 length of xattr name * \retval < 0 failure to get security context xattr name */ int ll_listsecurity(struct inode *inode, char *secctx_name, size_t secctx_name_size) { int rc; if (!selinux_is_enabled()) return 0; #ifdef HAVE_SECURITY_INODE_LISTSECURITY rc = security_inode_listsecurity(inode, secctx_name, secctx_name_size); if (rc >= secctx_name_size) rc = -ERANGE; else if (rc >= 0) secctx_name[rc] = '\0'; return rc; #else /* !HAVE_SECURITY_INODE_LISTSECURITY */ rc = sizeof(XATTR_NAME_SELINUX); if (secctx_name && rc < secctx_name_size) { memcpy(secctx_name, XATTR_NAME_SELINUX, rc); secctx_name[rc] = '\0'; } else { rc = -ERANGE; } return rc; #endif /* HAVE_SECURITY_INODE_LISTSECURITY */ }
ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size) { ssize_t error; error = security_inode_listxattr(d); if (error) return error; error = -EOPNOTSUPP; if (d->d_inode->i_op && d->d_inode->i_op->listxattr) { error = d->d_inode->i_op->listxattr(d, list, size); } else { error = security_inode_listsecurity(d->d_inode, list, size); if (size && error > size) error = -ERANGE; } return error; }