From: xf0r3m Date: Thu, 4 Jan 2024 17:58:31 +0000 (+0100) Subject: Dostosowanie narzędzia immudex-crypt do pracy z poleceniem sudo - Ustawienie użytkown... X-Git-Url: https://gitweb.morketsmerke.org/?a=commitdiff_plain;h=379611296a00e6caf7eaa34be48f6a686f7186e1;p=immudex.git Dostosowanie narzędzia immudex-crypt do pracy z poleceniem sudo - Ustawienie użytkowników cz. 3 --- diff --git a/tools/sbin/immudex-crypt b/tools/sbin/immudex-crypt index 05656ef..a9f0ac2 100755 --- a/tools/sbin/immudex-crypt +++ b/tools/sbin/immudex-crypt @@ -4,16 +4,17 @@ function help() { echo "immudex-crypt - script used for listing, open and close crypt_LUKS ppartitions"; echo "@ 2023 morketsmerke.org"; + echo "Superuser (root) privileges are required."; echo "Options:"; echo " list - displaing list of opened and available crypt_LUKS devices"; echo " create - formatting device for crypt_LUKS"; echo " open - opening crypt_LUKS device, after this device is ready to mount"; echo " close - unmount and closing crypt_LUKS devices"; echo "Using:"; - echo "$ immudex-crypt list"; - echo "$ immudex-crypt create "; - echo "$ immudex-crypt open "; - echo "$ immudex-crypt close immudex-crypt[0-9] | ic[0-9] | [0-9]"; + echo "# immudex-crypt list"; + echo "# immudex-crypt create "; + echo "# immudex-crypt open "; + echo "# immudex-crypt close immudex-crypt[0-9] | ic[0-9] | [0-9]"; } function list() { @@ -129,8 +130,8 @@ function set_ownership(){ else mountPoint=$(list | grep "$USER" | grep "$1" | awk '{printf $3}') owner=$(stat -c %u $mountPoint); - if [ $owner -eq $UID ]; then - if id $USER | grep -q $UID; then + if [ $owner -eq $RUID ]; then + if id $USER | grep -q $RUID; then echo "User $USER is already owner of $mountPoint"; fi else @@ -141,6 +142,18 @@ function set_ownership(){ if [ "$1" ]; then + if [ $UID -ne 0 ]; then + echo "Permission denied!"; + help; + exit 1; + fi + + immudexCryptPID=$$; + parentProcessPID=$((immudexCryptPID - 1)); + #immudex-crypt RUID is EUID of sudo, which spawning immudex-crypt + export RUID=$(grep '^Uid:' /proc/${parentProcessPID}/status | awk '{printf $2}'); + export USER=$(grep "$RUID" /etc/passwd | cut -d ":" -f1); + case $1 in "list") list;; "open") if [ "$2" ]; then open $2;