s3:rpc_server: Return NTSTATUS for dcesrv_setup_ncacn_np_socket
[Samba.git] / nsswitch / tests / test_rfc2307_mapping.sh
blob8ab814cd7d043f27a9b8aa404a54794290d24a6a
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
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 SERVER=$4
14 UID_RFC2307TEST=$5
15 GID_RFC2307TEST=$6
16 shift 6
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"
29 . `dirname $0`/../../testprogs/blackbox/subunit.sh
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"
43 return $status
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
60 return $status
64 # Create new testing account
65 testit "user add" $PYTHON $samba_tool user create --given-name="rfc2307" --surname="Tester" --initial="UT" rfc2307_test_user testp@ssw0Rd $@
67 #test creation of six different groups
68 testit "group add" $PYTHON $samba_tool group add $CONFIG --group-scope='Domain' --group-type='Security' rfc2307_test_group $@
70 # Create new testing group
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"
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"
81 tested_name=`echo $DOMAIN/rfc2307_test_user | tr a-z A-Z`
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"
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`
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"
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"
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
117 testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -U$DOMAIN/$USERNAME%$PASSWORD $@ || failed=`expr $failed + 1`
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
127 testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -U$DOMAIN/$USERNAME%$PASSWORD $@ || failed=`expr $failed + 1`
129 rm -f $PREFIX/tmpldbmodify
131 # Now check we get a correct SID for the UID
133 testit "wbinfo -U against $TARGET" $wbinfo -U $UID_RFC2307TEST || failed=`expr $failed + 1`
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"
145 testit "wbinfo -G against $TARGET" $wbinfo -G $GID_RFC2307TEST || failed=`expr $failed + 1`
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"
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`
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"
170 # Now check we get the right GID from the SID
171 testit "wbinfo -Y" $wbinfo -Y "$group_sid" || failed=`expr $failed + 1`
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"
183 testit "group delete" $PYTHON $samba_tool group delete rfc2307_test_group $@
184 testit "user delete" $PYTHON $samba_tool user delete rfc2307_test_user $@
186 exit $failed