Skip to content

Commit

Permalink
More IPv6 friendly function conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Nov 1, 2010
1 parent 583c18b commit b0ce51e
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 26 deletions.
4 changes: 2 additions & 2 deletions acl/save_sql.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand Down
3 changes: 1 addition & 2 deletions apache/create_virt.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions apache/save_vserv.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'})) {
Expand Down
2 changes: 1 addition & 1 deletion bacula-backup/fixaddr.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion bacula-backup/index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
"<tt>$console_cmd</tt>", "<tt>$conaddr</tt>"),"<p>\n";
Expand Down
3 changes: 2 additions & 1 deletion bacula-backup/save_client.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
3 changes: 2 additions & 1 deletion bacula-backup/save_storage.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
4 changes: 2 additions & 2 deletions bsdexports/save_export.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
}
Expand Down Expand Up @@ -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));
Expand Down
53 changes: 53 additions & 0 deletions cluster-shutdown/save_sched.cgi
Original file line number Diff line number Diff line change
@@ -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'},"<p>\n";
}
else {
print $text{'sched_disabled'},"<p>\n";
}

&ui_print_footer("", $text{'index_return'});

3 changes: 2 additions & 1 deletion custom/save_sql.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion dfsadmin/save_share.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dhcpd/save_options.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dhcpd/save_subnet.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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'}");
Expand Down
2 changes: 1 addition & 1 deletion exports/save_export.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
}
Expand Down
8 changes: 5 additions & 3 deletions fetchmail/fetchmail-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,16 @@ sub modify_poll
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'});
Expand Down
4 changes: 2 additions & 2 deletions fetchmail/save_poll.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit b0ce51e

Please sign in to comment.