#!/bin/bash #---------------------------------------------------------------------- # reconfig-named # # Allows easy way to config a chroot bind environmet # # This software is distributed under the GPL V2 #---------------------------------------------------------------------- progname="reconfig-named" menutitle="Bind DNS reconfigurator" config_file="/etc/conf.d/named" check_root() { ####################### TEST ROOT PRIVILEDGES ####################### # test if program start as root, warn user and terminate program # if not started as root ##################################################################### if [ ! $(whoami) = "root" ] then # Access denied echo echo "This program requires root access to work properly." echo exit fi } check_dialog_bin() { ###################### LOOK FOR DIALOG BINARY ####################### # check if the dialog program is installed at /usr/bin/dialog. If # not warn the user and allow to install it using Pacman. ##################################################################### local answer if [ ! -f "/usr/bin/dialog" ] then echo echo "The dialog program could not be found, and $progname needs it" echo "to display dialog messages." echo echo -n "Do you want to install it using pacman (Y/N)? " read answer if [ $answer = "Y" ] || [ $answer = "y" ] then echo "Installing dialog with pacman, please wait..." pacman -S dialog else echo echo "Required program missing, cannot continue." echo exit fi fi } check_named_is_running() { ##################### LOOK IF NAMED IS RUNNING ###################### # check if the named daemon is running, and return true if it is ##################################################################### local retval declare -i retval=1 # default to think named is not running if [ -f /var/run/named/named.pid ] || [ -f /var/named/var/run/named/named.pid ]; then retval=0 fi return $retval } file_header() { ################### WRITE STANDARD HEADER FILE ###################### # Write standard header to /etc/rc.d/named file that is shared by # both environments ##################################################################### echo "#" > $config_file echo "# Parameters to be passed to BIND" >> $config_file echo "#" >> $config_file } mod_init_normal() { ################# NORMAL ENVIRONMENT MODE CHANGES ################### # Normal environment options will be set within this routine # making named work the usual Archlinux way ##################################################################### # write header to config file file_header # write named args for normal environment echo "NAMED_ARGS=\"-u named\"" >> $config_file # remove chroot directories if they exists rm -rf /var/named/{dev,var} } normal_env() { ################# CHECK NORMAL ENVIRONMENT STATUS ################### # Check if named is running prior to making changes to it. The # changes allow named work the usual Archlinux way ##################################################################### # before doing anything, check if bind is already configure in a # normal environment if [ -d /var/named/dev ] then if check_named_is_running then # stop service, do changes to config and restart named again /etc/rc.d/named stop /bin/sleep 1 mod_init_normal /etc/rc.d/named start else # named is not running, just do the changes mod_init_normal fi else echo "bind was previously configured for normal environment." fi } mod_init_chroot() { ################# CHROOT ENVIRONMENT MODE CHANGES ################### # Chroot environment options will be set within this routine ##################################################################### # write header to config file file_header # write named args for normal environment echo "NAMED_ARGS=\"-u named -t /var/named -c /etc/bind/named.conf\"" >> $config_file # add chroot directories and files mkdir /var/named/dev mkdir -p /var/named/var/run/named mkdir -p /var/named/var/log # create needed devices mknod /var/named/dev/null c 1 3 mknod /var/named/dev/random c 1 8 # syncronize bind time with system time cp /etc/localtime /var/named/etc # adjust ownership and priviledges of new files chmod 666 /var/named/dev/{null,random} chown -R named:named /var/named/var chown -R root:named /var/named/dev chown named:named /var/named/etc/localtime chmod 640 /var/named/etc/localtime } chroot_env() { ################# CHECK CHROOT ENVIRONMENT STATUS ################### # Check if named is running prior to making changes to it. The # changes allow named work under a chroot environment ##################################################################### # before doing anything, check if bind is already configure in a # chroot environment if [ ! -d /var/named/dev ] then if check_named_is_running then # stop service, do changes to config and restart named again /etc/rc.d/named stop mod_init_chroot /etc/rc.d/named start else # named is not running, just do the changes mod_init_chroot fi else echo "bind was previously configured for chroot environment." fi } ####################### MAIN MENU LOGIC ######################## # This loop handles the main menu functionality and invoke the # selected menu subroutine ################################################################ tempfile="/tmp/reconfig-named" # temp file to store menu choice # test root access check_root # check for /usr/bin/dialog check_dialog_bin dialog --backtitle "$progname" --nocancel --title "$menutitle" --menu "\nSelect how the named enviroment will reside \n \n" 13 50 3 1 "Normal environment" 2 "Chroot environment" 3 "Exit this menu" 2> $tempfile mynetsel=`cat $tempfile` case $mynetsel in 1) normal_env ;; # adjust named to work on a normal environment 2) chroot_env ;; # adjust named to work on a chroot environment esac # remove temporary file and exit rm $tempfile exit