Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create usergroup based policy rules #6398

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions perl-xCAT/xCAT/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4987,6 +4987,26 @@ sub natural_sort_cmp($$) {

#--------------------------------------------------------------------------------

=head3 groups
Pure perl implementation of /bin/groups
=cut

#--------------------------------------------------------------------------------
sub groups($) {
my ($name)=@_;
my @list;
my $n=(getpwnam($name))[3];
@list=((getgrgid($n))[0]);
while (my @l=getgrent()) {
if ($l[3] && $l[3] ne "" && $l[3] =~ /$name/) {
push @list, $l[0];
}
}
endgrent();
}

#--------------------------------------------------------------------------------

=head3 console_sleep
A wrap for sleep subroutine, if goconserver is used, just exit immidiately
as goconserver has its own sleep mechanism.
Expand Down
8 changes: 7 additions & 1 deletion xCAT-server/lib/perl/xCAT/xcatd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ sub validate {
}
}

# Get groups for peername
my $usergroups = xCAT::Utils->groups($peername);

RULE: foreach $rule (@sortedpolicies) {
if ($rule->{name} and $rule->{name} ne '*') {

#TODO: more complex matching (lists, wildcards)
next unless ($peername and $peername eq $rule->{name});
if (!$usergroups or index($usergroups,$rule->{name}) < 0) {
# If the user's group is empty, or usergroups doesn't contain rule name then...
next unless ($peername and $peername eq $rule->{name});
}
}
if ($rule->{name} and $rule->{name} eq '*') { #a name is required, but can be any name whatsoever....
next unless ($peername);
Expand Down