Search code examples
phpldapiconvstrpos

PHP strpos on string returned from ldap_search


ok, so here's the problem:

I do a search for the userparameters attribute with ldap_search. I needed to get a couple of values out, being "CtxWFHomeDirDrive", "CtxWFHomeDir" and "CtxWFProfilePath"

The string I got was complete jibberish, so after an entire day of trying out every single character encoding conversion I could find, this one did half the trick:

$pUserParams = iconv('UTF-8', 'UTF-32', $entry_value)

For some reason the individual hex numbers following the 3 values I needed to extract were inversed (so 5C, which is backslash, came out as C5. Don't ask how I figured that one out :-P )

Knowing this, I could convert the hex values to display the actual citrix homedirdrive, profilepath, etc.

However, I still need to filter out a lot of unneeded characters from the final result string, but the following always returns false for some reason:

if (strpos($pUserParams,"CtxWFProfilePath") !== false) {}

When I echo the $pUserParams variable, it does display the whole string with the above three ctx parameters in it.

I suspected it must have something to do with special characters in the result string, so I tried removing line breaks, EOL's, unserializing the string (which produces an error at offset 0), etc etc

Nothing seems to work... Does anyone have an idea?

Thanks, Vincent

original string run through hex2bin:

20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202050071a080143747843666750726573656e74e394b5e694b1e688b0e381a2180801437478436667466c61677331e380b0e381a6e380b2e380b9120801437478536861646f77e384b0e380b0e380b0e380b02a02014374784d696e456e6372797074696f6e4c6576656ce384b02206014374785746486f6d654469724472697665e3a0b4e684b3e380b018c282014374785746486f6d65446972e68cb5e68cb5e394b7e38cb7e39cb6e388b6e394b6e398b6e3a4b6e68cb6e394b6e380b3e380b3e384b3e694b2e394b7e38cb7e39cb6e380b7e394b6e698b6e380b7e68cb6e394b6e388b6e394b6e694b2e3a4b6e694b6e390b7e68cb5e394b7e38cb7e394b6e388b7e3a0b6e698b6e690b6e394b6e390b6e388b7e3a4b6e398b7e394b6e390b2e68cb5e38cb7e390b7e3a4b6e684b6e694b6e694b2e688b6e698b6e688b6e688b6e394b6e68cb6e394b6e694b6e388b6e394b6e388b7e39cb6e380b020c28001437478574650726f66696c6550617468e68cb5e68cb5e384b6e38cb7e380b7e694b6e394b6e390b7e384b6e380b7e380b7e380b3e380b3e384b3e694b2e384b6e38cb7e380b7e694b2e3a4b6e694b6e390b7e68cb5e380b7e388b7e698b6e398b6e3a4b6e68cb6e394b6e38cb7e698b5e388b6e394b6e68cb6e39cb6e3a4b6e394b7e690b6e390b2e68cb5e38cb5e38cb5e38cb4e68cb5e38cb7e390b7e3a4b6e684b6e694b6e694b2e688b6e698b6e688b6e688b6e394b6e68cb6e394b6e694b6e388b6e394b6e388b7e39cb6e380b0e380b0
�� 

Solution

  • removing all special characters with

    preg_replace('/[^a-zA-Z0-9_ %[].()%&-]/s', '', $piConverted);

    solved it :-)

    Now, if I could only find a more elegant conversion so I don't have to "manually" reverse the hex code