delete rule 3 (advertising) from copyright
resolve symlinks before removing user's home directory with /bin/rm -rf <home dir> Submitted by: Guy Helmer <ghelmer@alpha.dsu.edu>
This commit is contained in:
parent
d5dcd8e63f
commit
d2b945efae
@ -1,5 +1,3 @@
|
||||
# $Id$
|
||||
|
||||
Here lies removeuser(8) for FreeBSD 2.x. It will remove a user's
|
||||
password entry, home directory, and incoming mail file from /var/mail.
|
||||
|
||||
|
@ -10,10 +10,7 @@
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by Guy Helmer.
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" 3. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY GUY HELMER ``AS IS'' AND ANY EXPRESS OR
|
||||
@ -29,7 +26,7 @@
|
||||
.\"
|
||||
.\" $Id$
|
||||
.\"
|
||||
.Dd June 28, 1996
|
||||
.Dd July 16, 1996
|
||||
.Dt REMOVEUSER 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -29,7 +29,7 @@
|
||||
# /usr/sbin/removeuser
|
||||
# Perl script to remove users
|
||||
#
|
||||
# Guy Helmer <ghelmer@alpha.dsu.edu>, 06/30/96
|
||||
# Guy Helmer <ghelmer@alpha.dsu.edu>, 07/17/96
|
||||
#
|
||||
# $Id$
|
||||
|
||||
@ -138,13 +138,26 @@ if ($ans eq 'N') {
|
||||
|
||||
$remove_directory = 1;
|
||||
|
||||
if (!(-d $home_dir)) {
|
||||
if (-l $home_dir) {
|
||||
$real_home_dir = &resolvelink($home_dir);
|
||||
} else {
|
||||
$real_home_dir = $home_dir;
|
||||
}
|
||||
|
||||
#
|
||||
# If home_dir is a symlink and points to something that isn't a directory,
|
||||
# or if home_dir is not a symlink and is not a directory, don't remove
|
||||
# home_dir -- seems like a good thing to do, but probably isn't necessary...
|
||||
if (((-l $home_dir) && ((-e $real_home_dir) && !(-d $real_home_dir))) ||
|
||||
(!(-l $home_dir) && !(-d $home_dir))) {
|
||||
print STDERR "${whoami}: Home ${home_dir} is not a directory, so it won't be removed\n";
|
||||
$remove_directory = 0;
|
||||
} else {
|
||||
$dir_owner = (stat($home_dir))[4]; # UID
|
||||
}
|
||||
|
||||
if (length($real_home_dir) && -d $real_home_dir) {
|
||||
$dir_owner = (stat($real_home_dir))[4]; # UID
|
||||
if ($dir_owner != $uid) {
|
||||
print STDERR "${whoami}: Home dir ${home_dir} is not owned by ${login_name} (uid ${dir_owner})\n";
|
||||
print STDERR "${whoami}: Home dir ${real_home_dir} is not owned by ${login_name} (uid ${dir_owner})\n";
|
||||
$remove_directory = 0;
|
||||
}
|
||||
}
|
||||
@ -377,11 +390,26 @@ sub update_group_file {
|
||||
}
|
||||
|
||||
sub remove_dir {
|
||||
# Recursively remove directories
|
||||
# Remove the user's home directory
|
||||
local($dir) = @_;
|
||||
local($linkdir);
|
||||
|
||||
if (-l $dir) {
|
||||
$linkdir = &resolvelink($dir);
|
||||
# Remove the symbolic link
|
||||
unlink($dir) ||
|
||||
warn "${whoami}: Warning: could not unlink symlink $dir: $!\n";
|
||||
if (!(-e $linkdir)) {
|
||||
#
|
||||
# Dangling symlink - just return now
|
||||
return;
|
||||
}
|
||||
# Set dir to be the resolved pathname
|
||||
$dir = $linkdir;
|
||||
}
|
||||
if (!(-d $dir)) {
|
||||
print STDERR "${whoami}: Error: $dir is not a directory\n";
|
||||
print STDERR "${whoami}: Warning: $dir is not a directory\n";
|
||||
unlink($dir) || warn "${whoami}: Warning: could not unlink $dir: $!\n";
|
||||
return;
|
||||
}
|
||||
system('/bin/rm', '-rf', $dir);
|
||||
@ -414,3 +442,22 @@ sub remove_at_jobs {
|
||||
print STDERR " done.\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub resolvelink {
|
||||
local($path) = @_;
|
||||
local($l);
|
||||
|
||||
while (-l $path && -e $path) {
|
||||
if (!defined($l = readlink($path))) {
|
||||
die "${whoami}: readlink on $path failed (but it should have worked!): $!\n";
|
||||
}
|
||||
if ($l =~ /^\//) {
|
||||
# Absolute link
|
||||
$path = $l;
|
||||
} else {
|
||||
# Relative link
|
||||
$path =~ s/\/[^\/]+\/?$/\/$l/; # Replace last component of path
|
||||
}
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user