3 # Copyright (c) 2000,2004 Matthias S. Benkmann <article AT winterdrache DOT de>
4 # You may do everything with this code except misrepresent its origin.
5 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
7 # Copyright (C) 2014 Steve Youngs <steve@steveyoungs.com>
8 # Rewrite, make it a lot more robost and handle most (all?)
9 # possibilities of chown'ing. --SY.
13 for p in $(type -ap chown) ; do
14 if [ ! $p -ef $0 ]; then
20 if [ ! -n "$DAISY_CHAIN" ]; then
21 echo 1>&2 '***' Cannot find real ${0##*/} command
25 if [ $UID == 0 ]; then
26 echo 1>&2 '***' $(dirname $0) should not be in root\'s \$PATH
27 echo 1>&2 '***' call '"'$DAISY_CHAIN $@'"' directly.
31 # An ordinary user cannot change the UID of a file if that UID is
32 # not their own, but chown can also be used to change the GID of a
33 # file as well so it is feasible that an ordinary user could use
36 # preseve the command line as we're gonna mess with it.
38 # strip off the options so that $1 becomes the UID:GID arg
46 # Split USER:GROUP or USER.GROUP into USER and GROUP
53 # Catch the case where USER is somebody else.
54 if [ -n "$usr" ]; then
55 printf '%d' $usr &>/dev/null
57 if [ $usr -ne $(id -u) ]; then
61 if [ "$usr" != "$(id -un)" ]; then
67 # Catch the case where GROUP isn't in our groups.
68 if [ -n "$grp" -a $report -eq 0 ]; then
70 printf '%d' $grp &>/dev/null
76 for g in ${GRP_LIST}; do
77 if [ "$grp" == "$g" ]; then
83 if [ -z "$GRP_CHAIN" ]; then
88 if [ $report -eq 1 ]; then
89 echo 1>&2 '***' chown ${cmdline}
91 exec $DAISY_CHAIN ${cmdline} || exit $?