Skip to content

Commit f76730e

Browse files
author
Neil Conway
committed
Small patch to move get_grosysid() from catalog/aclchk.c to
utils/cache/lsyscache.c where it can be used by other things. Also cleans up both get_usesysid() and get_grosysid() a bit. From Stephen Frost.
1 parent a885ecd commit f76730e

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

src/backend/catalog/aclchk.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.109 2005/01/27 23:23:51 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.110 2005/01/27 23:36:06 neilc Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -1208,28 +1208,6 @@ privilege_to_string(AclMode privilege)
12081208
return NULL; /* appease compiler */
12091209
}
12101210

1211-
1212-
AclId
1213-
get_grosysid(char *groname)
1214-
{
1215-
HeapTuple tuple;
1216-
AclId id = 0;
1217-
1218-
tuple = SearchSysCache(GRONAME,
1219-
PointerGetDatum(groname),
1220-
0, 0, 0);
1221-
if (HeapTupleIsValid(tuple))
1222-
{
1223-
id = ((Form_pg_group) GETSTRUCT(tuple))->grosysid;
1224-
ReleaseSysCache(tuple);
1225-
}
1226-
else
1227-
ereport(ERROR,
1228-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1229-
errmsg("group \"%s\" does not exist", groname)));
1230-
return id;
1231-
}
1232-
12331211
/*
12341212
* Convert group ID to name, or return NULL if group can't be found
12351213
*/

src/backend/utils/cache/lsyscache.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.119 2004/12/31 22:01:25 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.120 2005/01/27 23:36:12 neilc Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -25,6 +25,7 @@
2525
#include "catalog/pg_operator.h"
2626
#include "catalog/pg_proc.h"
2727
#include "catalog/pg_shadow.h"
28+
#include "catalog/pg_group.h"
2829
#include "catalog/pg_statistic.h"
2930
#include "catalog/pg_type.h"
3031
#include "nodes/makefuncs.h"
@@ -2032,7 +2033,7 @@ get_namespace_name(Oid nspid)
20322033
AclId
20332034
get_usesysid(const char *username)
20342035
{
2035-
int32 result;
2036+
AclId userId;
20362037
HeapTuple userTup;
20372038

20382039
userTup = SearchSysCache(SHADOWNAME,
@@ -2043,9 +2044,39 @@ get_usesysid(const char *username)
20432044
(errcode(ERRCODE_UNDEFINED_OBJECT),
20442045
errmsg("user \"%s\" does not exist", username)));
20452046

2046-
result = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
2047+
userId = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
20472048

20482049
ReleaseSysCache(userTup);
20492050

2050-
return result;
2051+
return userId;
2052+
}
2053+
2054+
/*
2055+
* get_grosysid
2056+
*
2057+
* Given a group name, look up the group's sysid.
2058+
* Raises an error if no such group (rather than returning zero,
2059+
* which might possibly be a valid grosysid).
2060+
*
2061+
*/
2062+
AclId
2063+
get_grosysid(char *groname)
2064+
{
2065+
AclId groupId;
2066+
HeapTuple groupTup;
2067+
2068+
groupTup = SearchSysCache(GRONAME,
2069+
PointerGetDatum(groname),
2070+
0, 0, 0);
2071+
if (!HeapTupleIsValid(groupTup))
2072+
ereport(ERROR,
2073+
(errcode(ERRCODE_UNDEFINED_OBJECT),
2074+
errmsg("group \"%s\" does not exist", groname)));
2075+
2076+
groupId = ((Form_pg_group) GETSTRUCT(groupTup))->grosysid;
2077+
2078+
ReleaseSysCache(groupTup);
2079+
2080+
return groupId;
20512081
}
2082+

src/include/utils/acl.h

Lines changed: 1 addition & 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/include/utils/acl.h,v 1.76 2004/12/31 22:03:45 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.77 2005/01/27 23:36:14 neilc Exp $
1111
*
1212
* NOTES
1313
* An ACL array is simply an array of AclItems, representing the union
@@ -245,7 +245,6 @@ extern Datum hash_aclitem(PG_FUNCTION_ARGS);
245245
* prototypes for functions in aclchk.c
246246
*/
247247
extern void ExecuteGrantStmt(GrantStmt *stmt);
248-
extern AclId get_grosysid(char *groname);
249248
extern char *get_groname(AclId grosysid);
250249

251250
extern AclMode pg_class_aclmask(Oid table_oid, AclId userid,

src/include/utils/lsyscache.h

Lines changed: 3 additions & 2 deletions
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/include/utils/lsyscache.h,v 1.93 2004/12/31 22:03:46 pgsql Exp $
9+
* $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.94 2005/01/27 23:36:15 neilc Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -115,7 +115,8 @@ extern void free_attstatsslot(Oid atttype,
115115
Datum *values, int nvalues,
116116
float4 *numbers, int nnumbers);
117117
extern char *get_namespace_name(Oid nspid);
118-
extern int32 get_usesysid(const char *username);
118+
extern AclId get_usesysid(const char *username);
119+
extern AclId get_grosysid(char *groname);
119120

120121
#define is_array_type(typid) (get_element_type(typid) != InvalidOid)
121122

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