Date: Fri, 15 Mar 1996 19:18:20 -0700 From: "Aaron D. Gifford" <agifford@infowest.com> To: Richard Chang <richardc@CSUA.Berkeley.EDU> Cc: questions@freebsd.org Subject: Re: Passwords Message-ID: <2.2.32.19960316021820.006a06d0@infowest.com>
next in thread | raw e-mail | index | archive | help
> Now is there a way to regenerate passwd from pwd.db? Thanks! > >Richard > > > > I was bored, so I modified the script. It now requires two paramaters, an input database file, and an output filename. An optional "-p" (for public) switch may be specified as well. The script no longer has a configuration section, and I added a "usage" report with examples if the script believes that the arguments are not correct (too many, not enough, or invalid switch(es) specified). Just do a "./remaster.pl" to see the usage information, which should explain how to generate master.passwd files or passwd files. Aaron ----CUT-HERE---- #!/usr/bin/perl # # remaster.pl -- a utility to regenerate /etc/master.passwd from /etc/spwd.db # version 2 # # Copyright (C) 1996 Aaron D. Gifford (agifford@infowest.com) # All rights reserved. # # Use this or change it in any way you want, just don't pretend you wrote it, # even though you probably could, and in less time! *grin* # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Gee, wasn't THAT a mouthful! Wonder where I've seen THAT before... # sub usage { $msg = <<EOM; USAGE: ./remaster.pl [-p] <password-database-file> <output-filename> EXAMPLES: To build a new version of /etc/master.passwd from /etc/spwd.db: ./remaster.pl /etc/spwd.db /etc/master.passwd.new To build a new version of /etc/passwd from /etc/spwd.db: ./remaster.pl /etc/spwd.db /etc/passwd.new To build a new version of /etc/passwd from /etc/pwd.db: ./remaster.pl /etc/pwd.db /etc/passwd.new To test the script against existing passwd or master.passwd files, generate the new version(s) as above, then "diff" or "cmp" the output to the originals. There SHOULD be no difference. NOTE: Don't try to build a master.passwd file from the /etc/pwd.db since the pwd.db file does NOT contain the encrypted user passwords. Also, be sure to set ownership and permissions on all new files generated. A world-readable master.passwd file would be fun... NOT! EOM die $msg; } if ($ARGV[0] =~ /^\-/) { $arg = shift(@ARGV); &usage() if ($arg ne "-p"); $pub = 1; } else { $pub = 0; } &usage() if ($#ARGV != 1); ($database,$output) = @ARGV; $database =~ s/\.db$//; dbmopen(%PASS, $database, undef) || die "Couldn't open \"".$database.".db\" file: ".$!."\n"; open(FILE, ">".$output) || die "Unable to open \"".$output."\" for writing: ".$!."\n"; # Take a look at /usr/include/pwd.h for some more info, or the sources # for /usr/sbin/pwd_mkdb... Oh, I sure hope pwd.h doesn't change the "1""2""3" # key start characters anytime soon... :) # $PASS{"1".$username} = $entry; # $PASS{"2".$lineno} = $entry; # $PASS{"3".$uid} = $entry; for ($line = 1; defined($PASS{"2".pack("i",$line)}); $line++) { # Extract all the goodies ($username,$pass,$stuff) = split(/\0/, $PASS{"2".pack("i",$line)}, 3); ($uid,$gid,$change,$stuff) = unpack("i i i a*", $stuff); ($class,$gecos,$dir,$shell,$stuff) = split(/\0/, $stuff, 5); $expire = unpack("i", $stuff); $pass = "*" if ($pub); print FILE $username.":".$pass.":".$uid.":".$gid.":"; print FILE $class.":".$change.":".$expire.":" if (!$pub); print FILE $gecos.":".$dir.":".$shell."\n"; } close(FILE); dbmclose(%PASS); $line--; print "remaster.pl: ".$line." lines written to \"".$output."\"\n"; # DONE!!! ----CUT-HERE---- --=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-- Aaron D. Gifford InfoWest, 1845 W. Sunset Blvd, St. George, UT 84770 InfoWest Networking Phone: (801) 674-0165 FAX: (801) 673-9734 <agifford@infowest.com> Visit InfoWest at: "http://www.infowest.com/" ICBM: 37.07847 N, 113.57858 W "Southern Utah's Finest Network Connection" --=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2.2.32.19960316021820.006a06d0>