From 7e4b8c33c3f169f0e6a8416ea8e978291122f560 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sat, 26 Dec 2009 00:13:51 +1300 Subject: [PATCH] Add support for the property. --- inc/DAVResource.php | 62 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 6e2af8ff..0d4bad08 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -347,6 +347,7 @@ EOSQL; $this->collection->type = 'root'; $this->collection->exists = true; $this->collection->displayname = $c->system_name; + $this->collection->default_privileges = (1 | 16 | 32); } else { dbg_error_log( 'DAVResource', 'No collection for path "%s".', $this->dav_name ); @@ -455,7 +456,7 @@ EOQRY; global $session; if ( $this->dav_name == '/' || $this->dav_name == '' ) { - $this->privileges = 1; // read + $this->privileges = (1 | 16 | 32); // read + read-acl + read-current-user-privilege-set dbg_error_log( 'DAVResource', 'Read permissions for user accessing /' ); return; } @@ -834,6 +835,61 @@ EOQRY; } + /** + * Return ACL settings + */ + function GetACL( &$xmldoc ) { + global $c, $session; + + if ( !isset($this->principal) ) $this->FetchPrincipal(); + $default_privs = $this->principal->default_privileges; + if ( isset($this->collection->default_privileges) ) $default_privs = $this->collection->default_privileges; + + $acl = array(); + $privilege_names = bits_to_privilege($default_privs); + $privileges = array(); + foreach( $privilege_names AS $k ) { + $privilege = new XMLElement('privilege'); + if ( isset($xmldoc) ) + $xmldoc->NSElement($privilege,$k); + else + $privilege->NewElement($k); + $privileges[] = $privilege; + } + $acl[] = new XMLElement('ace', array( + new XMLElement('principal', new XMLElement('authenticated')), + new XMLElement('grant', $privileges ) ) + ); + + $qry = new AwlQuery('SELECT dav_principal.dav_name, grants.* FROM grants JOIN dav_principal ON (to_principal=principal_id) WHERE by_collection = :collection_id OR by_principal = :principal_id ORDER BY by_collection', + array( ':collection_id' => $this->collection->collection_id, ':principal_id' => $this->principal->principal_id ) ); + if ( $qry->Exec('DAVResource') && $qry->rows() > 0 ) { + $by_collection = null; + while( $grant = $qry->Fetch() ) { + if ( !isset($by_collection) ) $by_collection = isset($grant->by_collection); + if ( $by_collection && !isset($grant->by_collection) ) break; + + $privilege_names = bits_to_privilege($grant->privileges); + $privileges = array(); + foreach( $privilege_names AS $k ) { + $privilege = new XMLElement('privilege'); + if ( isset($xmldoc) ) + $xmldoc->NSElement($privilege,$k); + else + $privilege->NewElement($k); + $privileges[] = $privilege; + } + $acl[] = new XMLElement('ace', array( + new XMLElement('principal', $xmldoc->href(ConstructURL($grant->dav_name))), + new XMLElement('grant', $privileges ) ) + ); + } + } + return $acl; + + } + + /** * Return general server-related properties, in plain form */ @@ -1051,6 +1107,10 @@ EOQRY; $reply->NSElement($prop, $tag, $address_data ); break; + case 'DAV::acl': + $reply->NSElement($prop, $tag, $this->GetACL( $reply ) ); + break; + default: $property_value = $this->GetProperty(preg_replace('{^.*:}', '', $tag)); if ( isset($property_value) ) {