Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* corrupt /etc/passwd
@ 2002-07-23 12:57 Skaghk
  2002-07-23 14:11 ` Sylvain Robitaille
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Skaghk @ 2002-07-23 12:57 UTC (permalink / raw)


Hi there,

I got a box running Tru64 V. 4.0 which got a blown up /etc/passwd. The file
currently consitst of 4096 characters of ASCII 0. Surprisingly users still
can log in and su to root also works well. Changing passwords ist the only
thing, that does not work.

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?

Thanx
S.

P.S. Comments containing the word "backup" will be ignored ;-)




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  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 18:53 ` Paul A Sand
  2 siblings, 0 replies; 11+ messages in thread
From: Sylvain Robitaille @ 2002-07-23 14:11 UTC (permalink / raw)


On Tue, 23 Jul 2002 14:57:22 +0200, Skaghk wrote:

> I got a box running Tru64 V. 4.0 which got a blown up /etc/passwd. The
> file currently consitst of 4096 characters of ASCII 0. Surprisingly
> users still can log in and su to root also works well. Changing
> passwords ist the only thing, that does not work.

Appended below my signature is the start of a Perl script which will
convert the /etc/passwd.dir and /etc/passwd.pag files into a not quite
complete /etc/passwd.txt.  You're going to need to either work on the
script to complete it (It was really written for .htpasswd files with
less information), or you'll need to go through the resulting passwd.txt
file and fix up userids, groupids, and take ':' characters out of the
GCOS field.  Whether you want to add to the script or fix up the output
manually probably depends on how many users you have...

When you're done, rename /etc/passwd.txt to /etc/passwd.

I'm sorry I don't have a more complete solution, but I hope this at
least helps get you started in the right direction.

Reloading from backup *would* be a *lot* easier, of course...  ;-)

-- 
----------------------------------------------------------------------
Sylvain Robitaille                              syl@alcor.concordia.ca
 
Systems analyst                                   Concordia University
Instructional & Information Technology        Montreal, Quebec, Canada
----------------------------------------------------------------------

#!/local/paths/perl -wT
#
# file: dbm2txt.pl
#
# 2000/08/30 Sylvain Robitaille: Quick hack to extract text password
#                                file from DBM file. 

my ($key, $value);
my ($db_file) = @ARGV;

if(!defined $db_file) {
  die "Usage:\n $0 <filename>\n";
}

