serv = $serv ;
$this -> base = $base ;
$this -> dscr = $dscr ;
$this -> binddn = '' ;
$this -> bindpw = '' ;
$this -> login = 'uid' ;
$this -> uname = 'cn' ;
$this -> email = 'mail' ;
return $this ;
}
function find_ldap_user ( $user )
{ $SERV = $this -> serv ;
$BASE = $this -> base ;
$binddn = $this -> binddn ;
$bindpw = $this -> bindpw ;
$uid = $this -> login ;
$uname = $this -> uname ;
$login = $user -> login ;
$res = '' ;
if ( ! $ds = ldap_connect ( $SERV ) )
{ html_exit ( "failed : connect to $SERV (1)" ) ; }
if ( ! ldap_set_option ( $ds, LDAP_OPT_PROTOCOL_VERSION,3 ) )
{ html_exit ( "failed : set ldap v3 protocol" ) ; }
# print "SERV ($SERV) binddn ($binddn)
\n" ;
if ( ! $r = ldap_bind ( $ds, $binddn, $bindpw ) )
{ html_exit ( "failed : bind to '$SERV' (anonymous)" ) ; }
$attrs = array ( 'dn', $uname ) ;
$sr = ldap_search ( $ds, $BASE, "$uid=$login", $attrs ) ;
$count = ldap_count_entries ( $ds, $sr ) ;
if ( $count > 1 )
{ html_exit ( "$SERV : $count entries '$login' found" ) ; }
elseif ( $count == 1 )
{ $info = ldap_get_entries ( $ds, $sr ) ;
$dn = strtolower ( $info [ 0 ] [ 'dn' ] ) ;
$cn = $info [ 0 ] [ $uname ] [ 0 ] ;
$res = array ( dn => $dn , cn => $cn ) ;
ldap_unbind ( $ds ) ;
}
return $res ;
}
function vrfy_pswd ( $usdn, $PSWD )
{ $SERV = $this -> serv ;
$res = 0 ;
ini_set ( "error_reporting", '0' ) ;
if ( ! $ds = ldap_connect ( $SERV ) )
{ html_exit ( "failed : connect to $SERV (2)" ) ; }
elseif ( ! ldap_set_option ( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 ) )
{ html_exit ( "failed : set ldap v3 protocol" ) ; }
elseif ( ldap_bind ( $ds, $usdn, $PSWD ) )
{ $res = 1 ; }
ini_set ( "error_reporting", '1' ) ;
if ( $ds ) { ldap_unbind ( $ds ) ; }
return $res ;
}
}
$full_names = array () ;
function new_user ( $login )
{ $res = new User ; $res -> init ( $login ) ; return $res ; }
function full_name ( $login )
{ global $full_names ;
if ( ! array_key_exists ( $login, $full_names ) )
{ $name = new_user ( $login ) -> name () ;
$full_names [ $login ] = $name ;
}
return $full_names [ $login ] ;
}
class User
{
function init ( $login )
{ $this -> login = $login ;
$this -> name = '' ;
$this -> usdn = '' ;
$this -> clas = '' ;
$this -> err = 'init' ;
return $this ;
}
function find ()
{ $clas_list = Conf ( 'clas_list' ) ;
$login = $this -> login ;
if ( ! $login ) { html_exit ( "find : no login for user" ) ; }
$usdn = '' ;
$clas = '' ;
foreach ( $clas_list as $uclas )
{ $typ = $uclas -> typ ;
$pat = $uclas -> pat ;
if ( $typ == 'ldap' )
{ if ( $res = $uclas -> ldap -> find_ldap_user ( $this )
and preg_match ( "/$pat/", $res [ 'dn' ] )
)
{ $this -> clas = $uclas -> clas ;
$this -> usdn = $res [ 'dn' ] ;
$this -> name = $res [ 'cn' ] ;
}
}
elseif ( $typ == 'table' )
{ if ( $guest = try_repo_guest_by_login ( $login ) )
{ $this -> clas = G_CLASS () ;
$this -> name = $guest -> name ;
}
}
if ( $this -> clas ) { $this -> uclas = $uclas ; break ; }
}
return $this -> clas ;
}
function vrfy ( $PSWD )
{ $login = $this -> login ;
$clas = $this -> clas ;
$uclas = $this -> uclas ;
$typ = $uclas -> typ ;
$res = 0 ;
if ( ! $clas ) { html_exit ( "vrfy : no clas for user ($login)" ) ; }
if ( ! $uclas ) { html_exit ( "vrfy : no uclas for user ($login)" ) ; }
if ( $uclas -> clas != $clas )
{ $c = $uclas -> clas ;
html_exit ( "vrfy : uclas clas ($c) != clas ($clas) for ($login)" ) ;
}
if ( $typ == 'table' )
{ $passwd = get_repo_guest_by_login ( $login ) -> passwd ;
$crypted = crypt ( $PSWD, $passwd ) ;
# echo "passwd($passwd) crypted($crypted) PSWD($PSWD)
\n" ;
$res = $passwd == $crypted ;
}
elseif ( $typ == 'ldap' )
{ if ( ! ( $usdn = $this -> usdn ) )
{ html_exit ( "vrfy : no usdn for user ($login)" ) ; }
$res = $uclas -> ldap -> vrfy_pswd ( $usdn, $PSWD ) ;
}
else
{ html_exit ( "vrfy : bad typ($typ) clas($clas) for user($login)" ) ; }
return $res ;
}
function name ()
{ if ( ! $this -> clas ) { $this -> find () ; } return $this -> name ; }
}
$USER = '' ;
$CLAS = '' ;
$BAD_USER = '' ;
function session_vars ()
{ $res .= "
logged in as $USER user class : $CLAS |
---|