MCPcopy Create free account
hub / github.com/apache/cloudberry / sepgsql_attribute_post_create

Function sepgsql_attribute_post_create

contrib/sepgsql/relation.c:42–125  ·  view source on GitHub ↗

* sepgsql_attribute_post_create * * This routine assigns a default security label on a newly defined * column, using ALTER TABLE ... ADD COLUMN. * Note that this routine is not invoked in the case of CREATE TABLE, * although it also defines columns in addition to table. */

Source from the content-addressed store, hash-verified

40 * although it also defines columns in addition to table.
41 */
42void
43sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
44{
45 Relation rel;
46 ScanKeyData skey[2];
47 SysScanDesc sscan;
48 HeapTuple tuple;
49 char *scontext;
50 char *tcontext;
51 char *ncontext;
52 ObjectAddress object;
53 Form_pg_attribute attForm;
54 StringInfoData audit_name;
55 char relkind = get_rel_relkind(relOid);
56
57 /*
58 * Only attributes within regular relations or partition relations have
59 * individual security labels.
60 */
61 if (relkind != RELKIND_RELATION && relkind != RELKIND_PARTITIONED_TABLE)
62 return;
63
64 /*
65 * Compute a default security label of the new column underlying the
66 * specified relation, and check permission to create it.
67 */
68 rel = table_open(AttributeRelationId, AccessShareLock);
69
70 ScanKeyInit(&skey[0],
71 Anum_pg_attribute_attrelid,
72 BTEqualStrategyNumber, F_OIDEQ,
73 ObjectIdGetDatum(relOid));
74 ScanKeyInit(&skey[1],
75 Anum_pg_attribute_attnum,
76 BTEqualStrategyNumber, F_INT2EQ,
77 Int16GetDatum(attnum));
78
79 sscan = systable_beginscan(rel, AttributeRelidNumIndexId, true,
80 SnapshotSelf, 2, &skey[0]);
81
82 tuple = systable_getnext(sscan);
83 if (!HeapTupleIsValid(tuple))
84 elog(ERROR, "could not find tuple for column %d of relation %u",
85 attnum, relOid);
86
87 attForm = (Form_pg_attribute) GETSTRUCT(tuple);
88
89 scontext = sepgsql_get_client_label();
90 tcontext = sepgsql_get_label(RelationRelationId, relOid, 0);
91 ncontext = sepgsql_compute_create(scontext, tcontext,
92 SEPG_CLASS_DB_COLUMN,
93 NameStr(attForm->attname));
94
95 /*
96 * check db_column:{create} permission
97 */
98 object.classId = RelationRelationId;
99 object.objectId = relOid;

Callers 1

sepgsql_object_accessFunction · 0.85

Calls 15

get_rel_relkindFunction · 0.85
table_openFunction · 0.85
ScanKeyInitFunction · 0.85
ObjectIdGetDatumFunction · 0.85
Int16GetDatumFunction · 0.85
systable_beginscanFunction · 0.85
systable_getnextFunction · 0.85
sepgsql_get_client_labelFunction · 0.85
sepgsql_get_labelFunction · 0.85
sepgsql_compute_createFunction · 0.85
initStringInfoFunction · 0.85
appendStringInfoFunction · 0.85

Tested by

no test coverage detected