pdb: add a blackbox test for setting password with hash
[nivanova/samba-autobuild/.git] / testprogs / blackbox / test_pdbtest.sh
1 #!/bin/sh
2 # Blackbox tests for pdbtest
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2012 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 2 ]; then
7 cat <<EOF
8 Usage: test_pdbtest.sh SERVER PREFIX USER SMBCLIENT SMB_CONF
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 PREFIX=$2
15 USER=$3
16 smbclient=$4
17 SMB_CONF=$5
18 shift 5
19 failed=0
20
21 samba4bindir="$BINDIR"
22 pdbtest="$samba4bindir/pdbtest"
23 pdbedit="$samba4bindir/pdbedit"
24 net="$samba4bindir/net"
25 smbpasswd="$samba4bindir/smbpasswd"
26 texpect="$samba4bindir/texpect"
27
28 . `dirname $0`/subunit.sh
29
30 test_smbclient() {
31         name="$1"
32         cmd="$2"
33         shift
34         shift
35         echo "test: $name"
36         $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" $@
37         status=$?
38         if [ x$status = x0 ]; then
39                 echo "success: $name"
40         else
41                 echo "failure: $name"
42         fi
43         return $status
44 }
45
46 UID_WRAPPER_ROOT=1
47 export UID_WRAPPER_ROOT
48
49 testit "pdbtest" $VALGRIND $BINDIR/pdbtest -u $USER $@ || failed=`expr $failed + 1`
50
51 NEWUSERPASS=testPaSS@01%
52
53 echo "set password with pdbedit"
54 cat > ./tmpsmbpasswdscript <<EOF
55 expect new password:
56 send ${NEWUSERPASS}\n
57 expect retype new password:
58 send ${NEWUSERPASS}\n
59 EOF
60
61 testit "create user with pdbedit" $texpect ./tmpsmbpasswdscript $VALGRIND $pdbedit -a $USER --account-desc="pdbedit-test-user" $@ || failed=`expr $failed + 1`
62 USERPASS=$NEWUSERPASS
63
64 test_smbclient "Test login with user (ntlm)" 'ls' -k no -U$USER%$NEWUSERPASS $@ || failed=`expr $failed + 1`
65
66 testit "modify user"  $VALGRIND $pdbedit --modify $USER --drive="D:" $@ || failed=`expr $failed + 1`
67
68 test_smbclient "Test login with user (ntlm)" 'ls' -k no -U$USER%$NEWUSERPASS $@|| failed=`expr $failed + 1`
69
70 NEWUSERPASS=testPaSS@02%
71
72 echo "set password with smbpasswd"
73 cat > ./tmpsmbpasswdscript <<EOF
74 expect New SMB password:
75 send ${NEWUSERPASS}\n
76 expect Retype new SMB password:
77 send ${NEWUSERPASS}\n
78 EOF
79
80 testit "set user password with smbpasswd" $texpect ./tmpsmbpasswdscript $smbpasswd -L $USER -c $SMB_CONF || failed=`expr $failed + 1`
81 USERPASS=$NEWUSERPASS
82
83 test_smbclient "Test login with user (ntlm)" 'ls' -k no -U$USER%$NEWUSERPASS $@|| failed=`expr $failed + 1`
84
85 testit "modify user - disabled"  $VALGRIND $net sam set disabled $USER yes $@ || failed=`expr $failed + 1`
86
87 testit_expect_failure  "Test login with disabled suer" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -k no -U$USER@%$USERPASS && failed=`expr $failed + 1`
88
89 testit "modify user - enabled"  $VALGRIND $net sam set disabled $USER no $@ || failed=`expr $failed + 1`
90
91 test_smbclient "Test login with re-enabled user (ntlm)" 'ls' -k no -U$USER%$NEWUSERPASS || failed=`expr $failed + 1`
92
93 testit "modify user - must change password now"  $VALGRIND $net sam set pwdmustchangenow $USER yes $@ || failed=`expr $failed + 1`
94
95 testit_expect_failure  "Test login with expired password" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -k no -U$USER@%$USERPASS && failed=`expr $failed + 1`
96
97 testit "modify user - disable password expiry"  $VALGRIND $net sam set pwnoexp $USER yes $@ || failed=`expr $failed + 1`
98
99 test_smbclient "Test login with no expiry (ntlm)" 'ls' -k no -U$USER%$NEWUSERPASS || failed=`expr $failed + 1`
100
101 NEWUSERPASS=testPaSS@03%
102 NEWUSERHASH=062519096c45739c1938800f80906731
103
104 testit "Set user password with password hash" $VALGRIND $pdbedit -u $USER --set-nt-hash $NEWUSERHASH $@ || failed=`expr $failed + 1`
105
106 test_smbclient "Test login with new password (from hash)" 'ls' -k no -U$USER%$NEWUSERPASS || failed=`expr $failed + 1`
107
108 testit "del user"  $VALGRIND $pdbedit -x $USER $@ || failed=`expr $failed + 1`
109
110 rm ./tmpsmbpasswdscript
111
112 exit $failed