askpass 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. #Barry Kauler 2011, GPL3 (/usr/share/doc/legal)
  3. #specified in /etc/sudoers or /etc/sudo.conf, gui-helper for sudo. (path compiled-in to my sudo PET)
  4. #110513 display name of app that is requesting to run.
  5. #120201 rodin.s: internationalized.
  6. export TEXTDOMAIN=askpass
  7. export OUTPUT_CHARSET=UTF-8
  8. PSALL="`ps`"
  9. CALLEDAPP="`echo "$PSALL" | grep -o ' sudo \-A .*' | tr -s ' ' | cut -f 4 -d ' '`"
  10. if [ "$CALLEDAPP" ];then
  11. INSERTMSG=" <text><label>$(gettext 'This application wants to run:')</label></text>
  12. <text><label>${CALLEDAPP}</label></text>
  13. <text><label>$(gettext 'The administrator password is required:')</label></text>
  14. "
  15. else
  16. INSERTMSG="<text><label>$(gettext 'Please enter the administrator password required to run this application:')</label></text>"
  17. fi
  18. if [ $DISPLAY ];then
  19. export ASKDIALOG="
  20. <window title=\"AskPass\" decorated=\"false\" window_position=\"1\" skip_taskbar_hint=\"true\">
  21. <vbox>
  22. <frame>
  23. ${INSERTMSG}
  24. <entry visible_char=\"x\" visibility=\"false\" width_chars=\"25\" activates_default=\"true\">
  25. <variable>ADMINPASSWORD</variable>
  26. </entry>
  27. <hbox>
  28. <button use-stock=\"true\" label=\"gtk-ok\" can-default=\"true\" has-default=\"true\"></button>
  29. </hbox>
  30. </frame>
  31. </vbox>
  32. </window>
  33. "
  34. RETVAL="`gtkdialog --program=ASKDIALOG 2>/dev/null | grep '^ADMINPASSWORD='`"
  35. #eval "$RETVAL"
  36. ADMINPASSWORD="`echo "$RETVAL" | cut -f2- -d '"' | rev | cut -f2- -d '"' | rev`"
  37. else
  38. echo >/dev/console
  39. echo -n "$(gettext 'Type admin password required to run this app:') " >/dev/console
  40. read -t 30 ADMINPASSWORD
  41. [ "$ADMINPASSWORD" = "" ] && echo '...failed' >/dev/console
  42. fi
  43. #echo "$RETVAL"
  44. echo "$ADMINPASSWORD" #return password to sudo.
  45. ###END###