selftest: test idmap backend id allocation for unknown SIDS
[vlendec/samba-autobuild/.git] / nsswitch / tests / test_rfc2307_mapping.sh
1 #!/bin/sh
2 # Blackbox test for wbinfo and rfc2307 mappings
3 if [ $# -lt 4 ]; then
4 cat <<EOF
5 Usage: test_rfc2307_mapping.sh DOMAIN USERNAME PASSWORD SERVER UID_RFC2307TEST GID_RFC2307TEST
6 EOF
7 exit 1;
8 fi
9
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 SERVER=$4
14 UID_RFC2307TEST=$5
15 GID_RFC2307TEST=$6
16 shift 6
17
18 failed=0
19 samba4bindir="$BINDIR"
20 wbinfo="$VALGRIND $samba4bindir/wbinfo"
21 samba_tool="$VALGRIND $samba4bindir/samba-tool"
22 if [ -f "$samba4bindir/ldbmodify" ]; then
23         ldbmodify="$samba4bindir/ldbmodify"
24 else
25         # Using system ldbmodify
26         ldbmodify="ldbmodify"
27 fi
28
29 . `dirname $0`/../../testprogs/blackbox/subunit.sh
30
31 testfail() {
32         name="$1"
33         shift
34         cmdline="$*"
35         echo "test: $name"
36         $cmdline
37         status=$?
38         if [ x$status = x0 ]; then
39                 echo "failure: $name"
40         else
41                 echo "success: $name"
42         fi
43         return $status
44 }
45
46 knownfail() {
47         name="$1"
48         shift
49         cmdline="$*"
50         echo "test: $name"
51         $cmdline
52         status=$?
53         if [ x$status = x0 ]; then
54                 echo "failure: $name [unexpected success]"
55                                 status=1
56         else
57                 echo "knownfail: $name"
58                                 status=0
59         fi
60         return $status
61 }
62
63
64 # Create new testing account
65 testit "user add" $samba_tool user create --given-name="rfc2307" --surname="Tester" --initial="UT" rfc2307_test_user testp@ssw0Rd $@
66
67 #test creation of six different groups
68 testit "group add" $samba_tool group add $CONFIG --group-scope='Domain' --group-type='Security' rfc2307_test_group $@
69
70 # Create new testing group
71
72 # Convert name to SID
73 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/rfc2307_test_user" || failed=`expr $failed + 1`
74 user_sid=`$wbinfo -n "$DOMAIN/rfc2307_test_user" | cut -d " " -f1`
75 echo "$DOMAIN/rfc2307_test_user resolved to $user_sid"
76
77 testit "wbinfo -s $user_sid against $TARGET" $wbinfo -s $user_sid || failed=`expr $failed + 1`
78 user_name=`$wbinfo -s $user_sid | cut -d " " -f1| tr a-z A-Z`
79 echo "$user_sid resolved to $user_name"
80
81 tested_name=`echo $DOMAIN/rfc2307_test_user | tr a-z A-Z`
82
83 # Now check that wbinfo works correctly (sid <=> name)
84 echo "test: wbinfo -s check for sane mapping"
85 if test x$user_name != x$tested_name; then
86         echo "$user_name does not match $tested_name"
87         echo "failure: wbinfo -s check for sane mapping"
88         failed=`expr $failed + 1`
89 else
90         echo "success: wbinfo -s check for sane mapping"
91 fi
92
93 testit "wbinfo -n on the returned name against $TARGET" $wbinfo -n $user_name || failed=`expr $failed + 1`
94 test_sid=`$wbinfo -n $tested_name | cut -d " " -f1`
95
96 echo "test: wbinfo -n check for sane mapping"
97 if test x$user_sid != x$test_sid; then
98         echo "$user_sid does not match $test_sid"
99         echo "failure: wbinfo -n check for sane mapping"
100         failed=`expr $failed + 1`
101 else
102         echo "success: wbinfo -n check for sane mapping"
103 fi
104
105 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/rfc2307_test_group" || failed=`expr $failed + 1`
106 group_sid=`$wbinfo -n "$DOMAIN/rfc2307_test_group" | cut -d " " -f1`
107 echo "$DOMAIN/rfc2307_test_group resolved to $group_sid"
108
109 # Then add a uidNumber to the group record using ldbmodify
110 cat > $PREFIX/tmpldbmodify <<EOF
111 dn: <SID=$user_sid>
112 changetype: modify
113 add: uidNumber
114 uidNumber: $UID_RFC2307TEST
115 EOF
116
117 testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -U$DOMAIN/$USERNAME%$PASSWORD $@ || failed=`expr $failed + 1`
118
119 # Then add a gidNumber to the group record using ldbmodify
120 cat > $PREFIX/tmpldbmodify <<EOF
121 dn: <SID=$group_sid>
122 changetype: modify
123 add: gidNumber
124 gidNumber: $GID_RFC2307TEST
125 EOF
126
127 testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -U$DOMAIN/$USERNAME%$PASSWORD $@ || failed=`expr $failed + 1`
128
129 rm -f $PREFIX/tmpldbmodify
130
131 # Now check we get a correct SID for the UID
132
133 testit "wbinfo -U against $TARGET" $wbinfo -U $UID_RFC2307TEST || failed=`expr $failed + 1`
134
135 echo "test: wbinfo -U check for sane mapping"
136 sid_for_user=`$wbinfo -U $UID_RFC2307TEST`
137 if test x"$sid_for_user" != x"$user_sid"; then
138         echo "uid $UID_RFC2307TEST mapped to $sid_for_user, not $user_sid"
139         echo "failure: wbinfo -U check for sane mapping"
140         failed=`expr $failed + 1`
141 else
142         echo "success: wbinfo -U check for sane mapping"
143 fi
144
145 testit "wbinfo -G against $TARGET" $wbinfo -G $GID_RFC2307TEST || failed=`expr $failed + 1`
146
147 echo "test: wbinfo -G check for sane mapping"
148 sid_for_group=`$wbinfo -G $GID_RFC2307TEST`
149 if test x$sid_for_group != "x$group_sid"; then
150         echo "gid $GID_RFC2307TEST mapped to $sid_for_group, not $group_sid"
151         echo "failure: wbinfo -G check for sane mapping"
152         failed=`expr $failed + 1`
153 else
154         echo "success: wbinfo -G check for sane mapping"
155 fi
156
157 # Now check we get the right UID from the SID
158 testit "wbinfo -S against $TARGET" $wbinfo -S "$user_sid" || failed=`expr $failed + 1`
159
160 echo "test: wbinfo -S check for sane mapping"
161 uid_for_user_sid=`$wbinfo -S $user_sid`
162 if test 0$uid_for_user_sid -ne $UID_RFC2307TEST; then
163         echo "$user_sid mapped to $uid_for_sid, not $UID_RFC2307TEST"
164         echo "failure: wbinfo -S check for sane mapping"
165         failed=`expr $failed + 1`
166 else
167         echo "success: wbinfo -S check for sane mapping"
168 fi
169
170 # Now check we get the right GID from the SID
171 testit "wbinfo -Y" $wbinfo -Y "$group_sid" || failed=`expr $failed + 1`
172
173 echo "test: wbinfo -Y check for sane mapping"
174 gid_for_user_sid=`$wbinfo -Y $group_sid`
175 if test 0$gid_for_user_sid -ne $GID_RFC2307TEST; then
176         echo "$group_sid mapped to $gid_for_sid, not $GID_RFC2307TEST"
177         echo "failure: wbinfo -Y check for sane mapping"
178         failed=`expr $failed + 1`
179 else
180         echo "success: wbinfo -Y check for sane mapping"
181 fi
182
183 testit "group delete" $samba_tool group delete rfc2307_test_group $@
184 testit "user delete" $samba_tool user delete rfc2307_test_user $@
185
186 exit $failed