Date: Thu, 13 Sep 2001 13:01:46 -0500 From: Brian Poole <raj@cerias.purdue.edu> To: freebsd-audit@freebsd.org Subject: Cleanup in adduser.perl Message-ID: <20010913130145.L1855@basm.cerias.purdue.edu>
next in thread | raw e-mail | index | archive | help
Hello, Cleaned up many similar problems in OpenBSD's adduser which was originally from Free, decided to mirror the changes where possible in FreeBSD's adduser. This patch hasn't been tested, but the changes are all relatively minor and should be correct. If someone could review & possibly commit, would be appreciated. Corrects: - grammar/spelling - correct initing of hashes (they were not being inited, scalars with the same names were) - optimization of file checking (eliminates multiple stat calls) - removal of unused variables - initializing $last before using it (just something I noticed when running with -w ) - removal of copyright sub (it is a null function, does nothing) - fix another misnamed variable ($verb -> $verbose) - flock goes before close, can't flock a closed handle - fix config_read's handling of $opt (it was taking a one element slice of the array, which means that if the -noconfig option was passed as the second or later option, it would not be detected even though it should have been.) Enjoy, -b --- adduser.perl.orig Fri Sep 7 16:05:14 2001 +++ adduser.perl Fri Sep 7 16:11:08 2001 @@ -62,9 +62,9 @@ # global variables # passwd - $username = ''; # $username{username} = uid - $uid = ''; # $uid{uid} = username - $pwgid = ''; # $pwgid{pwgid} = username; gid from passwd db + %username = (); # $username{username} = uid + %uid = (); # $uid{uid} = username + %pwgid = (); # $pwgid{pwgid} = username; gid from passwd db $password = ''; # password for new users $usepassword = ''; # use password-based auth @@ -72,13 +72,13 @@ $enableaccount = ''; # enable or disable account password at creation # group - $groupname =''; # $groupname{groupname} = gid - $groupmembers = ''; # $groupmembers{gid} = members of group/kommalist - $gid = ''; # $gid{gid} = groupname; gid form group db + %groupname = (); # $groupname{groupname} = gid + %groupmembers = (); # $groupmembers{gid} = members of group/kommalist + %gid = (); # $gid{gid} = groupname; gid form group db @group_comments; # Comments in the group file # shell - $shell = ''; # $shell{`basename sh`} = sh + %shell = (); # $shell{`basename sh`} = sh umask 022; # don't give login group write access @@ -96,7 +96,7 @@ local($err) = 0; print "Check $etc_shells\n" if $verbose; - open(S, $etc_shells) || die "$etc_shells:$!\n"; + open(S, $etc_shells) || die "$etc_shells: $!\n"; while(<S>) { if (/^\s*\//) { @@ -203,7 +203,7 @@ $h = &stripdir($h); # all right (I hope) - return $h if $h =~ "^/" && -e $h && -w $h && (-d $h || -l $h); + return $h if $h =~ "^/" && -e $h && -w _ && (-d _ || -l $h); # Errors or todo if ($h !~ "^/") { @@ -232,7 +232,7 @@ # read /etc/passwd sub passwd_read { - local($p_username, $pw, $p_uid, $p_gid, $sh, %shlist); + local($p_username, $pw, $p_uid, $p_gid, $sh); print "Check $etc_passwd\n" if $verbose; open(P, "$etc_passwd") || die "$etc_passwd: $!\n"; @@ -328,7 +328,7 @@ local($name) = @_; if ($name !~ /^[a-z0-9_][a-z0-9_\-]*$/ || $name eq "a-z0-9_-") { - warn "Wrong username. " . + warn "Illegal username. " . "Please use only lowercase characters or digits\a\n"; return 0; } elsif ($username{$name}) { @@ -878,7 +878,7 @@ # uniq(1) sub uniq { local(@list) = @_; - local($e, $last, @array); + local($e, $last = "", @array); foreach $e (sort @list) { push(@array, $e) unless $e eq $last; @@ -905,12 +905,6 @@ return $salt; } - -# print banner -sub copyright { - return; -} - # hints sub hints { if ($verbose) { @@ -972,7 +966,7 @@ # return 1 if $file is a readable file or link sub filetest { - local($file, $verb) = @_; + local($file, $verbose) = @_; if (-e $file) { if (-f $file || -l $file) { @@ -1314,9 +1308,9 @@ unless &confirm_yn("Try again?", "yes"); } print F join("\n", @list) . "\n"; - close F; print "Unlock $file.\n" if $verbose > 1; flock(F, $LOCK_UN); + close F; } # return free uid+gid @@ -1338,7 +1332,7 @@ $gid_start = $groupname{$group}; } # gid is in use, looking for another gid. - # Note: uid an gid are not equal + # Note: uid and gid are not equal elsif ($gid{$uid_start}) { while($gid{$gid_start} || $uid{$gid_start}) { $gid_start--; @@ -1350,7 +1344,7 @@ # read config file sub config_read { - local($opt) = @_; + local($opt) = join " ", @_; local($user_flag) = 0; # don't read config file @@ -1486,7 +1480,7 @@ &parse_arguments(@ARGV); # parse arguments if (!$check_only) { - ©right; &hints; + &hints; } # check To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010913130145.L1855>