Debian Codegraph @

testprogs/blackbox/test_net_offline.sh

raw symbols SCIP
1 if [scip-shell system . . `[`. $# -lt 4 ]; then
2 catscip-shell system . . cat. <<EOF
3 Usage: test_net_offline.sh DC_SERVER DC_USERNAME DC_PASSWORD PREFIX
4 EOF
5 exit 1
6 fi
7
8 DC_SERVER=$1
9 DC_USERNAME=$2
10 DC_PASSWORD=$3
11 BASEDIR=$4
12
13 HOSTNAME=$(LD_PRELOAD='' ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. bs=1 count=32 2>/dev/nullscip-shell filesystem . . `/dev/null`. | sha1sumscip-shell system . . sha1sum. | cutscip-shell system . . cut. -b 1-10)
14
15 RUNDIR=$(pwdscip-shell system . . pwd.)
16 cd $BASEDIR
17 WORKDIR=$(mktempscip-shell system . . mktemp. -d -p .)
18 WORKDIR=$(basenamescip-shell system . . basename. $WORKDIR)
19 ODJFILE="$BASEDIR/$WORKDIR/odj_provision.txt"
20
21 cpscip-shell system . . cp. -a client/* $WORKDIR/
22 sedscip-shell system . . sed. -ri "s@(dir|directory) = (.*)/client/@\1 = \2/$WORKDIR/@" $WORKDIR/client.conf
23 sedscip-shell system . . sed. -ri "s/netbios name = .*/netbios name = $HOSTNAME/" $WORKDIR/client.conf
24 rmscip-shell system . . rm. -f $WORKDIR/private/secrets.tdb
25 cd $RUNDIR
26
27 failed=0
28
29 net_tool="$BINDIR/net --configfile=$BASEDIR/$WORKDIR/client.conf --option=security=ads"
30 samba_texpect="$BINDIR/texpect"
31
32 # Load test functions
33 . $(dirnamescip-shell system . . dirname. $0)/subunit.sh
34
35 netbios=$(grepscip-shell system . . grep. "netbios name" $BASEDIR/$WORKDIR/client.conf | cutscip-shell system . . cut. -f2 -d= | awkscip-shell system . . awk. '{$1=$1};1')
36
37 # 0. Test with machine_name != lp_netbios_name()
38
39 NONLOCALMACHINE=win11
40
41 testit "provision with non local machine name" \
42 ${VALGRIND} ${net_tool} offlinejoin provision domain="${REALM}" machine_name="${NONLOCALMACHINE}" savefile="${ODJFILE}" -U"${DC_USERNAME}%${DC_PASSWORD}" || \
43 failed=$((failed + 1))
44
45 testit "net rpc user delete" \
46 ${VALGRIND} ${net_tool} rpc user delete "${NONLOCALMACHINE}$" -U"${DC_USERNAME}%${DC_PASSWORD}" -S "${DC_SERVER}" || \
47 failed=$((failed + 1))
48
49 rmscip-shell system . . rm. -f "${ODJFILE}"
50
51 # 1. Test w/o dcname
52
53 testit "provision without dcname" $VALGRIND $net_tool offlinejoin provision domain=$REALM machine_name=$netbios savefile=$ODJFILE -U$DC_USERNAME%$DC_PASSWORD || failed=$(exprscip-shell system . . expr. $failed + 1)
54
55 testit "requestodj" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
56
57 testit "testjoin" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(exprscip-shell system . . expr. $failed + 1)
58
59 rmscip-shell system . . rm. -f $ODJFILE
60
61 testit "leave" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=$(exprscip-shell system . . expr. $failed + 1)
62
63 # 2. Test with dcname
64
65 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=$(exprscip-shell system . . expr. $failed + 1)
66
67 testit "requestodj" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
68
69 testit "testjoin" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(exprscip-shell system . . expr. $failed + 1)
70
71 rmscip-shell system . . rm. -f $ODJFILE
72
73 testit "leave" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=$(exprscip-shell system . . expr. $failed + 1)
74
75 # 3. Test with defpwd
76
77 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=$(exprscip-shell system . . expr. $failed + 1)
78
79 testit "requestodj" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
80
81 testit "testjoin" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(exprscip-shell system . . expr. $failed + 1)
82
83 rmscip-shell system . . rm. -f $ODJFILE
84
85 testit "leave" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=$(exprscip-shell system . . expr. $failed + 1)
86
87 test_compose_odjscip-shell shell samba 2:4.24.3+dfsg-1 test_compose_odj().() {
88 local mode=$1
89 local composeargv=()
90
91 # Retrieve the necessary information to compose the ODJ blob
92 # The machine needs to be correctly joined at this point
93 local netbios_domain_name=$($net_tool ads lookup | awkscip-shell system . . awk. -F': ' '/^Pre-Win2k Domain/ {print $2}scip-shell filesystem . . `/^Pre-Win2k Domain/ {print $2}`.')
94 local domain_sid=$($net_tool getdomainsid | awkscip-shell system . . awk. -F': ' "/^SID for domain $netbios_domain_name/ {print \$2}")
95 local domain_guid=$($net_tool ads lookup | awkscip-shell system . . awk. -F': ' '/^GUID/ {print $2}scip-shell filesystem . . `/^GUID/ {print $2}`.')
96 local forest_name=$($net_tool ads lookup | awkscip-shell system . . awk. -F': ' '/^Forest/ {print $2}scip-shell filesystem . . `/^Forest/ {print $2}`.')
97 local dc_name=$($net_tool ads info | awkscip-shell system . . awk. -F': ' '/^LDAP server name/ {print $2}scip-shell filesystem . . `/^LDAP server name/ {print $2}`.')
98 local dc_address=$($net_tool ads info | awkscip-shell system . . awk. -F': ' '/^LDAP server:/ {print $2}scip-shell filesystem . . `/^LDAP server:/ {print $2}`.')
99 local ret=1
100 local out=""
101
102 composeargv=( \
103 "domain_sid=${domain_sid}" \
104 "domain_guid=${domain_guid}" \
105 "forest_name=${forest_name}" \
106 "-S ${dc_name}" \
107 "-I ${dc_address}" \
108 "savefile=${ODJFILE}"
109 )
110 case $mode in
111 machacct)
112 cmd='$net_tool offlinejoin composeodj ${composeargv[@]} -P 2>&1'
113 out=$(eval $cmd)
114 ret=$?
115 ;;
116 stdinfd)
117 cmd='echo ${netbios} | $net_tool offlinejoin composeodj ${composeargv[@]} -U${netbios^^}\$ 2>&1'
118 out=$(PASSWD_FD=0 eval $cmd)
119 ret=$?
120 ;;
121 callback)
122 tmpfile=$BASEDIR/$WORKDIR/composeodj_password_script
123 catscip-shell system . . cat. >$tmpfile <<EOF
124 expect Password for [${netbios_domain_name^^}\\${netbios^^}\$]:
125 send $netbios\n
126 EOF
127 cmd='$samba_texpect -v $tmpfile $net_tool offlinejoin composeodj ${composeargv[@]} 2>&1'
128 out=$(eval $cmd)
129 ret=$?
130 rmscip-shell system . . rm. -f $tmpfile
131 ;;
132 *)
133 out="Unknown mode '$mode'"
134 ;;
135 esac
136
137 if [scip-shell system . . `[`. $ret -ne 0 ]; then
138 echoscip-shell system . . echo. "Failed to compose ODJ blob: $out"
139 return 1
140 fi
141 }
142
143 # 4. Test composeodj
144
145 modes=("machacct" "stdinfd" "callback")
146 for mode in "${modes[@]}"; do
147
148 defpwd="defpwd"
149 if [scip-shell system . . `[`. "$mode" == "machacct" ]; then
150 defpwd=""
151 fi
152
153 testit "provision[$mode]" $VALGRIND $net_tool offlinejoin provision domain=$REALM machine_name=$netbios savefile=$ODJFILE $defpwd -U$DC_USERNAME%$DC_PASSWORD || failed=$(exprscip-shell system . . expr. $failed + 1)
154
155 testit "requestodj [$mode]" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
156
157 testit "testjoin [$mode]" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(exprscip-shell system . . expr. $failed + 1)
158
159 testit "removeodjblob [$mode]" rm $ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
160
161 testit "composeodj [$mode]" test_compose_odj $mode || failed=$(exprscip-shell system . . expr. $failed + 1)
162
163 testit "removesecretsdb [$mode]" rm $BASEDIR/$WORKDIR/private/secrets.tdb || failed=$(exprscip-shell system . . expr. $failed + 1)
164
165 testit "requestodj [$mode]" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
166
167 testit "removeodjblob [$mode]" rm $ODJFILE || failed=$(exprscip-shell system . . expr. $failed + 1)
168
169 testit "testjoin [$mode]" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(exprscip-shell system . . expr. $failed + 1)
170
171 testit "leave [$mode]" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=$(exprscip-shell system . . expr. $failed + 1)
172 done
173
174 rmscip-shell system . . rm. -rf $BASEDIR/$WORKDIR
175
176 exit $failed