*/
bool
buildDefaultACLCommands(const char *type, const char *nspname,
- const char *acls, const char *owner,
+ const char *acls, const char *racls,
+ const char *initacls, const char *initracls,
+ const char *owner,
int remoteVersion,
PQExpBuffer sql)
{
- bool result;
PQExpBuffer prefix;
prefix = createPQExpBuffer();
if (nspname)
appendPQExpBuffer(prefix, "IN SCHEMA %s ", fmtId(nspname));
- result = buildACLCommands("", NULL,
- type, acls, "", owner,
- prefix->data, remoteVersion,
- sql);
+ if (strlen(initacls) != 0 || strlen(initracls) != 0)
+ {
+ appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
+ if (!buildACLCommands("", NULL, type, initacls, initracls, owner,
+ prefix->data, remoteVersion, sql))
+ return false;
+ appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
+ }
+
+ if (!buildACLCommands("", NULL, type, acls, racls, owner,
+ prefix->data, remoteVersion, sql))
+ return false;
destroyPQExpBuffer(prefix);
- return result;
+ return true;
}
/*
int i_defaclnamespace;
int i_defaclobjtype;
int i_defaclacl;
+ int i_rdefaclacl;
+ int i_initdefaclacl;
+ int i_initrdefaclacl;
int i,
ntups;
/* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog");
- appendPQExpBuffer(query, "SELECT oid, tableoid, "
- "(%s defaclrole) AS defaclrole, "
- "defaclnamespace, "
- "defaclobjtype, "
- "defaclacl "
- "FROM pg_default_acl",
- username_subquery);
+ if (fout->remoteVersion >= 90600)
+ {
+ PQExpBuffer acl_subquery = createPQExpBuffer();
+ PQExpBuffer racl_subquery = createPQExpBuffer();
+ PQExpBuffer initacl_subquery = createPQExpBuffer();
+ PQExpBuffer initracl_subquery = createPQExpBuffer();
+
+ buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
+ initracl_subquery, "defaclacl", "defaclrole",
+ "CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
+ dopt->binary_upgrade);
+
+ appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
+ "(%s d.defaclrole) AS defaclrole, "
+ "d.defaclnamespace, "
+ "d.defaclobjtype, "
+ "%s AS defaclacl, "
+ "%s AS rdefaclacl, "
+ "%s AS initdefaclacl, "
+ "%s AS initrdefaclacl "
+ "FROM pg_default_acl d "
+ "LEFT JOIN pg_init_privs pip ON "
+ "(d.oid = pip.objoid "
+ "AND pip.classoid = 'pg_default_acl'::regclass "
+ "AND pip.objsubid = 0) ",
+ username_subquery,
+ acl_subquery->data,
+ racl_subquery->data,
+ initacl_subquery->data,
+ initracl_subquery->data);
+ }
+ else
+ {
+ appendPQExpBuffer(query, "SELECT oid, tableoid, "
+ "(%s defaclrole) AS defaclrole, "
+ "defaclnamespace, "
+ "defaclobjtype, "
+ "defaclacl, "
+ "NULL AS rdefaclacl, "
+ "NULL AS initdefaclacl, "
+ "NULL AS initrdefaclacl "
+ "FROM pg_default_acl",
+ username_subquery);
+ }
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
i_defaclnamespace = PQfnumber(res, "defaclnamespace");
i_defaclobjtype = PQfnumber(res, "defaclobjtype");
i_defaclacl = PQfnumber(res, "defaclacl");
+ i_rdefaclacl = PQfnumber(res, "rdefaclacl");
+ i_initdefaclacl = PQfnumber(res, "initdefaclacl");
+ i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
for (i = 0; i < ntups; i++)
{
daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
+ daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
+ daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
+ daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
/* Decide whether we want to dump it */
selectDumpableDefaultACL(&(daclinfo[i]), dopt);
daclinfo->dobj.namespace != NULL ?
daclinfo->dobj.namespace->dobj.name : NULL,
daclinfo->defaclacl,
+ daclinfo->rdefaclacl,
+ daclinfo->initdefaclacl,
+ daclinfo->initrdefaclacl,
daclinfo->defaclrole,
fout->remoteVersion,
q))