You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.7 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #include "config.hpp"
  15. #include "errno.hpp"
  16. #include "fs_lremovexattr.hpp"
  17. #include "fs_path.hpp"
  18. #include "rv.hpp"
  19. #include "ugid.hpp"
  20. #include <fuse.h>
  21. #include <string>
  22. #include <vector>
  23. using std::string;
  24. using std::vector;
  25. namespace l
  26. {
  27. static
  28. int
  29. removexattr_loop_core(const string &basepath_,
  30. const char *fusepath_,
  31. const char *attrname_,
  32. const int error_)
  33. {
  34. int rv;
  35. string fullpath;
  36. fullpath = fs::path::make(basepath_,fusepath_);
  37. rv = fs::lremovexattr(fullpath,attrname_);
  38. return error::calc(rv,error_,errno);
  39. }
  40. static
  41. int
  42. removexattr_loop(const vector<string> &basepaths_,
  43. const char *fusepath_,
  44. const char *attrname_)
  45. {
  46. int error;
  47. error = -1;
  48. for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
  49. {
  50. error = l::removexattr_loop_core(basepaths_[i],fusepath_,attrname_,error);
  51. }
  52. return -error;
  53. }
  54. static
  55. int
  56. removexattr(Policy::Func::Action actionFunc_,
  57. const Branches &branches_,
  58. const char *fusepath_,
  59. const char *attrname_)
  60. {
  61. int rv;
  62. vector<string> basepaths;
  63. rv = actionFunc_(branches_,fusepath_,&basepaths);
  64. if(rv == -1)
  65. return -errno;
  66. return l::removexattr_loop(basepaths,fusepath_,attrname_);
  67. }
  68. }
  69. namespace FUSE
  70. {
  71. int
  72. removexattr(const char *fusepath_,
  73. const char *attrname_)
  74. {
  75. const Config &config = Config::ro();
  76. if(fusepath_ == config.controlfile)
  77. return -ENOATTR;
  78. if(config.xattr.to_int())
  79. return -config.xattr.to_int();
  80. const fuse_context *fc = fuse_get_context();
  81. const ugid::Set ugid(fc->uid,fc->gid);
  82. return l::removexattr(config.func.removexattr.policy,
  83. config.branches,
  84. fusepath_,
  85. attrname_);
  86. }
  87. }