13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 2 ■ CENTRALIZING YOUR NETWORK: KERBEROS, LDAP, AND NFS12 my $mesg = $ldap->bind;1314 $mesg = $ldap->delete("uid=$username,ou=people,dc=example,dc=com");1516 $mesg = $ldap->unbind;01 #!/usr/bin/perl -w02 use strict;03 use Net::LDAPS;0405 die "Usage is deluser.pl [username]\n" if length(@ARGV) != 0;0607 my $username = $ARGV[0];0809 my $ldap = Net::LDAPS->new( 'ldapserver.example.com',10 verify => 'optional',11 cafile => '/etc/ldap/cacert.pem' ) or die $@;12 my $mesg = $ldap->bind;1314 my $entry = Net::LDAP::Entry->new;15 # Need to specify the DN of the entry16 $entry->dn("uid=$username,ou=people,dc=example,dc=com");17 $entry->delete;18 $entry->update( $ldap );19 $mesg = $ldap->unbind;It may be easier, however, to use LDIF in this situation. For example, you might want to readin from an LDIF file a list of entries to be deleted. Net::LDAP::LDIF will read LDIF files and generateNet::LDAP::Entry objects. This script reads in entries from a file, checks for errors in the reading process,and then deletes the entries:01 #!/usr/bin/perl -w02 use strict;03 use Net::LDAP::LDIF;0405 # Open a file for reading from - the r option06 my $ldif = Net::LDAP::LDIF->new( "file.ldif", "r");0708 my $ldap = Net::LDAPS->new( 'ldapserver.example.com',09 verify => 'optional',10 cafile => '/etc/ldap/cacert.pem' ) or die $@;11 my $mesg = $ldap->bind;1213 while( not $ldif->eof ( ) ) {14 $entry = $ldif->read_entry ( );15 if ( $ldif->error ( ) ) {16 print "Error msg: ", $ldif->error ( ), "\n";17 print "Error lines:\n", $ldif->error_lines ( ), "\n";18 } else {19 $mesg = $ldap->delete($entry);20 }54Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!