/** * Get person object from cache * * \param server Resource to LDAP * \param uid PersonID in cache * \return person object, or <i>NULL</i> if fail */ ItemPerson *ldapsvr_get_contact(LdapServer *server, gchar *uid) { AddrItemObject *aio; cm_return_val_if_fail(server != NULL || uid != NULL, NULL); aio = addrcache_get_object(server->addressCache, uid); if (aio) { if(aio->type == ITEMTYPE_PERSON) { return (ItemPerson *) aio; } } return NULL; }
/* * Find email address in address cache. * param: eid EMail ID. * return: email object for specified object ID and email ID, or NULL if not found. */ ItemEMail *addrcache_get_email( AddressCache *cache, const gchar *eid ) { ItemEMail *email = NULL; AddrItemObject *obj = addrcache_get_object( cache, eid ); if( obj ) { if( ADDRITEM_TYPE(obj) == ITEMTYPE_EMAIL ) { email = ( ItemEMail * ) obj; } } return email; }
/** * Deside which other attributes needs updating * * \param ld LDAP resource * \param server AddressBook resource * \param dn dn for the entry * \param contact GHashTable with information for the current contact */ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHashTable *contact) { GList *node; gboolean CHECKED_ATTRIBUTE[ATTRIBUTE_SIZE + 1]; LDAPMod *mods[ATTRIBUTE_SIZE + 1]; LDAPMod modarr[ATTRIBUTE_SIZE]; gint cnt = 0; char *attr[ATTRIBUTE_SIZE + 1][2]; int mod_op, rc, i; cm_return_if_fail(server != NULL || dn != NULL || contact != NULL); for (i = 0; i <= ATTRIBUTE_SIZE; i++) { CHECKED_ATTRIBUTE[i] = FALSE; attr[i][0] = attr[i][1] = NULL; } node = g_hash_table_lookup(contact , "attribute"); while (node) { AttrKeyValue *item = node->data; if (item) { int index = get_attribute_index(item->key); if (index >= 0) { debug_print("Found other attribute: %s = %s\n", item->key?item->key:"null", item->value?item->value:"null"); mod_op = ldapsvr_deside_operation(ld, server, dn, item->key, item->value); /* Only consider attributes which we no how to handle. * Set to TRUE in CHECKED_ATTRIBUTE array to indicate no further action */ if (mod_op < 0) { CHECKED_ATTRIBUTE[index] = TRUE; node = g_list_next(node); continue; } if (mod_op == LDAP_MOD_DELETE) { /* Setting param to NULL instructs OpenLDAP to remove any * value stored for this attribute and remove the attribute * completely. Should multiple instances of an attribute be * allowed in the future param is required to have the value * store for the attribute which is going to be deleted */ item->value = NULL; } if (mod_op == LDAP_MOD_REPLACE && strcmp(item->value, "") == 0) { /* Having an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we treate this as a request for deleting * the attribute. */ mod_op = LDAP_MOD_DELETE; item->value = NULL; } if (mod_op == LDAP_MOD_ADD && strcmp(item->value, "") == 0) { /* Adding an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we silently refuse to add this entry */ } else { SETMOD(mods[cnt], modarr[cnt], mod_op, g_strdup(item->key), attr[cnt], g_strdup(item->value)); cnt++; CHECKED_ATTRIBUTE[index] = TRUE; } } } node = g_list_next(node); } char **attribs = ldapctl_full_attribute_array(server->control); for (i = 0; i < ATTRIBUTE_SIZE; i++) { /* Attributes which holds no information are to be removed */ if (CHECKED_ATTRIBUTE[i] == FALSE) { /* Only consider those attributes which is currently part of the search criteria. * If attributes are not part of the search criteria they would seem to hold * no information since their values will not be populated in the GUI */ if (!strcmp(ATTRIBUTE[i], "jpegPhoto")) { debug_print("not updating jpegPhoto\n"); continue; } if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) { mod_op = ldapsvr_deside_operation(ld, server, dn, (char *) ATTRIBUTE[i], ""); if (mod_op == LDAP_MOD_DELETE) { SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_DELETE, g_strdup((char *) ATTRIBUTE[i]), attr[cnt], NULL); cnt++; } } } } ldapctl_free_attribute_array(attribs); mods[cnt] = NULL; if (debug_get_mode()) ldapsvr_print_ldapmod(mods); server->retVal = LDAPRC_SUCCESS; rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL); if (rc) { switch (rc) { case LDAP_ALREADY_EXISTS: server->retVal = LDAPRC_ALREADY_EXIST; break; default: g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n", dn, rc, ldaputil_get_error(ld)); if (rc == 0x8) server->retVal = LDAPRC_STRONG_AUTH; else server->retVal = LDAPRC_NAMING_VIOLATION; } } else { char **attribs = ldapctl_full_attribute_array(server->control); for (i = 0; i < ATTRIBUTE_SIZE; i++) { if (!strcmp(ATTRIBUTE[i], "jpegPhoto")) { debug_print("not updating jpegPhoto\n"); continue; } if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) { if (CHECKED_ATTRIBUTE[i] == FALSE) { AddrItemObject *aio = addrcache_get_object(server->addressCache, g_hash_table_lookup(contact , "uid")); ItemPerson *person = (ItemPerson *) aio; addritem_person_remove_attribute(person, (const gchar *) ATTRIBUTE[i]); } } } ldapctl_free_attribute_array(attribs); } }