schema: register 'timezone' format and add verification method

/usr/share/zoneinfo/zone.tab has the valid list of time zones.

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Oguz Bektas 2020-06-17 15:32:29 +02:00 committed by Thomas Lamprecht
parent 0bbe789c6a
commit e76308e6eb

View File

@ -482,6 +482,25 @@ sub pve_verify_dns_name {
return $name;
}
register_format('timezone', \&pve_verify_timezone);
sub pve_verify_timezone {
my ($timezone, $noerr) = @_;
my $zonetab = "/usr/share/zoneinfo/zone.tab";
return $timezone if $timezone eq 'UTC';
open(my $fh, "<", $zonetab);
while(my $line = <$fh>) {
next if $line =~ /^#/;
chomp $line;
return $timezone if $timezone eq (split /\t/, $line)[2]; # found
}
close $fh;
return undef if $noerr;
die "invalid time zone '$timezone'\n";
}
# network interface name
register_format('pve-iface', \&pve_verify_iface);
sub pve_verify_iface {