Home | History | Annotate | Download | only in mmc_security
      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: assign_password.sh 							*#
     25 #* 										*#
     26 #* Description: Get password from user space and save at MMC			*#
     27 #* 										*#
     28 #* 										*#
     29 #* Total Tests: 1 								*#
     30 #* 										*#
     31 #* Author: Anderson Briglia <anderson.briglia (at] indt.org.br> 			*#
     32 #* Anderson Lizardo <anderson.lizardo (at] indt.org.br> 				*#
     33 #* Carlos Eduardo Aguiar <carlos.aguiar (at] indt.org.br> 				*#
     34 #* 										*#
     35 #* 										*#
     36 #* 										*#
     37 #********************************************************************************#
     38 assign_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="assign_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 
     47 	USER_CONSOLE=/dev/ttyS0
     48 	{
     49 	echo "=== Assign password to MMC ==="
     50 	while [ -z "$newpasswd" ]; do
     51 		read -s -p "New MMC password: " newpasswd; echo
     52 	done
     53 	while [ -z "$newpasswd2" ]; do
     54 		read -s -p "Retype MMC password: " newpasswd2; echo
     55 	done
     56 	if [ "$newpasswd" != "$newpasswd2" ]; then
     57 		echo "*** Passwords do not match."
     58 		exit 1
     59 	fi
     60 	if ! keyctl instantiate $1 "$newpasswd" $2 >/dev/null 2>&1; then
     61 		echo "*** Error while assigning new password"
     62 		exit 1
     63 	fi
     64 	echo "Password assigned."
     65 
     66 	exit 0
     67 	} >$USER_CONSOLE 2>&1 < $USER_CONSOLE
     68 }
     69 
     70 assign_password || exit $RC
     71