作为一个捷径,我为Samba创建了脚本,它将更新shadowLastChange
密码更改:
#!/bin/sh
# script to update shadowLastChange when samba updates passwords
# it's not needed when using 'passwd', it does update the field,
# even if pam_ldap is using LDAP Extented Operation to change password
LDAP_MODIFY="/usr/bin/ldapmodify"
LDAP_SEARCH="/usr/bin/ldapsearch"
LDAP_USER="uid=shadow-update,ou=Services,dc=example,dc=com"
LDAP_PASSWORD="change-me"
LDAP_HOST="localhost"
# get date
SLC=$((`date '+%s'` / 24 / 3600))
# get user login name
user=$1
# find user's DN
dn=$($LDAP_SEARCH -x -h $LDAP_HOST -LLL -b dc=example,dc=com "(uid=$user)" dn)
dn=${dn#dn:}
# check if DN is not base64 encoded
if [ "${dn:0:1}" = ":" ]; then
# update password change date
echo "dn:$dn
changetype: modify
replace: shadowLastChange
shadowLastChange: $SLC" | cat | $LDAP_MODIFY -x -h "$LDAP_HOST" \
-D "$LDAP_USER" -w "$LDAP_PASSWORD" > /dev/null 2>&1
else
# update password change date
echo "dn: $dn
changetype: modify
replace: shadowLastChange
shadowLastChange: $SLC" | cat | $LDAP_MODIFY -x -h "$LDAP_HOST" \
-D "$LDAP_USER" -w "$LDAP_PASSWORD" > /dev/null 2>&1
fi
err=$?
if [ ! $err -eq 0 ]; then
echo "error: can't update shadowLastChange: $err"
echo "`date`: shadow.sh: can't update shadowLastChange: $err"\
>> /var/log/shadow-update.log
exit;
fi
echo OK
在Samba config中,需要unix password sync
将设置为yes
,passwd chat
设置为*OK*
和passwd program
上面的脚本"%u"
作为参数。
LDAP_USER
需要在LDAP中创建一个在中指定的帐户,并授予其读取uid
所有Samba用户的权限和写入权限shadowLastChange
。