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 NFS#!/bin/sh# Script to run automatic Kerberos dump & transfer to slave serverDUMPFILE=/etc/krb5kdc/slave_dump_fileRESULT=/etc/krb5kdc/slave_dump_resultSLAVE=server2.example.comMAIL=sysadmin@example.com/usr/sbin/kdb5_util dump $DUMPFILE/usr/sbin/kprop -f $DUMPFILE $SLAVE > $RESULTif grep -vq SUCCEEDED $RESULT ; thenmail -s "Kerberos replication problem" $MAIL < $RESULTfiPut this in the /etc/cron.hourly directory. If you want to run it more often, add a line to /etc/crontab at whatever interval you prefer; you’ll probably want to keep the file in /etc/cron.d/ in this case.2-10. Adding a New User to LDAP with a ScriptLDIF is a format used to make changes to the LDAP database, and it’s perfectly possible to add, delete,and modify records just by writing LDIF files and using ldapadd, ldapmodify, and ldapdelete. In fact,sometimes that’s the best option. However, it’s useful to be able to script those interactions.perl-ldap is a very useful collection of Perl modules providing an OO interface to LDAP servers. Toinstall the Debian/Ubuntu package, run this:sudo apt-get install libnet-ldap-perlOr you can install it from CPAN by running this as root:perl -m CPAN -e "install perl-ldap"The following script will add a new user, with parameters taken from the command line. You wouldneed to authenticate as the LDAP admin user before running it in full (the parts that just search shouldwork as any user).Net::LDAP and Net::LDAPS are the modules that handle connecting and talking to the server.Net::LDAP deals with regular LDAP connections, and Net::LDAPS deals with LDAPS (secure) connections(although Net::LDAP also has options to force an ldaps:/// connection and to handle TLS with thestart_tls() method).The following code connects to an LDAP server, makes an anonymous bind, performs a search tolook for the new username (to see whether it already exists), adds the user, and takes the session down:01 #!/usr/bin/perl -w02 use strict;0304 # Use whichever module matches your server05 #use Net::LDAP;06 use Net::LDAPS;49Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!