* sepgsql_relation_post_create * * The post creation hook of relation/attribute */
| 237 | * The post creation hook of relation/attribute |
| 238 | */ |
| 239 | void |
| 240 | sepgsql_relation_post_create(Oid relOid) |
| 241 | { |
| 242 | Relation rel; |
| 243 | ScanKeyData skey; |
| 244 | SysScanDesc sscan; |
| 245 | HeapTuple tuple; |
| 246 | Form_pg_class classForm; |
| 247 | ObjectAddress object; |
| 248 | uint16_t tclass; |
| 249 | char *scontext; /* subject */ |
| 250 | char *tcontext; /* schema */ |
| 251 | char *rcontext; /* relation */ |
| 252 | char *ccontext; /* column */ |
| 253 | char *nsp_name; |
| 254 | StringInfoData audit_name; |
| 255 | |
| 256 | /* |
| 257 | * Fetch catalog record of the new relation. Because pg_class entry is not |
| 258 | * visible right now, we need to scan the catalog using SnapshotSelf. |
| 259 | */ |
| 260 | rel = table_open(RelationRelationId, AccessShareLock); |
| 261 | |
| 262 | ScanKeyInit(&skey, |
| 263 | Anum_pg_class_oid, |
| 264 | BTEqualStrategyNumber, F_OIDEQ, |
| 265 | ObjectIdGetDatum(relOid)); |
| 266 | |
| 267 | sscan = systable_beginscan(rel, ClassOidIndexId, true, |
| 268 | SnapshotSelf, 1, &skey); |
| 269 | |
| 270 | tuple = systable_getnext(sscan); |
| 271 | if (!HeapTupleIsValid(tuple)) |
| 272 | elog(ERROR, "could not find tuple for relation %u", relOid); |
| 273 | |
| 274 | classForm = (Form_pg_class) GETSTRUCT(tuple); |
| 275 | |
| 276 | /* ignore indexes on toast tables */ |
| 277 | if (classForm->relkind == RELKIND_INDEX && |
| 278 | classForm->relnamespace == PG_TOAST_NAMESPACE) |
| 279 | goto out; |
| 280 | |
| 281 | /* |
| 282 | * check db_schema:{add_name} permission of the namespace |
| 283 | */ |
| 284 | object.classId = NamespaceRelationId; |
| 285 | object.objectId = classForm->relnamespace; |
| 286 | object.objectSubId = 0; |
| 287 | sepgsql_avc_check_perms(&object, |
| 288 | SEPG_CLASS_DB_SCHEMA, |
| 289 | SEPG_DB_SCHEMA__ADD_NAME, |
| 290 | getObjectIdentity(&object, false), |
| 291 | true); |
| 292 | |
| 293 | switch (classForm->relkind) |
| 294 | { |
| 295 | case RELKIND_RELATION: |
| 296 | case RELKIND_PARTITIONED_TABLE: |
no test coverage detected