Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,142 @@
package Net::DNS::Resolver::MSWin32;
use strict;
use warnings;
our $VERSION = (qw$Id: MSWin32.pm 1812 2020-10-07 18:09:53Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::MSWin32 - MS Windows resolver class
=cut
use base qw(Net::DNS::Resolver::Base);
use Carp;
use constant WINHLP => defined eval 'require Win32::IPHelper'; ## no critic
use constant WINREG => defined eval 'use Win32::TieRegistry qw(KEY_READ REG_DWORD); 1'; ## no critic
our $Registry;
sub _init {
my $defaults = shift->_defaults;
my $debug = 0;
my $FIXED_INFO = {};
my $err = Win32::IPHelper::GetNetworkParams($FIXED_INFO);
croak "GetNetworkParams() error %u: %s\n", $err, Win32::FormatMessage($err) if $err;
if ($debug) {
require Data::Dumper;
print Data::Dumper::Dumper $FIXED_INFO;
}
my @nameservers = map { $_->{IpAddress} } @{$FIXED_INFO->{DnsServersList}};
$defaults->nameservers(@nameservers);
my $devolution = 0;
my $domainname = $FIXED_INFO->{DomainName} || '';
my @searchlist = grep {length} $domainname;
if (WINREG) {
# The Win32::IPHelper does not return searchlist.
# Make best effort attempt to get searchlist from the registry.
my @root = qw(HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Services);
my $leaf = join '\\', @root, qw(Tcpip Parameters);
my $reg_tcpip = $Registry->Open( $leaf, {Access => KEY_READ} );
unless ( defined $reg_tcpip ) { # Didn't work, Win95/98/Me?
$leaf = join '\\', @root, qw(VxD MSTCP);
$reg_tcpip = $Registry->Open( $leaf, {Access => KEY_READ} );
}
if ( defined $reg_tcpip ) {
my $searchlist = $reg_tcpip->GetValue('SearchList') || '';
push @searchlist, split m/[\s,]+/, $searchlist;
my ( $value, $type ) = $reg_tcpip->GetValue('UseDomainNameDevolution');
$devolution = defined $value && $type == REG_DWORD ? hex $value : 0;
}
}
# fix devolution if configured, and simultaneously
# eliminate duplicate entries (but keep the order)
my @list;
my %seen;
foreach (@searchlist) {
s/\.+$//;
push( @list, $_ ) unless $seen{lc $_}++;
next unless $devolution;
# while there are more than two labels, cut
while (s#^[^.]+\.(.+\..+)$#$1#) {
push( @list, $_ ) unless $seen{lc $_}++;
}
}
$defaults->searchlist(@list);
%$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
$defaults->_read_env;
return;
}
1;
__END__
=head1 SYNOPSIS
use Net::DNS::Resolver;
=head1 DESCRIPTION
This class implements the OS specific portions of C<Net::DNS::Resolver>.
No user serviceable parts inside, see L<Net::DNS::Resolver>
for all your resolving needs.
=head1 COPYRIGHT
Copyright (c)2003 Chris Reinhardt.
Portions Copyright (c)2009 Olaf Kolkman, NLnet Labs
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl>, L<Net::DNS>, L<Net::DNS::Resolver>
=cut

View File

@@ -0,0 +1,237 @@
package Net::DNS::Resolver::Recurse;
use strict;
use warnings;
our $VERSION = (qw$Id: Recurse.pm 1811 2020-10-05 08:24:23Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::Recurse - DNS recursive resolver
=head1 SYNOPSIS
use Net::DNS::Resolver::Recurse;
my $resolver = new Net::DNS::Resolver::Recurse();
$resolver->debug(1);
$resolver->hints('198.41.0.4'); # A.ROOT-SERVER.NET.
my $packet = $resolver->send( 'www.rob.com.au.', 'A' );
=head1 DESCRIPTION
This module is a subclass of Net::DNS::Resolver.
=cut
use base qw(Net::DNS::Resolver);
=head1 METHODS
This module inherits almost all the methods from Net::DNS::Resolver.
Additional module-specific methods are described below.
=head2 hints
This method specifies a list of the IP addresses of nameservers to
be used to discover the addresses of the root nameservers.
$resolver->hints(@ip);
If no hints are passed, the priming query is directed to nameservers
drawn from a built-in list of IP addresses.
=cut
my @hints;
my $root = [];
sub hints {
shift;
return @hints unless scalar @_;
$root = [];
@hints = @_;
return;
}
=head2 query, search, send
The query(), search() and send() methods produce the same result
as their counterparts in Net::DNS::Resolver.
$packet = $resolver->send( 'www.example.com.', 'A' );
Server-side recursion is suppressed by clearing the recurse flag in
query packets and recursive name resolution is performed explicitly.
The query() and search() methods are inherited from Net::DNS::Resolver
and invoke send() indirectly.
=cut
sub send {
my $self = shift;
my @conf = ( recurse => 0, udppacketsize => 1024 ); # RFC8109
return bless( {persistent => {'.' => $root}, %$self, @conf}, ref($self) )->_send(@_);
}
sub query_dorecursion { ## historical
my ($self) = @_; # uncoverable pod
$self->_deprecate('prefer $resolver->send(...)');
return &send;
}
sub _send {
my $self = shift;
my $query = $self->_make_query_packet(@_);
unless ( scalar(@$root) ) {
$self->_diag("resolver priming query");
$self->nameservers( scalar(@hints) ? @hints : $self->_hints );
my $packet = $self->SUPER::send(qw(. NS));
$self->_callback($packet);
$self->_referral($packet);
$root = $self->{persistent}->{'.'};
}
return $self->_recurse( $query, '.' );
}
sub _recurse {
my ( $self, $query, $apex ) = @_;
$self->_diag("using cached nameservers for $apex");
my $nslist = $self->{persistent}->{$apex};
$self->nameservers(@$nslist);
$query->header->id(undef);
my $reply = $self->SUPER::send($query);
$self->_callback($reply);
return unless $reply;
my $qname = lc( ( $query->question )[0]->qname );
my $zone = $self->_referral($reply) || return $reply;
return $reply if grep { lc( $_->owner ) eq $qname } $reply->answer;
return $self->_recurse( $query, $zone );
}
sub _referral {
my ( $self, $packet ) = @_;
return unless $packet;
my @auth = grep { $_->type eq 'NS' } $packet->answer, $packet->authority;
return unless scalar(@auth);
my $owner = lc( $auth[0]->owner );
my $cache = $self->{persistent}->{$owner};
return $owner if $cache && scalar(@$cache);
my @addr = grep { $_->can('address') } $packet->additional;
my @ip;
my @ns = map { lc( $_->nsdname ) } @auth;
foreach my $ns (@ns) {
push @ip, map { $_->address } grep { $ns eq lc( $_->owner ) } @addr;
}
$self->_diag("resolving glue for $owner") unless scalar(@ip);
@ip = $self->nameservers( $ns[0], $ns[-1] ) unless scalar(@ip);
$self->_diag("caching nameservers for $owner");
$self->{persistent}->{$owner} = \@ip;
return $owner;
}
=head2 callback
This method specifies a code reference to a subroutine,
which is then invoked at each stage of the recursive lookup.
For example to emulate dig's C<+trace> function:
my $coderef = sub {
my $packet = shift;
printf ";; Received %d bytes from %s\n\n",
$packet->answersize, $packet->answerfrom;
};
$resolver->callback($coderef);
The callback subroutine is not called
for queries for missing glue records.
=cut
sub callback {
my $self = shift;
( $self->{callback} ) = grep { ref($_) eq 'CODE' } @_;
return;
}
sub _callback {
my $callback = shift->{callback};
$callback->(@_) if $callback;
return;
}
sub recursion_callback { ## historical
my ($self) = @_; # uncoverable pod
$self->_deprecate('prefer $resolver->callback(...)');
&callback;
return;
}
1;
__END__
=head1 ACKNOWLEDGEMENT
This package is an improved and compatible reimplementation of the
Net::DNS::Resolver::Recurse.pm created by Rob Brown in 2002,
whose contribution is gratefully acknowledged.
=head1 COPYRIGHT
Copyright (c)2014,2019 Dick Franks.
Portions Copyright (c)2002 Rob Brown.
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<Net::DNS::Resolver>
=cut

View File

@@ -0,0 +1,90 @@
package Net::DNS::Resolver::UNIX;
use strict;
use warnings;
our $VERSION = (qw$Id: UNIX.pm 1811 2020-10-05 08:24:23Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::UNIX - Unix resolver class
=cut
use base qw(Net::DNS::Resolver::Base);
my @config_file = grep { -f $_ && -r _ } '/etc/resolv.conf';
my $dotfile = '.resolv.conf';
my @dotpath = grep {defined} $ENV{HOME}, '.';
my @dotfile = grep { -f $_ && -o _ } map {"$_/$dotfile"} @dotpath;
local $ENV{PATH} = '/bin:/usr/bin';
my $uname = eval {`uname -n 2>/dev/null`} || '';
chomp $uname;
my ( $host, @domain ) = split /\./, $uname, 2;
__PACKAGE__->domain(@domain);
sub _init {
my $defaults = shift->_defaults;
$defaults->_read_config_file($_) foreach @config_file;
%$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
$defaults->_read_config_file($_) foreach @dotfile;
$defaults->_read_env;
return;
}
1;
__END__
=head1 SYNOPSIS
use Net::DNS::Resolver;
=head1 DESCRIPTION
This class implements the OS specific portions of C<Net::DNS::Resolver>.
No user serviceable parts inside, see L<Net::DNS::Resolver>
for all your resolving needs.
=head1 COPYRIGHT
Copyright (c)2003 Chris Reinhardt.
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl>, L<Net::DNS>, L<Net::DNS::Resolver>
=cut

View File

@@ -0,0 +1,95 @@
package Net::DNS::Resolver::android;
use strict;
use warnings;
our $VERSION = (qw$Id: android.pm 1811 2020-10-05 08:24:23Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::android - Android resolver class
=cut
use base qw(Net::DNS::Resolver::Base);
my $config_file = 'resolv.conf';
my @config_path = ( $ENV{ANDROID_ROOT} || '/system' );
my @config_file = grep { -f $_ && -r _ } map {"$_/etc/$config_file"} @config_path;
my $dotfile = '.resolv.conf';
my @dotpath = grep {defined} $ENV{HOME}, '.';
my @dotfile = grep { -f $_ && -o _ } map {"$_/$dotfile"} @dotpath;
sub _init {
my $defaults = shift->_defaults;
my @nameserver;
for ( 1 .. 4 ) {
my $ret = `getprop net.dns$_` || next;
chomp $ret;
push @nameserver, $ret || next;
}
$defaults->nameserver(@nameserver) if @nameserver;
$defaults->_read_config_file($_) foreach @config_file;
%$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
$defaults->_read_config_file($_) foreach @dotfile;
$defaults->_read_env;
return;
}
1;
__END__
=head1 SYNOPSIS
use Net::DNS::Resolver;
=head1 DESCRIPTION
This class implements the OS specific portions of C<Net::DNS::Resolver>.
No user serviceable parts inside, see L<Net::DNS::Resolver>
for all your resolving needs.
=head1 COPYRIGHT
Copyright (c)2014 Dick Franks.
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl>, L<Net::DNS>, L<Net::DNS::Resolver>
=cut

View File

@@ -0,0 +1,179 @@
package Net::DNS::Resolver::cygwin;
use strict;
use warnings;
our $VERSION = (qw$Id: cygwin.pm 1811 2020-10-05 08:24:23Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::cygwin - Cygwin resolver class
=cut
use base qw(Net::DNS::Resolver::Base);
use IO::File;
sub _getregkey {
my @key = @_;
my $handle = IO::File->new( join( '/', @key ), '<' ) or return '';
my $value = <$handle> || '';
close($handle);
$value =~ s/\0+$//;
return $value;
}
sub _init {
my $defaults = shift->_defaults;
my $dirhandle;
my $root = '/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters';
unless ( -d $root ) {
# Doesn't exist, maybe we are on 95/98/Me?
$root = '/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/VxD/MSTCP';
-d $root || Carp::croak "can't read registry: $!";
}
# Best effort to find a useful domain name for the current host
# if domain ends up blank, we're probably (?) not connected anywhere
# a DNS server is interesting either...
my $domain = _getregkey( $root, 'Domain' ) || _getregkey( $root, 'DhcpDomain' );
# If nothing else, the searchlist should probably contain our own domain
# also see below for domain name devolution if so configured
# (also remove any duplicates later)
my $devolution = _getregkey( $root, 'UseDomainNameDevolution' );
my $searchlist = _getregkey( $root, 'SearchList' );
my @searchlist = ( $domain, split m/[\s,]+/, $searchlist );
# This is (probably) adequate on NT4
my @nt4nameservers;
foreach ( grep {length} _getregkey( $root, 'NameServer' ), _getregkey( $root, 'DhcpNameServer' ) ) {
push @nt4nameservers, split m/[\s,]+/;
last;
}
# but on W2K/XP the registry layout is more advanced due to dynamically
# appearing connections. So we attempt to handle them, too...
# opt to silently fail if something isn't ok (maybe we're on NT4)
# If this doesn't fail override any NT4 style result we found, as it
# may be there but is not valid.
# drop any duplicates later
my @nameservers;
my $dnsadapters = join '/', $root, 'DNSRegisteredAdapters';
if ( opendir( $dirhandle, $dnsadapters ) ) {
my @adapters = grep { !/^\.\.?$/ } readdir($dirhandle);
closedir($dirhandle);
foreach my $adapter (@adapters) {
my $ns = _getregkey( $dnsadapters, $adapter, 'DNSServerAddresses' );
until ( length($ns) < 4 ) {
push @nameservers, join '.', unpack( 'C4', $ns );
substr( $ns, 0, 4 ) = '';
}
}
}
my $interfaces = join '/', $root, 'Interfaces';
if ( opendir( $dirhandle, $interfaces ) ) {
my @ifacelist = grep { !/^\.\.?$/ } readdir($dirhandle);
closedir($dirhandle);
foreach my $iface (@ifacelist) {
my $ip = _getregkey( $interfaces, $iface, 'DhcpIPAddress' )
|| _getregkey( $interfaces, $iface, 'IPAddress' );
next unless $ip;
next if $ip eq '0.0.0.0';
foreach (
grep {length} _getregkey( $interfaces, $iface, 'NameServer' ),
_getregkey( $interfaces, $iface, 'DhcpNameServer' )
) {
push @nameservers, split m/[\s,]+/;
last;
}
}
}
@nameservers = @nt4nameservers unless @nameservers;
$defaults->nameservers(@nameservers);
# fix devolution if configured, and simultaneously
# eliminate duplicate entries (but keep the order)
my @list;
my %seen;
foreach (@searchlist) {
s/\.+$//;
push( @list, $_ ) unless $seen{lc $_}++;
next unless $devolution;
# while there are more than two labels, cut
while (s#^[^.]+\.(.+\..+)$#$1#) {
push( @list, $_ ) unless $seen{lc $_}++;
}
}
$defaults->searchlist(@list);
%$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
$defaults->_read_env;
return;
}
1;
__END__
=head1 SYNOPSIS
use Net::DNS::Resolver;
=head1 DESCRIPTION
This class implements the OS specific portions of C<Net::DNS::Resolver>.
No user serviceable parts inside, see L<Net::DNS::Resolver>
for all your resolving needs.
=head1 COPYRIGHT
Copyright (c)2003 Sidney Markowitz.
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl>, L<Net::DNS>, L<Net::DNS::Resolver>
=cut

View File

@@ -0,0 +1,85 @@
package Net::DNS::Resolver::os2;
use strict;
use warnings;
our $VERSION = (qw$Id: os2.pm 1811 2020-10-05 08:24:23Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::os2 - OS2 resolver class
=cut
use base qw(Net::DNS::Resolver::Base);
my $config_file = 'resolv';
my @config_path = ( $ENV{ETC} || '/etc' );
my @config_file = grep { -f $_ && -r _ } map {"$_/$config_file"} @config_path;
my $dotfile = '.resolv.conf';
my @dotpath = grep {$_} $ENV{HOME}, '.';
my @dotfile = grep { -f $_ && -o _ } map {"$_/$dotfile"} @dotpath;
sub _init {
my $defaults = shift->_defaults;
$defaults->_read_config_file($_) foreach @config_file;
%$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
$defaults->_read_config_file($_) foreach @dotfile;
$defaults->_read_env;
return;
}
1;
__END__
=head1 SYNOPSIS
use Net::DNS::Resolver;
=head1 DESCRIPTION
This class implements the OS specific portions of C<Net::DNS::Resolver>.
No user serviceable parts inside, see L<Net::DNS::Resolver>
for all your resolving needs.
=head1 COPYRIGHT
Copyright (c)2012 Dick Franks.
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl>, L<Net::DNS>, L<Net::DNS::Resolver>
=cut

View File

@@ -0,0 +1,183 @@
package Net::DNS::Resolver::os390;
use strict;
use warnings;
our $VERSION = (qw$Id: os390.pm 1811 2020-10-05 08:24:23Z willem $)[2];
=head1 NAME
Net::DNS::Resolver::os390 - IBM OS/390 resolver class
=cut
use base qw(Net::DNS::Resolver::Base);
use IO::File;
local $ENV{PATH} = join ':', grep {$_} qw(/bin /usr/bin), $ENV{PATH};
my $sysname = eval {`sysvar SYSNAME 2>/dev/null`} || '';
chomp $sysname;
my %RESOLVER_SETUP; ## placeholders for unimplemented search list elements
my @dataset = ( ## plausible places to seek resolver configuration
$RESOLVER_SETUP{GLOBALTCPIPDATA},
$ENV{RESOLVER_CONFIG}, # MVS dataset or Unix file name
"/etc/resolv.conf",
$RESOLVER_SETUP{SYSTCPD},
"//TCPIP.DATA", # <username>.TCPIP.DATA
"//'${sysname}.TCPPARMS(TCPDATA)'",
"//'SYS1.TCPPARMS(TCPDATA)'",
$RESOLVER_SETUP{DEFAULTTCPIPDATA},
"//'TCPIP.TCPIP.DATA'"
);
my $dotfile = '.resolv.conf';
my @dotpath = grep {$_} $ENV{HOME}, '.';
my @dotfile = grep { -f $_ && -o _ } map {"$_/$dotfile"} @dotpath;
my %option = ( ## map MVS config option names
NSPORTADDR => 'port',
RESOLVERTIMEOUT => 'retrans',
RESOLVERUDPRETRIES => 'retry',
SORTLIST => 'sortlist',
);
sub _init {
my $defaults = shift->_defaults;
my %stop;
local $ENV{PATH} = join ':', grep {$_} qw(/bin /usr/bin), $ENV{PATH};
foreach my $dataset ( Net::DNS::Resolver::Base::_untaint( grep {$_} @dataset ) ) {
eval {
local $_;
my @nameserver;
my @searchlist;
my $handle = IO::File->new( qq[cat "$dataset" 2>/dev/null], '-|' )
or die "$dataset: $!"; # "cat" able to read MVS datasets
while (<$handle>) {
s/[;#].*$//; # strip comment
s/^\s+//; # strip leading white space
next unless $_; # skip empty line
next if m/^\w+:/ && !m/^$sysname:/oi;
s/^\w+:\s*//; # discard qualifier
m/^(NSINTERADDR|nameserver)/i && do {
my ( $keyword, @ip ) = grep {defined} split;
push @nameserver, @ip;
next;
};
m/^(DOMAINORIGIN|domain)/i && do {
my ( $keyword, @domain ) = grep {defined} split;
$defaults->domain(@domain) unless $stop{domain}++;
next;
};
m/^search/i && do {
my ( $keyword, @domain ) = grep {defined} split;
push @searchlist, @domain;
next;
};
m/^option/i && do {
my ( $keyword, @option ) = grep {defined} split;
foreach (@option) {
my ( $attribute, @value ) = split m/:/;
$defaults->_option( $attribute, @value )
unless $stop{$attribute}++;
}
next;
};
m/^RESOLVEVIA/i && do {
my ( $keyword, $value ) = grep {defined} split;
$defaults->_option( 'usevc', $value eq 'TCP' )
unless $stop{usevc}++;
next;
};
m/^\w+\s*/ && do {
my ( $keyword, @value ) = grep {defined} split;
my $attribute = $option{uc $keyword} || next;
$defaults->_option( $attribute, @value )
unless $stop{$attribute}++;
};
}
close($handle);
$defaults->nameserver(@nameserver) if @nameserver && !$stop{nameserver}++;
$defaults->searchlist(@searchlist) if @searchlist && !$stop{search}++;
};
warn $@ if $@;
}
%$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
$defaults->_read_config_file($_) foreach @dotfile;
$defaults->_read_env;
return;
}
1;
__END__
=head1 SYNOPSIS
use Net::DNS::Resolver;
=head1 DESCRIPTION
This class implements the OS specific portions of C<Net::DNS::Resolver>.
No user serviceable parts inside, see L<Net::DNS::Resolver>
for all your resolving needs.
=head1 COPYRIGHT
Copyright (c)2017 Dick Franks.
All rights reserved.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl>, L<Net::DNS>, L<Net::DNS::Resolver>
=cut