Index: res_config_ldap.c
===================================================================
--- res_config_ldap.c (revision 50465)
+++ res_config_ldap.c (working copy)
@@ -29,7 +29,6 @@
*/
/*** MODULEINFO
- ldap
***/
#include "asterisk.h"
@@ -40,6 +39,7 @@
#include
#include
+
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
@@ -69,7 +69,7 @@
static int ldap_reconnect(void);
static int realtime_ldap_status(int fd, int argc, char **argv);
-LOCAL_USER_DECL;
+int LOCAL_USER_DECL;
struct category_and_metric {
char *name;
@@ -377,46 +377,49 @@
int i=0;
char *ldap_attribute_name = ldap_first_attribute(ldapConn, ldap_entry, &ber);
- char *value;
+// char *value;
+ struct berval *value;
int pos=0;
while (ldap_attribute_name) {
const char *attribute_name =
convert_attribute_name_from_ldap(table_config,ldap_attribute_name);
int is_realmed_password_attribute = strcasecmp(attribute_name, "md5secret") == 0;
- char **values = NULL;
+// char **values = NULL;
+ struct berval **values = NULL;
- values = ldap_get_values(ldapConn, ldap_entry, ldap_attribute_name);/*these are freed at the end*/
+ values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name);/*these are freed at the end*/
if (values) {
- char **v = values;
+// char **v = values;
+ struct berval **v = values;
while (*v) {
value = *v;
if (option_debug > 1)
- ast_log(LOG_DEBUG, "LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, value);
+ ast_log(LOG_DEBUG, "LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, value->bv_val);
if (is_realmed_password_attribute) {
- if (strncasecmp(value, "{md5}", 5) == 0)
- value += 5;
+ if (strncasecmp(value->bv_val, "{md5}", 5) == 0)
+ value->bv_val += 5;
else
- value = NULL;
+ value->bv_val = NULL;
if (option_debug > 1)
- ast_log(LOG_DEBUG, "md5: %s\n", value);
+ ast_log(LOG_DEBUG, "md5: %s\n", value->bv_val);
}
- if (value) {
+ if (value->bv_val) {
/* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */
if( is_delimited != 0){
i=0;
pos=0;
- while ( !ast_strlen_zero(value + i) ){
- if (value[i] == ';'){
- value[i] = '\0';
+ while ( !ast_strlen_zero(value->bv_val + i) ){
+ if (value->bv_val[i] == ';'){
+ value->bv_val[i] = '\0';
if (prev) {
- prev->next = ast_variable_new(attribute_name, &value[pos]);
+ prev->next = ast_variable_new(attribute_name, &value->bv_val[pos]);
if (prev->next) {
prev = prev->next;
}
} else {
- prev = var = ast_variable_new(attribute_name, &value[pos]);
+ prev = var = ast_variable_new(attribute_name, &value->bv_val[pos]);
}
pos = i + 1;
}
@@ -425,17 +428,18 @@
}
/* for the last delimited value or if the value is not delimited: */
if (prev) {
- prev->next = ast_variable_new(attribute_name, &value[pos]);
+ prev->next = ast_variable_new(attribute_name, &value->bv_val[pos]);
if (prev->next) {
prev = prev->next;
}
} else {
- prev = var = ast_variable_new(attribute_name, &value[pos]);
+ prev = var = ast_variable_new(attribute_name, &value->bv_val[pos]);
}
}
v++;
}
- ldap_value_free(values);
+// ldap_value_free(values);
+ ber_bvecfree(values);
}
ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
}
@@ -500,36 +504,39 @@
/*Starting new static var*/
char *ldap_attribute_name = ldap_first_attribute(ldapConn, ldap_entry, &ber);
- char *value;
+ //char *value;
+ struct berval *value;
while (ldap_attribute_name) {
const char *attribute_name =
convert_attribute_name_from_ldap(table_config,ldap_attribute_name);
int is_realmed_password_attribute = strcasecmp(attribute_name, "md5secret") == 0;
- char **values = NULL;
+ // char **values = NULL;
+ struct berval **values = NULL;
- values = ldap_get_values(ldapConn, ldap_entry, ldap_attribute_name);
+ values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name);
if (values) {
- char **v = values;
+ //char **v = values;
+ struct berval **v = values;
while (*v) {
value = *v;
if (is_realmed_password_attribute) {
- if (strncasecmp(value, "{md5}", 5) == 0)
- value += 5;
+ if (strncasecmp(value->bv_val, "{md5}", 5) == 0)
+ value->bv_val += 5;
else
- value = NULL;
+ value->bv_val = NULL;
if (option_debug > 1)
- ast_log(LOG_DEBUG, "md5: %s\n", value);
+ ast_log(LOG_DEBUG, "md5: %s\n", value->bv_val);
}
- if (value) {
+ if (value->bv_val) {
if( delim_value == NULL
&& !is_realmed_password_attribute
&& (static_table_config != table_config || strcmp(attribute_name,"variable_value") == 0) ){
- delim_value = ast_calloc(1,sizeof(char)*(strlen(value)+1));
- ast_copy_string(delim_value,value,strlen(value)+1);
+ delim_value = ast_calloc(1,sizeof(char)*(strlen(value->bv_val)+1));
+ ast_copy_string(delim_value,value->bv_val,strlen(value->bv_val)+1);
if( (delim_tot_count = semicolon_count_str(delim_value)) > 0){
if (option_debug > 3)
@@ -545,7 +552,7 @@
i=pos;
- while ( !ast_strlen_zero(value + i) ){
+ while ( !ast_strlen_zero(value->bv_val + i) ){
if (option_debug > 3)
ast_log(LOG_DEBUG, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
if (delim_value[i] == ';'){
@@ -570,7 +577,7 @@
}
i++;
}
- if(ast_strlen_zero(value + i)){
+ if(ast_strlen_zero(value->bv_val + i)){
if (option_debug > 3)
ast_log(LOG_DEBUG, "LINE(%d) DELIM pos: %d i: %d delim_count: %d\n", __LINE__, pos, i,delim_count);
/* Last delimited value */
@@ -600,21 +607,22 @@
delim_value = NULL;
}
if (option_debug > 1)
- ast_log(LOG_DEBUG, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, value);
+ ast_log(LOG_DEBUG, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, value->bv_val);
if (prev) {
- prev->next = ast_variable_new(attribute_name, value);
+ prev->next = ast_variable_new(attribute_name, value->bv_val);
if (prev->next) {
prev = prev->next;
}
} else {
- prev = var = ast_variable_new(attribute_name, value);
+ prev = var = ast_variable_new(attribute_name, value->bv_val);
}
}
}
v++;
}/*! 0) {
if (option_debug>2)
ast_log(LOG_DEBUG, "num_entry: %d\n", num_entry);
@@ -1332,7 +1340,7 @@
{
int error=0;
LDAPMessage *ldap_entry = NULL;
- struct ast_variable **vars = NULL;
+ //struct ast_variable **vars = NULL;
/*!< done defining counting vars */
LDAPMod ** ldap_mods;
const char *newparam = NULL;
@@ -1509,7 +1517,7 @@
for (i = 0; ldap_entry; i++){
dn = ldap_get_dn(ldapConn,ldap_entry);
- if (!(error = ldap_modify_s(ldapConn,dn,ldap_mods)))
+ if (!(error = ldap_modify_ext_s(ldapConn,dn,ldap_mods,NULL,NULL)))
ast_log(LOG_ERROR,"Couldn't modify dn:%s because %s",dn,ldap_err2string(error) );
ldap_entry = ldap_next_entry(ldapConn, ldap_entry);
@@ -1609,7 +1617,7 @@
int parse_config(void)
{
struct ast_config *config;
- char *s;
+ const char *s;
config = ast_config_load(RES_CONFIG_LDAP_CONF);
@@ -1633,8 +1641,10 @@
if (!(s = ast_variable_retrieve(config, "_general", "host"))) {
ast_log(LOG_ERROR, "No directory host found.\n");
host[0] = '\0';
- } else
- ast_copy_string(host, s, sizeof(host));
+ } else {
+ ast_copy_string(host, "ldap://", 8 );
+ ast_copy_string(host + 7, s, sizeof(host));
+ }
if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) {
ast_log(LOG_ERROR, "No LDAP base dn found, using 'asterisk' as default.\n");
@@ -1645,8 +1655,12 @@
if (!(s = ast_variable_retrieve(config, "_general", "port"))) {
ast_log(LOG_WARNING, "No directory port found, using 389 as default.\n");
port = 389;
- } else
+ 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();
@@ -1704,15 +1718,16 @@
return res_config_ldap_desc;
}
-static const char *key(void)
-{
- return ASTERISK_GPL_KEY;
-}
+//static const char *key(void)
+//{
+// return ASTERISK_GPL_KEY;
+//}
static int ldap_reconnect(void)
{
/* mutex lock should have been locked before calling this function. */
int bind_result = 0;
+ struct berval cred;
if (ldapConn) {
if (option_debug > 1)
@@ -1725,7 +1740,8 @@
return 0;
}
- if (!(ldapConn = ldap_init(host, port))) {
+ //if (!(ldapConn = ldap_init(host, port))) {
+ 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);
return 0;
}
@@ -1733,11 +1749,15 @@
if (user && *user) {
if (option_debug > 1)
ast_log(LOG_DEBUG, "bind to %s as %s\n", host, user);
- bind_result = ldap_simple_bind_s(ldapConn, user, pass);
+ //bind_result = ldap_simple_bind_s(ldapConn, user, pass);
+ 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);
} else {
if (option_debug > 1)
ast_log(LOG_DEBUG, "bind anonymously %s anonymously\n", host);
- bind_result = ldap_simple_bind_s(ldapConn, NULL, NULL);
+ bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
+ //bind_result = ldap_simple_bind_s(ldapConn, NULL, NULL);
}
if (bind_result == LDAP_SUCCESS) {
if (option_debug > 1)