Skip to content

Commit

Permalink
nsswitch: Add tests to lookup user via getpwnam
Browse files Browse the repository at this point in the history
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13503

Signed-off-by: Andreas Schneider <[email protected]>
Reviewed-by: Ralph Boehme <[email protected]>
  • Loading branch information
cryptomilk authored and slowfranklin committed Jul 4, 2018
1 parent e311801 commit 8e96e9e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
71 changes: 62 additions & 9 deletions nsswitch/tests/test_wbinfo_user_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
# Blackbox test for wbinfo lookup for account name and upn
# Copyright (c) 2018 Andreas Schneider <[email protected]>

if [ $# -lt 5 ]; then
if [ $# -lt 6 ]; then
cat <<EOF
Usage: $(basename $0) DOMAIN REALM USERNAME1 UPN_NAME1 USERNAME2 UPN_NAME2
Usage: $(basename $0) DOMAIN REALM OWN_DOMAIN USERNAME1 UPN_NAME1 USERNAME2 UPN_NAME2
EOF
exit 1;
fi

DOMAIN=$1
REALM=$2
USERNAME1=$3
UPN_NAME1=$4
USERNAME2=$5
UPN_NAME2=$6
OWN_DOMAIN=$3
USERNAME1=$4
UPN_NAME1=$5
USERNAME2=$6
UPN_NAME2=$7
shift 6

failed=0
Expand All @@ -31,9 +32,9 @@ test_user_info()
{
local cmd out ret user domain upn userinfo

domain="$1"
user="$2"
upn="$3"
local domain="$1"
local user="$2"
local upn="$3"

if [ $# -lt 3 ]; then
userinfo="$domain/$user"
Expand Down Expand Up @@ -62,6 +63,39 @@ test_user_info()
return 0
}

test_getpwnam()
{
local cmd out ret

local lookup_username=$1
local expected_return=$2
local expected_output=$3

cmd='getent passwd $lookup_username'
eval echo "$cmd"
out=$(eval $cmd)
ret=$?

if [ $ret -ne $expected_return ]; then
echo "return code: $ret, expected return code is: $expected_return"
echo "$out"
return 1
fi

if [ -n "$expected_output" ]; then
echo "$out" | grep "$expected_output"
ret=$?

if [ $ret -ne 0 ]; then
echo "Unable to find $expected_output in:"
echo "$out"
return 1
fi
fi

return 0
}

testit "name_to_sid.domain.$USERNAME1" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME1 || failed=$(expr $failed + 1)
testit "name_to_sid.upn.$UPN_NAME1" $wbinfo_tool --name-to-sid $UPN1 || failed=$(expr $failed + 1)

Expand All @@ -80,4 +114,23 @@ UPN3="$UPN_NAME3@${REALM}.upn"
testit "name_to_sid.upn.$UPN_NAME3" $wbinfo_tool --name-to-sid $UPN3 || failed=$(expr $failed + 1)
testit "user_info.upn.$UPN_NAME3" test_user_info $DOMAIN $USERNAME3 $UPN3 || failed=$(expr $failed + 1)

testit "getpwnam.domain.$DOMAIN.$USERNAME1" test_getpwnam "$DOMAIN/$USERNAME1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)

testit "getpwnam.upn.$UPN_NAME1" test_getpwnam "$UPN1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)

# We should not be able to lookup the user just by the name
test_ret=0
test_output="$DOMAIN/$USERNAME1"

if [ "$ENVNAME" = "ad_member" ]; then
test_ret=2
test_output=""
fi
if [ "$ENVNAME" = "fl2008r2dc" ]; then
test_ret=0
test_output="$OWN_DOMAIN/$USERNAME1"
fi

testit "getpwnam.local.$USERNAME1" test_getpwnam "$USERNAME1" $test_ret $test_output || failed=$(expr $failed + 1)

exit $failed
2 changes: 2 additions & 0 deletions selftest/knownfail.d/upn_handling
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
^samba3\.wbinfo_user_info\.name_to_sid\.upn\.testdenied_upn.ad_member
^samba3\.wbinfo_user_info\.user_info\.upn\.testdenied_upn.ad_member
^samba3\.wbinfo_user_info\.getpwnam\.local\.alice.ad_member
^samba3\.wbinfo_user_info\.user_info\.domain\.alice.fl2008r2dc
^samba3\.wbinfo_user_info\.user_info\.upn\.alice.fl2008r2dc
^samba3\.wbinfo_user_info\.user_info\.domain\.jane.fl2008r2dc
^samba3\.wbinfo_user_info\.user_info\.upn\.jane\.doe.fl2008r2dc
^samba3\.wbinfo_user_info\.name_to_sid\.upn\.testdenied_upn.fl2008r2dc
^samba3\.wbinfo_user_info\.user_info\.upn\.testdenied_upn.fl2008r2dc
^samba3\.wbinfo_user_info\.getpwnam\.local\.alice.fl2008r2dc
4 changes: 2 additions & 2 deletions source3/selftest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ def plansmbtorture4testsuite(name, env, options, description=''):
plantestsuite("samba3.wbinfo_user_info", env,
[ os.path.join(srcdir(),
"nsswitch/tests/test_wbinfo_user_info.sh"),
'$DOMAIN', '$REALM', 'alice', 'alice', 'jane', 'jane.doe' ])
'$DOMAIN', '$REALM', '$DOMAIN', 'alice', 'alice', 'jane', 'jane.doe' ])

env = "fl2008r2dc:local"
plantestsuite("samba3.wbinfo_user_info", env,
[ os.path.join(srcdir(),
"nsswitch/tests/test_wbinfo_user_info.sh"),
'$TRUST_DOMAIN', '$TRUST_REALM', 'alice', 'alice', 'jane', 'jane.doe' ])
'$TRUST_DOMAIN', '$TRUST_REALM', '$DOMAIN', 'alice', 'alice', 'jane', 'jane.doe' ])

env = "ad_member"
t = "WBCLIENT-MULTI-PING"
Expand Down

0 comments on commit 8e96e9e

Please sign in to comment.