summaryrefslogtreecommitdiffstats
path: root/share/examples
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-08-11 13:03:25 +0000
committerwosch <wosch@FreeBSD.org>1996-08-11 13:03:25 +0000
commitb6b7ab5f10e6646df43349effd5daa3d124c1636 (patch)
treee2f4a65ed7d8e90dbedb338991a6f5005f2b5483 /share/examples
parenta9ad33617398ec6667e8bed56280a4ecc27719e5 (diff)
downloadFreeBSD-src-b6b7ab5f10e6646df43349effd5daa3d124c1636.zip
FreeBSD-src-b6b7ab5f10e6646df43349effd5daa3d124c1636.tar.gz
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>
Diffstat (limited to 'share/examples')
-rw-r--r--share/examples/removeuser/README.removeuser2
-rw-r--r--share/examples/removeuser/removeuser.87
-rw-r--r--share/examples/removeuser/removeuser.perl63
3 files changed, 57 insertions, 15 deletions
diff --git a/share/examples/removeuser/README.removeuser b/share/examples/removeuser/README.removeuser
index 28d354c..ac8ac4b 100644
--- a/share/examples/removeuser/README.removeuser
+++ b/share/examples/removeuser/README.removeuser
@@ -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.
diff --git a/share/examples/removeuser/removeuser.8 b/share/examples/removeuser/removeuser.8
index b17f557..b1b3d66 100644
--- a/share/examples/removeuser/removeuser.8
+++ b/share/examples/removeuser/removeuser.8
@@ -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
diff --git a/share/examples/removeuser/removeuser.perl b/share/examples/removeuser/removeuser.perl
index a0fd742..c2258e9 100644
--- a/share/examples/removeuser/removeuser.perl
+++ b/share/examples/removeuser/removeuser.perl
@@ -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;
+}
OpenPOWER on IntegriCloud