lib/param: Make and use common lpcfg_map_parameter
[Samba.git] / nsswitch / tests / test_idmap_rfc2307.sh
blobb9efd346c8aae09746555bc662c54854c8a8bd5f
1 #!/bin/sh
2 # Test id mapping through idmap_rfc2307 module
3 if [ $# -lt 9 ]; then
4 echo Usage: $0 DOMAIN USERNAME UID GROUPNAME GID LDAPPREFIX DC_SERVER DC_USERNAME DC_PASSWORD
5 exit 1
6 fi
8 DOMAIN="$1"
9 USERNAME="$2"
10 USERUID="$3"
11 GROUPNAME="$4"
12 GROUPGID="$5"
13 LDAPPREFIX="$6"
14 DC_SERVER="$7"
15 DC_USERNAME="$8"
16 DC_PASSWORD="$9"
18 echo called with: $1 $2 $3 $4 $5 $6 $7 $8 $9
20 wbinfo="$VALGRIND $BINDIR/wbinfo"
21 ldbadd="$BINDIR/ldbadd"
22 ldbdel="$BINDIR/ldbdel"
23 failed=0
25 . `dirname $0`/../../testprogs/blackbox/subunit.sh
27 # Delete LDAP records
28 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$USERNAME,$LDAPPREFIX"
29 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$GROUPNAME,$LDAPPREFIX"
30 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "$LDAPPREFIX"
32 # Add id mapping information to LDAP
34 cat > $PREFIX/tmpldb <<EOF
35 dn: $LDAPPREFIX
36 objectclass: organizationalUnit
37 EOF
39 testit "add ldap prefix" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
41 cat > $PREFIX/tmpldb <<EOF
42 dn: cn=$USERNAME,$LDAPPREFIX
43 objectClass: organizationalPerson
44 objectClass: posixAccount
45 ou: People
46 cn: $USERNAME
47 uid: $USERNAME
48 uidNumber: $USERUID
49 gidNumber: 1
50 homeDirectory: /home/admin
51 EOF
53 testit "add ldap user mapping record" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
55 cat > $PREFIX/tmpldb <<EOF
56 dn: cn=$GROUPNAME,$LDAPPREFIX
57 objectClass: posixGroup
58 objectClass: groupOfNames
59 cn: $GROUPNAME
60 gidNumber: $GROUPGID
61 member: cn=$USERNAME,$LDAPPREFIX
62 EOF
64 testit "add ldap group mapping record" $VALGRIND $ldbadd -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD $PREFIX/tmpldb
66 rm -f $PREFIX/tmpldbmodify
68 testit "wbinfo --name-to-sid" $wbinfo --name-to-sid "$DOMAIN\\$USERNAME" || failed=$(expr $failed + 1)
69 user_sid=$($wbinfo -n "$DOMAIN\\$USERNAME" | cut -d " " -f1)
70 echo "$DOMAIN\\$USERNAME resolved to $user_sid"
72 testit "wbinfo --sid-to-uid=$user_sid" $wbinfo --sid-to-uid=$user_sid || failed=$(expr $failed + 1)
73 user_uid=$($wbinfo --sid-to-uid=$user_sid | cut -d " " -f1)
74 echo "$DOMAIN\\$USERNAME resolved to $user_uid"
76 testit "test $user_uid -eq $USERUID" test $user_uid -eq $USERUID || failed=$(expr $failed + 1)
78 # Not sure how to get group names with spaces to resolve through testit
79 #testit "wbinfo --name-to-sid" $wbinfo --name-to-sid="$DOMAIN\\$GROUPNAME" || failed=$(expr $failed + 1)
80 group_sid=$($wbinfo --name-to-sid="$DOMAIN\\$GROUPNAME" | cut -d " " -f1)
81 echo "$DOMAIN\\$GROUPNAME resolved to $group_sid"
83 testit "wbinfo --sid-to-gid=$group_sid" $wbinfo --sid-to-gid=$group_sid || failed=$(expr $failed + 1)
84 group_gid=$($wbinfo --sid-to-gid=$group_sid | cut -d " " -f1)
85 echo "$DOMAIN\\$GROUPNAME resolved to $group_gid"
87 testit "test $group_gid -eq $GROUPGID" test $group_gid -eq $GROUPGID || failed=$(expr $failed + 1)
89 # Delete LDAP records
90 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$USERNAME,$LDAPPREFIX"
91 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "cn=$GROUPNAME,$LDAPPREFIX"
92 $VALGRIND $ldbdel -H ldap://$DC_SERVER -U$DOMAIN/$DC_USERNAME%$DC_PASSWORD "$LDAPPREFIX"
94 exit $failed