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>
8 Usage: test_net_ads_dns.sh SERVER DC_USERNAME DC_PASSWORD REALM USER PASS
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}")
39 IP6ADDRESS
=fd00
:1a1a
::1:5ee
:bad
:c0de
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.
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)
57 "We should be able to see the new name $ADMINNAME.$REALM $IPADDRESS" \
60 dig @
$SERVER +short
-t a
$ADMINNAME.
$REALM ||
61 failed
=$
(expr $failed + 1)
63 "We should be able to see the new name $ADMINNAME.$REALM $IP6ADDRESS" \
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)
74 "The name $ADMINNAME.$REALM $IPADDRESS should not be there any longer" \
77 dig @
$SERVER +short
-t a
$ADMINNAME.
$REALM ||
78 failed
=$
(expr $failed + 1)
81 "The name $ADMINNAME.$REALM $IP6ADDRESS should not be there any longer" \
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
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)
112 "We should be able to see the new name $MACHINENAME.$REALM" \
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
135 "The name $UNPRIVNAME.$REALM ($IPADDRESS) should not be there any longer" \
138 dig @
$SERVER +short
-t a
$UNPRIVNAME.
$REALM ||
139 failed
=$
(expr $failed + 1)
141 "The name $UNPRIVNAME.$REALM ($IP6ADDRESS) should not be there any longer" \
144 dig @
$SERVER +short
-t aaaa
$UNPRIVNAME.
$REALM ||
145 failed
=$
(expr $failed + 1)
147 "The name $MACHINENAME.$REALM ($IPADDRESS) should not be there any longer" \
150 dig @
$SERVER +short
-t a
$MACHINENAME.
$REALM ||
151 failed
=$
(expr $failed + 1)
153 "The name $MACHINENAME.$REALM ($IP6ADDRESS) should not be there any longer" \
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 |
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 |
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)
183 "The name $MACHINENAME.$REALM ($IPADDRESS) should not be there any longer" \
186 dig @
$SERVER.
$REALM +short
-t A
$MACHINENAME.
$REALM ||
187 failed
=$
(expr $failed + 1)
189 "The name $MACHINENAME.$REALM ($IP6ADDRESS) should not be there any longer" \
192 dig @
$SERVER.
$REALM +short
-t AAAA
$MACHINENAME.
$REALM ||
193 failed
=$
(expr $failed + 1)