diff options
-rwxr-xr-x | lib/RHRD/rddb.pm | 20 | ||||
-rwxr-xr-x | utils/rhrd-user | 24 |
2 files changed, 43 insertions, 1 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 99b4128..bfa31fd 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -547,6 +547,26 @@ sub list_users return @users; } +sub get_user_groups +{ + my ($ctx, $username) = @_; + + my $sql = qq{select GROUP_NAME from USER_PERMS where USER_NAME = ?;}; + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($username) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @groups; + while(my ($user) = $sth->fetchrow_array()) { + push @groups, $user; + } + $sth->finish(); + + return @groups; +} + ########################### GROUP handling ########################### sub add_group diff --git a/utils/rhrd-user b/utils/rhrd-user index a473ddc..9d606eb 100755 --- a/utils/rhrd-user +++ b/utils/rhrd-user @@ -27,7 +27,7 @@ use String::MkPasswd qw(mkpasswd); sub print_usage { print STDERR "Usage: rhrd-user list\n" . - " rhrd-user (check|remove) <username>\n" . + " rhrd-user (check|remove|groups) <username>\n" . " rhrd-user add <username> [ <fullname> ]\n"; } @@ -84,6 +84,21 @@ sub remove return 0; } +sub groups +{ + my ($ctx, $username) = @_; + + my @groups = RHRD::rddb::get_user_groups($ctx, $username); + if(!defined $groups[0] && defined $groups[1]) { + print STDERR "$groups[1]: $groups[2]"; + return 1; + } + for my $user (@groups) { + print $user . "\n"; + } + return 0; +} + my $num_args = $#ARGV + 1; if($num_args < 1) { @@ -125,6 +140,13 @@ if(defined $ctx) { } else { $ret = remove($ctx, $username); } + } elsif($cmd eq "groups") { + if($num_args != 2) { + print_usage(); + $ret = 1; + } else { + $ret = groups($ctx, $username); + } } else { print_usage(); $ret = 1; |