From 6e5f39d215cd767c461666a020e75c4c9d6ef414 Mon Sep 17 00:00:00 2001 From: ligc Date: Sat, 10 Oct 2009 07:05:40 +0000 Subject: [PATCH] fix for bug 2871938: add check for rmdef flags, check node attribute when create dynamic node group git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4337 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/DBobjectdefs.pm | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm index 474f80223..b1973f684 100644 --- a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm +++ b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm @@ -308,6 +308,25 @@ sub processArgs } } + # Check arguments for rmdef command + # rmdef is very dangerous if wrong flag is specified + # it may cause all the objects to be deleted, check the flags + # for example: rmdef -t node -d, the user want to delete the node named "-d", + # but it will delete all the nodes! + # use -o instead + if ($::command eq 'rmdef') + { + if (defined($::opt_d) || defined($::opt_i) || defined($::opt_l) + || defined($::opt_m) || defined($::opt_p) || defined($::opt_w) + || defined($::opt_x) || defined($::opt_z)) + { + my $rsp; + $rsp->{data}->[0] = "Invalid flag specified, see rmdef manpage for details."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + return 1; + } + } + # Option -h for Help # if user specifies "-t" & "-h" they want a list of valid attrs if (defined($::opt_h) && !defined($::opt_t)) @@ -696,6 +715,26 @@ sub processArgs xCAT::MsgUtils->message("E", $rsp, $::callback); return 3; } + # For dynamic node groups, check the selection string + if (($::opt_t eq 'group') && ($::opt_d)) + { + my $datatype = $xCAT::Schema::defspec{'node'}; + my @nodeattrs = (); + foreach my $this_attr (@{$datatype->{'attrs'}}) + { + push @nodeattrs, $this_attr->{attr_name}; + } + foreach my $whereattr (keys %::WhereHash) + { + if (!grep(/^$whereattr$/, @nodeattrs)) + { + my $rsp; + $rsp->{data}->[0] = "Incorrect attribute \'$whereattr\' in the selection string specified with -w flag."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + return 1; + } + } + } } # check for the -i option