From 15788164228a34cc3cb4d4886a74d42c9a757825 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 17 Apr 2008 04:43:42 -0400
Subject: [PATCH] - Updated PEAR::Auth_SASL to 1.0.2

---
 program/lib/Auth/SASL/DigestMD5.php |   24 ++++++++++++++----------
 CHANGELOG                           |    1 +
 program/lib/Auth/SASL.php           |    3 ++-
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index b7c8da5..5644c39 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@
 2008/04/17 (alec)
 ----------
 - Fix IMAP response in message body when message has no body (#1484964)
+- Updated PEAR::Auth_SASL to 1.0.2
 
 2008/04/16 (estadtherr)
 ----------
diff --git a/program/lib/Auth/SASL.php b/program/lib/Auth/SASL.php
index 6e3dc34..9b7090c 100644
--- a/program/lib/Auth/SASL.php
+++ b/program/lib/Auth/SASL.php
@@ -91,7 +91,8 @@
         }
 
         require_once($filename);
-        return new $classname();
+        $obj = new $classname();
+        return $obj;
     }
 }
 
diff --git a/program/lib/Auth/SASL/DigestMD5.php b/program/lib/Auth/SASL/DigestMD5.php
index dcd9910..a465b98 100644
--- a/program/lib/Auth/SASL/DigestMD5.php
+++ b/program/lib/Auth/SASL/DigestMD5.php
@@ -74,7 +74,12 @@
             $digest_uri     = sprintf('%s/%s', $service, $hostname);
             $response_value = $this->_getResponseValue($authcid, $pass, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $authzid);
 
-            return sprintf('username="%s",realm="%s"' . $authzid_string  . ',nonce="%s",cnonce="%s",nc="00000001",qop=auth,digest-uri="%s",response=%s,%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
+            if ($challenge['realm']) {
+                return sprintf('username="%s",realm="%s"' . $authzid_string  .
+',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
+            } else {
+                return sprintf('username="%s"' . $authzid_string  . ',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
+            }
         } else {
             return PEAR::raiseError('Invalid digest challenge');
         }
@@ -125,20 +130,19 @@
         */
         // Realm
         if (empty($tokens['realm'])) {
-            $uname = posix_uname();
-            $tokens['realm'] = $uname['nodename'];
+            $tokens['realm'] = "";
         }
-        
+
         // Maxbuf
         if (empty($tokens['maxbuf'])) {
             $tokens['maxbuf'] = 65536;
         }
-        
+
         // Required: nonce, algorithm
         if (empty($tokens['nonce']) OR empty($tokens['algorithm'])) {
             return array();
         }
-        
+
         return $tokens;
     }
 
@@ -174,11 +178,11 @@
     */
     function _getCnonce()
     {
-        if (file_exists('/dev/urandom')) {
-            return base64_encode(fread(fopen('/dev/urandom', 'r'), 32));
+        if (file_exists('/dev/urandom') && $fd = @fopen('/dev/urandom', 'r')) {
+            return base64_encode(fread($fd, 32));
 
-        } elseif (file_exists('/dev/random')) {
-            return base64_encode(fread(fopen('/dev/random', 'r'), 32));
+        } elseif (file_exists('/dev/random') && $fd = @fopen('/dev/random', 'r')) {
+            return base64_encode(fread($fd, 32));
 
         } else {
             $str = '';

--
Gitblit v1.9.1