From c6745c97b05b9c07a811373ee318ab2d17b72681 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sat, 6 Mar 2010 23:30:12 +1300 Subject: [PATCH] Tickets now working for PROPFIND requests, and maybe more... --- inc/CalDAVRequest.php | 6 +++++- inc/DAVResource.php | 7 +++++++ inc/DAVTicket.php | 30 +++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index bd1b549a..ab1fb8bf 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -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 */ diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 1a645b71..63a9f4d9 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -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(); diff --git a/inc/DAVTicket.php b/inc/DAVTicket.php index 8655863f..171975a4 100644 --- a/inc/DAVTicket.php +++ b/inc/DAVTicket.php @@ -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); + } }