From 53f3a59216455a5aa3208191be76782eba246ba1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 25 Jul 2016 22:40:04 +0200 Subject: implemented command to list groups of user 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) \n" . + " rhrd-user (check|remove|groups) \n" . " rhrd-user add [ ]\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; -- cgit v0.10.2