ctdb-takeover: IPAllocAlgorithm replaces LCP2PublicIPs, DeterministicIPs
[sfrench/samba-autobuild/.git] / testprogs / blackbox / test_net_ads_dns.sh
1 #!/bin/sh
2 # Blackbox tests for net ads dns register etc.
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 4 ]; then
7 cat <<EOF
8 Usage: test_net_ads_dns.sh SERVER DC_USERNAME DC_PASSWORD REALM USER PASS
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 DC_USERNAME=$2
15 DC_PASSWORD=$3
16 REALM=$4
17 USERNAME=$5
18 PASSWORD=$6
19 shift 6
20 failed=0
21
22 samba4bindir="$BINDIR"
23 samba4kinit=kinit
24 if test -x $BINDIR/samba4kinit; then
25         samba4kinit=$BINDIR/samba4kinit
26 fi
27
28 samba_tool="$samba4bindir/samba-tool"
29 net_tool="$samba4bindir/net"
30 smbpasswd="$samba4bindir/smbpasswd"
31 texpect="$samba4bindir/texpect"
32 samba4kpasswd=kpasswd
33 if test -x $BINDIR/samba4kpasswd; then
34         samba4kpasswd=$BINDIR/samba4kpasswd
35 fi
36
37 newuser="$samba_tool user create"
38 groupaddmem="$samba_tool group addmembers"
39
40 . `dirname $0`/subunit.sh
41
42 UID_WRAPPER_ROOT=1
43 export UID_WRAPPER_ROOT
44
45 IPADDRESS=10.1.4.111
46 IPADDRMAC=10.1.4.124
47 UNPRIVIP=10.1.4.130
48 NAME=testname
49 UNPRIVNAME=unprivname
50 UNPRIVUSER=unprivuser
51 UNPRIVPASS=UnPrivPass1
52
53 # These tests check that privileged users can add DNS names and that
54 # unprivileged users cannot do so.
55 echo "Starting ..."
56
57 testit "admin user should be able to add a DNS entry $NAME.$REALM $IPADDRESS" $VALGRIND $net_tool ads dns register $NAME.$REALM $IPADDRESS -U$DC_USERNAME%$DC_PASSWORD || failed=`expr $failed + 1`
58
59 # The complicated pipeline is to ensure that we remove exclamation points
60 # and spaces from the output. Thew will screw up the comparison syntax.
61 testit "We should be able to see the new name $NAME.$REALM" [ X"`$VALGRIND $net_tool ads dns gethostbyname $SERVER $NAME.$REALM -U$DC_USERNAME%$DC_PASSWORD | tr \! N | tr " " B`" = X"$IPADDRESS" ] || failed=`expr $failed + 1`
62
63 testit "We should be able to unregister the name $NAME.$REALM $IPADDRESS" $VALGRIND $net_tool ads dns unregister $NAME.$REALM -U$DC_USERNAME%$DC_PASSWORD || failed=`expr $failed + 1`
64
65 # The complicated pipeline is to ensure that we remove exclamation points
66 # and spaces from the output. Thew will screw up the comparison syntax.
67 testit "The name $NAME.$REALM should not be there any longer" test X"`$net_tool ads dns gethostbyname $SERVER $NAME.$REALM -U$DC_USERNAME%$DC_PASSWORD | tr " " B | tr \! N`" != X"$IPADDRESS" || failed=`expr $failed + 1`
68
69 # This should be an expect_failure test ...
70 testit "Adding an unprivileged user" $VALGRIND $net_tool user add $UNPRIVUSER $UNPRIVPASS -U$DC_USERNAME%$DC_PASSWORD || failed=`expr $failed + 1`
71
72 LDIF="dn: CN=$UNPRIVUSER,CN=users,DC=samba,DC=example,DC=com+changetype: modify+replace: userAccountControl+userAccountControl: 512"
73
74 echo $LDIF | tr '+' '\n' | ./bin/ldbmodify -Uadministrator%locDCpass1 -H ldap://localdc.samba.example.com -i
75 STATUS=$?
76
77 testit "We should have enabled the account" test $STATUS -eq 0 || failed=`expr $failed + 1`
78
79 #Unprivileged users should be able to add new names
80 testit "Unprivileged users should be able to add new names" $net_tool ads dns register $UNPRIVNAME.$REALM $UNPRIVIP -U$UNPRIVUSER%$UNPRIVPASS || failed=`expr $failed + 1`
81
82 # This should work as well
83 testit "machine account should be able to add a DNS entry net ads dns register membername.$REALM $IPADDRMAC -P " $net_tool ads dns register membername.$REALM $IPADDRMAC -P || failed=`expr $failed + 1`
84
85 # The complicated pipeline is to ensure that we remove exclamation points
86 # and spaces from the output. Thew will screw up the comparison syntax.
87 testit "We should be able to see the new name membername.$REALM using -P" [ X"`$VALGRIND $net_tool ads dns gethostbyname $SERVER membername.$REALM -P | tr \! N | tr " " B`" = X"$IPADDRMAC" ] || failed=`expr $failed + 1`
88
89 #Unprivileged users should not be able to overwrite other's names
90 testit_expect_failure "Unprivileged users should not be able modify existing names" $net_tool ads dns register membername.$REALM $UNPRIVIP -U$UNPRIVUSER%$UNPRIVPASS || failed=`expr $failed + 1`
91
92 testit "We should be able to unregister the name $NAME.$REALM $IPADDRESS" $VALGRIND $net_tool ads dns unregister $NAME.$REALM -P || failed=`expr $failed + 1`
93
94 # The complicated pipeline is to ensure that we remove exclamation points
95 # and spaces from the output. Thew will screw up the comparison syntax.
96 testit "The name $NAME.$REALM should not be there any longer" test X"`$net_tool ads dns gethostbyname $SERVER $NAME.$REALM -P | tr " " B | tr \! N`" != X"$IPADDRESS" || failed=`expr $failed + 1`
97
98 exit $failed