3 Usage: test_net.sh DC_SERVER DC_USERNAME DC_PASSWORD PREFIX_ABS
13 HOSTNAME
=$
(dd if=/dev
/urandom bs
=1 count
=32 2>/dev
/null |
sha1sum | cut
-b 1-10)
17 WORKDIR
=$
(mktemp
-d -p .
)
18 WORKDIR
=$
(basename $WORKDIR)
19 ODJFILE
="$BASEDIR/$WORKDIR/odj_provision.txt"
21 cp -a client
/* $WORKDIR/
22 sed -ri "s@(dir|directory) = (.*)/client/@\1 = \2/$WORKDIR/@" $WORKDIR/client.conf
23 sed -ri "s/netbios name = .*/netbios name = $HOSTNAME/" $WORKDIR/client.conf
24 rm -f $WORKDIR/private
/secrets.tdb
29 net_tool
="$BINDIR/net --configfile=$BASEDIR/$WORKDIR/client.conf --option=security=ads"
30 samba_texpect
="$BINDIR/texpect"
33 . $
(dirname $0)/subunit.sh
35 netbios
=$
(grep "netbios name" $BASEDIR/$WORKDIR/client.conf | cut
-f2 -d= |
awk '{$1=$1};1')
39 testit
"provision without dcname" $VALGRIND $net_tool offlinejoin provision domain
=$REALM machine_name
=$netbios savefile
=$ODJFILE -U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
41 testit
"requestodj" $VALGRIND $net_tool offlinejoin requestodj loadfile
=$ODJFILE || failed
=$
(expr $failed + 1)
43 testit
"testjoin" $VALGRIND $net_tool ads testjoin
-P --use-kerberos=required || failed
=$
(expr $failed + 1)
47 testit
"leave" $VALGRIND $net_tool ads leave
-U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
51 testit
"provision with dcname" $VALGRIND $net_tool offlinejoin provision domain
=$REALM machine_name
=$netbios savefile
=$ODJFILE dcname
=$DC_SERVER -U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
53 testit
"requestodj" $VALGRIND $net_tool offlinejoin requestodj loadfile
=$ODJFILE || failed
=$
(expr $failed + 1)
55 testit
"testjoin" $VALGRIND $net_tool ads testjoin
-P --use-kerberos=required || failed
=$
(expr $failed + 1)
59 testit
"leave" $VALGRIND $net_tool ads leave
-U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
63 testit
"provision with dcname and default password" $VALGRIND $net_tool offlinejoin provision domain
=$REALM machine_name
=$netbios savefile
=$ODJFILE dcname
=$DC_SERVER defpwd
-U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
65 testit
"requestodj" $VALGRIND $net_tool offlinejoin requestodj loadfile
=$ODJFILE || failed
=$
(expr $failed + 1)
67 testit
"testjoin" $VALGRIND $net_tool ads testjoin
-P --use-kerberos=required || failed
=$
(expr $failed + 1)
71 testit
"leave" $VALGRIND $net_tool ads leave
-U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
77 # Retrieve the necessary information to compose the ODJ blob
78 # The machine needs to be correctly joined at this point
79 local netbios_domain_name
=$
($net_tool ads lookup |
awk -F': ' '/^Pre-Win2k Domain/ {print $2}')
80 local domain_sid
=$
($net_tool getdomainsid |
awk -F': ' "/^SID for domain $netbios_domain_name/ {print \$2}")
81 local domain_guid
=$
($net_tool ads lookup |
awk -F': ' '/^GUID/ {print $2}')
82 local forest_name
=$
($net_tool ads lookup |
awk -F': ' '/^Forest/ {print $2}')
83 local dc_name
=$
($net_tool ads info |
awk -F': ' '/^LDAP server name/ {print $2}')
84 local dc_address
=$
($net_tool ads info |
awk -F': ' '/^LDAP server:/ {print $2}')
89 "domain_sid=${domain_sid}" \
90 "domain_guid=${domain_guid}" \
91 "forest_name=${forest_name}" \
98 cmd
='$net_tool offlinejoin composeodj ${composeargv[@]} -P 2>&1'
103 cmd
='echo ${netbios} | $net_tool offlinejoin composeodj ${composeargv[@]} -U${netbios^^}\$ 2>&1'
104 out
=$
(PASSWD_FD
=0 eval $cmd)
108 tmpfile
=$BASEDIR/$WORKDIR/composeodj_password_script
110 expect Password for [${netbios_domain_name^^}\\${netbios^^}\$]:
113 cmd
='$samba_texpect -v $tmpfile $net_tool offlinejoin composeodj ${composeargv[@]} 2>&1'
119 out
="Unknown mode '$mode'"
123 if [ $ret -ne 0 ]; then
124 echo "Failed to compose ODJ blob: $out"
131 modes
=("machacct" "stdinfd" "callback")
132 for mode
in "${modes[@]}"; do
135 if [ "$mode" == "machacct" ]; then
139 testit
"provision[$mode]" $VALGRIND $net_tool offlinejoin provision domain
=$REALM machine_name
=$netbios savefile
=$ODJFILE $defpwd -U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
141 testit
"requestodj [$mode]" $VALGRIND $net_tool offlinejoin requestodj loadfile
=$ODJFILE || failed
=$
(expr $failed + 1)
143 testit
"testjoin [$mode]" $VALGRIND $net_tool ads testjoin
-P --use-kerberos=required || failed
=$
(expr $failed + 1)
145 testit
"removeodjblob [$mode]" rm $ODJFILE || failed
=$
(expr $failed + 1)
147 testit
"composeodj [$mode]" test_compose_odj
$mode || failed
=$
(expr $failed + 1)
149 testit
"removesecretsdb [$mode]" rm $BASEDIR/$WORKDIR/private
/secrets.tdb || failed
=$
(expr $failed + 1)
151 testit
"requestodj [$mode]" $VALGRIND $net_tool offlinejoin requestodj loadfile
=$ODJFILE || failed
=$
(expr $failed + 1)
153 testit
"removeodjblob [$mode]" rm $ODJFILE || failed
=$
(expr $failed + 1)
155 testit
"testjoin [$mode]" $VALGRIND $net_tool ads testjoin
-P --use-kerberos=required || failed
=$
(expr $failed + 1)
157 testit
"leave [$mode]" $VALGRIND $net_tool ads leave
-U$DC_USERNAME%$DC_PASSWORD || failed
=$
(expr $failed + 1)
160 rm -rf $BASEDIR/$WORKDIR