From b0ce51ec87d3c13f81fd15330a59dbbe390561ed Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 31 Oct 2010 17:23:47 -0700 Subject: [PATCH] More IPv6 friendly function conversions --- acl/save_sql.cgi | 4 +-- apache/create_virt.cgi | 3 +- apache/save_vserv.cgi | 9 +++--- bacula-backup/fixaddr.cgi | 2 +- bacula-backup/index.cgi | 2 +- bacula-backup/save_client.cgi | 3 +- bacula-backup/save_storage.cgi | 3 +- bsdexports/save_export.cgi | 4 +-- cluster-shutdown/save_sched.cgi | 53 +++++++++++++++++++++++++++++++++ custom/save_sql.cgi | 3 +- dfsadmin/save_share.cgi | 3 +- dhcpd/save_options.cgi | 4 +-- dhcpd/save_subnet.cgi | 2 +- exports/save_export.cgi | 2 +- fetchmail/fetchmail-lib.pl | 8 +++-- fetchmail/save_poll.cgi | 4 +-- 16 files changed, 83 insertions(+), 26 deletions(-) create mode 100755 cluster-shutdown/save_sched.cgi diff --git a/acl/save_sql.cgi b/acl/save_sql.cgi index c51613303..f0c413cdc 100755 --- a/acl/save_sql.cgi +++ b/acl/save_sql.cgi @@ -10,8 +10,8 @@ $p = $in{'proto'}; # Parse inputs if ($p eq 'mysql' || $p eq 'postgresql' || $p eq 'ldap') { - gethostbyname($in{$p."_host"}) || - $in{$p."_host"} =~ /^(\S+):(\d+)$/ && gethostbyname($1) || + &to_ipaddress($in{$p."_host"}) || + $in{$p."_host"} =~ /^(\S+):(\d+)$/ && &to_ipaddress("$1") || &error($text{'sql_ehost'}); $in{$p."_user"} =~ /^\S+$/ || &error($text{'sql_euser'}); $in{$p."_pass"} =~ /^\S*$/ || &error($text{'sql_epass'}); diff --git a/apache/create_virt.cgi b/apache/create_virt.cgi index 8c6191b97..906a33832 100755 --- a/apache/create_virt.cgi +++ b/apache/create_virt.cgi @@ -30,8 +30,7 @@ elsif ($in{'addr'} !~ /\S/) { } else { foreach $a (split(/\s+/, $in{'addr'})) { - gethostbyname($a) || &check_ipaddress($a) || - &check_ip6address($a) || + &to_ipaddress($a) || &to_ip6address($a) || &error(&text('cvirt_eaddr2', $a)); push(@addrs, &check_ip6address($a) ? "[$a]" : $a); } diff --git a/apache/save_vserv.cgi b/apache/save_vserv.cgi index 17297ac34..38717bb0b 100755 --- a/apache/save_vserv.cgi +++ b/apache/save_vserv.cgi @@ -47,8 +47,8 @@ else { local $ac = $a; $ac =~ s/:(\d+)$//; $ac eq '*' || $ac eq '_default_' || - gethostbyname($ac) || - $ac =~ /^\[(\S+)\]$/ && &check_ip6address("$1") || + &to_ipaddress($ac) || + $ac =~ /^\[(\S+)\]$/ && &to_ip6address("$1") || &error(&text('vserv_eaddr2', $ac)); } $addr = join(" ", @addrs); @@ -66,9 +66,8 @@ else { elsif ($in{'addr'} !~ /\S/) { &error($text{'vserv_eaddr1'}); } - elsif (!gethostbyname($in{'addr'}) && - !&check_ipaddress($in{'addr'}) && - !&check_ip6address($in{'addr'})) { + elsif (!&to_ipaddress($in{'addr'}) && + !&to_ip6address($in{'addr'})) { &error(&text('vserv_eaddr2', $in{'addr'})); } elsif (&check_ip6address($in{'addr'})) { diff --git a/bacula-backup/fixaddr.cgi b/bacula-backup/fixaddr.cgi index 02145df1a..0d81c05cf 100755 --- a/bacula-backup/fixaddr.cgi +++ b/bacula-backup/fixaddr.cgi @@ -7,7 +7,7 @@ require './bacula-backup-lib.pl'; $conconf = &get_bconsole_config(); $condir = &find("Director", $conconf); $addr = &get_system_hostname(); -if (!gethostbyname($addr)) { +if (!&to_ipaddress($addr) && !&to_ip6address($addr)) { $addr = "localhost"; } &save_directive($conconf, $condir, "Address", $addr, 1); diff --git a/bacula-backup/index.cgi b/bacula-backup/index.cgi index 182763446..804702986 100755 --- a/bacula-backup/index.cgi +++ b/bacula-backup/index.cgi @@ -59,7 +59,7 @@ if (&is_bacula_running("bacula-dir")) { $conconf = &get_bconsole_config(); $condir = &find("Director", $conconf); $conaddr = &find_value("Address", $condir->{'members'}); - if (!gethostbyname($conaddr)) { + if (!&to_ipaddress($conaddr) && !&to_ip6address($conaddr)) { # Offer to fix hostname print &text('index_econsole2', "$console_cmd", "$conaddr"),"

