2011-05-05 41 views
0

我正在使用以下腳本獲取apache中登錄的用戶詳細信息。它工作的一種享受。獲取登錄用戶Email | 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); 
?>