Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Paul A Sand <pas@granite.unh.edu>
Subject: Re: corrupt /etc/passwd
Date: Wed, 24 Jul 2002 18:53:45 +0000 (UTC)	[thread overview]
Message-ID: <slrnajtttp.rjp.pas@granite.unh.edu> (raw)
In-Reply-To: 3d3d52b5$1@eumel.hag.hilti.com

In article <3d3d52b5$1@eumel.hag.hilti.com>, Skaghk wrote:
> There are two other files /etc/passwd.dir (as bad as passwd) and
> /etc/passwd.pag (readable but wired passwd fragments) which I think got
> created while /etc/passwd has been accessed rw last time. Running mkpasswd
> did blow up the system completely. Restoring those two files at least
> brought me bak to the original state.
> 
> Has anyone got an idea how to fix the /etc/passwd file?

I responded to the poster directly via e-mail, but on the off chance
anyone else is interested in my hacked-together script:

#!/usr/bin/perl

use NDBM_File;

tie(%PW, NDBM_File, "/etc/passwd", O_RDONLY, 0) ||
    die "Can't tie /etc/passwd: $!\n";

foreach $id (keys %PW) {
    $data = $PW{$id};
    $pos = 0;
    while (($c = substr($data, $pos++, 1)) ne "\0") {
	print $c;
    }
    print ":";
    while (($c = substr($data, $pos++, 1)) ne "\0") {
	print $c;
    }
    print ":";
    @nums = unpack("i i i", substr($data, $pos, 12));
    print "$nums[0]:$nums[1]:";
    $pos += 13;
    while (($c = substr($data, $pos++, 1)) ne "\0") {
	print $c;
    }
    print ":";
    while (($c = substr($data, $pos++, 1)) ne "\0") {
	print $c;
    }
    print ":";
    while (($c = substr($data, $pos++, 1)) ne "\0") {
	print $c;
    }
    print "\n";
}
untie(%PW);

Notes: The data values stored in the /etc/passwd.{dir,pag} 
hash are a mushed-together binary format resistent to elegant
solutions using unpack() or split(). Each password file line
has two entries in the hash: one for login keys, one for uid
keys; so this code outputs each user twice.
I suggested that the output be piped through 'sort -u'.

I tested this as much as possible on a Tru64 system... although
I didn't go as far as to blow away /etc/passwd.


-- 
-- Paul A. Sand                 | It might look like I'm doing
-- University of New Hampshire  | nothing, but at the cellular
-- pas@unh.edu                  | level I'm really quite busy.
-- http://pubpages.unh.edu/~pas | ( http://www.msd-corp.com/msd/humor.htm )


      parent reply	other threads:[~2002-07-24 18:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-23 12:57 corrupt /etc/passwd Skaghk
2002-07-23 14:11 ` Sylvain Robitaille
2002-07-24  5:32 ` Nikola Milutinovic
2002-07-24 10:04   ` Craig Markwardt
2002-07-24 12:05     ` Stuart Fuller
2002-07-24 12:24     ` Skaghk
2002-07-30 14:19       ` Michael Joosten
2002-07-31 18:42         ` Sylvain Robitaille
2002-08-05 14:42           ` Michael Joosten
2002-07-24 17:01   ` Rich Alderson
2002-07-24 18:53 ` Paul A Sand [this message]
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