Use the default that the log output claims will be used for the basedn
[asterisk/asterisk.git] / res / res_config_ldap.c
index 79a326b..52855fd 100644 (file)
@@ -58,6 +58,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/linkedlists.h"
 
 #define RES_CONFIG_LDAP_CONF "res_ldap.conf"
+#define RES_CONFIG_LDAP_DEFAULT_BASEDN "asterisk"
 
 AST_MUTEX_DEFINE_STATIC(ldap_lock);
 
@@ -326,7 +327,7 @@ static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config
                                }
                                v++;
                        }
-                       ber_bvecfree(values);
+                       ldap_value_free_len(values);
                }
                ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
        }
@@ -492,7 +493,7 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
                                                }
                                                v++;
                                        } /*!< while(*v) */
-                                       ber_bvecfree(values);
+                                       ldap_value_free_len(values);
                                }/*!< if (values) */
                                ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
                        } /*!< while (ldap_attribute_name) */
@@ -552,7 +553,7 @@ static struct ast_variable *ldap_loadentry(struct ldap_table_config *table_confi
                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 != LDAP_SUCCESS && is_ldap_connect_error(result)) {
                                ast_log(LOG_WARNING,
                                        "Failed to query database. Try %d/3\n",
                                        tries + 1);
@@ -567,9 +568,9 @@ static struct ast_variable *ldap_loadentry(struct ldap_table_config *table_confi
                                                break;
                                }
                        }
-               } while (result < 0 && tries < 3 && is_ldap_connect_error(result));
+               } while (result != LDAP_SUCCESS && tries < 3 && is_ldap_connect_error(result));
 
-               if (result < 0) {
+               if (result != LDAP_SUCCESS) {
                        ast_log(LOG_WARNING,
                                        "Failed to query database. Check debug for more info.\n");
                        ast_debug(2, "dn=%s\n", dn);
@@ -787,7 +788,7 @@ static struct ast_variable **realtime_ldap_base_ap(unsigned int *entries_count_p
                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 != LDAP_SUCCESS && is_ldap_connect_error(result)) {
                        ast_log(LOG_DEBUG, "Failed to query database. Try %d/10\n",
                                tries + 1);
                        if (++tries < 10) {
@@ -800,9 +801,9 @@ static struct ast_variable **realtime_ldap_base_ap(unsigned int *entries_count_p
                                        break;
                        }
                }
-       } while (result < 0 && tries < 10 && is_ldap_connect_error(result));
+       } while (result != LDAP_SUCCESS && tries < 10 && is_ldap_connect_error(result));
 
-       if (result < 0) {
+       if (result != LDAP_SUCCESS) {
                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));
@@ -1244,7 +1245,7 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
                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 != LDAP_SUCCESS && is_ldap_connect_error(result)) {
                        ast_log(LOG_WARNING, "Failed to query database. Try %d/3\n",
                                tries + 1);
                        tries++;
@@ -1258,9 +1259,9 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
                                        break;
                        }
                }
-       } while (result < 0 && tries < 3 && is_ldap_connect_error(result));
+       } while (result != LDAP_SUCCESS && tries < 3 && is_ldap_connect_error(result));
 
-       if (result < 0) {
+       if (result != LDAP_SUCCESS) {
                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",
@@ -1285,7 +1286,7 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
 
                for (i = 0; ldap_entry; i++) { 
                        dn = ldap_get_dn(ldapConn, ldap_entry);
-                       if (!(error = ldap_modify_ext_s(ldapConn, dn, ldap_mods, NULL, NULL))) 
+                       if ((error = ldap_modify_ext_s(ldapConn, dn, ldap_mods, NULL, NULL)) != LDAP_SUCCESS) 
                                ast_log(LOG_ERROR, "Couldn't modify dn:%s because %s", dn, ldap_err2string(error));
 
                        ldap_entry = ldap_next_entry(ldapConn, ldap_entry);
@@ -1364,6 +1365,7 @@ static int reload(void)
 
        if (parse_config() < 0) {
                ast_log(LOG_NOTICE, "Cannot reload LDAP RealTime driver.\n");
+               ast_mutex_unlock(&ldap_lock);
                return 0;
        }               
 
@@ -1422,8 +1424,8 @@ int parse_config(void)
        }
 
        if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) {
-               ast_log(LOG_ERROR, "No LDAP base dn found, using 'asterisk' as default.\n");
-               basedn[0] = '\0';
+               ast_log(LOG_ERROR, "No LDAP base dn found, using '%s' as default.\n", RES_CONFIG_LDAP_DEFAULT_BASEDN);
+               ast_copy_string(basedn, RES_CONFIG_LDAP_DEFAULT_BASEDN, sizeof(basedn));
        } else 
                ast_copy_string(basedn, s, sizeof(basedn));