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/guc.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 71 of file pg_parameter_acl.c.

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  */
85  if (!check_GUC_name_for_parameter_acl(parameter))
86  ereport(ERROR,
87  (errcode(ERRCODE_INVALID_NAME),
88  errmsg("invalid parameter name \"%s\"",
89  parameter)));
90 
91  /* Convert name to the form it should have in pg_parameter_acl. */
92  parname = convert_GUC_name_for_parameter_acl(parameter);
93 
94  /*
95  * Create and insert a new record containing a null ACL.
96  *
97  * We don't take a strong enough lock to prevent concurrent insertions,
98  * relying instead on the unique index.
99  */
100  rel = table_open(ParameterAclRelationId, RowExclusiveLock);
101  tupDesc = RelationGetDescr(rel);
102  parameterId = GetNewOidWithIndex(rel,
103  ParameterAclOidIndexId,
104  Anum_pg_parameter_acl_oid);
105  values[Anum_pg_parameter_acl_oid - 1] = ObjectIdGetDatum(parameterId);
106  values[Anum_pg_parameter_acl_parname - 1] =
108  nulls[Anum_pg_parameter_acl_paracl - 1] = true;
109  tuple = heap_form_tuple(tupDesc, values, nulls);
110  CatalogTupleInsert(rel, tuple);
111 
112  /* Close pg_parameter_acl, but keep lock till commit. */
113  heap_freetuple(tuple);
114  table_close(rel, NoLock);
115 
116  return parameterId;
117 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:393
int errcode(int sqlerrcode)
Definition: elog.c:735
int errmsg(const char *fmt,...)
Definition: elog.c:946
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
bool check_GUC_name_for_parameter_acl(const char *name)
Definition: guc.c:1375
char * convert_GUC_name_for_parameter_acl(const char *name)
Definition: guc.c:1339
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
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
uintptr_t Datum
Definition: postgres.h:412
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:600
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetDescr(relation)
Definition: rel.h:527
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:189

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(), 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 38 of file pg_parameter_acl.c.

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 }
#define OidIsValid(objectId)
Definition: c.h:711
void pfree(void *pointer)
Definition: mcxt.c:1306
@ 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().