PostgreSQL Source Code  git master
pg_parameter_acl.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_parameter_acl.c
4  * routines to support manipulation of the pg_parameter_acl relation
5  *
6  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/catalog/pg_parameter_acl.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/table.h"
18 #include "catalog/catalog.h"
19 #include "catalog/indexing.h"
20 #include "catalog/objectaccess.h"
21 #include "catalog/pg_namespace.h"
23 #include "utils/builtins.h"
24 #include "utils/guc.h"
25 #include "utils/pg_locale.h"
26 #include "utils/rel.h"
27 #include "utils/syscache.h"
28 
29 
30 /*
31  * ParameterAclLookup - Given a configuration parameter name,
32  * look up the associated configuration parameter ACL's OID.
33  *
34  * If missing_ok is false, throw an error if ACL entry not found. If
35  * true, just return InvalidOid.
36  */
37 Oid
38 ParameterAclLookup(const char *parameter, bool missing_ok)
39 {
40  Oid oid;
41  char *parname;
42 
43  /* Convert name to the form it should have in pg_parameter_acl... */
44  parname = convert_GUC_name_for_parameter_acl(parameter);
45 
46  /* ... and look it up */
47  oid = GetSysCacheOid1(PARAMETERACLNAME, Anum_pg_parameter_acl_oid,
49 
50  if (!OidIsValid(oid) && !missing_ok)
51  ereport(ERROR,
52  (errcode(ERRCODE_UNDEFINED_OBJECT),
53  errmsg("parameter ACL \"%s\" does not exist", parameter)));
54 
55  pfree(parname);
56 
57  return oid;
58 }
59 
60 /*
61  * ParameterAclCreate
62  *
63  * Add a new tuple to pg_parameter_acl.
64  *
65  * parameter: the parameter name to create an entry for.
66  * Caller should have verified that there's no such entry already.
67  *
68  * Returns the new entry's OID.
69  */
70 Oid
71 ParameterAclCreate(const char *parameter)
72 {
73  Oid parameterId;
74  char *parname;
75  Relation rel;
76  TupleDesc tupDesc;
77  HeapTuple tuple;
78  Datum values[Natts_pg_parameter_acl] = {0};
79  bool nulls[Natts_pg_parameter_acl] = {0};
80 
81  /*
82  * To prevent cluttering pg_parameter_acl with useless entries, insist
83  * that the name be valid.
84  */
86 
87  /* Convert name to the form it should have in pg_parameter_acl. */
88  parname = convert_GUC_name_for_parameter_acl(parameter);
89 
90  /*
91  * Create and insert a new record containing a null ACL.
92  *
93  * We don't take a strong enough lock to prevent concurrent insertions,
94  * relying instead on the unique index.
95  */
96  rel = table_open(ParameterAclRelationId, RowExclusiveLock);
97  tupDesc = RelationGetDescr(rel);
98  parameterId = GetNewOidWithIndex(rel,
99  ParameterAclOidIndexId,
100  Anum_pg_parameter_acl_oid);
101  values[Anum_pg_parameter_acl_oid - 1] = ObjectIdGetDatum(parameterId);
102  values[Anum_pg_parameter_acl_parname - 1] =
104  nulls[Anum_pg_parameter_acl_paracl - 1] = true;
105  tuple = heap_form_tuple(tupDesc, values, nulls);
106  CatalogTupleInsert(rel, tuple);
107 
108  /* Close pg_parameter_acl, but keep lock till commit. */
109  heap_freetuple(tuple);
110  table_close(rel, NoLock);
111 
112  return parameterId;
113 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define OidIsValid(objectId)
Definition: c.h:764
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:393
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void check_GUC_name_for_parameter_acl(const char *name)
Definition: guc.c:1405
char * convert_GUC_name_for_parameter_acl(const char *name)
Definition: guc.c:1369
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
void pfree(void *pointer)
Definition: mcxt.c:1456
Oid ParameterAclLookup(const char *parameter, bool missing_ok)
Oid ParameterAclCreate(const char *parameter)
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetDescr(relation)
Definition: rel.h:530
@ PARAMETERACLNAME
Definition: syscache.h:75
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:200
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
text * cstring_to_text(const char *s)
Definition: varlena.c:184