From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,c785d8fd79fda27b X-Google-Attributes: gidfee84,public From: Allan Hawdon Subject: Re: Recovering Lost passwd file Date: 1999/03/08 Message-ID: <7c0re9$13m$1@willow.cc.kcl.ac.uk>#1/1 X-Deja-AN: 452607533 References: Organization: King's College London Newsgroups: comp.unix.osf.osf1 Erik Persson wrote: : "Ellefson" writes: :> I need to know if there is a way to recover a what appears to be a zeroed :> out passwd file by manipulating the passwd.pag. There is no backup, all the :> users were created in one evening (600 or so) and a backup could not be :> taken although I realize a cp of the /etc/passwd to /etc/passwd.bak, would :> of save my butt. It is not know as of yet what actually happened to the :> passwd file. But I would like to know up front before we start recreating :> them over again if we have a fighting chance at salvaging the lost passwd :> file. Thanks for you help! :> :> Jason : You will probably need both the .dir and .pag files, but if you have : these you could do it like this (if the names are passwd.pag and : passwd.dir): : makedbm -u passwd > passwd.restore This doesn't seem to work for the files in /etc, at least on my 4.0b box. The following perl script will do the trick. Use at your own risk, I haven't thoroughly tested it. You'll get duplicate records, so you'll want to pipe the output through sort & uniq. Allan ======================================================================= use strict; use NDBM_File; use Fcntl; use vars qw( $key $val %PASSWD ); use vars qw( $uname $pwd $uid $gid $gcos $dir $shell ); tie (%PASSWD, 'NDBM_File', '/etc/passwd', O_RDONLY, 0) or die "Can't open ($!)"; while ( ($key, $val) = each %PASSWD ) { ($uname,$pwd,$val) = split /\000/, $val, 3; ($uid, $gid) = unpack "LL", $val; $val = substr $val, 13; ($gcos,$dir,$shell) = split /\000/, $val; print "$uname:$pwd:$uid:$gid:$gcos:$dir:$shell\n"; } untie %PASSWD; =============================================================================