test_idmap_rfc2307: Remove the correct file
[samba.git] / nsswitch / tests / test_idmap_rfc2307.sh
1 #!/bin/sh
2 # Test id mapping through idmap_rfc2307 module
3 if [ $# -lt 9 ]; then
4         echo Usage: $0 DOMAIN USERNAME UID USERNAME2 UID2 GROUPNAME GID GROUPNAME2 GID2 LDAPPREFIX DC_SERVER DC_USERNAME DC_PASSWORD
5         exit 1
6 fi
7
8 DOMAIN="$1"
9 USERNAME="$2"
10 USERUID="$3"
11 USERNAME2="$4"
12 USERUID2="$5"
13 GROUPNAME="$6"
14 GROUPGID="$7"
15 GROUPNAME2="$8"
16 GROUPGID2="$9"
17 shift 9
18 LDAPPREFIX="$1"
19 DC_SERVER="$2"
20 DC_USERNAME="$3"
21 DC_PASSWORD="$4"
22
23 wbinfo="$VALGRIND $BINDIR/wbinfo"
24
25 ldbadd="ldbadd"
26 if [ -x "$BINDIR/ldbadd" ]; then
27         ldbadd="$BINDIR/ldbadd"
28 fi
29
30 ldbdel="ldbdel"
31 if [ -x "$BINDIR/ldbdel" ]; then
32         ldbdel="$BINDIR/ldbdel"
33 fi
34
35 failed=0
36
37 . `dirname $0`/../../testprogs/blackbox/subunit.sh
38
39 # Delete LDAP records
40 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$USERNAME,$LDAPPREFIX"
41 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$USERNAME2,$LDAPPREFIX"
42 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$GROUPNAME,$LDAPPREFIX"
43 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$GROUPNAME2,$LDAPPREFIX"
44 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "$LDAPPREFIX"
45
46 # Add id mapping information to LDAP
47
48 cat > $PREFIX/tmpldb <<EOF
49 dn: $LDAPPREFIX
50 objectclass: organizationalUnit
51 EOF
52
53 testit "add ldap prefix" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
54
55 cat > $PREFIX/tmpldb <<EOF
56 dn: cn=$USERNAME,$LDAPPREFIX
57 objectClass: organizationalPerson
58 objectClass: posixAccount
59 ou: People
60 cn: $USERNAME
61 uid: $USERNAME
62 uidNumber: $USERUID
63 gidNumber: 1
64 homeDirectory: /home/admin
65 EOF
66
67 testit "add ldap user mapping record" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
68
69 cat > $PREFIX/tmpldb <<EOF
70 dn: cn=$USERNAME2,$LDAPPREFIX
71 objectClass: organizationalPerson
72 objectClass: posixAccount
73 ou: People
74 cn: $USERNAME2
75 uid: $USERNAME2
76 uidNumber: $USERUID2
77 gidNumber: 2
78 homeDirectory: /home/admin
79 EOF
80
81 testit "add second ldap user mapping record" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
82
83 cat > $PREFIX/tmpldb <<EOF
84 dn: cn=$GROUPNAME,$LDAPPREFIX
85 objectClass: posixGroup
86 objectClass: groupOfNames
87 cn: $GROUPNAME
88 gidNumber: $GROUPGID
89 member: cn=$USERNAME,$LDAPPREFIX
90 EOF
91
92 testit "add ldap group mapping record" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
93
94 cat > $PREFIX/tmpldb <<EOF
95 dn: cn=$GROUPNAME2,$LDAPPREFIX
96 objectClass: posixGroup
97 objectClass: groupOfNames
98 cn: $GROUPNAME2
99 gidNumber: $GROUPGID2
100 member: cn=$USERNAME,$LDAPPREFIX
101 EOF
102
103 testit "add second ldap group mapping record" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
104
105 rm -f $PREFIX/tmpldb
106
107 testit "wbinfo --name-to-sid" $wbinfo --name-to-sid "$DOMAIN/$USERNAME" || failed=$(expr $failed + 1)
108 user_sid=$($wbinfo -n "$DOMAIN/$USERNAME" | cut -d " " -f1)
109 echo "$DOMAIN/$USERNAME resolved to $user_sid"
110
111 testit "wbinfo --sid-to-uid=$user_sid" $wbinfo --sid-to-uid=$user_sid || failed=$(expr $failed + 1)
112 user_uid=$($wbinfo --sid-to-uid=$user_sid | cut -d " " -f1)
113 echo "$DOMAIN/$USERNAME resolved to $user_uid"
114
115 testit "test $user_uid -eq $USERUID" test $user_uid -eq $USERUID || failed=$(expr $failed + 1)
116
117 # Not sure how to get group names with spaces to resolve through testit
118 #testit "wbinfo --name-to-sid" $wbinfo --name-to-sid="$DOMAIN/$GROUPNAME" || failed=$(expr $failed + 1)
119 group_sid=$($wbinfo --name-to-sid="$DOMAIN/$GROUPNAME" | cut -d " " -f1)
120 echo "$DOMAIN/$GROUPNAME resolved to $group_sid"
121
122 testit "wbinfo --sid-to-gid=$group_sid" $wbinfo --sid-to-gid=$group_sid || failed=$(expr $failed + 1)
123 group_gid=$($wbinfo --sid-to-gid=$group_sid | cut -d " " -f1)
124 echo "$DOMAIN/$GROUPNAME resolved to $group_gid"
125
126 testit "test $group_gid -eq $GROUPGID" test $group_gid -eq $GROUPGID || failed=$(expr $failed + 1)
127
128 # Use different user and group for reverse lookup to not read from cache
129
130 testit "$wbinfo --uid-to-sid=$USERUID2" $wbinfo --uid-to-sid=$USERUID2 || failed=$(expr $failed + 1)
131 user_sid2=$($wbinfo --uid-to-sid=$USERUID2 | cut -d " " -f1)
132 echo "UID $USERUID2 resolved to SID $user_sid2"
133
134 testit "$wbinfo --sid-to-name=$user_sid2" $wbinfo --sid-to-name=$user_sid2 || failed=$(expr $failed + 1)
135 user_name2=$($wbinfo --sid-to-name=$user_sid2 | cut -d " " -f1)
136 echo "SID $user_sid2 resolved to $user_name2"
137
138 testit "test $user_name2 = $DOMAIN/$USERNAME2" test "$(echo $user_name2 | tr A-Z a-z)" = "$(echo $DOMAIN/$USERNAME2 | tr A-Z a-z)" || failed=$(expr $failed + 1)
139
140 testit "$wbinfo --gid-to-sid=$GROUPGID2" $wbinfo --gid-to-sid=$GROUPGID2 || failed=$(expr $failed + 1)
141 group_sid2=$($wbinfo --gid-to-sid=$GROUPGID2 | cut -d " " -f1)
142 echo "GID $GROUPGID2 resolved to SID $group_sid2"
143
144 testit "$wbinfo --sid-to-name=$group_sid2" $wbinfo --sid-to-name=$group_sid2 || failed=$(expr $failed + 1)
145 group_name2=$($wbinfo --sid-to-name=$group_sid2 | cut -d " " -f1)
146 echo "SID $group_sid2 resolved to $group_name2"
147
148 testit "test $group_name2 = $DOMAIN/$GROUPNAME2" test "$(echo $group_name2 | tr A-Z a-z)" = "$(echo $DOMAIN/$GROUPNAME2 | tr A-Z a-z)" || failed=$(expr $failed + 1)
149
150 # Delete LDAP records
151 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$USERNAME,$LDAPPREFIX"
152 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$USERNAME2,$LDAPPREFIX"
153 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$GROUPNAME,$LDAPPREFIX"
154 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$GROUPNAME2,$LDAPPREFIX"
155 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "$LDAPPREFIX"
156
157 exit $failed