Debian Codegraph @

usr/share/rear/skel/default/bin/login

raw symbols SCIP
1 #!/bin/bash
2 #
3 # This is a minimal version of login(1). It will be called by agetty for console and serial terminal logins.
4 #
5
6 function authenticate_user() {
7 # Authenticates the (only) user if a terminal login password is configured.
8 # Returns if successful or if no password is configured, exits after some failed attempts.
9 # The login name is always ignored as the recovery system knows only one user.
10 if [[ -f /.TTY_ROOT_PASSWORD ]]; then
11 trap '' SIGINT SIGQUIT SIGTSTP
12
13 # Read the configured hash signature from its file
14 read -r TTY_ROOT_PASSWORD </.TTY_ROOT_PASSWORD
15 # Extract hash algorithm and salt from the configured hash signature
16 IFS='$' read -r _ method salt _ </.TTY_ROOT_PASSWORD
17
18 for _ in 1 2 3; do
19 read -r -s -p "Password: " password 2>&1
20 echo ""
21
22 # Compute signature of the password to verify
23 password_signature="$(openssl passwd -"$method" -salt "$salt" "$password")"
24
25 if [[ "$password_signature" == "$TTY_ROOT_PASSWORD" ]]; then # Password matches: Success!
26 trap - SIGINT SIGQUIT SIGTSTP
27 return
28 fi
29
30 sleep 5
31 echo -e "\nLogin incorrect"
32 read -r -p "$(hostname) login: " _ 2>&1 # Fake a login prompt although the user name is not used.
33 done
34
35 exit 1 # Exit after several unsuccessful attempts
36 fi
37 }
38
39 # Authenticate the (only) user if a password is configured.
40 authenticate_user
41
42 # setup standard environment for root user
43 # ATM root is the only user who can logon at the rescue system
44 export HOME=/root
45 cd $HOME
46 exec -a -bash /bin/bash