<?php

   
/*
    *   AUTHROIZATION AGAINST A SAMBA SERVER
    *
    *
    *   Author:
    *           - Daniel Rozsnyo <daniel@rozsnyo.com>
    *
    *   References:
    *           - http://php.net/proc_open
    *           - http://www.samba.org/samba/docs/man/manpages-3/smbclient.1.html
    *
    *   Created for & with the help of yak ;)
    *
    */

    // returns TRUE or FALSE depending on the authorization result and NULL on error
    
function smb_auth$host$user$pass ) { 
    
        
$service "//$host/IPC$";
        
        
$command "smbclient ".escapeshellarg($service)." -c exit";

        
$FD      = array( => array('pipe','r')
                        , 
=> array('pipe','w')
                        , 
=> array('pipe','w')
                        );
                  
        
$workdir '/';
    
        
$ENV     = array( 'LOGNAME' => $user
                        
'PASSWD'  => $pass
                        
);

        
$phandle proc_open$command$FD$pipes$workdir$ENV );
    
        if (!
is_resource($phandle)) return null;
    
        
fclose($pipes[0]);
        while(!
feof($pipes[1])) fgets($pipes[1],1024);
        while(!
feof($pipes[2])) fgets($pipes[2],1024);
        
fclose($pipes[1]);
        
fclose($pipes[2]);

        
$retval proc_close($phandle);
        
        return (
$retval==0);

    }

?>