Active Directory 에서 binary 형태로 된 데이터를 검색하니깐 그냥 데이터가 보이지는 않더라구요.
이경우에는 인코딩같은것을 해 주거나 추가로 작업을 해 주어야 하나요?
어떤 프로그램이든 예제가 있으면 참고할 듯한데요.
제가 작업하려고 하는건 PHP, VBS(여기서는 ADSI 이런거 이용하던가? 아직 해보지는 않아서 모르겠음) 입니다.
PHP에서는 일단 그냥 일반 텍스트형태의 검색과는 달라서 값이 안 나오더군요.
앗 찾았습니다. 분석은 내일 해봐야겠군요.
ldap_search 한것을 ldap_get_entries 를 이용하여 가져오지 않고 ldap_first_entry 를 이용하고 가져오고 ldap_get_values_len 를 이용하여 무언가 바이너리 데이터의 크기?를 구하고 bin2hex 를 이용하여 바이너리 포맷을 출력할 수 있는 포맷으로 변경을 하는 듯 합니다.
ldap_get_values_len 를 이용하여 무언가 바이너리 데이터의 크기?를 구하고
어찌되었건 실행이 잘 되는군요.
http://forums.windrivers.com/showthread.php?t=71265
$result = ldap_search($ad, $dn,$filter);
$entry=ldap_first_entry($ad,$result);
$hoursbinary=ldap_get_values_len($ad,$entry,"logonhours");
$hourshex=bin2hex($hoursbinary[0])."<br>";
print "hours: ".$hourshex."<br>";
아 보이지 않는것이 아니라 LDAP 브라우저같은것으로 보시면 Binary데이터가 LDAP에 들어갈때는
Base64로 encoding되서 들어가거든요.
즉 데이터를 받아서 Base64로 decoding하여 변수에 넣고 처리하면 될거 같습니다.
자바에서 그렇게 처리하고 있습니다.
예제)
넣을때
byte[] jpeg_data = readImage( "myimage.jpg" );
LDAPAttribute attr3 = new LDAPAttribute( "jpegPhoto", jpeg_data );
빼올때
Enumeration enumVals =
attr.getByteValues();
// Get the first value - if there’s more
// than one
if ( enumVals.hasMoreElements() ) {
theLDAPPhoto = (byte[])enumVals.nextElement();
}
즉 LDAP에 들어 있는 데이터를 byte처리해서 가지고 오시면 파일이든 그림이든 가지고
오시면 될 듯합니다.
그럼 수고하세요.
댓글 감사합니다.
제가 php에서 처리한 내용을 간략히 정리해보았습니다.
LDAP (AD, Openldap 등) 에서 text, 숫자는 검색하여 바로 볼 수 있지만 binary string 은 별도의 처리가 필요하다.
http://www.php.net/manual/en/book.ldap.php
ldap_get_values_len — Get all binary values from a result entry
ldap_get_values — Get all values from a result entry
바이너리 데이터를 가져오기 위해서는 ldap_get_values_len 를 이용한다.
http://www.php.net/manual/en/function.ldap-get-values-len.php 를 보면 이에 대해서 상세한 예제가 있다.
ldap_get_values 나 ldap_get_values_len 에서 리턴하는 자료는 array 로 나온다.
하나의 attribute 에 대하여 여러개의 엔트리가 있을 수 있다.
return_value["count"] = number of values for attribute return_value[0] = first value of attribute return_value[i] = ith value of attribute
bin2hex 는 바이너리 데이터를 ASCII string 으로 바꾸어준다.
bin2hex — Convert binary data into hexadecimal representation
http://www.php.net/manual/en/function.bin2hex.php
#!/usr/bin/php -q$rootdn="CN=Computers,dc=WDS,dc=TEST";$ldaphost="ldap://wds.test";$userdn="administrator@wds.test";$password="xxxx";$cn="test2";$ad=ldap_connect($ldaphost) or die("Couldn't connect to $ldaphost!");ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);$bd=ldap_bind($ad,$userdn,$password) or die("Couldn't bind to AD!");$justthese=array("cn","netbootMachineFilePath","netbootGUID");$filter="cn=$cn";$sr=ldap_search($ad, $rootdn, $filter, $justthese) or die("Couldn't search to AD!");$count=ldap_count_entries($ad, $sr);if($count < 1) { echo "$cn not found.\n"; exit;}// attribute 는 소문자로 사용해야 함$entry=ldap_first_entry($ad,$sr);$name=ldap_get_values($ad, $entry, "cn");$netbootmachinefilepath=ldap_get_values($ad, $entry, "netbootmachinefilepath");$bin_netbootguid=ldap_get_values_len($ad,$entry,"netbootguid");$netbootguid=bin2hex($bin_netbootguid[0]);$netbootguid=substr($netbootguid,20);echo "cn : ". $name[0] . "\n";echo "netbootmachinefilepath : ". $netbootmachinefilepath[0] . "\n";echo "netbootguid : " . $netbootguid . "\n";ldap_close($ad);?>