pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jonas Sundman <jonas.sundman@thl.fi>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: getTablePrivileges empty if table owned by group role
Date: Tue, 23 Aug 2011 15:30:07 +0300
Message-ID: <4E539D4F.6090803@thl.fi> (raw)
In-Reply-To: <4E4CD82E.3040102@thl.fi>
References: <4E4CD82E.3040102@thl.fi>

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

Attachments:

AbstractJdbc2DatabaseMetaData.java.patch (text/x-patch, 6.2K) download 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 + "}";

view thread (4+ messages)  latest in thread

Message-ID: <4E539D4F.6090803@thl.fi>
Permalink:  ../4E539D4F.6090803@thl.fi/
Also on:    postgresql.org/message-id/4E539D4F.6090803@thl.fi

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: jonas.sundman@thl.fi
  Subject: Re: getTablePrivileges empty if table owned by group role
  In-Reply-To: <4E539D4F.6090803@thl.fi>
  References: <4E4CD82E.3040102@thl.fi> <4E539D4F.6090803@thl.fi>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox