views:

41

answers:

0

If I run the following PHP code on the command line I get the expected result:

php -r 'var_dump(ldap_connect("ldaps://ldaps.example.com", 636));'
resource(4) of type (ldap link)

However if I put this in a PHP script

<?php ldap_connect("ldaps://ldaps.example.com", 636); ?>

Apache drops the connection, for example this is what cURL returns if I hit the script from the command line:

curl http://example.com/ldap_test.php
curl: (52) Empty reply from server

The Apache access_log never shows the hit to this page, and the error_log is empty.

I know the LDAP server is working as I have tested this on two other servers. I am working on an Joyent accelerator running PHP 5.2.9 and Apache. Anyone know why Apache is choking on this?

Update:

Today I debugged Apache using GDB while running the problem script. When the script hits the ldap_connect() line I get the following in GDB:

Program received signal SIGSEGV, Segmentation fault.
0xfe94b8bb in _free_unlocked () from /lib/libc.so.1

I'm not sure what is causing the segfault yet, but at least I know that Apache is actually crashing.

Here is the full backtrace:

Breakpoint 1, 0x08094417 in ap_process_request ()
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0xfe94b8bb in _free_unlocked () from /lib/libc.so.1
(gdb) where
#0  0xfe94b8bb in _free_unlocked () from /lib/libc.so.1
#1  0xfe94b86f in free () from /lib/libc.so.1
#2  0xfde2d7e8 in ldap_x_free () from /usr/lib/libldap.so.5
#3  0xfde3f78b in ldap_free_urldesc () from /usr/lib/libldap.so.5
#4  0xfd0943d9 in ldap_free_urllist () from /opt/local/lib/libldap-2.4.so.2
#5  0xfd087191 in ldap_ld_free () from /opt/local/lib/libldap-2.4.so.2
#6  0xfd07ce8f in ldap_initialize () from /opt/local/lib/libldap-2.4.so.2
#7  0xfd3831a1 in zif_ldap_connect () from /opt/local/lib/php/20040412/ldap.so
#8  0xfcbda874 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#9  0xfcbe1a23 in ZEND_DO_FCALL_SPEC_CONST_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#10 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#11 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#12 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#13 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#14 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#15 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#16 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
---Type <return> to continue, or q <return> to quit---
#17 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#18 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#19 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#20 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#21 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#22 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#23 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#24 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#25 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#26 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#27 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#28 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#29 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#30 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
---Type <return> to continue, or q <return> to quit---
   from /opt/local/lib/httpd/mod_php5.so
#31 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#32 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#33 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#34 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#35 0xfcbda985 in zend_do_fcall_common_helper_SPEC ()
   from /opt/local/lib/httpd/mod_php5.so
#36 0xfcbdad65 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER ()
   from /opt/local/lib/httpd/mod_php5.so
#37 0xfcbd9e99 in execute () from /opt/local/lib/httpd/mod_php5.so
#38 0xfcbbebaa in zend_execute_scripts () from /opt/local/lib/httpd/mod_php5.so
#39 0xfcb7f40e in php_execute_script () from /opt/local/lib/httpd/mod_php5.so
#40 0xfcc509ca in php_handler () from /opt/local/lib/httpd/mod_php5.so
#41 0x08085c2a in ap_run_handler ()
#42 0x0808638e in ap_invoke_handler ()
#43 0x08094ca7 in ap_internal_redirect ()
#44 0xfe48c232 in handler_redirect () from /opt/local/lib/httpd/mod_rewrite.so
#45 0x08085c2a in ap_run_handler ()
#46 0x0808638e in ap_invoke_handler ()
#47 0x08094471 in ap_process_request ()
#48 0x0809177c in ap_process_http_connection ()
---Type <return> to continue, or q <return> to quit---
#49 0x0808d426 in ap_run_process_connection ()
#50 0x0808d858 in ap_process_connection ()
#51 0x08099e89 in child_main ()
#52 0x08099f65 in make_child ()
#53 0x0809a472 in ap_mpm_run ()
#54 0x080709ab in main ()
(gdb) 

Update 2:

From what I can tell the problem begins in these two function calls:

#3  0xfde3f78b in ldap_free_urldesc () from /usr/lib/libldap.so.5
#4  0xfd0943d9 in ldap_free_urllist () from /opt/local/lib/libldap-2.4.so.2

The function in #4 (ldap_free_urllist) is called from a library in /opt/local/lib/libldap-2.4.so.2 and #3 is called from a library in /usr/lib/libldap.so.5. I don't know enough to tell whether or not it is normal, but I would assume it is not. So somehow both of these LDAP libraries are getting loaded.