]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/ldap/serv_ldap.c
* serv_ldap.c: upon successful connect to an LDAP server, post an aide message warnin...
[citadel.git] / citadel / modules / ldap / serv_ldap.c
index 23e6b91b66363fb7ae512e66a7fc22d47211b5b3..a7551dcbfecd1efcdb4c785ffc5980e13c6b1a6f 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -38,7 +39,6 @@
 #include "policy.h"
 #include "database.h"
 #include "serv_ldap.h"
-#include "tools.h"
 
 
 #include "ctdl_module.h"
@@ -55,6 +55,11 @@ LDAP *dirserver = NULL;
 int ldap_time_disconnect = 0;
 
 
+
+/* There is a forward referance so.... */
+int delete_from_ldap(char *cn, char *ou, void **object);
+
+
 /*
  * LDAP connector cleanup function
  */
@@ -70,7 +75,13 @@ void serv_ldap_cleanup(void)
 }
 
 
-
+/*
+ * connect_to_ldap
+ *
+ * BIG FAT WARNING
+ * Make sure this function is only called from within a begin_critical_section(S_LDAP)
+ * If you don't things will break!!!!!.
+ */
 
 
 int connect_to_ldap(void)
@@ -78,8 +89,8 @@ int connect_to_ldap(void)
        int i;
        int ldap_version = 3;
 
-       if (ldap_time_disconnect && dirserver) {        // Already connected
-               ldap_time_disconnect = 5;       // reset the timer.
+       if (dirserver) {        // Already connected
+               ldap_time_disconnect = 1 ;      // reset the timer.
                return 0;
        }
 
@@ -96,6 +107,16 @@ int connect_to_ldap(void)
                             "LDAP: Could not connect to server.");
                return -1;
        }
+       else {
+               CtdlAideMessage(
+                       "WARNING: populating an external LDAP address book is deprecated.\n"
+                       "This function will be discontinued in a future release.\n"
+                       "Please migrate to vCard-based address books as soon as possible.\n"
+                       "Visit the Citadel support forum if you need further assistance.\n"
+                       ,
+                       "Warning: LDAP address book is deprecated"
+               );
+       }
 
        ldap_set_option(dirserver, LDAP_OPT_PROTOCOL_VERSION,
                        &ldap_version);
@@ -113,7 +134,7 @@ int connect_to_ldap(void)
                             "LDAP: Cannot bind to server");
                return -1;
        }
-       ldap_time_disconnect = 5;
+       ldap_time_disconnect = 1;
        return 0;
 }
 
@@ -323,7 +344,7 @@ int add_ldap_object(char *cn, char *ou, void **object)
  */
 int save_ldap_object(char *cn, char *ou, void **object)
 {
-       int i, j;
+       int i;
 
        char this_dn[SIZ];
        LDAPMod **attrs;
@@ -379,14 +400,21 @@ int save_ldap_object(char *cn, char *ou, void **object)
        }
 
        /* If the entry already exists, repopulate it instead */
+       /* repopulating doesn't work as Citadel may want some attributes to be deleted.
+        * we have no way of knowing which attributes to delete and LDAP won't work it out for us
+        * so now we delete the old entry and create a new one.
+        */
        if (i == LDAP_ALREADY_EXISTS) {
-               for (j = 0; j < (num_attrs); ++j) {
-                       attrs[j]->mod_op = LDAP_MOD_REPLACE;
-               }
+               end_critical_section(S_LDAP);
                CtdlLogPrintf(CTDL_INFO,
-                       "LDAP: Calling ldap_modify_s() for dn of '%s'\n",
+                       "LDAP: Create, already exists, deleteing first.\n");
+               if (delete_from_ldap(cn, ou, NULL))
+                       return -1;
+               begin_critical_section(S_LDAP);
+               CtdlLogPrintf(CTDL_INFO,
+                       "LDAP: Calling ldap_add_s() to recreate for dn of '%s'\n",
                        this_dn);
-               i = ldap_modify_s(dirserver, this_dn, attrs);
+               i = ldap_add_s(dirserver, this_dn, attrs);
        }
 
        if (i != LDAP_SUCCESS) {
@@ -462,8 +490,6 @@ int delete_from_ldap(char *cn, char *ou, void **object)
 
        if (dirserver == NULL)
                return -1;
-       if (ou == NULL)
-               return -1;
        if (cn == NULL)
                return -1;
 
@@ -523,32 +549,35 @@ void ldap_disconnect_timer(void)
  */
 CTDL_MODULE_INIT(ldap)
 {
+       if (!threading)
+       {
 #ifdef HAVE_LDAP
-       if (!IsEmptyStr(config.c_ldap_base_dn)) {
-               CtdlRegisterCleanupHook(serv_ldap_cleanup);
-               CtdlRegisterSessionHook(ldap_disconnect_timer, EVT_TIMER);
-               CtdlRegisterDirectoryServiceFunc(delete_from_ldap,
-                                                DIRECTORY_USER_DEL,
-                                                "ldap");
-               CtdlRegisterDirectoryServiceFunc(create_ldap_host_OU,
-                                                DIRECTORY_CREATE_HOST,
-                                                "ldap");
-               CtdlRegisterDirectoryServiceFunc(create_ldap_object,
-                                                DIRECTORY_CREATE_OBJECT,
-                                                "ldap");
-               CtdlRegisterDirectoryServiceFunc(add_ldap_object,
-                                                DIRECTORY_ATTRIB_ADD,
-                                                "ldap");
-               CtdlRegisterDirectoryServiceFunc(save_ldap_object,
-                                                DIRECTORY_SAVE_OBJECT,
-                                                "ldap");
-               CtdlRegisterDirectoryServiceFunc(free_ldap_object,
-                                                DIRECTORY_FREE_OBJECT,
-                                                "ldap");
-               create_ldap_root();
-       }
+               if (!IsEmptyStr(config.c_ldap_base_dn)) {
+                       CtdlRegisterCleanupHook(serv_ldap_cleanup);
+                       CtdlRegisterSessionHook(ldap_disconnect_timer, EVT_TIMER);
+                       CtdlRegisterDirectoryServiceFunc(delete_from_ldap,
+                                                        DIRECTORY_USER_DEL,
+                                                        "ldap");
+                       CtdlRegisterDirectoryServiceFunc(create_ldap_host_OU,
+                                                        DIRECTORY_CREATE_HOST,
+                                                        "ldap");
+                       CtdlRegisterDirectoryServiceFunc(create_ldap_object,
+                                                        DIRECTORY_CREATE_OBJECT,
+                                                        "ldap");
+                       CtdlRegisterDirectoryServiceFunc(add_ldap_object,
+                                                        DIRECTORY_ATTRIB_ADD,
+                                                        "ldap");
+                       CtdlRegisterDirectoryServiceFunc(save_ldap_object,
+                                                        DIRECTORY_SAVE_OBJECT,
+                                                        "ldap");
+                       CtdlRegisterDirectoryServiceFunc(free_ldap_object,
+                                                        DIRECTORY_FREE_OBJECT,
+                                                        "ldap");
+                       create_ldap_root();
+               }
 #endif                         /* HAVE_LDAP */
-
+       }
+       
        /* return our Subversion id for the Log */
        return "$Id$";
 }