Add NeedPrivilege() method to DAVResource and simplify request method.

This commit is contained in:
Andrew McMillan 2009-12-26 11:19:21 +13:00
parent e0e5887762
commit ebbec96269
3 changed files with 25 additions and 6 deletions

View File

@ -1098,12 +1098,18 @@ EOSQL;
/**
* Send a need-privileges error response. This function will never return.
* Send a need-privileges error response. This function will only return
* if the $href is not supplied and the current user has the specified
* permission for the request path.
*
* @param string $href The unconstructed URI where we needed the privilege.
* @param string $privilege The name of the needed privilege.
* @param string $href The unconstructed URI where we needed the privilege.
*/
function NeedPrivilege( $href, $privilege ) {
function NeedPrivilege( $privilege, $href=null ) {
if ( !isset($href) ) {
if ( $request->AllowedTo($privilege) ) return;
}
$reply = new XMLDocument();
$xml = new XMLElement( 'need-privileges',
new XMLElement( 'resource', array(

View File

@ -509,6 +509,21 @@ EOQRY;
}
/**
* Check if we have the needed privilege or send an error response.
*
* @param string $privilege The name of the needed privilege.
*/
function NeedPrivilege( $privilege ) {
global $request;
if ( $this->HavePrivilegeTo($privilege) ) return;
$request->NeedPrivilege( $privilege, $this->dav_name );
exit(0); // Unecessary, but might clarify things
}
/**
* Returns the array of privilege names converted into XMLElements
*/

View File

@ -12,9 +12,7 @@ dbg_error_log("ACL", "method handler");
require_once('DAVResource.php');
if ( ! ( $request->AllowedTo('read-acl') || $request->AllowedTo('read-current-user-privilege-set') || $request->AllowedTo('write-acl') ) ) {
$request->DoResponse(403);
}
$request->NeedPrivilege('DAV::write-acl');
if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put']) && $c->dbg['put'])) ) {
$fh = fopen('/tmp/MOVE.txt','w');