tomb dig: useless sudo and chown

Depending script invokation, behavior is not exactly similar.
Assuming that if SUDO_USER is set, the _sudo invokation can be dropped (EUID=0).
In the other case, user has created file, owner is already good, don't call chown.

Method 1:
$ sudo tomb dig foo.tomb -s 10 -v

Method 2:
$ tomb dig foo.tomb -s 10 -v
... ask user password to gain superuser privileges
...
Sorry, user <username> is not allowed to execute '/bin/chown <uid>:<gid> foo.tomb' as root on <hostname>.

Signed-off-by: Matthieu Crapet <mcrapet@gmail.com>
This commit is contained in:
Matthieu Crapet 2021-01-01 21:02:54 +01:00
parent 859a5c7783
commit 99f10bf215

2
tomb
View File

@ -1840,7 +1840,7 @@ dig_tomb() {
_failure "Operation aborted."
}
# Ensure that file permissions are safe even if interrupted
_sudo chown ${_UID}:${_GID} "$1"
[[ -n $SUDO_USER ]] && chown ${_UID}:${_GID} "$1"
chmod 0600 $1
_verbose "Data dump using ::1:: from /dev/urandom" ${DD[1]}
${=DD} if=/dev/urandom bs=1048576 count=$tombsize of=$1