]> git.proxmox.com Git - pve-firewall.git/commitdiff
correctly verify ipset name
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 9 Apr 2014 05:34:06 +0000 (07:34 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 9 Apr 2014 05:34:06 +0000 (07:34 +0200)
src/PVE/API2/Firewall/IPSet.pm
src/PVE/Firewall.pm

index 71f6b4c913af1066f3d93b7853f5709598478c68..856e5f854a351c3c5b7fda2aae81191acd51ab46 100644 (file)
@@ -14,10 +14,7 @@ my $api_properties = {
        description => "Network/IP specification in CIDR format.",
        type => 'string', format => 'IPv4orCIDR',
     },
-    name => {
-       description => "IP set name.",
-       type => 'string',
-    },
+    name => get_standard_option('ipset-name'),
     comment => {
        type => 'string',
        optional => 1,
@@ -295,8 +292,9 @@ package PVE::API2::Firewall::BaseIPSetList;
 
 use strict;
 use warnings;
-use PVE::Firewall;
+use PVE::JSONSchema qw(get_standard_option);
 use PVE::Exception qw(raise_param_exc);
+use PVE::Firewall;
 
 use base qw(PVE::RESTHandler);
 
@@ -316,10 +314,7 @@ sub register_index {
            items => {
                type => "object",
                properties => { 
-                   name => {
-                       description => "IPSet name.",
-                       type => 'string',
-                   },
+                   name => get_standard_option('ipset-name'),
                },
            },
            links => [ { rel => 'child', href => "{name}" } ],
@@ -350,16 +345,11 @@ sub register_create {
        parameters => {
            additionalProperties => 0,
            properties => { 
-               name => {
-                   # fixme: verify format
-                   description => "IP set name.",
-                   type => 'string',
-               },
-               rename => {
+               name => get_standard_option('ipset-name'),
+               rename => get_standard_option('ipset-name', {
                    description => "Rename an existing IPSet.",
-                   type => 'string',
                    optional => 1,
-               },
+               }),
            }
        },
        returns => { type => 'null' },
@@ -400,11 +390,7 @@ sub register_delete {
        parameters => {
            additionalProperties => 0,
            properties => { 
-               name => {
-                   # fixme: verify format
-                   description => "IP set name.",
-                   type => 'string',
-               },
+               name => get_standard_option('ipset-name'),
            }
        },
        returns => { type => 'null' },
index a2e6b7934e59fc4b5f57acdf64befa5686a82186..1438125b4c31e298b37a9699502253d4698b6034 100644 (file)
@@ -7,7 +7,7 @@ use Data::Dumper;
 use Digest::SHA;
 use PVE::INotify;
 use PVE::Exception qw(raise raise_param_exc);
-use PVE::JSONSchema qw(get_standard_option);
+use PVE::JSONSchema qw(register_standard_option get_standard_option);
 use PVE::Cluster;
 use PVE::ProcFSTools;
 use PVE::Tools qw($IPV4RE);
@@ -48,6 +48,13 @@ sub pve_verify_ipv4_or_cidr {
     die "value does not look like a valid IP address or CIDR network\n";
 }
 
+PVE::JSONSchema::register_standard_option('ipset-name', {
+    description => "IP set name.",
+    type => 'string',
+    pattern => '[A-Za-z][A-Za-z0-9\-\_]+',
+    minLength => 2, 
+    maxLength => 20,                                             
+});
 
 my $feature_ipset_nomatch = 0;
 eval  {