note 99403 deleted from function.ldap-get-values-len by danbrown
| From: | danbrown@php.net | Date: | Tue, 17 Aug 2010 16:38:39 +0000 |
| Subject: | note 99403 deleted from function.ldap-get-values-len by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171780@lists.php.net to get a copy of this message | ||
Note Submitter: php at talpidae dot net
----
To complement the collection gathered from the previous posts:
<?php
// Return the binary SID (for LDAP search in AD, for example)
function str_to_bin_sid($strsid)
{
if (empty($strsid) || !is_string($strsid))
throw new Exception(
'no SID string',
13);
$sid = explode('-', $strsid);
if (empty($sid) || count($sid) < 4)
throw new Exception(
'invalid SID string',
14);
$sid[0] = $sid[1]; // move rev, don't need "S-"
$sid[1] = count($sid) - 3; // set subcount
if ($sid[1] > 8)
throw new Exception(
'SID string with invalid sub authority count',
15);
foreach($sid as $idx => &$field) {
$field = dechex($field);
switch($idx) {
case 0: // rev, 8-bit
case 1: // subcount, 8-bit
$pad = 2;
break;
case 2: // auth, 48-bit
$pad = 12;
break;
default: // subauth, 32-bit, byteswap
$pad = 8;
}
$field = str_pad($field, $pad, '0', STR_PAD_LEFT);
if ($pad == 8)
$field = byteswap($field);
}
return pack('H*', implode('', $sid));
}
// Do a simple byte swap on a hex string
// borrowed from derek's post below
function byteswap($hex)
{
for ($i = strlen($hex) - 2; $i >= 0; $i -= 2)
$swp .= substr($hex, $i, 2);
return $swp;
}
?>