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


package PSGConf::Control::AIX;

use strict;

use PSGConf::Action::ModifyFile;
use PSGConf::Data::String;
use PSGConf::Data::List;


###############################################################################
###  PSGConf::Action::ModifyFile plugin for /etc/security/login.cfg
###############################################################################

sub _modify_etc_security_login_cfg
{
	my ($action, $infh, $fh, $psgconf) = @_;
	my ($line, $in_default);

	while ($line = <$infh>)
	{
		if ($line =~ m/^default:/)
		{
			$in_default = 1;
		}
		elsif ($in_default)
		{
			next
				if ($line =~ m/^\s*herald\s*=/);

			if ($line =~ m/^\s*$/)
			{
				print $fh "\therald = \""
					  . $psgconf->data_obj('console_login_prompt')->get()
					  . "\"\n";
				$in_default = 0;
			}
		}

		print $fh $line;
	}

	return 1;
}


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

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

	return
		if (!defined $psgconf->data_obj('console_login_prompt')->get());

	$psgconf->data_obj('console_login_prompt')->gsub(
		'%h',
		$psgconf->data_obj('hostname')->get()
	);
}


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

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

	return
		if (!defined $psgconf->data_obj('console_login_prompt')->get());

	$psgconf->register_actions(
		PSGConf::Action::ModifyFile->new(
			'name'		=> '/etc/security/login.cfg',
			'modify_func'	=> \&_modify_etc_security_login_cfg,
			'gid'		=> (getgrnam('security'))[2],
			'mode'		=> 0640
		)
	);
}


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

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

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

	$self->{name} = 'AIX';

	$psgconf->register_data(
		'console_login_prompt'	=> PSGConf::Data::String->new(),
		'refresh_daemons'		=> PSGConf::Data::List->new()
	);

	$psgconf->register_policy($self,
		login_prompt_expand_tokens => '_policy_expand_tokens'
	);

	return $self;
}


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

1;

__END__

=head1 NAME

PSGConf::Control::AIX - psgconf control class for AIX-specific files

=head1 SYNOPSIS

In F<psgconf_modules>:

  Control PSGConf::Control::AIX

=head1 DESCRIPTION

The B<PSGConf::Control::AIX> module provides a B<psgconf> control
object for configuring certain AIX-specific files.  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<console_login_prompt>

A B<PSGConf::Data::String> object that represents the contents of the
system's console login prompt.

=item I<refesh_daemons>

A B<PSGConf::Data::List> object that lists all the daemons that can be
used with the F</usr/bin/refresh> command.

=back

The constructor also registers the following policy methods:

=over 4

=item I<login_prompt_expand_tokens>

If the I<console_login_prompt> object is set, replaces the string "%h"
in the object's value with the value of the I<hostname> object (provided
by the B<PSGConf::Control::Core> module).

=back

=item decide()

If the I<console_login_prompt> object is set, it registers a
B<PSGConf::Action::ModifyFile> action to modify the "herald" attribute
in F</etc/security/login.cfg>.

=back

=head1 SEE ALSO

L<perl>

L<PSGConf>

L<PSGConf::Action::ModifyFile>

L<PSGConf::Data::List>

L<PSGConf::Data::String>

L<PSGConf::Control::Core>

L<psgconf-intro>

=cut



syntax highlighted by Code2HTML, v. 0.9.1