Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Oct 2000 17:43:19 -0700 (PDT)
From:      Doug Barton <DougB@gorean.org>
To:        Warner Losh <imp@village.org>
Cc:        Gianmarco Giovannelli <gmarco@giovannelli.it>, stable@FreeBSD.ORG
Subject:   Re: username with - 
Message-ID:  <Pine.BSF.4.21.0010091741150.84731-200000@dt051n37.san.rr.com>
In-Reply-To: <200010091802.MAA13347@harmony.village.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Mon, 9 Oct 2000, Warner Losh wrote:

> In message <5.0.0.25.0.20001009083602.02993e90@194.184.65.4> Gianmarco Giovannelli writes:
> : Let's remove the check from rmuser : if a user is in the user db, rmuser 
> : must know how to wipe it from there :-)
> 
> Index: rmuser.perl
> ===================================================================
> RCS file: /home/imp/FreeBSD/CVS/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/09 18:00:58
> @@ -107,8 +107,8 @@
>  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*$/);
> +    die "Sorry, login name must not contain colons (:).\n"
> +	if ($login_name =~ /:/);
>  } else {
>      if ($affirm) {
>  	print STDERR "${whoami}: Error: -y option given without username!\n";
> 
> Nuff said?

	Actually the attached patch is more what I had in mind. If you
would rather go with your version, make sure to hit get_login_name() as
well. 

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

	Do YOU Yahoo!?


[-- Attachment #2 --]
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;
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0010091741150.84731-200000>