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 NFS21 }22 $mesg = $ldap->unbind;Net::LDAP::LDIF will also write to an LDIF file from a set of Net::LDAP::Entry objects. So, here’sanother approach to your new user creation script:01 #!/usr/bin/perl -w02 use strict;03 use Net::LDAP::LDIF;0405 die "Usage is adduser.pl [username] [$newuid] ["realname"]\n" if length(@ARGV) != 2;0607 my $username = $ARGV[0];08 my $newuid = $ARGV[1];09 my $realname = $ARGV[2];1011 # Open a file for writing to - the w option12 my $ldif = Net::LDAP::LDIF->new( "file.ldif", "w");1314 my $entry = Net::LDAP::Entry->new();1516 # set DN17 $entry->dn("uid=$userid,ou=people,dc=example,dc=com");18 # You can add attributes all at once, or in as many operations as you like19 $entry->add (20 'cn' => $realname,21 'uid' => $userid,22 'uidNumber' => $newuid,23 'mail' => "$userid@example.com",24 'homeDirectory' => "/home/$userid",25 'objectclass' => [ 'person', 'inetOrgPerson',26 'posixAccount' ]27 );28 # Write the entry to the LDIF file29 $ldif->write_entry($entry);After this, you could use the following at the command line to make the change to the server ormove the file to another LDAP directory:ldapmodify -f file.ldif2-12. Querying LDAP with a ScriptThis script queries the LDAP database to find out which disks are available via NFS for a given machinename (see recipes 2-13 to 2-15 for more NFS information). Note that the attributes looked at here are'automountInformation' and 'automountMap'. If your LDAP information was imported from NIS, the NFSmappings may have different names, and you may need to adjust the search filter and the attributes toreturn.55Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!