rmuser.sh (116624) | rmuser.sh (126398) |
---|---|
1#!/bin/sh 2# 3# Copyright (c) 2002, 2003 Michael Telahun Makonnen. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24# 25# Email: Mike Makonnen <mtm@FreeBSD.Org> 26# | 1#!/bin/sh 2# 3# Copyright (c) 2002, 2003 Michael Telahun Makonnen. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24# 25# Email: Mike Makonnen <mtm@FreeBSD.Org> 26# |
27# $FreeBSD: head/usr.sbin/adduser/rmuser.sh 116624 2003-06-20 16:53:36Z mtm $ | 27# $FreeBSD: head/usr.sbin/adduser/rmuser.sh 126398 2004-02-29 09:54:15Z schweikh $ |
28# 29 30ATJOBDIR="/var/at/jobs" 31CRONJOBDIR="/var/cron/tabs" 32MAILSPOOL="/var/mail" 33SIGKILL="-KILL" 34TEMPDIRS="/tmp /var/tmp" 35THISCMD=`/usr/bin/basename $0` --- 14 unchanged lines hidden (view full) --- 50 51# rm_files login 52# Removes files or empty directories belonging to $login from various 53# temporary directories. 54# 55rm_files() { 56 # The argument is required 57 [ -n $1 ] && login=$1 || return | 28# 29 30ATJOBDIR="/var/at/jobs" 31CRONJOBDIR="/var/cron/tabs" 32MAILSPOOL="/var/mail" 33SIGKILL="-KILL" 34TEMPDIRS="/tmp /var/tmp" 35THISCMD=`/usr/bin/basename $0` --- 14 unchanged lines hidden (view full) --- 50 51# rm_files login 52# Removes files or empty directories belonging to $login from various 53# temporary directories. 54# 55rm_files() { 56 # The argument is required 57 [ -n $1 ] && login=$1 || return |
58 | 58 |
59 totalcount=0 60 for _dir in ${TEMPDIRS} ; do 61 filecount=0 62 if [ ! -d $_dir ]; then 63 err "$_dir is not a valid directory." 64 continue 65 fi 66 verbose && echo -n "Removing files owned by ($login) in $_dir:" | 59 totalcount=0 60 for _dir in ${TEMPDIRS} ; do 61 filecount=0 62 if [ ! -d $_dir ]; then 63 err "$_dir is not a valid directory." 64 continue 65 fi 66 verbose && echo -n "Removing files owned by ($login) in $_dir:" |
67 filecount=`find 2>/dev/null "$_dir" -user "$login" -delete -print | \ | 67 filecount=`find 2>/dev/null "$_dir" -user "$login" -delete -print | |
68 wc -l | sed 's/ *//'` 69 verbose && echo " $filecount removed." 70 totalcount=$(($totalcount + $filecount)) 71 done 72 ! verbose && [ $totalcount -ne 0 ] && echo -n " files($totalcount)" 73} 74 75# rm_mail login 76# Removes unix mail and pop daemon files belonging to the user 77# specified in the $login argument. 78# 79rm_mail() { 80 # The argument is required 81 [ -n $1 ] && login=$1 || return 82 83 verbose && echo -n "Removing mail spool(s) for ($login):" 84 if [ -f ${MAILSPOOL}/$login ]; then | 68 wc -l | sed 's/ *//'` 69 verbose && echo " $filecount removed." 70 totalcount=$(($totalcount + $filecount)) 71 done 72 ! verbose && [ $totalcount -ne 0 ] && echo -n " files($totalcount)" 73} 74 75# rm_mail login 76# Removes unix mail and pop daemon files belonging to the user 77# specified in the $login argument. 78# 79rm_mail() { 80 # The argument is required 81 [ -n $1 ] && login=$1 || return 82 83 verbose && echo -n "Removing mail spool(s) for ($login):" 84 if [ -f ${MAILSPOOL}/$login ]; then |
85 verbose && echo -n " ${MAILSPOOL}/$login" || \ | 85 verbose && echo -n " ${MAILSPOOL}/$login" || |
86 echo -n " mailspool" 87 rm ${MAILSPOOL}/$login 88 fi 89 if [ -f ${MAILSPOOL}/${login}.pop ]; then | 86 echo -n " mailspool" 87 rm ${MAILSPOOL}/$login 88 fi 89 if [ -f ${MAILSPOOL}/${login}.pop ]; then |
90 verbose && echo -n " ${MAILSPOOL}/${login}.pop" || \ | 90 verbose && echo -n " ${MAILSPOOL}/${login}.pop" || |
91 echo -n " pop3" 92 rm ${MAILSPOOL}/${login}.pop 93 fi 94 verbose && echo '.' 95} 96 97# kill_procs login 98# Send a SIGKILL to all processes owned by $login. --- 41 unchanged lines hidden (view full) --- 140 verbose && echo -n "Removing crontab for ($login):" 141 if [ -f ${CRONJOBDIR}/$login ]; then 142 verbose && echo -n " ${CRONJOBDIR}/$login" || echo -n " crontab" 143 rm -f ${CRONJOBDIR}/$login 144 fi 145 verbose && echo '.' 146} 147 | 91 echo -n " pop3" 92 rm ${MAILSPOOL}/${login}.pop 93 fi 94 verbose && echo '.' 95} 96 97# kill_procs login 98# Send a SIGKILL to all processes owned by $login. --- 41 unchanged lines hidden (view full) --- 140 verbose && echo -n "Removing crontab for ($login):" 141 if [ -f ${CRONJOBDIR}/$login ]; then 142 verbose && echo -n " ${CRONJOBDIR}/$login" || echo -n " crontab" 143 rm -f ${CRONJOBDIR}/$login 144 fi 145 verbose && echo '.' 146} 147 |
148# rm_ipc login 149# Remove all IPC mechanisms which are owned by $login. 150# 151rm_ipc() { 152 verbose && echo -n "Removing IPC mechanisms" 153 for i in s m q; do 154 ipcs -$i | 155 awk -v i=$i -v login=$1 '$1 == i && $5 == login { print $2 }' | 156 xargs -n 1 ipcrm -$i 157 done 158 verbose && echo '.' 159} 160 |
|
148# rm_user login 149# Remove user $login from the system. This subroutine makes use 150# of the pw(8) command to remove a user from the system. The pw(8) 151# command will remove the specified user from the user database 152# and group file and remove any crontabs. His home 153# directory will be removed if it is owned by him and contains no 154# files or subdirectories owned by other users. Mail spool files will 155# also be removed. --- 177 unchanged lines hidden (view full) --- 333 pw 2>/dev/null lock $_user 334 335 # Remove crontab, mail spool, etc. Then obliterate the user from 336 # the passwd and group database. 337 # 338 ! verbose && echo -n "Removing user ($_user):" 339 rm_crontab $_user 340 rm_at_jobs $_user | 161# rm_user login 162# Remove user $login from the system. This subroutine makes use 163# of the pw(8) command to remove a user from the system. The pw(8) 164# command will remove the specified user from the user database 165# and group file and remove any crontabs. His home 166# directory will be removed if it is owned by him and contains no 167# files or subdirectories owned by other users. Mail spool files will 168# also be removed. --- 177 unchanged lines hidden (view full) --- 346 pw 2>/dev/null lock $_user 347 348 # Remove crontab, mail spool, etc. Then obliterate the user from 349 # the passwd and group database. 350 # 351 ! verbose && echo -n "Removing user ($_user):" 352 rm_crontab $_user 353 rm_at_jobs $_user |
354 rm_ipc $_user |
|
341 kill_procs $_user 342 rm_files $_user 343 rm_mail $_user 344 rm_user $_user 345 ! verbose && echo "." 346done | 355 kill_procs $_user 356 rm_files $_user 357 rm_mail $_user 358 rm_user $_user 359 ! verbose && echo "." 360done |