Tickets now working for PROPFIND requests, and maybe more...

This commit is contained in:
Andrew McMillan 2010-03-06 23:30:12 +13:00
parent 2255e1fa6a
commit c6745c97b0
3 changed files with 35 additions and 8 deletions

View File

@ -612,7 +612,11 @@ EOSQL;
if ( $qry->Exec("caldav") && $permission_result = $qry->Fetch() )
$this->privileges |= bindec($permission_result->perm);
dbg_error_log( "caldav", "Restricted permissions for user accessing someone elses hierarchy: %s", decbin($this->privileges) );
dbg_error_log( 'caldav', 'Restricted permissions for user accessing someone elses hierarchy: %s', decbin($this->privileges) );
if ( isset($this->ticket) && $this->ticket->MatchesPath($this->path) ) {
$this->privileges |= $this->ticket->privileges();
dbg_error_log( 'caldav', 'Applying permissions for ticket "%s" now: %s', $this->ticket->id(), decbin($this->privileges) );
}
}
/** convert privileges into older style permissions */

View File

@ -488,6 +488,11 @@ EOQRY;
$this->privileges = $this->collection->path_privs;
if ( is_string($this->privileges) ) $this->privileges = bindec( $this->privileges );
if ( isset($request->ticket) && $request->ticket->MatchesPath($this->dav_name) ) {
$this->privileges |= $request->ticket->privileges();
dbg_error_log( 'DAVResource', 'Applying permissions for ticket "%s" now: %s', $request->ticket->id(), decbin($this->privileges) );
}
}
@ -502,6 +507,8 @@ EOQRY;
/**
* Is the user has the privileges to do what is requested.
* @param $do_what mixed The request privilege name, or array of privilege names, to be checked.
* @return boolean Whether they do have one of those privileges against this resource.
*/
function HavePrivilegeTo( $do_what ) {
if ( !isset($this->privileges) ) $this->FetchPrivileges();

View File

@ -77,19 +77,25 @@ class DAVTicket
$this->grantor_collection_privileges = 0;
$qry = new AwlQuery(
'SELECT access_ticket.*, collection.dav_name, (access_ticket.expiry >= current_timestamp) AS expired,
'SELECT access_ticket.*, collection.dav_name, (access_ticket.expires < current_timestamp) AS expired,
path_privs(access_ticket.dav_owner_id,collection.dav_name,:scan_depth) AS grantor_collection_privileges
FROM access_ticket JOIN collection ON (target_collection_id = collection_id)
WHERE ticket_id = :ticket_id',
array(':ticket_id' => $ticket_id, ':scan_depth' => $c->permission_scan_depth)
);
if ( $qry->Exec('DAVTicket',__LINE__,__FILE__) && $qry->rows() == 1 && $t = $qry->Fetch() && $t->expired === 'f' ) {
foreach( $t AS $k => $v ) {
$this->{$k} = $v;
if ( $qry->Exec('DAVTicket',__LINE__,__FILE__) && $qry->rows() == 1 && $t = $qry->Fetch() ) {
if ( ! $t->expired ) {
foreach( $t AS $k => $v ) {
$this->{$k} = $v;
}
$this->expired = false;
$this->privileges = bindec($this->privileges);
$this->grantor_collection_privileges = bindec($this->grantor_collection_privileges);
dbg_error_log( 'DAVTicket', 'Found a current ticket for "%s"', implode(', ',bits_to_privilege($this->privileges())) );
}
else {
dbg_error_log( 'DAVTicket', 'Found an expired ticket: %s - %s', $ticket_id, $t->expires );
}
$this->expired = false;
$this->privileges = bindec($this->privileges);
$this->grantor_collection_privileges = bindec($this->grantor_collection_privileges);
}
if ( isset($this->target_resource_id) ) {
$qry = new AwlQuery( 'SELECT dav_name FROM caldav_data WHERE dav_id = :dav_id', array(':dav_id' => $this->target_resource_id ) );
@ -105,8 +111,18 @@ class DAVTicket
}
function id() {
return $this->ticket_id;
}
function privileges() {
return ($this->privileges & $this->grantor_collection_privileges);
}
function MatchesPath( $test_path ) {
$length = strlen($this->dav_name);
return (substr($test_path, 0, $length) == $this->dav_name);
}
}