[sork] Patches to sort (accounts, forwards, passwd, vacation) for qmail-ldap

Ian S ian at mrzesty.net
Mon Dec 27 12:06:10 PST 2004


Hi,

I made the following modifications to the CVS sork packages today to make them 
work with recent versions of qmail-ldap (OpenLDAP backend, using qmail-ldap's 
schema), as well as with a defined LDAP bind login.

Some of the changes are not ideal since they just change the hard-coded 
defaults from the Exim/LDAP values to qmail-ldap's.

Please feel free to incorporate any ideas you might find useful.

Cheers!

i.

diff -ur accounts/config/conf.xml horde-3.0/accounts/config/conf.xml
--- accounts/config/conf.xml    2004-06-24 19:10:04.000000000 -0400
+++ horde-3.0/accounts/config/conf.xml  2004-12-27 12:13:02.407026352 -0500
@@ -26,6 +26,8 @@
      <configstring name="host" desc="LDAP 
server/host">localhost</configstring>
      <configinteger name="port" required="false" desc="Port LDAP is running 
on, if non-standard">389</configinteger>
      <configstring name="basedn" desc="basedn 
string">o=example.com,c=US</configstring>
+     <configstring name="binddn" required="false" desc="binddn 
string">cn=Manager,o=example.com,c=US</configstring>
+     <configstring name="bindpass" required="false" desc="bindpass 
string">password</configstring>
      <configstring name="attr" desc="LDAP attribute to search 
on">uid</configstring>
     </configsection>
    </case>
diff -ur accounts/lib/Driver/ldap.php horde-3.0/accounts/lib/Driver/ldap.php
--- accounts/lib/Driver/ldap.php        2004-08-19 07:31:31.000000000 -0400
+++ horde-3.0/accounts/lib/Driver/ldap.php      2004-12-27 12:18:54.717588486 
-0500
@@ -67,7 +67,9 @@
             }

             // bind as anonymous
-            $result = @ldap_bind($this->_ds);
+            $result = @ldap_bind($this->_ds,
+                                $this->_params['binddn'],
+                                $this->_params['bindpass']);
             if (!$result) {
                 return PEAR::raiseError(_("Could not bind to ldap server"));
             }
@@ -115,7 +117,8 @@
     function getHome()
     {
         $information = $this->_getAccount();
-        $homedir = $information[0]['homedirectory'][0];
+        if(!empty($information[0]['homedirectory'][0]))
+           $homedir = $information[0]['homedirectory'][0];
         return (empty($homedir) ? false : $homedir);
     }

@@ -127,7 +130,8 @@
     function getShell()
     {
         $information = $this->_getAccount();
-        $shell = $information[0]['loginshell'][0];
+        if(!empty($information[0]['loginshell'][0]))
+           $shell = $information[0]['loginshell'][0];
         return (empty($shell) ? false : $shell);
     }
     

diff -ur forwards/config/conf.xml horde-3.0/forwards/config/conf.xml
--- forwards/config/conf.xml    2004-11-15 22:23:01.000000000 -0500
+++ horde-3.0/forwards/config/conf.xml  2004-12-27 13:09:06.899453548 -0500
@@ -100,6 +100,31 @@
     </configsection>
    </case>

+   <case name="ldap" desc="qmail-ldap based LDAP driver">
+    <configdescription>
+     If not using realms (multiple domains or virtual hosting) then there is
+     only one possible default configuration.
+     Even if you are using realms/hosting, you have to set a default
+     configuration.  This may be overriden by realm/domain specific values by
+     defining additional arrays, one per realm/domain, with the realm/domain
+     name as the key instead of the key 'default'. This not possible with 
this
+     interface though.
+    </configdescription>
+    <configsection name="params">
+     <configsection name="default">
+      <configstring name="host" desc="Hostname where the LDAP server is 
running on">localhost</configstring>
+      <configinteger name="port" desc="Port that the LDAP server is 
using">389</configinteger>
+      <configinteger name="version" required="false" desc="LDAP 
version">3</configinteger>
+      <configstring name="basedn" 
desc="Basedn">ou=mailaccount,dc=example,dc=com</configstring>
+      <configstring name="binddn" required="false" desc="Bind DN 
string">cn=Manager,dc=example,dc=com</configstring>
+      <configstring name="bindpass" required="false" desc="Bind password 
string"></configstring>
+      <configstring name="realm" required="false" 
desc="Realm"></configstring>
+      <configstring name="uid" desc="The attribute that is searched for the 
user ID">uid</configstring>
+      <configstring name="forwards" desc="The attribute that defines where 
the mail should go">mailForwardingAddress</configstring>
+     </configsection>
+    </configsection>
+   </case>
+
    <case name="customsql" desc="Custom SQL based forwarding driver">
     <configsection name="params">
      <configsql switchname="driverconfig"/>
