PostgreSQL Source Code  git master
pg_parameter_acl.c File Reference
#include "postgres.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_parameter_acl.h"
#include "utils/builtins.h"
#include "utils/pg_locale.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for pg_parameter_acl.c:

Go to the source code of this file.

Functions

Oid ParameterAclLookup (const char *parameter, bool missing_ok)
 
Oid ParameterAclCreate (const char *parameter)
 

Function Documentation

◆ ParameterAclCreate()

Oid ParameterAclCreate ( const char *  parameter)

Definition at line 70 of file pg_parameter_acl.c.

71 {
72  Oid parameterId;
73  char *parname;
74  Relation rel;
75  TupleDesc tupDesc;
76  HeapTuple tuple;
77  Datum values[Natts_pg_parameter_acl];
78  bool nulls[Natts_pg_parameter_acl];
79 
80  /*
81  * To prevent cluttering pg_parameter_acl with useless entries, insist
82  * that the name be valid.
83  */
84  if (!check_GUC_name_for_parameter_acl(parameter))
85  ereport(ERROR,
86  (errcode(ERRCODE_INVALID_NAME),
87  errmsg("invalid parameter name \"%s\"",
88  parameter)));
89 
90  /* Convert name to the form it should have in pg_parameter_acl. */
91  parname = convert_GUC_name_for_parameter_acl(parameter);
92 
93  /*
94  * Create and insert a new record containing a null ACL.
95  *
96  * We don't take a strong enough lock to prevent concurrent insertions,
97  * relying instead on the unique index.
98  */
99  rel = table_open(ParameterAclRelationId, RowExclusiveLock);
100  tupDesc = RelationGetDescr(rel);
101  MemSet(values, 0, sizeof(values));
102  MemSet(nulls, false, sizeof(nulls));
103  parameterId = GetNewOidWithIndex(rel,
104  ParameterAclOidIndexId,
105  Anum_pg_parameter_acl_oid);
106  values[Anum_pg_parameter_acl_oid - 1] = ObjectIdGetDatum(parameterId);
107  values[Anum_pg_parameter_acl_parname - 1] =
109  nulls[Anum_pg_parameter_acl_paracl - 1] = true;
110  tuple = heap_form_tuple(tupDesc, values, nulls);
111  CatalogTupleInsert(rel, tuple);
112 
113  /* Close pg_parameter_acl, but keep lock till commit. */
114  heap_freetuple(tuple);
115  table_close(rel, NoLock);
116 
117  return parameterId;
118 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define MemSet(start, val, len)
Definition: c.h:1008
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:391
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
bool check_GUC_name_for_parameter_acl(const char *name)
Definition: guc.c:5817
char * convert_GUC_name_for_parameter_acl(const char *name)
Definition: guc.c:5781
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:221
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:411
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define PointerGetDatum(X)
Definition: postgres.h:600
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetDescr(relation)
Definition: rel.h:514
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
text * cstring_to_text(const char *s)
Definition: varlena.c:188

References CatalogTupleInsert(), check_GUC_name_for_parameter_acl(), convert_GUC_name_for_parameter_acl(), cstring_to_text(), ereport, errcode(), errmsg(), ERROR, GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), MemSet, NoLock, ObjectIdGetDatum, PointerGetDatum, RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.

Referenced by objectNamesToOids().

◆ ParameterAclLookup()

Oid ParameterAclLookup ( const char *  parameter,
bool  missing_ok 
)

Definition at line 37 of file pg_parameter_acl.c.

38 {
39  Oid oid;
40  char *parname;
41 
42  /* Convert name to the form it should have in pg_parameter_acl... */
43  parname = convert_GUC_name_for_parameter_acl(parameter);
44 
45  /* ... and look it up */
46  oid = GetSysCacheOid1(PARAMETERACLNAME, Anum_pg_parameter_acl_oid,
48 
49  if (!OidIsValid(oid) && !missing_ok)
50  ereport(ERROR,
51  (errcode(ERRCODE_UNDEFINED_OBJECT),
52  errmsg("parameter ACL \"%s\" does not exist", parameter)));
53 
54  pfree(parname);
55 
56  return oid;
57 }
#define OidIsValid(objectId)
Definition: c.h:710
void pfree(void *pointer)
Definition: mcxt.c:1175
@ PARAMETERACLNAME
Definition: syscache.h:75
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:197

References convert_GUC_name_for_parameter_acl(), cstring_to_text(), ereport, errcode(), errmsg(), ERROR, GetSysCacheOid1, OidIsValid, PARAMETERACLNAME, pfree(), and PointerGetDatum.

Referenced by get_object_address_unqualified(), and objectNamesToOids().