Added LDAP: to begining of lprintfs in ldap module.
authorDave West <davew@uncensored.citadel.org>
Sat, 6 Oct 2007 13:45:39 +0000 (13:45 +0000)
committerDave West <davew@uncensored.citadel.org>
Sat, 6 Oct 2007 13:45:39 +0000 (13:45 +0000)
Now editing a Vcard in the GAB room updates the ldap entry but only
if it is the users own ldap entry.

citadel/modules/ldap/serv_ldap.c
citadel/modules/ldap/serv_ldap.h [new file with mode: 0644]
citadel/modules/vcard/serv_vcard.c
citadel/serv_ldap.h [deleted file]

index 55af94521ec63c7d99a03839159504442973bfa1..78343e05df5f2bcb5865800cc235235b11e47bc0 100644 (file)
@@ -61,7 +61,7 @@ void serv_ldap_cleanup(void)
 {
        if (!dirserver) return;
 
-       lprintf(CTDL_INFO, "Unbinding from directory server\n");
+       lprintf(CTDL_INFO, "LDAP: Unbinding from directory server\n");
        ldap_unbind(dirserver);
        dirserver = NULL;
 }
@@ -108,16 +108,16 @@ void CtdlCreateLdapRoot(void) {
        mods[2] = NULL;
 
        /* Perform the transaction */
-       lprintf(CTDL_DEBUG, "Setting up Base DN node...\n");
+       lprintf(CTDL_DEBUG, "LDAP: Setting up Base DN node...\n");
        begin_critical_section(S_LDAP);
        i = ldap_add_s(dirserver, config.c_ldap_base_dn, mods);
        end_critical_section(S_LDAP);
 
        if (i == LDAP_ALREADY_EXISTS) {
-               lprintf(CTDL_INFO, "Base DN is already present in the directory; no need to add it again.\n");
+               lprintf(CTDL_INFO, "LDAP: 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",
+               lprintf(CTDL_CRIT, "LDAP: ldap_add_s() failed: %s (%d)\n",
                        ldap_err2string(i), i);
        }
 }
@@ -156,16 +156,16 @@ int CtdlCreateLdapHostOU(char *cn, char *host, void **object) {
        mods[2] = NULL;
 
        /* Perform the transaction */
-       lprintf(CTDL_DEBUG, "Setting up Host OU node...\n");
+       lprintf(CTDL_DEBUG, "LDAP: Setting up Host OU node...\n");
        begin_critical_section(S_LDAP);
        i = ldap_add_s(dirserver, dn, mods);
        end_critical_section(S_LDAP);
 
        if (i == LDAP_ALREADY_EXISTS) {
-               lprintf(CTDL_INFO, "Host OU is already present in the directory; no need to add it again.\n");
+               lprintf(CTDL_INFO, "LDAP: 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",
+               lprintf(CTDL_CRIT, "LDAP: ldap_add_s() failed: %s (%d)\n",
                        ldap_err2string(i), i);
                return -1;
        }
@@ -183,12 +183,12 @@ void CtdlConnectToLdap(void) {
        int i;
        int ldap_version = 3;
 
-       lprintf(CTDL_INFO, "Connecting to LDAP server %s:%d...\n",
+       lprintf(CTDL_INFO, "LDAP: Connecting to LDAP server %s:%d...\n",
                config.c_ldap_host, config.c_ldap_port);
 
        dirserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
        if (dirserver == NULL) {
-               lprintf(CTDL_CRIT, "Could not connect to %s:%d : %s\n",
+               lprintf(CTDL_CRIT, "LDAP: Could not connect to %s:%d : %s\n",
                        config.c_ldap_host,
                        config.c_ldap_port,
                        strerror(errno));
@@ -197,14 +197,14 @@ void CtdlConnectToLdap(void) {
 
        ldap_set_option(dirserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
 
-       lprintf(CTDL_INFO, "Binding to %s\n", config.c_ldap_bind_dn);
+       lprintf(CTDL_INFO, "LDAP: Binding to %s\n", config.c_ldap_bind_dn);
 
        i = ldap_simple_bind_s(dirserver,
                                config.c_ldap_bind_dn,
                                config.c_ldap_bind_pw
        );
        if (i != LDAP_SUCCESS) {
-               lprintf(CTDL_CRIT, "Cannot bind: %s (%d)\n", ldap_err2string(i), i);
+               lprintf(CTDL_CRIT, "LDAP: Cannot bind: %s (%d)\n", ldap_err2string(i), i);
                dirserver = NULL;       /* FIXME disconnect from ldap */
                return;
        }
@@ -221,7 +221,7 @@ void CtdlConnectToLdap(void) {
 int CtdlCreateLdapObject(char *cn, char *ou, void **object)
 {
        // We do nothing here, this just gets the base structure created by the interface.
-       lprintf (CTDL_DEBUG, "Created ldap object\n");
+       lprintf (CTDL_DEBUG, "LDAP: Created ldap object\n");
        return 0;
 }
 
@@ -238,7 +238,7 @@ int CtdlAddLdapAttr(char *cn, char *ou, void **object)
        int cur_attr;
        
        
-       lprintf (CTDL_DEBUG, "Adding ldap attribute\n");
+       lprintf (CTDL_DEBUG, "LDAP: Adding ldap attribute name:\"%s\" vlaue:\"%s\"\n", cn, ou);
        
        attrs = *object;
        if (attrs)
@@ -305,7 +305,7 @@ int CtdlSaveLdapObject(char *cn, char *ou, void **object)
                        num_attrs++;
        }
        
-       lprintf(CTDL_DEBUG, "Calling ldap_add_s() for '%s'\n", this_dn);
+       lprintf(CTDL_DEBUG, "LDAP: Calling ldap_add_s() for '%s'\n", this_dn);
        
        begin_critical_section(S_LDAP);
        i = ldap_add_s(dirserver, this_dn, attrs);
@@ -316,14 +316,14 @@ int CtdlSaveLdapObject(char *cn, char *ou, void **object)
                for (j=0; j<(num_attrs); ++j) {
                        attrs[j]->mod_op = LDAP_MOD_REPLACE;
                }
-               lprintf(CTDL_DEBUG, "Calling ldap_modify_s() for '%s'\n", this_dn);
+               lprintf(CTDL_DEBUG, "LDAP: 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);
        }
 
        if (i != LDAP_SUCCESS) {
-               lprintf(CTDL_ERR, "ldap_add_s() failed: %s (%d)\n",
+               lprintf(CTDL_ERR, "LDAP: ldap_add_s() failed: %s (%d)\n",
                        ldap_err2string(i), i);
                return -1;
        }
@@ -348,7 +348,7 @@ int CtdlFreeLdapObject(char *cn, char *ou, void **object)
                        num_attrs++;
        }
 
-       lprintf(CTDL_DEBUG, "Freeing attributes\n");
+       lprintf(CTDL_DEBUG, "LDAP: Freeing attributes\n");
        /* Free the attributes */
        for (i=0; i<num_attrs; ++i) {
                if (attrs[i] != NULL) {
@@ -393,14 +393,14 @@ int CtdlDeleteFromLdap(char *cn, char *ou, void **object)
        
        sprintf(this_dn, "cn=%s,ou=%s,%s", cn, ou, config.c_ldap_base_dn);
        
-       lprintf(CTDL_DEBUG, "Calling ldap_delete_s()\n");
+       lprintf(CTDL_DEBUG, "LDAP: Calling ldap_delete_s()\n");
        
        begin_critical_section(S_LDAP);
        i = ldap_delete_s(dirserver, this_dn);
        end_critical_section(S_LDAP);
        
        if (i != LDAP_SUCCESS) {
-               lprintf(CTDL_ERR, "ldap_delete_s() failed: %s (%d)\n",
+               lprintf(CTDL_ERR, "LDAP: ldap_delete_s() failed: %s (%d)\n",
                        ldap_err2string(i), i);
                return -1;
        }
diff --git a/citadel/modules/ldap/serv_ldap.h b/citadel/modules/ldap/serv_ldap.h
new file mode 100644 (file)
index 0000000..5f3130d
--- /dev/null
@@ -0,0 +1,10 @@
+/*
+ * $Id$
+ *
+ */
+
+#ifdef HAVE_LDAP
+
+void ctdl_vcard_to_ldap(struct CtdlMessage *msg, int op);
+
+#endif /* HAVE_LDAP */
index 5ece955e1564b8c43b3f644a372c3754d40564b4..066fc72534780a57216584f45b17e52faf695238 100644 (file)
@@ -663,6 +663,8 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
        int linelen;
        long I;
        struct vCard *v;
+       int is_UserConf=0;
+       int is_GAB=0;
 
        if (!CC->logged_in) return(0);  /* Only do this if logged in. */
 
@@ -670,7 +672,9 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
         * message, don't bother.
         */
        if (msg->cm_fields['O'] == NULL) return(0);
-       if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
+       if (!strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) is_UserConf = 1;
+       if (!strcasecmp(msg->cm_fields['O'], ADDRESS_BOOK_ROOM)) is_GAB = 1;
+       if (!is_UserConf && !is_GAB) return(0);
        if (msg->cm_format_type != 4) return(0);
 
        ptr = msg->cm_fields['M'];
@@ -698,8 +702,11 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
                        extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
                        vcard_free(v);
 
-                       /* Put it in the Global Address Book room... */
-                       CtdlSaveMsgPointerInRoom(ADDRESS_BOOK_ROOM, I, 1, msg);
+                       if (!is_GAB)
+                       {       // This is not the GAB
+                               /* Put it in the Global Address Book room... */
+                               CtdlSaveMsgPointerInRoom(ADDRESS_BOOK_ROOM, I, 1, msg);
+                       }
 
                        /* ...and also in the directory database. */
                        vcard_add_to_directory(I, NULL);
diff --git a/citadel/serv_ldap.h b/citadel/serv_ldap.h
deleted file mode 100644 (file)
index 5f3130d..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * $Id$
- *
- */
-
-#ifdef HAVE_LDAP
-
-void ctdl_vcard_to_ldap(struct CtdlMessage *msg, int op);
-
-#endif /* HAVE_LDAP */