summaryrefslogtreecommitdiffstats
path: root/nsswitch/tests/test_idmap_nss_use_upn.sh
blob: df2c67203d8228fde3b676bb97b967f76be6935f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh

wbinfo="$BINDIR/wbinfo"
smbcontrol="$BINDIR/smbcontrol"
net="$BINDIR/net"
global_inject_conf=$(dirname $SMB_CONF_PATH)/global_inject.conf

failed=0

. $(dirname $0)/../../testprogs/blackbox/subunit.sh

# Reset idmap_nss configuration and clear cache
echo "idmap config $DOMAIN : use_upn = no" >$global_inject_conf
$smbcontrol winbindd reload-config
if [ $? -ne 0 ]; then
	echo "Could not reload config" | subunit_fail_test "test_idmap_nss_use_upn"
fi

$net cache flush
if [ $? -ne 0 ]; then
	echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
fi

# Get the user SID
USER="bob"
USER_SID=$($wbinfo --name-to-sid="$USER")
if [ $? -ne 0 ]; then
	echo "Could not find SID for user '$USER'" | subunit_fail_test "test_idmap_nss_use_upn"
	exit 1
fi

USER_SID=$(echo $USER_SID | cut -d " " -f 1)
if [ $? -ne 0 ]; then
	echo "Could not find SID for user '$USER'" | subunit_fail_test "test_idmap_nss_use_upn"
	exit 1
fi

testit "SID to UID (use_upn = no)" $wbinfo --sid-to-uid=${USER_SID} || failed=$(expr $failed + 1)

echo "idmap config $DOMAIN : use_upn = yes" >$global_inject_conf
$smbcontrol winbindd reload-config
if [ $? -ne 0 ]; then
	echo "Could not reload config" | subunit_fail_test "test_idmap_nss_use_upn"
fi

$net cache flush
if [ $? -ne 0 ]; then
	echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
fi

# The following test will fail because idmap_nss will search ADDOMAIN/bob, which does not
# exists in NSS_WRAPPER_PASSWD
testit_expect_failure "SID to UID (use_upn = yes)" $wbinfo --sid-to-uid=${USER_SID} || failed=$(expr $failed + 1)

$net cache flush
if [ $? -ne 0 ]; then
	echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
fi

# Add the ADDOMAIN/bob temporarily
ENTRY="$(getent passwd bob)"
ENTRY="$DOMAIN/${ENTRY}"
sed -i "1i ${ENTRY}" $NSS_WRAPPER_PASSWD
testit "Get user UID (use_upn = yes)" $wbinfo --sid-to-uid=${USER_SID} || failed=$(expr $failed + 1)
sed -i "1d" $NSS_WRAPPER_PASSWD

# Reset config
echo "idmap config $DOMAIN : use_upn = no" >$global_inject_conf
$smbcontrol winbindd reload-config
if [ $? -ne 0 ]; then
	echo "Could not reload config" | subunit_fail_test "test_idmap_nss_use_upn"
fi

$net cache flush
if [ $? -ne 0 ]; then
	echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
fi

exit $failed