Skip to content

Commit c9499e6

Browse files
committed
has_table_privilege functions from Joe Conway (with some kibitzing from
Tom Lane). For the moment, only the OID/name variants are provided. I didn't force initdb, but the additions to the 'privileges' regress test won't pass until you do one.
1 parent d7763c1 commit c9499e6

File tree

10 files changed

+845
-84
lines changed

10 files changed

+845
-84
lines changed

src/backend/commands/command.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.133 2001/06/12 05:55:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.134 2001/06/14 01:09:22 tgl Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -19,40 +19,36 @@
1919
*/
2020
#include "postgres.h"
2121

22+
#include "access/genam.h"
2223
#include "access/tuptoaster.h"
2324
#include "catalog/catalog.h"
2425
#include "catalog/catname.h"
26+
#include "catalog/heap.h"
2527
#include "catalog/index.h"
2628
#include "catalog/indexing.h"
2729
#include "catalog/pg_attrdef.h"
30+
#include "catalog/pg_index.h"
2831
#include "catalog/pg_opclass.h"
29-
#include "catalog/pg_rewrite.h"
32+
#include "catalog/pg_type.h"
3033
#include "commands/command.h"
31-
#include "executor/spi.h"
32-
#include "catalog/heap.h"
34+
#include "commands/trigger.h"
35+
#include "executor/execdefs.h"
36+
#include "executor/executor.h"
3337
#include "miscadmin.h"
38+
#include "optimizer/clauses.h"
39+
#include "optimizer/planmain.h"
3440
#include "optimizer/prep.h"
35-
#include "utils/acl.h"
36-
#include "utils/fmgroids.h"
37-
#include "commands/trigger.h"
38-
41+
#include "parser/parse.h"
3942
#include "parser/parse_expr.h"
40-
#include "parser/parse_clause.h"
41-
#include "parser/parse_relation.h"
4243
#include "parser/parse_oper.h"
43-
#include "nodes/makefuncs.h"
44-
#include "optimizer/planmain.h"
45-
#include "optimizer/clauses.h"
46-
#include "rewrite/rewriteSupport.h"
47-
#include "commands/view.h"
48-
#include "utils/temprel.h"
49-
#include "executor/spi_priv.h"
50-
#include "catalog/pg_index.h"
51-
#include "catalog/pg_shadow.h"
44+
#include "parser/parse_relation.h"
45+
#include "utils/acl.h"
46+
#include "utils/builtins.h"
47+
#include "utils/fmgroids.h"
48+
#include "utils/lsyscache.h"
49+
#include "utils/syscache.h"
5250
#include "utils/relcache.h"
53-
54-
#include "parser/parse.h"
55-
#include "access/genam.h"
51+
#include "utils/temprel.h"
5652

5753

5854
static void drop_default(Oid relid, int16 attnum);
@@ -1689,13 +1685,7 @@ AlterTableOwner(const char *relationName, const char *newOwnerName)
16891685
/*
16901686
* look up the new owner in pg_shadow and get the sysid
16911687
*/
1692-
tuple = SearchSysCache(SHADOWNAME,
1693-
PointerGetDatum(newOwnerName),
1694-
0, 0, 0);
1695-
if (!HeapTupleIsValid(tuple))
1696-
elog(ERROR, "ALTER TABLE: user \"%s\" not found", newOwnerName);
1697-
newOwnerSysid = ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
1698-
ReleaseSysCache(tuple);
1688+
newOwnerSysid = get_usesysid(newOwnerName);
16991689

17001690
/*
17011691
* find the table's entry in pg_class and make a modifiable copy

src/backend/commands/user.c

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.76 2001/06/12 05:55:49 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.77 2001/06/14 01:09:22 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -29,6 +29,7 @@
2929
#include "utils/array.h"
3030
#include "utils/builtins.h"
3131
#include "utils/fmgroids.h"
32+
#include "utils/lsyscache.h"
3233
#include "utils/syscache.h"
3334

3435

@@ -728,16 +729,9 @@ CreateGroup(CreateGroupStmt *stmt)
728729
const char *groupuser = strVal(lfirst(item));
729730
Value *v;
730731

731-
tuple = SearchSysCache(SHADOWNAME,
732-
PointerGetDatum(groupuser),
733-
0, 0, 0);
734-
if (!HeapTupleIsValid(tuple))
735-
elog(ERROR, "CREATE GROUP: user \"%s\" does not exist", groupuser);
736-
737-
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
732+
v = makeInteger(get_usesysid(groupuser));
738733
if (!member(v, newlist))
739734
newlist = lcons(v, newlist);
740-
ReleaseSysCache(tuple);
741735
}
742736

743737
/* build an array to insert */
@@ -879,18 +873,10 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
879873
if (strcmp(tag, "ALTER GROUP") == 0)
880874
{
881875
/* Get the uid of the proposed user to add. */
882-
tuple = SearchSysCache(SHADOWNAME,
883-
PointerGetDatum(strVal(lfirst(item))),
884-
0, 0, 0);
885-
if (!HeapTupleIsValid(tuple))
886-
elog(ERROR, "%s: user \"%s\" does not exist",
887-
tag, strVal(lfirst(item)));
888-
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
889-
ReleaseSysCache(tuple);
876+
v = makeInteger(get_usesysid(strVal(lfirst(item))));
890877
}
891878
else if (strcmp(tag, "CREATE USER") == 0)
892879
{
893-
894880
/*
895881
* in this case we already know the uid and it wouldn't be
896882
* in the cache anyway yet
@@ -906,12 +892,12 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
906892
if (!member(v, newlist))
907893
newlist = lcons(v, newlist);
908894
else
909-
910895
/*
911896
* we silently assume here that this error will only come
912897
* up in a ALTER GROUP statement
913898
*/
914-
elog(NOTICE, "%s: user \"%s\" is already in group \"%s\"", tag, strVal(lfirst(item)), stmt->name);
899+
elog(NOTICE, "%s: user \"%s\" is already in group \"%s\"",
900+
tag, strVal(lfirst(item)), stmt->name);
915901
}
916902

917903
newarray = palloc(ARR_OVERHEAD(1) + length(newlist) * sizeof(int32));
@@ -1001,13 +987,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
1001987
if (!is_dropuser)
1002988
{
1003989
/* Get the uid of the proposed user to drop. */
1004-
tuple = SearchSysCache(SHADOWNAME,
1005-
PointerGetDatum(strVal(lfirst(item))),
1006-
0, 0, 0);
1007-
if (!HeapTupleIsValid(tuple))
1008-
elog(ERROR, "ALTER GROUP: user \"%s\" does not exist", strVal(lfirst(item)));
1009-
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
1010-
ReleaseSysCache(tuple);
990+
v = makeInteger(get_usesysid(strVal(lfirst(item))));
1011991
}
1012992
else
1013993
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy