ID:               28291
 User updated by:  raphux at raphux dot com
 Reported By:      raphux at raphux dot com
-Status:           Open
+Status:           Closed
 Bug Type:         LDAP related
 Operating System: GNU/Linux 2.4.26
 PHP Version:      4.3.6
 New Comment:

Ok, I found why it acts like this. Thanks to a friend of mine who has
some experiences in php and shell hacking.

The probleme was that the shell_exec() really takes the mac address of
the host, but also the \n at the end of the string, even if it doesn't
print it out. So I hadded this little function to make it works (thx to
[EMAIL PROTECTED](dhot)com who write a comment on the chop() function)
:

function delbackslash_n($mac){
        $endchar = substr("$mac", strlen("$mac") - 1, 1);
        if ($endchar == "\n")
        {
                $mac = substr("$mac", 0, -1);
                echo '"\n" is present'; // just to verify
                echo "<br>"; //may be commented to :)
        }
        return $mac;
}

It deletes the \n if there is one, and then the ldap-search function
works well.

Hop this will be helpfull for someone someday...

Bye!


Previous Comments:
------------------------------------------------------------------------

[2004-05-06 01:44:15] raphux at raphux dot com

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 this bug report at http://bugs.php.net/?id=28291&edit=1

Reply via email to