itsme_asif
asked on
Populating LDAP with test users
Hi,
i am looking for a code, where in i can populate say 100 users in a particular ou in ldap (iPlanet). I would be glad if the experts could help in figuring out a way for this
Thanks
i am looking for a code, where in i can populate say 100 users in a particular ou in ldap (iPlanet). I would be glad if the experts could help in figuring out a way for this
Thanks
http://search.cpan.org/~gbarr/perl-ldap-0.33/lib/Net/LDAP/Examples.pod
ASKER
Thanks a lot, can i have some more examples, i am kinda rusty with perl
What kind of directory are you talking about? x.500? Active Directory? NDS?
Here is an example for active directory.
use Win32::OLE 'in';
my $server = "MyServerName";
my $obj = Win32::OLE->GetObject("LDA P://$serve r/OU=iPlan et,DC=Doma in,DC=Com" );
open(USERS, "users.txt") || die "Could not find users.txt file\n";
@users = <USERS>;
close(USERS);
chomp(@users);
# users.txt should be a file formated like
# Charles,Dickens,cdickens,s crooge
# Emily,Walworth,ewalworth,c ookies
# etc...etc...
foreach my $user(@users) {
my($firstname,$lastname,$u serid,$pas sword) = split("\,",$user);
my $objUser = $obj->Create("user", "cn=$firstname $lastname");
$objUser->Put("sAMAccountN ame", "$userid");
$objUser->Put("userPrincip alName", "$userid\@domain.com");
$objUser->Put("givenName", "$firstname");
$objUser->Put("sn", "$lastname");
$objUser->Put("displayName ", "$firstname $lastname");
$objUser->SetInfo;
$objUser->SetPassword("$pa ssword");
$objUser->{AccountDisabled } = FALSE;
$objUser->SetInfo;
if(Win32::OLE::LastError() ) {
print Win32::OLE::LastError,"\n\ n";
}
else {
print "Created $firstname $lastname : $userid\n";
}
}
print "Done\n";
Here is an example for active directory.
use Win32::OLE 'in';
my $server = "MyServerName";
my $obj = Win32::OLE->GetObject("LDA
open(USERS, "users.txt") || die "Could not find users.txt file\n";
@users = <USERS>;
close(USERS);
chomp(@users);
# users.txt should be a file formated like
# Charles,Dickens,cdickens,s
# Emily,Walworth,ewalworth,c
# etc...etc...
foreach my $user(@users) {
my($firstname,$lastname,$u
my $objUser = $obj->Create("user", "cn=$firstname $lastname");
$objUser->Put("sAMAccountN
$objUser->Put("userPrincip
$objUser->Put("givenName",
$objUser->Put("sn", "$lastname");
$objUser->Put("displayName
$objUser->SetInfo;
$objUser->SetPassword("$pa
$objUser->{AccountDisabled
$objUser->SetInfo;
if(Win32::OLE::LastError()
print Win32::OLE::LastError,"\n\
}
else {
print "Created $firstname $lastname : $userid\n";
}
}
print "Done\n";
ASKER
I am looking for LDAP, i am using a iPlanet Directory Server 5.1 from Sun which is a LDAP. It would be really helpfull if you could give me a similar example as in AD.
I see. I am going to look into this a little more. I would use the perLdap module for this. I don't have enough information on iPlanet but I might find what I need to give you something to start with.
ASKER
Thanks a lot
what's wrong with
man Net::LDAP
as suggested by ozo?
Net::LDAP works perfect with iPlanet.
man Net::LDAP
as suggested by ozo?
Net::LDAP works perfect with iPlanet.
ASKER
do i have to download the package or if i add Net::LDAP in my code is enough? for example
use Net::LDAP;
$ldap = Net::LDAP->new( 'ldap.bigfoot.com' ) or die "$@";
$mesg = $ldap->bind ; # an anonymous bind
$mesg = $ldap->search( # perform a search
base => "c=US",
filter => "(&(sn=Barr) (o=Texas Instruments))"
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->entries) { $entry->dump; }
$mesg = $ldap->unbind; # take down session
$ldap = Net::LDAP->new( 'ldap.umich.edu' );
# bind to a directory with dn and password
$mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
password => 'secret'
);
$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US',
attr => [
'cn' => ['Barbara Jensen', 'Barbs Jensen'],
'sn' => 'Jensen',
'mail' => 'b.jensen@umich.edu',
'objectclass' => ['top', 'person',
'organizationalPerson',
'inetOrgPerson' ],
]
);
$result->code && warn "failed to add entry: ", $result->error ;
$mesg = $ldap->unbind; # take down session
would the above code work, with no modification (when the bind instructions are changes according to my directory)
use Net::LDAP;
$ldap = Net::LDAP->new( 'ldap.bigfoot.com' ) or die "$@";
$mesg = $ldap->bind ; # an anonymous bind
$mesg = $ldap->search( # perform a search
base => "c=US",
filter => "(&(sn=Barr) (o=Texas Instruments))"
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->entries) { $entry->dump; }
$mesg = $ldap->unbind; # take down session
$ldap = Net::LDAP->new( 'ldap.umich.edu' );
# bind to a directory with dn and password
$mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
password => 'secret'
);
$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US',
attr => [
'cn' => ['Barbara Jensen', 'Barbs Jensen'],
'sn' => 'Jensen',
'mail' => 'b.jensen@umich.edu',
'objectclass' => ['top', 'person',
'organizationalPerson',
'inetOrgPerson' ],
]
);
$result->code && warn "failed to add entry: ", $result->error ;
$mesg = $ldap->unbind; # take down session
would the above code work, with no modification (when the bind instructions are changes according to my directory)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.