Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

620 lines
13 KiB

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15. #
  16. # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
  17. use strict;
  18. use IO::File;
  19. use Getopt::Std;
  20. use ExtUtils::MakeMaker qw(prompt);
  21. use vars qw($opt_d $opt_o);
  22. use Config;
  23. ##
  24. ##
  25. ##
  26. my %cfg = ();
  27. my @cfg = ();
  28. my($libnet_cfg,$msg,$ans,$def,$have_old);
  29. ##
  30. ##
  31. ##
  32. sub valid_host
  33. {
  34. my $h = shift;
  35. defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
  36. }
  37. ##
  38. ##
  39. ##
  40. sub test_hostnames (\@)
  41. {
  42. my $hlist = shift;
  43. my @h = ();
  44. my $host;
  45. my $err = 0;
  46. foreach $host (@$hlist)
  47. {
  48. if(valid_host($host))
  49. {
  50. push(@h, $host);
  51. next;
  52. }
  53. warn "Bad hostname: '$host'\n";
  54. $err++;
  55. }
  56. @$hlist = @h;
  57. $err ? join(" ",@h) : undef;
  58. }
  59. ##
  60. ##
  61. ##
  62. sub Prompt
  63. {
  64. my($prompt,$def) = @_;
  65. $def = "" unless defined $def;
  66. chomp($prompt);
  67. if($opt_d)
  68. {
  69. print $prompt,," [",$def,"]\n";
  70. return $def;
  71. }
  72. prompt($prompt,$def);
  73. }
  74. ##
  75. ##
  76. ##
  77. sub get_host_list
  78. {
  79. my($prompt,$def) = @_;
  80. $def = join(" ",@$def) if ref($def);
  81. my @hosts;
  82. do
  83. {
  84. my $ans = Prompt($prompt,$def);
  85. $ans =~ s/(\A\s+|\s+\Z)//g;
  86. @hosts = split(/\s+/, $ans);
  87. }
  88. while(@hosts && defined($def = test_hostnames(@hosts)));
  89. \@hosts;
  90. }
  91. ##
  92. ##
  93. ##
  94. sub get_hostname
  95. {
  96. my($prompt,$def) = @_;
  97. my $host;
  98. while(1)
  99. {
  100. my $ans = Prompt($prompt,$def);
  101. $host = ($ans =~ /(\S*)/)[0];
  102. last
  103. if(!length($host) || valid_host($host));
  104. $def =""
  105. if $def eq $host;
  106. print <<"EDQ";
  107. *** ERROR:
  108. Hostname `$host' does not seem to exist, please enter again
  109. or a single space to clear any default
  110. EDQ
  111. }
  112. length $host
  113. ? $host
  114. : undef;
  115. }
  116. ##
  117. ##
  118. ##
  119. sub get_bool ($$)
  120. {
  121. my($prompt,$def) = @_;
  122. chomp($prompt);
  123. my $val = Prompt($prompt,$def ? "yes" : "no");
  124. $val =~ /^y/i ? 1 : 0;
  125. }
  126. ##
  127. ##
  128. ##
  129. sub get_netmask ($$)
  130. {
  131. my($prompt,$def) = @_;
  132. chomp($prompt);
  133. my %list;
  134. @list{@$def} = ();
  135. MASK:
  136. while(1) {
  137. my $bad = 0;
  138. my $ans = Prompt($prompt) or last;
  139. if($ans eq '*') {
  140. %list = ();
  141. next;
  142. }
  143. if($ans eq '=') {
  144. print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
  145. next;
  146. }
  147. unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
  148. warn "Bad netmask '$ans'\n";
  149. next;
  150. }
  151. my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
  152. if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
  153. warn "Bad netmask '$ans'\n";
  154. next MASK;
  155. }
  156. foreach my $byte (@ip) {
  157. if ( $byte > 255 ) {
  158. warn "Bad netmask '$ans'\n";
  159. next MASK;
  160. }
  161. }
  162. my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
  163. if ($remove) {
  164. delete $list{$mask};
  165. }
  166. else {
  167. $list{$mask} = 1;
  168. }
  169. }
  170. [ keys %list ];
  171. }
  172. ##
  173. ##
  174. ##
  175. sub default_hostname
  176. {
  177. my $host;
  178. my @host;
  179. foreach $host (@_)
  180. {
  181. if(defined($host) && valid_host($host))
  182. {
  183. return $host
  184. unless wantarray;
  185. push(@host,$host);
  186. }
  187. }
  188. return wantarray ? @host : undef;
  189. }
  190. ##
  191. ##
  192. ##
  193. getopts('do:');
  194. $libnet_cfg = "$Config{installsitelib}/Net/libnet.cfg"
  195. unless(defined($libnet_cfg = $opt_o));
  196. my %oldcfg = ();
  197. $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
  198. if( -f $libnet_cfg )
  199. {
  200. %oldcfg = ( %{ do $libnet_cfg } );
  201. }
  202. elsif (eval { require Net::Config })
  203. {
  204. $have_old = 1;
  205. %oldcfg = %Net::Config::NetConfig;
  206. }
  207. map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
  208. $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
  209. $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
  210. #---------------------------------------------------------------------------
  211. if($have_old && !$opt_d)
  212. {
  213. $msg = <<EDQ;
  214. Ah, I see you already have installed libnet before.
  215. Do you want to modify/update your configuration (y|n) ?
  216. EDQ
  217. $opt_d = 1
  218. unless get_bool($msg,0);
  219. }
  220. #---------------------------------------------------------------------------
  221. $msg = <<EDQ;
  222. This script will prompt you to enter hostnames that can be used as
  223. defaults for some of the modules in the libnet distribution.
  224. To ensure that you do not enter an invalid hostname, I can perform a
  225. lookup on each hostname you enter. If your internet connection is via
  226. a dialup line then you may not want me to perform these lookups, as
  227. it will require you to be on-line.
  228. Do you want me to perform hostname lookups (y|n) ?
  229. EDQ
  230. $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
  231. print <<EDQ unless $cfg{'test_exist'};
  232. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  233. OK I will not check if the hostnames you give are valid
  234. so be very cafeful
  235. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  236. EDQ
  237. #---------------------------------------------------------------------------
  238. print <<EDQ;
  239. The following questions all require a list of host names, separated
  240. with spaces. If you do not have a host available for any of the
  241. services, then enter a single space, followed by <CR>. To accept the
  242. default, hit <CR>
  243. EDQ
  244. $msg = 'Enter a list of available NNTP hosts :';
  245. $def = $oldcfg{'nntp_hosts'} ||
  246. [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
  247. $cfg{'nntp_hosts'} = get_host_list($msg,$def);
  248. #---------------------------------------------------------------------------
  249. $msg = 'Enter a list of available SMTP hosts :';
  250. $def = $oldcfg{'smtp_hosts'} ||
  251. [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
  252. $cfg{'smtp_hosts'} = get_host_list($msg,$def);
  253. #---------------------------------------------------------------------------
  254. $msg = 'Enter a list of available POP3 hosts :';
  255. $def = $oldcfg{'pop3_hosts'} || [];
  256. $cfg{'pop3_hosts'} = get_host_list($msg,$def);
  257. #---------------------------------------------------------------------------
  258. $msg = 'Enter a list of available SNPP hosts :';
  259. $def = $oldcfg{'snpp_hosts'} || [];
  260. $cfg{'snpp_hosts'} = get_host_list($msg,$def);
  261. #---------------------------------------------------------------------------
  262. $msg = 'Enter a list of available PH Hosts :' ;
  263. $def = $oldcfg{'ph_hosts'} ||
  264. [ default_hostname('dirserv') ];
  265. $cfg{'ph_hosts'} = get_host_list($msg,$def);
  266. #---------------------------------------------------------------------------
  267. $msg = 'Enter a list of available TIME Hosts :' ;
  268. $def = $oldcfg{'time_hosts'} || [];
  269. $cfg{'time_hosts'} = get_host_list($msg,$def);
  270. #---------------------------------------------------------------------------
  271. $msg = 'Enter a list of available DAYTIME Hosts :' ;
  272. $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
  273. $cfg{'daytime_hosts'} = get_host_list($msg,$def);
  274. #---------------------------------------------------------------------------
  275. $msg = <<EDQ;
  276. Do you have a firewall/ftp proxy between your machine and the internet
  277. If you use a SOCKS firewall answer no
  278. (y|n) ?
  279. EDQ
  280. if(get_bool($msg,0)) {
  281. $msg = <<'EDQ';
  282. What series of FTP commands do you need to send to your
  283. firewall to connect to an external host.
  284. user/pass => external user & password
  285. fwuser/fwpass => firewall user & password
  286. 0) None
  287. 1) -----------------------
  288. USER [email protected]
  289. PASS pass
  290. 2) -----------------------
  291. USER fwuser
  292. PASS fwpass
  293. USER [email protected]
  294. PASS pass
  295. 3) -----------------------
  296. USER fwuser
  297. PASS fwpass
  298. SITE remote.site
  299. USER user
  300. PASS pass
  301. 4) -----------------------
  302. USER fwuser
  303. PASS fwpass
  304. OPEN remote.site
  305. USER user
  306. PASS pass
  307. 5) -----------------------
  308. USER user@[email protected]
  309. PASS pass@fwpass
  310. 6) -----------------------
  311. USER [email protected]
  312. PASS fwpass
  313. USER user
  314. PASS pass
  315. 7) -----------------------
  316. USER [email protected]
  317. PASS pass
  318. AUTH fwuser
  319. RESP fwpass
  320. Choice:
  321. EDQ
  322. $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
  323. $ans = Prompt($msg,$def);
  324. $cfg{'ftp_firewall_type'} = 0+$ans;
  325. $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
  326. $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
  327. }
  328. else {
  329. delete $cfg{'ftp_firewall'};
  330. }
  331. #---------------------------------------------------------------------------
  332. if (defined $cfg{'ftp_firewall'})
  333. {
  334. print <<EDQ;
  335. By default Net::FTP assumes that it only needs to use a firewall if it
  336. cannot resolve the name of the host given. This only works if your DNS
  337. system is setup to only resolve internal hostnames. If this is not the
  338. case and your DNS will resolve external hostnames, then another method
  339. is needed. Net::Config can do this if you provide the netmasks that
  340. describe your internal network. Each netmask should be entered in the
  341. form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
  342. EDQ
  343. $def = [];
  344. if(ref($oldcfg{'local_netmask'}))
  345. {
  346. $def = $oldcfg{'local_netmask'};
  347. print "Your current netmasks are :\n\n\t",
  348. join("\n\t",@{$def}),"\n\n";
  349. }
  350. print "
  351. Enter one netmask at each prompt, prefix with a - to remove a netmask
  352. from the list, enter a '*' to clear the whole list, an '=' to show the
  353. current list and an empty line to continue with Configure.
  354. ";
  355. my $mask = get_netmask("netmask :",$def);
  356. $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
  357. }
  358. #---------------------------------------------------------------------------
  359. ###$msg =<<EDQ;
  360. ###
  361. ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
  362. ###then enter a list of hostames
  363. ###
  364. ###Enter a list of available SOCKS hosts :
  365. ###EDQ
  366. ###
  367. ###$def = $cfg{'socks_hosts'} ||
  368. ### [ default_hostname($ENV{SOCKS5_SERVER},
  369. ### $ENV{SOCKS_SERVER},
  370. ### $ENV{SOCKS4_SERVER}) ];
  371. ###
  372. ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
  373. #---------------------------------------------------------------------------
  374. print <<EDQ;
  375. Normally when FTP needs a data connection the client tells the server
  376. a port to connect to, and the server initiates a connection to the client.
  377. Some setups, in particular firewall setups, can/do not work using this
  378. protocol. In these situations the client must make the connection to the
  379. server, this is called a passive transfer.
  380. EDQ
  381. if (defined $cfg{'ftp_firewall'}) {
  382. $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
  383. $def = $oldcfg{'ftp_ext_passive'} || 0;
  384. $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
  385. $msg = "\nShould all other FTP connections be passive (y|n) ?";
  386. }
  387. else {
  388. $msg = "\nShould all FTP connections be passive (y|n) ?";
  389. }
  390. $def = $oldcfg{'ftp_int_passive'} || 0;
  391. $cfg{'ftp_int_passive'} = get_bool($msg,$def);
  392. #---------------------------------------------------------------------------
  393. $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
  394. $ans = Prompt("\nWhat is your local internet domain name :",$def);
  395. $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
  396. #---------------------------------------------------------------------------
  397. $msg = <<EDQ;
  398. If you specified some default hosts above, it is possible for me to
  399. do some basic tests when you run `make test'
  400. This will cause `make test' to be quite a bit slower and, if your
  401. internet connection is via dialup, will require you to be on-line
  402. unless the hosts are local.
  403. Do you want me to run these tests (y|n) ?
  404. EDQ
  405. $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
  406. #---------------------------------------------------------------------------
  407. $msg = <<EDQ;
  408. To allow Net::FTP to be tested I will need a hostname. This host
  409. should allow anonymous access and have a /pub directory
  410. What host can I use :
  411. EDQ
  412. $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
  413. if $cfg{'test_hosts'};
  414. print "\n";
  415. #---------------------------------------------------------------------------
  416. chmod(0644, $libnet_cfg);
  417. my $fh = IO::File->new($libnet_cfg, "w") or
  418. die "Cannot create `$libnet_cfg': $!";
  419. print "Writing $libnet_cfg\n";
  420. print $fh "{\n";
  421. my $key;
  422. foreach $key (keys %cfg) {
  423. my $val = $cfg{$key};
  424. if(!defined($val)) {
  425. $val = "undef";
  426. }
  427. elsif(ref($val)) {
  428. $val = '[' . join(",",
  429. map {
  430. my $v = "undef";
  431. if(defined $_) {
  432. ($v = $_) =~ s/'/\'/sog;
  433. $v = "'" . $v . "'";
  434. }
  435. $v;
  436. } @$val ) . ']';
  437. }
  438. else {
  439. $val =~ s/'/\'/sog;
  440. $val = "'" . $val . "'" if $val =~ /\D/;
  441. }
  442. print $fh "\t'",$key,"' => ",$val,",\n";
  443. }
  444. print $fh "}\n";
  445. $fh->close;
  446. ############################################################################
  447. ############################################################################
  448. exit 0;
  449. __END__
  450. :endofperl