blob: e9389e5d75c30f7083a04364ccc4fea2035fc408 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Dave Kleikampac27a0e2006-10-11 01:20:50 -07002/*
Mingming Cao617ba132006-10-11 01:20:53 -07003 * linux/fs/ext4/xattr_trusted.c
Dave Kleikampac27a0e2006-10-11 01:20:50 -07004 * Handler for trusted extended attributes.
5 *
6 * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
7 */
8
Dave Kleikampac27a0e2006-10-11 01:20:50 -07009#include <linux/string.h>
10#include <linux/capability.h>
11#include <linux/fs.h>
Christoph Hellwig3dcf5452008-04-29 18:13:32 -040012#include "ext4_jbd2.h"
13#include "ext4.h"
Dave Kleikampac27a0e2006-10-11 01:20:50 -070014#include "xattr.h"
15
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010016static bool
17ext4_xattr_trusted_list(struct dentry *dentry)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070018{
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010019 return capable(CAP_SYS_ADMIN);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070020}
21
22static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020023ext4_xattr_trusted_get(const struct xattr_handler *handler,
Al Virob2968212016-04-10 20:48:24 -040024 struct dentry *unused, struct inode *inode,
25 const char *name, void *buffer, size_t size)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070026{
Al Virob2968212016-04-10 20:48:24 -040027 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
Christoph Hellwig431547b2009-11-13 09:52:56 +000028 name, buffer, size);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070029}
30
31static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020032ext4_xattr_trusted_set(const struct xattr_handler *handler,
Al Viro59301222016-05-27 10:19:30 -040033 struct dentry *unused, struct inode *inode,
34 const char *name, const void *value,
35 size_t size, int flags)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070036{
Al Viro59301222016-05-27 10:19:30 -040037 return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
Christoph Hellwig431547b2009-11-13 09:52:56 +000038 name, value, size, flags);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070039}
40
Stephen Hemminger11e27522010-05-13 17:53:18 -070041const struct xattr_handler ext4_xattr_trusted_handler = {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070042 .prefix = XATTR_TRUSTED_PREFIX,
Mingming Cao617ba132006-10-11 01:20:53 -070043 .list = ext4_xattr_trusted_list,
44 .get = ext4_xattr_trusted_get,
45 .set = ext4_xattr_trusted_set,
Dave Kleikampac27a0e2006-10-11 01:20:50 -070046};