From 49e9feca74a4efce86ac4f6f6bd223f5d0719cc3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 19 Jul 2021 10:18:12 +0300 Subject: [PATCH] kiss: as_root changes 1. Removed strict list of KISS_SU values. Anything that uses sudo-like arguments is now supported. 2. Calling a nested package manager instance is now avoided when unneeded. 3. Removed hardcoded root assumptions (and renamed as_root to as_user). The check is now simply (current_user == owner of path). --- kiss | 87 ++++++++++++++++++++---------------------------------------- 1 file changed, 29 insertions(+), 58 deletions(-) diff --git a/kiss b/kiss index 892f237..90993e9 100755 --- a/kiss +++ b/kiss @@ -105,40 +105,32 @@ fnr() { esac done } -as_root() { - case $uid/${user:=root}/${cmd_su##*/} in - 0/root/*) - "$@" - ;; +am_owner() { + # Figure out if we need to change users to operate on + # a given file or directory. + inf=$(ls -ld "$1") || + die "Failed to file information for '$1'" - */doas|*/sudo|*/ssu) - log "Using '$cmd_su' (to become $user)" + # Split the ls output into fields. + # Intentional, globbing disabled. + # shellcheck disable=2046,2086 + set -- "$1" $inf - "$cmd_su" -u "$user" -- "$@" - ;; + user=$4 - */su) - log "Using 'su' (to become $user) -Note: su will ask for password every time. - Use doas, sudo or ssu for more control." + uid=$(id -u "$user") || + die "Invalid user '$user' for '$1'" - "$cmd_su" -c "$* <&3" "$user" 3<&0 /dev/null 2>&1 || user=root + case ${cmd_su##*/} in + su) "$cmd_su" -c "$* <&3" "$user" 3<&0