From: raphux at raphux dot com
Operating system: GNU/Linux 2.4.26
PHP version: 4.3.6
PHP Bug Type: LDAP related
Bug description: Can't pass a dynamic variable to $filter in ldap_search()
Description:
------------
I made a script that get the mac address of users on my LAN, and then
check in an openldap directory if it exists or not.
The probleme is that it seems to be impossible to pass a dynamic variable
to "ldap_search()" for the "filter" field.
Reproduce code:
---------------
<?php
function get_mac(){
$user_ip = $_SERVER['REMOTE_ADDR'];
$user_mac = shell_exec('/usr/sbin/arp -a '.$user_ip.' | cut -d" "
-f4');
return $user_mac;
}
$mac = get_mac(); //the client's MAC (on my LAN) is now
stored in $mac
$ldap_host = "127.0.0.1"; //my LDAP server
$connect = ldap_connect($ldap_host); //get a resource
identifier
$base_dn = "ou=utilisateurs,dc=pinel-wifi,dc=org"; //where to search
in the directory
$filter = "pager=$mac";
echo $filter; //to see if $filter is really what it
should be
echo "<br>";
$sr=ldap_search($connect, $base_dn, $filter); //let's search!
?>
Expected result:
----------------
the value of $filter should be placed correctly in the ldap_search
function. In my ldap log, I should have :
May 6 01:47:13 Pinel-WiFi slapd[341]: conn=56 fd=14 ACCEPT from
IP=127.0.0.1:32866 (IP=0.0.0.0:389)
May 6 01:47:13 Pinel-WiFi slapd[526]: begin get_filter
May 6 01:47:13 Pinel-WiFi slapd[526]: EQUALITY
May 6 01:47:13 Pinel-WiFi slapd[526]: end get_filter 0
May 6 01:47:13 Pinel-WiFi slapd[526]: conn=56 op=0 SRCH
base="ou=utilisateurs,dc=pinel-wifi,dc=org" scope=2
filter="(pager=00:0A:E6:A7:27:CC)"
[...]
I cut the end, uninteresting I think.
I got this log by replacing manually
$filter = "pager=$mac";
by this :
$filter = "pager=00:0A:E6:A7:27:CC";
Actual result:
--------------
And if I leave the original:
$filter = "pager=$mac";
that is what my openldap server recieve :
May 6 01:48:56 Pinel-WiFi slapd[341]: conn=58 fd=14 ACCEPT from
IP=127.0.0.1:32868 (IP=0.0.0.0:389)
May 6 01:48:56 Pinel-WiFi slapd[526]: begin get_filter
May 6 01:48:56 Pinel-WiFi slapd[526]: EQUALITY
May 6 01:48:56 Pinel-WiFi slapd[526]: end get_filter 0
May 6 01:48:56 Pinel-WiFi slapd[526]: conn=58 op=0 SRCH
base="ou=utilisateurs,dc=pinel-wifi,dc=org" scope=2
filter="(?=undefined)"
[...]
I cut the end too.
As you can see, there is a "(?=undefined)" in the filter field, which, I
think, shouldn't be here. I tought that was a bug, so that's why I
reported it.
--
Edit bug report at http://bugs.php.net/?id=28291&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28291&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28291&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28291&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28291&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28291&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28291&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28291&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28291&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28291&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28291&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28291&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28291&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28291&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28291&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28291&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28291&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28291&r=float