forked from ungleich-public/cdist
Merge branch 'fix/stat-explorer' into 'master'
type/{__file/__directory}: Support setuid,setguid,sticky bits See merge request ungleich-public/cdist!903
This commit is contained in:
commit
652ffea4a8
4 changed files with 28 additions and 89 deletions
|
@ -30,10 +30,10 @@ fallback() {
|
||||||
gid=$(echo "$ls_line" | awk '{ print $4 }')
|
gid=$(echo "$ls_line" | awk '{ print $4 }')
|
||||||
|
|
||||||
owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
|
owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
|
||||||
group=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
|
group=$(awk -F: -v gid="$gid" '$3 == gid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
|
||||||
|
|
||||||
mode_text=$(echo "$ls_line" | awk '{ print $1 }')
|
mode_text=$(echo "$ls_line" | awk '{ print $1 }')
|
||||||
mode=$(echo "$mode_text" | awk '{ k=0; for (i=0; i<=8; i++) k += ((substr($1, i+2, 1) ~ /[rwx]/) * 2^(8-i)); printf("%0o", k) }')
|
mode=$(echo "$mode_text" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')
|
||||||
|
|
||||||
printf 'type: %s\nowner: %d %s\ngroup: %d %s\nmode: %s %s\n' \
|
printf 'type: %s\nowner: %d %s\ngroup: %d %s\nmode: %s %s\n' \
|
||||||
"$("$__type_explorer/type")" \
|
"$("$__type_explorer/type")" \
|
||||||
|
@ -45,56 +45,27 @@ fallback() {
|
||||||
# nothing to work with, nothing we could do
|
# nothing to work with, nothing we could do
|
||||||
[ -e "$destination" ] || exit 0
|
[ -e "$destination" ] || exit 0
|
||||||
|
|
||||||
if ! command -v stat >/dev/null
|
command -v stat >/dev/null 2>&1 || {
|
||||||
then
|
|
||||||
fallback
|
fallback
|
||||||
exit
|
exit
|
||||||
fi
|
}
|
||||||
|
|
||||||
case $("$__explorer/os") in
|
case $("$__explorer/os")
|
||||||
"freebsd"|"netbsd"|"openbsd"|"macosx")
|
in
|
||||||
stat -f "type: %HT
|
freebsd|netbsd|openbsd|macosx)
|
||||||
|
stat -f 'type: %HT
|
||||||
owner: %Du %Su
|
owner: %Du %Su
|
||||||
group: %Dg %Sg
|
group: %Dg %Sg
|
||||||
mode: %Lp %Sp
|
mode: %Mp%03Lp %Sp
|
||||||
" "$destination" | awk '/^type/ { print tolower($0); next } { print }'
|
' "$destination" | awk '/^type/ { print tolower($0); next } { print }'
|
||||||
;;
|
;;
|
||||||
solaris)
|
|
||||||
ls1="$( ls -ld "$destination" )"
|
|
||||||
ls2="$( ls -ldn "$destination" )"
|
|
||||||
|
|
||||||
if [ -f "$__object/parameter/mode" ]
|
|
||||||
then mode_should="$( cat "$__object/parameter/mode" )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# yes, it is ugly hack, but if you know better way...
|
|
||||||
if [ -z "$( find "$destination" -perm "$mode_should" )" ]
|
|
||||||
then octets=888
|
|
||||||
else octets="$( echo "$mode_should" | sed 's/^0//' )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$( echo "$ls1" | cut -c1-1 )" in
|
|
||||||
-) echo 'type: regular file' ;;
|
|
||||||
d) echo 'type: directory' ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "owner: $( echo "$ls2" \
|
|
||||||
| awk '{print $3}' ) $( echo "$ls1" \
|
|
||||||
| awk '{print $3}' )"
|
|
||||||
|
|
||||||
echo "group: $( echo "$ls2" \
|
|
||||||
| awk '{print $4}' ) $( echo "$ls1" \
|
|
||||||
| awk '{print $4}' )"
|
|
||||||
|
|
||||||
echo "mode: $octets $( echo "$ls1" | awk '{print $1}' )"
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
|
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
|
||||||
# NOTE: BusyBox's stat might not support the "-c" option, in which case
|
# NOTE: BusyBox's stat might not support the "-c" option, in which case
|
||||||
# we fall through to the shell fallback.
|
# we fall through to the shell fallback.
|
||||||
stat -c "type: %F
|
stat -c 'type: %F
|
||||||
owner: %u %U
|
owner: %u %U
|
||||||
group: %g %G
|
group: %g %G
|
||||||
mode: %a %A" "$destination" 2>/dev/null || fallback
|
mode: %04a %A' "$destination" 2>/dev/null || fallback
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -97,9 +97,9 @@ case "$state_should" in
|
||||||
value_should="$(cat "$__object/parameter/$attribute")"
|
value_should="$(cat "$__object/parameter/$attribute")"
|
||||||
value_is="$(get_current_value "$attribute" "$value_should")"
|
value_is="$(get_current_value "$attribute" "$value_should")"
|
||||||
|
|
||||||
# change 0xxx format to xxx format => same as stat returns
|
# format mode in four digits => same as stat returns
|
||||||
if [ "$attribute" = mode ]; then
|
if [ "$attribute" = mode ]; then
|
||||||
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
|
value_should=$(printf '%04u' "${value_should}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
|
if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
|
||||||
|
|
|
@ -31,10 +31,10 @@ fallback() {
|
||||||
gid=$(echo "$ls_line" | awk '{ print $4 }')
|
gid=$(echo "$ls_line" | awk '{ print $4 }')
|
||||||
|
|
||||||
owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
|
owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
|
||||||
group=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
|
group=$(awk -F: -v gid="$gid" '$3 == gid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
|
||||||
|
|
||||||
mode_text=$(echo "$ls_line" | awk '{ print $1 }')
|
mode_text=$(echo "$ls_line" | awk '{ print $1 }')
|
||||||
mode=$(echo "$mode_text" | awk '{ k=0; for (i=0; i<=8; i++) k += ((substr($1, i+2, 1) ~ /[rwx]/) * 2^(8-i)); printf("%0o", k) }')
|
mode=$(echo "$mode_text" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')
|
||||||
|
|
||||||
size=$(echo "$ls_line" | awk '{ print $5 }')
|
size=$(echo "$ls_line" | awk '{ print $5 }')
|
||||||
links=$(echo "$ls_line" | awk '{ print $2 }')
|
links=$(echo "$ls_line" | awk '{ print $2 }')
|
||||||
|
@ -53,64 +53,32 @@ fallback() {
|
||||||
[ -e "$destination" ] || exit 0
|
[ -e "$destination" ] || exit 0
|
||||||
|
|
||||||
|
|
||||||
if ! command -v stat >/dev/null
|
command -v stat >/dev/null 2>&1 || {
|
||||||
then
|
|
||||||
fallback
|
fallback
|
||||||
exit
|
exit
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
|
||||||
case $("$__explorer/os")
|
case $("$__explorer/os")
|
||||||
in
|
in
|
||||||
freebsd|netbsd|openbsd|macosx)
|
freebsd|netbsd|openbsd|macosx)
|
||||||
stat -f "type: %HT
|
stat -f 'type: %HT
|
||||||
owner: %Du %Su
|
owner: %Du %Su
|
||||||
group: %Dg %Sg
|
group: %Dg %Sg
|
||||||
mode: %Lp %Sp
|
mode: %Mp%03Lp %Sp
|
||||||
size: %Dz
|
size: %Dz
|
||||||
links: %Dl
|
links: %Dl
|
||||||
" "$destination" | awk '/^type/ { print tolower($0); next } { print }'
|
' "$destination" | awk '/^type/ { print tolower($0); next } { print }'
|
||||||
;;
|
;;
|
||||||
solaris)
|
|
||||||
ls1="$( ls -ld "$destination" )"
|
|
||||||
ls2="$( ls -ldn "$destination" )"
|
|
||||||
|
|
||||||
if [ -f "$__object/parameter/mode" ]
|
|
||||||
then mode_should="$( cat "$__object/parameter/mode" )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# yes, it is ugly hack, but if you know better way...
|
|
||||||
if [ -z "$( find "$destination" -perm "$mode_should" )" ]
|
|
||||||
then octets=888
|
|
||||||
else octets="$( echo "$mode_should" | sed 's/^0//' )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$( echo "$ls1" | cut -c1-1 )" in
|
|
||||||
-) echo 'type: regular file' ;;
|
|
||||||
d) echo 'type: directory' ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "owner: $( echo "$ls2" \
|
|
||||||
| awk '{print $3}' ) $( echo "$ls1" \
|
|
||||||
| awk '{print $3}' )"
|
|
||||||
|
|
||||||
echo "group: $( echo "$ls2" \
|
|
||||||
| awk '{print $4}' ) $( echo "$ls1" \
|
|
||||||
| awk '{print $4}' )"
|
|
||||||
|
|
||||||
echo "mode: $octets $( echo "$ls1" | awk '{print $1}' )"
|
|
||||||
echo "size: $( echo "$ls1" | awk '{print $5}' )"
|
|
||||||
echo "links: $( echo "$ls1" | awk '{print $2}' )"
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
|
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
|
||||||
# NOTE: BusyBox's stat might not support the "-c" option, in which case
|
# NOTE: BusyBox's stat might not support the "-c" option, in which case
|
||||||
# we fall through to the shell fallback.
|
# we fall through to the shell fallback.
|
||||||
stat -c "type: %F
|
stat -c 'type: %F
|
||||||
owner: %u %U
|
owner: %u %U
|
||||||
group: %g %G
|
group: %g %G
|
||||||
mode: %a %A
|
mode: %04a %A
|
||||||
size: %s
|
size: %s
|
||||||
links: %h" "$destination" 2>/dev/null || fallback
|
links: %h' "$destination" 2>/dev/null || fallback
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -68,9 +68,9 @@ case "$state_should" in
|
||||||
if [ -f "$__object/parameter/$attribute" ]; then
|
if [ -f "$__object/parameter/$attribute" ]; then
|
||||||
value_should="$(cat "$__object/parameter/$attribute")"
|
value_should="$(cat "$__object/parameter/$attribute")"
|
||||||
|
|
||||||
# change 0xxx format to xxx format => same as stat returns
|
# format mode in four digits => same as stat returns
|
||||||
if [ "$attribute" = mode ]; then
|
if [ "$attribute" = mode ]; then
|
||||||
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
|
value_should=$(printf '%04u' "${value_should}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
value_is="$(get_current_value "$attribute" "$value_should")"
|
value_is="$(get_current_value "$attribute" "$value_should")"
|
||||||
|
|
Loading…
Reference in a new issue