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


package PSGConf::Control::sudo;

use strict;

use PSGConf::Action::GenerateFile::sudoers;
use PSGConf::Action::Remove;
use PSGConf::Data::Boolean;
use PSGConf::Data::Hash;
use PSGConf::Data::List;
use PSGConf::Data::String;

use PSGConf::Control::Packages qw(_add_pkgs);


###############################################################################
###  Constructor
###############################################################################

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

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

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

	$psgconf->register_data(
		'sudo_enable'		=> PSGConf::Data::Boolean->new(
						value => 'false'
				        ),	
		'sudo'			=> PSGConf::Data::Hash->new(
						'value_type' => 'HASH'
					),
		'sudoers_path'		=> PSGConf::Data::String->new(
						'value_abspath' => 1,
						value => '/etc/sudoers'
					),
		'sudo_defaults'		=> PSGConf::Data::String->new(),
		'sudo_packages'		=> PSGConf::Data::List->new(),
		'sudo_nopasswd'		=> PSGConf::Data::Boolean->new(
						value => 'true'
					)
	);

	$psgconf->register_policy($self,
		sudo_add_packages	=> '_add_pkgs'
	);

	return $self;
}


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

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

	if ($psgconf->data_obj('sudo_enable')->equals('false')
		|| ! $psgconf->data_obj('sudo')->count())
	{
		$psgconf->register_actions(
			PSGConf::Action::Remove->new(
				'name'		=> $psgconf->data_obj('sudoers_path')->get()
			)
		);
		return;
	}

	$psgconf->register_actions(
		PSGConf::Action::GenerateFile::sudoers->new(
			'name'		=> $psgconf->data_obj('sudoers_path')->get(),
			'description'	=> 'sudo access control file',
			'mode'		=> 0440,
			'hostname'	=> $psgconf->data_obj('hostname')->get(),
			'defaults'	=> $psgconf->data_obj('sudo_defaults')->get(),
			'sudo'		=> $psgconf->data_obj('sudo')->get(),
			'no_passwd'	=> $psgconf->data_obj('sudo_nopasswd')->get()
		)
	);
}


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

1;

__END__

=head1 NAME

PSGConf::Control::sudo - psgconf control class for sudo

=head1 SYNOPSIS

In F<psgconf_modules>:

  Control PSGConf::Control::sudo

=head1 DESCRIPTION

The B<PSGConf::Control::sudo> module provides a B<psgconf> control object
for configuring C<sudo>.  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<sudo_enable>

A B<PSGConf::Data::Boolean> object indicating if we should use C<sudo>
on the system.  The default is no.

=item I<sudo>

A B<PSGConf::Data::Hash> object containing the permission entries for
F</etc/sudoers>.  The hash key is the command.  The value is a reference
to a hash whose key is the user to run the command as, and whose value
is a reference to yet another hash whose keys are the list of users who
are allowed to run the command as that user.

=item I<sudoers_path>

A B<PSGConf::Data::String> object containing the filename for the F<sudoers>
file.

=item I<sudo_defaults>

A B<PSGConf::Data::String> object containing the arguments for the
C<Defaults> directive in F</etc/sudoers>.

=item I<sudo_nopasswd>

A B<PSGConf::Data::Boolean> object indicating whether the user should
be required to enter a password when using C<sudo>.

=item I<sudo_packages>

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

=back

The constructor also registers the following policy method:

=over 4

=item I<sudo_add_packages>

If I<sudo> is defined, adds the C<sudo> package to the I<pkg_install_list>
object, which is provided by the B<PSGConf::Control::Packages> module.

=back

=item decide()

If I<sudo> is defined, it registers a
B<PSGConf::Action::GenerateFile::sudoers> action object to create the
C<sudo> config file.  Otherwise, registers a B<PSGConf::Action::Remove>
object to remove the C<sudo> config file.

=back

=head1 SEE ALSO

sudoers(4)

L<perl>

L<PSGConf>

L<PSGConf::Action::GenerateFile::sudoers>

L<PSGConf::Action::Remove>

L<PSGConf::Control::Packages>

L<PSGConf::Data::Boolean>

L<PSGConf::Data::Hash>

L<PSGConf::Data::List>

L<PSGConf::Data::String>

L<psgconf-intro>

=cut



syntax highlighted by Code2HTML, v. 0.9.1