From 1eb677de16f604fb8278f371e5dac91e6ab7c473 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 21 Dec 2009 21:41:37 +1300 Subject: [PATCH] Make some of those unused functions really not be used! --- inc/DAVResource.php | 10 +- inc/always.php | 8 +- inc/always.php.in | 8 +- inc/caldav-PROPFIND.php | 6 +- .../regression-suite/245-Moz-POST-FB.result | 2 +- .../regression-suite/245-Moz-POST-FB.test | 3 +- .../873-GroupDAV-PROPFIND.result | 112 +++++++++++------- 7 files changed, 87 insertions(+), 62 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index e66bdb9e..cfa327f6 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -275,12 +275,12 @@ class DAVResource 'is_calendar' => false, 'is_principal' => false, 'is_addressbook' => false ); - $base_sql = 'SELECT collection.*, path_privileges(:session_principal, collection.dav_name), '; + $base_sql = 'SELECT collection.*, path_privs(:session_principal, collection.dav_name,:scan_depth), '; $base_sql .= 'p.principal_id, p.type_id AS principal_type_id, '; $base_sql .= 'p.displayname AS principal_displayname, p.default_privileges AS principal_default_privileges '; $base_sql .= 'FROM collection LEFT JOIN principal p USING (user_no) WHERE '; $sql = $base_sql .'collection.dav_name = :raw_path '; - $params = array( ':raw_path' => $this->dav_name, ':session_principal' => $session->principal_id ); + $params = array( ':raw_path' => $this->dav_name, ':session_principal' => $session->principal_id, ':scan_depth' => $c->permission_scan_depth ); if ( !preg_match( '#/$#', $this->dav_name ) ) { $sql .= ' OR collection.dav_name = :up_to_slash OR collection.dav_name = :plus_slash '; $params[':up_to_slash'] = preg_replace( '#[^/]*$#', '', $this->dav_name); @@ -472,16 +472,16 @@ EOQRY; $this->privileges = 0; - if ( !isset($this->collection->path_privileges) ) { + if ( !isset($this->collection->path_privs) ) { $parent_path = preg_replace('{/[^/]*/$}', '/', $this->collection->dav_name ); dbg_error_log( 'DAVResource', 'Checking privileges of "%s" - parent of "%s"', $parent_path, $this->collection->dav_name ); $parent = new DAVResource( $parent_path ); - $this->collection->path_privileges = $parent->Privileges(); + $this->collection->path_privs = $parent->Privileges(); $this->collection->user_no = $parent->GetProperty('user_no'); } - $this->privileges = $this->collection->path_privileges; + $this->privileges = $this->collection->path_privs; } diff --git a/inc/always.php b/inc/always.php index 2e362887..db07d819 100644 --- a/inc/always.php +++ b/inc/always.php @@ -169,9 +169,9 @@ function getUserByName( $username, $use_cache = true ) { // Provide some basic caching in case this ends up being overused. if ( $use_cache && isset( $_known_users_name[$username] ) ) return $_known_users_name[$username]; - global $session; + global $c, $session; if ( isset($session->user_no) ) - $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, user_privileges(?,usr.user_no) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE lower(username) = lower(?) ", $session->user_no, $username ); + $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, pprivs(?,principal.principal_id,?) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE lower(username) = lower(?) ", $session->principal_id, $c->permission_scan_depth, $username ); else $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, 0::BIT(24) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE lower(username) = lower(?) ", $username ); if ( $qry->Exec('always',__LINE__,__FILE__) && $qry->rows == 1 ) { @@ -194,8 +194,8 @@ function getUserByID( $user_no, $use_cache = true ) { // Provide some basic caching in case this ends up being overused. if ( $use_cache && isset( $_known_users_id[$user_no] ) ) return $_known_users_id[$user_no]; - global $session; - $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, user_privileges(?,usr.user_no) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE user_no = ? ", $session->user_no, intval($user_no) ); + global $c, $session; + $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, pprivs(?,principal.principal_id,?) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE user_no = ? ", $session->principal_id, $c->permission_scan_depth, intval($user_no) ); if ( $qry->Exec('always',__LINE__,__FILE__) && $qry->rows == 1 ) { $_known_users_id[$user_no] = $qry->Fetch(); $name = $_known_users_id[$user_no]->username; diff --git a/inc/always.php.in b/inc/always.php.in index 49715856..e9edee9e 100644 --- a/inc/always.php.in +++ b/inc/always.php.in @@ -169,9 +169,9 @@ function getUserByName( $username, $use_cache = true ) { // Provide some basic caching in case this ends up being overused. if ( $use_cache && isset( $_known_users_name[$username] ) ) return $_known_users_name[$username]; - global $session; + global $c, $session; if ( isset($session->user_no) ) - $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, user_privileges(?,usr.user_no) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE lower(username) = lower(?) ", $session->user_no, $username ); + $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, pprivs(?,principal.principal_id,?) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE lower(username) = lower(?) ", $session->principal_id, $c->permission_scan_depth, $username ); else $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, 0::BIT(24) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE lower(username) = lower(?) ", $username ); if ( $qry->Exec('always',__LINE__,__FILE__) && $qry->rows == 1 ) { @@ -194,8 +194,8 @@ function getUserByID( $user_no, $use_cache = true ) { // Provide some basic caching in case this ends up being overused. if ( $use_cache && isset( $_known_users_id[$user_no] ) ) return $_known_users_id[$user_no]; - global $session; - $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, user_privileges(?,usr.user_no) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE user_no = ? ", $session->user_no, intval($user_no) ); + global $c, $session; + $qry = new PgQuery( "SELECT *, to_char(updated at time zone 'GMT','Dy, DD Mon IYYY HH24:MI:SS \"GMT\"') AS modified, principal.*, pprivs(?,principal.principal_id,?) AS privileges FROM usr LEFT JOIN principal USING(user_no) WHERE user_no = ? ", $session->principal_id, $c->permission_scan_depth, intval($user_no) ); if ( $qry->Exec('always',__LINE__,__FILE__) && $qry->rows == 1 ) { $_known_users_id[$user_no] = $qry->Fetch(); $name = $_known_users_id[$user_no]->username; diff --git a/inc/caldav-PROPFIND.php b/inc/caldav-PROPFIND.php index 645c5ccc..bcd39f37 100644 --- a/inc/caldav-PROPFIND.php +++ b/inc/caldav-PROPFIND.php @@ -98,7 +98,7 @@ function get_collection_contents( $depth, $user_no, $collection ) { /** * Calendar/Addressbook collections may not contain collections, so we won't look */ - $params = array( ':session_principal' => $session->principal_id ); + $params = array( ':session_principal' => $session->principal_id, ':scan_depth' => $c->permission_scan_depth ); if ( $collection->dav_name() == '/' ) { $sql = "SELECT usr.*, '/' || username || '/' AS dav_name, md5(username || updated::text) AS dav_etag, "; $sql .= "to_char(joined at time zone 'GMT',$date_format) AS created, "; @@ -107,13 +107,13 @@ function get_collection_contents( $depth, $user_no, $collection ) { $sql .= 'principal_id AS collection_id, '; $sql .= 'principal.* '; $sql .= 'FROM usr JOIN principal USING (user_no) '; - $sql .= "WHERE (principal_privileges(:session_principal,principal.principal_id) & 1::BIT(24))::INT4::BOOLEAN "; + $sql .= "WHERE (pprivs(:session_principal::int8,principal.principal_id,:scan_depth::int) & 1::BIT(24))::INT4::BOOLEAN "; $sql .= 'ORDER BY usr.user_no'; } else { $sql = 'SELECT principal.*, collection.*, \'collection\' AS type FROM collection LEFT JOIN principal USING (user_no) '; $sql .= 'WHERE parent_container = :this_dav_name '; - $sql .= "AND (path_privileges(:session_principal,collection.dav_name) & 1::BIT(24))::INT4::BOOLEAN "; + $sql .= "AND (path_privs(:session_principal::int8,collection.dav_name,:scan_depth::int) & 1::BIT(24))::INT4::BOOLEAN "; $sql .= ' ORDER BY collection_id'; $params[':this_dav_name'] = $collection->dav_name(); } diff --git a/testing/tests/regression-suite/245-Moz-POST-FB.result b/testing/tests/regression-suite/245-Moz-POST-FB.result index afd02483..1a75470b 100644 --- a/testing/tests/regression-suite/245-Moz-POST-FB.result +++ b/testing/tests/regression-suite/245-Moz-POST-FB.result @@ -2,7 +2,7 @@ HTTP/1.1 200 OK Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule, extended-mkcol Allow: OPTIONS, PROPFIND, REPORT, DELETE, LOCK, UNLOCK, MOVE, POST, GET, PUT, HEAD, PROPPATCH -ETag: "ae241cc30505f7f7148b7fee176731fb" +ETag: "some valid etag" Content-Length: 968 Content-Type: text/xml; charset="utf-8" diff --git a/testing/tests/regression-suite/245-Moz-POST-FB.test b/testing/tests/regression-suite/245-Moz-POST-FB.test index 4d21ee24..c699fe4e 100644 --- a/testing/tests/regression-suite/245-Moz-POST-FB.test +++ b/testing/tests/regression-suite/245-Moz-POST-FB.test @@ -1,4 +1,4 @@ -# +#--------- # POST to scheduling outbox for freebusy query on user2 # TYPE=POST @@ -15,6 +15,7 @@ HEADER=Recipient: mailto:user3@example.net HEAD REPLACE=/^DTSTAMP:\d{4}[01]\d[0123]\dT[012]\d[0-5]\d[0-6]\dZ\r?$/DTSTAMP:yyyymmddThhmmssZ/ +REPLACE=/^ETag: "[0-9a-f]+".?$/ETag: "some valid etag"/ BEGINDATA BEGIN:VCALENDAR diff --git a/testing/tests/regression-suite/873-GroupDAV-PROPFIND.result b/testing/tests/regression-suite/873-GroupDAV-PROPFIND.result index 6552ca5a..0b7322b0 100644 --- a/testing/tests/regression-suite/873-GroupDAV-PROPFIND.result +++ b/testing/tests/regression-suite/873-GroupDAV-PROPFIND.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule, extended-mkcol Allow: OPTIONS, PROPFIND, REPORT -ETag: "8dade0339d83135c772d8f0838cc8339" -Content-Length: 8407 +ETag: "d3163c39f62cb97290677e0a12032a26" +Content-Length: 8679 Content-Type: text/xml; charset="utf-8" @@ -139,33 +139,15 @@ Content-Type: text/xml; charset="utf-8" httpd/unix-directory + + + - - - - - - - - - - - - - - - - - - - - - ab4a67c917e242e0989cd278c75a510e @@ -195,33 +177,15 @@ Content-Type: text/xml; charset="utf-8" httpd/unix-directory + + + - - - - - - - - - - - - - - - - - - - - - 4d470212545b8dd76f702fe2444accad @@ -251,12 +215,42 @@ Content-Type: text/xml; charset="utf-8" httpd/unix-directory + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -310,12 +304,42 @@ Content-Type: text/xml; charset="utf-8" httpd/unix-directory + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +