1 #! /bin/sh 2 # 3 # Copyright (c) 2012 FUJITSU LIMITED 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 # the GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 # 19 ################################################################## 20 21 export TST_TOTAL=${TST_TOTAL:=1} 22 export TST_COUNT=1 23 export TCID=${TCID:="$(basename "$0")"} 24 25 if [ -z "$LTPTMP" -a -z "$TMPBASE" ]; then 26 LTPTMP=/tmp 27 else 28 LTPTMP=$TMPBASE 29 fi 30 31 if ! which sss_useradd >/dev/null 2>&1; then 32 tst_brkm TCONF NULL \ 33 "sss_useradd does not exist. Skipping all testcases." 34 exit 0 35 fi 36 37 # Signals to trap. 38 readonly TRAP_SIGS="2 3 6 11 15" 39 40 CONFIG_FILE="/etc/sssd/sssd.conf" 41 NSS_CONFIG_FILE="/etc/nsswitch.conf" 42 43 # number of seconds to wait for another sssd test to complete 44 WAIT_COUNT=30 45 46 cleanup() 47 { 48 disable_traps 49 exit_code=$1 50 51 # Restore the previous sssd daemon state. 52 if [ -f "$CONFIG_FILE.ltpback" ]; then 53 if mv "$CONFIG_FILE.ltpback" "$CONFIG_FILE"; then 54 mv $NSS_CONFIG_FILE.ltpback $NSS_CONFIG_FILE 55 # Make sure that restart_sssd_daemon doesn't loop 56 # back to cleanup again. 57 if [ $SSSD_STARTED -eq 1 ]; then 58 stop_daemon sssd 59 else 60 restart_sssd_daemon "return 1" 61 fi 62 # Maintain any nonzero exit codes 63 if [ $exit_code -ne $? ]; then 64 exit_code=1 65 fi 66 else 67 exit_code=1 68 fi 69 fi 70 71 exit $exit_code 72 } 73 74 setup() 75 { 76 tst_require_root 77 78 trap ' disable_traps 79 tst_resm TBROK "Testing is terminating due to a signal" 80 cleanup 1' $TRAP_SIGS || exit 1 81 82 # Check to see if sssd exists 83 if [ ! -e /usr/sbin/sssd ]; then 84 tst_resm TCONF "couldn't find sssd" 85 cleanup 0 86 fi 87 88 # Check to see if nscd exists 89 if [ ! -e /usr/sbin/nscd ]; then 90 tst_resm TCONF "couldn't find nscd" 91 cleanup 0 92 fi 93 94 # Back up configuration file 95 if [ -f "$CONFIG_FILE" ]; then 96 # Pause if another LTP sssd test is running 97 while [ -f "$CONFIG_FILE.ltpback" -a $WAIT_COUNT -gt 0 ]; do 98 : $(( WAIT_COUNT -= 1 )) 99 sleep 1 100 done 101 # Oops -- $CONFIG_FILE.ltpback is still there! 102 if [ $WAIT_COUNT -eq 0 ]; then 103 tst_resm TBROK "another sssd test is stuck" 104 cleanup 1 105 elif ! cp "$CONFIG_FILE" "$CONFIG_FILE.ltpback"; then 106 tst_resm TBROK "failed to backup $CONFIG_FILE" 107 cleanup 1 108 fi 109 110 cp $NSS_CONFIG_FILE $NSS_CONFIG_FILE.ltpback 111 grep "passwd: files sss" $NSS_CONFIG_FILE > /dev/null 112 if [ $? -ne 0 ]; then 113 sed -i "s/passwd: files/passwd: files sss/" \ 114 $NSS_CONFIG_FILE 115 fi 116 else 117 tst_resm TWARN "$CONFIG_FILE not found!" 118 touch $CONFIG_FILE 119 fi 120 chmod 0600 $CONFIG_FILE 121 if [ $? -ne 0 ]; then 122 tst_brkm TBROK NULL "fail to modify the permission of $CONFIG_FILE" 123 fi 124 } 125 126 disable_traps() 127 { 128 trap - $TRAP_SIGS 129 } 130 131 restart_sssd_daemon() 132 { 133 # Default to running `cleanup 1' when dealing with error cases. 134 if [ $# -eq 0 ]; then 135 cleanup_command="cleanup 1" 136 else 137 cleanup_command=$1 138 fi 139 140 tst_resm TINFO "restarting sssd daemon" 141 restart_daemon sssd 142 if [ $? -eq 0 ]; then 143 # wait sssd restart success. 144 sleep 1 145 else 146 $cleanup_command 147 fi 148 } 149 150 # sssd.conf should contain: 151 # [sssd] 152 # config_file_version = 2 153 # services = nss, pam 154 # domains = LOCAL 155 # 156 #[nss] 157 # 158 #[pam] 159 # 160 #[domain/LOCAL] 161 #id_provider = local 162 make_config_file() 163 { 164 echo -e "[sssd]\nconfig_file_version = 2" > $CONFIG_FILE 165 echo -e "services = nss, pam\ndomains = LOCAL" >> $CONFIG_FILE 166 echo -e "\n[nss]\n\n[pam]\n" >> $CONFIG_FILE 167 echo -e "[domain/LOCAL]\nid_provider = local" >> $CONFIG_FILE 168 } 169 170 . cmdlib.sh 171 172 SSSD_STARTED=0 173 status_daemon sssd 174 if [ $? -ne 0 ]; then 175 SSSD_STARTED=1 176 fi 177 178 # determine sssd.conf can support override_gid? 179 setup 180 make_config_file 181 sed -i -e "/\[domain\/LOCAL\]/ a\override_gid = error" $CONFIG_FILE 182 # make sure config file is OK 183 sleep 1 184 restart_daemon sssd 185 186 if [ $? -ne 1 ]; then 187 tst_resm TCONF "override_gid does not exist. Skipping all testcases" 188 cleanup 0 189 fi 190