ask_password.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. #********************************************************************************#
  3. #* *#
  4. #* Copyright (c) 2005 Instituto Nokia de Tecnologia - INdT - Manaus Brazil *#
  5. #* *#
  6. #* This program is free software; you can redistribute it and#or modify *#
  7. #* it under the terms of the GNU General Public License as published by *#
  8. #* the Free Software Foundation; either version 2 of the License, or *#
  9. #* (at your option) any later version. *#
  10. #* *#
  11. #* This program is distributed in the hope that it will be useful, *#
  12. #* but WITHOUT ANY WARRANTY; without even the implied warranty of *#
  13. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See *#
  14. #* the GNU General Public License for more details. *#
  15. #* *#
  16. #* You should have received a copy of the GNU General Public License *#
  17. #* along with this program; if not, write to the Free Software *#
  18. #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *#
  19. #* *#
  20. #********************************************************************************#
  21. #********************************************************************************#
  22. #* *#
  23. #* File: ask_password.sh *#
  24. #* *#
  25. #* Description: get the password from userspace. It's called when unlocking *#
  26. #* the card or assigning a new password to an unlocked card. *#
  27. #* Return - zero on success *#
  28. #* - non zero on failure. return value from commands ($RC) *#
  29. #* Total Tests: 1 *#
  30. #* *#
  31. #* Author: Anderson Briglia <anderson.briglia@indt.org.br> *#
  32. #* Anderson Lizardo <anderson.lizardo@indt.org.br> *#
  33. #* Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br> *#
  34. #* *#
  35. #* *#
  36. #* *#
  37. #********************************************************************************#
  38. ask_password()
  39. {
  40. export TST_TOTAL=1 # Total number of test cases in this file.
  41. # Set up LTPTMP (temporary directory used by the tests).
  42. LTPTMP=${TMP} # Temporary directory to create files, etc.
  43. export TCID="ask_password" # Test case identifier
  44. export TST_COUNT=0 # Set up is initialized as test 0
  45. RC=0 # Exit values of system commands used
  46. USER_CONSOLE=/dev/ttyS0
  47. {
  48. echo "=== Unlock Protected MMC ==="
  49. while [ -z "$passwd" ]; do
  50. read -s -p "MMC password: " passwd; echo
  51. done
  52. if ! keyctl instantiate $1 "$passwd" $2 >/dev/null 2>&1; then
  53. echo "*** Wrong password! The card was not unlocked."
  54. exit 1
  55. fi
  56. echo "Password accepted."
  57. exit 0
  58. } >$USER_CONSOLE 2>&1 < $USER_CONSOLE
  59. }
  60. ask_password || exit $RC