:::::::::::::: ldap-dump-all.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-dump-all.pl,v 1.1 2007/07/11 15:35:02 kishi Exp kishi $ use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => "dc=OK-farm,dc=ne,dc=jp", filter => "objectclass=theUser" ); my $entry; foreach $entry ($mesg->entries) { $entry->dump; } :::::::::::::: ldap-dump-attr.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-dump-attr.pl,v 1.1 2007/07/11 15:35:04 kishi Exp kishi $ # Dump values of specified attributes use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => "dc=OK-farm,dc=ne,dc=jp", filter => "objectclass=theUser" ); my $entry; foreach $entry ($mesg->entries) { print join( "|" , $entry->get_value( myKey' ) , $entry->get_value( 'currAddr' ) , $entry->get_value( 'userTelNumber' ) , $entry->get_value( 'currStatus' ) ) . "\n"; } :::::::::::::: ldap-filter1.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-filter1.pl,v 1.1 2007/07/11 15:35:05 kishi Exp kishi $ # NOT operator use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => "dc=OK-farm,dc=ne,dc=jp", filter => '!(userTelNumber=0)' ); my $entry; foreach $entry ($mesg->entries) { $entry->dump; } :::::::::::::: ldap-filter2.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-filter2.pl,v 1.1 2007/07/11 15:35:06 kishi Exp kishi $ # OR operator use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => "dc=OK-farm,dc=ne,dc=jp", filter => '(|(isLockedOut=1)(userTelNumber=0))' ); my $entry; foreach $entry ($mesg->entries) { $entry->dump; } :::::::::::::: ldap-filter3.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-filter3.pl,v 1.1 2007/07/11 15:35:07 kishi Exp kishi $ # AND operator use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => "dc=OK-farm,dc=ne,dc=jp", filter => '(&(isLockedOut=1)(userTelNumber=0))' ); my $entry; foreach $entry ($mesg->entries) { $entry->dump; } :::::::::::::: ldap-filter4.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-filter4.pl,v 1.1 2007/07/11 15:35:07 kishi Exp kishi $ # AND operator use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => "dc=OK-farm,dc=ne,dc=jp", filter => '(currAddr=2*)' ); my $entry; foreach $entry ($mesg->entries) { $entry->dump; } :::::::::::::: ldap-findByPrimaryKey.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-findByPrimaryKey.pl,v 1.1 2007/07/11 15:35:07 kishi Exp kishi $ use strict; use Net::LDAP; if ( $#ARGV + 1 != 1 ){ print STDERR "Usage: $0 [LDAP_primary_Key]\n"; exit -1; } my $pKey = $ARGV[0]; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); #---------------------------------------- # perform a search #---------------------------------------- $mesg = $ldap->search( base => qq{ primaryKey=$pKey,dc=OK-farm,dc=ne,dc=jp}, filter => "objectclass=theUser" ); my $entry; foreach $entry ($mesg->entries) { $entry->dump; } :::::::::::::: ldap-modification1.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-modification1.pl,v 1.1 2007/07/11 15:35:07 kishi Exp kishi $ # Modify the values of specified attributes use strict; use Net::LDAP; use Net::LDAP::Entry; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); $mesg = $ldap->modify( "primaryKey=2020,dc=OK-farm,dc=ne,dc=jp", replace => { 'mailPassword' => '7361d38e8246d058' } ); :::::::::::::: ldap-modification2.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-modification2.pl,v 1.1 2007/07/11 15:35:08 kishi Exp kishi $ # Modify the values of specified attributes use strict; use Net::LDAP; use Net::LDAP::Entry; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- my $mesg = $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); $mesg = $ldap->modify( "primaryKey=210,dc=OK-farm,dc=ne,dc=jp", replace => { 'mailPassword' => '7361d38e8246d058' , 'isAvailable' => 1 } ); print $@ . "\n"; :::::::::::::: ldap-schema.pl :::::::::::::: #!/usr/bin/perl # $Id: ldap-schema.pl,v 1.1 2007/07/11 15:35:08 kishi Exp kishi $ use strict; use Net::LDAP; my $ldap = Net::LDAP->new( '192.168.0.192' ) or die "$@"; #---------------------------------------- # bind to a directory with dn and password #---------------------------------------- $ldap->bind( 'cn=X-O-JANMMS', password => 'OK-farmds' ); my $schema = $ldap->schema; #---------------------------------------- # get objectClasses #---------------------------------------- my @ocs = $schema->all_objectclasses; foreach my $oc (@ocs){ print $oc->{name} . "\n"; } #---------------------------------------- # Get the attributes #---------------------------------------- my @atts = $schema->all_attributes; foreach my $att (@atts){ print $att->{name} . "\n"; }