From: Stoiko Ivanov Date: Wed, 18 Mar 2020 10:23:43 +0000 (+0100) Subject: allow for optional 'ipv6:' prefix in transports X-Git-Url: https://git.proxmox.com/?p=pmg-api.git;a=commitdiff_plain;h=8e3b0ef15c4dbaf3009932a9f9bb3189bcb7c1a9 allow for optional 'ipv6:' prefix in transports according to the smtp(8) and transport(5) manuals literal ipv6 addresses must be written as '[ipv6:2001:db8::ff]', in accordance with rfc2821 [0]. Postfix does work irrespective of this prefix (as it has been working until now), but we should allow for administrators to enter the addresses with the prefix present. [0] http://www.postfix.org/IPV6_README.html Signed-off-by: Stoiko Ivanov Reviewed-By: Dominik Csapak --- diff --git a/src/PMG/API2/Transport.pm b/src/PMG/API2/Transport.pm index 6a370fe..54edbc5 100644 --- a/src/PMG/API2/Transport.pm +++ b/src/PMG/API2/Transport.pm @@ -72,7 +72,7 @@ __PACKAGE__->register_method ({ }, host => { description => "Target host (name or IP address).", - type => 'string', format => 'address', + type => 'string', format => 'transport-address', }, protocol => { description => "Transport protocol.", @@ -188,7 +188,7 @@ __PACKAGE__->register_method ({ }, host => { description => "Target host (name or IP address).", - type => 'string', format => 'address', + type => 'string', format => 'transport-address', optional => 1, }, protocol => { diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm index 4d3b0e3..1cd4ac6 100755 --- a/src/PMG/Config.pm +++ b/src/PMG/Config.pm @@ -1102,6 +1102,22 @@ sub postmap_pmg_transport { PMG::Utils::run_postmap($transport_map_filename); } +PVE::JSONSchema::register_format( + 'transport-address', \&pmg_verify_transport_address); + +sub pmg_verify_transport_address { + my ($name, $noerr) = @_; + + if ($name =~ m/^ipv6:($IPV6RE)$/i) { + return $name; + } elsif (PVE::JSONSchema::pve_verify_address($name, 1)) { + return $name; + } else { + return undef if $noerr; + die "value does not look like a valid address\n"; + } +} + sub read_transport_map { my ($filename, $fh) = @_; @@ -1140,7 +1156,7 @@ sub read_transport_map { } $use_mx = 0 if ($protocol eq "lmtp"); - eval { PVE::JSONSchema::pve_verify_address($host); }; + eval { pmg_verify_transport_address($host); }; if (my $err = $@) { $parse_error->($err); next; @@ -1182,7 +1198,7 @@ sub write_transport_map { $bracket_host = 0; $data->{protocol} .= ":inet"; } - $bracket_host = 1 if $data->{host} =~ m/^(?:$IPV4RE|$IPV6RE)$/i; + $bracket_host = 1 if $data->{host} =~ m/^(?:$IPV4RE|(?:ipv6:)?$IPV6RE)$/i; my $host = $bracket_host ? "[$data->{host}]" : $data->{host}; PVE::Tools::safe_print($filename, $fh, "$data->{domain} $data->{protocol}:$host:$data->{port}\n"); @@ -1231,8 +1247,8 @@ sub get_template_vars { my $host = $data->{host}; if ($host =~ m/^$IPV4RE$/) { push @$transportnets, "$host/32"; - } elsif ($host =~ m/^$IPV6RE$/) { - push @$transportnets, "[$host]/128"; + } elsif ($host =~ m/^(?:ipv6:)?($IPV6RE)$/i) { + push @$transportnets, "[$1]/128"; } } }