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.
47 lines
1.2 KiB
47 lines
1.2 KiB
#!/bin/bash
|
|
|
|
# Description: This script will generate initial passwords for samba users
|
|
ENABLED=yes
|
|
[[ ${ENABLED} == "yes" ]] || exit 0
|
|
DEBUGMODE=no
|
|
|
|
# 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"
|
|
|
|
. /usr/lib/ublinux/functions
|
|
. /usr/lib/ublinux/default
|
|
debug_mode "$0" "$@"
|
|
|
|
SOURCE=${SYSCONF}/config; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
|
|
|
|
[ "$SMBGUEST" != "yes" ] && GUESTOPT=e || GUESTOPT=d
|
|
|
|
addusers()
|
|
{
|
|
for a in $SMBUSERS ;do
|
|
PASS=$(echo "$a $SMBRANDOMSTR" | md5sum | cut -c 1-6)
|
|
echo -e $PASS\\n$PASS\\n | smbpasswd -Lsa $a >/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 a in $SMBUSERS ;do
|
|
PASS=$(echo "$a $SMBRANDOMSTR" | md5sum | cut -c 1-6)
|
|
echo $a $PASS
|
|
done
|
|
[ "$SMBGUEST" = "yes" ] && echo "guest account is enabled on default" || echo "guest account is disabled on default"
|
|
}
|
|
|
|
|
|
if [ "$MKSMBPWD" != "no" ] ;then
|
|
smbpasswd -L$GUESTOPT nobody >/dev/null 2>&1 || addusers
|
|
fi
|
|
|
|
[ "$UID" = "0" -a "$1" = "show" ] && $1
|