lib:ldb: Use correct integer types for sizes
[vlendec/samba-autobuild/.git] / nsswitch / tests / test_idmap_nss_use_upn.sh
1 #!/bin/sh
2
3 wbinfo="$BINDIR/wbinfo"
4 smbcontrol="$BINDIR/smbcontrol"
5 net="$BINDIR/net"
6 global_inject_conf=$(dirname $SMB_CONF_PATH)/global_inject.conf
7
8 failed=0
9
10 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
11
12 # Reset idmap_nss configuration and clear cache
13 echo "idmap config $DOMAIN : use_upn = no" >$global_inject_conf
14 $smbcontrol winbindd reload-config
15 if [ $? -ne 0 ]; then
16         echo "Could not reload config" | subunit_fail_test "test_idmap_nss_use_upn"
17 fi
18
19 $net cache flush
20 if [ $? -ne 0 ]; then
21         echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
22 fi
23
24 # Get the user SID
25 USER="bob"
26 USER_SID=$($wbinfo --name-to-sid="$USER")
27 if [ $? -ne 0 ]; then
28         echo "Could not find SID for user '$USER'" | subunit_fail_test "test_idmap_nss_use_upn"
29         exit 1
30 fi
31
32 USER_SID=$(echo $USER_SID | cut -d " " -f 1)
33 if [ $? -ne 0 ]; then
34         echo "Could not find SID for user '$USER'" | subunit_fail_test "test_idmap_nss_use_upn"
35         exit 1
36 fi
37
38 testit "SID to UID (use_upn = no)" $wbinfo --sid-to-uid=${USER_SID} || failed=$(expr $failed + 1)
39
40 echo "idmap config $DOMAIN : use_upn = yes" >$global_inject_conf
41 $smbcontrol winbindd reload-config
42 if [ $? -ne 0 ]; then
43         echo "Could not reload config" | subunit_fail_test "test_idmap_nss_use_upn"
44 fi
45
46 $net cache flush
47 if [ $? -ne 0 ]; then
48         echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
49 fi
50
51 # The following test will fail because idmap_nss will search ADDOMAIN/bob, which does not
52 # exists in NSS_WRAPPER_PASSWD
53 testit_expect_failure "SID to UID (use_upn = yes)" $wbinfo --sid-to-uid=${USER_SID} || failed=$(expr $failed + 1)
54
55 $net cache flush
56 if [ $? -ne 0 ]; then
57         echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
58 fi
59
60 # Add the ADDOMAIN/bob temporarily
61 ENTRY="$(getent passwd bob)"
62 ENTRY="$DOMAIN/${ENTRY}"
63 sed -i "1i ${ENTRY}" $NSS_WRAPPER_PASSWD
64 testit "Get user UID (use_upn = yes)" $wbinfo --sid-to-uid=${USER_SID} || failed=$(expr $failed + 1)
65 sed -i "1d" $NSS_WRAPPER_PASSWD
66
67 # Reset config
68 echo "idmap config $DOMAIN : use_upn = no" >$global_inject_conf
69 $smbcontrol winbindd reload-config
70 if [ $? -ne 0 ]; then
71         echo "Could not reload config" | subunit_fail_test "test_idmap_nss_use_upn"
72 fi
73
74 $net cache flush
75 if [ $? -ne 0 ]; then
76         echo "Could not flush cache" | subunit_fail_test "test_idmap_nss_use_upn"
77 fi
78
79 exit $failed