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.

105 lines
2.6 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_base_chmod.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. #include <string.h>
  24. using std::string;
  25. using std::vector;
  26. namespace l
  27. {
  28. static
  29. int
  30. chmod_loop_core(const string &basepath_,
  31. const char *fusepath_,
  32. const mode_t mode_,
  33. const int error_)
  34. {
  35. int rv;
  36. string fullpath;
  37. fullpath = fs::path::make(basepath_,fusepath_);
  38. rv = fs::chmod(fullpath,mode_);
  39. return error::calc(rv,error_,errno);
  40. }
  41. static
  42. int
  43. chmod_loop(const vector<string> &basepaths_,
  44. const char *fusepath_,
  45. const mode_t mode_)
  46. {
  47. int error;
  48. error = -1;
  49. for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
  50. {
  51. error = l::chmod_loop_core(basepaths_[i],fusepath_,mode_,error);
  52. }
  53. return -error;
  54. }
  55. static
  56. int
  57. chmod(Policy::Func::Action actionFunc_,
  58. const Branches &branches_,
  59. const uint64_t minfreespace_,
  60. const char *fusepath_,
  61. const mode_t mode_)
  62. {
  63. int rv;
  64. vector<string> basepaths;
  65. rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
  66. if(rv == -1)
  67. return -errno;
  68. return l::chmod_loop(basepaths,fusepath_,mode_);
  69. }
  70. }
  71. namespace FUSE
  72. {
  73. int
  74. chmod(const char *fusepath_,
  75. mode_t mode_)
  76. {
  77. const fuse_context *fc = fuse_get_context();
  78. const Config &config = Config::ro();
  79. const ugid::Set ugid(fc->uid,fc->gid);
  80. return l::chmod(config.func.chmod.policy,
  81. config.branches,
  82. config.minfreespace,
  83. fusepath_,
  84. mode_);
  85. }
  86. }