Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Allan Hawdon <udaa460@axolotl.kcl.ac.uk>
Subject: Re: Recovering Lost passwd file
Date: 1999/03/08	[thread overview]
Message-ID: <7c0re9$13m$1@willow.cc.kcl.ac.uk> (raw)
In-Reply-To: t0k8wxcfh4.fsf@oberon.ikp.liu.se

Erik Persson <erik@ikp.liu.se> wrote:
: "Ellefson" <ellefson@visi.com> 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;

=============================================================================



  reply	other threads:[~1999-03-08  5:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-04  5:00 Recovering Lost passwd file Ellefson
1999-03-04  5:00 ` Erik Persson
1999-03-08  5:00   ` Allan Hawdon [this message]
1999-03-11  5:00 ` Ron Feral
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox