Hi list,

In setups using postfix, LDAP, and virtual users, you used to have to
specify a user's homedirectory twice in the LDAP database. This is
because postfix uses a relative homedirectory with a configurable path
prepended, and courier uses an absolute homedir. This patch introduces a
new variable in the authldaprc, HOMEDIR_PREFIX, which can be used to
prefix the homedirectory from the ldap database with a given path, for
courier-imap.

i hope it is useful, please let me know what you think.

It is a patch against courier-imap-1.4.2.

Regards,
rolek

--
1A First Alternative [EMAIL PROTECTED]    www.alt001.com
Linvision BV         [EMAIL PROTECTED] (www|devel).linvision.com
--
diff -ru courier-imap-1.4.2-orig/authlib/authldaplib.c 
courier-imap-1.4.2/authlib/authldaplib.c
--- courier-imap-1.4.2-orig/authlib/authldaplib.c       Sat Jan 12 07:26:11 2002
+++ courier-imap-1.4.2/authlib/authldaplib.c    Wed Mar  6 15:35:00 2002
@@ -26,6 +26,15 @@
  */
 
 /*
+ * Modified 05/03/2002 Roel van Meer <[EMAIL PROTECTED]>
+ * Added support for the HOMEDIR_PREFIX option. If this option
+ * is specified in the config file, the contents of the ldap
+ * homedirectory attribute are prefixed with this string.
+ * It is mainly useful with postfix, which has a similar prefix
+ * option.
+ */
+
+/*
  * Modified 28/11/2001 Iustin Pop <[EMAIL PROTECTED]>
  * There was a bug regarding the LDAP_TLS option: if both LDAP_TLS
  * and was LDAP_AUTHBIND were enabled, the ldap_start_tls function
@@ -710,6 +719,7 @@
        int i, j;
 
        struct authinfo auth;
+       char *ldaphomeDir=0;
        char *homeDir=0;
        char *mailDir=0;
        char *userPassword=0;
@@ -740,7 +750,7 @@
        timeout.tv_sec=my_ldap.timeout;
        timeout.tv_usec=0;
 
-       read_env("LDAP_HOMEDIR", &attributes[0], "", 0, "homeDir");
+       read_env("LDAP_HOMEDIR", &attributes[0], "", 0, "ldaphomeDir");
        read_env("LDAP_MAILDIR", &attributes[1], "", 0, 0);
        read_env("LDAP_FULLNAME", &attributes[2], "", 0, "cn");
        read_env("LDAP_CLEARPW", &attributes[3], "", 0, 0);
@@ -749,6 +759,7 @@
        read_env("LDAP_GID", &attributes[6], "", 0, 0);
        attributes[7]=my_ldap.mail;
        read_env("LDAP_MAILDIRQUOTA", &attributes[8], "", 0, 0);
+       read_env("HOMEDIR_PREFIX", &attributes[9], "", 0, 0);
 
        j=0;
        for (i=0; i<9; i++)
@@ -807,8 +818,31 @@
 #if DEBUG_LDAP
        syslog(LOG_DAEMON|LOG_CRIT,"after ldap_first_entry\n");
 #endif
-       /* Copy the directory and the password into struct */
-       copy_value(my_ldap_fp,entry,attributes[0],&homeDir, user);
+       /* Copy the directory and the password into struct
+          if we have a value for HOMEDIR_PREFIX we put it
+          before the value of ldaphomeDir */
+       copy_value(my_ldap_fp,entry,attributes[0],&ldaphomeDir, user);
+       if (attributes[9])
+       {
+               homeDir = (char *)malloc(strlen(attributes[9])+strlen(ldaphomeDir)+1);
+               if (!homeDir)
+               {
+                       perror("malloc");
+                       exit(1);
+               }
+               strcpy (homeDir, attributes[9]);
+               strcat (homeDir, ldaphomeDir);
+       }
+       else
+       {
+               homeDir = (char *)malloc(strlen(ldaphomeDir)+1);
+               if (!homeDir)
+               {
+                       perror("malloc");
+                       exit(1);
+               }
+               strcpy (homeDir, ldaphomeDir);
+       }
        if (attributes[1])
                copy_value(my_ldap_fp,entry,attributes[1],&mailDir, user);
        copy_value(my_ldap_fp,entry,attributes[2],&cn, user);
@@ -1011,6 +1045,7 @@
        ldap_msgfree(result);
 
        if (homeDir)    free(homeDir);
+       if (ldaphomeDir)        free(ldaphomeDir);
        if (mailDir)    free(mailDir);
        if (userPassword)       free(userPassword);
        if (cryptPassword)      free(cryptPassword);
diff -ru courier-imap-1.4.2-orig/authlib/authldaprc 
courier-imap-1.4.2/authlib/authldaprc
--- courier-imap-1.4.2-orig/authlib/authldaprc  Mon Nov 19 02:20:28 2001
+++ courier-imap-1.4.2/authlib/authldaprc       Wed Mar  6 13:56:36 2002
@@ -91,6 +91,15 @@
 
 LDAP_HOMEDIR           homeDirectory
 
+##NAME: HOMEDIR_PREFIX:0
+#
+# If HOMEDIR_PREFIX is specified, the result of the attribute specified with
+# LDAP_HOMEDIR will be prefixed with this string. It can be used to use a
+# single attribute for the homedir when using postfix, which has a similar
+# prefix option. Please note the ending slash, it is important in most setups.
+#
+# HOMEDIR_PREFIX       /var/spool/mail/
+
 ##NAME: LDAP_MAILDIR:0
 #
 # The MAILDIR attribute is OPTIONAL, and specifies the location of the

Reply via email to