3 # Blackbox tests for smbpasswd
5 # Copyright (c) 2015-2016 Andreas Schneider <asn@samba.org>
10 Usage: test_smbpasswd.sh SERVER USERNAME PASSWORD
21 incdir=$(dirname $0)/../../../testprogs/blackbox
26 samba_bindir="$BINDIR"
27 samba_srcdir="$SRCDIR"
29 samba_texpect="$samba_bindir/texpect"
30 samba_smbpasswd="$samba_bindir/smbpasswd"
32 samba_test_user="alice_smbpasswd"
33 samba_test_user_pwd="Secret007"
34 samba_test_user_new_pwd="Secret008"
36 create_local_smb_user()
41 tmpfile=$PREFIX/smbpasswd_create_user_script
43 expect New SMB password:
45 expect Retype new SMB password:
49 cmd='UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $samba_texpect $tmpfile $samba_smbpasswd -c $SMB_CONF_PATH -a $user 2>&1'
56 if [ $ret -ne 0 ]; then
57 echo "Failed to create smb user $user"
63 if [ $ret -ne 0 ]; then
64 echo "Failed to create smb user $user"
69 delete_local_smb_user()
73 # This also deletes the unix account!
74 UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $samba_smbpasswd -c $SMB_CONF_PATH -x $user
76 if [ $ret -ne 0 ]; then
77 echo "Failed to delete smb user $user"
88 user_id=$(id -u $user)
90 tmpfile=$PREFIX/smbpasswd_change_password_script
92 expect Old SMB password:
94 expect New SMB password:
96 expect Retype new SMB password:
100 cmd='UID_WRAPPER_INITIAL_RUID=$user_id UID_WRAPPER_INITIAL_EUID=$user_id $samba_texpect $tmpfile $samba_smbpasswd -c $SMB_CONF_PATH -r $SERVER 2>&1'
105 if [ $ret -ne 0 ]; then
106 echo "Failed to change user password $user"
110 prompt="Password changed for user $user"
111 echo "$out" | grep "$prompt" >/dev/null 2>&1
113 if [ $ret -ne 0 ]; then
114 echo "Failed to change password for user $user"
120 testit "Create user $samba_test_user" \
121 create_local_smb_user $samba_test_user $samba_test_user_pwd \
122 || failed=$(expr $failed + 1)
124 testit "Change user password" \
125 test_smbpasswd $samba_test_user $samba_test_user_pwd $samba_test_user_new_pwd \
126 || failed=$(expr $failed + 1)
128 testit "Delete user $samba_test_user" \
129 delete_local_smb_user $samba_test_user \
130 || failed=$(expr $failed + 1)