Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e4a9229

Browse files
committed
Treat procedural languages as owned by the bootstrap superuser, rather
than owned by nobody. This results in cleaner display of language ACLs, since the backend's aclchk.c uses the same convention. AFAICS there is no practical difference but it's nice to avoid emitting SET SESSION AUTHORIZATION; also this will make it easier to transition pg_dump to some future version in which we may include an explicit ownership column in pg_language. Per gripe from David Begley.
1 parent 6d4bcda commit e4a9229

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

src/bin/pg_dump/dumputils.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.22 2005/12/02 22:06:07 tgl Exp $
10+
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.23 2005/12/03 21:06:18 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -328,7 +328,8 @@ parsePGArray(const char *atext, char ***itemarray, int *nitems)
328328
* type: the object type (as seen in GRANT command: must be one of
329329
* TABLE, FUNCTION, LANGUAGE, SCHEMA, DATABASE, or TABLESPACE)
330330
* acls: the ACL string fetched from the database
331-
* owner: username of object owner (will be passed through fmtId), or NULL
331+
* owner: username of object owner (will be passed through fmtId); can be
332+
* NULL or empty string to indicate "no owner known"
332333
* remoteVersion: version of database
333334
*
334335
* Returns TRUE if okay, FALSE if could not parse the acl string.
@@ -357,6 +358,10 @@ buildACLCommands(const char *name, const char *type,
357358
if (strlen(acls) == 0)
358359
return true; /* object has default permissions */
359360

361+
/* treat empty-string owner same as NULL */
362+
if (owner && *owner == '\0')
363+
owner = NULL;
364+
360365
if (!parsePGArray(acls, &aclitems, &naclitems))
361366
{
362367
if (aclitems)

src/bin/pg_dump/pg_dump.c

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.423 2005/11/22 18:17:28 momjian Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.424 2005/12/03 21:06:18 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -3493,14 +3493,36 @@ getProcLangs(int *numProcLangs)
34933493
int i_lanname;
34943494
int i_lanpltrusted;
34953495
int i_lanplcallfoid;
3496-
int i_lanvalidator = -1;
3497-
int i_lanacl = -1;
3496+
int i_lanvalidator;
3497+
int i_lanacl;
3498+
int i_lanowner;
34983499

34993500
/* Make sure we are in proper schema */
35003501
selectSourceSchema("pg_catalog");
35013502

3502-
if (g_fout->remoteVersion >= 70100)
3503+
if (g_fout->remoteVersion >= 80100)
35033504
{
3505+
/* Languages are owned by the bootstrap superuser, OID 10 */
3506+
appendPQExpBuffer(query, "SELECT tableoid, oid, *, "
3507+
"(%s '10') as lanowner "
3508+
"FROM pg_language "
3509+
"WHERE lanispl "
3510+
"ORDER BY oid",
3511+
username_subquery);
3512+
}
3513+
else if (g_fout->remoteVersion >= 70400)
3514+
{
3515+
/* Languages are owned by the bootstrap superuser, sysid 1 */
3516+
appendPQExpBuffer(query, "SELECT tableoid, oid, *, "
3517+
"(%s '1') as lanowner "
3518+
"FROM pg_language "
3519+
"WHERE lanispl "
3520+
"ORDER BY oid",
3521+
username_subquery);
3522+
}
3523+
else if (g_fout->remoteVersion >= 70100)
3524+
{
3525+
/* No clear notion of an owner at all before 7.4 ... */
35043526
appendPQExpBuffer(query, "SELECT tableoid, oid, * FROM pg_language "
35053527
"WHERE lanispl "
35063528
"ORDER BY oid");
@@ -3528,11 +3550,10 @@ getProcLangs(int *numProcLangs)
35283550
i_lanname = PQfnumber(res, "lanname");
35293551
i_lanpltrusted = PQfnumber(res, "lanpltrusted");
35303552
i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
3531-
if (g_fout->remoteVersion >= 70300)
3532-
{
3533-
i_lanvalidator = PQfnumber(res, "lanvalidator");
3534-
i_lanacl = PQfnumber(res, "lanacl");
3535-
}
3553+
/* these may fail and return -1: */
3554+
i_lanvalidator = PQfnumber(res, "lanvalidator");
3555+
i_lanacl = PQfnumber(res, "lanacl");
3556+
i_lanowner = PQfnumber(res, "lanowner");
35363557

35373558
for (i = 0; i < ntups; i++)
35383559
{
@@ -3544,24 +3565,28 @@ getProcLangs(int *numProcLangs)
35443565
planginfo[i].dobj.name = strdup(PQgetvalue(res, i, i_lanname));
35453566
planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
35463567
planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
3547-
if (g_fout->remoteVersion >= 70300)
3548-
{
3568+
if (i_lanvalidator >= 0)
35493569
planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
3550-
planginfo[i].lanacl = strdup(PQgetvalue(res, i, i_lanacl));
3551-
}
35523570
else
3553-
{
3554-
FuncInfo *funcInfo;
3555-
35563571
planginfo[i].lanvalidator = InvalidOid;
3572+
if (i_lanacl >= 0)
3573+
planginfo[i].lanacl = strdup(PQgetvalue(res, i, i_lanacl));
3574+
else
35573575
planginfo[i].lanacl = strdup("{=U}");
3576+
if (i_lanowner >= 0)
3577+
planginfo[i].lanowner = strdup(PQgetvalue(res, i, i_lanowner));
3578+
else
3579+
planginfo[i].lanowner = strdup("");
35583580

3581+
if (g_fout->remoteVersion < 70300)
3582+
{
35593583
/*
35603584
* We need to make a dependency to ensure the function will be
35613585
* dumped first. (In 7.3 and later the regular dependency
35623586
* mechanism will handle this for us.)
35633587
*/
3564-
funcInfo = findFuncByOid(planginfo[i].lanplcallfoid);
3588+
FuncInfo *funcInfo = findFuncByOid(planginfo[i].lanplcallfoid);
3589+
35653590
if (funcInfo)
35663591
addObjectDependency(&planginfo[i].dobj,
35673592
funcInfo->dobj.dumpId);
@@ -5171,7 +5196,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
51715196

51725197
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
51735198
plang->dobj.name,
5174-
lanschema, NULL, "",
5199+
lanschema, NULL, plang->lanowner,
51755200
false, "PROCEDURAL LANGUAGE",
51765201
defqry->data, delqry->data, NULL,
51775202
plang->dobj.dependencies, plang->dobj.nDeps,
@@ -5188,7 +5213,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
51885213
dumpACL(fout, plang->dobj.catId, plang->dobj.dumpId, "LANGUAGE",
51895214
qlanname, plang->dobj.name,
51905215
lanschema,
5191-
NULL, plang->lanacl);
5216+
plang->lanowner, plang->lanacl);
51925217

51935218
free(qlanname);
51945219

@@ -6689,7 +6714,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
66896714
*
66906715
* 'objCatId' is the catalog ID of the underlying object.
66916716
* 'objDumpId' is the dump ID of the underlying object.
6692-
* 'type' must be TABLE, FUNCTION, LANGUAGE, or SCHEMA.
6717+
* 'type' must be TABLE, FUNCTION, LANGUAGE, SCHEMA, DATABASE, or TABLESPACE.
66936718
* 'name' is the formatted name of the object. Must be quoted etc. already.
66946719
* 'tag' is the tag for the archive entry (typ. unquoted name of object).
66956720
* 'nspname' is the namespace the object is in (NULL if none).

src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.122 2005/10/15 02:49:39 momjian Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.123 2005/12/03 21:06:18 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -297,6 +297,7 @@ typedef struct _procLangInfo
297297
Oid lanplcallfoid;
298298
Oid lanvalidator;
299299
char *lanacl;
300+
char *lanowner; /* name of owner, or empty string */
300301
} ProcLangInfo;
301302

302303
typedef struct _castInfo

0 commit comments

Comments
 (0)