eaops.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  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
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/capability.h>
  14. #include <linux/xattr.h>
  15. #include <linux/gfs2_ondisk.h>
  16. #include <linux/lm_interface.h>
  17. #include <asm/uaccess.h>
  18. #include "gfs2.h"
  19. #include "incore.h"
  20. #include "acl.h"
  21. #include "eaops.h"
  22. #include "eattr.h"
  23. #include "util.h"
  24. /**
  25. * gfs2_ea_name2type - get the type of the ea, and truncate type from the name
  26. * @namep: ea name, possibly with type appended
  27. *
  28. * Returns: GFS2_EATYPE_XXX
  29. */
  30. unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name)
  31. {
  32. unsigned int type;
  33. if (strncmp(name, "system.", 7) == 0) {
  34. type = GFS2_EATYPE_SYS;
  35. if (truncated_name)
  36. *truncated_name = name + sizeof("system.") - 1;
  37. } else if (strncmp(name, "user.", 5) == 0) {
  38. type = GFS2_EATYPE_USR;
  39. if (truncated_name)
  40. *truncated_name = name + sizeof("user.") - 1;
  41. } else if (strncmp(name, "security.", 9) == 0) {
  42. type = GFS2_EATYPE_SECURITY;
  43. if (truncated_name)
  44. *truncated_name = name + sizeof("security.") - 1;
  45. } else {
  46. type = GFS2_EATYPE_UNUSED;
  47. if (truncated_name)
  48. *truncated_name = NULL;
  49. }
  50. return type;
  51. }
  52. static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  53. {
  54. return gfs2_ea_get_i(ip, er);
  55. }
  56. static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  57. {
  58. return gfs2_ea_set_i(ip, er);
  59. }
  60. static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  61. {
  62. return gfs2_ea_remove_i(ip, er);
  63. }
  64. static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  65. {
  66. if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
  67. !GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) &&
  68. !capable(CAP_SYS_ADMIN))
  69. return -EPERM;
  70. if (GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl == 0 &&
  71. (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) ||
  72. GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
  73. return -EOPNOTSUPP;
  74. return gfs2_ea_get_i(ip, er);
  75. }
  76. static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  77. {
  78. int remove = 0;
  79. int error;
  80. if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
  81. if (!(er->er_flags & GFS2_ERF_MODE)) {
  82. er->er_mode = ip->i_inode.i_mode;
  83. er->er_flags |= GFS2_ERF_MODE;
  84. }
  85. error = gfs2_acl_validate_set(ip, 1, er,
  86. &remove, &er->er_mode);
  87. if (error)
  88. return error;
  89. error = gfs2_ea_set_i(ip, er);
  90. if (error)
  91. return error;
  92. if (remove)
  93. gfs2_ea_remove_i(ip, er);
  94. return 0;
  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. }
  107. return error;
  108. }
  109. return -EPERM;
  110. }
  111. static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  112. {
  113. if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
  114. int error = gfs2_acl_validate_remove(ip, 1);
  115. if (error)
  116. return error;
  117. } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
  118. int error = gfs2_acl_validate_remove(ip, 0);
  119. if (error)
  120. return error;
  121. } else
  122. return -EPERM;
  123. return gfs2_ea_remove_i(ip, er);
  124. }
  125. static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  126. {
  127. return gfs2_ea_get_i(ip, er);
  128. }
  129. static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  130. {
  131. return gfs2_ea_set_i(ip, er);
  132. }
  133. static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
  134. {
  135. return gfs2_ea_remove_i(ip, er);
  136. }
  137. static const struct gfs2_eattr_operations gfs2_user_eaops = {
  138. .eo_get = user_eo_get,
  139. .eo_set = user_eo_set,
  140. .eo_remove = user_eo_remove,
  141. .eo_name = "user",
  142. };
  143. const struct gfs2_eattr_operations gfs2_system_eaops = {
  144. .eo_get = system_eo_get,
  145. .eo_set = system_eo_set,
  146. .eo_remove = system_eo_remove,
  147. .eo_name = "system",
  148. };
  149. static const struct gfs2_eattr_operations gfs2_security_eaops = {
  150. .eo_get = security_eo_get,
  151. .eo_set = security_eo_set,
  152. .eo_remove = security_eo_remove,
  153. .eo_name = "security",
  154. };
  155. const struct gfs2_eattr_operations *gfs2_ea_ops[] = {
  156. NULL,
  157. &gfs2_user_eaops,
  158. &gfs2_system_eaops,
  159. &gfs2_security_eaops,
  160. };