diff -ur forwards/lib/Driver/ldap.php horde-3.0/forwards/lib/Driver/ldap.php
--- forwards/lib/Driver/ldap.php        2004-03-30 12:38:20.000000000 -0500
+++ horde-3.0/forwards/lib/Driver/ldap.php      2004-12-27 14:40:18.326271513 
-0500
@@ -67,17 +67,13 @@
         }

         // Connect as the user.
-        $res = $this->_connect($userdn, $pass, $realm);
+        $res = $this->_connect($this->_params[$realm]['binddn'], 
$this->_params[$realm]['bindpass'], $realm);
         if (is_a($res, 'PEAR_Error')) {
             $this->_error = $res->getMessage();
             $this->_error .= ' - ' .  _("Check your password");
@@ -86,7 +82,7 @@

         // Change the user's forwards.
         $newDetails[$this->_params[$realm]['forwards']] = $message;
-        $res = ldap_mod_replace($this->_ds, $userdn, $newDetails);
+        $res = ldap_mod_replace($this->_ds, $userdn, $newDetails) or 
ldap_mod_add($this->_ds, $userdn, $newDetails);
         if (!$res) {
             $res = PEAR::raiseError(ldap_error($this->_ds));
         }
@@ -308,8 +304,8 @@
                             $this->_params[$realm]['version']);
         }

