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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 2 ■ CENTRALIZING YOUR NETWORK: KERBEROS, LDAP, AND NFS$entry->add ('cn'=> $realname,'uid'=> $userid,'uidNumber' => $newuid,'mail'=> '$userid@example.com','homeDirectory' => '/home/$userid','objectclass' => [ 'person', 'inetOrgPerson','posixAccount' ]);# Then update the LDAP server$entry->update( $ldap );Finally, the unbind operation in line 46 takes down the session when you’re finished. This shouldalways be the last thing you do with the LDAP server.■ Note See the documentation available on the project web site at http://ldap.perl.org/ for full details of thisset of modules and further examples.2-11. Modifying and Deleting Using LDAP ScriptsYou can also modify entries with Net::LDAP. This script will change all the email addresses in thedatabase from userid@mail.example.com to userid@example.com.■ Note This doesn’t check that the existing e-mail address is of the standard format, which in practice you wouldalmost certainly want to do. If you just want to check that the address was of the formatuserid@mail.example.com, you could change line 17–18 to these lines:my $email = $entry->get_value('mail');if ($email =~ /\w+\@mail.example.com/) {$mesg = $ldap->modify( $entry, replace => { 'mail' => '$uid@mail.example.com' } );}This assumes that the first part of all addresses consist only of word characters (alphabetic plus underscore) butcan obviously be altered.If you want to check e-mail address validity more generally, there are various modules that will do this, includingMail::Verify, Email::Valid, RFC::RFC822::Address, and Mail::RFC822::Address.52Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!