suid.sh 807 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. SHELL=/bin/bash
  3. if [[ $EUID -ne 0 ]]; then echo 'root only'; exit 1; fi
  4. ## parent process id
  5. #_PPID=$PPID
  6. ## grandparent process id (process that called sudo that called us)
  7. #_GPPID=$(ps -p$PPID -o ppid=)
  8. ## grandparent command
  9. #_GPCMD=$(ps -f -p$_GPPID)
  10. ## check if called by admin.sh
  11. #if [[ ! $_GPCMD =~ 'admin/admin.sh' ]]; then echo 'bad granny'; exit 1; fi
  12. ## get lighttpd session id
  13. #_LSID=$(ps -C lighttpd -o sid=)
  14. ## parent session id
  15. _PSID=${@: -1}
  16. ## our session id
  17. #_SID=$(ps -p$$ -o sid=)
  18. ## check if we belong to group/session of lighty and admin.sh
  19. #if [ $_LSID != $_PSID -o $_SID != $_LSID ]; then echo 'bad session'; exit 1; fi
  20. #if [[ $_LSID != $_PSID ]]; then echo 'bad session'; exit 1; fi
  21. ## remove _PSID from the arguments
  22. _ARGS=${@//$_PSID}
  23. eval $_ARGS
  24. exit $?