Commit b46c9211 authored by Tom Lane's avatar Tom Lane

Fix assorted bugs in privileges-for-types patch.

Commit 72920557 added privileges on data
types, but there were a number of oversights.  The implementation of
default privileges for types missed a few places, and pg_dump was
utterly innocent of the whole concept.  Per bug #7741 from Nathan Alden,
and subsequent wider investigation.
parent a99c42f2
...@@ -2674,7 +2674,8 @@ ...@@ -2674,7 +2674,8 @@
Type of object this entry is for: Type of object this entry is for:
<literal>r</> = relation (table, view), <literal>r</> = relation (table, view),
<literal>S</> = sequence, <literal>S</> = sequence,
<literal>f</> = function <literal>f</> = function,
<literal>T</> = type
</entry> </entry>
</row> </row>
......
...@@ -1346,10 +1346,13 @@ RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid) ...@@ -1346,10 +1346,13 @@ RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid)
case DEFACLOBJ_FUNCTION: case DEFACLOBJ_FUNCTION:
iacls.objtype = ACL_OBJECT_FUNCTION; iacls.objtype = ACL_OBJECT_FUNCTION;
break; break;
case DEFACLOBJ_TYPE:
iacls.objtype = ACL_OBJECT_TYPE;
break;
default: default:
/* Shouldn't get here */ /* Shouldn't get here */
elog(ERROR, "unexpected default ACL type %d", elog(ERROR, "unexpected default ACL type: %d",
pg_default_acl_tuple->defaclobjtype); (int) pg_default_acl_tuple->defaclobjtype);
break; break;
} }
......
...@@ -2899,6 +2899,11 @@ getObjectDescription(const ObjectAddress *object) ...@@ -2899,6 +2899,11 @@ getObjectDescription(const ObjectAddress *object)
_("default privileges on new functions belonging to role %s"), _("default privileges on new functions belonging to role %s"),
GetUserNameFromId(defacl->defaclrole)); GetUserNameFromId(defacl->defaclrole));
break; break;
case DEFACLOBJ_TYPE:
appendStringInfo(&buffer,
_("default privileges on new types belonging to role %s"),
GetUserNameFromId(defacl->defaclrole));
break;
default: default:
/* shouldn't get here */ /* shouldn't get here */
appendStringInfo(&buffer, appendStringInfo(&buffer,
......
...@@ -890,6 +890,9 @@ do { \ ...@@ -890,6 +890,9 @@ do { \
} }
else if (strcmp(type, "TABLESPACE") == 0) else if (strcmp(type, "TABLESPACE") == 0)
CONVERT_PRIV('C', "CREATE"); CONVERT_PRIV('C', "CREATE");
else if (strcmp(type, "TYPE") == 0 ||
strcmp(type, "TYPES") == 0)
CONVERT_PRIV('U', "USAGE");
else if (strcmp(type, "FOREIGN DATA WRAPPER") == 0) else if (strcmp(type, "FOREIGN DATA WRAPPER") == 0)
CONVERT_PRIV('U', "USAGE"); CONVERT_PRIV('U', "USAGE");
else if (strcmp(type, "FOREIGN SERVER") == 0) else if (strcmp(type, "FOREIGN SERVER") == 0)
......
...@@ -2820,6 +2820,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2820,6 +2820,7 @@ getTypes(Archive *fout, int *numTypes)
int i_oid; int i_oid;
int i_typname; int i_typname;
int i_typnamespace; int i_typnamespace;
int i_typacl;
int i_rolname; int i_rolname;
int i_typinput; int i_typinput;
int i_typoutput; int i_typoutput;
...@@ -2849,10 +2850,25 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2849,10 +2850,25 @@ getTypes(Archive *fout, int *numTypes)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (fout->remoteVersion >= 80300) if (fout->remoteVersion >= 90200)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, " "typnamespace, typacl, "
"(%s typowner) AS rolname, "
"typinput::oid AS typinput, "
"typoutput::oid AS typoutput, typelem, typrelid, "
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
"typtype, typisdefined, "
"typname[0] = '_' AND typelem != 0 AND "
"(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
"FROM pg_type",
username_subquery);
}
else if (fout->remoteVersion >= 80300)
{
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, '{=U}' AS typacl, "
"(%s typowner) AS rolname, " "(%s typowner) AS rolname, "
"typinput::oid AS typinput, " "typinput::oid AS typinput, "
"typoutput::oid AS typoutput, typelem, typrelid, " "typoutput::oid AS typoutput, typelem, typrelid, "
...@@ -2867,7 +2883,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2867,7 +2883,7 @@ getTypes(Archive *fout, int *numTypes)
else if (fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, " "typnamespace, '{=U}' AS typacl, "
"(%s typowner) AS rolname, " "(%s typowner) AS rolname, "
"typinput::oid AS typinput, " "typinput::oid AS typinput, "
"typoutput::oid AS typoutput, typelem, typrelid, " "typoutput::oid AS typoutput, typelem, typrelid, "
...@@ -2881,7 +2897,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2881,7 +2897,7 @@ getTypes(Archive *fout, int *numTypes)
else if (fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"0::oid AS typnamespace, " "0::oid AS typnamespace, '{=U}' AS typacl, "
"(%s typowner) AS rolname, " "(%s typowner) AS rolname, "
"typinput::oid AS typinput, " "typinput::oid AS typinput, "
"typoutput::oid AS typoutput, typelem, typrelid, " "typoutput::oid AS typoutput, typelem, typrelid, "
...@@ -2897,7 +2913,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2897,7 +2913,7 @@ getTypes(Archive *fout, int *numTypes)
appendPQExpBuffer(query, "SELECT " appendPQExpBuffer(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_type') AS tableoid, " "(SELECT oid FROM pg_class WHERE relname = 'pg_type') AS tableoid, "
"oid, typname, " "oid, typname, "
"0::oid AS typnamespace, " "0::oid AS typnamespace, '{=U}' AS typacl, "
"(%s typowner) AS rolname, " "(%s typowner) AS rolname, "
"typinput::oid AS typinput, " "typinput::oid AS typinput, "
"typoutput::oid AS typoutput, typelem, typrelid, " "typoutput::oid AS typoutput, typelem, typrelid, "
...@@ -2919,6 +2935,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2919,6 +2935,7 @@ getTypes(Archive *fout, int *numTypes)
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
i_typname = PQfnumber(res, "typname"); i_typname = PQfnumber(res, "typname");
i_typnamespace = PQfnumber(res, "typnamespace"); i_typnamespace = PQfnumber(res, "typnamespace");
i_typacl = PQfnumber(res, "typacl");
i_rolname = PQfnumber(res, "rolname"); i_rolname = PQfnumber(res, "rolname");
i_typinput = PQfnumber(res, "typinput"); i_typinput = PQfnumber(res, "typinput");
i_typoutput = PQfnumber(res, "typoutput"); i_typoutput = PQfnumber(res, "typoutput");
...@@ -2941,6 +2958,7 @@ getTypes(Archive *fout, int *numTypes) ...@@ -2941,6 +2958,7 @@ getTypes(Archive *fout, int *numTypes)
atooid(PQgetvalue(res, i, i_typnamespace)), atooid(PQgetvalue(res, i, i_typnamespace)),
tyinfo[i].dobj.catId.oid); tyinfo[i].dobj.catId.oid);
tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
tyinfo[i].typacl = pg_strdup(PQgetvalue(res, i, i_typacl));
tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem)); tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid)); tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind); tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
...@@ -7592,6 +7610,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -7592,6 +7610,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
int num, int num,
i; i;
Oid enum_oid; Oid enum_oid;
char *qtypname;
char *label; char *label;
/* Set proper schema search path */ /* Set proper schema search path */
...@@ -7614,6 +7633,8 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -7614,6 +7633,8 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
num = PQntuples(res); num = PQntuples(res);
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
/* /*
* DROP must be fully qualified in case same name appears in pg_catalog. * DROP must be fully qualified in case same name appears in pg_catalog.
* CASCADE shouldn't be required here as for normal types since the I/O * CASCADE shouldn't be required here as for normal types since the I/O
...@@ -7622,14 +7643,14 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -7622,14 +7643,14 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "DROP TYPE %s.", appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tyinfo->dobj.namespace->dobj.name)); fmtId(tyinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tyinfo->dobj.name)); qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, q, binary_upgrade_set_type_oids_by_type_oid(fout, q,
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
appendPQExpBuffer(q, "CREATE TYPE %s AS ENUM (", appendPQExpBuffer(q, "CREATE TYPE %s AS ENUM (",
fmtId(tyinfo->dobj.name)); qtypname);
if (!binary_upgrade) if (!binary_upgrade)
{ {
...@@ -7662,13 +7683,13 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -7662,13 +7683,13 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(q, "ALTER TYPE %s.", appendPQExpBuffer(q, "ALTER TYPE %s.",
fmtId(tyinfo->dobj.namespace->dobj.name)); fmtId(tyinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(q, "%s ADD VALUE ", appendPQExpBuffer(q, "%s ADD VALUE ",
fmtId(tyinfo->dobj.name)); qtypname);
appendStringLiteralAH(q, label, fout); appendStringLiteralAH(q, label, fout);
appendPQExpBuffer(q, ";\n\n"); appendPQExpBuffer(q, ";\n\n");
} }
} }
appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name)); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
...@@ -7691,6 +7712,11 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -7691,6 +7712,11 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl);
PQclear(res); PQclear(res);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
destroyPQExpBuffer(delq); destroyPQExpBuffer(delq);
...@@ -7711,6 +7737,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7711,6 +7737,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
PGresult *res; PGresult *res;
Oid collationOid; Oid collationOid;
char *qtypname;
char *procname; char *procname;
/* /*
...@@ -7736,6 +7763,8 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7736,6 +7763,8 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
/* /*
* DROP must be fully qualified in case same name appears in pg_catalog. * DROP must be fully qualified in case same name appears in pg_catalog.
* CASCADE shouldn't be required here as for normal types since the I/O * CASCADE shouldn't be required here as for normal types since the I/O
...@@ -7744,14 +7773,14 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7744,14 +7773,14 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "DROP TYPE %s.", appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tyinfo->dobj.namespace->dobj.name)); fmtId(tyinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tyinfo->dobj.name)); qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, binary_upgrade_set_type_oids_by_type_oid(fout,
q, tyinfo->dobj.catId.oid); q, tyinfo->dobj.catId.oid);
appendPQExpBuffer(q, "CREATE TYPE %s AS RANGE (", appendPQExpBuffer(q, "CREATE TYPE %s AS RANGE (",
fmtId(tyinfo->dobj.name)); qtypname);
appendPQExpBuffer(q, "\n subtype = %s", appendPQExpBuffer(q, "\n subtype = %s",
PQgetvalue(res, 0, PQfnumber(res, "rngsubtype"))); PQgetvalue(res, 0, PQfnumber(res, "rngsubtype")));
...@@ -7793,7 +7822,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7793,7 +7822,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(q, "\n);\n"); appendPQExpBuffer(q, "\n);\n");
appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name)); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
...@@ -7816,6 +7845,11 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7816,6 +7845,11 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl);
PQclear(res); PQclear(res);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
destroyPQExpBuffer(delq); destroyPQExpBuffer(delq);
...@@ -7835,6 +7869,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -7835,6 +7869,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer labelq = createPQExpBuffer();
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
PGresult *res; PGresult *res;
char *qtypname;
char *typlen; char *typlen;
char *typinput; char *typinput;
char *typoutput; char *typoutput;
...@@ -8067,6 +8102,8 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8067,6 +8102,8 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
else else
typdefault = NULL; typdefault = NULL;
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
/* /*
* DROP must be fully qualified in case same name appears in pg_catalog. * DROP must be fully qualified in case same name appears in pg_catalog.
* The reason we include CASCADE is that the circular dependency between * The reason we include CASCADE is that the circular dependency between
...@@ -8076,7 +8113,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8076,7 +8113,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "DROP TYPE %s.", appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tyinfo->dobj.namespace->dobj.name)); fmtId(tyinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(delq, "%s CASCADE;\n", appendPQExpBuffer(delq, "%s CASCADE;\n",
fmtId(tyinfo->dobj.name)); qtypname);
/* We might already have a shell type, but setting pg_type_oid is harmless */ /* We might already have a shell type, but setting pg_type_oid is harmless */
if (binary_upgrade) if (binary_upgrade)
...@@ -8086,7 +8123,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8086,7 +8123,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(q, appendPQExpBuffer(q,
"CREATE TYPE %s (\n" "CREATE TYPE %s (\n"
" INTERNALLENGTH = %s", " INTERNALLENGTH = %s",
fmtId(tyinfo->dobj.name), qtypname,
(strcmp(typlen, "-1") == 0) ? "variable" : typlen); (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
if (fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
...@@ -8175,7 +8212,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8175,7 +8212,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(q, "\n);\n"); appendPQExpBuffer(q, "\n);\n");
appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name)); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
...@@ -8198,6 +8235,11 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8198,6 +8235,11 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl);
PQclear(res); PQclear(res);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
destroyPQExpBuffer(delq); destroyPQExpBuffer(delq);
...@@ -8218,6 +8260,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8218,6 +8260,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
PGresult *res; PGresult *res;
int i; int i;
char *qtypname;
char *typnotnull; char *typnotnull;
char *typdefn; char *typdefn;
char *typdefault; char *typdefault;
...@@ -8273,9 +8316,11 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8273,9 +8316,11 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
binary_upgrade_set_type_oids_by_type_oid(fout, q, binary_upgrade_set_type_oids_by_type_oid(fout, q,
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
appendPQExpBuffer(q, appendPQExpBuffer(q,
"CREATE DOMAIN %s AS %s", "CREATE DOMAIN %s AS %s",
fmtId(tyinfo->dobj.name), qtypname,
typdefn); typdefn);
/* Print collation only if different from base type's collation */ /* Print collation only if different from base type's collation */
...@@ -8328,9 +8373,9 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8328,9 +8373,9 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "DROP DOMAIN %s.", appendPQExpBuffer(delq, "DROP DOMAIN %s.",
fmtId(tyinfo->dobj.namespace->dobj.name)); fmtId(tyinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tyinfo->dobj.name)); qtypname);
appendPQExpBuffer(labelq, "DOMAIN %s", fmtId(tyinfo->dobj.name)); appendPQExpBuffer(labelq, "DOMAIN %s", qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
...@@ -8353,6 +8398,11 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8353,6 +8398,11 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
destroyPQExpBuffer(delq); destroyPQExpBuffer(delq);
destroyPQExpBuffer(labelq); destroyPQExpBuffer(labelq);
...@@ -8373,6 +8423,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8373,6 +8423,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer labelq = createPQExpBuffer();
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
PGresult *res; PGresult *res;
char *qtypname;
int ntups; int ntups;
int i_attname; int i_attname;
int i_atttypdefn; int i_atttypdefn;
...@@ -8450,8 +8501,10 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8450,8 +8501,10 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
binary_upgrade_set_pg_class_oids(fout, q, typrelid, false); binary_upgrade_set_pg_class_oids(fout, q, typrelid, false);
} }
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
appendPQExpBuffer(q, "CREATE TYPE %s AS (", appendPQExpBuffer(q, "CREATE TYPE %s AS (",
fmtId(tyinfo->dobj.name)); qtypname);
actual_atts = 0; actual_atts = 0;
for (i = 0; i < ntups; i++) for (i = 0; i < ntups; i++)
...@@ -8517,11 +8570,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8517,11 +8570,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
"WHERE attname = ", attlen, attalign); "WHERE attname = ", attlen, attalign);
appendStringLiteralAH(dropped, attname, fout); appendStringLiteralAH(dropped, attname, fout);
appendPQExpBuffer(dropped, "\n AND attrelid = "); appendPQExpBuffer(dropped, "\n AND attrelid = ");
appendStringLiteralAH(dropped, fmtId(tyinfo->dobj.name), fout); appendStringLiteralAH(dropped, qtypname, fout);
appendPQExpBuffer(dropped, "::pg_catalog.regclass;\n"); appendPQExpBuffer(dropped, "::pg_catalog.regclass;\n");
appendPQExpBuffer(dropped, "ALTER TYPE %s ", appendPQExpBuffer(dropped, "ALTER TYPE %s ",
fmtId(tyinfo->dobj.name)); qtypname);
appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n", appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n",
fmtId(attname)); fmtId(attname));
} }
...@@ -8535,9 +8588,9 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8535,9 +8588,9 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "DROP TYPE %s.", appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tyinfo->dobj.namespace->dobj.name)); fmtId(tyinfo->dobj.namespace->dobj.name));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tyinfo->dobj.name)); qtypname);
appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name)); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
...@@ -8561,6 +8614,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8561,6 +8614,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl);
PQclear(res); PQclear(res);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
destroyPQExpBuffer(dropped); destroyPQExpBuffer(dropped);
...@@ -11832,10 +11890,13 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) ...@@ -11832,10 +11890,13 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo)
case DEFACLOBJ_FUNCTION: case DEFACLOBJ_FUNCTION:
type = "FUNCTIONS"; type = "FUNCTIONS";
break; break;
case DEFACLOBJ_TYPE:
type = "TYPES";
break;
default: default:
/* shouldn't get here */ /* shouldn't get here */
exit_horribly(NULL, exit_horribly(NULL,
"unknown object type (%d) in default privileges\n", "unrecognized object type in default privileges: %d\n",
(int) daclinfo->defaclobjtype); (int) daclinfo->defaclobjtype);
type = ""; /* keep compiler quiet */ type = ""; /* keep compiler quiet */
} }
......
...@@ -164,6 +164,7 @@ typedef struct _typeInfo ...@@ -164,6 +164,7 @@ typedef struct _typeInfo
* produce something different than typname * produce something different than typname
*/ */
char *rolname; /* name of owner, or empty string */ char *rolname; /* name of owner, or empty string */
char *typacl;
Oid typelem; Oid typelem;
Oid typrelid; Oid typrelid;
char typrelkind; /* 'r', 'v', 'c', etc */ char typrelkind; /* 'r', 'v', 'c', etc */
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <ctype.h> #include <ctype.h>
#include "catalog/pg_default_acl.h"
#include "common.h" #include "common.h"
#include "describe.h" #include "describe.h"
#include "dumputils.h" #include "dumputils.h"
...@@ -774,7 +776,7 @@ permissionsList(const char *pattern) ...@@ -774,7 +776,7 @@ permissionsList(const char *pattern)
/* /*
* \ddp * \ddp
* *
* List DefaultACLs. The pattern can match either schema or role name. * List Default ACLs. The pattern can match either schema or role name.
*/ */
bool bool
listDefaultACLs(const char *pattern) listDefaultACLs(const char *pattern)
...@@ -796,13 +798,18 @@ listDefaultACLs(const char *pattern) ...@@ -796,13 +798,18 @@ listDefaultACLs(const char *pattern)
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n" "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
" n.nspname AS \"%s\",\n" " n.nspname AS \"%s\",\n"
" CASE d.defaclobjtype WHEN 'r' THEN '%s' WHEN 'S' THEN '%s' WHEN 'f' THEN '%s' END AS \"%s\",\n" " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
" ", " ",
gettext_noop("Owner"), gettext_noop("Owner"),
gettext_noop("Schema"), gettext_noop("Schema"),
DEFACLOBJ_RELATION,
gettext_noop("table"), gettext_noop("table"),
DEFACLOBJ_SEQUENCE,
gettext_noop("sequence"), gettext_noop("sequence"),
DEFACLOBJ_FUNCTION,
gettext_noop("function"), gettext_noop("function"),
DEFACLOBJ_TYPE,
gettext_noop("type"),
gettext_noop("Type")); gettext_noop("Type"));
printACLColumn(&buf, "d.defaclacl"); printACLColumn(&buf, "d.defaclacl");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment