#!/opt/bin/perl # # NON-production program to generate ldif dump from mcdb table passwd # $Id$ # $Revision$ # $Source$ # use strict; $^W++; use DBI; use Getopt::Long; use Net::LDAP::LDIF; use Net::LDAP; use Net::LDAPS; #variables for options my $debug = ''; #debug mode my $passwd = ''; #update passwd info my $help = ''; #help msg my $verbose = ''; #verbose mode my $ldif = ''; #ldif file to write to my $entry = ''; #passwd entries my $i = ''; #counter my $fh = ''; #file handle #get the options and set up GetOptions( "help" => \$help, "debug" => \$debug, "verbose" => \$verbose, ); if ( $help ) { print <connect("dbi:Sybase:server=localhost;port=4100", "", ""); $dbh->do("use mydb"); #get data from passwd table my $sth = $dbh->prepare( "select login,password,crypt,uid,gid,gecos,home,shell from nsit..passwd" ); #defines for field positions my $PWLOGIN = 0; my $PWPASSWORD = 1; my $PWCRYPT = 2; my $PWUID = 3; my $PWGID = 4; my $PWGECOS = 5; my $PWHOME = 6; my $PWSHELl = 7; $sth->execute() || die; #load up multidimensional array my $pwarray = $sth->fetchall_arrayref(); #load all results into multi-dimensional array my %pwarrayindex; warn "Indexing Information ... \n" if $debug; for ( $i = 0; $i < scalar(@$pwarray); $i++ ) { if ( exists( $pwarrayindex{ $pwarray->[$i][0] } ) ) { $pwarrayindex{ $pwarray->[$i][0] } .= ",$i"; #add the index number } else { $pwarrayindex{ $pwarray->[$i][0] } = $i; } } #open up ldif file for writing $ldif = Net::LDAP::LDIF->new( $fh, "w" ); #load up the ldif file for ( $i = 0; $i < scalar(@$pwarray); $i++ ) { print qq($pwarray->[$i][0]); print qq($pwarray->[$i][1]); print qq($pwarray->[$i][2]); print qq($pwarray->[$i][3]); print qq($pwarray->[$i][4]); print qq($pwarray->[$i][5]); print qq($pwarray->[$i][6]); print qq($pwarray->[$i][7]); $ldif->write($pwarray->[$i][0]);//string $ldif->write($pwarray->[$i][1]);/string $ldif->write($pwarray->[$i][2]);//string $ldif->write($pwarray->[$i][3]);//int $ldif->write($pwarray->[$i][4]);//int $ldif->write($pwarray->[$i][5]);//string $ldif->write($pwarray->[$i][6]);//string $ldif->write($pwarray->[$i][7]);//string } $ldif->done();