Debian Codegraph @

nsswitch/tests/test_wbinfo_user_info.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # Blackbox test for wbinfo lookup for account name and upn
3 # Copyright (c) 2018 Andreas Schneider <[email protected]>
4
5 if [scip-shell system . . `[`. $# -lt 6 ]; then
6 catscip-shell system . . cat. <<EOF
7 Usage: $(basenamescip-shell system . . 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 . $(dirnamescip-shell system . . dirname. $0)/../../testprogs/blackbox/subunit.sh
31
32 test_user_infoscip-shell shell samba 2:4.24.3+dfsg-1 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 [scip-shell system . . `[`. $# -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 [scip-shell system . . `[`. $ret -ne 0 ]; then
51 echoscip-shell system . . echo. "failed to lookup $userinfo"
52 echoscip-shell system . . echo. "$out"
53 return 1
54 fi
55
56 echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. "$domain/$user:.*:.*:.*::/home/$domain/Domain Users/$user"
57 ret=$?
58 if [scip-shell system . . `[`. $ret != 0 ]; then
59 echoscip-shell system . . echo. "failed to lookup $userinfo"
60 echoscip-shell system . . echo. "$out"
61 return 1
62 fi
63
64 return 0
65 }
66
67 test_getpwnamscip-shell shell samba 2:4.24.3+dfsg-1 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 [scip-shell system . . `[`. $ret -ne $expected_return ]; then
81 echoscip-shell system . . echo. "return code: $ret, expected return code is: $expected_return"
82 echoscip-shell system . . echo. "$out"
83 return 1
84 fi
85
86 if [scip-shell system . . `[`. -n "$expected_output" ]; then
87 echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. "$expected_output"
88 ret=$?
89
90 if [scip-shell system . . `[`. $ret -ne 0 ]; then
91 echoscip-shell system . . echo. "Unable to find $expected_output in:"
92 echoscip-shell system . . 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=$(exprscip-shell system . . expr. $failed + 1)
101 testit "name_to_sid.upn.$UPN_NAME1" $wbinfo_tool --name-to-sid $UPN1 || failed=$(exprscip-shell system . . expr. $failed + 1)
102
103 testit "user_info.domain.$USERNAME1" test_user_info $DOMAIN $USERNAME1 || failed=$(exprscip-shell system . . expr. $failed + 1)
104 testit "user_info.upn.$UPN_NAME1" test_user_info $DOMAIN $USERNAME1 $UPN1 || failed=$(exprscip-shell system . . expr. $failed + 1)
105
106 testit "name_to_sid.domain.$USERNAME2" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME2 || failed=$(exprscip-shell system . . expr. $failed + 1)
107 testit "name_to_sid.upn.$UPN_NAME2" $wbinfo_tool --name-to-sid $UPN2 || failed=$(exprscip-shell system . . expr. $failed + 1)
108
109 testit "user_info.domain.$USERNAME2" test_user_info $DOMAIN $USERNAME2 || failed=$(exprscip-shell system . . expr. $failed + 1)
110 testit "user_info.upn.$UPN_NAME2" test_user_info $DOMAIN $USERNAME2 $UPN2 || failed=$(exprscip-shell system . . 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=$(exprscip-shell system . . expr. $failed + 1)
116 testit "user_info.upn.$UPN_NAME3" test_user_info $DOMAIN $USERNAME3 $UPN3 || failed=$(exprscip-shell system . . expr. $failed + 1)
117
118 testit "getpwnam.domain.$DOMAIN.$USERNAME1" test_getpwnam "$DOMAIN/$USERNAME1" 0 "$DOMAIN/$USERNAME1" || failed=$(exprscip-shell system . . expr. $failed + 1)
119
120 testit "getpwnam.upn.$UPN_NAME1" test_getpwnam "$UPN1" 0 "$DOMAIN/$USERNAME1" || failed=$(exprscip-shell system . . 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=$(exprscip-shell system . . expr. $failed + 1)
139
140 exit $failed