#!/usr/bin/perl -I/usr/lib/cmu # $Id: redoPasswd,v 1.1.2.2 2000/10/13 01:23:29 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; }