--- res_config_ldap/res/res_config_ldap.c 2007-11-28 21:47:44.000000000 +0100 +++ res_config_ldap.new/res/res_config_ldap.c 2007-11-28 21:48:50.000000000 +0100 @@ -32,6 +32,7 @@ */ /*** MODULEINFO + ldap ***/ #include "asterisk.h" @@ -562,7 +563,7 @@ do { result = ldap_search_ext_s(ldapConn, dn, LDAP_SCOPE_BASE, "(objectclass=*)", NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &ldap_result); - if (result < 0 && is_ldap_connect_error(result)) { + if (result != 0 && is_ldap_connect_error(result)) { ast_log(LOG_WARNING, "Failed to query database. Try %d/3\n", tries + 1); @@ -577,9 +578,9 @@ break; } } - } while (result < 0 && tries < 3 && is_ldap_connect_error(result)); + } while (result != 0 && tries < 3 && is_ldap_connect_error(result)); - if (result < 0) { + if (result != 0) { ast_log(LOG_WARNING, "Failed to query database. Check debug for more info.\n"); ast_debug(2, "dn=%s\n", dn); @@ -698,7 +699,7 @@ ast_debug(2, "name='%s' value='%s'\n", name, value); if (like_pos) { - name = new_name = ast_strdupa(like_pos + strlen(" LIKE")); + name = new_name = ast_strndup(name, strlen(name) - strlen(" LIKE")); value = new_value = ast_strdupa(value); replace_string_in_string(new_value, "\\_", "_"); replace_string_in_string(new_value, "%", "*"); @@ -741,13 +742,13 @@ /* Get the first parameter and first value in our list of passed paramater/value pairs */ newparam = va_arg(ap, const char *); newval = va_arg(ap, const char *); - if (!newparam || !newval) { ast_log(LOG_WARNING, "Realtime retrieval requires at least 1 parameter" " and 1 value to search on.\n"); return NULL; } + ast_mutex_lock(&ldap_lock); /* We now have our complete statement; Lets connect to the server and execute it. */ @@ -787,7 +788,7 @@ result = ldap_search_ext_s(ldapConn, clean_basedn, LDAP_SCOPE_SUBTREE, filter->str, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &ldap_result); - if (result < 0 && is_ldap_connect_error(result)) { + if (result != 0 && is_ldap_connect_error(result)) { ast_log(LOG_WARNING, "Failed to query database. Try %d/3\n", tries + 1); tries++; @@ -801,9 +802,9 @@ break; } } - } while (result < 0 && tries < 3 && is_ldap_connect_error(result)); + } while (result != 0 && tries < 3 && is_ldap_connect_error(result)); - if (result < 0) { + if (result != 0) { ast_log(LOG_WARNING, "Failed to query database. Check debug for more info.\n"); ast_log(LOG_WARNING, "Query: %s\n", filter->str); ast_log(LOG_WARNING, "Query Failed because: %s\n", ldap_err2string(result)); @@ -1242,7 +1243,7 @@ result = ldap_search_ext_s(ldapConn, clean_basedn, LDAP_SCOPE_SUBTREE, filter->str, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &ldap_result); - if (result < 0 && is_ldap_connect_error(result)) { + if (result != 0 && is_ldap_connect_error(result)) { ast_log(LOG_WARNING, "Failed to query database. Try %d/3\n", tries + 1); tries++; @@ -1256,9 +1257,9 @@ break; } } - } while (result < 0 && tries < 3 && is_ldap_connect_error(result)); + } while (result != 0 && tries < 3 && is_ldap_connect_error(result)); - if (result < 0) { + if (result != 0) { ast_log(LOG_WARNING, "Failed to query directory. Check debug for more info.\n"); ast_log(LOG_WARNING, "Query: %s\n", filter->str); ast_log(LOG_WARNING, "Query Failed because: %s\n",