\n"; diff --git a/bacula-backup/save_client.cgi b/bacula-backup/save_client.cgi index abecfd5d6..ec74388be 100755 --- a/bacula-backup/save_client.cgi +++ b/bacula-backup/save_client.cgi @@ -45,7 +45,8 @@ else { $in{'pass'} || &error($text{'client_epass'}); &save_directive($conf, $client, "Password", $in{'pass'}, 1); - gethostbyname($in{'address'}) || &error($text{'client_eaddress'}); + &to_ipaddress($in{'address'}) || &to_ip6address($in{'address'}) || + &error($text{'client_eaddress'}); &save_directive($conf, $client, "Address", $in{'address'}, 1); $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 || diff --git a/bacula-backup/save_storage.cgi b/bacula-backup/save_storage.cgi index 98d18a729..9e47e2640 100755 --- a/bacula-backup/save_storage.cgi +++ b/bacula-backup/save_storage.cgi @@ -45,7 +45,8 @@ else { $in{'pass'} || &error($text{'storage_epass'}); &save_directive($conf, $storage, "Password", $in{'pass'}, 1); - gethostbyname($in{'address'}) || &error($text{'storage_eaddress'}); + &to_ipaddress($in{'address'}) || &to_ip6address($in{'address'}) || + &error($text{'storage_eaddress'}); &save_directive($conf, $storage, "Address", $in{'address'}, 1); $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 || diff --git a/bsdexports/save_export.cgi b/bsdexports/save_export.cgi index 4faf17096..5784a71bd 100755 --- a/bsdexports/save_export.cgi +++ b/bsdexports/save_export.cgi @@ -68,7 +68,7 @@ if ($in{'cmode'} == 0) { @hl || &error($text{'save_ehosts'}); $exp{'hosts'} = \@hl; foreach $h (@hl) { - $ip = gethostbyname($h); + $ip = &to_ipaddress($h) || &to_ip6address($h); if ($ip) { push(@iplist, $ip); } } } @@ -96,7 +96,7 @@ for($i=0; $i<@exps; $i++) { } next if (!$samefs); foreach $h (@{$exps[$i]->{'hosts'}}) { - $ip = gethostbyname($h); + $ip = &to_ipaddress($h) || &to_ip6address($h); if ($ip && &indexof($ip, @iplist) >= 0) { # Another export on this filesystem is to the same host &error(&text('save_esame1', $samefs, $h)); diff --git a/cluster-shutdown/save_sched.cgi b/cluster-shutdown/save_sched.cgi new file mode 100755 index 000000000..12a7efce0 --- /dev/null +++ b/cluster-shutdown/save_sched.cgi @@ -0,0 +1,53 @@ +#!/usr/local/bin/perl +# Update scheduled checking + +require './cluster-shutdown-lib.pl'; +&ReadParse(); +&error_setup($text{'sched_err'}); + +# Validate and store inputs +$job = &find_cron_job(); +if ($in{'sched'}) { + $in{'email'} =~ /\S/ || &error($text{'sched_eemail'}); + $config{'email'} = $in{'email'}; + if ($in{'smtp_def'}) { + delete($config{'smtp'}); + } + else { + &to_ipaddress($in{'smtp'}) || &to_ip6address($in{'smtp'}) || + &error($text{'sched_esmtp'}); + $config{'smtp'} = $in{'smtp'}; + } + &save_module_config(); + } + +# Create or delete cron job +&cron::create_wrapper($cron_cmd, $module_name, "check.pl"); +if ($in{'sched'} && !$job) { + $job = { 'command' => $cron_cmd, + 'user' => 'root', + 'active' => 1, + 'mins' => '*/5', + 'hours' => '*', + 'days' => '*', + 'months' => '*', + 'weekdays' => '*', + }; + &cron::create_cron_job($job); + } +elsif (!$in{'sched'} && $job) { + &cron::delete_cron_job($job); + } + +# Tell the user +&ui_print_header(undef, $text{'sched_title'}, ""); + +if ($in{'sched'}) { + print $text{'sched_enabled'},"

\n"; + } +else { + print $text{'sched_disabled'},"

