suid.sh 743 B

123456789101112131415161718192021222324252627282930313233343536
  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. ## remove _PSID from the arguments
  21. _ARGS=${@//$_PSID}
  22. eval $_ARGS
  23. exit $?