From 75940bfda15951d73f60d119b96dda9a5f2d3737 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Thu, 15 Mar 2018 03:10:06 -0400 Subject: [PATCH] add value check for rspconfig options powersupplyredundancy,... --- xCAT-server/lib/xcat/plugins/openbmc2.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc2.pm b/xCAT-server/lib/xcat/plugins/openbmc2.pm index 162a5bf02..f5e4a8920 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc2.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc2.pm @@ -144,7 +144,13 @@ sub process_request { my @rsp_common_options = qw/autoreboot bootmode powersupplyredundancy powerrestorepolicy timesyncmethod ip netmask gateway hostname vlan ntpservers/; my @rspconfig_set_options = (@rsp_common_options, qw/admin_passwd/); - +my %rsp_set_valid_values = ( + autoreboot => "0|1", + bootmode => "regular|safe|setup", + powersupplyredundancy => "disabled|enabled", + powerrestorepolicy => "restore|always_on|always_off", + timesyncmethod => "ntp|manual", +); my @rspconfig_get_options = (@rsp_common_options, qw/ipsrc sshcfg gard dump/); #------------------------------------------------------- @@ -270,6 +276,10 @@ sub parse_args { return ([1, "Can not set and query OpenBMC information at the same time"]); } elsif ($set and $value eq '' and ($key ne "ntpservers")) { return ([1, "Invalid parameter for option $key"]); + } elsif ($set and $value ne '' and exists($rsp_set_valid_values{$key})) { + unless ($value =~ /^($rsp_set_valid_values{$key})$/) { + return([1, "Invalid value '$value' for '$key', Valid values: " . join(',', split('\|',$rsp_set_valid_values{$key}))]); + } } if (($set and !grep /$key/, @rspconfig_set_options) or ($get and !grep /$key/, @rspconfig_get_options)) {