###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### Resolver.pm - DNS resolver configuration module for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Control::Resolver;
use strict;
use PSGConf::Action::GenerateFile::resolv_conf;
use PSGConf::Data::List;
###############################################################################
### policy method
###############################################################################
sub _policy_default_search_list
{
my ($self, $psgconf) = @_;
my (@tmp);
if (! $psgconf->data_obj('dns_search')->count())
{
@tmp = split(/\./, $psgconf->data_obj('hostname')->get());
while (shift(@tmp) && @tmp > 1)
{
$psgconf->data_obj('dns_search')->add(join('.', @tmp));
}
}
}
###############################################################################
### decide() method
###############################################################################
sub decide
{
my ($self, $psgconf) = @_;
return
if (! $psgconf->data_obj('dns_servers')->count() );
$psgconf->register_actions(
PSGConf::Action::GenerateFile::resolv_conf->new(
name => '/etc/resolv.conf',
description => 'resolver configuration file',
dns_search => $psgconf->data_obj('dns_search')->get(),
dns_sortlist => $psgconf->data_obj('dns_sortlist')->get(),
dns_servers => $psgconf->data_obj('dns_servers')->get()
)
);
}
###############################################################################
### constructor
###############################################################################
sub new
{
my ($class, $psgconf) = @_;
my ($self);
$self = {};
bless($self, $class);
$self->{name} = 'Resolver';
$psgconf->register_data(
dns_search => PSGConf::Data::List->new(),
dns_sortlist => PSGConf::Data::List->new(),
dns_servers => PSGConf::Data::List->new()
);
$psgconf->register_policy($self,
resolver_default_search_list => '_policy_default_search_list'
);
return $self;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Control::Resolver - psgconf control class for DNS resolver configuration
=head1 SYNOPSIS
In F<psgconf_modules>:
Control PSGConf::Control::Resolver
=head1 DESCRIPTION
The B<PSGConf::Control::Resolver> module provides a B<psgconf> control object
for configuring DNS lookups. It supports the following methods:
=over 4
=item new()
The constructor. Its parameter is a reference to the B<PSGConf>
object. It registers the following data objects:
=over 4
=item I<dns_search>
A B<PSGConf::Data::List> object that contains an ordered list of domains
to try for DNS lookups.
=item I<dns_sortlist>
A B<PSGConf::Data::List> object that contains an ordered list of
network and netmask tuples to put into the DNS sortlist.
=item I<dns_servers>
A B<PSGConf::Data::List> object that contains an ordered list of DNS
servers.
=back
The constructor also registers the following policy method:
=over 4
=item I<resolver_default_search_list>
If I<dns_search> is not set, set it to start with the subdomain that the
I<hostname> object is in, and then iterates through all parent domains
until the top-level domain.
=back
=item decide()
If I<dns_servers> is set, instantiates and registers a
B<PSGConf::Action::GenerateFile::resolv_conf> object to create
F</etc/resolv.conf>.
=back
=head1 SEE ALSO
L<perl>
resolver(5)
L<PSGConf>
L<PSGConf::Action::GenerateFile::resolv_conf>
L<PSGConf::Data::List>
L<psgconf-intro>
=cut
syntax highlighted by Code2HTML, v. 0.9.1