#!/bin/bash # samba-collect-debug-info.sh # # 31 Aug 2019 Rowland Penny # re-wrote several sections and added time and nsswitch.conf checks # 0.3 # # d.d. 16 Aug 2019 # 0.21 Added kerberos REALM detection before kinit when starting the script. # # Created and maintained by Rowland Penny and Louis van Belle. # questions, ask them in the samba list. # This script helps with debugging problems when you report them on the samba list. # This really helps a lot in finding/helping with problems. # Don't attach this to an e-mail, the samba list removes attachments, # add the content in the mail. # This is the only changeable variable. # If you want to put the output somewhere else, change this, # but the path must exist. LOGFILE="/tmp/samba-debug-info.txt" ############################################################################### # DO NOT CHANGE ANYTHING BELOW! # ############################################################################### ################ Functions fileserver_auth() { fileserver=0 PASSWD=$(cat /etc/nsswitch.conf | grep '[p]asswd' | grep -c '[w]inbind') if [ "$PASSWD" -eq 1 ]; then fileserver=$((fileserver+2)) fi GROUP=$(cat /etc/nsswitch.conf | grep '^[g]roup' | grep -c '[w]inbind') if [ "$GROUP" -eq 1 ]; then fileserver=$((fileserver+3)) fi SHADOW=$(cat /etc/nsswitch.conf | grep '^[s]hadow' | grep -c '[w]inbind') if [ "$SHADOW" -eq 1 ]; then fileserver=$((fileserver+4)) fi echo "$fileserver" } Check_file_exists () { if [ -e "${1}" ]; then local FILE="$(cat "${1}")" cat >> "$LOGFILE" <> "$LOGFILE" < $LOGFILE HOSTNAME="$(hostname -s)" DOMAIN="$(hostname -d)" REALM="${DOMAIN^^}" FQDN="$(hostname -f)" IP="$(hostname -I)" # Base info. cat >> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> $LOGFILE else cat >> "$LOGFILE" <> "$LOGFILE" cat >> "$LOGFILE" < /dev/null 2>&1 if [ "$?" -ne 0 ]; then printf "WARNING: 'kinit Administrator' will fail, you need to fix this.\nUnable to verify DNS kerberos._tcp SRV records\n\n-----------\n\n" >> $LOGFILE else printf "Kerberos SRV _kerberos._tcp.${DOMAIN} record(s) verified ok, sample output:\n%s\n\n-----------\n\n" "$(nslookup -type=SRV _kerberos._tcp.${DOMAIN})" >> $LOGFILE for x in $(nslookup -type=NS "${DOMAIN}"|grep nameserver |awk -F"=" '{ print $NF }' >/dev/null) do nslookup -type=SRV _kerberos._tcp."${DOMAIN}" "${x}" > /dev/null status="$?" if [ "$status" -ne 0 ]; then printf "Error detecting the nameserver '$x' _kerberos._tcp.${DOMAIN} records\n\n-----------\n\n" >> $LOGFILE else printf "DNS NS records for the nameservers: ${x} in domain ${DOMAIN} verified ok\n%s\n\n-----------\n\n" "$(nslookup -type=NS "${DOMAIN}"|grep nameserver |awk -F"=" '{ print $NF }')" >> $LOGFILE fi done fi # Initialize the Administrator kinit Administrator 2> /dev/null if [ "$?" -ne 0 ]; then printf "'kinit Administrator' password checked failed.\nWrong password or kerberos REALM problems.\n\n-----------\n\n" >> "$LOGFILE" else printf "'kinit Administrator' checked successfully.\n\n-----------\n\n" >> "$LOGFILE" # Remove Administrators kerberos ticket. kdestroy fi SMBCONF='smb.conf' DCOUNT=0 for deamon in samba smbd nmbd winbindd do pgrep -xl $deamon > /dev/null 2>&1 ret="$?" case $ret in 1) continue ;; 0) [[ $deamon == samba ]] && DCOUNT=$((DCOUNT+1)) [[ $deamon == smbd ]] && DCOUNT=$((DCOUNT+2)) [[ $deamon == nmbd ]] && DCOUNT=$((DCOUNT+3)) [[ $deamon == winbindd ]] && DCOUNT=$((DCOUNT+5)) ;; esac done case $DCOUNT in 0) cat >> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" </dev/null) ROLE="${ROLE^^}" if [ "$ROLE" = "ADS" ]; then cat >> "$LOGFILE" <> $LOGFILE SMBCONF=/etc/samba/smb.conf fi fi fi ;; 7) ROLE="$(testparm -s --parameter-name='security' 2>/dev/null)" ROLE="${ROLE^^}" if [ "$ROLE" = "ADS" ]; then printf "Samba is running as a Unix domain member\n\n-----------\n" >> $LOGFILE UDM=1 SMBCONF=$(smbd -b | grep 'CONFIGFILE' | awk '{print $NF}') fi ;; 8) cat >> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" < /dev/null)" else SERVER_ROLE="$(testparm -s --parameter-name="server role" 2> /dev/null)" fi if [ -e "${USERMAP}" ]; then if [ "$UDM" = "1" ]; then MAPCONTENTS=$(cat "$USERMAP") cat >> "$LOGFILE" << EOF Running as Unix domain member and user.map detected. Contents of $USERMAP $MAPCONTENTS Server Role is set to : $SERVER_ROLE ----------- EOF elif [ "$ADDC" = "1" ]; then cat >> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" <> $LOGFILE if [ -d /etc/bind ]; then CHECK_PACKAGES="${CHECK_PACKAGES}|bind9" Check_file_exists "/etc/bind/named.conf" Check_file_exists "/etc/bind/named.conf.options" Check_file_exists "/etc/bind/named.conf.local" Check_file_exists "/etc/bind/named.conf.default-zones" echo "Samba DNS zone list check : " >> $LOGFILE zonelist="$(samba-tool dns zonelist "${FQDN}" -P)" zones="$(echo "${zonelist}" | grep '[p]szZoneName' | awk '{print $NF}' | tr '\n' ' ')" while read -r -d ' ' zone do zonetest=$(grep -r "${zone}" /etc/bind | grep -v dpkg-dist) if [ -n "${zonetest}" ]; then found=$((found+1)) fi if [ "${found}" -gt 0 ]; then cat >> "$LOGFILE" <> "$LOGFILE" fi done <<< "${zones}" cat >> "$LOGFILE" <> "$LOGFILE" else # this should only be the Samba named.conf # test for 'samba' in $file path if [[ $file == *samba* ]]; then # is the right path ? if [ -f "$file" ]; then continue else printf "incorrect Samba 'named.conf' path '%s' set in %s" "$file" "$named_file" >> "$LOGFILE" fi else printf "unknown 'include' file '%s' in %s" "$file" "$named_file" >> "$LOGFILE" fi fi done done cat >> "$LOGFILE" <> "$LOGFILE" <> "$LOGFILE" < /dev/null | date +%FT%T) printf "\nTime on the DC with PDC Emulator role is: %s\n\n" "$pdc_emulator_time" >> "$LOGFILE" pdc_emulator_secs=$(echo "$pdc_emulator_time" | date +%s) local_time=$(net time system -S "${FQDN}" 2> /dev/null | date +%FT%T) printf "\nTime on this computer is: %s\n\n" "$local_time" >> "$LOGFILE" local_time_secs=$(echo "$local_time" | date +%s) time_diff="$((pdc_emulator_secs - local_time_secs))" if [ "$time_diff" -gt 300 ] || [ "$time_diff" -lt -300 ]; then printf "Error, the time difference between servers is too great.\n\n-----------\n" >> "$LOGFILE" else printf "\nTime verified ok, within the allowed 300sec margin.\nTime offset is currently : %s seconds\n\n-----------\n" "${time_diff}" >> "$LOGFILE" fi else pdc_emulator_time=$(echo $(net time system -S "${pdc_emulator}") 2> /dev/null | date +%FT%T) printf "\nThis is the DC with the PDC Emulator role and time is: %s\n\n-----------\n" "$pdc_emulator_time" >> "$LOGFILE" fi # TODO..add more checks.. running=$(dpkg -l | grep -E "${CHECK_PACKAGES}") cat >> "$LOGFILE" <