mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-07 10:28:32 +00:00
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. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@109779 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
; Sample Asterisk config file for res_config_ldap
|
; 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
|
; sipusers = ldap,"dc=myDomain,dc=myDomainExt",sip
|
||||||
; sippeers = ldap,"dc=myDomain,dc=myDomainExt",sip
|
; sippeers = ldap,"dc=myDomain,dc=myDomainExt",sip
|
||||||
; extensions = ldap,"dc=myDomain,dc=myDomainExt",extensions
|
; extensions = ldap,"dc=myDomain,dc=myDomainExt",extensions
|
||||||
@@ -11,20 +11,29 @@
|
|||||||
|
|
||||||
|
|
||||||
[_general]
|
[_general]
|
||||||
;host=192.168.1.1,ldap.mydomain.com ; LDAP host(s)
|
;
|
||||||
;protocol=3 ; Version of the LDAP protocol to use default is 3.
|
; 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
|
;basedn=MyRootDN ; Base DN
|
||||||
;pass=MyPassword ; Bind password
|
|
||||||
;user=MyDN ; Bind DN
|
;user=MyDN ; Bind DN
|
||||||
|
;pass=MyPassword ; Bind password
|
||||||
|
|
||||||
; Configuration Table
|
; Configuration Table
|
||||||
[config]
|
[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.
|
; when querying the LDAP server.
|
||||||
|
;
|
||||||
additionalFilter=(objectClass=PBXConfig)
|
additionalFilter=(objectClass=PBXConfig)
|
||||||
|
;
|
||||||
; Attributes mapping (asterisk variable name = ldap attribute name)
|
; Attributes mapping (asterisk variable name = ldap attribute name)
|
||||||
; When Asterisk requests the variable by the name of the value on the left,
|
; 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.
|
; this module will look up the attribute listed on the right.
|
||||||
|
;
|
||||||
filename = PBXConfigFilename
|
filename = PBXConfigFilename
|
||||||
category = PBXConfigCategory
|
category = PBXConfigCategory
|
||||||
variable_name = PBXConfigVariableName
|
variable_name = PBXConfigVariableName
|
||||||
@@ -32,7 +41,9 @@ variable_value = PBXConfigVariableValue
|
|||||||
cat_metric = PBXConfigCategoryMetric
|
cat_metric = PBXConfigCategoryMetric
|
||||||
commented = PBXConfigCommented
|
commented = PBXConfigCommented
|
||||||
|
|
||||||
|
;
|
||||||
; Extensions Table
|
; Extensions Table
|
||||||
|
;
|
||||||
[extensions]
|
[extensions]
|
||||||
context = PBXExtensionContext
|
context = PBXExtensionContext
|
||||||
exten = PBXExtensionExten
|
exten = PBXExtensionExten
|
||||||
@@ -41,7 +52,9 @@ app = PBXExtensionApplication
|
|||||||
appdata = PBXExtensionApplicationData
|
appdata = PBXExtensionApplicationData
|
||||||
additionalFilter=(objectClass=PBXExtension)
|
additionalFilter=(objectClass=PBXExtension)
|
||||||
|
|
||||||
|
;
|
||||||
; Sip Users Table
|
; Sip Users Table
|
||||||
|
;
|
||||||
[sip]
|
[sip]
|
||||||
name = uid
|
name = uid
|
||||||
amaflags = PBXAccountAMAFlags
|
amaflags = PBXAccountAMAFlags
|
||||||
@@ -77,7 +90,9 @@ regexten = PBXAccountRegistrationExten
|
|||||||
CanCallForward = PBXAccountCanCallForward
|
CanCallForward = PBXAccountCanCallForward
|
||||||
additionalFilter=(objectClass=PBXAccountSIP)
|
additionalFilter=(objectClass=PBXAccountSIP)
|
||||||
|
|
||||||
|
;
|
||||||
; IAX Users Table
|
; IAX Users Table
|
||||||
|
;
|
||||||
[iax]
|
[iax]
|
||||||
amaflags = PBXAccountAMAFlags
|
amaflags = PBXAccountAMAFlags
|
||||||
callerid = PBXAccountCallerID
|
callerid = PBXAccountCallerID
|
||||||
@@ -100,7 +115,9 @@ regexten = PBXAccountRegistrationExten
|
|||||||
notransfer = PBXAccountNoTransfer
|
notransfer = PBXAccountNoTransfer
|
||||||
additionalFilter=(objectClass=PBXAccountIAX)
|
additionalFilter=(objectClass=PBXAccountIAX)
|
||||||
|
|
||||||
|
;
|
||||||
; A Test Family
|
; A Test Family
|
||||||
|
;
|
||||||
[testfamily]
|
[testfamily]
|
||||||
MyUSERID = uid
|
MyUSERID = uid
|
||||||
additionalFilter=(objectClass=*)
|
additionalFilter=(objectClass=*)
|
||||||
|
|||||||
@@ -62,11 +62,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
AST_MUTEX_DEFINE_STATIC(ldap_lock);
|
AST_MUTEX_DEFINE_STATIC(ldap_lock);
|
||||||
|
|
||||||
static LDAP *ldapConn;
|
static LDAP *ldapConn;
|
||||||
static char host[512];
|
static char url[512];
|
||||||
static char user[512];
|
static char user[512];
|
||||||
static char pass[50];
|
static char pass[50];
|
||||||
static char basedn[512];
|
static char basedn[512];
|
||||||
static int port = 389;
|
|
||||||
static int version = 3;
|
static int version = 3;
|
||||||
static time_t connect_time;
|
static time_t connect_time;
|
||||||
|
|
||||||
@@ -1383,7 +1382,8 @@ int parse_config(void)
|
|||||||
{
|
{
|
||||||
struct ast_config *config;
|
struct ast_config *config;
|
||||||
struct ast_flags config_flags = {0};
|
struct ast_flags config_flags = {0};
|
||||||
const char *s;
|
const char *s, *host;
|
||||||
|
int port;
|
||||||
char *category_name = NULL;
|
char *category_name = NULL;
|
||||||
|
|
||||||
config = ast_config_load(RES_CONFIG_LDAP_CONF, config_flags);
|
config = ast_config_load(RES_CONFIG_LDAP_CONF, config_flags);
|
||||||
@@ -1405,12 +1405,20 @@ int parse_config(void)
|
|||||||
} else
|
} else
|
||||||
ast_copy_string(pass, s, sizeof(pass));
|
ast_copy_string(pass, s, sizeof(pass));
|
||||||
|
|
||||||
if (!(s = ast_variable_retrieve(config, "_general", "host"))) {
|
/* URL is preferred, use host and port if not found */
|
||||||
ast_log(LOG_ERROR, "No directory host found.\n");
|
if ((s = ast_variable_retrieve(config, "_general", "url"))) {
|
||||||
host[0] = '\0';
|
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 {
|
} else {
|
||||||
ast_copy_string(host, "ldap://", 8 );
|
ast_log(LOG_ERROR, "No directory URL or host found.\n");
|
||||||
ast_copy_string(host + 7, s, sizeof(host) - 7);
|
ast_config_destroy(config);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) {
|
if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) {
|
||||||
@@ -1419,11 +1427,6 @@ int parse_config(void)
|
|||||||
} else
|
} else
|
||||||
ast_copy_string(basedn, s, sizeof(basedn));
|
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"))) {
|
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");
|
ast_log(LOG_NOTICE, "No explicit LDAP version found, using 3 as default.\n");
|
||||||
version = 3;
|
version = 3;
|
||||||
@@ -1475,13 +1478,13 @@ static int ldap_reconnect(void)
|
|||||||
return 1;
|
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");
|
ast_log(LOG_ERROR, "Not enough parameters to connect to ldap database\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ldapConn = ldap_open(host, port))) {
|
if (LDAP_SUCCESS != ldap_initialize(&ldapConn, url)) {
|
||||||
ast_log(LOG_ERROR, "Failed to init ldap connection to %s, port %d. Check debug for more info.\n", host, port);
|
ast_log(LOG_ERROR, "Failed to init ldap connection to '%s'. Check debug for more info.\n", url);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1490,12 +1493,12 @@ static int ldap_reconnect(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ast_strlen_zero(user)) {
|
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_val = (char *) pass;
|
||||||
cred.bv_len = strlen(pass);
|
cred.bv_len = strlen(pass);
|
||||||
bind_result = ldap_sasl_bind_s(ldapConn, user, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
|
bind_result = ldap_sasl_bind_s(ldapConn, user, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
|
||||||
} else {
|
} 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);
|
bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
if (bind_result == LDAP_SUCCESS) {
|
if (bind_result == LDAP_SUCCESS) {
|
||||||
@@ -1529,8 +1532,8 @@ static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_c
|
|||||||
if (!ldapConn)
|
if (!ldapConn)
|
||||||
return CLI_FAILURE;
|
return CLI_FAILURE;
|
||||||
|
|
||||||
if (!ast_strlen_zero(host))
|
if (!ast_strlen_zero(url))
|
||||||
snprintf(status, sizeof(status), "Connected to %s, port %d baseDN %s", host, port, basedn);
|
snprintf(status, sizeof(status), "Connected to '%s', baseDN %s", url, basedn);
|
||||||
|
|
||||||
if (!ast_strlen_zero(user))
|
if (!ast_strlen_zero(user))
|
||||||
snprintf(status2, sizeof(status2), " with username %s", user);
|
snprintf(status2, sizeof(status2), " with username %s", user);
|
||||||
|
|||||||
Reference in New Issue
Block a user