[asterisk-dev] PATCHES: Fixes and updates for Asterisk 1.6beta5 LDAP support

Tuomas Jormola tj at solitudo.net
Mon Mar 17 10:01:57 CDT 2008


Hello,

I played a little bit with Asterisk using LDAP as backend for SIP users.
To get everything working, I needed to hack the Asterisk source code
a bit. Here are the results as 4 separate patches. More detailed
explanation of each patch follows. Feel free to use them as is or as
basis for further development.

fix-ldap-bugs.diff
==================
This patch fixes two simple bugs in res_config_ldap.c. In function
realtime_ldap_base_ap(), due to missing brackets in an if block, the
execution will always stop to the return NULL statement. In fucntcion
update_ldap(), error checking after call to ldap_modify_ext_s() is not
good. It's better to compare the returned value to LDAP_SUCCESS
constant. Also the formatting of the error message is missing "\n".

use-ldap-url.diff
=================
This patch alters res_config_ldap.c so that full LDAP URL is used
internally to represent the LDAP server to use instead of using hostname
and port variables. It's also possible to specify the full URL in
res_ldap.conf using the new url keyword instead of just specifying host
and port (but this works too, of course, so existing configurations
should not break due to this change). Rationale behind this is that
using a URL you can specify extra settings for the connections that
are not available otherwise (e.g. you can use ldapi:// urls when
connecting to a local OpenLDAP server, or you can specify the scope of
the queries, see ldap_url(3) manual page for more info). Also currently
the port setting code is broken. It generates invalid LDAP URLs if both
host and port of the LDAP server is specified in the configuration file.
The patch also fixes setting of the protocol. You can specify this in
the configuration file, but the setting was never applied to the LDAP
connection. Thus all connections were using LDAPv2 by default (at least
when Asterisk is compiled against OpenLDAP 2.4).

update-asterisk-ldap-schema.diff
================================
I notcied that in order to get the LDAP/SIP support working, you need to
add attributes ipaddr, defaultuser and regserver to the [sip] section of
res_ldap.conf. These did not have corresponding LDAP attributes in the
included asterisk.ldap-schema, so I created them.

update-ldap-default-config.diff
===============================
This patch adds afformentioned SIP attributes to the sample
res_ldap.conf. It also renames PBXAccount* LDAP attributes to the
current AstAccount* form. Also realmedPassword is renamed to
AstAccountRealmedPassword.

I also experience a segfault with each call to ber_bvecfree() in
res_config_ldap.c. I'm not sure how to handle that correctly. For my
testing, I just commented out these calls, but that's hardly a long-term
solution due to memory leaking. I've attached a gdb backtrace of such
a segfault.

Regards,

-- 
Tuomas Jormola <tj at solitudo.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-ldap-bugs.diff
Type: text/x-diff
Size: 995 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20080317/43497cd9/attachment-0004.diff 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: use-ldap-url.diff
Type: text/x-diff
Size: 4564 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20080317/43497cd9/attachment-0005.diff 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: update-asterisk-ldap-schema.diff
Type: text/x-diff
Size: 2352 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20080317/43497cd9/attachment-0006.diff 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: update-ldap-default-config.diff
Type: text/x-diff
Size: 5900 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20080317/43497cd9/attachment-0007.diff 
-------------- next part --------------
#0  0xb7d563ca in free () from /lib/tls/i686/cmov/libc.so.6
#1  0xb782d34a in ber_memfree_x () from /opt/local/lib/liblber-2.4.so.2
#2  0xb782d9b7 in ber_bvfree_x () from /opt/local/lib/liblber-2.4.so.2
#3  0xb782da37 in ber_bvecfree_x () from /opt/local/lib/liblber-2.4.so.2
#4  0xb782da85 in ber_bvecfree () from /opt/local/lib/liblber-2.4.so.2
#5  0xb5cb881d in realtime_ldap_result_to_vars (table_config=0x82100a8, ldap_result=0x8224fa0,
    entries_count_ptr=0x0) at res_config_ldap.c:329
#6  0xb5cb9db7 in realtime_ldap_base_ap (entries_count_ptr=0x0, basedn=<value optimized out>,
    table_name=<value optimized out>, ap=0xb60c52b4 " ?\030?~T\f?q?\030?\021?\030?") at res_config_ldap.c:812
#7  0xb5cba7c7 in realtime_ldap (basedn=0xb60c5198 "dc=sipusers,dc=asterisk,dc=test,dc=net",
    table_name=0xb60c5098 "sip", ap=0xb60c52b4 " ?\030?~T\f?q?\030?\021?\030?") at res_config_ldap.c:901
#8  0x0809a371 in ast_load_realtime (family=0xb618a518 "sippeers") at config.c:2023
#9  0xb614e9a6 in find_peer (peer=0xb60c547e "test", sin=0x0, realtime=1) at chan_sip.c:3538
#10 0xb6183a2d in handle_request_register (p=0x8222ef0, req=0xb60c7020, sin=0xb60c8258,
    e=<value optimized out>) at chan_sip.c:10234
#11 0xb6187414 in handle_incoming (p=0x8222ef0, req=0xb60c7020, sin=0xb60c8258, recount=0xb60c6ed4,
    nounlock=0xb60c6ed0) at chan_sip.c:17870
#12 0xb618930a in handle_request_do (req=0xb60c7020, sin=0xb60c8258) at chan_sip.c:18019
#13 0xb61897f7 in sipsock_read (id=0x81c4678, fd=13, events=1, ignore=0x0) at chan_sip.c:17947
#14 0x080cd960 in ast_io_wait (ioc=0x81f2140, howlong=1000) at io.c:287
#15 0xb615d41c in do_monitor (data=0x0) at chan_sip.c:18336
#16 0x08132deb in dummy_start (data=0x81f37a8) at utils.c:857
#17 0xb7ccc4fb in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#18 0xb7dbd8ee in clone () from /lib/tls/i686/cmov/libc.so.6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20080317/43497cd9/attachment-0001.pgp 


More information about the asterisk-dev mailing list