lib: Fix CID 1620428: Memory - illegal accesses (OVERRUN)
[Samba.git] / nsswitch / tests / test_rfc2307_mapping.sh
blob440a924b09070683e76c673f733516759d74cd0f
1 #!/bin/sh
2 # Blackbox test for wbinfo and rfc2307 mappings
3 if [ $# -lt 7 ]; then
4 cat <<EOF
5 Usage: test_rfc2307_mapping.sh DOMAIN USERNAME PASSWORD SERVER UID_RFC2307TEST GID_RFC2307TEST CONFIGURATION
6 EOF
7 exit 1
8 fi
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 SERVER=$4
14 UID_RFC2307TEST=$5
15 GID_RFC2307TEST=$6
16 CONFIGURATION=${7}
17 shift 6
19 failed=0
20 samba4bindir="$BINDIR"
21 wbinfo="$VALGRIND $samba4bindir/wbinfo"
22 samba_tool="$VALGRIND $samba4bindir/samba-tool"
24 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
25 . "$(dirname "${0}")/../../testprogs/blackbox/common_test_fns.inc"
27 ldbmodify=$(system_or_builddir_binary ldbmodify "${BINDIR}")
29 # Create new testing account
30 testit "user add" $PYTHON $samba_tool user create --given-name="rfc2307" \
31 --surname="Tester" --initial="UT" rfc2307_test_user testp@ssw0Rd \
32 "${CONFIGURATION}" "$@"
34 #test creation of six different groups
35 testit "group add" $PYTHON $samba_tool group add \
36 --group-scope='Domain' --group-type='Security' rfc2307_test_group \
37 "${CONFIGURATION}" "$@"
39 # Create new testing group
41 # Convert name to SID
42 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/rfc2307_test_user" || failed=$(expr $failed + 1)
43 user_sid=$($wbinfo -n "$DOMAIN/rfc2307_test_user" | cut -d " " -f1)
44 echo "$DOMAIN/rfc2307_test_user resolved to $user_sid"
46 testit "wbinfo -s $user_sid against $TARGET" $wbinfo -s $user_sid || failed=$(expr $failed + 1)
47 user_name=$($wbinfo -s $user_sid | cut -d " " -f1 | tr a-z A-Z)
48 echo "$user_sid resolved to $user_name"
50 tested_name=$(echo $DOMAIN/rfc2307_test_user | tr a-z A-Z)
52 # Now check that wbinfo works correctly (sid <=> name)
53 echo "test: wbinfo -s check for sane mapping"
54 if test x$user_name != x$tested_name; then
55 echo "$user_name does not match $tested_name"
56 echo "failure: wbinfo -s check for sane mapping"
57 failed=$(expr $failed + 1)
58 else
59 echo "success: wbinfo -s check for sane mapping"
62 testit "wbinfo -n on the returned name against $TARGET" $wbinfo -n $user_name || failed=$(expr $failed + 1)
63 test_sid=$($wbinfo -n $tested_name | cut -d " " -f1)
65 echo "test: wbinfo -n check for sane mapping"
66 if test x$user_sid != x$test_sid; then
67 echo "$user_sid does not match $test_sid"
68 echo "failure: wbinfo -n check for sane mapping"
69 failed=$(expr $failed + 1)
70 else
71 echo "success: wbinfo -n check for sane mapping"
74 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/rfc2307_test_group" || failed=$(expr $failed + 1)
75 group_sid=$($wbinfo -n "$DOMAIN/rfc2307_test_group" | cut -d " " -f1)
76 echo "$DOMAIN/rfc2307_test_group resolved to $group_sid"
78 # Then add a uidNumber to the group record using ldbmodify
79 cat >$PREFIX/tmpldbmodify <<EOF
80 dn: <SID=$user_sid>
81 changetype: modify
82 add: uidNumber
83 uidNumber: $UID_RFC2307TEST
84 EOF
86 testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER \
87 $PREFIX/tmpldbmodify -U$DOMAIN/$USERNAME%$PASSWORD "$@" ||
88 failed=$(expr $failed + 1)
90 # Then add a gidNumber to the group record using ldbmodify
91 cat >$PREFIX/tmpldbmodify <<EOF
92 dn: <SID=$group_sid>
93 changetype: modify
94 add: gidNumber
95 gidNumber: $GID_RFC2307TEST
96 EOF
98 testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER \
99 $PREFIX/tmpldbmodify -U$DOMAIN/$USERNAME%$PASSWORD "$@" ||
100 failed=$(expr $failed + 1)
102 rm -f $PREFIX/tmpldbmodify
104 # Now check we get a correct SID for the UID
106 testit "wbinfo -U against $TARGET" $wbinfo -U $UID_RFC2307TEST || failed=$(expr $failed + 1)
108 echo "test: wbinfo -U check for sane mapping"
109 sid_for_user=$($wbinfo -U $UID_RFC2307TEST)
110 if test x"$sid_for_user" != x"$user_sid"; then
111 echo "uid $UID_RFC2307TEST mapped to $sid_for_user, not $user_sid"
112 echo "failure: wbinfo -U check for sane mapping"
113 failed=$(expr $failed + 1)
114 else
115 echo "success: wbinfo -U check for sane mapping"
118 testit "wbinfo -G against $TARGET" $wbinfo -G $GID_RFC2307TEST || failed=$(expr $failed + 1)
120 echo "test: wbinfo -G check for sane mapping"
121 sid_for_group=$($wbinfo -G $GID_RFC2307TEST)
122 if test x$sid_for_group != "x$group_sid"; then
123 echo "gid $GID_RFC2307TEST mapped to $sid_for_group, not $group_sid"
124 echo "failure: wbinfo -G check for sane mapping"
125 failed=$(expr $failed + 1)
126 else
127 echo "success: wbinfo -G check for sane mapping"
130 # Now check we get the right UID from the SID
131 testit "wbinfo -S against $TARGET" $wbinfo -S "$user_sid" || failed=$(expr $failed + 1)
133 echo "test: wbinfo -S check for sane mapping"
134 uid_for_user_sid=$($wbinfo -S $user_sid)
135 if test 0$uid_for_user_sid -ne $UID_RFC2307TEST; then
136 echo "$user_sid mapped to $uid_for_sid, not $UID_RFC2307TEST"
137 echo "failure: wbinfo -S check for sane mapping"
138 failed=$(expr $failed + 1)
139 else
140 echo "success: wbinfo -S check for sane mapping"
143 # Now check we get the right GID from the SID
144 testit "wbinfo -Y" $wbinfo -Y "$group_sid" || failed=$(expr $failed + 1)
146 echo "test: wbinfo -Y check for sane mapping"
147 gid_for_user_sid=$($wbinfo -Y $group_sid)
148 if test 0$gid_for_user_sid -ne $GID_RFC2307TEST; then
149 echo "$group_sid mapped to $gid_for_sid, not $GID_RFC2307TEST"
150 echo "failure: wbinfo -Y check for sane mapping"
151 failed=$(expr $failed + 1)
152 else
153 echo "success: wbinfo -Y check for sane mapping"
156 testit "group delete" $PYTHON $samba_tool group delete rfc2307_test_group "${CONFIGURATION}" "$@"
157 testit "user delete" $PYTHON $samba_tool user delete rfc2307_test_user "${CONFIGURATION}" "$@"
159 exit $failed