Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Oct 2000 09:25:47 -0700
From:      Doug Barton <DougB@gorean.org>
To:        "Brandon D. Valentine" <bandix@looksharp.net>
Cc:        Salvo Bartolotta <bartequi@inwind.it>, Chris Byrnes <chris@awww.jeah.net>, freebsd-questions@FreeBSD.ORG, Warner Losh <imp@village.org>
Subject:   Re: Removing user with "-" in username
Message-ID:  <39F5B80B.6FD8E3C7@gorean.org>
References:  <Pine.BSF.4.21.0010231703340.65525-100000@turtle.looksharp.net>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------14B89AA7EC04DEBC3E6D08F5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

"Brandon D. Valentine" wrote:
> 
> On Mon, 23 Oct 2000, Salvo Bartolotta wrote:
> 
> >Dear Brandon Valentine and Chris Byrnes,
> >
> >The following letter from Warner Losh is from my personal (local)
> >archives, reposted for your convenience.

	...

> Thank you, now if someone would commit that and then merge it back all
> would be well.

	I sent the attached more complete fix as a response to warner's,  but
never heard back (presumably due to 'con preparations). Without
objection I will probably commit this to -current once my account on
freefall gets setup. 

Doug
-- 
        "The dead cannot be seduced."
		- Kai, "Lexx"

	Do YOU Yahoo!?
--------------14B89AA7EC04DEBC3E6D08F5
Content-Type: text/plain; charset=us-ascii;
 name="rmuser.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="rmuser.diff"

Index: rmuser.perl
===================================================================
RCS file: /usr/ncvs/src/usr.sbin/adduser/rmuser.perl,v
retrieving revision 1.10
diff -u -r1.10 rmuser.perl
--- rmuser.perl	2000/03/14 14:27:34	1.10
+++ rmuser.perl	2000/10/10 00:38:03
@@ -107,8 +107,6 @@
 if ($#ARGV == 0) {
     # Username was given as a parameter
     $login_name = pop(@ARGV);
-    die "Sorry, login name must contain alphanumeric characters only.\n"
-	if ($login_name !~ /^[a-zA-Z0-9_]\w*$/);
 } else {
     if ($affirm) {
 	print STDERR "${whoami}: Error: -y option given without username!\n";
@@ -119,15 +117,13 @@
     $login_name = &get_login_name;
 }
 
-if (($pw_ent = &check_login_name($login_name)) eq '0') {
+if (not ($name, $password, $uid, $gid, $change, $class, $gecos, $home_dir,
+ $shell) = (getpwnam("$login_name"))) {
     print STDERR "${whoami}: Error: User ${login_name} not in password database\n";
     &unlockpw;
     exit 1;
 }
 
-($name, $password, $uid, $gid, $class, $change, $expire, $gecos, $home_dir,
- $shell) = split(/:/, $pw_ent);
-
 if ($uid == 0) {
     print "${whoami}: Error: I'd rather not remove a user with a uid of 0.\n";
     &unlockpw;
@@ -135,7 +131,7 @@
 }
 
 if (! $affirm) {
-    print "Matching password entry:\n\n$pw_ent\n\n";
+    print "Matching password entry:\n\n$name\:$password\:$uid\:$gid\:$class\:$change\:0\:$gecos\:$home_dir\:$shell\n\n";
 
     $ans = &get_yn("Is this the entry you wish to remove? ");
 
@@ -275,11 +271,9 @@
     for ($done = 0; ! $done; ) {
 	print "Enter login name for user to remove: ";
 	$login_name = <>;
-	chop $login_name;
-	if (!($login_name =~ /^[a-z0-9_][a-z0-9_\-]*$/)) {
-	    print STDERR "Sorry, login name must contain alphanumeric characters only.\n";
-	} elsif (length($login_name) > 16 || length($login_name) == 0) {
-	    print STDERR "Sorry, login name must be 16 characters or less.\n";
+	chomp $login_name;
+	if (not getpwnam("$login_name")) {
+	    print STDERR "Sorry, login name not in password database.\n";
 	} else {
 	    $done = 1;
 	}
@@ -289,29 +283,6 @@
     return($login_name);
 }
 
-sub check_login_name {
-    #
-    # Check to see whether login name is in password file
-    local($login_name) = @_;
-    local($Mname, $Mpassword, $Muid, $Mgid, $Mclass, $Mchange, $Mexpire,
-	  $Mgecos, $Mhome_dir, $Mshell);
-    local($i);
-
-    seek(MASTER_PW, 0, 0);
-    while ($i = <MASTER_PW>) {
-	chop $i;
-	($Mname, $Mpassword, $Muid, $Mgid, $Mclass, $Mchange, $Mexpire,
-	 $Mgecos, $Mhome_dir, $Mshell) = split(/:/, $i);
-	if ($Mname eq $login_name) {
-	    seek(MASTER_PW, 0, 0);
-	    return($i);		# User is in password database
-	}
-    }
-    seek(MASTER_PW, 0, 0);
-
-    return '0';			# User wasn't found
-}
-
 sub get_yn {
     #
     # Get a yes or no answer; return 'Y' or 'N'
@@ -334,7 +305,7 @@
 }
 
 sub update_passwd_file {
-    local($skipped, $i);
+    local($skipped);
 
     print STDERR "Updating password file,";
     seek(MASTER_PW, 0, 0);
@@ -343,12 +314,9 @@
     chmod(0600, $new_passwd_file) ||
 	print STDERR "\n${whoami}: Warning: couldn't set mode of $new_passwd_file to 0600 ($!)\n\tcontinuing, but please check mode of /etc/master.passwd!\n";
     $skipped = 0;
-    while ($i = <MASTER_PW>) {
-	if ($i =~ /\n$/) {
-	    chop $i;
-	}
-	if ($i ne $pw_ent) {
-	    print NEW_PW "$i\n";
+    while (<MASTER_PW>) {
+	if (not /^$login_name\:/io) {
+	    print NEW_PW;
 	} else {
 	    print STDERR "Dropped entry for $login_name\n" if $debug;
 	    $skipped = 1;

--------------14B89AA7EC04DEBC3E6D08F5--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?39F5B80B.6FD8E3C7>