Index: res/res_config_ldap.c =================================================================== --- res/res_config_ldap.c (revision 108133) +++ res/res_config_ldap.c (working copy) @@ -1409,7 +1409,7 @@ host[0] = '\0'; } else { ast_copy_string(host, "ldap://", 8 ); - ast_copy_string(host + 7, s, sizeof(host)); + ast_copy_string(host + 7, s, sizeof(host) - 7); } if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) { @@ -1418,14 +1418,9 @@ } else ast_copy_string(basedn, s, sizeof(basedn)); - if (!(s = ast_variable_retrieve(config, "_general", "port"))) { + if (!(s = ast_variable_retrieve(config, "_general", "port")) || sscanf(s, "%d", &port) != 1) { ast_log(LOG_WARNING, "No directory port found, using 389 as default.\n"); port = 389; - ast_copy_string(host + strlen(host), ":389", sizeof(host)); - } else { - ast_copy_string(host + 1, ":", sizeof(s)); - ast_copy_string(host + strlen(host), s, sizeof(s)); - port = atoi(s); } table_configs_free(); @@ -1476,13 +1471,13 @@ return 0; } - if (LDAP_SUCCESS != ldap_initialize(&ldapConn, host)) { - ast_log(LOG_ERROR, "Failed to init ldap connection to %s. Check debug for more info.\n", host); + if (!(ldapConn = ldap_open(host, port))) { + ast_log(LOG_ERROR, "Failed to init ldap connection to %s, port %d. Check debug for more info.\n", host, port); return 0; } if (!ast_strlen_zero(user)) { - ast_debug(2, "bind to %s as %s\n", host, user); + ast_debug(2, "bind to %s:%d as %s\n", host, port, user); cred.bv_val = (char *) pass; cred.bv_len = strlen(pass); bind_result = ldap_sasl_bind_s(ldapConn, user, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);