[svn-commits] tilghman: branch 1.6.0 r109779 - in /branches/1.6.0: ./ configs/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 18 18:23:38 CDT 2008


Author: tilghman
Date: Tue Mar 18 18:23:37 2008
New Revision: 109779

URL: http://svn.digium.com/view/asterisk?view=rev&rev=109779
Log:
Merged revisions 109775 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r109775 | tilghman | 2008-03-18 18:22:25 -0500 (Tue, 18 Mar 2008) | 3 lines

Change back to using ldap_initialize() and let the user specify a URL directly,
instead of trying to piece it together, badly.

........

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/configs/res_ldap.conf.sample
    branches/1.6.0/res/res_config_ldap.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/configs/res_ldap.conf.sample
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/configs/res_ldap.conf.sample?view=diff&rev=109779&r1=109778&r2=109779
==============================================================================
--- branches/1.6.0/configs/res_ldap.conf.sample (original)
+++ branches/1.6.0/configs/res_ldap.conf.sample Tue Mar 18 18:23:37 2008
@@ -3,7 +3,7 @@
 ;
 
 ; Sample Asterisk config file for res_config_ldap
-; in extconfig.conf you can use it like this:
+; in extconfig.conf; you can use it like this:
 ; sipusers = ldap,"dc=myDomain,dc=myDomainExt",sip
 ; sippeers = ldap,"dc=myDomain,dc=myDomainExt",sip
 ; extensions = ldap,"dc=myDomain,dc=myDomainExt",extensions
@@ -11,20 +11,29 @@
 
 
 [_general]
-;host=192.168.1.1,ldap.mydomain.com	; LDAP host(s)
-;protocol=3		; Version of the LDAP protocol to use default is 3.
-;basedn=MyRootDN	; Base DN
-;pass=MyPassword	; Bind password
-;user=MyDN		; Bind DN
+;
+; Specify one of either host and port OR url.  URL is preferred, as you can
+; use more options.
+;host=192.168.1.1                    ; LDAP host
+;port=389
+;url=ldap://ldap3.mydomain.com:3890
+;protocol=3                          ; Version of the LDAP protocol to use; default is 3.
+;basedn=MyRootDN                     ; Base DN
+;user=MyDN                           ; Bind DN
+;pass=MyPassword                     ; Bind password
 
 ; Configuration Table
 [config]
-; addtional filter - This specifies an additional set of criteria to be used
+;
+; additionalFilter - This specifies an additional set of criteria to be used
 ; when querying the LDAP server.
+;
 additionalFilter=(objectClass=PBXConfig)
+;
 ; Attributes mapping (asterisk variable name = ldap attribute name)
 ; When Asterisk requests the variable by the name of the value on the left,
 ; this module will look up the attribute listed on the right.
+;
 filename = PBXConfigFilename
 category = PBXConfigCategory
 variable_name = PBXConfigVariableName
@@ -32,7 +41,9 @@
 cat_metric = PBXConfigCategoryMetric
 commented = PBXConfigCommented
 
+;
 ; Extensions Table
+;
 [extensions]
 context  =  PBXExtensionContext
 exten  =  PBXExtensionExten
@@ -41,7 +52,9 @@
 appdata = PBXExtensionApplicationData
 additionalFilter=(objectClass=PBXExtension)
 
+;
 ; Sip Users Table
+;
 [sip]
 name = uid
 amaflags = PBXAccountAMAFlags
@@ -77,7 +90,9 @@
 CanCallForward = PBXAccountCanCallForward
 additionalFilter=(objectClass=PBXAccountSIP)
 
+;
 ; IAX Users Table
+;
 [iax]
 amaflags = PBXAccountAMAFlags
 callerid = PBXAccountCallerID
@@ -100,7 +115,9 @@
 notransfer = PBXAccountNoTransfer
 additionalFilter=(objectClass=PBXAccountIAX)
 
+;
 ; A Test Family
+;
 [testfamily]
 MyUSERID = uid
 additionalFilter=(objectClass=*)

