ovirt-node 2.2.0 release
[ovirt-node.git] / scripts / ovirt-config-password
blob6405f7ca958c55001b9c2123063a63d03c99c502
1 #!/bin/bash
3 # Set the root password and others
4 # Source functions library
5 . /etc/init.d/functions
6 . /usr/libexec/ovirt-functions
8 trap '__st=$?; stop_log; exit $__st' 0
9 trap 'exit $?' 1 2 13 15
11 warn() { printf '%s\n' "$*" >&2; }
13 if ! is_local_storage_configured; then
14 warn "Local storage must be configured prior to setting the administrator password."
15 exit 99
18 # Usage: set_sasl_password USER
19 # Prompt(twice) for a password for the specified USER.
20 # If they match, set that user's system password,
21 # and add USER to the SASL list for libvirt.
22 function set_sasl_password {
23 user=$1
25 printf "\nNode SASL User ($user):\n"
26 saslpasswd2 -a libvirt "$user"
27 return 0
30 # Prompts the user for a single username, password combo
31 function prompt_sasl_user {
32 while true; do
33 printf "\nPlease enter a new username (hit return to skip) "
34 read -e
35 test -z "$REPLY" && return 1
36 set_sasl_password "$REPLY"
37 done
40 set_password () {
41 printf "\n\n Password Configuration\n\n"
42 local user=${1-root}
44 # prompt user
45 # Set the password for the root user first
46 printf "\nSystem Administrator ($user):\n"
47 unmount_config /etc/shadow
48 passwd $user
49 ovirt_store_config /etc/shadow
52 toggle_ssh_access ()
54 local permit=$1
56 augtool <<EOF
57 set /files/etc/ssh/sshd_config/PasswordAuthentication ${permit}
58 EOF
59 ovirt_store_config /etc/ssh/sshd_config
60 service sshd reload
63 toggle_ssh () {
64 printf "\nSSH password authentication\n\n"
66 if ask_yes_or_no "Enable SSH password authentication ([Y]es/[N]o)?"; then
67 toggle_ssh_access yes
68 else
69 toggle_ssh_access no
73 PASSWORD="Set root password"
74 ADMIN_PASSWORD="Set admin user password"
75 SSH="Toggle SSH password authentication"
76 QUIT="Quit and Return To Menu"
78 if [[ "$1" == "AUTO" ]]; then
79 if [ -n "${OVIRT_SSH_PWAUTH}" ]; then
80 toggle_ssh_access $OVIRT_SSH_PWAUTH
82 else
83 while true; do
84 state="disabled"
85 /usr/bin/augtool get /files/etc/ssh/sshd_config/PasswordAuthentication|grep -q yes$
86 if [ $? == 0 ]; then
87 state="enabled"
89 printf "\nSSH password authentication is currently ${state}.\n\n"
91 PS3="Please select an option: "
92 select option in "$PASSWORD" "$ADMIN_PASSWORD" "$SSH" "$QUIT"
94 case $option in
95 $PASSWORD) set_password; break;;
96 $ADMIN_PASSWORD) set_password admin; break;;
97 $SSH) toggle_ssh; break;;
98 $QUIT) exit;;
99 esac
100 done
102 printf "\n"
103 done