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.

70 lines
1.8 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_eaccess.hpp"
  17. #include "fs_path.hpp"
  18. #include "ugid.hpp"
  19. #include <string>
  20. #include <vector>
  21. using std::string;
  22. using std::vector;
  23. namespace l
  24. {
  25. static
  26. int
  27. access(const Policy::Search &searchFunc_,
  28. const Branches &branches_,
  29. const char *fusepath_,
  30. const int mask_)
  31. {
  32. int rv;
  33. string fullpath;
  34. StrVec basepaths;
  35. rv = searchFunc_(branches_,fusepath_,&basepaths);
  36. if(rv == -1)
  37. return -errno;
  38. fullpath = fs::path::make(basepaths[0],fusepath_);
  39. rv = fs::eaccess(fullpath,mask_);
  40. return ((rv == -1) ? -errno : 0);
  41. }
  42. }
  43. namespace FUSE
  44. {
  45. int
  46. access(const char *fusepath_,
  47. int mask_)
  48. {
  49. Config::Read cfg;
  50. const fuse_context *fc = fuse_get_context();
  51. const ugid::Set ugid(fc->uid,fc->gid);
  52. return l::access(cfg->func.access.policy,
  53. cfg->branches,
  54. fusepath_,
  55. mask_);
  56. }
  57. }