\n"; + } + +&ui_print_footer("", $text{'index_return'}); + diff --git a/custom/save_sql.cgi b/custom/save_sql.cgi index 96c5be053..92022d58b 100755 --- a/custom/save_sql.cgi +++ b/custom/save_sql.cgi @@ -40,7 +40,8 @@ else { delete($cmd->{'host'}); } else { - gethostbyname($in{'host'}) || &error($text{'sql_ehost'}); + &to_ipaddress($in{'host'}) || + &error($text{'sql_ehost'}); $cmd->{'host'} = $in{'host'}; } &parse_params_inputs($cmd); diff --git a/dfsadmin/save_share.cgi b/dfsadmin/save_share.cgi index 9e9cc1e3e..fdf82fc88 100755 --- a/dfsadmin/save_share.cgi +++ b/dfsadmin/save_share.cgi @@ -141,7 +141,8 @@ sub check_hosts local $h; if ($gconfig{'os_version'} < 7) { foreach $h (@_) { - gethostbyname($h) || &error(&text('save_ehost', $h)); + &to_ipaddress($h) || &to_ip6address($h) || + &error(&text('save_ehost', $h)); } } } diff --git a/dhcpd/save_options.cgi b/dhcpd/save_options.cgi index 57e794734..da89e92a7 100755 --- a/dhcpd/save_options.cgi +++ b/dhcpd/save_options.cgi @@ -220,7 +220,7 @@ else { local $nv = $in{$_[0]}; local @nv = split(/\s+/, $nv); if ($_[1] == 0) { - gethostbyname($nv) || &check_ipaddress($nv) || + &to_ipaddress($nv) || &error("$_[0] '$nv' $text{'sopt_invalidip'}"); } elsif ($_[1] == 1) { @@ -229,7 +229,7 @@ else { elsif ($_[1] == 2) { local $ip; foreach $ip (@nv) { - gethostbyname($ip) || &check_ipaddress($ip) || + &to_ipaddress($ip) || &error("'$ip' $text{'sopt_invalidip'}"); } $nv = join(", ", @nv); diff --git a/dhcpd/save_subnet.cgi b/dhcpd/save_subnet.cgi index 563fb0097..0c7bfcbad 100755 --- a/dhcpd/save_subnet.cgi +++ b/dhcpd/save_subnet.cgi @@ -63,7 +63,7 @@ else { else { &error_setup($text{'ssub_failsave'}); # Validate and save inputs - gethostbyname($in{'network'}) || &check_ipaddress($in{'network'}) || + &to_ipaddress($in{'network'}) || &error("'$in{'network'}' $text{'ssub_invalidsubaddr'}"); &check_ipaddress($in{'netmask'}) || &error("'$in{'netmask'}' $text{'ssub_invalidnmask'}"); diff --git a/exports/save_export.cgi b/exports/save_export.cgi index 9fdcd6c5c..3bc2f9767 100755 --- a/exports/save_export.cgi +++ b/exports/save_export.cgi @@ -42,7 +42,7 @@ else { } elsif ($in{'mode'} == 3) { $exp{'host'} = ""; } else { - $in{'host'} =~ /\*/ || gethostbyname($in{'host'}) || + $in{'host'} =~ /\*/ || &to_ipaddress($in{'host'}) || &error(&text('save_ehost', $in{'host'})); $exp{'host'} = $in{'host'}; } diff --git a/fetchmail/fetchmail-lib.pl b/fetchmail/fetchmail-lib.pl index 036ad1450..67ee9d56e 100755 --- a/fetchmail/fetchmail-lib.pl +++ b/fetchmail/fetchmail-lib.pl @@ -197,14 +197,16 @@ splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1, sub poll_lines { local @rv; +local $name = $_[0]->{'poll'}; +$name = "\"$name\"" if ($name =~ /[\s:;,]/); if ($_[0]->{'skip'}) { - push(@rv, "skip $_[0]->{'poll'}"); + push(@rv, "skip $name"); } elsif ($_[0]->{'defaults'}) { - push(@rv, "defaults $_[0]->{'poll'}"); + push(@rv, "defaults $name"); } else { - push(@rv, "poll $_[0]->{'poll'}"); + push(@rv, "poll $name"); } push(@rv, "\tproto $_[0]->{'proto'}") if ($_[0]->{'proto'}); push(@rv, "\tauth $_[0]->{'auth'}") if ($_[0]->{'auth'}); diff --git a/fetchmail/save_poll.cgi b/fetchmail/save_poll.cgi index a25b19bfb..0141d327a 100755 --- a/fetchmail/save_poll.cgi +++ b/fetchmail/save_poll.cgi @@ -112,8 +112,8 @@ else { sub check_host { -return 1 if (gethostbyname($_[0])); -return 0 if (gethostbyname("www.webmin.com")); # only fail if we are online +return 1 if (&to_ipaddress($_[0]) || &to_ip6address($_[0])); +return 0 if (&to_ipaddress("www.webmin.com")); # only fail if we are online return 1; }