Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jan 2006 23:16:47 -0500
From:      "Anish Mistry" <amistry@am-productions.biz>
To:        "FreeBSD gnats submit" <FreeBSD-gnats-submit@FreeBSD.org>
Cc:        martin@matuska.org
Subject:   ports/91899: Add STARTTLS support to Net_Sieve
Message-ID:  <1137471407.94144@bigguy.am-productions.biz>
Resent-Message-ID: <200601170420.k0H4K46U063896@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         91899
>Category:       ports
>Synopsis:       Add STARTTLS support to Net_Sieve
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 17 04:20:03 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Anish Mistry
>Release:        FreeBSD 6.0-STABLE i386
>Organization:
AM Productions 
>Environment:


System: FreeBSD 6.0-STABLE #10: Fri Jan  6 17:53:21 EST 2006
    amistry@bigguy.am-productions.biz:/usr/obj/usr/src/sys/BIGGUY



>Description:


The attached patch will update Net_Sieve to support STARTTLS.  I've already tried to contact the upstream authors and the port maintainer with no response.  Hopefully Martin will weigh in on this PR.


>How-To-Repeat:





>Fix:


--- pear-Net_Sieve-STARTTLS.patch begins here ---
diff -ruN pear-Net_Sieve.orig/Makefile pear-Net_Sieve/Makefile
--- pear-Net_Sieve.orig/Makefile	Mon Jan 16 23:04:35 2006
+++ pear-Net_Sieve/Makefile	Mon Jan 16 23:09:09 2006
@@ -7,6 +7,7 @@
 
 PORTNAME=	Net_Sieve
 PORTVERSION=	1.1.1
+PORTREVISION=	1
 CATEGORIES=	net www pear
 
 MAINTAINER=	martin@matuska.org
diff -ruN pear-Net_Sieve.orig/files/patch-Sieve.php pear-Net_Sieve/files/patch-Sieve.php
--- pear-Net_Sieve.orig/files/patch-Sieve.php	Wed Dec 31 19:00:00 1969
+++ pear-Net_Sieve/files/patch-Sieve.php	Wed Jan  4 14:39:08 2006
@@ -0,0 +1,123 @@
+--- Sieve.php.orig	Sat Dec 17 17:48:27 2005
++++ Sieve.php	Wed Jan  4 14:37:54 2006
+@@ -331,7 +331,7 @@
+     * @param  string $port Port of server
+     * @return mixed        True on success, PEAR_Error otherwise
+     */
+-    function connect($host, $port)
++    function connect($host, $port, $options = null)
+     {
+         if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) {
+             $msg='Not currently in DISCONNECTED state';
+@@ -339,16 +339,16 @@
+             return $this->_raiseError($msg,$code);
+         }
+ 
+-        if (PEAR::isError($res = $this->_sock->connect($host, $port, null, 5))) {
++        if (PEAR::isError($res = $this->_sock->connect($host, $port, null, 5, $options))) {
+             return $res;
+         }
+ 
+-
+         $this->_state = NET_SIEVE_STATE_AUTHORISATION;
+         if (PEAR::isError($res = $this->_doCmd())) {
+             return $res;
+         }
+-        /*
++
++       /*
+         if(PEAR::isError($res = $this->_cmdCapability() )) {
+             $msg='Failed to connect, server said: ' . $res->getMessage();
+             $code=2;
+@@ -358,6 +358,15 @@
+         // Get logon greeting/capability and parse
+         $this->_parseCapability($res);
+ 
++	// check if we can enable TLS via STARTTLS
++	if($this->_capability['starttls'] == true && function_exists('stream_socket_enable_crypto') == true)
++	{// begin enable TLS
++		if (PEAR::isError($res = $this->_startTLS())) {
++			return $res;
++		}
++	}// end enable TLS
++
++
+         return true;
+     }
+ 
+@@ -806,7 +815,7 @@
+         $data = preg_split('/\r?\n/', $data, -1, PREG_SPLIT_NO_EMPTY);
+ 
+         for ($i = 0; $i < count($data); $i++) {
+-            if (preg_match('/^"([a-z]+)" ("(.*)")?$/i', $data[$i], $matches)) {
++            if (preg_match('/^"([a-z]+)"( "(.*)")?$/i', $data[$i], $matches)) {
+                 switch (strtolower($matches[1])) {
+                     case 'implementation':
+                         $this->_capability['implementation'] = $matches[3];
+@@ -822,6 +831,7 @@
+ 
+                     case 'starttls':
+                         $this->_capability['starttls'] = true;
++			break;
+                 }
+             }
+         }
+@@ -946,8 +956,10 @@
+                         if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches)) {
+                             // Check for referral, then follow it.  Otherwise, carp an error.
+                             //$this->_data['host'] = $matches[1];
+-                            $this->_data['host'] = $matches[2];
+-                            if (PEAR::isError($error = $this->_handleConnectAndLogin() ) ){
++				//$this->_data['host'] = $matches[2];
++				//replace the old host with the referral host preserving any protocol prefix
++				$this->_data['host'] = preg_replace('/\w+(?!(\w|\:\/\/)).*/',$matches[2],$this->_data['host']);
++                           if (PEAR::isError($error = $this->_handleConnectAndLogin() ) ){
+                                 $msg="Can't follow referral to " . $this->_data['host'] . ", The error was= " . $error->getMessage() ;
+                                 $code=5;
+                                 return $this->_raiseError($msg,$code);
+@@ -1133,7 +1145,7 @@
+ 
+ 
+     /**
+-    * Return true if tyhe server has that extension
++    * Return true if the server has that extension
+     *
+     * @access public
+     * @param string  the extension to compare
+@@ -1157,9 +1169,32 @@
+         return false;
+     }
+ 
++    /**
++    * Return true if the TLS negotiation was successful
++    *
++    * @access public
++    * @return mixed              true on success, PEAR_Error on failure
++    */
++    function _startTLS()
++    {
++	if (PEAR::isError($res = $this->_doCmd("STARTTLS"))) {
++		return $res;
++	}
++
++	if(stream_socket_enable_crypto($this->_sock->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT) == false) {
++		$msg='Failed to establish TLS connection';
++		$code=2;
++		return $this->_raiseError($msg,$code);
++	}
+ 
+-
+-
++	// RFC says we need to query the server capabilities again
++        if(PEAR::isError($res = $this->_cmdCapability() )) {
++            $msg='Failed to connect, server said: ' . $res->getMessage();
++            $code=2;
++            return $this->_raiseError($msg,$code);
++        }
++	return true;
++    }
+ 
+ }
+-?>
+\ No newline at end of file
++?>
--- pear-Net_Sieve-STARTTLS.patch ends here ---



>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1137471407.94144>