• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#* 										*#
24#* File: force_erase.sh 							*#
25#* 										*#
26#* Description: used to force-erase a card, usually when the user has forgot	*#
27#* the password and wants to unlock the card. NOTE: all the card's contents are *#
28#* lost when using this option! It only works for _locked_ cards.		*#
29#*										*#
30#* Total Tests: 1 								*#
31#* 										*#
32#* Author: Anderson Briglia <anderson.briglia@indt.org.br> 			*#
33#* Anderson Lizardo <anderson.lizardo@indt.org.br> 				*#
34#* Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br> 				*#
35#* 										*#
36#* 										*#
37#* 										*#
38#********************************************************************************#
39force_erase()
40{
41	export TST_TOTAL=1  # Total number of test cases in this file.
42	# Set up LTPTMP (temporary directory used by the tests).
43	LTPTMP=${TMP}       # Temporary directory to create files, etc.
44	export TCID="force_erase" # Test case identifier
45	export TST_COUNT=0  # Set up is initialized as test 0
46	RC=0                # Exit values of system commands used
47
48	echo "=== Erase MMC Password (AND its contents!) ==="
49	if grep -q "unlocked" /sys/bus/mmc/devices/mmc0\:*/lockable; then
50		echo -n "*** No locked MMC card was found. You can only use the forced "
51		echo "erase operation on locked cards."
52		exit 1
53	fi
54
55	while [ -z "$yn" ]; do
56		read -p "WARNING: all card contents will be lost! Continue? (y/n) " yn
57		case "$yn" in
58			y|Y) break ;;
59			n|N) exit 0 ;;
60			*) yn=""
61		esac
62	done
63
64	echo "Erasing card. This may take some time, wait..."
65	echo erase > /sys/bus/mmc/devices/mmc0\:*/lockable || \
66	{ echo "*** Error erasing card" >&2; exit 1 ;}
67
68	# Clear session keyring
69	# FIXME: It assumes we have only the MMC key there
70	keyctl clear -3
71
72	echo "Card unlocked and erased."
73}
74
75force_erase || exit $RC
76