Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #+BEGIN_QUOTE
  2. How can I clear the POSIX ACLs from a file?
  3. #+END_QUOTE
  4.  
  5. #+BEGIN_SRC cfengine3 :include-stdlib t :verbose-mode nil :inform-mode nil :exports both
  6. bundle agent main
  7. {
  8. vars:
  9. "file" string => "/tmp/myFileWithAces";
  10.  
  11. files:
  12. "$(file)"
  13. create => "true";
  14.  
  15. methods:
  16. "Set POSIX ACL and report"
  17. usebundle => SetAndReport( $(file) );
  18.  
  19. "UnSet POSIX ACL and report"
  20. usebundle => UnSetAndReport( $(file) );
  21. }
  22.  
  23. bundle agent SetAndReport( file )
  24. {
  25. files:
  26. "$(file)"
  27. acl => my_posix_aces;
  28.  
  29. reports:
  30. "In $(this.bundle)$(const.n)$(with)" with => execresult( "getfacl $(file)", useshell);
  31. }
  32.  
  33. bundle agent UnSetAndReport( file )
  34. {
  35. files:
  36. "$(file)"
  37. acl => no_posix_aces;
  38.  
  39. reports:
  40.  
  41. # Yes, it is intentional that there is a space at the end of this
  42. # execresult, it's there so that this identical function call does not
  43. # return the cached result, alternatively I could havd disabled function
  44. # caching globally.
  45.  
  46. "In $(this.bundle)$(const.n)$(with)" with => execresult( "getfacl $(file) ", useshell);
  47. }
  48.  
  49. body acl my_posix_aces
  50. # @brief Settings some aces here
  51. {
  52. acl_method => "overwrite";
  53. acl_type => "posix";
  54. aces => { "user:*:rx", "group:*:rx", "all:r", "mask:rx" };
  55. }
  56.  
  57. body acl no_posix_aces
  58. # @brief I want to remove current aces of the file
  59. {
  60. acl_method => "overwrite";
  61. acl_type => "posix";
  62. aces => { "user:*:", "group:*:", "all:", "mask:" };
  63. }
  64. #+END_SRC
  65.  
  66. #+RESULTS:
  67. #+begin_example
  68. R: In SetAndReport
  69. getfacl: Removing leading '/' from absolute path names
  70. # file: tmp/myFileWithAces
  71. # owner: nickanderson
  72. # group: nickanderson
  73. user::r-x
  74. group::r-x
  75. mask::r-x
  76. other::r--
  77. R: In UnSetAndReport
  78. getfacl: Removing leading '/' from absolute path names
  79. # file: tmp/myFileWithAces
  80. # owner: nickanderson
  81. # group: nickanderson
  82. user::---
  83. group::---
  84. mask::---
  85. other::---
  86. #+end_example
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement