2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-07-09 06:11:34 +00:00

Merge pull request #5132 from zet809/fix_issue_5111

Fix issue 5111: REST API does not respect the "host" setting in "policy" table
This commit is contained in:
Mark Gurevich
2018-04-23 09:34:36 -04:00
committed by GitHub
2 changed files with 22 additions and 2 deletions

View File

@ -73,6 +73,11 @@ sub validate {
return 0;
}
my $remote_host = undef;
if ($request->{'remote_client'} && defined($request->{'remote_client'}->[0])) {
$remote_host = $request->{'remote_client'}->[0];
}
my $policies = $policytable->getAllEntries;
$policytable->close;
my $rule;
@ -114,9 +119,20 @@ sub validate {
#TODO: time ranges
}
if ($rule->{host} and $rule->{host} ne '*') {
#TODO: more complex matching (lists, noderanges?, wildcards)
next unless ($peerhost eq $rule->{host});
if (defined($remote_host) and $remote_host ne '') {
my @tmp_hosts = split(",",$remote_host);
my $found = 0;
foreach my $tmp_host (@tmp_hosts) {
if ($tmp_host eq $rule->{host}) {
$found = 1;
last;
}
}
next unless ($found);
} else {
next unless ($peerhost eq $rule->{host});
}
}
if ($rule->{commands} and $rule->{commands} ne '*') {
my @commands = split(",", $rule->{commands});

View File

@ -1373,6 +1373,10 @@ my @path = split(/\//, $pathInfo); # The uri path like /nodes/node1/...
my $pageContent = ''; # Global var containing the ouptut back to the rest client
my %header_info; #Global var containing the extra info to the http header
my $request = { clienttype => 'ws' }; # Global var that holds the request to send to xcatd
my $remote_host = $q->remote_host();
my ($client_name, $client_aliases) = gethostbyaddr(inet_aton($remote_host), AF_INET);
$request->{remote_client}->[0]= $client_name.','.$client_aliases;
my $format = 'json'; # The output format for a request invoke
my $xmlinstalled; # Global var to speicfy whether the xml modules have been loaded