libsmb: Simplify an if-condition
[Samba.git] / testprogs / blackbox / test_net_ads_dns.sh
blob20f917ad2773e613a6ec3da72a9bf28ee4bd185f
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>
6 if [ $# -lt 6 ]; then
7 cat <<EOF
8 Usage: test_net_ads_dns.sh SERVER DC_USERNAME DC_PASSWORD REALM USER PASS
9 EOF
10 exit 1
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
22 samba4bindir="$BINDIR"
24 samba_tool="$samba4bindir/samba-tool"
25 net_tool="$samba4bindir/net"
26 smbpasswd="$samba4bindir/smbpasswd"
27 texpect="$samba4bindir/texpect"
29 newuser="$samba_tool user create"
30 groupaddmem="$samba_tool group addmembers"
32 . $(dirname $0)/subunit.sh
33 . "$(dirname "${0}")/common_test_fns.inc"
35 ldbmodify=$(system_or_builddir_binary ldbmodify "${BINDIR}")
36 ldbsearch=$(system_or_builddir_binary ldbsearch "${BINDIR}")
38 IPADDRESS=10.1.4.111
39 IP6ADDRESS=fd00:1a1a::1:5ee:bad:c0de
40 IPADDRMAC=10.1.4.124
41 UNPRIVIP=10.1.4.130
42 ADMINNAME=testname.$$
43 MACHINENAME=membername.$$
44 UNPRIVNAME=unprivname.$$
45 UNPRIVUSER=unprivuser.$$
46 UNPRIVPASS=UnPrivPass1
48 # These tests check that privileged users can add DNS names and that
49 # unprivileged users cannot do so.
50 echo "Starting ..."
52 testit "admin user should be able to add a DNS entry $ADMINNAME.$REALM $IPADDRESS $IP6ADDRESS" \
53 $VALGRIND $net_tool ads dns register $ADMINNAME.$REALM $IPADDRESS $IP6ADDRESS -U$DC_USERNAME%$DC_PASSWORD ||
54 failed=$(expr $failed + 1)
56 testit_grep_count \
57 "We should be able to see the new name $ADMINNAME.$REALM $IPADDRESS" \
58 "$IPADDRESS" \
59 1 \
60 dig @$SERVER +short -t a $ADMINNAME.$REALM ||
61 failed=$(expr $failed + 1)
62 testit_grep_count \
63 "We should be able to see the new name $ADMINNAME.$REALM $IP6ADDRESS" \
64 "$IP6ADDRESS" \
65 1 \
66 dig @$SERVER +short -t aaaa $ADMINNAME.$REALM ||
67 failed=$(expr $failed + 1)
69 testit "We should be able to unregister the name $ADMINNAME.$REALM" \
70 $VALGRIND $net_tool ads dns unregister $ADMINNAME.$REALM -U$DC_USERNAME%$DC_PASSWORD ||
71 failed=$(expr $failed + 1)
73 testit_grep_count \
74 "The name $ADMINNAME.$REALM $IPADDRESS should not be there any longer" \
75 "$IPADDRESS" \
76 0 \
77 dig @$SERVER +short -t a $ADMINNAME.$REALM ||
78 failed=$(expr $failed + 1)
80 testit_grep_count \
81 "The name $ADMINNAME.$REALM $IP6ADDRESS should not be there any longer" \
82 "$IP6ADDRESS" \
83 0 \
84 dig @$SERVER +short -t aaaa $ADMINNAME.$REALM ||
85 failed=$(expr $failed + 1)
87 # prime the kpasswd server, see "git blame" for an explanation
88 $VALGRIND $net_tool user add $UNPRIVUSER $UNPRIVPASS -U$DC_USERNAME%$DC_PASSWORD
89 $VALGRIND $net_tool user delete $UNPRIVUSER -U$DC_USERNAME%$DC_PASSWORD
91 # This should be an expect_failure test ...
92 testit "Adding an unprivileged user" $VALGRIND $net_tool user add $UNPRIVUSER $UNPRIVPASS -U$DC_USERNAME%$DC_PASSWORD || failed=$(expr $failed + 1)
94 BASEDN=$($VALGRIND $ldbsearch -U$DC_USERNAME%$DC_PASSWORD -H ldap://$SERVER.$REALM -b '' --scope=base defaultNamingContext | grep defaultNamingContext | sed -e 's!^defaultNamingContext: !!')
96 LDIF="dn: CN=$UNPRIVUSER,CN=users,${BASEDN}+changetype: modify+replace: userAccountControl+userAccountControl: 512"
98 echo $LDIF | tr '+' '\n' | $VALGRIND $ldbmodify -U$DC_USERNAME%$DC_PASSWORD -H ldap://$SERVER.$REALM -i
99 STATUS=$?
101 testit "We should have enabled the account" test $STATUS -eq 0 || failed=$(expr $failed + 1)
103 #Unprivileged users should be able to add new names
104 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)
106 # This should work as well
107 testit "machine account should be able to add a DNS entry net ads dns register $MACHINENAME.$REALM $IPADDRMAC -P" \
108 $net_tool ads dns register $MACHINENAME.$REALM $IPADDRMAC -P ||
109 failed=$(expr $failed + 1)
111 testit_grep_count \
112 "We should be able to see the new name $MACHINENAME.$REALM" \
113 "$IPADDRMAC" \
115 dig @$SERVER +short -t a $MACHINENAME.$REALM ||
116 failed=$(expr $failed + 1)
118 #Unprivileged users should not be able to overwrite other's names
119 testit_expect_failure \
120 "Unprivileged users should not be able to modify existing names" \
121 $net_tool ads dns register $MACHINENAME.$REALM $UNPRIVIP -U$UNPRIVUSER%$UNPRIVPASS ||
122 failed=$(expr $failed + 1)
124 testit "We should be able to unregister the name $UNPRIVNAME.$REALM $IPADDRESS" \
125 $VALGRIND $net_tool ads dns unregister $UNPRIVNAME.$REALM -U$UNPRIVUSER%$UNPRIVPASS ||
126 failed=$(expr $failed + 1)
127 testit "We should be able to unregister the name $MACHINENAME.$REALM $IPADDRESS" \
128 $VALGRIND $net_tool ads dns unregister $MACHINENAME.$REALM -P ||
129 failed=$(expr $failed + 1)
131 # Remove the unprivileged user, which is not required anymore
132 $VALGRIND $net_tool user delete $UNPRIVUSER -U$DC_USERNAME%$DC_PASSWORD
134 testit_grep_count \
135 "The name $UNPRIVNAME.$REALM ($IPADDRESS) should not be there any longer" \
136 "$IPADDRESS" \
138 dig @$SERVER +short -t a $UNPRIVNAME.$REALM ||
139 failed=$(expr $failed + 1)
140 testit_grep_count \
141 "The name $UNPRIVNAME.$REALM ($IP6ADDRESS) should not be there any longer" \
142 "$IP6ADDRESS" \
144 dig @$SERVER +short -t aaaa $UNPRIVNAME.$REALM ||
145 failed=$(expr $failed + 1)
146 testit_grep_count \
147 "The name $MACHINENAME.$REALM ($IPADDRESS) should not be there any longer" \
148 "$IPADDRESS" \
150 dig @$SERVER +short -t a $MACHINENAME.$REALM ||
151 failed=$(expr $failed + 1)
152 testit_grep_count \
153 "The name $MACHINENAME.$REALM ($IP6ADDRESS) should not be there any longer" \
154 "$IP6ADDRESS" \
156 dig @$SERVER +short -t aaaa $MACHINENAME.$REALM ||
157 failed=$(expr $failed + 1)
159 # Tests with --dns-ttl option
160 testit "net ads dns register with default TTL" \
161 $net_tool ads dns register $MACHINENAME.$REALM $IPADDRMAC -P ||
162 failed=$(expr $failed + 1)
163 TTL=$(dig @$SERVER.$REALM +noall +ttlid +answer -t A $MACHINENAME.$REALM |
164 awk '{ print $2 }')
165 testit "Verify default TTL of 3600 seconds" \
166 test "$TTL" = "3600" ||
167 failed=$(expr $failed + 1)
169 testit "Update record with TTL of 60 seconds" \
170 $net_tool ads dns register --dns-ttl 60 --force $MACHINENAME.$REALM $IPADDRMAC -P ||
171 failed=$(expr $failed + 1)
172 TTL=$(dig @$SERVER.$REALM +noall +ttlid +answer -t A $MACHINENAME.$REALM |
173 awk '{ print $2 }')
174 testit "Verify new TTL of 60 seconds" \
175 test "$TTL" = "60" ||
176 failed=$(expr $failed + 1)
178 testit "We should be able to unregister the name $MACHINENAME.$REALM $IPADDRESS" \
179 $VALGRIND $net_tool ads dns unregister $MACHINENAME.$REALM -P ||
180 failed=$(expr $failed + 1)
182 testit_grep_count \
183 "The name $MACHINENAME.$REALM ($IPADDRESS) should not be there any longer" \
184 "$IPADDRESS" \
186 dig @$SERVER.$REALM +short -t A $MACHINENAME.$REALM ||
187 failed=$(expr $failed + 1)
188 testit_grep_count \
189 "The name $MACHINENAME.$REALM ($IP6ADDRESS) should not be there any longer" \
190 "$IP6ADDRESS" \
192 dig @$SERVER.$REALM +short -t AAAA $MACHINENAME.$REALM ||
193 failed=$(expr $failed + 1)
195 testok $0 $failed