-        if (!is_null($userdn)) {
-            $result = @ldap_bind($this->_ds, $userdn, $password);
+        if (!is_null($this->_params[$realm]['binddn'])) {
+            $result = @ldap_bind($this->_ds, $this->_params[$realm]
['binddn'], $this->_params[$realm]['bindpass']);
         } else {
             $result = @ldap_bind($this->_ds);
         }

diff -ur passwd/lib/Driver/ldap.php horde-3.0/passwd/lib/Driver/ldap.php
--- passwd/lib/Driver/ldap.php  2004-08-19 06:40:20.000000000 -0400
+++ horde-3.0/passwd/lib/Driver/ldap.php        2004-12-27 14:28:58.981559289 
-0500
@@ -34,6 +34,8 @@
         $this->_params['show_encryption'] = 
isset($params['show_encryption']) ? $params['show_encryption'] : 'true';
         $this->_params['uid']             = isset($params['uid']) ? 
$params['uid'] : 'uid';
         $this->_params['basedn']          = isset($params['basedn']) ? 
$params['basedn'] : '';
+        $this->_params['binddn']          = isset($params['binddn']) ? 
$params['binddn'] : '';
+        $this->_params['bindpass']        = isset($params['bindpass']) ? 
$params['bindpass'] : '';
         $this->_params['realm']           = isset($params['realm']) ? 
$params['realm'] : '';
         $this->_params['tls']             = isset($params['tls']) ? 
$params['tls'] : null;
         $this->_params['attribute']       = isset($params['attribute']) ? 
$params['attribute'] : 'userPassword';
@@ -71,8 +73,8 @@

         // Try to bind as the current userdn with password.
         $result = false;
-        if (!is_null($userdn)) {
-            $result = @ldap_bind($this->_ds, $userdn, $password);
+        if (!is_null($this->_params['binddn'])) {
+            $result = @ldap_bind($this->_ds, $this->_params['binddn'], 
$this->_params['bindpass']);
         }

         // If unable to bind as current user, still try to bind as
@@ -162,12 +164,12 @@
         $result = ldap_search($this->_ds, $this->_params['basedn'], $search);
         $entry = ldap_first_entry($this->_ds, $result);
         if ($entry !== false) {
-            $information = ldap_get_values($this->_ds, $entry, 
$this->_params['shadowlastchange']);
+            $information = @ldap_get_values($this->_ds, $entry, 
$this->_params['shadowlastchange']);
             if ($information) {
                 $lookupshadow['shadowlastchange'] = $information[0];
             }

-            $information = ldap_get_values($this->_ds, $entry, 
$this->_params['shadowmin']);
+            $information = @ldap_get_values($this->_ds, $entry, 
$this->_params['shadowmin']);
             if ($information) {
                 $lookupshadow['shadowmin'] = $information[0];
             }
	     
diff -ur vacation/config/conf.xml horde-3.0/vacation/config/conf.xml
--- vacation/config/conf.xml    2004-11-10 14:20:07.000000000 -0500
+++ horde-3.0/vacation/config/conf.xml  2004-12-27 14:07:01.205803580 -0500
@@ -139,6 +139,38 @@
      </configsection>
     </configsection>
    </case>
+   <case name="ldap" desc="qmail-ldap based LDAP driver">
+    <configdescription>
+     If not using realms (multiple domains or virtual hosting) then there is
+     only one possible default configuration.
+     Even if you are using realms/hosting, you have to set a default
+     configuration.  This may be overriden by realm/domain specific values by
+     defining additional arrays, one per realm/domain, with the realm/domain
+     name as the key instead of the key 'default'. This not possible with 
this
+     interface though.
+    </configdescription>
+    <configsection name="params">
+     <configsection name="default">
+      <configstring name="host" desc="Hostname where the LDAP server is 
running on">localhost</configstring>
+      <configinteger name="port" desc="Port that the LDAP server is 
using">389</configinteger>
+      <configstring name="basedn" 
desc="Basedn">ou=qmail,dc=example,dc=com</configstring>
+      <configstring name="binddn" required="false" desc="DN to bind as (empty 
for anonymous)">cn=Manager,dc=example,dc=com</configstring>
+      <configstring name="bindpass" required="false" desc="Bind DN 
password"></configstring>
+      <configstring name="uid" required="true" desc="Username search 
attribute">uid</configstring>
+      <configstring name="active" required="true" desc="Vacation Message 
Active attribute">deliveryMode</configstring>
+      <configstring name="vacation" desc="The attribute to search for. If it 
exists it defines the vacation message">mailReplyText</configstring>
+      <configenum name="hordeauth" desc="Should we log the user automatically
+      in with the username and password he uses to login to Horde?">
+       <values>
+        <value desc="No">false</value>
+        <value desc="Yes, with the full username">full</value>
+        <value desc="Yes, but with everything after the @ stripped from the
+        username">true</value>
+       </values>
+      </configenum>
+     </configsection>
+    </configsection>
+   </case>
   </configswitch>
  </configsection>

diff -ur vacation/lib/Driver/ldap.php horde-3.0/vacation/lib/Driver/ldap.php
--- vacation/lib/Driver/ldap.php        2004-04-29 09:56:54.000000000 -0400
+++ horde-3.0/vacation/lib/Driver/ldap.php      2004-12-27 14:40:37.354157858 
-0500
@@ -70,8 +70,8 @@
                                        $this->_params[$realm]['version']);
         }

