From: <svn...@op...> - 2009-04-04 00:36:58
|
Author: scriptor Date: Sat Apr 4 02:36:54 2009 New Revision: 5530 URL: http://www.opensync.org/changeset/5530 Log: Better handling of "No such object": This is an LDAP error message, that seems to occur even in regular cases, where there is really not a single entry in the DIT and nobody would consider this as an error condition. Modified: plugins/ldap-sync/src/ldap_connect.c plugins/ldap-sync/src/ldap_plugin.c plugins/ldap-sync/src/ldap_plugin.h plugins/ldap-sync/src/ldap_sasl.c Modified: plugins/ldap-sync/src/ldap_connect.c ============================================================================== --- plugins/ldap-sync/src/ldap_connect.c Sat Apr 4 02:36:45 2009 (r5529) +++ plugins/ldap-sync/src/ldap_connect.c Sat Apr 4 02:36:54 2009 (r5530) @@ -1134,7 +1134,7 @@ // Look for all the LDAP subschemata: - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "cn=Subschema", "(objectClass=subschema)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, &res, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "cn=Subschema", "(objectClass=subschema)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, FALSE, &res, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -1220,12 +1220,15 @@ * @param kind_of_attributes For example, whether user attributes or control attributes are to be shown. * @param sinkenv The object type specific environment * @param results This function fills this struct with the search result. + * @param ignore_no_such_object This variable tells this function whether + * or not it should ignore "No such object" + * messages by libldap. * @param error The libopensync error pointer. * * @returns TRUE on success, FALSE, on failure. */ -osync_bool ldap_plugin_call_ldap_search(OSyncContext *ctx, const LDAP *ldap_handle, const char *searchbase, const char *filter, const int scope, const int kind_of_attributes, const sink_environment *sinkenv, LDAPMessage **results, OSyncError **error) +osync_bool ldap_plugin_call_ldap_search(OSyncContext *ctx, const LDAP *ldap_handle, const char *searchbase, const char *filter, const int scope, const int kind_of_attributes, const sink_environment *sinkenv, osync_bool ignore_no_such_object, LDAPMessage **results, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %d, %d, %p, %p)", __func__, ctx, ldap_handle, searchbase, filter, scope, kind_of_attributes, sinkenv, error); @@ -1316,41 +1319,46 @@ ); - if (rv != LDAP_SUCCESS) { - // Translate scope into something human readable - switch(scope) { - case LDAP_SCOPE_BASE: - scope_str = "base"; - break; - - case LDAP_SCOPE_ONELEVEL: - scope_str = "one"; - break; - - case LDAP_SCOPE_SUBTREE: - scope_str = "sub"; - break; - - case LDAP_SCOPE_CHILDREN: - scope_str = "children"; - break; - - default: - scope_str = "default"; - break; - } - - msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, rv); + if (rv == LDAP_NO_SUCH_OBJECT && ignore_no_such_object) { + osync_trace(TRACE_INTERNAL, "%s:%i: ldap_search_ext_s() has returned LDAP_NO_SUCH_OBJECT, but ignore_no_such_object was set to TRUE.", __FILE__, __LINE__); + } else { + if (rv != LDAP_SUCCESS) { + // Translate scope into something human readable + switch(scope) { + case LDAP_SCOPE_BASE: + scope_str = "base"; + break; - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Unable to search on \"%s\" with filter \"%s\" and scope \"%s\": %s", __FILE__, __LINE__, searchbase, filter, scope_str, msg ? msg : ""); - - if (msg) { - g_free(msg); - msg = NULL; + case LDAP_SCOPE_ONELEVEL: + scope_str = "one"; + break; + + case LDAP_SCOPE_SUBTREE: + scope_str = "sub"; + break; + + case LDAP_SCOPE_CHILDREN: + scope_str = "children"; + break; + + default: + scope_str = "default"; + break; + } + + msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, rv); + + + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Unable to search on \"%s\" with filter \"%s\" and scope \"%s\": %s", __FILE__, __LINE__, searchbase, filter, scope_str, msg ? msg : ""); + + if (msg) { + g_free(msg); + msg = NULL; + } + + goto error; } - - goto error; } @@ -1410,7 +1418,7 @@ *rv = LDAP_SUCCESS; - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, dn, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, &all_results, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, dn, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, TRUE, &all_results, error)) { int result_code = 0; @@ -1801,7 +1809,7 @@ // --------------------------------------------------------------- /* Search all entries that apply to the filter */ - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, &all_results, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, TRUE, &all_results, error)) { int result_code = 0; @@ -1812,11 +1820,18 @@ ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); if (result_code == LDAP_NO_SUCH_OBJECT) { - ldap_plugin_printf("%s:%i: Either the searchbase (\"%s\") is really wrong, or the user does not have sufficient access permissions to this particular part of the DIT.", __FILE__, __LINE__, base); - } + osync_trace(TRACE_INTERNAL, "%s:%i: Either the searchbase (\"%s\") is really wrong, or the user does not have sufficient access permissions to this particular part of the DIT, or there is indeed not a single entry.", __FILE__, __LINE__, base); + // Forget error message in this case. + if (osync_error_is_set(error)) { + osync_error_unref(error); + } - goto error; + goto done; + + } else { + goto error; + } } @@ -1831,7 +1846,21 @@ ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); - if (result_code != LDAP_SUCCESS) { + if (result_code == LDAP_SUCCESS) { + goto done; + + } else if (result_code == LDAP_NO_SUCH_OBJECT) { + goto done; + + } else { + char *ldap_error = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, result_code); + + if (ldap_error == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_first_entry() has failed.", __FILE__, __LINE__); + } else { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_first_entry() has failed: \"%s\"", __FILE__, __LINE__, ldap_error); + } + goto error; } } @@ -1853,7 +1882,7 @@ char *subentry_filter = (char *)"(objectClass=*)"; LDAPMessage *possible_subentries = NULL; - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, subentry_filter, LDAP_SCOPE_CHILDREN, USER_ATTRIBUTES, sinkenv, &possible_subentries, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, subentry_filter, LDAP_SCOPE_CHILDREN, USER_ATTRIBUTES, sinkenv, FALSE, &possible_subentries, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -1911,7 +1940,7 @@ ldap_msgfree(all_results); - +done: osync_trace(TRACE_EXIT, "%s: *entrylist = %p", __func__, *entrylist); return TRUE; @@ -2178,7 +2207,7 @@ snprintf(filter, 4095, "(%s=*)", sinkenv->keyattr); - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, sinkenv->searchbase, filter, LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, &uids, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, sinkenv->searchbase, filter, LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, TRUE, &uids, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -2224,9 +2253,8 @@ if (result_code == LDAP_SUCCESS) { osync_trace(TRACE_INTERNAL, "%s:%i: uid = NULL, but LDAP_SUCCESS. This is ok.", __FILE__, __LINE__); goto ok1; - } - if (result_code == LDAP_NO_SUCH_OBJECT) { + } else if (result_code == LDAP_NO_SUCH_OBJECT) { osync_trace(TRACE_INTERNAL, "%s:%i: uid = NULL: LDAP_NO_SUCH_OBJECT: This is ok here.", __FILE__, __LINE__); goto ok1; @@ -2503,7 +2531,7 @@ // -------------------------------------------------- // Get entryCSN for the base entry itself plus all related subentries - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_SUBTREE, OPERATIONAL_ATTRIBUTES, sinkenv, &all_entries, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_SUBTREE, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &all_entries, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -4196,7 +4224,7 @@ filter = (char *)"(entryCSN=*)"; } - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "(entryCSN=*)", LDAP_SCOPE_SUB, OPERATIONAL_ATTRIBUTES, sinkenv, &messages, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "(entryCSN=*)", LDAP_SCOPE_SUB, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } Modified: plugins/ldap-sync/src/ldap_plugin.c ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.c Sat Apr 4 02:36:45 2009 (r5529) +++ plugins/ldap-sync/src/ldap_plugin.c Sat Apr 4 02:36:54 2009 (r5530) @@ -3283,7 +3283,7 @@ // we should call ldap_add_ext_s(), instead. // So we must check for the existence of this LDAP entry in order to // decide which libldap call to make. - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "", LDAP_SCOPE_BASE, USER_ATTRIBUTES, sinkenv, &res2, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "", LDAP_SCOPE_BASE, USER_ATTRIBUTES, sinkenv, FALSE, &res2, error)) { int result_code = 0; @@ -3531,7 +3531,7 @@ #endif LDAPMessage *dn_list = NULL; - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, *dn_of_modified_entry, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, &dn_list, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, *dn_of_modified_entry, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, FALSE, &dn_list, error)) { int result_code2 = 0; ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code2); Modified: plugins/ldap-sync/src/ldap_plugin.h ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.h Sat Apr 4 02:36:45 2009 (r5529) +++ plugins/ldap-sync/src/ldap_plugin.h Sat Apr 4 02:36:54 2009 (r5530) @@ -396,7 +396,7 @@ GList *ldap_plugin_append_ldapmod(GList *list, gchar *ldapattr, gchar *value); osync_bool ldap_plugin_assure_attribute(ldap_entry *entry, const char *attribute, const char *value, OSyncError **error); char *ldap_plugin_build_actual_hash(OSyncContext *ctx, sink_environment *sinkenv, const char *base, const char *filter, LDAPMessage *all_entries, OSyncError **error); -osync_bool ldap_plugin_call_ldap_search(OSyncContext *ctx, const LDAP *ldap_handle, const char *searchbase, const char *filter, const int scope, const int kind_of_attributes, const sink_environment *sinkenv, LDAPMessage **results, OSyncError **error); +osync_bool ldap_plugin_call_ldap_search(OSyncContext *ctx, const LDAP *ldap_handle, const char *searchbase, const char *filter, const int scope, const int kind_of_attributes, const sink_environment *sinkenv, osync_bool ignore_no_such_object, LDAPMessage **results, OSyncError **error); osync_bool ldap_plugin_check_contact_format_support(OSyncContext *ctx, sink_environment *sinkenv, OSyncError **error); osync_bool ldap_plugin_check_for_keyattribute(sink_environment *sinkenv, ldap_entry *entry, osync_bool check_key_attribute, OSyncError **error); osync_bool ldap_plugin_check_ldap_schema_support(OSyncContext *ctx, sink_environment *sinkenv, const char *ldap_schema, osync_bool *result, OSyncError **error); Modified: plugins/ldap-sync/src/ldap_sasl.c ============================================================================== --- plugins/ldap-sync/src/ldap_sasl.c Sat Apr 4 02:36:45 2009 (r5529) +++ plugins/ldap-sync/src/ldap_sasl.c Sat Apr 4 02:36:54 2009 (r5530) @@ -355,7 +355,7 @@ - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "", "(supportedSASLMechanisms)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, &res, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "", "(supportedSASLMechanisms)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, FALSE, &res, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } |