summaryrefslogtreecommitdiff
path: root/utils/get-rd-token
diff options
context:
space:
mode:
Diffstat (limited to 'utils/get-rd-token')
-rwxr-xr-xutils/get-rd-token25
1 files changed, 16 insertions, 9 deletions
diff --git a/utils/get-rd-token b/utils/get-rd-token
index 1a59f21..ff014c0 100755
--- a/utils/get-rd-token
+++ b/utils/get-rd-token
@@ -23,24 +23,31 @@
use strict;
use RHRD::rddb;
-# this is ridiculous but makes it a little harder to find user passwords...
-if ($> != 0 ) {
- print STDERR "this must be run as root!\n";
- exit 1;
-}
-
my $num_args = $#ARGV + 1;
-if ($num_args != 1) {
+
+if($num_args > 1) {
print STDERR "Usage: get-rd-token <username>\n";
exit 1;
}
-my $username=$ARGV[0];
+my $requsername=$ARGV[0];
+my $pwusername = getpwuid($>);
+
+# this is ridiculous but makes it a little harder to find user passwords...
+if($num_args == 1) {
+ unless($> == 0 || $pwusername eq $requsername) {
+ print STDERR "this must be run as root or as the user whos token is requested!\n";
+ exit 1;
+ }
+} else {
+ $requsername = $pwusername;
+}
+
my $token='';
my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
if(defined $dbh) {
- ($token, undef, $errorstring) = RHRD::rddb::get_token($dbh, $username);
+ ($token, undef, $errorstring) = RHRD::rddb::get_token($dbh, $requsername);
unless($token) {
print STDERR "$errorstring\n";
exit 1;