note 119809 added to function.ldap-get-values-len
| From: | m1tk0123123 at abv dot bg | Date: | Tue, 30 Aug 2016 23:52:17 +0000 |
| Subject: | note 119809 added to function.ldap-get-values-len | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206424@lists.php.net to get a copy of this message | ||
Hi
Here solution for WINDOWS objectsid:
// LIB .............................
class LDAP_OBJECT_SID {
public function toString($SID_BINARY) {
$split = str_split($SID_BINARY, 8);
$hexArray = array();
foreach ($split as $key => $byte) {
$hexArray[$key] = strToUpper(substr('0'.dechex(bindec($byte)), -2));
}
$BLOCK_COUNT = hexdec($hexArray[1]);
$DEC_GROUP['SUB-ID-BLOCKS'] = array();
for ($i=0; $i<$BLOCK_COUNT; $i++) {
$offset = 8 + (4 * $i);
$DEC_GROUP['SUB-ID-BLOCKS'][$i] = array();
$DEC_GROUP['SUB-ID-BLOCKS'][$i][1] = hexdec($hexArray[$offset+3]);
$DEC_GROUP['SUB-ID-BLOCKS'][$i][2] = hexdec($hexArray[$offset+2]);
$DEC_GROUP['SUB-ID-BLOCKS'][$i][3] = hexdec($hexArray[$offset+1]);
$DEC_GROUP['SUB-ID-BLOCKS'][$i][4] = hexdec($hexArray[$offset]);
}
$SID = 'S-'.hexdec($hexArray[0]).'-'.$this->byte6ToLong(
hexdec($hexArray[2]),
hexdec($hexArray[3]),
hexdec($hexArray[4]),
hexdec($hexArray[5]),
hexdec($hexArray[6]),
hexdec($hexArray[7])
);
foreach ($DEC_GROUP['SUB-ID-BLOCKS'] as $BLOCK) {
$SID .= '-'.$this->byte4ToLong(
$BLOCK[1],
$BLOCK[2],
$BLOCK[3],
$BLOCK[4]
);
}
return $SID;
}
private function byte6ToLong($b1, $b2, $b3, $b4, $b5, $b6) {
$byte6ToLong = $b1;
$byte6ToLong = $byte6ToLong*256 + $b2;
$byte6ToLong = $byte6ToLong*256 + $b3;
$byte6ToLong = $byte6ToLong*256 + $b4;
$byte6ToLong = $byte6ToLong*256 + $b5;
$byte6ToLong = $byte6ToLong*256 + $b6;
return $byte6ToLong;
}
private function byte4ToLong($b1, $b2, $b3, $b4) {
$byte4ToLong = $b1;
$byte4ToLong = $byte4ToLong*256 + $b2;
$byte4ToLong = $byte4ToLong*256 + $b3;
$byte4ToLong = $byte4ToLong*256 + $b4;
return $byte4ToLong;
}
}
TEST:
$sr=ldap_search($conn, $base_dn, $filter,$fields);
$entry = ldap_first_entry($conn, $sr);
$objectsid_binary = ldap_get_values_len($conn, $entry, "objectsid");
$Obj = new LDAP_OBJECT_SID();
echo $Obj->toString($objectsid_binary[0]);
----
Server IP: 72.52.91.14
Probable Submitter: 87.97.235.189
----
Manual Page -- http://php.net/manual/en/function.ldap-get-values-len.php
Edit -- https://master.php.net/note/edit/119809
Del: integrated -- https://master.php.net/note/delete/119809/integrated
Del: useless -- https://master.php.net/note/delete/119809/useless
Del: bad code -- https://master.php.net/note/delete/119809/bad+code
Del: spam -- https://master.php.net/note/delete/119809/spam
Del: non-english -- https://master.php.net/note/delete/119809/non-english
Del: in docs -- https://master.php.net/note/delete/119809/in+docs
Del: other reasons-- https://master.php.net/note/delete/119809
Reject -- https://master.php.net/note/reject/119809
Search -- https://master.php.net/manage/user-notes.php