# Untaint input:
if( $db_file =~ m%^([^`\\<>|]+)$% ) {
  $db_file = $1;
} else {
  die "$db_file tainted\n";
}

dbmopen  %PW, "$db_file", 0666 or die "can't dbmopen $db_file: $!\n";
open  TXTPW, "> $db_file.txt" or die "can't open $db_file.txt: $!\n";

# Make sure we'll be writing to the output file:
my $oldfh = select TXTPW;

# translate the input:
while (($key,$value) = each %PW) {
  $value =~ s/[\0\s]+/:/g;
  $value =~ s/:$//g;
  print "$value\n";
}

# Reset our stdout:
select $oldfh;

close TXTPW;
dbmclose %PW;



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  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 17:01   ` Rich Alderson
  2002-07-24 18:53 ` Paul A Sand
  2 siblings, 2 replies; 11+ messages in thread
From: Nikola Milutinovic @ 2002-07-24  5:32 UTC (permalink / raw)


"Skaghk" <skaghk@hotmail.com> wrote in message
news:3d3d52b5$1@eumel.hag.hilti.com...
> Hi there,
>
> I got a box running Tru64 V. 4.0 which got a blown up /etc/passwd. The
file
> currently consitst of 4096 characters of ASCII 0. Surprisingly users still
> can log in and su to root also works well. Changing passwords ist the only
> thing, that does not work.
>
> 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.

/etc/passwd.dir and /etc/passwd.pag are DBM files generated from /etc/passwd
by command "mkpasswd". As long as they are intact, you'll be able to login,
but nothing else. Restoring? Well, I suppose it can be restored, but I've
never seen a utility for that. Theoretically, you could write a small C
program to just open DBM version and read all keyes and write them to
STDOUT.

> Has anyone got an idea how to fix the /etc/passwd file?

Apart from writing a C program yourself? No.

Nix.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  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-24 17:01   ` Rich Alderson
  1 sibling, 2 replies; 11+ messages in thread
From: Craig Markwardt @ 2002-07-24 10:04 UTC (permalink / raw)



"Nikola Milutinovic" <Nikola.Milutinovic@ev.co.yu> writes:

> "Skaghk" <skaghk@hotmail.com> wrote in message
> news:3d3d52b5$1@eumel.hag.hilti.com...
> > Hi there,
> >
> > I got a box running Tru64 V. 4.0 which got a blown up /etc/passwd. The
> file
> > currently consitst of 4096 characters of ASCII 0. Surprisingly users still
> > can log in and su to root also works well. Changing passwords ist the only
> > thing, that does not work.
> >
> > 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.
> 
> /etc/passwd.dir and /etc/passwd.pag are DBM files generated from /etc/passwd
> by command "mkpasswd". As long as they are intact, you'll be able to login,
> but nothing else. Restoring? Well, I suppose it can be restored, but I've
> never seen a utility for that. Theoretically, you could write a small C
> program to just open DBM version and read all keyes and write them to
> STDOUT.

If the password database is still intact, and people can log in, then
won't the command "ypcat passwd" produce a legitimate ASCII version of
the password file?

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
--------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  2002-07-24 10:04   ` Craig Markwardt
@ 2002-07-24 12:05     ` Stuart Fuller
  2002-07-24 12:24     ` Skaghk
  1 sibling, 0 replies; 11+ messages in thread
From: Stuart Fuller @ 2002-07-24 12:05 UTC (permalink / raw)


Craig Markwardt wrote:

> 
> "Nikola Milutinovic" <Nikola.Milutinovic@ev.co.yu> writes:
> 
>> "Skaghk" <skaghk@hotmail.com> wrote in message
>> news:3d3d52b5$1@eumel.hag.hilti.com...
>> > Hi there,
>> >
>> > I got a box running Tru64 V. 4.0 which got a blown up /etc/passwd. The
>> file
>> > currently consitst of 4096 characters of ASCII 0. Surprisingly users
>> > still can log in and su to root also works well. Changing passwords ist
>> > the only thing, that does not work.
>> >
>> > 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.
>> 
>> /etc/passwd.dir and /etc/passwd.pag are DBM files generated from
>> /etc/passwd by command "mkpasswd". As long as they are intact, you'll be
>> able to login, but nothing else. Restoring? Well, I suppose it can be
>> restored, but I've never seen a utility for that. Theoretically, you
>> could write a small C program to just open DBM version and read all keyes
>> and write them to STDOUT.
> 
> If the password database is still intact, and people can log in, then
> won't the command "ypcat passwd" produce a legitimate ASCII version of
> the password file?
> 
> Craig
> 

Yes, "ypcat passwd" would produce a password file -- if the user was using 
NIS for distributing passwords.  However, his initial post does not 
indicate so, and since the files /etc/passwd.{dir|pag} are present, this 
indicates a local password file.

        Stu


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Skaghk @ 2002-07-24 12:24 UTC (permalink / raw)


>
> If the password database is still intact, and people can log in, then
> won't the command "ypcat passwd" produce a legitimate ASCII version of
> the password file?
>

It would, if I was using NIS, but I don't.

S.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  2002-07-24  5:32 ` Nikola Milutinovic
  2002-07-24 10:04   ` Craig Markwardt
@ 2002-07-24 17:01   ` Rich Alderson
  1 sibling, 0 replies; 11+ messages in thread
From: Rich Alderson @ 2002-07-24 17:01 UTC (permalink / raw)


"Nikola Milutinovic" <Nikola.Milutinovic@ev.co.yu> writes:

> /etc/passwd.dir and /etc/passwd.pag are DBM files generated from /etc/passwd
> by command "mkpasswd". As long as they are intact, you'll be able to login,
> but nothing else. Restoring? Well, I suppose it can be restored, but I've
> never seen a utility for that. Theoretically, you could write a small C
> program to just open DBM version and read all keyes and write them to STDOUT.

Perl has builtin support for treating DBM files as hash tables.  The following
Perl script should suffice to provide the information in the DBM version of
/etc/passwd:

	#!/usr/bin/perl -w

	use strict;

	dbmopen(%PASSWD, "/etc/passwd", undef)
		or die "Cannot open password database";

	while (my ($key, $value) = each (%DATA)) {
		print "$key:$value\n";
	}

Hope that helps.

-- 
Rich Alderson                                          alderson+news@panix.com
  "You get what anybody gets.  You get a lifetime."  --Death, of the Endless


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  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 18:53 ` Paul A Sand
  2 siblings, 0 replies; 11+ messages in thread
From: Paul A Sand @ 2002-07-24 18:53 UTC (permalink / raw)


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 )


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  2002-07-24 12:24     ` Skaghk
@ 2002-07-30 14:19       ` Michael Joosten
  2002-07-31 18:42         ` Sylvain Robitaille
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Joosten @ 2002-07-30 14:19 UTC (permalink / raw)


Skaghk wrote:
> 
> >
> > If the password database is still intact, and people can log in, then
> > won't the command "ypcat passwd" produce a legitimate ASCII version of
> > the password file?
> >
> 
> It would, if I was using NIS, but I don't.
> 
> S.

I havent checked this with Tru64, but the SunOS/Solaris versions of the
NIS tools habe a 'makedbm' with some 'unDBM' funtionality:

makedbm(1M)
.....
-u dbmfilename
     Undo a dbm file.  Prints out the file in text for-
     mat, one entry per line, with a single space sepa-
     rating keys from values.



-- 
Michael Joosten, SBS C-LAB, joost@c-lab.de
Fuerstenallee 11, 33094 Paderborn, Germany
Phone: +49 5251 606127, Fax: +49 5251 606065
C-LAB is a cooperation of University Paderborn & SIEMENS


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  2002-07-30 14:19       ` Michael Joosten
@ 2002-07-31 18:42         ` Sylvain Robitaille
  2002-08-05 14:42           ` Michael Joosten
  0 siblings, 1 reply; 11+ messages in thread
From: Sylvain Robitaille @ 2002-07-31 18:42 UTC (permalink / raw)


On Tue, 30 Jul 2002 16:19:28 +0200, Michael Joosten wrote:

> I havent checked this with Tru64, but the SunOS/Solaris versions of
> the NIS tools habe a 'makedbm' with some 'unDBM' funtionality:

Oh, man!  I thought this might have been the perfect answer, but on my
Tru64 Unix 4.0g system, with no NIS setup, the output is gibberish, I'm
afraid...

-- 
----------------------------------------------------------------------
Sylvain Robitaille                              syl@alcor.concordia.ca
 
Systems analyst                                   Concordia University
Instructional & Information Technology        Montreal, Quebec, Canada
----------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: corrupt /etc/passwd
  2002-07-31 18:42         ` Sylvain Robitaille
@ 2002-08-05 14:42           ` Michael Joosten
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Joosten @ 2002-08-05 14:42 UTC (permalink / raw)


Sylvain Robitaille wrote:
> 
> On Tue, 30 Jul 2002 16:19:28 +0200, Michael Joosten wrote:
> 
> > I havent checked this with Tru64, but the SunOS/Solaris versions of
> > the NIS tools habe a 'makedbm' with some 'unDBM' funtionality:
> 
Three typos in one sentence. Time for vacation, I believe...

> Oh, man!  I thought this might have been the perfect answer, but on my
> Tru64 Unix 4.0g system, with no NIS setup, the output is gibberish, I'm
> afraid...

Pity... Either Tru64 uses a different versions of 'dbm' functions for
passwd and NIS or a (simple?) encryption. 
Using 'strings' on the .pag file should yield something reasonable - at
least it does so with some old NIS files here.
-- 
Michael Joosten, SBS C-LAB, joost@c-lab.de
Fuerstenallee 11, 33094 Paderborn, Germany
Phone: +49 5251 606127, Fax: +49 5251 606065
C-LAB is a cooperation of University Paderborn & SIEMENS


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-08-05 14:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox