Re: How can I rescue my passwd file after corrupting it (and why does it still work) ?

2009-11-22 Thread Ruben de Groot
On Sun, Nov 22, 2009 at 08:14:00AM +, Matthew Seaman typed:
> 
> % pw user show -n matthew
> matthew:*:1001:1001::0:0:Matthew Seaman:/home/matthew:/bin/tcsh
> 
> prints out the master.passwd entry for the user account but *without* the
> password crypt-text.  You can use:
> 
>  % pw user show -a 
> 
> to get a list of all users.  This should use spwd.db rather than the 
> original
> flat files -- it will enumerate all users from LDAP or NIS if your machine 
> is
> configured to use those.  Unfortunately, you will have to merge in the 
> crypted
> password strings by hand or else get all your users to set new passwords.

Another way to recover is using perl:

while ( ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell,$expire) = 
getpwent ) {
print $name . ":" . $passwd . ":" . $uid . ":" . $gid . "::0:" . 
$expire . ":" . $gcos . ":" .$dir . ":" . $shell . "\n";
}

This will generate a file you can use to replace master.passwd, without
login class or passwd last changed information (if you use that) but
including the encrypted password.

Ruben
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: How can I rescue my passwd file after corrupting it (and why does it still work) ?

2009-11-22 Thread Matthew Seaman

George Sanders wrote:


I do some automated account creation on a FreeBSD 6.x system ... and 
unbeknownst to me, the '/' filesystem was completely full when I did my last 
account creation, resulting in:

/: write failed, filesystem is full
pwd_mkdb: /etc/pwd.db to /etc/pwd.db.tmp: No space left on device
pw: passwd file update: No space left on device
pwd_mkdb: corrupted entry
pwd_mkdb: at line #187
pwd_mkdb: /mnt/etc/master.passwd: Inappropriate file type or format

My situation is now as follows:

passwd and master.passwd have a lot of lines missing, and one or two mangled 
lines toward the end.  So a LOT of user accounts are gone.

BUT, all of those missing accounts still work.

So ... 


1) why do all of the accounts that are missing from both passwd and 
master.passwd continue to work properly (they can authenticate and log in over 
SSH and so on) ?

2) how can I get back to healthy ?

I suspect that somehow my (s)pwd.db files are still healthy ... is it possible 
to reconstruct complete passwd/master.passwd files using the existing (s)pwd.db 
files ?


There's a backup copy of master.passwd, groups and aliases stored in 
/var/backups
every time any of those files are changed -- the backups are created by the
overnight periodic cron jobs, so you should be able to restore yesterday's 
status
quo.

Otherwise, you can sort of reconstruct the missing entries from yor 
master.passwd
file by using pw(8) -- eg:

% pw user show -n matthew
matthew:*:1001:1001::0:0:Matthew Seaman:/home/matthew:/bin/tcsh

prints out the master.passwd entry for the user account but *without* the
password crypt-text.  You can use:

 % pw user show -a 


to get a list of all users.  This should use spwd.db rather than the original
flat files -- it will enumerate all users from LDAP or NIS if your machine is
configured to use those.  Unfortunately, you will have to merge in the crypted
password strings by hand or else get all your users to set new passwords.

Cheers,

Matthew

--
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
 Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
 Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature


How can I rescue my passwd file after corrupting it (and why does it still work) ?

2009-11-21 Thread George Sanders


I do some automated account creation on a FreeBSD 6.x system ... and 
unbeknownst to me, the '/' filesystem was completely full when I did my last 
account creation, resulting in:

/: write failed, filesystem is full
pwd_mkdb: /etc/pwd.db to /etc/pwd.db.tmp: No space left on device
pw: passwd file update: No space left on device
pwd_mkdb: corrupted entry
pwd_mkdb: at line #187
pwd_mkdb: /mnt/etc/master.passwd: Inappropriate file type or format

My situation is now as follows:

passwd and master.passwd have a lot of lines missing, and one or two mangled 
lines toward the end.  So a LOT of user accounts are gone.

BUT, all of those missing accounts still work.

So ... 

1) why do all of the accounts that are missing from both passwd and 
master.passwd continue to work properly (they can authenticate and log in over 
SSH and so on) ?

2) how can I get back to healthy ?

I suspect that somehow my (s)pwd.db files are still healthy ... is it possible 
to reconstruct complete passwd/master.passwd files using the existing (s)pwd.db 
files ?

Thank you.


  

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"