David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 10 | #include <linux/slab.h> |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/completion.h> |
| 13 | #include <linux/buffer_head.h> |
Alexey Dobriyan | aa0ac36 | 2007-07-15 23:40:39 -0700 | [diff] [blame] | 14 | #include <linux/capability.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 15 | #include <linux/xattr.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 16 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 17 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 18 | #include <asm/uaccess.h> |
| 19 | |
| 20 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 22 | #include "acl.h" |
| 23 | #include "eaops.h" |
| 24 | #include "eattr.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 25 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * gfs2_ea_name2type - get the type of the ea, and truncate type from the name |
| 29 | * @namep: ea name, possibly with type appended |
| 30 | * |
| 31 | * Returns: GFS2_EATYPE_XXX |
| 32 | */ |
| 33 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 34 | unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 35 | { |
| 36 | unsigned int type; |
| 37 | |
| 38 | if (strncmp(name, "system.", 7) == 0) { |
| 39 | type = GFS2_EATYPE_SYS; |
| 40 | if (truncated_name) |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 41 | *truncated_name = name + sizeof("system.") - 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 42 | } else if (strncmp(name, "user.", 5) == 0) { |
| 43 | type = GFS2_EATYPE_USR; |
| 44 | if (truncated_name) |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 45 | *truncated_name = name + sizeof("user.") - 1; |
Ryan O'Hara | 639b6d7 | 2006-05-22 10:08:35 -0400 | [diff] [blame] | 46 | } else if (strncmp(name, "security.", 9) == 0) { |
| 47 | type = GFS2_EATYPE_SECURITY; |
| 48 | if (truncated_name) |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 49 | *truncated_name = name + sizeof("security.") - 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 50 | } else { |
| 51 | type = GFS2_EATYPE_UNUSED; |
| 52 | if (truncated_name) |
| 53 | *truncated_name = NULL; |
| 54 | } |
| 55 | |
| 56 | return type; |
| 57 | } |
| 58 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 59 | static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 60 | { |
| 61 | if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) && |
| 62 | !GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) && |
| 63 | !capable(CAP_SYS_ADMIN)) |
| 64 | return -EPERM; |
| 65 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 66 | if (GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl == 0 && |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 67 | (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) || |
| 68 | GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len))) |
| 69 | return -EOPNOTSUPP; |
| 70 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 71 | return gfs2_ea_get_i(ip, er); |
| 72 | } |
| 73 | |
| 74 | static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 75 | { |
| 76 | int remove = 0; |
| 77 | int error; |
| 78 | |
| 79 | if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) { |
| 80 | if (!(er->er_flags & GFS2_ERF_MODE)) { |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 81 | er->er_mode = ip->i_inode.i_mode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 82 | er->er_flags |= GFS2_ERF_MODE; |
| 83 | } |
| 84 | error = gfs2_acl_validate_set(ip, 1, er, |
| 85 | &remove, &er->er_mode); |
| 86 | if (error) |
| 87 | return error; |
| 88 | error = gfs2_ea_set_i(ip, er); |
| 89 | if (error) |
| 90 | return error; |
| 91 | if (remove) |
| 92 | gfs2_ea_remove_i(ip, er); |
| 93 | return 0; |
| 94 | |
| 95 | } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) { |
| 96 | error = gfs2_acl_validate_set(ip, 0, er, |
| 97 | &remove, NULL); |
| 98 | if (error) |
| 99 | return error; |
| 100 | if (!remove) |
| 101 | error = gfs2_ea_set_i(ip, er); |
| 102 | else { |
| 103 | error = gfs2_ea_remove_i(ip, er); |
| 104 | if (error == -ENODATA) |
| 105 | error = 0; |
| 106 | } |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 107 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return -EPERM; |
| 111 | } |
| 112 | |
| 113 | static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 114 | { |
| 115 | if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) { |
| 116 | int error = gfs2_acl_validate_remove(ip, 1); |
| 117 | if (error) |
| 118 | return error; |
| 119 | |
| 120 | } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) { |
| 121 | int error = gfs2_acl_validate_remove(ip, 0); |
| 122 | if (error) |
| 123 | return error; |
| 124 | |
| 125 | } else |
| 126 | return -EPERM; |
| 127 | |
| 128 | return gfs2_ea_remove_i(ip, er); |
| 129 | } |
| 130 | |
Denis Cheng | 4ef2900 | 2007-07-31 18:31:11 +0800 | [diff] [blame] | 131 | static const struct gfs2_eattr_operations gfs2_user_eaops = { |
Fabio M. Di Nitto | bcd4055 | 2007-11-28 16:22:09 +0100 | [diff] [blame] | 132 | .eo_get = gfs2_ea_get_i, |
| 133 | .eo_set = gfs2_ea_set_i, |
| 134 | .eo_remove = gfs2_ea_remove_i, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 135 | .eo_name = "user", |
| 136 | }; |
| 137 | |
Denis Cheng | 4ef2900 | 2007-07-31 18:31:11 +0800 | [diff] [blame] | 138 | const struct gfs2_eattr_operations gfs2_system_eaops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 139 | .eo_get = system_eo_get, |
| 140 | .eo_set = system_eo_set, |
| 141 | .eo_remove = system_eo_remove, |
| 142 | .eo_name = "system", |
| 143 | }; |
| 144 | |
Denis Cheng | 4ef2900 | 2007-07-31 18:31:11 +0800 | [diff] [blame] | 145 | static const struct gfs2_eattr_operations gfs2_security_eaops = { |
Fabio M. Di Nitto | bcd4055 | 2007-11-28 16:22:09 +0100 | [diff] [blame] | 146 | .eo_get = gfs2_ea_get_i, |
| 147 | .eo_set = gfs2_ea_set_i, |
| 148 | .eo_remove = gfs2_ea_remove_i, |
Ryan O'Hara | 639b6d7 | 2006-05-22 10:08:35 -0400 | [diff] [blame] | 149 | .eo_name = "security", |
| 150 | }; |
| 151 | |
Denis Cheng | 4ef2900 | 2007-07-31 18:31:11 +0800 | [diff] [blame] | 152 | const struct gfs2_eattr_operations *gfs2_ea_ops[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 153 | NULL, |
| 154 | &gfs2_user_eaops, |
| 155 | &gfs2_system_eaops, |
Ryan O'Hara | e70409f | 2006-05-25 17:36:15 -0400 | [diff] [blame] | 156 | &gfs2_security_eaops, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 157 | }; |
| 158 | |