Voting

: two plus seven?
(Example: nine)

The Note You're Voting On

m1tk0123123 at abv dot bg
8 years ago
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]);

<< Back to user notes page

To Top