From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,e4ce2f02460124d3 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-07-24 11:53:47 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed-east.nntpserver.com!nntpserver.com!news-out.visi.com!hermes.visi.com!nntp1.roc.gblx.net!nntp.gblx.net!nntp.gblx.net!news.unh.edu!not-for-mail From: Paul A Sand Newsgroups: comp.unix.tru64 Subject: Re: corrupt /etc/passwd Date: Wed, 24 Jul 2002 18:53:45 +0000 (UTC) Organization: University of New Hampshire Message-ID: References: <3d3d52b5$1@eumel.hag.hilti.com> NNTP-Posting-Host: granite.unh.edu X-Trace: tabloid.unh.edu 1027536825 19235 132.177.137.16 (24 Jul 2002 18:53:45 GMT) X-Complaints-To: usenet@tabloid.unh.edu NNTP-Posting-Date: Wed, 24 Jul 2002 18:53:45 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.unix.tru64:8213 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 )