summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-25 20:40:04 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-25 20:40:33 (GMT)
commit53f3a59216455a5aa3208191be76782eba246ba1 (patch)
tree539e2b53d2d9d976d6cc075853941ff253daf626
parentdf6717fea5d717e3ed3a27612339b9b80930abca (diff)
implemented command to list groups of user
-rwxr-xr-xlib/RHRD/rddb.pm20
-rwxr-xr-xutils/rhrd-user24
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;