]> git.proxmox.com Git - pmg-api.git/commitdiff
allow for optional 'ipv6:' prefix in transports
authorStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 18 Mar 2020 10:23:43 +0000 (11:23 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Mar 2020 12:30:52 +0000 (13:30 +0100)
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 <s.ivanov@proxmox.com>
Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
src/PMG/API2/Transport.pm
src/PMG/Config.pm

index 6a370fe175a357422ba921b32d35aab28f3e0de1..54edbc53f9dafd868eeda1d6d0e956e086129b15 100644 (file)
@@ -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 => {
index 4d3b0e3170ba6aaa698a4ece2cf48677306294f0..1cd4ac622c7d807b0da259a96194cc5af56d2b21 100755 (executable)
@@ -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";
            }
        }
     }