+/**
+ * Deside which kind of operation is required to handle
+ * updating the specified attribute
+ *
+ * \param ld AddressBook resource
+ * \param dn dn for the entry
+ * \param attr Attribute
+ * \param value New value
+ * \return int, return will be LDAP_MOD_ADD, LDAP_MOD_REPLACE, or LDAP_MOD_DELETE
+ */
+int ldapsvr_deside_operation(LDAP *ld, char *dn, char *attr, char *value) {
+ int rc;
+ gboolean dummy = FALSE;
+
+ g_return_val_if_fail(ld != NULL || dn != NULL || attr != NULL, -1);
+ if (value == NULL)
+ return -1;
+ /* value containing empty string cause invalid syntax. A bug in
+ * the LDAP library? Therefore we add a dummy value
+ */
+ if (strcmp(value,"") == 0) {
+ value = g_strdup("thisisonlyadummy");
+ dummy = TRUE;
+ }
+ rc = ldap_compare_s(ld, dn, attr, value);
+ debug_print("ldap_compare for (%s:%s)\" error_code[0x%x]: %s\n",
+ attr, value, rc, ldap_err2string(rc));
+ switch (rc) {
+ case LDAP_COMPARE_FALSE:
+ if (dummy)
+ return LDAP_MOD_DELETE;
+ else
+ return LDAP_MOD_REPLACE;
+ case LDAP_COMPARE_TRUE: return -1;
+ case LDAP_NO_SUCH_ATTRIBUTE: return LDAP_MOD_ADD;
+ case LDAP_UNDEFINED_TYPE: return -2;
+ case LDAP_INVALID_SYNTAX: return -2;
+ default: return -2;
+ }
+}
+