###
###  Copyright 2000-2007 University of Illinois Board of Trustees
###  All rights reserved. 
###
###  sudoers.pm - psgconf action class to generate /etc/sudoers
###
###  Campus Information Technologies and Educational Services
###  University of Illinois at Urbana-Champaign
###


package PSGConf::Action::GenerateFile::sudoers;

use strict;

use PSGConf::Action::GenerateFile;

our @ISA = qw(PSGConf::Action::GenerateFile);


###############################################################################
###  generate() method
###############################################################################

sub generate
{
	my ($self, $fh, $psgconf) = @_;
	my ($cmd, $run_as_user, @userlist);

	print $fh "Defaults $self->{defaults}\n"
		if (defined($self->{defaults}));

	foreach $cmd (sort keys %{$self->{sudo}})
	{
		foreach $run_as_user (sort keys %{$self->{sudo}->{$cmd}})
		{
			print $fh join(',', sort keys %{$self->{sudo}->{$cmd}->{$run_as_user}});
			print $fh ' ' . $self->{hostname};
			print $fh "=($run_as_user)";
			print $fh ($self->{no_passwd}
				   ? 'NOPASSWD:'
				   : ' ');
			print $fh "$cmd\n";
		}
	}

	return 1;
}


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

1;

__END__

=head1 NAME

PSGConf::Action::GenerateFile::sudoers - generate /etc/sudoers file

=head1 SYNOPSIS

  use PSGConf::Action::GenerateFile::sudoers;

  $psgconf->register_actions(
		PSGConf::Action::GenerateFile::sudoers->new(
			'name'		=> '/etc/sudoers',
			'defaults'	=> '...',
			'sudo'		=> { ... },
			'no_passwd'	=> 0,
			...
		),
		...
	);

=head1 DESCRIPTION

The B<PSGConf::Action::GenerateFile::sudoers> module provides a B<PSGConf>
action class for generating the F</etc/sudoers> file.

The B<PSGConf::Action::GenerateFile::sudoers> class is derived from the
B<PSGConf::Action::GenerateFile> class, but it defines/overrides the
following methods:

=over 4

=item generate()

Generate the F</etc/sudoers> file.

=back

In addition to the attributes supported by
the B<PSGConf::Action::GenerateFile> class, the
B<PSGConf::Action::GenerateFile::sudoers> class supports the following
attributes:

=over 4

=item I<defaults>

Arguments for the C<Defaults> directive.  This attribute is optional.

=item I<sudo>

A hash mapping the command to a hash mapping the run-as user to a hash
whose keys are the names of users that are allowed to execute the
command as the run-as user.

=item I<hostname>

A string containing the system's hostname.

=item I<no_passwd>

A boolean value indicating whether to add C<NOPASSWD:> to each entry.

=back

=head1 BUGS

The structure of the I<sudo> attribute is cumbersome.

The I<no_passwd> attribute should be set on a per-entry basis, not
globally.

=head1 SEE ALSO

L<perl>

L<PSGConf>

L<PSGConf::Action::GenerateFile>

=cut




syntax highlighted by Code2HTML, v. 0.9.1