Moved to new module init structure.
[citadel.git] / citadel / serv_ldap.c
index fc184155e92cb2574d587381c1a3f1341f4da027..f3e5a774a64b37cda558ac3f7fe8748f87527167 100644 (file)
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "serv_extensions.h"
 #include "room_ops.h"
 #include "policy.h"
 #include "database.h"
 #include "vcard.h"
 #include "tools.h"
 
+
+#include "ctdl_module.h"
+
+
+
 #ifdef HAVE_LDAP
 
 #include <ldap.h>
@@ -106,7 +109,10 @@ void CtdlCreateLdapRoot(void) {
        i = ldap_add_s(dirserver, config.c_ldap_base_dn, mods);
        end_critical_section(S_LDAP);
 
-       if (i != LDAP_SUCCESS) {
+       if (i == LDAP_ALREADY_EXISTS) {
+               lprintf(CTDL_INFO, "Base DN is already present in the directory; no need to add it again.\n");
+       }
+       else if (i != LDAP_SUCCESS) {
                lprintf(CTDL_CRIT, "ldap_add_s() failed: %s (%d)\n",
                        ldap_err2string(i), i);
        }
@@ -149,12 +155,13 @@ void CtdlCreateHostOU(char *host) {
        i = ldap_add_s(dirserver, dn, mods);
        end_critical_section(S_LDAP);
 
-       /* ignore the error -- it's ok if it already exists
-       if (i != LDAP_SUCCESS) {
-               lprintf(CTDL_ERR, "ldap_add_s() failed: %s (%d)\n",
+       if (i == LDAP_ALREADY_EXISTS) {
+               lprintf(CTDL_INFO, "Host OU is already present in the directory; no need to add it again.\n");
+       }
+       else if (i != LDAP_SUCCESS) {
+               lprintf(CTDL_CRIT, "ldap_add_s() failed: %s (%d)\n",
                        ldap_err2string(i), i);
        }
-       */
 }
 
 
@@ -530,7 +537,7 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg, int op) {
        attrs = realloc(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
        attrs[num_attrs - 1] = NULL;
        
-       lprintf(CTDL_DEBUG, "Calling ldap_add_s()\n");
+       lprintf(CTDL_DEBUG, "Calling ldap_add_s() for '%s'\n", this_dn);
        begin_critical_section(S_LDAP);
        i = ldap_add_s(dirserver, this_dn, attrs);
        end_critical_section(S_LDAP);
@@ -540,7 +547,7 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg, int op) {
                for (j=0; j<(num_attrs-1); ++j) {
                        attrs[j]->mod_op = LDAP_MOD_REPLACE;
                }
-               lprintf(CTDL_DEBUG, "Calling ldap_modify_s()\n");
+               lprintf(CTDL_DEBUG, "Calling ldap_modify_s() for '%s'\n", this_dn);
                begin_critical_section(S_LDAP);
                i = ldap_modify_s(dirserver, this_dn, attrs);
                end_critical_section(S_LDAP);
@@ -583,7 +590,7 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg, int op) {
 /*
  * Initialize the LDAP connector module ... or don't, if we don't have LDAP.
  */
-char *serv_ldap_init(void)
+CTDL_MODULE_INIT(ldap)
 {
 #ifdef HAVE_LDAP
        CtdlRegisterCleanupHook(serv_ldap_cleanup);
@@ -593,5 +600,7 @@ char *serv_ldap_init(void)
        }
 
 #endif                         /* HAVE_LDAP */
+
+       /* return our Subversion id for the Log */
        return "$Id$";
 }