*** pgsql/src/bin/pg_dump/dumputils.c 2009/01/01 17:23:54 1.43 --- pgsql/src/bin/pg_dump/dumputils.c 2009/01/22 20:16:07 1.44 *************** *** 8,14 **** * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * ! * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.42 2008/12/19 16:25:17 petere Exp $ * *------------------------------------------------------------------------- */ --- 8,14 ---- * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * ! * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.43 2009/01/01 17:23:54 momjian Exp $ * *------------------------------------------------------------------------- */ *************** *** 23,33 **** #define supports_grant_options(version) ((version) >= 70400) ! static bool parseAclItem(const char *item, const char *type, const char *name, ! int remoteVersion, PQExpBuffer grantee, PQExpBuffer grantor, PQExpBuffer privs, PQExpBuffer privswgo); static char *copyAclUserName(PQExpBuffer output, char *input); ! static void AddAcl(PQExpBuffer aclbuf, const char *keyword); /* --- 23,35 ---- #define supports_grant_options(version) ((version) >= 70400) ! static bool parseAclItem(const char *item, const char *type, ! const char *name, const char *subname, int remoteVersion, ! PQExpBuffer grantee, PQExpBuffer grantor, PQExpBuffer privs, PQExpBuffer privswgo); static char *copyAclUserName(PQExpBuffer output, char *input); ! static void AddAcl(PQExpBuffer aclbuf, const char *keyword, ! const char *subname); /* *************** parsePGArray(const char *atext, char *** *** 384,389 **** --- 386,392 ---- * Build GRANT/REVOKE command(s) for an object. * * name: the object name, in the form to use in the commands (already quoted) + * subname: the sub-object name, if any (already quoted); NULL if none * type: the object type (as seen in GRANT command: must be one of * TABLE, SEQUENCE, FUNCTION, LANGUAGE, SCHEMA, DATABASE, or TABLESPACE) * acls: the ACL string fetched from the database *************** parsePGArray(const char *atext, char *** *** 394,405 **** * Returns TRUE if okay, FALSE if could not parse the acl string. * The resulting commands (if any) are appended to the contents of 'sql'. * ! * Note: beware of passing fmtId() result as 'name', since this routine ! * uses fmtId() internally. */ bool ! buildACLCommands(const char *name, const char *type, ! const char *acls, const char *owner, int remoteVersion, PQExpBuffer sql) { --- 397,408 ---- * Returns TRUE if okay, FALSE if could not parse the acl string. * The resulting commands (if any) are appended to the contents of 'sql'. * ! * Note: beware of passing a fmtId() result directly as 'name' or 'subname', ! * since this routine uses fmtId() internally. */ bool ! buildACLCommands(const char *name, const char *subname, ! const char *type, const char *acls, const char *owner, int remoteVersion, PQExpBuffer sql) { *************** buildACLCommands(const char *name, const *** 448,455 **** * wire-in knowledge about the default public privileges for different * kinds of objects. */ ! appendPQExpBuffer(firstsql, "REVOKE ALL ON %s %s FROM PUBLIC;\n", ! type, name); /* * We still need some hacking though to cover the case where new default --- 451,460 ---- * wire-in knowledge about the default public privileges for different * kinds of objects. */ ! appendPQExpBuffer(firstsql, "REVOKE ALL"); ! if (subname) ! appendPQExpBuffer(firstsql, "(%s)", subname); ! appendPQExpBuffer(firstsql, " ON %s %s FROM PUBLIC;\n", type, name); /* * We still need some hacking though to cover the case where new default *************** buildACLCommands(const char *name, const *** 468,474 **** /* Scan individual ACL items */ for (i = 0; i < naclitems; i++) { ! if (!parseAclItem(aclitems[i], type, name, remoteVersion, grantee, grantor, privs, privswgo)) return false; --- 473,479 ---- /* Scan individual ACL items */ for (i = 0; i < naclitems; i++) { ! if (!parseAclItem(aclitems[i], type, name, subname, remoteVersion, grantee, grantor, privs, privswgo)) return false; *************** buildACLCommands(const char *name, const *** 491,505 **** ? strcmp(privswgo->data, "ALL") != 0 : strcmp(privs->data, "ALL") != 0) { ! appendPQExpBuffer(firstsql, "REVOKE ALL ON %s %s FROM %s;\n", ! type, name, ! fmtId(grantee->data)); if (privs->len > 0) ! appendPQExpBuffer(firstsql, "GRANT %s ON %s %s TO %s;\n", privs->data, type, name, fmtId(grantee->data)); if (privswgo->len > 0) ! appendPQExpBuffer(firstsql, "GRANT %s ON %s %s TO %s WITH GRANT OPTION;\n", privswgo->data, type, name, fmtId(grantee->data)); } --- 496,514 ---- ? strcmp(privswgo->data, "ALL") != 0 : strcmp(privs->data, "ALL") != 0) { ! appendPQExpBuffer(firstsql, "REVOKE ALL"); ! if (subname) ! appendPQExpBuffer(firstsql, "(%s)", subname); ! appendPQExpBuffer(firstsql, " ON %s %s FROM %s;\n", ! type, name, fmtId(grantee->data)); if (privs->len > 0) ! appendPQExpBuffer(firstsql, ! "GRANT %s ON %s %s TO %s;\n", privs->data, type, name, fmtId(grantee->data)); if (privswgo->len > 0) ! appendPQExpBuffer(firstsql, ! "GRANT %s ON %s %s TO %s WITH GRANT OPTION;\n", privswgo->data, type, name, fmtId(grantee->data)); } *************** buildACLCommands(const char *name, const *** 553,560 **** * If we didn't find any owner privs, the owner must have revoked 'em all */ if (!found_owner_privs && owner) ! appendPQExpBuffer(firstsql, "REVOKE ALL ON %s %s FROM %s;\n", type, name, fmtId(owner)); destroyPQExpBuffer(grantee); destroyPQExpBuffer(grantor); --- 562,574 ---- * If we didn't find any owner privs, the owner must have revoked 'em all */ if (!found_owner_privs && owner) ! { ! appendPQExpBuffer(firstsql, "REVOKE ALL"); ! if (subname) ! appendPQExpBuffer(firstsql, "(%s)", subname); ! appendPQExpBuffer(firstsql, " ON %s %s FROM %s;\n", type, name, fmtId(owner)); + } destroyPQExpBuffer(grantee); destroyPQExpBuffer(grantor); *************** buildACLCommands(const char *name, const *** 587,594 **** * appropriate. */ static bool ! parseAclItem(const char *item, const char *type, const char *name, ! int remoteVersion, PQExpBuffer grantee, PQExpBuffer grantor, PQExpBuffer privs, PQExpBuffer privswgo) { char *buf; --- 601,609 ---- * appropriate. */ static bool ! parseAclItem(const char *item, const char *type, ! const char *name, const char *subname, int remoteVersion, ! PQExpBuffer grantee, PQExpBuffer grantor, PQExpBuffer privs, PQExpBuffer privswgo) { char *buf; *************** do { \ *** 626,637 **** { \ if (*(pos + 1) == '*') \ { \ ! AddAcl(privswgo, keywd); \ all_without_go = false; \ } \ else \ { \ ! AddAcl(privs, keywd); \ all_with_go = false; \ } \ } \ --- 641,652 ---- { \ if (*(pos + 1) == '*') \ { \ ! AddAcl(privswgo, keywd, subname); \ all_without_go = false; \ } \ else \ { \ ! AddAcl(privs, keywd, subname); \ all_with_go = false; \ } \ } \ *************** do { \ *** 654,666 **** /* table only */ CONVERT_PRIV('a', "INSERT"); if (remoteVersion >= 70200) - { - CONVERT_PRIV('d', "DELETE"); CONVERT_PRIV('x', "REFERENCES"); ! CONVERT_PRIV('t', "TRIGGER"); } - if (remoteVersion >= 80400) - CONVERT_PRIV('D', "TRUNCATE"); } /* UPDATE */ --- 669,686 ---- /* table only */ CONVERT_PRIV('a', "INSERT"); if (remoteVersion >= 70200) CONVERT_PRIV('x', "REFERENCES"); ! /* rest are not applicable to columns */ ! if (subname == NULL) ! { ! if (remoteVersion >= 70200) ! { ! CONVERT_PRIV('d', "DELETE"); ! CONVERT_PRIV('t', "TRIGGER"); ! } ! if (remoteVersion >= 80400) ! CONVERT_PRIV('D', "TRUNCATE"); } } /* UPDATE */ *************** do { \ *** 700,710 **** --- 720,734 ---- { resetPQExpBuffer(privs); printfPQExpBuffer(privswgo, "ALL"); + if (subname) + appendPQExpBuffer(privswgo, "(%s)", subname); } else if (all_without_go) { resetPQExpBuffer(privswgo); printfPQExpBuffer(privs, "ALL"); + if (subname) + appendPQExpBuffer(privs, "(%s)", subname); } free(buf); *************** copyAclUserName(PQExpBuffer output, char *** 757,767 **** * Append a privilege keyword to a keyword list, inserting comma if needed. */ static void ! AddAcl(PQExpBuffer aclbuf, const char *keyword) { if (aclbuf->len > 0) appendPQExpBufferChar(aclbuf, ','); appendPQExpBuffer(aclbuf, "%s", keyword); } --- 781,793 ---- * Append a privilege keyword to a keyword list, inserting comma if needed. */ static void ! AddAcl(PQExpBuffer aclbuf, const char *keyword, const char *subname) { if (aclbuf->len > 0) appendPQExpBufferChar(aclbuf, ','); appendPQExpBuffer(aclbuf, "%s", keyword); + if (subname) + appendPQExpBuffer(aclbuf, "(%s)", subname); }