###
###  Copyright 2000-2007 University of Illinois Board of Trustees
###  All rights reserved. 
###
###  RPC.pm - RPC configuration module for psgconf
###
###  Campus Information Technologies and Educational Services
###  University of Illinois at Urbana-Champaign
###


package PSGConf::Control::RPC;

use PSGConf::Action::svcs::setprop;
use PSGConf::Action::GenerateFile::etc_rpc;
use PSGConf::Data::Boolean;
use PSGConf::Data::Table;
use PSGConf::Data::List;
use PSGConf::Control::Packages qw(_add_pkgs);

use strict;


###############################################################################
###  decide() method
###############################################################################

sub decide
{
	my ($self, $psgconf) = @_;

	return
		if ($psgconf->data_obj('rpc_enable')->equals('false'));

	$psgconf->register_actions(
		PSGConf::Action::GenerateFile::etc_rpc->new(
			'name'         => '/etc/rpc',
			'description'  => 'RPC configuration file',
			entries        => $psgconf->data_obj('rpc')->get()
		)
	);

	if ( $psgconf->data_obj('platform')->match('solaris10') ) {
		$psgconf->register_actions(
			PSGConf::Action::svcs::setprop->new(
				name			=> 'enable TCP Wrappers for rpcbind',
				FMRI			=> 'svc:/network/rpc/bind',
				property		=> 'config/enable_tcpwrappers',
				value		=> 'true'
			)
		);
	}
}


###############################################################################
###  policy methods
###############################################################################

### add TCP wrappers entry
sub _policy_add_tcpwrapper_entry
{
     my ($self, $psgconf) = @_;
     my ($hosts);

     return
          if ( $psgconf->data_obj('rpc_enable')->equals('false') );

	### FIXME
     #$psgconf->data_obj('tcp_wrappers')->insert_row(
     #     { 1 => 'all' },
     #     [ 'rpcbind', $hosts, 'allow' ]
     #)
     #     if (! $psgconf->data_obj('tcp_wrappers')->find_row(
     #                    { 0 => qr/\brpcbind\b/ }));
}

sub _enable_rc_scripts
{
     my ($self, $psgconf) = @_;
	my ($cmd);

	###
	### Why can AIX and Linux be consistant and call the program
	### the same thing it is in the TCP Wrappers stanza  :(
	###
	$cmd = ($psgconf->data_obj('platform')->match('aix|linux'))
			? 'portmap'
			: 'rpcbind';

     $psgconf->data_obj('rc_scripts')->insert(
		{ $cmd => { 'state' => 'enable' }}
	) if ( $psgconf->data_obj('rpc_enable')->equals('true') );
}

###############################################################################
###  constructor
###############################################################################

sub new
{
	my ($class, $psgconf) = @_;
	my ($self);

	$self = {};
	bless($self, $class);

	### So that _add_pkgs knows which directives to look at
	$self->{name} = 'rpc';
	$self->{enable} = $self->{name} . '_enable';
	$self->{packages} = $self->{name} . '_packages';

	$psgconf->register_data(
		rpc_enable		=> PSGConf::Data::Boolean->new(
							value => 'false'
						),
		rpc				=> PSGConf::Data::Table->new(),
		rpc_packages		=> PSGConf::Data::List->new()
	);

	$psgconf->register_policy($self,
		rpc_add_packages	=> '_add_pkgs',
		rpc_enable_rc_scripts	=> '_enable_rc_scripts'
	);

	return $self;
}


###############################################################################
###  documentation
###############################################################################

1;

__END__

=head1 NAME

PSGConf::Control::RPC - psgconf control class for RPC configuration

=head1 SYNOPSIS

In F<psgconf_modules>:

  Control PSGConf::Control::RPC

=head1 DESCRIPTION

The B<PSGConf::Control::RPC> module provides a B<psgconf> control object
for configuring RPC services.  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<rpc_enable>

A B<PSGConf::Data::Boolean> object enabling the RPC module.

=item I<rpc_packages>

A B<PSGConf::Data::List> object containing the packages to install.

=item I<rpc>

A B<PSGConf::Data::Table> object containing the list of rpcs to put
into the F</etc/rpc> file.

=back

The constructor also registers the following policy method:

=over 4

=item I<rpc_add_packages>

Adds the packges listed in the C<rpc_packages> directive to the
C<pkg_install_list> list to be installed by the C<Packages>
Control module.

=back

=item decide()

=back

=head1 SEE ALSO

L<perl>

L<PSGConf>

L<PSGConf::Action::svcs::setprop>

L<PSGConf::Action::GenerateFile::etc_rpc>

L<PSGConf::Control::Packages>

L<PSGConf::Data::Boolean>

L<PSGConf::Data::Table>

L<PSGConf::Data::List>

L<psgconf-intro>

=cut



syntax highlighted by Code2HTML, v. 0.9.1