From 47ed2908be8a30f9cb0871a5d06f7d2c90391cfb Mon Sep 17 00:00:00 2001 From: Jeff Godin Date: Wed, 13 May 2015 17:00:28 -0700 Subject: [PATCH] move _verify_password, call from telnet transport as well Signed-off-by: Jeff Godin --- SIPServer.pm | 19 ++++++++++++++++++- Sip/MsgType.pm | 19 +------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/SIPServer.pm b/SIPServer.pm index 9e598b6..eda77cc 100755 --- a/SIPServer.pm +++ b/SIPServer.pm @@ -621,7 +621,7 @@ sub telnet_transport { $pwd =~ s/[\r\n]+$//; if (exists($config->{accounts}->{$uid}) - && ($pwd eq $config->{accounts}->{$uid}->password())) { + && _verify_client_password($config->{accounts}->{$uid}, $pwd) == 1) { $account = $config->{accounts}->{$uid}; last; } else { @@ -709,3 +709,20 @@ sub sip_protocol_loop { } } + +sub _verify_client_password { + # Accept a config hash representing a single login, and a supplied client password + # Return 1 on match, otherwise 0 + # XXX: implement support for salted + hashed "clientpassword" value + my ($login_config, $pwd_from_client) = @_; + + # if config has a clientpassword, verify against that + if (exists($login_config->{clientpassword})) { + syslog("LOG_INFO", "_verify_client_password: checking supplied password against clientpassword from config"); + return 1 if ($pwd_from_client eq $login_config->{clientpassword}); + } else { # otherwise, verify against "password" attribute + syslog("LOG_INFO", "_verify_client_password: checking supplied password against password from config"); + return 1 if ($pwd_from_client eq $login_config->{password}); + } + return 0; # password did not match +} diff --git a/Sip/MsgType.pm b/Sip/MsgType.pm index c3938b8..01f1a56 100644 --- a/Sip/MsgType.pm +++ b/Sip/MsgType.pm @@ -852,7 +852,7 @@ sub handle_login { if (!exists($server->{config}->{accounts}->{$uid})) { syslog("LOG_WARNING", "MsgType::handle_login: Unknown login '$uid'"); $status = 0; - } elsif (_verify_client_password($server->{config}->{accounts}->{$uid}, $pwd) != 1) { + } elsif (SIPServer::_verify_client_password($server->{config}->{accounts}->{$uid}, $pwd) != 1) { syslog("LOG_WARNING", "MsgType::handle_login: Invalid password for login '$uid'"); $status = 0; } else { @@ -866,23 +866,6 @@ sub handle_login { return $status ? LOGIN : ''; } -sub _verify_client_password { - # Accept a config hash representing a single login, and a supplied client password - # Return 1 on match, otherwise 0 - # XXX: implement support for salted + hashed "clientpassword" value - my ($login_config, $pwd_from_client) = @_; - - # if config has a clientpassword, verify against that - if (exists($login_config->{clientpassword})) { - syslog("LOG_INFO", "_verify_client_password: checking supplied password against clientpassword from config"); - return 1 if ($pwd_from_client eq $login_config->{clientpassword}); - } else { # otherwise, verify against "password" attribute - syslog("LOG_INFO", "_verify_client_password: checking supplied password against password from config"); - return 1 if ($pwd_from_client eq $login_config->{password}); - } - return 0; # password did not match -} - sub _load_ils_handler { my ($server, $uid) = @_; -- 2.11.0