Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6BC4EB5D803 for ; Tue, 23 Aug 2011 09:30:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 23022-08 for ; Tue, 23 Aug 2011 12:30:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout.thl.fi (mailout.thl.fi [193.167.195.59]) by mail.postgresql.org (Postfix) with ESMTP id 4F781B5DC03 for ; Tue, 23 Aug 2011 09:30:08 -0300 (ADT) Received: from mailout (localhost.localdomain [127.0.0.1]) by mailout.thl.fi (8.13.1/8.13.1) with SMTP id p7NCU7JE006125 for ; Tue, 23 Aug 2011 15:30:07 +0300 Received: from 172.24.32.92 (172.24.32.92) by mailout (F-Secure/fsigk_smtp/580/mailout); Tue, 23 Aug 2011 15:30:07 +0200 (EET) X-Virus-Status: clean(F-Secure/fsigk_smtp/580/mailout) Received: from exhub1.stakes.fi (exhub1.stakes.fi [10.10.3.203]) by mail-hub.thl.fi (8.13.8/8.13.8) with ESMTP id p7NCU7j3023328 for ; Tue, 23 Aug 2011 15:30:07 +0300 Received: from [172.24.90.216] (172.24.90.216) by exhub1.stakes.fi (10.10.3.203) with Microsoft SMTP Server id 8.3.83.0; Tue, 23 Aug 2011 15:30:07 +0300 Message-ID: <4E539D4F.6090803@thl.fi> Date: Tue, 23 Aug 2011 15:30:07 +0300 From: Jonas Sundman User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: "pgsql-jdbc@postgresql.org" Subject: Re: getTablePrivileges empty if table owned by group role References: <4E4CD82E.3040102@thl.fi> In-Reply-To: <4E4CD82E.3040102@thl.fi> Content-Type: multipart/mixed; boundary="------------020204000801060701050305" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.373 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.473 X-Spam-Level: X-Archive-Number: 201108/65 X-Sequence-Number: 22097 --------------020204000801060701050305 Content-Type: text/plain; charset="ISO-8859-15"; format=flowed Content-Transfer-Encoding: 7bit Hi all, after some digging and further reading in the todo list I learned that acl parsing is known to be uncompatible with versions after 7.3. I decided to have a look into the code and turned up with a working version of the acl parsing, which I would like to share. To summarize whats in there - use rolename instead of username (which corrects the problem which my original message refers to) - handle the grantor part of the acl - handle the grantable attribute - use attacl for column permissions. The patch is against the development version (build 900). I have tested this against 8.4.4. Best regards, Jonas Sundman --------------020204000801060701050305 Content-Type: text/x-patch; name="AbstractJdbc2DatabaseMetaData.java.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="AbstractJdbc2DatabaseMetaData.java.patch" 2638,2639c2638,2639 < sql = "SELECT n.nspname,c.relname,r.rolname,a.attacl,a.attname " + < " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_roles r, pg_catalog.pg_attribute a " + --- > sql = "SELECT n.nspname,c.relname,u.usename,c.relacl,a.attname " + > " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_user u, pg_catalog.pg_attribute a " + 2641c2641 < " AND c.relowner = r.oid " + --- > " AND u.usesysid = c.relowner " + 2673,2674c2673,2674 < String owner = rs.getString("rolname"); < String acl = rs.getString("attacl"); --- > String owner = rs.getString("usename"); > String acl = rs.getString("relacl"); 2687,2693c2687 < Hashtable grantees = (Hashtable)permissions.get(permNames[i]); < String granteeUsers[] = new String[grantees.size()]; < Enumeration g = grantees.keys(); < int k = 0; < while (g.hasMoreElements()){ < granteeUsers[k++] = (String)g.nextElement(); < } --- > Vector grantees = (Vector)permissions.get(permNames[i]); 2696,2700c2690,2691 < Vector grantor = (Vector)grantees.get(granteeUsers[j]); < String grantee = (String)granteeUsers[j]; < for (int l = 0; l < grantor.size(); l++) { < String[] grants = (String[])grantor.elementAt(l); < String grantable = owner.equals(grantee) ? "YES" : grants[1]; --- > String grantee = (String)grantees.elementAt(j); > String grantable = owner.equals(grantee) ? "YES" : "NO"; 2706c2697 < tuple[4] = connection.encodeString(grants[0]); --- > tuple[4] = connection.encodeString(owner); 2714d2704 < } 2766,2767c2756,2757 < sql = "SELECT n.nspname,c.relname,r.rolname,c.relacl " + < " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_roles r " + --- > sql = "SELECT n.nspname,c.relname,u.usename,c.relacl " + > " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_user u " + 2769c2759 < " AND c.relowner = r.oid " + --- > " AND u.usesysid = c.relowner " + 2795c2785 < String owner = rs.getString("rolname"); --- > String owner = rs.getString("usename"); 2809,2822c2799,2803 < Hashtable grantees = (Hashtable)permissions.get(permNames[i]); < String granteeUsers[] = new String[grantees.size()]; < Enumeration g = grantees.keys(); < int k = 0; < while (g.hasMoreElements()){ < granteeUsers[k++] = (String)g.nextElement(); < } < for (int j = 0; j < granteeUsers.length; j++) < { < Vector grantor = (Vector)grantees.get(granteeUsers[j]); < String grantee = (String)granteeUsers[j]; < for (int l = 0; l < grantor.size(); l++) { < String[] grants = (String[])grantor.elementAt(l); < String grantable = owner.equals(grantee) ? "YES" : grants[1]; --- > Vector grantees = (Vector)permissions.get(permNames[i]); > for (int j = 0; j < grantees.size(); j++) > { > String grantee = (String)grantees.elementAt(j); > String grantable = owner.equals(grantee) ? "YES" : "NO"; 2827c2808 < tuple[3] = connection.encodeString(grants[0]); --- > tuple[3] = connection.encodeString(owner); 2832,2833d2812 < < } 2907d2885 < int slashIndex = acl.lastIndexOf("/"); 2911,2913c2889,2890 < String user = acl.substring(0, equalIndex); < String grantor = null; < if (user.length() == 0) --- > String name = acl.substring(0, equalIndex); > if (name.length() == 0) 2915,2921c2892 < user = "PUBLIC"; < } < if (slashIndex != -1) { < grantor = acl.substring(slashIndex + 1, acl.length()); < } < if (grantor == null) { < grantor = "Default"; --- > name = "PUBLIC"; 2923,2924c2894 < < String privs = acl.substring(equalIndex + 1, slashIndex); --- > String privs = acl.substring(equalIndex + 1); 2928d2897 < if (c != '*') { 2930,2935d2898 < String grantable; < if ( i < privs.length()-1 && privs.charAt(i + 1) == '*') { < grantable = "YES"; < } else { < grantable = "NO"; < } 2979,2987c2942,2945 < < Hashtable usersWithPermission = (Hashtable)privileges.get(sqlpriv); < String[] grant = {grantor, grantable}; < < if (usersWithPermission == null) { < usersWithPermission = new Hashtable(); < Vector permissionByGrantor = new Vector(); < permissionByGrantor.addElement(grant); < usersWithPermission.put(user, permissionByGrantor); --- > Vector usersWithPermission = (Vector)privileges.get(sqlpriv); > if (usersWithPermission == null) > { > usersWithPermission = new Vector(); 2989,2996d2946 < } else { < Vector permissionByGrantor = (Vector)usersWithPermission.get(user); < if (permissionByGrantor == null) { < permissionByGrantor = new Vector(); < permissionByGrantor.addElement(grant); < usersWithPermission.put(user,permissionByGrantor); < } else { < permissionByGrantor.addElement(grant); 2998,3002c2948 < < } < < } < --- > usersWithPermission.addElement(name); 3023c2969 < aclArray = "{" + owner + "=" + perms + "/" + owner + "}"; --- > aclArray = "{" + owner + "=" + perms + "}"; --------------020204000801060701050305--