From c3fd8faefc68e5ae738462f9bb446d76b7a8102a Mon Sep 17 00:00:00 2001 From: Dave West Date: Sat, 6 Oct 2007 13:45:39 +0000 Subject: [PATCH] Added LDAP: to begining of lprintfs in ldap module. 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 | 38 +++++++++++++------------- citadel/{ => modules/ldap}/serv_ldap.h | 0 citadel/modules/vcard/serv_vcard.c | 13 +++++++-- 3 files changed, 29 insertions(+), 22 deletions(-) rename citadel/{ => modules/ldap}/serv_ldap.h (100%) diff --git a/citadel/modules/ldap/serv_ldap.c b/citadel/modules/ldap/serv_ldap.c index 55af94521..78343e05d 100644 --- a/citadel/modules/ldap/serv_ldap.c +++ b/citadel/modules/ldap/serv_ldap.c @@ -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; ilogged_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); -- 2.39.2