summaryrefslogtreecommitdiffstats
path: root/adduser
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2000-11-21 05:52:35 +0000
committerDoug Barton <dougb@FreeBSD.org>2000-11-21 05:52:35 +0000
commit0b1ad6939a0c56ca76eacbed6c8e656885e990f8 (patch)
treeca5a80a4eb27bf887dbcf54c85bade21ba666ff9 /adduser
parent3ab68a645db4e4f8d163f0bb0b6da5f74e392008 (diff)
downloadpw-darwin-0b1ad6939a0c56ca76eacbed6c8e656885e990f8.tar.gz
pw-darwin-0b1ad6939a0c56ca76eacbed6c8e656885e990f8.tar.zst
pw-darwin-0b1ad6939a0c56ca76eacbed6c8e656885e990f8.zip
If a user is in the database, rmuser ought to be able to remove them.
Address this by using getpwnam(), thus killing several birds with the same stone. My fix is slightly more aggressive than the originators. :) PR: misc/22278
Diffstat (limited to 'adduser')
-rw-r--r--adduser/rmuser.perl53
1 files changed, 11 insertions, 42 deletions
diff --git a/adduser/rmuser.perl b/adduser/rmuser.perl
index 8f6d56e..b3f1406 100644
--- a/adduser/rmuser.perl
+++ b/adduser/rmuser.perl
@@ -107,8 +107,6 @@ if ($< != 0) {
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,14 @@ if ($#ARGV == 0) {
$login_name = &get_login_name;
}
-if (($pw_ent = &check_login_name($login_name)) eq '0') {
+($name, $password, $uid, $gid, $change, $class, $gecos, $home_dir, $shell) = (getpwnam("$login_name"));
+
+if ($?) {
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 +132,7 @@ if ($uid == 0) {
}
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 +272,9 @@ sub get_login_name {
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 +284,6 @@ sub get_login_name {
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 +306,7 @@ sub get_yn {
}
sub update_passwd_file {
- local($skipped, $i);
+ local($skipped);
print STDERR "Updating password file,";
seek(MASTER_PW, 0, 0);
@@ -343,12 +315,9 @@ sub update_passwd_file {
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;