#!/usr/bin/perl -w



use strict;



my $outputCGP = "import.txt";



print "Starting\n";





open OUTFILE, "> $outputCGP" or die "Can't open $outputCGP: $!\n";

print OUTFILE "Name\tRealName\tUnixPassword\n";



my ($dn,$givenname,$sn,$uid,$pass)=('','','','','');

while(my $idString=<>) {



  if ($idString =~ m/^dn:/) {

    $dn = $idString ;

  }



  if ($idString =~ m/^givenname: (.*)/i) {

   $givenname=$1;   

  }



  if ($idString =~ m/^sn: (.*)/i) {

   $sn=$1;   

  }



  if ($idString =~ m/^uid: (.*)/i) {

    $uid=$1;   

  }



  if ($idString =~ m/^userpassword: (.*)/i) {

    $pass=$1;

  }



  if ($idString eq "\n" && $dn ne '') {

    if (($uid ne '') && ($pass ne '')) {

      print OUTFILE $uid, "\t", $givenname, " ", $sn, "\t", $pass, "\n";

      $uid = $pass = $dn = '';

    } else {

      print "\nError: ", $dn, " doesn't have <uid> or <userpassword> attributes\n\n";

    }

  }





}



close OUTFILE;



exit(0);



__END__;

