#!/usr/bin/perl
#
# logpopauth-pre
# smtp-poplock package by David Harris <dharris@drh.net>
#

use strict;

BEGIN:
{
	require POSIX;
	POSIX->import( qw (F_DUPFD) );
}

&main;

sub main
{
	# Print an error when missing the ipaddress
	if ( $ENV{'TCPREMOTEIP'} eq "" ) {
		print STDERR "logpopauth-pre: ERROR: the TCPREMOTEIP environment variable is blank\n";
	}

	# Dup the filehandle
	my $fno = fcntl STDERR, &F_DUPFD(), 10;

	if ( defined $fno ) {
		$ENV{'LOGPOPAUTH_FILENUM'} = $fno
	} else {
		print STDERR "logpopauth-pre: error duping filehandle: $!\n";
	}

	# Run our friend
	exec @ARGV;
	die "exec failed";
}

