2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
10 #include <linux/slab.h>
11 #include <linux/spinlock.h>
12 #include <linux/completion.h>
13 #include <linux/buffer_head.h>
14 #include <linux/xattr.h>
15 #include <linux/gfs2_ondisk.h>
16 #include <linux/lm_interface.h>
17 #include <asm/uaccess.h>
27 * gfs2_ea_name2type - get the type of the ea, and truncate type from the name
28 * @namep: ea name, possibly with type appended
30 * Returns: GFS2_EATYPE_XXX
33 unsigned int gfs2_ea_name2type(const char *name
, const char **truncated_name
)
37 if (strncmp(name
, "system.", 7) == 0) {
38 type
= GFS2_EATYPE_SYS
;
40 *truncated_name
= name
+ sizeof("system.") - 1;
41 } else if (strncmp(name
, "user.", 5) == 0) {
42 type
= GFS2_EATYPE_USR
;
44 *truncated_name
= name
+ sizeof("user.") - 1;
45 } else if (strncmp(name
, "security.", 9) == 0) {
46 type
= GFS2_EATYPE_SECURITY
;
48 *truncated_name
= name
+ sizeof("security.") - 1;
50 type
= GFS2_EATYPE_UNUSED
;
52 *truncated_name
= NULL
;
58 static int user_eo_get(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
60 struct inode
*inode
= &ip
->i_inode
;
61 int error
= permission(inode
, MAY_READ
, NULL
);
65 return gfs2_ea_get_i(ip
, er
);
68 static int user_eo_set(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
70 struct inode
*inode
= &ip
->i_inode
;
72 if (S_ISREG(inode
->i_mode
) ||
73 (S_ISDIR(inode
->i_mode
) && !(inode
->i_mode
& S_ISVTX
))) {
74 int error
= permission(inode
, MAY_WRITE
, NULL
);
80 return gfs2_ea_set_i(ip
, er
);
83 static int user_eo_remove(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
85 struct inode
*inode
= &ip
->i_inode
;
87 if (S_ISREG(inode
->i_mode
) ||
88 (S_ISDIR(inode
->i_mode
) && !(inode
->i_mode
& S_ISVTX
))) {
89 int error
= permission(inode
, MAY_WRITE
, NULL
);
95 return gfs2_ea_remove_i(ip
, er
);
98 static int system_eo_get(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
100 if (!GFS2_ACL_IS_ACCESS(er
->er_name
, er
->er_name_len
) &&
101 !GFS2_ACL_IS_DEFAULT(er
->er_name
, er
->er_name_len
) &&
102 !capable(CAP_SYS_ADMIN
))
105 if (GFS2_SB(&ip
->i_inode
)->sd_args
.ar_posix_acl
== 0 &&
106 (GFS2_ACL_IS_ACCESS(er
->er_name
, er
->er_name_len
) ||
107 GFS2_ACL_IS_DEFAULT(er
->er_name
, er
->er_name_len
)))
112 return gfs2_ea_get_i(ip
, er
);
115 static int system_eo_set(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
120 if (GFS2_ACL_IS_ACCESS(er
->er_name
, er
->er_name_len
)) {
121 if (!(er
->er_flags
& GFS2_ERF_MODE
)) {
122 er
->er_mode
= ip
->i_inode
.i_mode
;
123 er
->er_flags
|= GFS2_ERF_MODE
;
125 error
= gfs2_acl_validate_set(ip
, 1, er
,
126 &remove
, &er
->er_mode
);
129 error
= gfs2_ea_set_i(ip
, er
);
133 gfs2_ea_remove_i(ip
, er
);
136 } else if (GFS2_ACL_IS_DEFAULT(er
->er_name
, er
->er_name_len
)) {
137 error
= gfs2_acl_validate_set(ip
, 0, er
,
142 error
= gfs2_ea_set_i(ip
, er
);
144 error
= gfs2_ea_remove_i(ip
, er
);
145 if (error
== -ENODATA
)
154 static int system_eo_remove(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
156 if (GFS2_ACL_IS_ACCESS(er
->er_name
, er
->er_name_len
)) {
157 int error
= gfs2_acl_validate_remove(ip
, 1);
161 } else if (GFS2_ACL_IS_DEFAULT(er
->er_name
, er
->er_name_len
)) {
162 int error
= gfs2_acl_validate_remove(ip
, 0);
169 return gfs2_ea_remove_i(ip
, er
);
172 static int security_eo_get(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
174 struct inode
*inode
= &ip
->i_inode
;
175 int error
= permission(inode
, MAY_READ
, NULL
);
179 return gfs2_ea_get_i(ip
, er
);
182 static int security_eo_set(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
184 struct inode
*inode
= &ip
->i_inode
;
185 int error
= permission(inode
, MAY_WRITE
, NULL
);
189 return gfs2_ea_set_i(ip
, er
);
192 static int security_eo_remove(struct gfs2_inode
*ip
, struct gfs2_ea_request
*er
)
194 struct inode
*inode
= &ip
->i_inode
;
195 int error
= permission(inode
, MAY_WRITE
, NULL
);
199 return gfs2_ea_remove_i(ip
, er
);
202 static struct gfs2_eattr_operations gfs2_user_eaops
= {
203 .eo_get
= user_eo_get
,
204 .eo_set
= user_eo_set
,
205 .eo_remove
= user_eo_remove
,
209 struct gfs2_eattr_operations gfs2_system_eaops
= {
210 .eo_get
= system_eo_get
,
211 .eo_set
= system_eo_set
,
212 .eo_remove
= system_eo_remove
,
216 static struct gfs2_eattr_operations gfs2_security_eaops
= {
217 .eo_get
= security_eo_get
,
218 .eo_set
= security_eo_set
,
219 .eo_remove
= security_eo_remove
,
220 .eo_name
= "security",
223 struct gfs2_eattr_operations
*gfs2_ea_ops
[] = {
227 &gfs2_security_eaops
,