1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?php
define('_NTLM_AUTH_FAILED',1);
define('_NTLM_PROXY',2);
function getInfosFromNTLM()
{
@session_start();
if (!empty($_SERVER['HTTP_VIA'])) {
return _NTLM_PROXY;
}
$header = apache_request_headers();
$auth = isset($header['Authorization']) ? $header['Authorization'] : null;
if (is_null($auth)) {
return unAuthorized();
}
if ($auth && (substr($auth,0,4) == 'NTLM')) {
$c64 = base64_decode(substr($auth,5));
$state = ord($c64{8});
switch ($state) {
case 1:
$chrs = array(0,2,0,0,0,0,0,0,0,40,0,0,0,1,130,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0);
$ret = "NTLMSSP";
foreach ($chrs as $chr) {
$ret .= chr($chr);
}
return unAuthorized(trim(base64_encode($ret)));
break;
case 3:
$l = ord($c64{31}) * 256 + ord($c64{30});
$o = ord($c64{33}) * 256 + ord($c64{32});
$domain = str_replace("\0","",substr($c64,$o,$l));
$l = ord($c64{39}) * 256 + ord($c64{38});
$o = ord($c64{41}) * 256 + ord($c64{40});
$user = str_replace("\0","",substr($c64,$o,$l));
return array('domain'=>$domain,'user'=>$user);
break;
}
}
}
function unAuthorized($msg=null) {
$ntlm = 'WWW-Authenticate: NTLM';
if ($msg) {
$ntlm .= ' '.$msg;
}
header('HTTP1.0 401 Unauthorized');
header($ntlm);
return _NTLM_AUTH_FAILED;
}
?> |
Partager