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 NFS01 #!/usr/bin/perl -w02 use strict;03 use Net::LDAPS;0405 my $ldap = Net::LDAPS->new( 'ldapserver.example.com',06 verify => 'optional',07 cafile => '/etc/ldap/cacert.pem' ) or die $@;08 my $mesg = $ldap->bind;0910 $mesg = $ldap->search( base => "ou=people,dc=example,dc=com",11 filter => "mail=*",12 attrs => [ 'uid', 'mail' ],13 );14 my @entries = $mesg->entries;1516 foreach my $entry ( @entries ) {17 $mesg = $ldap->modify( $entry, replace => { 'mail' => '$uid@mail.example.com'18 } );19 }2021 $mesg = ldap->unbindAlternatively, you could use the Net::LDAP::Entry replace method at lines 16–19:foreach my $entry ( @entries ) {$entry->replace(mail => "$uid\@mail.example.com",);$entry->update( $ldap );}Here you need to explicitly call the update method—without this, changes remain local and aren’tactually passed to the server. You don’t need to do this with the first method.Deleting EntriesIn the same way, you can delete an entry by DN. So, either of these two scripts would work:01 #!/usr/bin/perl -w02 use strict;03 use Net::LDAPS;0405 die "Usage is deluser.pl [username] 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 $@;53Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!