-        if (!is_null($userdn)) {
-            $result = @ldap_bind($this->_ds, $userdn, $password);
+        if (!is_null($this->_params[$realm]['binddn'])) {
+            $result = @ldap_bind($this->_ds, $this->_params[$realm]
['binddn'], $this->_params[$realm]['bindpass']);
         } else {
             $result = @ldap_bind($this->_ds);
         }
@@ -188,11 +188,11 @@

         // Prepare the message. \n->\n\n and UTF-8 encode.
         $message = str_replace("\r\n", "\\n", $message);
-        $message = mb_convert_encoding($message, 'UTF-8', 'ISO-8859-1');
+        // $message = mb_convert_encoding($message, 'UTF-8', 'ISO-8859-1');

         // change the user's vacation.
         $newDetails[$this->_params[$realm]['vacation']] = $message;
-        $newDetails[$this->_params[$realm]['active']] = 'Y';
+        $newDetails[$this->_params[$realm]['active']] = 'reply';
         $res = ldap_mod_replace($this->_ds, $userdn, $newDetails);
         $attribs = array($this->_params[$realm]['vacation'], 
$this->_params[$realm]['active']);
         $value = $this->_getVacation($userdn, $attribs);
@@ -238,7 +238,7 @@

         // Prepare the message. \n->\n\n and UTF-8 encode.
         $vac['message'] = str_replace("\\\\n", "\r\n", $vac['message']);
-        $vac['message'] = mb_convert_encoding($vac['message'], 'ISO-8859-1', 
'UTF-8');
+        // $vac['message'] = mb_convert_encoding($vac['message'], 
'ISO-8859-1', 'UTF-8');

         return $vac;
     }
@@ -250,16 +250,12 @@
         if (!$entry) {
             return false;
         }
-        $value = ldap_get_values($this->_ds, $entry, $attribs[0]);
-        if ($value['count'] == 0) {
-            return false;
-        }
+        $value = @ldap_get_values($this->_ds, $entry, $attribs[0]);
         $retval['message'] = $value[0];
-        $value = ldap_get_values($this->_ds, $entry, $attribs[1]);
-        if ($value['count'] == 0) {
-            return false;
-        }
+
+        $value = @ldap_get_values($this->_ds, $entry, $attribs[1]);
         $retval['vacation'] = $value[0];
+
         return $retval;
     }

@@ -302,8 +298,8 @@
         }

         // Set the vacation message to inactive.
-        $newDetails[$this->_params[$realm]['active']] = 'N';
-        $res = ldap_mod_replace($this->_ds, $userdn, $newDetails);
+        $newDetails[$this->_params[$realm]['active']] = array();
+        $res = @ldap_mod_del($this->_ds, $userdn, $newDetails);
         if (!$res) {
             $res = PEAR::raiseError(ldap_error($this->_ds));
         }
diff -ur vacation/lib/Driver.php horde-3.0/vacation/lib/Driver.php
--- vacation/lib/Driver.php     2004-09-01 13:32:24.000000000 -0400
+++ horde-3.0/vacation/lib/Driver.php   2004-12-27 13:56:32.627701155 -0500
@@ -94,12 +94,10 @@
         }

         // Check vacation flag.
-        if ($current_details['vacation'] === 'y' ||
-            $current_details['vacation'] === 'Y') {
-            return 'Y';
-        } elseif ($current_details['vacation'] === 'n' ||
-                  $current_details['vacation'] === 'N') {
+       if(empty($current_details['vacation']))
             return 'N';
+        if ($current_details['vacation'] === 'reply') {
+            return 'Y';
         } else {
             return false;
         }
diff -ur vacation/templates/main/main.inc 
horde-3.0/vacation/templates/main/main.inc
--- vacation/templates/main/main.inc    2004-11-22 15:33:51.000000000 -0500
+++ horde-3.0/vacation/templates/main/main.inc  2004-12-27 14:11:55.366324264 
-0500
@@ -57,13 +57,6 @@

 <div>
 <br />
-<?php echo _("Subject:") ?>
-<br />
-<input name="subject" type="text" size="70" value="<?php echo 
htmlspecialchars($cursubject) ?>">
-</div>
-
-<div>
-<br />
 <?php echo _("Message:") ?>
 <br />
 <textarea name="mess" rows="8" cols="70"><?php echo 
htmlspecialchars($curmessage) ?></textarea>

-- 
Ian Samuel  B.Sc. CIS
Sr. Linux Systems Administrator


More information about the sork mailing list