mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Changed password script to work with multiple NICs.
This commit is contained in:
parent
9ec4911285
commit
25cd4a5768
@ -8,39 +8,72 @@
|
||||
# Modify this line to specify the user (default is root)
|
||||
user=root
|
||||
|
||||
# Add your DHCP lease file here
|
||||
DHCP_FILES="/var/lib/dhclient/dhclient-eth0.leases /var/lib/dhcp3/dhclient.eth0.leases"
|
||||
# Add your DHCP lease folders here
|
||||
DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/*"
|
||||
password_received=0
|
||||
|
||||
for DHCP_FILE in $DHCP_FILES
|
||||
for DHCP_FILE in $DHCP_FOLDERS
|
||||
do
|
||||
if [ -f $DHCP_FILE ]
|
||||
then
|
||||
DOMR_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;')
|
||||
break;
|
||||
PASSWORD_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;')
|
||||
|
||||
if [ -n $PASSWORD_SERVER_IP ]
|
||||
then
|
||||
logger -t "cloud" "Sending request to password server at $PASSWORD_SERVER_IP"
|
||||
password=$(wget -t 3 -T 20 -O - --header "DomU_Request: send_my_password" $PASSWORD_SERVER_IP:8080)
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
logger -t "cloud" "Got a password from server at $PASSWORD_SERVER_IP"
|
||||
password_received=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
password=$(wget -t 3 -T 20 -O - --header "DomU_Request: send_my_password" $DOMR_IP:8080)
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
if [ "$password_received" == "0" ]
|
||||
then
|
||||
logger -t "cloud" "Failed to get password from server"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
password=$(echo $password | tr -d '\r')
|
||||
|
||||
if [ -n "$password" ] && [ "$password" != "bad_request" ] && [ "$password" != "saved_password" ]
|
||||
then
|
||||
echo $password | passwd --stdin $user
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
usermod -p `mkpasswd $password 42` $user
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" $DOMR_IP:8080
|
||||
fi
|
||||
case $password in
|
||||
|
||||
exit 0
|
||||
"") logger -t "cloud" "Password server did not have any password for the VM."
|
||||
exit 0
|
||||
;;
|
||||
|
||||
"bad_request") logger -t "cloud" "VM sent an invalid request to password server."
|
||||
exit 1
|
||||
;;
|
||||
|
||||
"saved_password") logger -t "cloud" "VM has already saved a password from the password server."
|
||||
exit 0
|
||||
;;
|
||||
|
||||
*) logger -t "cloud" "Changing password for the VM..."
|
||||
echo $password | passwd --stdin $user
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
usermod -p `mkpasswd $password 42` $user
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
logger -t "cloud" "Failed to change password for user $user"
|
||||
exit 1
|
||||
else
|
||||
logger -t "cloud" "Successfully changed password for user $user"
|
||||
fi
|
||||
fi
|
||||
|
||||
logger -t "cloud" "Sending acknowledgment to password server at $PASSWORD_SERVER_IP"
|
||||
wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" $PASSWORD_SERVER_IP:8080
|
||||
exit 0
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user