2 * Copyright (c) 2002 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 STATIC
int xfs_cap_allow_set(vnode_t
*);
39 * Test for existence of capability attribute as efficiently as possible.
46 int len
= sizeof(xfs_cap_set_t
);
47 int flags
= ATTR_KERNOVAL
|ATTR_ROOT
;
49 VOP_ATTR_GET(vp
, SGI_CAP_LINUX
, NULL
, &len
, flags
, sys_cred
, error
);
54 * Convert from extended attribute representation to in-memory for XFS.
57 posix_cap_xattr_to_xfs(
65 if (src
->c_version
!= cpu_to_le32(POSIX_CAP_XATTR_VERSION
))
67 if (src
->c_abiversion
!= cpu_to_le32(_LINUX_CAPABILITY_VERSION
))
70 if (size
< sizeof(posix_cap_xattr
))
73 ASSERT(sizeof(dest
->cap_effective
) == sizeof(src
->c_effective
));
75 dest
->cap_effective
= src
->c_effective
;
76 dest
->cap_permitted
= src
->c_permitted
;
77 dest
->cap_inheritable
= src
->c_inheritable
;
83 * Convert from in-memory XFS to extended attribute representation.
86 posix_cap_xfs_to_xattr(
88 posix_cap_xattr
*xattr_cap
,
91 size_t new_size
= posix_cap_xattr_size();
96 ASSERT(sizeof(xattr_cap
->c_effective
) == sizeof(src
->cap_effective
));
98 xattr_cap
->c_version
= cpu_to_le32(POSIX_CAP_XATTR_VERSION
);
99 xattr_cap
->c_abiversion
= cpu_to_le32(_LINUX_CAPABILITY_VERSION
);
100 xattr_cap
->c_effective
= src
->cap_effective
;
101 xattr_cap
->c_permitted
= src
->cap_permitted
;
102 xattr_cap
->c_inheritable
= src
->cap_inheritable
;
114 int len
= sizeof(xfs_cap_set_t
);
115 int flags
= ATTR_ROOT
;
116 xfs_cap_set_t xfs_cap
= { 0 };
117 posix_cap_xattr
*xattr_cap
= cap
;
118 char *data
= (char *)&xfs_cap
;
121 if ((error
= _MAC_VACCESS(vp
, NULL
, VREAD
)))
125 flags
|= ATTR_KERNOVAL
;
128 VOP_ATTR_GET(vp
, SGI_CAP_LINUX
, data
, &len
, flags
, sys_cred
, error
);
131 ASSERT(len
== sizeof(xfs_cap_set_t
));
133 error
= (size
)? -posix_cap_xattr_size() :
134 -posix_cap_xfs_to_xattr(&xfs_cap
, xattr_cap
, size
);
147 error
= xfs_cap_allow_set(vp
);
149 VOP_ATTR_REMOVE(vp
, SGI_CAP_LINUX
, ATTR_ROOT
, sys_cred
, error
);
150 if (error
== ENOATTR
)
151 error
= 0; /* 'scool */
163 posix_cap_xattr
*xattr_cap
= cap
;
164 xfs_cap_set_t xfs_cap
;
170 error
= posix_cap_xattr_to_xfs(xattr_cap
, size
, &xfs_cap
);
175 error
= xfs_cap_allow_set(vp
);
179 VOP_ATTR_SET(vp
, SGI_CAP_LINUX
, (char *)&xfs_cap
,
180 sizeof(xfs_cap_set_t
), ATTR_ROOT
, sys_cred
, error
);
193 if (vp
->v_vfsp
->vfs_flag
& VFS_RDONLY
)
195 if ((error
= _MAC_VACCESS(vp
, NULL
, VWRITE
)))
197 va
.va_mask
= XFS_AT_UID
;
198 VOP_GETATTR(vp
, &va
, 0, NULL
, error
);
201 if (va
.va_uid
!= current
->fsuid
&& !capable(CAP_FOWNER
))