__acl: rewrite
This commit is contained in:
parent
d723f60673
commit
91a6ecc701
6 changed files with 66 additions and 84 deletions
|
@ -20,29 +20,17 @@
|
||||||
|
|
||||||
# TODO check if filesystem has ACL turned on etc
|
# TODO check if filesystem has ACL turned on etc
|
||||||
|
|
||||||
for parameter in user group
|
grep -E '^(default:)?(user|group):' "$__object/parameter/acl" \
|
||||||
|
| while read -r acl
|
||||||
do
|
do
|
||||||
if [ ! -f "$__object/parameter/$parameter" ]
|
param="$( echo "$acl" | awk -F: '{print $(NF-2)}' )"
|
||||||
|
check="$( echo "$acl" | awk -F: '{print $(NF-1)}' )"
|
||||||
|
|
||||||
|
[ "$param" = 'user' ] && db=passwd || db="$param"
|
||||||
|
|
||||||
|
if ! getent "$db" "$check" > /dev/null
|
||||||
then
|
then
|
||||||
continue
|
echo "missing $param '$check'" >&2
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while read -r acl
|
|
||||||
do
|
|
||||||
check="$( echo "$acl" | awk -F: '{print $1}' )"
|
|
||||||
|
|
||||||
if [ "$parameter" = 'user' ]
|
|
||||||
then
|
|
||||||
getent_db=passwd
|
|
||||||
else
|
|
||||||
getent_db="$parameter"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! getent "$getent_db" "$check" > /dev/null
|
|
||||||
then
|
|
||||||
echo "missing $parameter '$check'" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done \
|
|
||||||
< "$__object/parameter/$parameter"
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -24,41 +24,35 @@ file_is="$( cat "$__object/explorer/file_is" )"
|
||||||
|
|
||||||
os="$( cat "$__global/explorer/os" )"
|
os="$( cat "$__global/explorer/os" )"
|
||||||
|
|
||||||
acl_is="$( cat "$__object/explorer/acl_is" )"
|
|
||||||
|
|
||||||
acl_path="/$__object_id"
|
acl_path="/$__object_id"
|
||||||
|
|
||||||
if [ -f "$__object/parameter/default" ] && [ "$file_is" = 'directory' ]
|
acl_is="$( cat "$__object/explorer/acl_is" )"
|
||||||
|
|
||||||
|
acl_should="$( cat "$__object/parameter/acl" )"
|
||||||
|
|
||||||
|
if [ -f "$__object/parameter/default" ]
|
||||||
then
|
then
|
||||||
set_default=1
|
acl_should="$( echo "$acl_should" \
|
||||||
else
|
| sed 's/^default://' \
|
||||||
set_default=0
|
| sort -u \
|
||||||
|
| sed 's/\(.*\)/default:\1\n\1/' )"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
acl_should="$( for parameter in user group mask other
|
if [ "$file_is" = 'regular' ] \
|
||||||
do
|
&& echo "$acl_should" | grep -Eq '^default:'
|
||||||
if [ ! -f "$__object/parameter/$parameter" ]
|
then
|
||||||
then
|
# only directories can have default ACLs,
|
||||||
continue
|
# but instead of error,
|
||||||
fi
|
# let's just remove default entries
|
||||||
|
acl_should="$( echo "$acl_should" | grep -Ev '^default:' )"
|
||||||
|
fi
|
||||||
|
|
||||||
while read -r acl
|
if echo "$acl_should" | awk -F: '{ print $NF }' | grep -Fq 'X'
|
||||||
do
|
then
|
||||||
if echo "$acl" | awk -F: '{ print $NF }' | grep -Fq 'X'
|
[ "$file_is" = 'directory' ] && rep=x || rep=-
|
||||||
then
|
|
||||||
[ "$file_is" = 'directory' ] && rep=x || rep=-
|
|
||||||
|
|
||||||
acl="$( echo "$acl" | sed "s/\\(.*\\)X/\\1$rep/" )"
|
acl_should="$( echo "$acl_should" | sed "s/\\(.*\\)X/\\1$rep/" )"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$parameter" | grep -Eq '(mask|other)' && sep=:: || sep=:
|
|
||||||
|
|
||||||
echo "$parameter$sep$acl"
|
|
||||||
|
|
||||||
[ "$set_default" = '1' ] && echo "default:$parameter$sep$acl"
|
|
||||||
done \
|
|
||||||
< "$__object/parameter/$parameter"
|
|
||||||
done )"
|
|
||||||
|
|
||||||
setfacl_exec='setfacl'
|
setfacl_exec='setfacl'
|
||||||
|
|
||||||
|
@ -76,7 +70,7 @@ if [ -f "$__object/parameter/remove" ]
|
||||||
then
|
then
|
||||||
echo "$acl_is" | while read -r acl
|
echo "$acl_is" | while read -r acl
|
||||||
do
|
do
|
||||||
# Skip wanted ACL entries which already exist
|
# skip wanted ACL entries which already exist
|
||||||
# and skip mask and other entries, because we
|
# and skip mask and other entries, because we
|
||||||
# can't actually remove them, but only change.
|
# can't actually remove them, but only change.
|
||||||
if echo "$acl_should" | grep -Eq "^$acl" \
|
if echo "$acl_should" | grep -Eq "^$acl" \
|
||||||
|
@ -103,7 +97,7 @@ do
|
||||||
if echo "$os" | grep -Fq 'freebsd' \
|
if echo "$os" | grep -Fq 'freebsd' \
|
||||||
&& echo "$acl" | grep -Eq '^default:'
|
&& echo "$acl" | grep -Eq '^default:'
|
||||||
then
|
then
|
||||||
echo "setting default ACL in $os is currently not supported. sorry :(" >&2
|
echo "setting default ACL in $os is currently not supported" >&2
|
||||||
else
|
else
|
||||||
echo "$setfacl_exec -m \"$acl\" \"$acl_path\""
|
echo "$setfacl_exec -m \"$acl\" \"$acl_path\""
|
||||||
echo "added '$acl'" >> "$__messages_out"
|
echo "added '$acl'" >> "$__messages_out"
|
||||||
|
|
|
@ -8,42 +8,30 @@ cdist-type__acl - Set ACL entries
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
ACL must be defined as 3-symbol combination, using ``r``, ``w``, ``x`` and ``-``.
|
|
||||||
|
|
||||||
Fully supported and tested on Linux (ext4 filesystem), partial support for FreeBSD.
|
Fully supported and tested on Linux (ext4 filesystem), partial support for FreeBSD.
|
||||||
|
|
||||||
See ``setfacl`` and ``acl`` manpages for more details.
|
See ``setfacl`` and ``acl`` manpages for more details.
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL MULTIPLE PARAMETERS
|
REQUIRED MULTIPLE PARAMETERS
|
||||||
----------------------------
|
----------------------------
|
||||||
user
|
acl
|
||||||
Add user ACL entry.
|
Set ACL entry following ``getfacl`` output syntax.
|
||||||
|
|
||||||
group
|
|
||||||
Add group ACL entry.
|
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
|
||||||
-------------------
|
|
||||||
mask
|
|
||||||
Add mask ACL entry.
|
|
||||||
|
|
||||||
other
|
|
||||||
Add other ACL entry.
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN PARAMETERS
|
BOOLEAN PARAMETERS
|
||||||
------------------
|
------------------
|
||||||
|
default
|
||||||
|
Set all ACL entries as default too.
|
||||||
|
Only directories can have default ACLs.
|
||||||
|
Setting default ACL in FreeBSD is currently not supported.
|
||||||
|
|
||||||
recursive
|
recursive
|
||||||
Make ``setfacl`` recursive (Linux only), but not ``getfacl`` in explorer.
|
Make ``setfacl`` recursive (Linux only), but not ``getfacl`` in explorer.
|
||||||
|
|
||||||
default
|
|
||||||
Add default ACL entries (FreeBSD not supported).
|
|
||||||
|
|
||||||
remove
|
remove
|
||||||
Remove undefined ACL entries (Solaris not supported).
|
Remove undefined ACL entries.
|
||||||
ACL entries for ``mask`` and ``other`` can't be removed.
|
``mask`` and ``other`` entries can't be removed, but only changed.
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
@ -52,15 +40,30 @@ EXAMPLES
|
||||||
.. code-block:: sh
|
.. code-block:: sh
|
||||||
|
|
||||||
__acl /srv/project \
|
__acl /srv/project \
|
||||||
|
--default \
|
||||||
--recursive \
|
--recursive \
|
||||||
|
--remove \
|
||||||
|
--acl user:alice:rwx \
|
||||||
|
--acl user:bob:r-x \
|
||||||
|
--acl group:project-group:rwx \
|
||||||
|
--acl group:some-other-group:r-x \
|
||||||
|
--acl mask::r-x \
|
||||||
|
--acl other::r-x
|
||||||
|
|
||||||
|
# give Alice read-only access to subdir,
|
||||||
|
# but don't allow her to see parent content.
|
||||||
|
|
||||||
|
__acl /srv/project2 \
|
||||||
|
--remove \
|
||||||
|
--acl default:group:secret-project:rwx \
|
||||||
|
--acl group:secret-project:rwx \
|
||||||
|
--acl user:alice:--x
|
||||||
|
|
||||||
|
__acl /srv/project2/subdir \
|
||||||
--default \
|
--default \
|
||||||
--remove \
|
--remove \
|
||||||
--user alice:rwx \
|
--acl group:secret-project:rwx \
|
||||||
--user bob:r-x \
|
--acl user:alice:r-x
|
||||||
--group project-group:rwx \
|
|
||||||
--group some-other-group:r-x \
|
|
||||||
--mask r-x \
|
|
||||||
--other r-x
|
|
||||||
|
|
||||||
|
|
||||||
AUTHORS
|
AUTHORS
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
mask
|
|
||||||
other
|
|
|
@ -1,2 +0,0 @@
|
||||||
user
|
|
||||||
group
|
|
1
cdist/conf/type/__acl/parameter/required_multiple
Normal file
1
cdist/conf/type/__acl/parameter/required_multiple
Normal file
|
@ -0,0 +1 @@
|
||||||
|
acl
|
Loading…
Reference in a new issue