Commit 76053d5f authored by Mike Gabriel's avatar Mike Gabriel Committed by root
Browse files

Fix user-remove.sh script (never really worked).

parent 85e87cee
Pipeline #426 canceled with stages
......@@ -13,8 +13,12 @@ set -xe
## Malicious execution can mark directories for purging, but if $MAXAGE is chosen not
## too short, this will be detected by the owner and no data will get lost.
USERID=$1
MOUNTED_HOMEDIR=$2
USERID="$1"
if ! id "${USERID}" 1>/dev/null 2>/dev/null; then
echo "No such user name (\"${USERID}\")!"
exit 1
fi
## minimum age to keep a directory before it is purged
## in days (only integer values):
......@@ -25,19 +29,13 @@ MAXAGE_DAYS=500
MAXAGE_SEC=$(( $MAXAGE_DAYS*24*60*60 ))
[ -d $MOUNTED_HOMEDIR ] || exit 1
PREFIX=/net
HOSTNAME=$(hostname -s)
echo "$MOUNTED_HOMEDIR" | egrep -q "^$PREFIX/$HOSTNAME.*$USERID" || exit 1
HOMEDIR="$MOUNTED_HOMEDIR"
HOMEDIR="/home/${USERID}"
## move mail directory to home directory
if [ -d /var/mail/$USERID ]; then
if [ -d "/var/mail/${USERID}" ]; then
mkdir -p $HOMEDIR/Maildir/
mv /var/mail/$USERID/* $HOMEDIR/Maildir/
rmdir /var/mail/$USERID
mv /var/mail/${USERID}/* $HOMEDIR/Maildir/
rmdir /var/mail/${USERID}
fi
## rename home directory and delete principal:
......@@ -48,8 +46,8 @@ mv $HOMEDIR $RM_HOMEDIR
chown root:root $RM_HOMEDIR
chmod go-rwx $RM_HOMEDIR
kadmin.local -q "delete_principal -force $USERID"
logger -p notice Home directory \'$HOMEDIR\' marked for deletion and principal \'$USERID\' removed.
kadmin.local -q "delete_principal -force ${USERID}"
logger -p notice Home directory \'$HOMEDIR\' marked for deletion and principal \'${USERID}\' removed.
for DIR in `find $HOME -maxdepth 1 -type d -regextype posix-egrep -regex ".*/rm_[0-9]{8}_[^/]+"` ; do
RMDATE=`echo $DIR | sed "s/.*rm_\([0-9]\{8\}\)_.*/\1/"`
AGE=$(( `date +"%s"`-`date +"%s" -d $RMDATE` ))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment