remove_password.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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: remove_password.sh *#
  24. #* *#
  25. #* Description: used to remove the password from a card previously unlocked. *#
  26. #* *#
  27. #* *#
  28. #* Total Tests: 1 *#
  29. #* *#
  30. #* Author: Anderson Briglia <anderson.briglia@indt.org.br> *#
  31. #* Anderson Lizardo <anderson.lizardo@indt.org.br> *#
  32. #* Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br> *#
  33. #* *#
  34. #* *#
  35. #* *#
  36. #********************************************************************************#
  37. remove_password()
  38. {
  39. export TST_TOTAL=1 # Total number of test cases in this file.
  40. # Set up LTPTMP (temporary directory used by the tests).
  41. LTPTMP=${TMP} # Temporary directory to create files, etc.
  42. export TCID="remove_password" # Test case identifier
  43. export TST_COUNT=0 # Set up is initialized as test 0
  44. RC=0 # Exit values of system commands used
  45. echo "=== Remove MMC Password ==="
  46. keyid=$(keyctl request mmc "mmc:key")
  47. if [ -z "$keyid" ]; then
  48. echo "*** No protected and unlocked MMC was found. The password cannot be removed."
  49. exit 1
  50. fi
  51. echo remove > /sys/bus/mmc/devices/mmc0\:*/lockable || \
  52. { echo "*** Password reset failed."; exit 1 ;}
  53. # Clear session keyring
  54. # FIXME: It assumes we have only the MMC key there
  55. keyctl clear -3
  56. echo "Password removed."
  57. }
  58. remove_password || exit $RC