1*0Sstevel@tonic-gate# Net::Config.pm 2*0Sstevel@tonic-gate# 3*0Sstevel@tonic-gate# Copyright (c) 2000 Graham Barr <gbarr@pobox.com>. All rights reserved. 4*0Sstevel@tonic-gate# This program is free software; you can redistribute it and/or 5*0Sstevel@tonic-gate# modify it under the same terms as Perl itself. 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gatepackage Net::Config; 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gaterequire Exporter; 10*0Sstevel@tonic-gateuse vars qw(@ISA @EXPORT %NetConfig $VERSION $CONFIGURE $LIBNET_CFG); 11*0Sstevel@tonic-gateuse Socket qw(inet_aton inet_ntoa); 12*0Sstevel@tonic-gateuse strict; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate@EXPORT = qw(%NetConfig); 15*0Sstevel@tonic-gate@ISA = qw(Net::LocalCfg Exporter); 16*0Sstevel@tonic-gate$VERSION = "1.10"; # $Id: //depot/libnet/Net/Config.pm#17 $ 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gateeval { local $SIG{__DIE__}; require Net::LocalCfg }; 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate%NetConfig = ( 21*0Sstevel@tonic-gate nntp_hosts => [], 22*0Sstevel@tonic-gate snpp_hosts => [], 23*0Sstevel@tonic-gate pop3_hosts => [], 24*0Sstevel@tonic-gate smtp_hosts => [], 25*0Sstevel@tonic-gate ph_hosts => [], 26*0Sstevel@tonic-gate daytime_hosts => [], 27*0Sstevel@tonic-gate time_hosts => [], 28*0Sstevel@tonic-gate inet_domain => undef, 29*0Sstevel@tonic-gate ftp_firewall => undef, 30*0Sstevel@tonic-gate ftp_ext_passive => 0, 31*0Sstevel@tonic-gate ftp_int_passive => 0, 32*0Sstevel@tonic-gate test_hosts => 1, 33*0Sstevel@tonic-gate test_exist => 1, 34*0Sstevel@tonic-gate); 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate# 37*0Sstevel@tonic-gate# Try to get as much configuration info as possible from InternetConfig 38*0Sstevel@tonic-gate# 39*0Sstevel@tonic-gate$^O eq 'MacOS' and eval <<TRY_INTERNET_CONFIG; 40*0Sstevel@tonic-gateuse Mac::InternetConfig; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate{ 43*0Sstevel@tonic-gatemy %nc = ( 44*0Sstevel@tonic-gate nntp_hosts => [ \$InternetConfig{ kICNNTPHost() } ], 45*0Sstevel@tonic-gate pop3_hosts => [ \$InternetConfig{ kICMailAccount() } =~ /\@(.*)/ ], 46*0Sstevel@tonic-gate smtp_hosts => [ \$InternetConfig{ kICSMTPHost() } ], 47*0Sstevel@tonic-gate ftp_testhost => \$InternetConfig{ kICFTPHost() } ? \$InternetConfig{ kICFTPHost()} : undef, 48*0Sstevel@tonic-gate ph_hosts => [ \$InternetConfig{ kICPhHost() } ], 49*0Sstevel@tonic-gate ftp_ext_passive => \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0, 50*0Sstevel@tonic-gate ftp_int_passive => \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0, 51*0Sstevel@tonic-gate socks_hosts => 52*0Sstevel@tonic-gate \$InternetConfig{ kICUseSocks() } ? [ \$InternetConfig{ kICSocksHost() } ] : [], 53*0Sstevel@tonic-gate ftp_firewall => 54*0Sstevel@tonic-gate \$InternetConfig{ kICUseFTPProxy() } ? [ \$InternetConfig{ kICFTPProxyHost() } ] : [], 55*0Sstevel@tonic-gate); 56*0Sstevel@tonic-gate\@NetConfig{keys %nc} = values %nc; 57*0Sstevel@tonic-gate} 58*0Sstevel@tonic-gateTRY_INTERNET_CONFIG 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gatemy $file = __FILE__; 61*0Sstevel@tonic-gatemy $ref; 62*0Sstevel@tonic-gate$file =~ s/Config.pm/libnet.cfg/; 63*0Sstevel@tonic-gateif ( -f $file ) { 64*0Sstevel@tonic-gate $ref = eval { local $SIG{__DIE__}; do $file }; 65*0Sstevel@tonic-gate if (ref($ref) eq 'HASH') { 66*0Sstevel@tonic-gate %NetConfig = (%NetConfig, %{ $ref }); 67*0Sstevel@tonic-gate $LIBNET_CFG = $file; 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate} 70*0Sstevel@tonic-gateif ($< == $> and !$CONFIGURE) { 71*0Sstevel@tonic-gate my $home = eval { local $SIG{__DIE__}; (getpwuid($>))[7] } || $ENV{HOME}; 72*0Sstevel@tonic-gate $home ||= $ENV{HOMEDRIVE} . ($ENV{HOMEPATH}||'') if defined $ENV{HOMEDRIVE}; 73*0Sstevel@tonic-gate if (defined $home) { 74*0Sstevel@tonic-gate $file = $home . "/.libnetrc"; 75*0Sstevel@tonic-gate $ref = eval { local $SIG{__DIE__}; do $file } if -f $file; 76*0Sstevel@tonic-gate %NetConfig = (%NetConfig, %{ $ref }) 77*0Sstevel@tonic-gate if ref($ref) eq 'HASH'; 78*0Sstevel@tonic-gate } 79*0Sstevel@tonic-gate} 80*0Sstevel@tonic-gatemy ($k,$v); 81*0Sstevel@tonic-gatewhile(($k,$v) = each %NetConfig) { 82*0Sstevel@tonic-gate $NetConfig{$k} = [ $v ] 83*0Sstevel@tonic-gate if($k =~ /_hosts$/ and $k ne "test_hosts" and defined($v) and !ref($v)); 84*0Sstevel@tonic-gate} 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate# Take a hostname and determine if it is inside the firewall 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gatesub requires_firewall { 89*0Sstevel@tonic-gate shift; # ignore package 90*0Sstevel@tonic-gate my $host = shift; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate return 0 unless defined $NetConfig{'ftp_firewall'}; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate $host = inet_aton($host) or return -1; 95*0Sstevel@tonic-gate $host = inet_ntoa($host); 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate if(exists $NetConfig{'local_netmask'}) { 98*0Sstevel@tonic-gate my $quad = unpack("N",pack("C*",split(/\./,$host))); 99*0Sstevel@tonic-gate my $list = $NetConfig{'local_netmask'}; 100*0Sstevel@tonic-gate $list = [$list] unless ref($list); 101*0Sstevel@tonic-gate foreach (@$list) { 102*0Sstevel@tonic-gate my($net,$bits) = (m#^(\d+\.\d+\.\d+\.\d+)/(\d+)$#) or next; 103*0Sstevel@tonic-gate my $mask = ~0 << (32 - $bits); 104*0Sstevel@tonic-gate my $addr = unpack("N",pack("C*",split(/\./,$net))); 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate return 0 if (($addr & $mask) == ($quad & $mask)); 107*0Sstevel@tonic-gate } 108*0Sstevel@tonic-gate return 1; 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate return 0; 112*0Sstevel@tonic-gate} 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gateuse vars qw(*is_external); 115*0Sstevel@tonic-gate*is_external = \&requires_firewall; 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate1; 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate__END__ 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate=head1 NAME 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gateNet::Config - Local configuration data for libnet 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate=head1 SYNOPSYS 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate use Net::Config qw(%NetConfig); 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate=head1 DESCRIPTION 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gateC<Net::Config> holds configuration data for the modules in the libnet 132*0Sstevel@tonic-gatedistribuion. During installation you will be asked for these values. 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gateThe configuration data is held globally in a file in the perl installation 135*0Sstevel@tonic-gatetree, but a user may override any of these values by providing their own. This 136*0Sstevel@tonic-gatecan be done by having a C<.libnetrc> file in their home directory. This file 137*0Sstevel@tonic-gateshould return a reference to a HASH containing the keys described below. 138*0Sstevel@tonic-gateFor example 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate # .libnetrc 141*0Sstevel@tonic-gate { 142*0Sstevel@tonic-gate nntp_hosts => [ "my_prefered_host" ], 143*0Sstevel@tonic-gate ph_hosts => [ "my_ph_server" ], 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate __END__ 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate=head1 METHODS 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gateC<Net::Config> defines the following methods. They are methods as they are 150*0Sstevel@tonic-gateinvoked as class methods. This is because C<Net::Config> inherits from 151*0Sstevel@tonic-gateC<Net::LocalCfg> so you can override these methods if you want. 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate=over 4 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate=item requires_firewall HOST 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gateAttempts to determine if a given host is outside your firewall. Possible 158*0Sstevel@tonic-gatereturn values are. 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate -1 Cannot lookup hostname 161*0Sstevel@tonic-gate 0 Host is inside firewall (or there is no ftp_firewall entry) 162*0Sstevel@tonic-gate 1 Host is outside the firewall 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gateThis is done by using hostname lookup and the C<local_netmask> entry in 165*0Sstevel@tonic-gatethe configuration data. 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate=back 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate=head1 NetConfig VALUES 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate=over 4 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate=item nntp_hosts 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate=item snpp_hosts 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate=item pop3_hosts 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate=item smtp_hosts 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate=item ph_hosts 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate=item daytime_hosts 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate=item time_hosts 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gateEach is a reference to an array of hostnames (in order of preference), 188*0Sstevel@tonic-gatewhich should be used for the given protocol 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate=item inet_domain 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gateYour internet domain name 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate=item ftp_firewall 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gateIf you have an FTP proxy firewall (B<NOT> an HTTP or SOCKS firewall) 197*0Sstevel@tonic-gatethen this value should be set to the firewall hostname. If your firewall 198*0Sstevel@tonic-gatedoes not listen to port 21, then this value should be set to 199*0Sstevel@tonic-gateC<"hostname:port"> (eg C<"hostname:99">) 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate=item ftp_firewall_type 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gateThere are many different ftp firewall products available. But unfortunately 204*0Sstevel@tonic-gatethere is no standard for how to traverse a firewall. The list below shows the 205*0Sstevel@tonic-gatesequence of commands that Net::FTP will use 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate user Username for remote host 208*0Sstevel@tonic-gate pass Password for remote host 209*0Sstevel@tonic-gate fwuser Username for firewall 210*0Sstevel@tonic-gate fwpass Password for firewall 211*0Sstevel@tonic-gate remote.host The hostname of the remote ftp server 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate=over 4 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate=item 0 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gateThere is no firewall 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate=item 1 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate USER user@remote.host 222*0Sstevel@tonic-gate PASS pass 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate=item 2 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate USER fwuser 227*0Sstevel@tonic-gate PASS fwpass 228*0Sstevel@tonic-gate USER user@remote.host 229*0Sstevel@tonic-gate PASS pass 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate=item 3 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate USER fwuser 234*0Sstevel@tonic-gate PASS fwpass 235*0Sstevel@tonic-gate SITE remote.site 236*0Sstevel@tonic-gate USER user 237*0Sstevel@tonic-gate PASS pass 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate=item 4 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate USER fwuser 242*0Sstevel@tonic-gate PASS fwpass 243*0Sstevel@tonic-gate OPEN remote.site 244*0Sstevel@tonic-gate USER user 245*0Sstevel@tonic-gate PASS pass 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate=item 5 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate USER user@fwuser@remote.site 250*0Sstevel@tonic-gate PASS pass@fwpass 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate=item 6 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate USER fwuser@remote.site 255*0Sstevel@tonic-gate PASS fwpass 256*0Sstevel@tonic-gate USER user 257*0Sstevel@tonic-gate PASS pass 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate=item 7 260*0Sstevel@tonic-gate 261*0Sstevel@tonic-gate USER user@remote.host 262*0Sstevel@tonic-gate PASS pass 263*0Sstevel@tonic-gate AUTH fwuser 264*0Sstevel@tonic-gate RESP fwpass 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate=back 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate=item ftp_ext_passive 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate=item ftp_int_pasive 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gateFTP servers normally work on a non-passive mode. That is when you want to 273*0Sstevel@tonic-gatetransfer data you have to tell the server the address and port to 274*0Sstevel@tonic-gateconnect to. 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gateWith some firewalls this does not work as the server cannot 277*0Sstevel@tonic-gateconnect to your machine (because you are behind a firewall) and the firewall 278*0Sstevel@tonic-gatedoes not re-write the command. In this case you should set C<ftp_ext_passive> 279*0Sstevel@tonic-gateto a I<true> value. 280*0Sstevel@tonic-gate 281*0Sstevel@tonic-gateSome servers are configured to only work in passive mode. If you have 282*0Sstevel@tonic-gateone of these you can force C<Net::FTP> to always transfer in passive 283*0Sstevel@tonic-gatemode; when not going via a firewall, by setting C<ftp_int_passive> to 284*0Sstevel@tonic-gatea I<true> value. 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate=item local_netmask 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gateA reference to a list of netmask strings in the form C<"134.99.4.0/24">. 289*0Sstevel@tonic-gateThese are used by the C<requires_firewall> function to determine if a given 290*0Sstevel@tonic-gatehost is inside or outside your firewall. 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate=back 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gateThe following entries are used during installation & testing on the 295*0Sstevel@tonic-gatelibnet package 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate=over 4 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate=item test_hosts 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gateIf true then C<make test> may attempt to connect to hosts given in the 302*0Sstevel@tonic-gateconfiguration. 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate=item test_exists 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gateIf true then C<Configure> will check each hostname given that it exists 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gate=back 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate=for html <hr> 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gateI<$Id: //depot/libnet/Net/Config.pm#17 $> 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate=cut 315