From owner-freebsd-questions Tue Oct 24 9:26:24 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dt051n37.san.rr.com (dt051n37.san.rr.com [204.210.32.55]) by hub.freebsd.org (Postfix) with ESMTP id 47C6437B479 for ; Tue, 24 Oct 2000 09:26:20 -0700 (PDT) Received: from gorean.org (Studded@master [10.0.0.2]) by dt051n37.san.rr.com (8.9.3/8.9.3) with ESMTP id JAA88926; Tue, 24 Oct 2000 09:25:47 -0700 (PDT) (envelope-from DougB@gorean.org) Message-ID: <39F5B80B.6FD8E3C7@gorean.org> Date: Tue, 24 Oct 2000 09:25:47 -0700 From: Doug Barton Organization: Triborough Bridge & Tunnel Authority X-Mailer: Mozilla 4.75 [en] (X11; U; FreeBSD 5.0-CURRENT-102 i386) X-Accept-Language: en MIME-Version: 1.0 To: "Brandon D. Valentine" Cc: Salvo Bartolotta , Chris Byrnes , freebsd-questions@FreeBSD.ORG, Warner Losh Subject: Re: Removing user with "-" in username References: Content-Type: multipart/mixed; boundary="------------14B89AA7EC04DEBC3E6D08F5" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 = ) { - 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 = ) { - if ($i =~ /\n$/) { - chop $i; - } - if ($i ne $pw_ent) { - print NEW_PW "$i\n"; + while () { + 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