]> gitweb.morketsmerke.org Git - immudex.git/commitdiff
Dostosowanie narzędzia immudex-crypt do pracy z poleceniem sudo - Ustawienie użytkown...
authorxf0r3m <jakubstasinski@protonmail.com>
Thu, 4 Jan 2024 17:58:31 +0000 (18:58 +0100)
committerxf0r3m <jakubstasinski@protonmail.com>
Thu, 4 Jan 2024 17:58:31 +0000 (18:58 +0100)
tools/sbin/immudex-crypt

index 05656eff0e5af1a5c5e7dc8fe612739805f12051..a9f0ac2f48e1abec3c91c65cfc1a5b8bea4814f5 100755 (executable)
@@ -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 <disk partition>";
-  echo "$ immudex-crypt open <crypt_LUKS device>";
-  echo "$ immudex-crypt close immudex-crypt[0-9] | ic[0-9] | [0-9]";
+  echo "# immudex-crypt list";
+  echo "# immudex-crypt create <disk partition>";
+  echo "# immudex-crypt open <crypt_LUKS device>";
+  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;