Authen::Libwrap(3pm)
β¨ NAME β¨
okay so bestie, meet Authen::Libwrap β your all-access pass to Wietse Venema's TCP Wrappers library π
π¦ SYNOPSIS π¦
use Authen::Libwrap qw( hosts_ctl STRING_UNKNOWN );
# we know the remote username (using identd)
$rc = hosts_ctl(
"programname",
"hostname.domain.com",
"10.1.1.1",
"username"
);
print "Access is ", $rc ? "granted" : "refused", "\n";
# we don't know the remote username
$rc = hosts_ctl(
"programname",
"hostname.domain.com",
"10.1.1.1"),
);
print "Access is ", $rc ? "granted" : "refused", "\n";
# use a socket instead
my $client = $listener->accept();
$rc = hosts_ctl( "programname" $socket );
print "Access is ", $rc ? "granted" : "refused", "\n";
πΈ DESCRIPTION πΈ
So the tea is: Authen::Libwrap lets you reach into the hosts_ctl() function from the wildly popular TCP Wrappers security package. What does that get you? The ability to validate network access from your Perl programs against the system-wide hosts.allow file. It's giving "gatekeeping, but for sockets" π
And if any of the parameters to hosts_ctl() aren't known β like, say, the username, because there's no identd server doing its thing β you can just pass the constant STRING_UNKNOWN to the function instead. Crisis averted, fr fr π«Ά
π FUNCTIONS π
Authen::Libwrap has literally only one function, but she can be invoked in several ways, because she contains multitudes β¨
In every case: a true return code means the connection is allowed per the rules in hosts.allow, and an undef value means the opposite. No in-between, no maybes. It's giving binary π
hosts_ctl($daemon, $hostname, $ip_addr, [ $user ] )
Takes three mandatory arguments and one optional one.
$daemonβ the service you're requesting access to (think'ftpd'or'sendmail').$hostnameβ the name of the host requesting access.$ip_addrβ that host's IP address in dotted-quad notation.$userβ the name of the user requesting access. If it's unknown, you can just omit$user, andSTRING_UNKNOWNwill get passed in its place. Slay, no keystrokes wasted π
hosts_ctl($daemon, $socket, [ $user ] )
Got a socket instead? Iconic. If you have a socket β be it a glob, a glob reference, or an IO::Socket::INET β you can pass that as the second argument. The hostname and IP address will be determined using this socket π§
And if the hostname or IP address can't be determined from the socket? You already know the drill: STRING_UNKNOWN gets passed in their place π
π₯ DEBUGGING π₯
Wanna peek behind the curtain and see the exact arguments that are about to get handed to the C function hosts_ctl()? Set $Authen::Libwrap::DEBUG to a true value. That's it. That's the whole ritual. Main character behaviour πβ¨
π EXPORTS π
Nothing unless you ask for it. Consent is key π
hosts_ctlβ optionallySTRING_UNKNOWNβ optionally
π EXPORT_TAGS π
- functions
hosts_ctl
- constants
STRING_UNKNOWN
- all β everything the module has to offer. the whole buffet, bestie π
β CONSTANTS β
STRING_UNKNOWN
π BUGS AND FEATURES π
Please report any bugs or feature requests (and a pull request for bonus points) through the issue tracker at https://github.com/drmuey/p5-Authen-Libwrap/issues.
Now for the spicy bits:
- twist in hosts.allow Calls to
hosts_ctl()which match a line inhosts.allowthat uses the"twist"option will terminate the running perl program. π And no, this is not a bug in Authen::Libwrap per se β libwrap usesexec(3)to replace the running process with the specified program, so there's literally nothing to return to. Not "nothing returned", not "undef returned" β gone. Bye. π Some operating systems ship with a default catch-all rule inhosts.allowthat uses thetwistoption. You may have to modify that configuration to use Authen::Libwrap effectively. Consider this your vibe check. - Test suite is not comprehensive The test suite isn't very comprehensive because the path to
hosts.allowis set when libwrap is built, and I can't tell what the user's rules are. I can make sure the function calls don't die, but I can't really tell if any call tohosts_ctlshould give back a true or false value. It's giving "I did my best" π
π§ TODO π§
In early 2003 I was contacted by another Perl developer who had developed an XS interface to libwrap that covered more of the API than mine did. Originally he offered it as a patch to my module, but at the time I wasn't in a position to actively maintain anything on CPAN, so I suggested that he upload it himself. I unfortunately lost the email thread to a disk crash. π
As of December 2003 I don't see any other modules professing to support libwrap on CPAN. If that person is still out there, please get in contact with me, otherwise I'll plan on implementing some of these TODOs in the new year:
- provide support for
hosts_accessandrequest_*functions - develop an OO interface
π SEE ALSO π
Authen::Tcpdmatch β a Pure Perl module that can parse hosts.allow and hosts.deny if you don't need all the underlying features of libwrap. Lowkey the lighter-weight option if that's your vibe π¦
hosts_access(3), hosts_access(5), hosts_options(5)
Wietse's tools and papers page: ftp://ftp.porcupine.org/pub/security/index.html
π AUTHOR π
James FitzGibbon, <jfitz@CPAN.org>
okay that's the whole page, bestie, you're fully caught up π«Ά this was Authen::Libwrap(3pm) from the User Contributed Perl Documentation, brought to you by perl v5.42.3 and dated 2026-08-19. go forth and gatekeep those connections β¨π
π¦ where this page comes from
- ubuntu stonking: libauthen-libwrap-perl 0.23-3build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms