From d98d23ff5be54a8f9210730fc64ff6fa37ce954c Mon Sep 17 00:00:00 2001 From: Wytze van der Raay Date: Wed, 7 Sep 2011 10:30:32 +0000 Subject: [PATCH] Fix for https://bugs.cacert.org/view.php?id=841 (Problems on cert login with "duplicate" serial numbers) --- includes/lib/general.php | 50 ++++++++++++++++++++++++++++++++++++++++ includes/loggedin.php | 13 +++++------ www/index.php | 15 +++++++----- 3 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 includes/lib/general.php diff --git a/includes/lib/general.php b/includes/lib/general.php new file mode 100644 index 0000000..25d2561 --- /dev/null +++ b/includes/lib/general.php @@ -0,0 +1,50 @@ + 0"; + $res = mysql_query($query); + if(mysql_num_rows($res) > 0) + { + $row = mysql_fetch_assoc($res); + return intval($row['memid']); + } + + return -1; +} + +?> diff --git a/includes/loggedin.php b/includes/loggedin.php index 640bc6c..bf6b455 100644 --- a/includes/loggedin.php +++ b/includes/loggedin.php @@ -16,6 +16,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + include_once("../includes/lib/general.php"); if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] != 0) { @@ -41,14 +42,11 @@ if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && ($_SESSION['profile']['id'] == 0 || $_SESSION['profile']['loggedin'] == 0)) { - $query = "select * from `emailcerts` where `serial`='${_SERVER['SSL_CLIENT_M_SERIAL']}' and `revoked`=0 and disablelogin=0 and - UNIX_TIMESTAMP(`expire`) - UNIX_TIMESTAMP() > 0"; - $res = mysql_query($query); + $user_id = get_user_id_from_cert($_SERVER['SSL_CLIENT_M_SERIAL'], + $_SERVER['SSL_CLIENT_I_DN_CN']); - if(mysql_num_rows($res) > 0) + if($user_id >= 0) { - $row = mysql_fetch_assoc($res); - $_SESSION['profile']['loggedin'] = 0; $_SESSION['profile'] = ""; foreach($_SESSION as $key) @@ -61,7 +59,8 @@ session_unregister($key); } - $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$row['memid']."'")); + $_SESSION['profile'] = mysql_fetch_assoc(mysql_query( + "select * from `users` where `id`='".$user_id."'")); if($_SESSION['profile']['locked'] == 0) $_SESSION['profile']['loggedin'] = 1; else diff --git a/www/index.php b/www/index.php index 7330877..a4c50fc 100644 --- a/www/index.php +++ b/www/index.php @@ -148,13 +148,16 @@ if($id == 4 && $_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname']) { - $query = "select * from `emailcerts` where `serial`='$_SERVER[SSL_CLIENT_M_SERIAL]' and `revoked`=0 and disablelogin=0 and - UNIX_TIMESTAMP(`expire`) - UNIX_TIMESTAMP() > 0"; - $res = mysql_query($query); - if(mysql_num_rows($res) > 0) + include_once("../includes/lib/general.php"); + $user_id = get_user_id_from_cert($_SERVER['SSL_CLIENT_M_SERIAL'], + $_SERVER['SSL_CLIENT_I_DN_CN']); + + if($user_id >= 0) { - $row = mysql_fetch_assoc($res); - $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$row[memid]' and `deleted`=0 and `locked`=0")); + $_SESSION['profile'] = mysql_fetch_assoc(mysql_query( + "select * from `users` where + `id`='$user_id' and `deleted`=0 and `locked`=0")); + if($_SESSION['profile']['id'] != 0) { $_SESSION['profile']['loggedin'] = 1;