s3:pylibsmb: make use of protocol independent cli_write_send/recv in py_cli_write()
[garming/samba-autobuild/.git] / nsswitch / tests / test_wbinfo_user_info.sh
1 #!/bin/sh
2 # Blackbox test for wbinfo lookup for account name and upn
3 # Copyright (c) 2018 Andreas Schneider <asn@samba.org>
4
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;
10 fi
11
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
21
22 failed=0
23
24 samba_bindir="$BINDIR"
25 wbinfo_tool="$VALGRIND $samba_bindir/wbinfo"
26
27 UPN1="$UPN_NAME1@$REALM"
28 UPN2="$UPN_NAME2@$REALM"
29
30 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
31
32 test_user_info()
33 {
34         local cmd out ret user domain upn userinfo
35
36         local domain="$1"
37         local user="$2"
38         local upn="$3"
39
40         if [ $# -lt 3 ]; then
41                 userinfo="$domain/$user"
42         else
43                 userinfo="$upn"
44         fi
45
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
54         fi
55
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
62         fi
63
64         return 0
65 }
66
67 test_getpwnam()
68 {
69         local cmd out ret
70
71         local lookup_username=$1
72         local expected_return=$2
73         local expected_output=$3
74
75         cmd='getent passwd $lookup_username'
76         eval echo "$cmd"
77         out=$(eval $cmd)
78         ret=$?
79
80         if [ $ret -ne $expected_return ]; then
81                 echo "return code: $ret, expected return code is: $expected_return"
82                 echo "$out"
83                 return 1
84         fi
85
86         if [ -n "$expected_output" ]; then
87                 echo "$out" | grep "$expected_output"
88                 ret=$?
89
90                 if [ $ret -ne 0 ]; then
91                         echo "Unable to find $expected_output in:"
92                         echo "$out"
93                         return 1
94                 fi
95         fi
96
97         return 0
98 }
99
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)
102
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)
105
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)
108
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)
111
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)
117
118 testit "getpwnam.domain.$DOMAIN.$USERNAME1" test_getpwnam "$DOMAIN/$USERNAME1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)
119
120 testit "getpwnam.upn.$UPN_NAME1" test_getpwnam "$UPN1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)
121
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=""
127         ;;
128         fl2008r2dc*)
129         test_ret=0
130         test_output="$OWN_DOMAIN/$USERNAME1"
131         ;;
132         *)
133         test_ret=0
134         test_output="$DOMAIN/$USERNAME1"
135         ;;
136 esac
137
138 testit "getpwnam.local.$USERNAME1" test_getpwnam "$USERNAME1" $test_ret $test_output || failed=$(expr $failed + 1)
139
140 exit $failed