diff options
Diffstat (limited to 'utils/rhrd-ws-login')
-rwxr-xr-x | utils/rhrd-ws-login | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/utils/rhrd-ws-login b/utils/rhrd-ws-login index c7a8d00..a3cee53 100755 --- a/utils/rhrd-ws-login +++ b/utils/rhrd-ws-login @@ -23,32 +23,48 @@ use strict; use RHRD::rddb; -my $num_args = $#ARGV + 1; -if($num_args != 1 || ($ARGV[0] ne "login" && $ARGV[0] ne "logout")) { +sub print_usage +{ print STDERR "Usage: rhrd-ws-login (login|logout)\n"; - exit 1; } +my $num_args = $#ARGV + 1; +if($num_args != 1) { + print_usage(); + exit 1; +} +my $cmd = $ARGV[0]; my $username = $ENV{'USER'}; +my $ret = 0; + my ($dbh, undef, $errorstring) = RHRD::rddb::opendb(); if(defined $dbh) { - my $macro = "NN!"; - if($ARGV[0] eq "logout") { + my $macro = ''; + if($cmd eq "logout") { $macro = "LO!"; - } elsif($ARGV[0] eq "login") { + } + elsif($cmd eq "login") { (my $token, undef, $errorstring) = RHRD::rddb::get_token($dbh, $username); - unless($token) { + if($token) { + $token =~ s/([ !'"\\])/\\$1/g; + $macro = "LO $username $token!"; + } else { print STDERR "$errorstring\n"; - exit 0; + $macro = "LO!"; } - $token =~ s/([ !'"\\])/\\$1/g; - $macro = "LO $username $token!" + } + else { + print_usage(); + $ret = 1; } RHRD::rddb::closedb($dbh); - system('/usr/bin/rmlsend', $macro) == 0 or die "system(/usr/bin/rmlsend, $macro) failed: $?"; + unless ($macro eq '') { + system('/usr/bin/rmlsend', $macro) == 0 or die "system(/usr/bin/rmlsend, $macro) failed: $?"; + } } else { print STDERR "$errorstring\n"; + $ret = 1; } -exit 0 +exit $ret; |