Modified: branches/1.6.0/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/res/res_config_ldap.c?view=diff&rev=109779&r1=109778&r2=109779
==============================================================================
--- branches/1.6.0/res/res_config_ldap.c (original)
+++ branches/1.6.0/res/res_config_ldap.c Tue Mar 18 18:23:37 2008
@@ -62,11 +62,10 @@
 AST_MUTEX_DEFINE_STATIC(ldap_lock);
 
 static LDAP *ldapConn;
-static char host[512];
+static char url[512];
 static char user[512];
 static char pass[50];
 static char basedn[512];
-static int port = 389;
 static int version = 3;
 static time_t connect_time;
 
@@ -1383,7 +1382,8 @@
 {
 	struct ast_config *config;
 	struct ast_flags config_flags = {0};
-	const char *s;
+	const char *s, *host;
+	int port;
 	char *category_name = NULL;
 
 	config = ast_config_load(RES_CONFIG_LDAP_CONF, config_flags);
@@ -1405,12 +1405,20 @@
 	} else
 		ast_copy_string(pass, s, sizeof(pass));
 
-	if (!(s = ast_variable_retrieve(config, "_general", "host"))) {
-		ast_log(LOG_ERROR, "No directory host found.\n");
-		host[0] = '\0';
+	/* URL is preferred, use host and port if not found */
+	if ((s = ast_variable_retrieve(config, "_general", "url"))) {
+		ast_copy_string(url, s, sizeof(url));
+	} else if ((host = ast_variable_retrieve(config, "_general", "host"))) {
+		if (!(s = ast_variable_retrieve(config, "_general", "port")) || sscanf(s, "%d", &port) != 1) {
+			ast_log(LOG_NOTICE, "No directory port found, using 389 as default.\n");
+			port = 389;
+		}
+
+		snprintf(url, sizeof(url), "ldap://%s:%d", host, port);
 	} else {
-		ast_copy_string(host, "ldap://", 8 );
-		ast_copy_string(host + 7, s, sizeof(host) - 7);
+		ast_log(LOG_ERROR, "No directory URL or host found.\n");
+		ast_config_destroy(config);
+		return -1;
 	}
 
 	if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) {
@@ -1418,11 +1426,6 @@
 		basedn[0] = '\0';
 	} else 
 		ast_copy_string(basedn, s, sizeof(basedn));
-
-	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;
-	}
 
 	if (!(s = ast_variable_retrieve(config, "_general", "version")) || !(s = ast_variable_retrieve(config, "_general", "protocol"))) {
 		ast_log(LOG_NOTICE, "No explicit LDAP version found, using 3 as default.\n");
@@ -1475,13 +1478,13 @@
 		return 1;
 	}
 
-	if (ast_strlen_zero(host)) {
+	if (ast_strlen_zero(url)) {
 		ast_log(LOG_ERROR, "Not enough parameters to connect to ldap database\n");
 		return 0;
 	}
 
-	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);
+	if (LDAP_SUCCESS != ldap_initialize(&ldapConn, url)) {
+		ast_log(LOG_ERROR, "Failed to init ldap connection to '%s'. Check debug for more info.\n", url);
 		return 0;
 	}
 
@@ -1490,12 +1493,12 @@
 	}
 
 	if (!ast_strlen_zero(user)) {
-		ast_debug(2, "bind to %s:%d as %s\n", host, port, user);
+		ast_debug(2, "bind to '%s' as user '%s'\n", url, 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);
 	} else {
-		ast_debug(2, "bind anonymously %s anonymously\n", host);
+		ast_debug(2, "bind %s anonymously\n", url);
 		bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
 	}
 	if (bind_result == LDAP_SUCCESS) {
@@ -1529,8 +1532,8 @@
 	if (!ldapConn)
 		return CLI_FAILURE;
 
-	if (!ast_strlen_zero(host)) 
-		snprintf(status, sizeof(status), "Connected to %s, port %d baseDN %s", host, port, basedn);
+	if (!ast_strlen_zero(url)) 
+		snprintf(status, sizeof(status), "Connected to '%s', baseDN %s", url, basedn);
 
 	if (!ast_strlen_zero(user))
 		snprintf(status2, sizeof(status2), " with username %s", user);




More information about the svn-commits mailing list