1/* -------------------------------------------------------------------------
3 * contrib/sepgsql/proc.c
5 * Routines corresponding to procedure objects
7 * Copyright (c) 2010-2025, PostgreSQL Global Development Group
9 * -------------------------------------------------------------------------
25#include "utils/fmgroids.h"
31 * sepgsql_proc_post_create
33 * This routine assigns a default security label on a newly defined
54 * Fetch namespace of the new procedure. Because pg_proc entry is not
55 * visible right now, we need to scan the catalog using SnapshotSelf.
69 elog(
ERROR,
"could not find tuple for function %u", functionId);
74 * check db_schema:{add_name} permission of the namespace
76 object.classId = NamespaceRelationId;
77 object.objectId = proForm->pronamespace;
78 object.objectSubId = 0;
86 * XXX - db_language:{implement} also should be checked here
91 * Compute a default security label when we create a new procedure object
92 * under the specified namespace.
96 proForm->pronamespace, 0);
102 * check db_procedure:{create (install)} permission
108 for (
i = 0;
i < proForm->pronargs;
i++)
113 object.classId = TypeRelationId;
114 object.objectId = proForm->proargtypes.values[
i];
115 object.objectSubId = 0;
121 if (proForm->proleakproof)
131 * Assign the default security label on a new procedure
133 object.classId = ProcedureRelationId;
134 object.objectId = functionId;
135 object.objectSubId = 0;
152 * It checks privileges to drop the supplied function.
161 * check db_schema:{remove_name} permission
163 object.
classId = NamespaceRelationId;
165 object.objectSubId = 0;
176 * check db_procedure:{drop} permission
178 object.classId = ProcedureRelationId;
179 object.objectId = functionId;
180 object.objectSubId = 0;
192 * sepgsql_proc_relabel
194 * It checks privileges to relabel the supplied function
203 object.
classId = ProcedureRelationId;
204 object.objectId = functionId;
205 object.objectSubId = 0;
209 * check db_procedure:{setattr relabelfrom} permission
219 * check db_procedure:{relabelto} permission
230 * sepgsql_proc_setattr
232 * It checks privileges to alter the supplied function.
249 * Fetch newer catalog
262 elog(
ERROR,
"could not find tuple for function %u", functionId);
266 * Fetch older catalog
270 elog(
ERROR,
"cache lookup failed for function %u", functionId);
274 * Does this ALTER command takes operation to namespace?
276 if (newform->pronamespace != oldform->pronamespace)
281 if (strcmp(
NameStr(newform->proname),
NameStr(oldform->proname)) != 0)
285 * check db_procedure:{setattr (install)} permission
288 if (!oldform->proleakproof && newform->proleakproof)
291 object.classId = ProcedureRelationId;
292 object.objectId = functionId;
293 object.objectSubId = 0;
310 * sepgsql_proc_execute
312 * It checks privileges to execute the supplied function
321 * check db_procedure:{execute} permission
323 object.
classId = ProcedureRelationId;
324 object.objectId = functionId;
325 object.objectSubId = 0;
void sepgsql_proc_post_create(Oid functionId)
void sepgsql_proc_relabel(Oid functionId, const char *seclabel)
void sepgsql_proc_setattr(Oid functionId)
void sepgsql_proc_drop(Oid functionId)
void sepgsql_proc_execute(Oid functionId)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
char * sepgsql_get_label(Oid classId, Oid objectId, int32 subId)
char * sepgsql_get_client_label(void)
Oid get_func_namespace(Oid funcid)
char * get_namespace_name(Oid nspid)
void pfree(void *pointer)
char * getObjectIdentity(const ObjectAddress *object, bool missing_ok)
FormData_pg_proc * Form_pg_proc
static Datum ObjectIdGetDatum(Oid X)
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void sepgsql_schema_rename(Oid namespaceId)
void sepgsql_schema_remove_name(Oid namespaceId)
void sepgsql_schema_add_name(Oid namespaceId)
void SetSecurityLabel(const ObjectAddress *object, const char *provider, const char *label)
char * sepgsql_compute_create(const char *scontext, const char *tcontext, uint16 tclass, const char *objname)
#define SEPG_CLASS_DB_SCHEMA
#define SEPG_DB_PROCEDURE__CREATE
#define SEPG_DB_PROCEDURE__RELABELFROM
#define SEPG_DB_SCHEMA__REMOVE_NAME
bool sepgsql_avc_check_perms_label(const char *tcontext, uint16 tclass, uint32 required, const char *audit_name, bool abort_on_violation)
#define SEPG_DB_PROCEDURE__INSTALL
#define SEPG_DB_PROCEDURE__DROP
#define SEPG_DB_SCHEMA__ADD_NAME
#define SEPG_DB_PROCEDURE__EXECUTE
#define SEPG_DB_PROCEDURE__RELABELTO
#define SEPG_DB_PROCEDURE__SETATTR
#define SEPG_CLASS_DB_PROCEDURE
#define SEPGSQL_LABEL_TAG
bool sepgsql_avc_check_perms(const ObjectAddress *tobject, uint16 tclass, uint32 required, const char *audit_name, bool abort_on_violation)
#define BTEqualStrategyNumber
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)