You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ublinux-init/ublinux/rc.network.d/81-samba

41 lines
1.5 KiB

#!/usr/bin/bash
# Description: This script will generate initial passwords for samba users
ENABLED=yes
[[ ${ENABLED} == "yes" ]] || { return 0 2>/dev/null && return 0 || exit 0; }
DEBUGMODE=no
unset ROOTFS; [[ -d /usr/lib/ublinux ]] || ROOTFS=.
SOURCE=/usr/lib/ublinux/functions; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
SOURCE=/usr/lib/ublinux/default; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
debug_mode "$0" "$@"
SOURCE=${SYSCONF}/config; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
# Machine only
SMBRANDOMSTR=$(lspci -nmm | cat - /etc/machine-id /proc/cmdline | md5sum | awk '{print $1}')
SMBUSERS=$(grep ^users: /etc/group | awk -F: '{print $4}' | tr ';,' ' ')
SMBGUEST="yes"
[[ ${SMBGUEST} != "yes" ]] && GUESTOPT=e || GUESTOPT=d
addusers(){
for SELECT_SMBUSERS in ${SMBUSERS}; do
PASS=$(md5sum <<< "${SELECT_SMBUSERS} $SMBRANDOMSTR"| cut -c 1-6)
echo -e ${PASS}$'\n'${PASS}$'\n' | smbpasswd -Lsa ${SELECT_SMBUSERS} >/dev/null 2>&1
done
smbpasswd -Lan nobody >/dev/null 2>&1
smbpasswd -L${GUESTOPT} nobody >/dev/null 2>&1
}
show(){
echo "Default samba passwords:"
for SELECT_SMBUSERS in ${SMBUSERS}; do
PASS=$(md5sum <<< "${SELECT_SMBUSERS} ${SMBRANDOMSTR}" | cut -c 1-6)
echo ${SELECT_SMBUSERS} ${PASS}
done
[[ ${SMBGUEST} = "yes" ]] && echo "Guest account is enabled on default" || echo "Guest account is disabled on default"
}
[[ ${MKSMBPWD} != "no" ]] && smbpasswd -L${GUESTOPT} nobody >/dev/null 2>&1 || addusers
[[ ${UID} == "0" && $1 = "show" ]] && $1