lots of work parsing acls to support weird usernames. use 7.4 magic for getting...
authorchriskl <chriskl>
Mon, 11 Aug 2003 05:48:04 +0000 (05:48 +0000)
committerchriskl <chriskl>
Mon, 11 Aug 2003 05:48:04 +0000 (05:48 +0000)
BUGS
classes/database/Postgres.php
classes/database/Postgres74.php
lang/english.php
lang/recoded/english.php

diff --git a/BUGS b/BUGS
index f6903deef28e6b4fbda34e5646050e08052cee62..b58198ce679b3588ef7206c160dfea1aa4350c87 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,4 +1,3 @@
-* Fix privileges for commas and stuff in usernames
 * Create trigger screen doesn't save fields if it fails creating trigger
 * XML output can't use field names as tag names...
 * Backport findObject to pre-7.3
@@ -8,4 +7,5 @@
 * pg_dump feature!!!
 * reports - unindexed fk's
          - slow indexes
+* Revoke grant option
 
index 62ce1bc7606272adb0906215008f98009b95cd31..388b8ee164e1564598a9683863b6f3e4dda136ba 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.135 2003/08/06 07:04:45 chriskl Exp $
+ * $Id: Postgres.php,v 1.136 2003/08/11 05:48:04 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1712,9 +1712,9 @@ class Postgres extends BaseDB {
        }
 
        /**
-        * Return information about a specific group
+        * Return users in a specific group
         * @param $groname The name of the group
-        * @return All groups
+        * @return All users in the group
         */
        function &getGroup($groname) {
                $this->clean($groname);
@@ -1734,7 +1734,6 @@ class Postgres extends BaseDB {
                return $this->selectSet($sql);
        }
 
-       
        /**
         * Creates a new group
         * @param $groname The name of the group
@@ -2058,17 +2057,42 @@ class Postgres extends BaseDB {
                // Take off the first and last characters (the braces)
                $acl = substr($acl, 1, strlen($acl) - 2);
 
-               // Pick out individual ACE's by exploding on the comma
-               $aces = explode(',', $acl);
+               // Pick out individual ACE's by carefully parsing.  This is necessary in order
+               // to cope with usernames and stuff that contain commas
+               $aces = array();
+               $i = $j = 0;            
+               $in_quotes = false;
+               while ($i < strlen($acl)) {
+                       // If current char is a double quote and it's not escaped, then
+                       // enter quoted bit
+                       $char = substr($acl, $i, 1);
+                       if ($char == '"' && ($i == 0 || substr($acl, $i - 1, 1) != '\\')) 
+                               $in_quotes = !$in_quotes;
+                       elseif ($char == ',' && !$in_quotes) {
+                               // Add text so far to the array
+                               $aces[] = substr($acl, $j, $i - $j);
+                               $j = $i + 1;
+                       }
+                       $i++;
+               }
+               // Add final text to the array
+               $aces[] = substr($acl, $j);
 
                // Create the array to be returned
                $temp = array();
 
                // For each ACE, generate an entry in $temp
                foreach ($aces as $v) {
+                       
                        // If the ACE begins with a double quote, strip them off both ends
-                       if (strpos($v, '"') === 0) $v = substr($v, 1, strlen($v) - 2);
-
+                       // and unescape backslashes and double quotes
+                       $unquote = false;
+                       if (strpos($v, '"') === 0) {
+                               $v = substr($v, 1, strlen($v) - 2);
+                               $v = str_replace('\\"', '"', $v);
+                               $v = str_replace('\\\\', '\\', $v);
+                       }
+                       
                        // Figure out type of ACE (public, user or group)
                        if (strpos($v, '=') === 0)
                                $atype = 'public';
@@ -2080,8 +2104,37 @@ class Postgres extends BaseDB {
                        else
                                $atype = 'user';
 
-                       // Separate entity from character list
-                       list ($entity, $chars) = explode('=', $v);
+                       // Break on unquoted equals sign...
+                       $i = 0;         
+                       $in_quotes = false;
+                       $entity = null;
+                       $chars = null;  
+                       while ($i < strlen($v)) {
+                               // If current char is a double quote and it's not escaped, then
+                               // enter quoted bit
+                               $char = substr($v, $i, 1);
+                               $next_char = substr($v, $i + 1, 1);
+                               if ($char == '"' && ($i == 0 || $next_char != '"')) {
+                                       $in_quotes = !$in_quotes;
+                               }
+                               // Skip over escaped double quotes
+                               elseif ($char == '"' && $next_char == '"') {
+                                       $i++;
+                               }
+                               elseif ($char == '=' && !$in_quotes) {
+                                       // Split on current equals sign                                 
+                                       $entity = substr($v, 0, $i);
+                                       $chars = substr($v, $i + 1);
+                                       break;
+                               }
+                               $i++;
+                       }
+                       
+                       // Check for quoting on entity name, and unescape if necessary
+                       if (strpos($entity, '"') === 0) {
+                               $entity = substr($entity, 1, strlen($entity) - 2);
+                               $entity = str_replace('""', '"', $entity);
+                       }
                        
                        // New row to be added to $temp
                        // (type, grantee, privileges, grantor, grant option?
@@ -2095,7 +2148,13 @@ class Postgres extends BaseDB {
                                if ($char == '*')
                                        $row[4][] = $this->privmap[substr($chars, $i - 1, 1)];
                                elseif ($char == '/') {
-                                       $row[3] = substr($chars, $i + 1);
+                                       $grantor = substr($chars, $i + 1);
+                                       // Check for quoting
+                                       if (strpos($grantor, '"') === 0) {
+                                               $grantor = substr($grantor, 1, strlen($grantor) - 2);
+                                               $grantor = str_replace('""', '"', $grantor);
+                                       }
+                                       $row[3] = $grantor;
                                        break;
                                }
                                else {
index 2b7126b396e6a9450589d8d2a88928d96f7f3857..ec0852a1edddf06ae3f83e254df240a1c1e31f16 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres74.php,v 1.9 2003/08/07 05:38:33 chriskl Exp $
+ * $Id: Postgres74.php,v 1.10 2003/08/11 05:48:04 chriskl Exp $
  */
 
 include_once('classes/database/Postgres73.php');
@@ -32,6 +32,23 @@ class Postgres74 extends Postgres73 {
        function Postgres74($host, $port, $database, $user, $password) {
                $this->Postgres73($host, $port, $database, $user, $password);
        }
+       
+       // Group functions
+       
+       /**
+        * Return users in a specific group
+        * @param $groname The name of the group
+        * @return All users in the group
+        */
+       function &getGroup($groname) {
+               $this->clean($groname);
+
+               $sql = "SELECT s.usename FROM pg_catalog.pg_user s, pg_catalog.pg_group g 
+                                       WHERE g.groname='{$groname}' AND s.usesysid = ANY (g.grolist)
+                                       ORDER BY s.usename";
+
+               return $this->selectSet($sql);
+       }               
 
        // View functions
        
index 2bad7977a9795b25394be64d0ce6c0c562ca0b23..145a5c7316562c0e3db180704f5dd0ac199a5bac 100755 (executable)
@@ -4,14 +4,14 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.94 2003/08/07 06:19:26 chriskl Exp $
+        * $Id: english.php,v 1.95 2003/08/11 05:48:04 chriskl Exp $
         */
 
        // Language and character set
        $lang['applang'] = 'English';
        $lang['appcharset'] = 'ISO-8859-1';
        $lang['applocale'] = 'en_US';
-       $lang['appdbencoding'] = 'SQL_ASCII';
+       $lang['appdbencoding'] = 'LATIN1';
 
        // Welcome  
        $lang['strintro'] = 'Welcome to phpPgAdmin.';
index 09f09cd8598c37164fcd63d20245b98d80e87910..41ae778ee64b22e1e840440dac72b7af7d4cae58 100644 (file)
@@ -4,14 +4,14 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.46 2003/08/07 06:19:26 chriskl Exp $
+        * $Id: english.php,v 1.47 2003/08/11 05:48:04 chriskl Exp $
         */
 
        // Language and character set
        $lang['applang'] = 'English';
        $lang['appcharset'] = 'ISO-8859-1';
        $lang['applocale'] = 'en_US';
-       $lang['appdbencoding'] = 'SQL_ASCII';
+       $lang['appdbencoding'] = 'LATIN1';
 
        // Welcome  
        $lang['strintro'] = 'Welcome to phpPgAdmin.';