s4:rpc_server/backupkey: make use dcesrv_call_session_info()
[Samba.git] / nsswitch / tests / test_wbinfo_user_info.sh
blobc699a30538fed2ce41855206a299d814e04edddb
1 #!/bin/sh
2 # Blackbox test for wbinfo lookup for account name and upn
3 # Copyright (c) 2018 Andreas Schneider <asn@samba.org>
5 if [ $# -lt 6 ]; then
6 cat <<EOF
7 Usage: $(basename $0) DOMAIN REALM OWN_DOMAIN USERNAME1 UPN_NAME1 USERNAME2 UPN_NAME2 ENVNAME
8 EOF
9 exit 1;
12 DOMAIN=$1
13 REALM=$2
14 OWN_DOMAIN=$3
15 USERNAME1=$4
16 UPN_NAME1=$5
17 USERNAME2=$6
18 UPN_NAME2=$7
19 ENVNAME=$8
20 shift 7
22 failed=0
24 samba_bindir="$BINDIR"
25 wbinfo_tool="$VALGRIND $samba_bindir/wbinfo"
27 UPN1="$UPN_NAME1@$REALM"
28 UPN2="$UPN_NAME2@$REALM"
30 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
32 test_user_info()
34 local cmd out ret user domain upn userinfo
36 local domain="$1"
37 local user="$2"
38 local upn="$3"
40 if [ $# -lt 3 ]; then
41 userinfo="$domain/$user"
42 else
43 userinfo="$upn"
46 cmd='$wbinfo_tool --user-info $userinfo'
47 eval echo "$cmd"
48 out=$(eval $cmd)
49 ret=$?
50 if [ $ret -ne 0 ]; then
51 echo "failed to lookup $userinfo"
52 echo "$out"
53 return 1
56 echo "$out" | grep "$domain/$user:.*:.*:.*::/home/$domain/Domain Users/$user"
57 ret=$?
58 if [ $ret != 0 ]; then
59 echo "failed to lookup $userinfo"
60 echo "$out"
61 return 1
64 return 0
67 test_getpwnam()
69 local cmd out ret
71 local lookup_username=$1
72 local expected_return=$2
73 local expected_output=$3
75 cmd='getent passwd $lookup_username'
76 eval echo "$cmd"
77 out=$(eval $cmd)
78 ret=$?
80 if [ $ret -ne $expected_return ]; then
81 echo "return code: $ret, expected return code is: $expected_return"
82 echo "$out"
83 return 1
86 if [ -n "$expected_output" ]; then
87 echo "$out" | grep "$expected_output"
88 ret=$?
90 if [ $ret -ne 0 ]; then
91 echo "Unable to find $expected_output in:"
92 echo "$out"
93 return 1
97 return 0
100 testit "name_to_sid.domain.$USERNAME1" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME1 || failed=$(expr $failed + 1)
101 testit "name_to_sid.upn.$UPN_NAME1" $wbinfo_tool --name-to-sid $UPN1 || failed=$(expr $failed + 1)
103 testit "user_info.domain.$USERNAME1" test_user_info $DOMAIN $USERNAME1 || failed=$(expr $failed + 1)
104 testit "user_info.upn.$UPN_NAME1" test_user_info $DOMAIN $USERNAME1 $UPN1 || failed=$(expr $failed + 1)
106 testit "name_to_sid.domain.$USERNAME2" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME2 || failed=$(expr $failed + 1)
107 testit "name_to_sid.upn.$UPN_NAME2" $wbinfo_tool --name-to-sid $UPN2 || failed=$(expr $failed + 1)
109 testit "user_info.domain.$USERNAME2" test_user_info $DOMAIN $USERNAME2 || failed=$(expr $failed + 1)
110 testit "user_info.upn.$UPN_NAME2" test_user_info $DOMAIN $USERNAME2 $UPN2 || failed=$(expr $failed + 1)
112 USERNAME3="testdenied"
113 UPN_NAME3="testdenied_upn"
114 UPN3="$UPN_NAME3@${REALM}.upn"
115 testit "name_to_sid.upn.$UPN_NAME3" $wbinfo_tool --name-to-sid $UPN3 || failed=$(expr $failed + 1)
116 testit "user_info.upn.$UPN_NAME3" test_user_info $DOMAIN $USERNAME3 $UPN3 || failed=$(expr $failed + 1)
118 testit "getpwnam.domain.$DOMAIN.$USERNAME1" test_getpwnam "$DOMAIN/$USERNAME1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)
120 testit "getpwnam.upn.$UPN_NAME1" test_getpwnam "$UPN1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)
122 case ${ENVNAME} in
123 ad_member*)
124 # We should not be able to lookup the user just by the name
125 test_ret=2
126 test_output=""
128 fl2008r2dc*)
129 test_ret=0
130 test_output="$OWN_DOMAIN/$USERNAME1"
133 test_ret=0
134 test_output="$DOMAIN/$USERNAME1"
136 esac
138 testit "getpwnam.local.$USERNAME1" test_getpwnam "$USERNAME1" $test_ret $test_output || failed=$(expr $failed + 1)
140 exit $failed