LDAP : SambaMungedDial Syntax
Yohann Fourteau
yohann.fourteau at aitb.org
Wed Dec 8 17:44:50 GMT 2004
Selon Yohann Fourteau <yohann.fourteau at aitb.org>:
> So for people who want to extract info from sambaMungedDial attribute, I ve
> done
> a little script (in php) :
> ----------------------------------------------
> <?
> function hexbin($hex){
> $bin='';
> for($i=0;$i<strlen($hex);$i+=2)
> $bin.=chr(hexdec(substr($hex,$i,2)));
> return $bin;
> }
>
> $res=ldap_connect("localhost");
> ldap_bind($res);
> $dn="the dn";
> $ret=ldap_read($res,$dn,"objectclass=*",array("sambamungeddial"));
> $entries = ldap_get_entries($res, $ret);
> $str=$entries[0]["sambamungeddial"][0];
> ldap_close($res);
>
>
> $string=base64_decode($str);
> $len=strlen($string);
> $noField=0;
> $i=0;
> while($i<$len)
> {
> if ($string[$i+6]=='C' && $string[$i+8]=='t' && $string[$i+10]=='x')
> {
> if ($noField==0)
> $first=$i;
> $fieldNameLen=ord($string[$i]);
> $field[$noField]["name"]="";
> $field[$noField]["value"]="";
> for($j=$i+6;$j<$i+6+$fieldNameLen;$j+=2)
> {
> $field[$noField]["name"].=$string[$j];
> }
> $fieldValueLen=ord($string[$i+2]);
> for($j=$i+6+$fieldNameLen;$j<$i+6+$fieldNameLen+$fieldValueLen;$j++)
> {
> $field[$noField]["value"].=$string[$j];
> }
> $noField++;
> $i=$i+6+$fieldNameLen+$fieldValueLen;
> }
> else
> $i++;
> }
>
>
$stringFields=array("CtxMinEncryptionLevel","CtxWorkDirectory","CtxNWLogonServer","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath","CtxInitialProgram","CtxCallbackNumber");
> foreach($field as $index => $fi)
> {
> if (in_array($fi["name"],$stringFields))
> {
> $field[$index]["value"]=hexbin($fi["value"]);
> }
> }
>
> var_dump($field);
> // no idea what it is, the rest is space caracters.
> echo ord($string[$first-4])."\n";
> echo ord($string[$first-2])."\n";
> ?>
> --------------------------------------------
>
> I'm writing another script (in php) which integrate data into that
> attribute.
Here it is (with same $field array - be carefull to the order of elements in
that array) :
----------------------------
$strBeginBase64="IAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAUAAQAA==";
$strBegin=base64_decode($strBeginBase64);
$stringFields=array("CtxMinEncryptionLevel","CtxWorkDirectory","CtxNWLogonServer","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath","CtxInitialProgram","CtxCallbackNumber");
foreach($field as $index => $fi)
{
if (in_array($fi["name"],$stringFields))
{
$field[$index]["value"]=bin2hex($fi["value"]);
}
}
$finalString=$strBegin;
foreach($field as $index => $fi)
{
$name=$fi["name"];
$finalName="";
for($i=0;$i<strlen($name);$i++)
{
$finalName.=$name[$i].chr(0);
}
$nameLenght=strlen($finalName);
$finalString.=chr($nameLenght).chr(0);
$valueLenght=strlen($fi["value"]);
$finalString.=chr($valueLenght).chr(0);
$finalString.=chr(1).chr(0);
$finalString.=$finalName;
$finalString.=$fi["value"];
}
echo base64_encode($finalString);
echo "\n";
----------------------------------
Hope it'll help somebody.
--
Yohann F.
More information about the samba-technical
mailing list