[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-developers] migration utility lose users passwords



Jeff Bilicki wrote:
> > > Try comparing the /etc/shadow entry for a user to the cmu.xml file, it
> > > should look like this:
> > > <user name="john">
> > >         <usrPasswd value="uc9/CqcRdFPg6"/>
> > >
> > > The entry in /etc/shadow and this value should match.
> > >

If you still have cmu.xml file on the system you can run the following
script to re-add all of the usrPasswd values into /etc/shadow.   

Jeff-

#!/usr/bin/perl -I/usr/lib/cmu
# $Id: redoPasswd,v 1.1.2.1 2000/10/13 01:12:03 jeffb Exp $
# Written by: Jeff Bilicki
# Goes back through the cmu.xml and pulls out the encypted passwords
# and adds them to /etc/shadow
# ./redoPasswd /location/of/xml/cmu.xml

die "You must run this script as root\n" if ($< != 0);

use CMU::Migrate;

my $cmuFile = $ARGV[0];
unless(-f $cmuFile) {
    print "Cannot find file $cmuFile\n";
    die "usage: $0 [FILE]\n";
}
my $mobj = CMU::Migrate->new();
$mobj->imptState($cmuFile);
for my $site ( @{ $mobj->{children} }) {
    next unless($site->{type} eq "vsite");
    warn "Processing site ", $site->{name}, "\n";
    for my $child ( @{ $site->{children} }) {
        next unless($child->{type} eq "user");
        setpwent;
        next unless((getpwnam($child->{name}))[0]);
        warn "Processing user", $child->{name},
            " with password ", $child->{usrPasswd}, "\n";
        my $ret = addPasswd($child->{name},$child->{usrPasswd});
        unless($ret) {
            warn "Error processing user ", $child->{name}, "\n";
        }
    }
}
exit;

sub addPasswd 
{
    my $userName = shift || return 0;
    my $passwd = shift || return 0;

    require FileHandle;
    my $Ptmp = "/etc/locks/ptmp";
    my $pwFile = "/etc/shadow";
    my $fhShadow = new FileHandle("< $pwFile");
    die "$0: Open failed: $pwFile: $!\n" if (!defined($fhShadow));
    my $fhPtmp = new FileHandle("> $Ptmp");
    die "$0: Open failed: $Ptmp: $!\n" if (!defined($fhPtmp));
    while (my $line = <$fhShadow>) {
        if ($line =~ /^$userName:\S+/ ) {
            my $end = "11198:0:99999:7:::\n";
            print $fhPtmp $userName.":".$passwd.":".$end;
        } else {
            print $fhPtmp $line;
        }
    }
    $fhPtmp->close();
    $fhShadow->close();
    my $ret = rename($Ptmp, $pwFile);
    return $ret;
}