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.

111 lines
2.6 KiB

  1. /*
  2. Copyright (c) 2018, 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 "category.hpp"
  15. #include "config.hpp"
  16. #include "errno.hpp"
  17. #include "fs_llistxattr.hpp"
  18. #include "fs_path.hpp"
  19. #include "ugid.hpp"
  20. #include "xattr.hpp"
  21. #include "fuse.h"
  22. #include <string>
  23. #include <string.h>
  24. using std::string;
  25. namespace l
  26. {
  27. static
  28. int
  29. listxattr_controlfile(Config::Read &cfg_,
  30. char *list_,
  31. const size_t size_)
  32. {
  33. string xattrs;
  34. cfg_->keys_xattr(xattrs);
  35. if(size_ == 0)
  36. return xattrs.size();
  37. if(size_ < xattrs.size())
  38. return -ERANGE;
  39. memcpy(list_,xattrs.c_str(),xattrs.size());
  40. return xattrs.size();
  41. }
  42. static
  43. int
  44. listxattr(const Policy::Search &searchFunc_,
  45. const Branches &branches_,
  46. const char *fusepath_,
  47. char *list_,
  48. const size_t size_)
  49. {
  50. int rv;
  51. string fullpath;
  52. StrVec basepaths;
  53. rv = searchFunc_(branches_,fusepath_,&basepaths);
  54. if(rv == -1)
  55. return -errno;
  56. fullpath = fs::path::make(basepaths[0],fusepath_);
  57. rv = fs::llistxattr(fullpath,list_,size_);
  58. return ((rv == -1) ? -errno : rv);
  59. }
  60. }
  61. namespace FUSE
  62. {
  63. int
  64. listxattr(const char *fusepath_,
  65. char *list_,
  66. size_t size_)
  67. {
  68. Config::Read cfg;
  69. if(fusepath_ == CONTROLFILE)
  70. return l::listxattr_controlfile(cfg,list_,size_);
  71. switch(cfg->xattr)
  72. {
  73. case XAttr::ENUM::PASSTHROUGH:
  74. break;
  75. case XAttr::ENUM::NOATTR:
  76. return 0;
  77. case XAttr::ENUM::NOSYS:
  78. return -ENOSYS;
  79. }
  80. const fuse_context *fc = fuse_get_context();
  81. const ugid::Set ugid(fc->uid,fc->gid);
  82. return l::listxattr(cfg->func.listxattr.policy,
  83. cfg->branches,
  84. fusepath_,
  85. list_,
  86. size_);
  87. }
  88. }