2011-05-05 2 views
0

아래 스크립트를 사용하여 아파치에서 로그온 한 사용자 정보를 얻습니다. 그것은 대접을합니다.로그온 한 사용자 전자 메일 | NTLM/Apache/PHP

내가 로그온 한 사용자의 이메일 주소를 가져 오는 것이 가능한지 궁금 했습니까?

다른 어떤 정보를 가져올 수 있습니까? 이름과 성?

이것이 작동하지 않는다면 로그인 한 사용자의 이메일 주소는 어떻게 얻을 수 있습니까? 가능한가? 사전에

감사

// This a copy taken 2008-08-21 from http://siphon9.net/loune/f/ntlm.php.txt to make sure the code is not lost. 
// For more information see: 
// http://blogs.msdn.com/cellfish/archive/2008/08/26/getting-the-logged-on-windows-user-in-your-apache-server.aspx 

// NTLM specs http://davenport.sourceforge.net/ntlm.html 

$headers = apache_request_headers(); 

if (!isset($headers['Authorization'])){ 
     header('HTTP/1.1 401 Unauthorized'); 
     header('WWW-Authenticate: NTLM'); 
     exit; 
} 

$auth = $headers['Authorization']; 

if (substr($auth,0,5) == 'NTLM ') { 
     $msg = base64_decode(substr($auth, 5)); 
     if (substr($msg, 0, 8) != "NTLMSSP\x00") 
       die('error header not recognised'); 

     if ($msg[8] == "\x01") { 
       $msg2 = "NTLMSSP\x00\x02"."\x00\x00\x00\x00". // target name len/alloc 
         "\x00\x00\x00\x00". // target name offset 
         "\x01\x02\x81\x01". // flags 
         "\x00\x00\x00\x00\x00\x00\x00\x00". // challenge 
         "\x00\x00\x00\x00\x00\x00\x00\x00". // context 
         "\x00\x00\x00\x00\x30\x00\x00\x00"; // target info len/alloc/offset 

       header('HTTP/1.1 401 Unauthorized'); 
       header('WWW-Authenticate: NTLM '.trim(base64_encode($msg2))); 
       exit; 
     } 
     else if ($msg[8] == "\x03") { 
       function get_msg_str($msg, $start, $unicode = true) { 
         $len = (ord($msg[$start+1]) * 256) + ord($msg[$start]); 
         $off = (ord($msg[$start+5]) * 256) + ord($msg[$start+4]); 
         if ($unicode) 
           return str_replace("\0", '', substr($msg, $off, $len)); 
         else 
           return substr($msg, $off, $len); 
       } 
       $user = get_msg_str($msg, 36); 
       $domain = get_msg_str($msg, 28); 
       $workstation = get_msg_str($msg, 44); 
       print $msg; 

       print "You are $user from $workstation.$domain"; 
     } 
} 

답변

0

아니, 죄송 NTLM 사양은 인증에 관한되며 해당 사용자 이름, 도메인 및 도전에서 해시 인증 응답을 제공 할 것입니다. 이런 식으로 이름이나 이메일 주소를 얻지 못할 것입니다.

1

로그온 한 사용자에 대해 PHP-ldap 모듈을 사용하여 누구인지 알 수 있습니다. 이 예제는 선택한 고유 이름에 대한 모든 항목을 출력합니다. 자신의 상황에 맞는 정보를 제공하려면 여기에서 약간의 작업을해야합니다. Windows의 LDP 도구는 여기에 넣을 정보를 찾는 데 매우 편리합니다.

<?php 
//specify the Distinguished Name 
$dn = "CN=Joe Bloggs,OU=SomeOU,DC=SomeDomain,DC=com"; 

$filter = "(sAMAccountName=bloggsj)"; 

$ad = ldap_connect("ldap://yourADserver"); 
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); 
$bd = ldap_bind($ad,"[email protected]","secret") or die("couldn't bind to AD!"); 

$result = ldap_search($ad, $dn, $filter); 
$entries = ldap_get_entries($ad, $result); 

print_r($entries); 
?> 
관련 문제